首页 > Android, System > Email正文中的电话号码、邮箱地址的识别

Email正文中的电话号码、邮箱地址的识别

2012-10-30 21:05 星期二    浏览: 2,779    绿 发表评论 阅读评论

Based on Android 4.0.4
当我们使用Android的Emai时,若里面出现了电话号码(phone number)、邮件地址(email address)或网页链接地址时,它会自动识别出来。当用户点击它们时,要么进行拨号,要么给对方发送邮件,要么使用浏览器打开网页链接。近日要解决其电话号码识别不准的问题,大致地浏览了相关代码。

Email正文的显示是通过WebView(见WebView.java文件)来实现的,而Java层的WebView类基于native的C++类WebView(见文件external/webkit/Source/…/WebView.cpp)实现,从而依赖于webkit。当Email获取html/xml内容时,将以节点的形式组织并展现它们。在读取Email内容时,会遍历里面的字符,若发现网址、邮件和电话号码等特征字符串,则将它们构建为”http:”、”mailto:”、”tel:”等节点。当用户点击它们时,将调用Java层去处理,见WebView.cpp中的overrideUrlLoading函数:

void overrideUrlLoading(const WTF::String& url)
{
JNIEnv* env = JSC::Bindings::getJNIEnv();
AutoJObject javaObject = m_javaGlue.object(env);
if (!javaObject.get())
return;
jstring jName = wtfStringToJstring(env, url);
env->CallVoidMethod(javaObject.get(), m_javaGlue.m_overrideLoading, jName);
env->DeleteLocalRef(jName);
}

Java层代码如下:

// Called by JNI to handle a touch on a node representing an email address,
// address, or phone number
private void overrideLoading(String url) {
mCallbackProxy.uiOverrideUrlLoading(url);
}

Java层可以通过重载CallbackProxy接口去处理,如通过发送Intent让对应的其它应用程序去处理,如android.webkit.CallbackProxy(见文件CallbackProxy.java):

那么WebView如何识别哪些是电话号码,哪些是邮件地址呢?由于从未看过WebKit,对其不熟,不知是在应用层还是native层的库中去进行匹配的。跟了WebView的java和native相关代码,如SelectText.cpp,无果。犹豫徘徊之时,在它们的目录下用grep搜索一下可疑字符串,迅速基本排除了Email,并在webkit中找到了相关匹配实现。
在4.0.1中,则是文件external/webkit/Source/Webkit/android/nav/CacheBuilder.cpp
在4.1.1中,则是文件external/webkit/Source/WebKit/android/content/PhoneEmailDetector.cpp
在ICS的CacheBuilder.cpp中,函数CacheBuilder::FindPhoneNumber负责查找电话号码,真正的操作则由FindPartialNumber函数完成,邮件正文将与PHONE_PATTERN定义的字符串进行比较来获取电话号码。

#define PHONE_PATTERN "(200) /-.\\ 100 -. 0000" // poor man's regex: parens optional, any one of punct, digit smallest allowed

对于邮件地址的匹配,则可参见CacheBuilder::FindPartialAddress、CacheBuilder::FindAddress和CacheBuilder::FindPartialEMail等函数。
另:1.可以在JNI层的WebViewCore.cpp中控制是否对email地址和电话号码进行自动检测,见WebViewCore::Settings::formatDetectionTelephone和WebViewCore::updateFrameCache等函数。
2.由于识别不可能100%正确,应用程序开发者,可以通过自己加标签的形式进行控制,可参考官方文档。

当点击邮件标题查阅邮件正文时,将对邮件内容进行遍历,若找到电话号码,则在其前面添加“tel:”标签。我们可以尝试打开debug选项,并添加一些log输出。打开log输出选项后,将导致一些编译错误。打开log并纠正编译错误的patch如下:

diff --git a/Source/WebKit/android/nav/CachedDebug.h b/Source/WebKit/android/nav/CachedDebug.h
index f77c07a..10ea402 100644
--- a/Source/WebKit/android/nav/CachedDebug.h
+++ b/Source/WebKit/android/nav/CachedDebug.h
@@ -26,9 +26,9 @@
#ifndef CachedDebug_h
#define CachedDebug_h

-#define DUMP_NAV_CACHE 0
-#define DEBUG_NAV_UI 0
-#define DEBUG_NAV_UI_VERBOSE 0
+#define DUMP_NAV_CACHE 1
+#define DEBUG_NAV_UI 1
+#define DEBUG_NAV_UI_VERBOSE 1

#if DEBUG_NAV_UI
#define DBG_NAV_LOG(message) LOGD(“%s %s”, __FUNCTION__, message)
diff –git a/Source/WebKit/android/nav/SelectText.cpp b/Source/WebKit/android/nav/SelectText.cpp
index d20c44a..38550d8 100644
— a/Source/WebKit/android/nav/SelectText.cpp
+++ b/Source/WebKit/android/nav/SelectText.cpp
@@ -1968,8 +1968,11 @@ bool SelectText::startSelection(const CachedRoot* root, const IntRect& vis,
}
m_hitTopLeft = hitStartHandle(x, y);
bool hitBottomRight = hitEndHandle(x, y);
– DBG_NAV_LOGD(“picture=(%d,%d) left=%d top=%d right=%d bottom=%d x=%d y=%d”,
– m_picture->width(), m_picture->height(),left, top, right, bottom, x, y);
+ //DBG_NAV_LOGD(“picture=(%d,%d) left=%d top=%d right=%d bottom=%d x=%d y=%d”,
+ // m_picture->width(), m_picture->height(),left, top, right, bottom, x, y);
+ DBG_NAV_LOGD(“picture=(%d,%d) left=null top=null right=null bottom=null x=%d y=%d”,
+ m_picture->width(), m_picture->height(), x, y);
+
if (m_hitTopLeft) {
DBG_NAV_LOG(“hit top left”);
m_original.fX -= m_selStart.fLeft;

diff –git a/Source/WebKit/android/nav/CacheBuilder.cpp b/Source/WebKit/android/nav/CacheBuilder.cpp
index 940991f..aaa9578 100644
— a/Source/WebKit/android/nav/CacheBuilder.cpp
+++ b/Source/WebKit/android/nav/CacheBuilder.cpp
@@ -493,7 +493,7 @@ void CacheBuilder::Debug::groups() {
RenderBlock* renderBlock = static_cast(renderer);
if (renderer->isRenderBlock() && renderBlock->hasColumns()) {
const RenderBox* box = static_cast(renderer);
– const IntRect& oRect = box->visibleOverflowRect();
+ const IntRect& oRect = box->visualOverflowRect();//visibleOverflowRect(); //commented by @BillYang_ycg
snprintf(scratch, sizeof(scratch), “// renderBlock:”
” columnCount=%d columnGap=%d direction=%d”
” hasOverflowClip=%d overflow=(%d,%d,w=%d,h=%d)”,
@@ -592,7 +592,9 @@ void CacheBuilder::Debug::groups() {
0 /*textBox->spaceAdd()*/, textBox->start(), 0 /*textBox->textPos()*/);
mIndex += snprintf(&mBuffer[mIndex], mBufferSize – mIndex, “, %d, %d, %d, %d”,
textBox->x(), textBox->y(), textBox->logicalWidth(), textBox->logicalHeight());
– int baseline = textBox->renderer()->style(textBox->isFirstLineStyle())->font().ascent();
+ //int baseline = textBox->renderer()->style(textBox->isFirstLineStyle())->font().ascent();//corrected by @BillYang_ycg
+ int baseline = textBox->renderer()->style(textBox->isFirstLineStyle())->font().fontMetrics().ascent();
+
mIndex += snprintf(&mBuffer[mIndex], mBufferSize – mIndex, “, %d, %d }, // %d “,

在添加调试语句后的输出log如下:
10-30 15:09:00.790: D/navcache(2203): ==================================================
10-30 15:09:00.790: D/navcache(2203): to FindPartialNumber: chars=1, length=11
10-30 15:09:00.790: D/navcache(2203): print the chars:
10-30 15:09:00.790: D/navcache(2203): Enter FindPartialNumber, handle chars=1, length=11
10-30 15:09:00.790: D/navcache(2203): patternChar=(,ch[pointer=0x31]=1
10-30 15:09:00.790: D/navcache(2203): patternChar=2,ch[pointer=0x31]=1
10-30 15:09:00.790: D/navcache(2203): patternChar=(,ch[pointer=0x33]=3
10-30 15:09:00.790: D/navcache(2203): patternChar=2,ch[pointer=0x33]=3
10-30 15:09:00.790: D/navcache(2203): Record the number:3
10-30 15:09:00.790: D/navcache(2203): patternChar=0,ch[pointer=0x39]=9
10-30 15:09:00.790: D/navcache(2203): Record the number:9
10-30 15:09:00.790: D/navcache(2203): patternChar=0,ch[pointer=0x31]=1
10-30 15:09:00.790: D/navcache(2203): Record the number:1
10-30 15:09:00.790: D/navcache(2203): patternChar=),ch[pointer=0x32]=2
10-30 15:09:00.790: D/navcache(2203): patternChar= ,ch[pointer=0x32]=2
10-30 15:09:00.790: D/navcache(2203): break
10-30 15:09:00.790: D/navcache(2203): patternChar=/,ch[pointer=0x32]=2
10-30 15:09:00.790: D/navcache(2203): patternChar=-,ch[pointer=0x32]=2
10-30 15:09:00.790: D/navcache(2203): patternChar=.,ch[pointer=0x32]=2
10-30 15:09:00.790: D/navcache(2203): patternChar=\,ch[pointer=0x32]=2
10-30 15:09:00.790: D/navcache(2203): patternChar= ,ch[pointer=0x32]=2
10-30 15:09:00.790: D/navcache(2203): break
10-30 15:09:00.790: D/navcache(2203): patternChar=1,ch[pointer=0x32]=2
10-30 15:09:00.790: D/navcache(2203): Record the number:2
10-30 15:09:00.790: D/navcache(2203): patternChar=0,ch[pointer=0x33]=3
10-30 15:09:00.790: D/navcache(2203): Record the number:3
10-30 15:09:00.790: D/navcache(2203): patternChar=0,ch[pointer=0x34]=4
10-30 15:09:00.790: D/navcache(2203): Record the number:4
10-30 15:09:00.790: D/navcache(2203): patternChar= ,ch[pointer=0x35]=5
10-30 15:09:00.790: D/navcache(2203): break
10-30 15:09:00.790: D/navcache(2203): patternChar=-,ch[pointer=0x35]=5
10-30 15:09:00.790: D/navcache(2203): patternChar=.,ch[pointer=0x35]=5
10-30 15:09:00.790: D/navcache(2203): patternChar= ,ch[pointer=0x35]=5
10-30 15:09:00.790: D/navcache(2203): break
10-30 15:09:00.790: D/navcache(2203): patternChar=0,ch[pointer=0x35]=5
10-30 15:09:00.790: D/navcache(2203): Record the number:5
10-30 15:09:00.790: D/navcache(2203): patternChar=0,ch[pointer=0x36]=6
10-30 15:09:00.790: D/navcache(2203): Record the number:6
10-30 15:09:00.790: D/navcache(2203): patternChar=0,ch[pointer=0x37]=7
10-30 15:09:00.790: D/navcache(2203): Record the number:7
10-30 15:09:00.790: D/navcache(2203): patternChar=0,ch[pointer=0x38]=8
10-30 15:09:00.790: D/navcache(2203): Record the number:8
10-30 15:09:00.790: D/navcache(2203): pattern[0]=
10-30 15:09:00.790: D/navcache(2203): state=FOUND_COMPLETE
10-30 15:09:00.790: D/navcache(2203): here:
10-30 15:09:00.790: D/navcache(2203): text link found: “tel:3912345678″

可以看出FindPartialNumber将根据PHONE_PATTERN去处理传递进来的字符串(宽字符,即UChar类型,也就是unsigned类型),得到的电话 号码被记录在FindStatePtr所指向的mStore数组中,但电话号码的第一个字符ascii吗值’1′小于‘2’(ch<patternChar)。重写一个FindPartialNumber函数如下:

/*
18612345678
+8613612345678
+86 18612345678
01012345678
010-12345678
010 12345678
+86 10 12345678
110
95533
40012345678
80012345678

*/
#define FIRSTNUMBER_PATTERN “+(“
#define DELIMITER_PATTERN ” -/”
//#define PHONENUMBER_PATTERN “+-() 0123456789″
#define MAXNUMBER 13
#define MINNUMBER 3

#define PHONE_PATTERN “(200) /-.\\ 100 -. 0000″ // poor man’s regex: parens optional, any one of punct, digit smallest allowed

#if 1
bool isFirstNumber(UChar ch)
{
if(WTF::isASCIIDigit(ch))
return true;

const char* pattern = FIRSTNUMBER_PATTERN;
char pattern_char = *pattern;
while(pattern_char != ‘\0′)
{
if(pattern_char == ch)
return true;
pattern++;
pattern_char=*pattern;
}
return false;

}

bool isDelimiter(UChar ch)
{
const char* pattern = DELIMITER_PATTERN;
char pattern_char=*pattern;
while(pattern_char != ‘\0′)
{
if(pattern_char == ch)
return true;
pattern++;
pattern_char=*pattern;
}
return false;
}

bool isValidPhoneNumber(UChar ch)
{
if(isFirstNumber(ch) || isDelimiter(ch) || ch == 41)//41 is ‘)’
return true;
return false;
}

CacheBuilder::FoundState CacheBuilder::FindPartialNumber(const UChar* chars, unsigned length,
FindState* s)
{
if(length < MINNUMBER){ DUMP_NAV_LOGD(“Length is less than %d, not to check”, MINNUMBER); return FOUND_NONE; } UChar* store = s->mStorePtr;
int count = 0;
unsigned n = 0;
UChar ch;

//const char* pattern = PHONENUMBER_PATTERN;
//char* pattern_char = *pattern;

const UChar* start = chars;
const UChar* end = chars + length;
const UChar* lastDigit = NULL;

bool flag = false;
//parse all characters from caller
do{
ch=*chars++;
if(isValidPhoneNumber(ch))
{
if(count == 0)//parse the first number
{
if(isFirstNumber(ch))//phone number begins
{
DUMP_NAV_LOGD(“First Number:%c”,ch);
flag = true;
count++;
}
else//reset: start record next time, like the character ‘)’
{
DUMP_NAV_LOGD(“the first is an invalid phone number:%c(ascii=%d)”,ch,ch);
count = 0;
flag = false;
FindResetNumber(s);
store = s->mStorePtr;
}
}

//count >= 1, record the number in FindState
if(flag)//when it is phone number
{
if(!isDelimiter(ch))
{
DUMP_NAV_LOGD(“record the valid number:%c”,ch);
*store++ = ch;
lastDigit = chars;
count++;
}
else//skip the dilimeter
{
DUMP_NAV_LOGD(“skip the dimiter:%c(ascii=%d)”,ch,ch);
}
}

if(count>MAXNUMBER)//We got number enough now and return it
{
DUMP_NAV_LOGD(“count=%d,too many numbers, more than:%d”,count,MAXNUMBER);

//more than the pre-defined number,reset
flag = false;
FindResetNumber(s);
store = s->mStorePtr;

break;
}
}else//meet an invalid charater, reset: all effort did before will disappear
{
DUMP_NAV_LOGD(“meet an invalid phone number character:%c(ascii=%d), reset”,ch,ch);
flag = false;
count = 0;
FindResetNumber(s);
store = s->mStorePtr;
}

}while (++nmStorePtr = store;
s->mEndResult = lastDigit -start +1;
return FOUND_COMPLETE;
}

DUMP_NAV_LOGD(“Not get a valid number”);
return FOUND_NONE;

}
#else
CacheBuilder::FoundState CacheBuilder::FindPartialNumber(const UChar* chars, unsigned length,
FindState* s)
{
输出的部分log如下:
10-30 19:43:53.450: D/navcache(2678): ==================================================
10-30 19:43:53.450: D/navcache(2678): to FindPartialNumber: chars=1, length=11
10-30 19:43:53.450: D/navcache(2678): print the chars:
10-30 19:43:53.450: D/navcache(2678): First Number:1
10-30 19:43:53.450: D/navcache(2678): record the valid number:1
10-30 19:43:53.450: D/navcache(2678): record the valid number:3
10-30 19:43:53.450: D/navcache(2678): record the valid number:9
10-30 19:43:53.450: D/navcache(2678): record the valid number:1
10-30 19:43:53.450: D/navcache(2678): record the valid number:2
10-30 19:43:53.450: D/navcache(2678): record the valid number:3
10-30 19:43:53.450: D/navcache(2678): record the valid number:4
10-30 19:43:53.450: D/navcache(2678): record the valid number:5
10-30 19:43:53.450: D/navcache(2678): record the valid number:6
10-30 19:43:53.450: D/navcache(2678): record the valid number:7
10-30 19:43:53.450: D/navcache(2678): record the valid number:8
10-30 19:43:53.450: D/navcache(2678): Got a valid phone number
10-30 19:43:53.450: D/navcache(2678): state=FOUND_COMPLETE
10-30 19:43:53.450: D/navcache(2678): here:
10-30 19:43:53.450: D/navcache(2678): text link found: “tel:13912345678″

这样,就可以解决中国大陆地区电话号码识别不准的问题。当点击Email正文中的电话号码时,都可以正确选中并进入到拨号盘。当然,也可以让保留原来的FindPartialNumber函数,当其返回FOUND_NONE时,再次调用上面的代码再一次进行识别判断。

 

完整的patch如下:

diff –git a/Source/WebKit/android/nav/CacheBuilder.cpp b/Source/WebKit/android/nav/CacheBuilder.cpp
index 940991f..04ce5df 100644
— a/Source/WebKit/android/nav/CacheBuilder.cpp
+++ b/Source/WebKit/android/nav/CacheBuilder.cpp
@@ -493,7 +493,7 @@ void CacheBuilder::Debug::groups() {
RenderBlock* renderBlock = static_cast<RenderBlock*>(renderer);
if (renderer->isRenderBlock() && renderBlock->hasColumns()) {
const RenderBox* box = static_cast<RenderBox*>(renderer);
- const IntRect& oRect = box->visibleOverflowRect();
+ const IntRect& oRect = box->visualOverflowRect();
snprintf(scratch, sizeof(scratch), “// renderBlock:”
” columnCount=%d columnGap=%d direction=%d”
” hasOverflowClip=%d overflow=(%d,%d,w=%d,h=%d)”,
@@ -592,7 +592,7 @@ void CacheBuilder::Debug::groups() {
0 /*textBox->spaceAdd()*/, textBox->start(), 0 /*textBox->textPos()*/);
mIndex += snprintf(&mBuffer[mIndex], mBufferSize – mIndex, “, %d, %d, %d, %d”,
textBox->x(), textBox->y(), textBox->logicalWidth(), textBox->logicalHeight());
- int baseline = textBox->renderer()->style(textBox->isFirstLineStyle())->font().ascent();
+ int baseline = textBox->renderer()->style(textBox->isFirstLineStyle())->font().fontMetrics().ascent();
mIndex += snprintf(&mBuffer[mIndex], mBufferSize – mIndex, “, %d, %d }, // %d “,
baseline, imageCount, ++rectIndex);
wideString(node->textContent().characters() + textBox->start(), textBox->len(), true);
@@ -2435,9 +2435,172 @@ nextAt:

#define PHONE_PATTERN “(200) /-.\\ 100 -. 0000″ // poor man’s regex: parens optional, any one of punct, digit smallest allowed

+
+
+/*
+Added by @BillYang_ycg on Oct 29 2012,and verified on Spreadtone board Oct 30 2012
+
+18612345678
++8613612345678
++86 18612345678
+01012345678
+010-12345678
+010 12345678
++86 10 12345678
+110
+95533
+40012345678
+80012345678
+*/
+#if 1
+#define FIRSTNUMBER_PATTERN “+(”
+#define DELIMITER_PATTERN ” -/”
+//#define PHONENUMBER_PATTERN “+-() 0123456789″
+#define MAXNUMBER 13
+#define MINNUMBER 3
+
+bool isFirstNumber(UChar ch)
+{
+ if(WTF::isASCIIDigit(ch))
+ return true;
+
+ const char* pattern = FIRSTNUMBER_PATTERN;
+ char pattern_char = *pattern;
+ while(pattern_char != ‘\0′)
+ {
+ if(pattern_char == ch)
+ return true;
+ pattern++;
+ pattern_char=*pattern;
+ }
+ return false;
+
+}
+
+bool isDelimiter(UChar ch)
+{
+ const char* pattern = DELIMITER_PATTERN;
+ char pattern_char=*pattern;
+ while(pattern_char != ‘\0′)
+ {
+ if(pattern_char == ch)
+ return true;
+ pattern++;
+ pattern_char=*pattern;
+ }
+ return false;
+}
+
+bool isValidPhoneNumber(UChar ch)
+{
+ if(isFirstNumber(ch) || isDelimiter(ch) || ch == 41)//41 is ‘)’
+ return true;
+ return false;
+}
+
CacheBuilder::FoundState CacheBuilder::FindPartialNumber(const UChar* chars, unsigned length,
FindState* s)
{
+ if(length < MINNUMBER){
+ DUMP_NAV_LOGD(“Length is less than %d, not to check”, MINNUMBER);
+ return FOUND_NONE;
+ }
+
+ UChar* store = s->mStorePtr;
+ int count = 0;
+ unsigned n = 0;
+ UChar ch;
+
+ //const char* pattern = PHONENUMBER_PATTERN;
+ //char* pattern_char = *pattern;
+
+ const UChar* start = chars;
+ const UChar* end = chars + length;
+ const UChar* lastDigit = NULL;
+
+ bool flag = false;
+ //parse all characters from caller
+ do{
+ ch=*chars++;
+ if(isValidPhoneNumber(ch))
+ {
+ if(count == 0)//parse the first number
+ {
+ if(isFirstNumber(ch))//phone number begins
+ {
+ DUMP_NAV_LOGD(“First Number:%c”,ch);
+ flag = true;
+ count++;
+ }
+ else//reset: start record next time, like the character ‘)’
+ {
+ DUMP_NAV_LOGD(“the first is an invalid phone number:%c(ascii=%d)”,ch,ch);
+ count = 0;
+ flag = false;
+ FindResetNumber(s);
+ store = s->mStorePtr;
+ }
+ }
+
+ //count >= 1, record the number in FindState
+ if(flag)//when it is phone number
+ {
+ if(!isDelimiter(ch))
+ {
+ DUMP_NAV_LOGD(“record the valid number:%c”,ch);
+ *store++ = ch;
+ lastDigit = chars;
+ count++;
+ }
+ else//skip the dilimeter
+ {
+ DUMP_NAV_LOGD(“skip the dimiter:%c(ascii=%d)”,ch,ch);
+ }
+ }
+
+ if(count>MAXNUMBER)//We got number enough now and return it
+ {
+ DUMP_NAV_LOGD(“count=%d,too many numbers, more than:%d”,count,MAXNUMBER);
+
+ //more than the pre-defined number,reset
+ flag = false;
+ FindResetNumber(s);
+ store = s->mStorePtr;
+
+ break;
+ }
+ }else//meet an invalid charater, reset: all effort did before will disappear
+ {
+ DUMP_NAV_LOGD(“meet an invalid phone number character:%c(ascii=%d), reset”,ch,ch);
+ flag = false;
+ count = 0;
+ FindResetNumber(s);
+ store = s->mStorePtr;
+ }
+
+ }while (++n<length);
+
+ if(flag)
+ {
+ DUMP_NAV_LOGD(“Got a valid phone number”);
+ *store = ‘\0′;
+ s->mStorePtr = store;
+ s->mEndResult = lastDigit -start +1;
+ return FOUND_COMPLETE;
+ }
+
+ DUMP_NAV_LOGD(“Not get a valid number”);
+ return FOUND_NONE;
+
+}
+#else
+
+CacheBuilder::FoundState CacheBuilder::FindPartialNumber(const UChar* chars, unsigned length,
+ FindState* s)
+{
+DUMP_NAV_LOGD(“Enter FindPartialNumber, handle chars=%s, length=%ld”, chars, length);
char* pattern = s->mPattern;
UChar* store = s->mStorePtr;
const UChar* start = chars;
@@ -2453,6 +2616,7 @@ CacheBuilder::FoundState CacheBuilder::FindPartialNumber(const UChar* chars, uns
UChar ch = s->mCurrent = *chars;
do {
char patternChar = *pattern;
+ DUMP_NAV_LOGD(“patternChar=%c,ch[pointer=%p]=%c”,patternChar,ch,ch);
switch (patternChar) {
case ’2′:
if (initialized == false) {
@@ -2463,6 +2627,7 @@ CacheBuilder::FoundState CacheBuilder::FindPartialNumber(const UChar* chars, uns
case ’1′:
if (ch < patternChar || ch > ’9′)
goto resetPattern;
+ DUMP_NAV_LOGD(“Record the number:%c”,ch);
*store++ = ch;
pattern++;
lastDigit = chars;
@@ -2470,8 +2635,10 @@ CacheBuilder::FoundState CacheBuilder::FindPartialNumber(const UChar* chars, uns
case ‘\0′:
if (WTF::isASCIIDigit(ch) == false) {
*store = ‘\0′;
+ DUMP_NAV_LOGD(“Meet non-digit character, to check match”);
goto checkMatch;
}
+DUMP_NAV_LOGD(“Parse PHONE_PATTERN end, to reset and check a new number”);
goto resetPattern;
case ‘ ‘:
if (ch == patternChar)
@@ -2514,10 +2681,11 @@ checkMatch:
s->mPattern = pattern;
s->mEndResult = lastDigit – start + 1;
char pState = pattern[0];
+ DUMP_NAV_LOGD(“pattern[0]=%c,pattern[-1]=%c”,pattern[0],pattern[-1]);
return pState == ‘\0′ ? FOUND_COMPLETE : pState == ‘(‘ || (WTF::isASCIIDigit(pState) && WTF::isASCIIDigit(pattern[-1])) ?
FOUND_NONE : FOUND_PARTIAL;
}
-
+#endif
CacheBuilder::FoundState CacheBuilder::FindPhoneNumber(const UChar* chars, unsigned length,
int* start, int* end)
{
diff –git a/Source/WebKit/android/nav/CachedDebug.h b/Source/WebKit/android/nav/CachedDebug.h
index f77c07a..10ea402 100644
— a/Source/WebKit/android/nav/CachedDebug.h
+++ b/Source/WebKit/android/nav/CachedDebug.h
@@ -26,9 +26,9 @@
#ifndef CachedDebug_h
#define CachedDebug_h

-#define DUMP_NAV_CACHE 0
-#define DEBUG_NAV_UI 0
-#define DEBUG_NAV_UI_VERBOSE 0
+#define DUMP_NAV_CACHE 1
+#define DEBUG_NAV_UI 1
+#define DEBUG_NAV_UI_VERBOSE 1

#if DEBUG_NAV_UI
#define DBG_NAV_LOG(message) LOGD(“%s %s”, __FUNCTION__, message)
diff –git a/Source/WebKit/android/nav/SelectText.cpp b/Source/WebKit/android/nav/SelectText.cpp
index d20c44a..6c73878 100644
— a/Source/WebKit/android/nav/SelectText.cpp
+++ b/Source/WebKit/android/nav/SelectText.cpp
@@ -1968,8 +1968,9 @@ bool SelectText::startSelection(const CachedRoot* root, const IntRect& vis,
}
m_hitTopLeft = hitStartHandle(x, y);
bool hitBottomRight = hitEndHandle(x, y);
- DBG_NAV_LOGD(“picture=(%d,%d) left=%d top=%d right=%d bottom=%d x=%d y=%d”,
- m_picture->width(), m_picture->height(),left, top, right, bottom, x, y);
+ //DBG_NAV_LOGD(“picture=(%d,%d) left=%d top=%d right=%d bottom=%d x=%d y=%d”,
+ // m_picture->width(), m_picture->height(),left, top, right, bottom, x, y);
+DBG_NAV_LOGD(“picture=(%d,%d) left=null top=null right=null bottom=null x=%d y=%d”, m_picture->width(), m_picture->height(), x, y);
if (m_hitTopLeft) {
DBG_NAV_LOG(“hit top left”);
m_original.fX -= m_selStart.fLeft;

本文链接地址: http://blog.redwolf-soft.com/?p=1791

原创文章,版权©红狼博客所有, 转载随意,但请注明出处。

    分享到:

相关文章:

  • 无相关文章
  1. 本文目前尚无任何评论.
订阅评论
  欢迎参与讨论,请在这里发表您的看法、交流您的观点。