diff options
author | George Mount <mount@google.com> | 2012-06-04 14:48:08 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-06-04 14:48:08 -0700 |
commit | dcf207c3db53858c06cf054f06721370eba23c77 (patch) | |
tree | f2865279b10c584e341166bd10867fcd9d3f1429 /Source | |
parent | 694d4b356b21c9d78cf5ba3ce101b0a76a23f859 (diff) | |
parent | 2d66db6bf0f6f3687361cce7d9280de47ed591ee (diff) | |
download | external_webkit-dcf207c3db53858c06cf054f06721370eba23c77.zip external_webkit-dcf207c3db53858c06cf054f06721370eba23c77.tar.gz external_webkit-dcf207c3db53858c06cf054f06721370eba23c77.tar.bz2 |
Merge "Change from left/right to base/extent for selection handles."
Diffstat (limited to 'Source')
-rw-r--r-- | Source/WebKit/android/jni/WebViewCore.cpp | 53 | ||||
-rw-r--r-- | Source/WebKit/android/jni/WebViewCore.h | 4 | ||||
-rw-r--r-- | Source/WebKit/android/nav/SelectText.h | 10 | ||||
-rw-r--r-- | Source/WebKit/android/nav/WebView.cpp | 18 |
4 files changed, 62 insertions, 23 deletions
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp index 90a71e2..0ef1609 100644 --- a/Source/WebKit/android/jni/WebViewCore.cpp +++ b/Source/WebKit/android/jni/WebViewCore.cpp @@ -1507,6 +1507,7 @@ bool WebViewCore::selectWordAroundPosition(Frame* frame, VisiblePosition pos) VisibleSelection selection(pos); selection.expandUsingGranularity(WordGranularity); SelectionController* selectionController = frame->selection(); + selection = VisibleSelection(selection.start(), selection.end()); bool wordSelected = false; if (selectionController->shouldChangeSelection(selection)) { @@ -1566,7 +1567,8 @@ void WebViewCore::layerToAbsoluteOffset(const LayerAndroid* layer, IntPoint& off void WebViewCore::setSelectionCaretInfo(SelectText* selectTextContainer, const WebCore::Position& pos, const IntPoint& frameOffset, - SelectText::HandleId handleId, int caretRectOffset, EAffinity affinity) + SelectText::HandleId handleId, SelectText::HandleType handleType, + int caretRectOffset, EAffinity affinity) { Node* node = pos.anchorNode(); LayerAndroid* layer = 0; @@ -1584,6 +1586,7 @@ void WebViewCore::setSelectionCaretInfo(SelectText* selectTextContainer, caretRect.setX(absoluteOffset.x() - offset.x() + caretRectOffset); caretRect.setY(absoluteOffset.y() - offset.y()); selectTextContainer->setCaretRect(handleId, caretRect); + selectTextContainer->setHandleType(handleId, handleType); selectTextContainer->setTextRect(handleId, positionToTextRect(pos, affinity, offset)); } @@ -1604,11 +1607,11 @@ bool WebViewCore::isLtr(const Position& position) SelectText* WebViewCore::createSelectText(const VisibleSelection& selection) { bool isCaret = selection.isCaret(); + Position base = selection.base(); + Position extent = selection.extent(); if (selection.isNone() || (!selection.isContentEditable() && isCaret) - || !selection.start().anchorNode() - || !selection.start().anchorNode()->renderer() - || !selection.end().anchorNode() - || !selection.end().anchorNode()->renderer()) + || !base.anchorNode() || !base.anchorNode()->renderer() + || !extent.anchorNode() || !extent.anchorNode()->renderer()) return 0; RefPtr<Range> range = selection.firstRange(); @@ -1624,20 +1627,27 @@ SelectText* WebViewCore::createSelectText(const VisibleSelection& selection) IntPoint frameOffset = convertGlobalContentToFrameContent(IntPoint()); SelectText* selectTextContainer = new SelectText(); if (isCaret) { - setSelectionCaretInfo(selectTextContainer, selection.start(), frameOffset, - SelectText::LeftHandle, 0, selection.affinity()); - setSelectionCaretInfo(selectTextContainer, selection.start(), frameOffset, - SelectText::RightHandle, 0, selection.affinity()); + setSelectionCaretInfo(selectTextContainer, base, frameOffset, + SelectText::BaseHandle, SelectText::CenterHandle, 0, + selection.affinity()); + setSelectionCaretInfo(selectTextContainer, base, frameOffset, + SelectText::ExtentHandle, SelectText::CenterHandle, 0, + selection.affinity()); } else { - bool ltr = isLtr(selection.start()); - Position left = ltr ? selection.start() : selection.end(); - Position right = ltr ? selection.end() : selection.start(); - int leftOffset = isLtr(left) ? 0 : -1; - int rightOffset = isLtr(right) ? 0 : -1; - setSelectionCaretInfo(selectTextContainer, left, frameOffset, - SelectText::LeftHandle, leftOffset, selection.affinity()); - setSelectionCaretInfo(selectTextContainer, right, frameOffset, - SelectText::RightHandle, rightOffset, selection.affinity()); + bool isBaseLtr = isLtr(base); + bool isBaseStart = selection.base() == selection.start(); + int baseOffset = isBaseLtr ? 0 : -1; + SelectText::HandleType baseHandleType = (isBaseLtr == isBaseStart) + ? SelectText::LeftHandle : SelectText::RightHandle; + EAffinity affinity = selection.affinity(); + setSelectionCaretInfo(selectTextContainer, base, frameOffset, + SelectText::BaseHandle, baseHandleType, baseOffset, affinity); + bool isExtentLtr = isLtr(extent); + int extentOffset = isExtentLtr ? 0 : -1; + SelectText::HandleType extentHandleType = (isExtentLtr == isBaseStart) + ? SelectText::RightHandle : SelectText::LeftHandle; + setSelectionCaretInfo(selectTextContainer, extent, frameOffset, + SelectText::ExtentHandle, extentHandleType, extentOffset, affinity); Node* stopNode = range->pastLastNode(); for (Node* node = range->firstNode(); node != stopNode; node = node->traverseNextNode()) { @@ -1738,7 +1748,8 @@ void WebViewCore::selectText(int startX, int startY, int endX, int endY) return; // Ensure startPosition is before endPosition - if (comparePositions(startPosition, endPosition) > 0) + bool swapPositions = (comparePositions(startPosition, endPosition) > 0); + if (swapPositions) swap(startPosition, endPosition); if (sc->isContentEditable()) { @@ -1766,7 +1777,9 @@ void WebViewCore::selectText(int startX, int startY, int endX, int endY) Position end = endPosition.deepEquivalent(); start = trimSelectionPosition(start, end); end = trimSelectionPosition(end, start); - VisibleSelection selection(start, end); + Position& base = swapPositions ? end : start; + Position& extent = swapPositions ? start : end; + VisibleSelection selection(base, extent); // Only allow changes between caret positions or to text selection. bool selectChangeAllowed = (!selection.isCaret() || sc->isCaret()); if (selectChangeAllowed && sc->shouldChangeSelection(selection)) diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h index 7cc3fd6..ac0f92c 100644 --- a/Source/WebKit/android/jni/WebViewCore.h +++ b/Source/WebKit/android/jni/WebViewCore.h @@ -728,8 +728,8 @@ namespace android { void setSelectionCaretInfo(SelectText* selectTextContainer, const WebCore::Position& position, const WebCore::IntPoint& frameOffset, - SelectText::HandleId handleId, int offset, - EAffinity affinity); + SelectText::HandleId handleId, SelectText::HandleType handleType, + int offset, EAffinity affinity); static int getMaxLength(WebCore::Node* node); static WTF::String getFieldName(WebCore::Node* node); static bool isAutoCompleteEnabled(WebCore::Node* node); diff --git a/Source/WebKit/android/nav/SelectText.h b/Source/WebKit/android/nav/SelectText.h index aaaf3bb..8f7592d 100644 --- a/Source/WebKit/android/nav/SelectText.h +++ b/Source/WebKit/android/nav/SelectText.h @@ -35,8 +35,13 @@ namespace android { class SelectText : public RegionLayerDrawExtra { public: enum HandleId { + BaseHandle = 0, + ExtentHandle = 1, + }; + enum HandleType { LeftHandle = 0, - RightHandle = 1, + CenterHandle = 1, + RightHandle = 2, }; IntRect& caretRect(HandleId id) { return m_caretRects[id]; } @@ -48,11 +53,14 @@ public: void setText(const String& text) { m_text = text.threadsafeCopy(); } String& getText() { return m_text; } + HandleType getHandleType(HandleId id) { return m_handleType[id]; } + void setHandleType(HandleId id, HandleType type) { m_handleType[id] = type; } private: IntRect m_caretRects[2]; IntRect m_textRects[2]; int m_caretLayerId[2]; + HandleType m_handleType[2]; String m_text; }; diff --git a/Source/WebKit/android/nav/WebView.cpp b/Source/WebKit/android/nav/WebView.cpp index a277fc3..fae566c 100644 --- a/Source/WebKit/android/nav/WebView.cpp +++ b/Source/WebKit/android/nav/WebView.cpp @@ -731,6 +731,15 @@ void findMaxVisibleRect(int movingLayerId, SkIRect& visibleContentRect) } } +bool isHandleLeft(SelectText::HandleId handleId) +{ + SelectText* selectText = static_cast<SelectText*>(getDrawExtra(DrawExtrasSelection)); + if (!selectText) + return (handleId == SelectText::BaseHandle); + + return (selectText->getHandleType(handleId) == SelectText::LeftHandle); +} + private: // local state for WebView bool m_isDrawingPaused; // private to getFrameCache(); other functions operate in a different thread @@ -1287,6 +1296,13 @@ static void nativeFindMaxVisibleRect(JNIEnv *env, jobject obj, jint nativeView, GraphicsJNI::irect_to_jrect(nativeRect, env, visibleContentRect); } +static bool nativeIsHandleLeft(JNIEnv *env, jobject obj, jint nativeView, + jint handleId) +{ + WebView* webview = reinterpret_cast<WebView*>(nativeView); + return webview->isHandleLeft(static_cast<SelectText::HandleId>(handleId)); +} + /* * JNI registration */ @@ -1365,6 +1381,8 @@ static JNINativeMethod gJavaWebViewMethods[] = { (void*) nativeSetHwAccelerated }, { "nativeFindMaxVisibleRect", "(IILandroid/graphics/Rect;)V", (void*) nativeFindMaxVisibleRect }, + { "nativeIsHandleLeft", "(II)Z", + (void*) nativeIsHandleLeft }, }; int registerWebView(JNIEnv* env) |