Commit 7ca6273c authored by christiank@opera.com's avatar christiank@opera.com

Update touch selection to only modify one selection point at a time.

This is made in preparation for enabling selection auto scroll using touch
handles.

BUG=340658

Review URL: https://codereview.chromium.org/653383002

git-svn-id: svn://svn.chromium.org/blink/trunk@184179 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 2aad83ba
...@@ -1160,6 +1160,22 @@ void WebLocalFrameImpl::selectRange(const WebRange& webRange) ...@@ -1160,6 +1160,22 @@ void WebLocalFrameImpl::selectRange(const WebRange& webRange)
frame()->selection().setSelectedRange(range.get(), VP_DEFAULT_AFFINITY, FrameSelection::NonDirectional, NotUserTriggered); frame()->selection().setSelectedRange(range.get(), VP_DEFAULT_AFFINITY, FrameSelection::NonDirectional, NotUserTriggered);
} }
void WebLocalFrameImpl::moveRangeSelectionExtent(const WebPoint& point)
{
VisibleSelection currentSelection = frame()->selection().selection();
VisiblePosition basePosition = currentSelection.isBaseFirst() ?
currentSelection.visibleStart() : currentSelection.visibleEnd();
VisiblePosition extentPosition = visiblePositionForWindowPoint(point);
// Prevent the selection from collapsing.
if (comparePositions(basePosition, extentPosition) == 0)
return;
VisibleSelection newSelection = VisibleSelection(basePosition, extentPosition);
frame()->selection().setSelection(newSelection, CharacterGranularity);
}
void WebLocalFrameImpl::moveRangeSelection(const WebPoint& base, const WebPoint& extent) void WebLocalFrameImpl::moveRangeSelection(const WebPoint& base, const WebPoint& extent)
{ {
VisiblePosition basePosition = visiblePositionForWindowPoint(base); VisiblePosition basePosition = visiblePositionForWindowPoint(base);
......
...@@ -161,6 +161,7 @@ public: ...@@ -161,6 +161,7 @@ public:
virtual bool selectWordAroundCaret() override; virtual bool selectWordAroundCaret() override;
virtual void selectRange(const WebPoint& base, const WebPoint& extent) override; virtual void selectRange(const WebPoint& base, const WebPoint& extent) override;
virtual void selectRange(const WebRange&) override; virtual void selectRange(const WebRange&) override;
virtual void moveRangeSelectionExtent(const WebPoint&) override;
virtual void moveRangeSelection(const WebPoint& base, const WebPoint& extent) override; virtual void moveRangeSelection(const WebPoint& base, const WebPoint& extent) override;
virtual void moveCaretSelection(const WebPoint&) override; virtual void moveCaretSelection(const WebPoint&) override;
virtual bool setEditableSelectionOffsets(int start, int end) override; virtual bool setEditableSelectionOffsets(int start, int end) override;
......
...@@ -4100,6 +4100,65 @@ TEST_F(WebFrameTest, SelectRangeCanMoveSelectionEnd) ...@@ -4100,6 +4100,65 @@ TEST_F(WebFrameTest, SelectRangeCanMoveSelectionEnd)
// EXPECT_EQ("Editable 1. Editable 2. ]", selectionAsString(frame)); // EXPECT_EQ("Editable 1. Editable 2. ]", selectionAsString(frame));
} }
TEST_F(WebFrameTest, MoveRangeSelectionExtent)
{
WebLocalFrameImpl* frame;
WebRect startWebRect;
WebRect endWebRect;
registerMockedHttpURLLoad("move_range_selection_extent.html");
FrameTestHelpers::WebViewHelper webViewHelper;
initializeTextSelectionWebView(m_baseURL + "move_range_selection_extent.html", &webViewHelper);
frame = toWebLocalFrameImpl(webViewHelper.webView()->mainFrame());
EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
frame->moveRangeSelectionExtent(WebPoint(640, 480));
EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsString(frame));
frame->moveRangeSelectionExtent(WebPoint(0, 0));
EXPECT_EQ("16-char header. ", selectionAsString(frame));
// Reset with swapped base and extent.
frame->selectRange(topLeft(endWebRect), bottomRightMinusOne(startWebRect));
EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
frame->moveRangeSelectionExtent(WebPoint(640, 480));
EXPECT_EQ(" 16-char footer.", selectionAsString(frame));
frame->moveRangeSelectionExtent(WebPoint(0, 0));
EXPECT_EQ("16-char header. This text is initially selected.", selectionAsString(frame));
frame->executeCommand(WebString::fromUTF8("Unselect"));
EXPECT_EQ("", selectionAsString(frame));
}
TEST_F(WebFrameTest, MoveRangeSelectionExtentCannotCollapse)
{
WebLocalFrameImpl* frame;
WebRect startWebRect;
WebRect endWebRect;
registerMockedHttpURLLoad("move_range_selection_extent.html");
FrameTestHelpers::WebViewHelper webViewHelper;
initializeTextSelectionWebView(m_baseURL + "move_range_selection_extent.html", &webViewHelper);
frame = toWebLocalFrameImpl(webViewHelper.webView()->mainFrame());
EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
webViewHelper.webView()->selectionBounds(startWebRect, endWebRect);
frame->moveRangeSelectionExtent(bottomRightMinusOne(startWebRect));
EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
// Reset with swapped base and extent.
frame->selectRange(topLeft(endWebRect), bottomRightMinusOne(startWebRect));
EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
frame->moveRangeSelectionExtent(bottomRightMinusOne(endWebRect));
EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
}
static int computeOffset(RenderObject* renderer, int x, int y) static int computeOffset(RenderObject* renderer, int x, int y)
{ {
return VisiblePosition(renderer->positionForPoint(LayoutPoint(x, y))).deepEquivalent().computeOffsetInContainerNode(); return VisiblePosition(renderer->positionForPoint(LayoutPoint(x, y))).deepEquivalent().computeOffsetInContainerNode();
......
<!DOCTYPE html>
<html id='root'>
<body>
<span id='target'>16-char header. This text is initially selected. 16-char footer.</span>
<script>
function select() {
var text = document.getElementById('target').firstChild;
var range = document.createRange();
range.setStart(text, 16);
range.setEnd(text, 48);
window.getSelection().addRange(range);
}
window.onload = select;
</script>
</body>
</html>
...@@ -74,6 +74,14 @@ public: ...@@ -74,6 +74,14 @@ public:
// Associates an isolated world with human-readable name which is useful for // Associates an isolated world with human-readable name which is useful for
// extension debugging. // extension debugging.
virtual void setIsolatedWorldHumanReadableName(int worldID, const WebString&) = 0; virtual void setIsolatedWorldHumanReadableName(int worldID, const WebString&) = 0;
// Selection --------------------------------------------------------------
// Moves the selection extent point. This function does not allow the
// selection to collapse. If the new extent is set to the same position as
// the current base, this function will do nothing.
virtual void moveRangeSelectionExtent(const WebPoint&) = 0;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment