summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2012-06-01 14:26:57 -0700
committerGeorge Mount <mount@google.com>2012-06-01 14:30:09 -0700
commit2d66db6bf0f6f3687361cce7d9280de47ed591ee (patch)
tree6923caafd73ce6d7441cedf416316090d8d6d22b
parentbe480525e35fed411698c2a58200b5d010f5ecde (diff)
downloadexternal_webkit-2d66db6bf0f6f3687361cce7d9280de47ed591ee.zip
external_webkit-2d66db6bf0f6f3687361cce7d9280de47ed591ee.tar.gz
external_webkit-2d66db6bf0f6f3687361cce7d9280de47ed591ee.tar.bz2
Change from left/right to base/extent for selection handles.
Bug 6557816 This is a step in preparation to fix text area selection. It moves selection from left/right to base/extent. left/right can cause problems when dragging cursors -- it is sometimes difficult to tell which cursor should be dragged, the left or right, but we can always keep the base/extent constant. Framework Change: I2f9b963e93bb1ab86a9b26518fca52449b56d5d9 Change-Id: I5609d07ea2ee67fc08d15cfcad31f49302f33297
-rw-r--r--Source/WebKit/android/jni/WebViewCore.cpp53
-rw-r--r--Source/WebKit/android/jni/WebViewCore.h4
-rw-r--r--Source/WebKit/android/nav/SelectText.h10
-rw-r--r--Source/WebKit/android/nav/WebView.cpp18
4 files changed, 62 insertions, 23 deletions
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp
index 161c0b2..922ea2f 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)