diff options
author | George Mount <mount@google.com> | 2012-03-21 10:29:19 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-03-21 10:29:19 -0700 |
commit | 26496e790276f8dfe693d2b011c8b34c643317cb (patch) | |
tree | d19e8126beb3019f37dbca2e27e8353fa995106c /Source | |
parent | 1acf6173ad2e607642c57cf7572354df1f2f3fa8 (diff) | |
parent | 389aa1b64f2d8adcd29c3299090aa698ab15641a (diff) | |
download | external_webkit-26496e790276f8dfe693d2b011c8b34c643317cb.zip external_webkit-26496e790276f8dfe693d2b011c8b34c643317cb.tar.gz external_webkit-26496e790276f8dfe693d2b011c8b34c643317cb.tar.bz2 |
Merge "Make paste window and caret handle show up at the right time."
Diffstat (limited to 'Source')
-rw-r--r-- | Source/WebKit/android/jni/WebViewCore.cpp | 30 | ||||
-rw-r--r-- | Source/WebKit/android/jni/WebViewCore.h | 4 |
2 files changed, 20 insertions, 14 deletions
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp index d1d8c84..f323838 100644 --- a/Source/WebKit/android/jni/WebViewCore.cpp +++ b/Source/WebKit/android/jni/WebViewCore.cpp @@ -1484,7 +1484,7 @@ VisiblePosition WebViewCore::visiblePositionForContentPoint(const IntPoint& poin return node->renderer()->positionForPoint(result.localPoint()); } -void WebViewCore::selectWordAt(int x, int y) +bool WebViewCore::selectWordAt(int x, int y) { HitTestResult hoverResult; moveMouse(x, y, &hoverResult); @@ -1506,25 +1506,29 @@ void WebViewCore::selectWordAt(int x, int y) // Matching the logic in MouseEventWithHitTestResults::targetNode() Node* node = result.innerNode(); if (!node) - return; + return false; Element* element = node->parentElement(); if (!node->inDocument() && element && element->inDocument()) node = element; SelectionController* sc = focusedFrame()->selection(); + bool wordSelected = false; if (!sc->contains(point) && (node->isContentEditable() || node->isTextNode()) && !result.isLiveLink() && node->dispatchEvent(Event::create(eventNames().selectstartEvent, true, true))) { VisiblePosition pos(node->renderer()->positionForPoint(result.localPoint())); - selectWordAroundPosition(node->document()->frame(), pos); + wordSelected = selectWordAroundPosition(node->document()->frame(), pos); } + return wordSelected; } -void WebViewCore::selectWordAroundPosition(Frame* frame, VisiblePosition pos) +bool WebViewCore::selectWordAroundPosition(Frame* frame, VisiblePosition pos) { VisibleSelection selection(pos); selection.expandUsingGranularity(WordGranularity); + SelectionController* selectionController = frame->selection(); - if (frame->selection()->shouldChangeSelection(selection)) { + bool wordSelected = false; + if (selectionController->shouldChangeSelection(selection)) { bool allWhitespaces = true; RefPtr<Range> firstRange = selection.firstRange(); String text = firstRange.get() ? firstRange->text() : ""; @@ -1534,13 +1538,15 @@ void WebViewCore::selectWordAroundPosition(Frame* frame, VisiblePosition pos) break; } } - if (allWhitespaces) { - VisibleSelection emptySelection(selection.visibleStart(), selection.visibleStart()); - frame->selection()->setSelection(emptySelection); + VisibleSelection emptySelection(pos); + selectionController->setSelection(emptySelection); + } else { + selectionController->setSelection(selection); + wordSelected = true; } - frame->selection()->setSelection(selection); } + return wordSelected; } int WebViewCore::platformLayerIdFromNode(Node* node, LayerAndroid** outLayer) @@ -4985,10 +4991,10 @@ static void ClearSelection(JNIEnv* env, jobject obj, jint nativeClass) viewImpl->focusedFrame()->selection()->clear(); } -static void SelectWordAt(JNIEnv* env, jobject obj, jint nativeClass, jint x, jint y) +static bool SelectWordAt(JNIEnv* env, jobject obj, jint nativeClass, jint x, jint y) { WebViewCore* viewImpl = reinterpret_cast<WebViewCore*>(nativeClass); - viewImpl->selectWordAt(x, y); + return viewImpl->selectWordAt(x, y); } static void SelectAll(JNIEnv* env, jobject obj, jint nativeClass) @@ -5124,7 +5130,7 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = { (void*) SelectText }, { "nativeClearTextSelection", "(I)V", (void*) ClearSelection }, - { "nativeSelectWordAt", "(III)V", + { "nativeSelectWordAt", "(III)Z", (void*) SelectWordAt }, { "nativeSelectAll", "(I)V", (void*) SelectAll }, diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h index 6850111..479f549 100644 --- a/Source/WebKit/android/jni/WebViewCore.h +++ b/Source/WebKit/android/jni/WebViewCore.h @@ -602,7 +602,7 @@ namespace android { int startX, int startY, int endX, int endY); static int platformLayerIdFromNode(Node* node, LayerAndroid** outLayer = 0); void selectText(int startX, int startY, int endX, int endY); - void selectWordAt(int x, int y); + bool selectWordAt(int x, int y); // Converts from the global content coordinates that WebView sends // to frame-local content coordinates using the focused frame @@ -732,7 +732,7 @@ namespace android { VisiblePosition visiblePositionForContentPoint(int x, int y); VisiblePosition visiblePositionForContentPoint(const IntPoint& point); - void selectWordAroundPosition(Frame* frame, VisiblePosition pos); + bool selectWordAroundPosition(Frame* frame, VisiblePosition pos); SelectText* createSelectText(const VisibleSelection&); static int getMaxLength(Node* node); static String getFieldName(Node* node); |