diff options
-rw-r--r-- | WebKit/android/jni/WebViewCore.cpp | 56 | ||||
-rw-r--r-- | WebKit/android/nav/WebView.cpp | 79 |
2 files changed, 73 insertions, 62 deletions
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 6ca1e4b..eb35d44 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -1481,19 +1481,25 @@ static int findTextBoxIndex(WebCore::Node* node, const WebCore::IntPoint& pt) do { int textBoxStart = textBox->start(); int textBoxEnd = textBoxStart + textBox->len(); - if (textBoxEnd <= textBoxStart) + if (textBoxEnd <= textBoxStart) { + DBG_NAV_LOGD("textBoxStart=%d <= textBoxEnd=%d", textBoxStart, + textBoxEnd); continue; + } WebCore::IntRect bounds = textBox->selectionRect(absPt.x(), absPt.y(), textBoxStart, textBoxEnd); - if (!bounds.contains(x, y)) + if (!bounds.contains(x, y)) { + DBG_NAV_LOGD("[absPt=(%g,%g) textBoxStart=%d textBoxEnd=%d]" + " !contains (x=%d, y=%d)", + absPt.x(), absPt.y(), textBoxStart, textBoxEnd, x, y); continue; + } int offset = textBox->offsetForPosition(x - absPt.x()); #if DEBUG_NAV_UI int prior = offset > 0 ? textBox->positionForOffset(offset - 1) : -1; int current = textBox->positionForOffset(offset); int next = textBox->positionForOffset(offset + 1); - DBG_NAV_LOGD( - "offset=%d pt.x=%d globalX=%d renderX=%d x=%d " + DBG_NAV_LOGD("offset=%d pt.x=%d globalX=%d renderX=%g x=%d " "textBox->x()=%d textBox->start()=%d prior=%d current=%d next=%d", offset, pt.x(), globalX, absPt.x(), x, textBox->x(), textBox->start(), prior, current, next @@ -1527,6 +1533,38 @@ static int centerY(const SkIRect& rect) return (rect.fTop + rect.fBottom) >> 1; } +static void ShowNode(Node* node) +{ +#if DEBUG_NAV_UI + WebCore::Node* match = node->document(); + int index = 1; + while (match != node && (match = match->traverseNextNode())) + index++; + if (match != node) + index = -1; + const char* name = "text"; + WebCore::CString cstr; + if (!node->isTextNode()) { + cstr = node->localName().string().utf8(); + name = cstr.data(); + } + node->getRect(); + const WebCore::IntRect& b = node->getRect(); + DBG_NAV_LOGD("%s %p (%d) (%d,%d,w=%d,h=%d)", name, node, index, + b.x(), b.y(), b.width(), b.height()); +#endif +} + +static WebCore::Node* ChildIsTextNode(WebCore::Node* node) +{ + WebCore::Node* child = node; + while (child && !child->isTextNode()) { + ShowNode(child); + child = child->traverseNextNode(node); + } + return child; +} + WebCore::String WebViewCore::getSelection(SkRegion* selRgn) { SkRegion::Iterator iter(*selRgn); @@ -1542,14 +1580,14 @@ WebCore::String WebViewCore::getSelection(SkRegion* selRgn) int cy = centerY(rect); WebCore::IntPoint startPt, endPt; WebCore::Node* node, * endNode; - for (int top = rect.fTop + 1; top != cy; top = cy) { + for (int top = rect.fTop + 2; top != cy; top = cy) { startPt = WebCore::IntPoint(rect.fLeft + 1, top); WebCore::HitTestResult hitTestResult = m_mainFrame->eventHandler()-> hitTestResultAtPoint(startPt, false); - node = hitTestResult.innerNode(); + node = ChildIsTextNode(hitTestResult.innerNode()); if (node) break; - DBG_NAV_LOGD("!node (%s)", top != cy ? "top+1" : "cy"); + DBG_NAV_LOGD("node=%p (%s)", node, top != cy ? "top+1" : "cy"); } if (!node) { DBG_NAV_LOG("!node"); @@ -1560,10 +1598,10 @@ WebCore::String WebViewCore::getSelection(SkRegion* selRgn) endPt = WebCore::IntPoint(right, bottom); WebCore::HitTestResult hitTestResult = m_mainFrame-> eventHandler()->hitTestResultAtPoint(endPt, false); - endNode = hitTestResult.innerNode(); + endNode = ChildIsTextNode(hitTestResult.innerNode()); if (endNode) break; - DBG_NAV_LOGD("!endNode (%s) (right-%d)", + DBG_NAV_LOGD("!endNode=%p (%s) (right-%d)", node, bottom != cy ? "bottom-1" : "cy", rect.fRight - right); } } diff --git a/WebKit/android/nav/WebView.cpp b/WebKit/android/nav/WebView.cpp index 8fff1b9..20e8a70 100644 --- a/WebKit/android/nav/WebView.cpp +++ b/WebKit/android/nav/WebView.cpp @@ -1104,17 +1104,6 @@ const SkRegion& getSelection() return m_selRegion; } -void drawSelection(SkCanvas* canvas, float scale, int offset, int x, int y, - bool extendSelection) -{ - if (!extendSelection) { - drawSelectionArrow(canvas, scale, x, y - offset); - } else { - drawSelectionRegion(canvas); - drawSelectionPointer(canvas, scale, offset, x, y, false); - } -} - void drawSelectionRegion(SkCanvas* canvas) { CachedRoot* root = getFrameCache(DontAllowNewer); @@ -1134,46 +1123,31 @@ void drawSelectionRegion(SkCanvas* canvas) canvas->drawPath(path, paint); } -void drawSelectionPointer(SkCanvas* canvas, float scale, int offset, - int x, int y, bool gridded) +void drawSelectionPointer(SkCanvas* canvas, float scale, int x, int y, bool ex) { SkPath path; - getSelectionCaret(&path); + if (ex) + getSelectionCaret(&path); + else + getSelectionArrow(&path); SkPaint paint; paint.setAntiAlias(true); paint.setStyle(SkPaint::kStroke_Style); paint.setColor(SK_ColorBLACK); SkPixelXorXfermode xorMode(SK_ColorWHITE); - paint.setXfermode(&xorMode); - int sc = canvas->save(); - canvas->scale(scale, scale); - canvas->translate(0, -SkIntToScalar(offset)); - if (gridded) { - bool useLeft = x <= (m_selStart.fLeft + m_selStart.fRight) >> 1; - canvas->translate(SkIntToScalar(useLeft ? m_selStart.fLeft : - m_selStart.fRight), SkIntToScalar(m_selStart.fTop)); - } else - canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); - canvas->drawPath(path, paint); - canvas->restoreToCount(sc); -} - -void drawSelectionArrow(SkCanvas* canvas, float scale, int x, int y) -{ - SkPath path; - getSelectionArrow(&path); - SkPaint paint; - paint.setAntiAlias(true); - paint.setStyle(SkPaint::kStroke_Style); - paint.setColor(SK_ColorBLACK); - paint.setStrokeWidth(SK_Scalar1 * 2); + if (ex) + paint.setXfermode(&xorMode); + else + paint.setStrokeWidth(SK_Scalar1 * 2); int sc = canvas->save(); canvas->scale(scale, scale); canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); canvas->drawPath(path, paint); - paint.setStyle(SkPaint::kFill_Style); - paint.setColor(SK_ColorWHITE); - canvas->drawPath(path, paint); + if (!ex) { + paint.setStyle(SkPaint::kFill_Style); + paint.setColor(SK_ColorWHITE); + canvas->drawPath(path, paint); + } canvas->restoreToCount(sc); } @@ -1191,14 +1165,13 @@ void getSelectionCaret(SkPath* path) { SkScalar height = SkIntToScalar(m_selStart.fBottom - m_selStart.fTop); SkScalar dist = height / 4; - path->lineTo(0, height); - SkScalar bottom = height + dist; - path->lineTo(-dist, bottom); - SkScalar edge = bottom - SK_Scalar1/2; - path->moveTo(-dist, edge); - path->lineTo(dist, edge); - path->moveTo(dist, bottom); - path->lineTo(0, height); + path->moveTo(0, -height / 2); + path->rLineTo(0, height); + path->rLineTo(-dist, dist); + path->rMoveTo(0, -SK_Scalar1/2); + path->rLineTo(dist * 2, 0); + path->rMoveTo(0, SK_Scalar1/2); + path->rLineTo(-dist, -dist); } void sendMoveMouse(WebCore::Frame* framePtr, WebCore::Node* nodePtr, int x, int y) @@ -1626,8 +1599,8 @@ static void nativeDrawCursorRing(JNIEnv *env, jobject obj, jobject canv) view->drawCursorRing(canvas); } -static void nativeDrawSelection(JNIEnv *env, jobject obj, - jobject canv, jfloat scale, jint offset, jint x, jint y, bool ex) +static void nativeDrawSelectionPointer(JNIEnv *env, jobject obj, + jobject canv, jfloat scale, jint x, jint y, bool ex) { SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, canv); if (!canv) { @@ -1639,7 +1612,7 @@ static void nativeDrawSelection(JNIEnv *env, jobject obj, DBG_NAV_LOG("!view"); return; } - view->drawSelection(canvas, scale, offset, x, y, ex); + view->drawSelectionPointer(canvas, scale, x, y, ex); } static void nativeDrawSelectionRegion(JNIEnv *env, jobject obj, jobject canv) @@ -2122,8 +2095,8 @@ static JNINativeMethod gJavaWebViewMethods[] = { (void*) nativeDrawCursorRing }, { "nativeDrawMatches", "(Landroid/graphics/Canvas;)V", (void*) nativeDrawMatches }, - { "nativeDrawSelection", "(Landroid/graphics/Canvas;FIIIZ)V", - (void*) nativeDrawSelection }, + { "nativeDrawSelectionPointer", "(Landroid/graphics/Canvas;FIIZ)V", + (void*) nativeDrawSelectionPointer }, { "nativeDrawSelectionRegion", "(Landroid/graphics/Canvas;)V", (void*) nativeDrawSelectionRegion }, { "nativeDumpDisplayTree", "(Ljava/lang/String;)V", |