Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp (128902 => 128903)
--- trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp 2012-09-18 16:51:26 UTC (rev 128902)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp 2012-09-18 17:23:37 UTC (rev 128903)
@@ -1466,71 +1466,15 @@
return true;
}
-void WebFrameImpl::selectRange(const WebPoint& start, const WebPoint& end)
+void WebFrameImpl::selectRange(const WebPoint& base, const WebPoint& extent)
{
- if (start == end && moveCaret(start))
- return;
-
- if (moveSelectionStart(start, true) && moveSelectionEnd(end, true))
- return;
-
- // Failed to move endpoints, probably because there's no current selection.
- // Just set the selection explicitly (but this won't handle editable boundaries correctly).
- VisibleSelection newSelection(visiblePositionForWindowPoint(start), visiblePositionForWindowPoint(end));
+ VisiblePosition basePos = visiblePositionForWindowPoint(base);
+ VisiblePosition extentPos = visiblePositionForWindowPoint(extent);
+ VisibleSelection newSelection = VisibleSelection(basePos, extentPos);
if (frame()->selection()->shouldChangeSelection(newSelection))
frame()->selection()->setSelection(newSelection, CharacterGranularity);
}
-bool WebFrameImpl::moveSelectionStart(const WebPoint& point, bool allowCollapsedSelection)
-{
- const VisibleSelection& selection = frame()->selection()->selection();
- if (selection.isNone())
- return false;
-
- VisiblePosition start = visiblePositionForWindowPoint(point);
- if (!allowCollapsedSelection) {
- VisiblePosition maxStart = selection.visibleEnd().previous();
- if (comparePositions(start, maxStart) > 0)
- start = maxStart;
- }
-
- // start is moving, so base=end, extent=start
- VisibleSelection newSelection = VisibleSelection(selection.visibleEnd(), start);
- frame()->selection()->setNonDirectionalSelectionIfNeeded(newSelection, CharacterGranularity);
- return true;
-}
-
-bool WebFrameImpl::moveSelectionEnd(const WebPoint& point, bool allowCollapsedSelection)
-{
- const VisibleSelection& selection = frame()->selection()->selection();
- if (selection.isNone())
- return false;
-
- VisiblePosition end = visiblePositionForWindowPoint(point);
- if (!allowCollapsedSelection) {
- VisiblePosition minEnd = selection.visibleStart().next();
- if (comparePositions(end, minEnd) < 0)
- end = minEnd;
- }
-
- // end is moving, so base=start, extent=end
- VisibleSelection newSelection = VisibleSelection(selection.visibleStart(), end);
- frame()->selection()->setNonDirectionalSelectionIfNeeded(newSelection, CharacterGranularity);
- return true;
-}
-
-bool WebFrameImpl::moveCaret(const WebPoint& point)
-{
- FrameSelection* frameSelection = frame()->selection();
- if (frameSelection->isNone() || !frameSelection->isContentEditable())
- return false;
-
- VisiblePosition pos = visiblePositionForWindowPoint(point);
- frameSelection->setExtent(pos, UserTriggered);
- frameSelection->setBase(frameSelection->extent(), UserTriggered);
- return true;
-}
-
void WebFrameImpl::selectRange(const WebRange& webRange)
{
RefPtr<Range> range = static_cast<PassRefPtr<Range> >(webRange);
Modified: trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp (128902 => 128903)
--- trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp 2012-09-18 16:51:26 UTC (rev 128902)
+++ trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp 2012-09-18 17:23:37 UTC (rev 128903)
@@ -1072,7 +1072,7 @@
frame = webView->mainFrame();
EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
webView->selectionBounds(startWebRect, endWebRect);
- frame->selectRange(WebPoint(0, 0), bottomRightMinusOne(endWebRect));
+ frame->selectRange(bottomRightMinusOne(endWebRect), WebPoint(0, 0));
EXPECT_EQ("16-char header. This text is initially selected.", selectionAsString(frame));
webView->close();
@@ -1086,176 +1086,100 @@
webView->close();
}
-TEST_F(WebFrameTest, MoveSelectionStart)
+TEST_F(WebFrameTest, SelectRangeCanMoveSelectionStart)
{
registerMockedHttpURLLoad("text_selection.html");
WebView* webView = createWebViewForTextSelection(m_baseURL + "text_selection.html");
WebFrame* frame = webView->mainFrame();
- // moveSelectionStart() always returns false if there's no selection.
- EXPECT_FALSE(frame->moveSelectionStart(topLeft(elementBounds(frame, "header_1")), false));
- EXPECT_FALSE(frame->moveSelectionStart(topLeft(elementBounds(frame, "header_1")), true));
-
- frame->executeScript(WebScriptSource("selectElement('header_1');"));
- EXPECT_EQ("Header 1.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionEnd(bottomRightMinusOne(elementBounds(frame, "header_2")), false));
- EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame));
-
// Select second span. We can move the start to include the first span.
frame->executeScript(WebScriptSource("selectElement('header_2');"));
EXPECT_EQ("Header 2.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionStart(topLeft(elementBounds(frame, "header_1")), false));
+ frame->selectRange(bottomRightMinusOne(elementBounds(frame, "header_2")), topLeft(elementBounds(frame, "header_1")));
EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame));
- // If allowCollapsedSelection=false we can't move the selection start beyond the current end.
- // We end up with a single character selected.
+ // We can move the start and end together.
frame->executeScript(WebScriptSource("selectElement('header_1');"));
EXPECT_EQ("Header 1.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionStart(bottomRightMinusOne(elementBounds(frame, "header_1")), false));
- EXPECT_EQ(".", selectionAsString(frame));
-
- // If allowCollapsedSelection=true we can move the start and end together.
- frame->executeScript(WebScriptSource("selectElement('header_1');"));
- EXPECT_EQ("Header 1.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionStart(bottomRightMinusOne(elementBounds(frame, "header_1")), true));
+ frame->selectRange(bottomRightMinusOne(elementBounds(frame, "header_1")), bottomRightMinusOne(elementBounds(frame, "header_1")));
EXPECT_EQ("", selectionAsString(frame));
// Selection is a caret, not empty.
EXPECT_FALSE(frame->selectionRange().isNull());
- EXPECT_TRUE(frame->moveSelectionStart(topLeft(elementBounds(frame, "header_1")), true));
- EXPECT_EQ("Header 1.", selectionAsString(frame));
- // If allowCollapsedSelection=true we can move the start across the end.
+ // We can move the start across the end.
frame->executeScript(WebScriptSource("selectElement('header_1');"));
EXPECT_EQ("Header 1.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionStart(bottomRightMinusOne(elementBounds(frame, "header_2")), true));
+ frame->selectRange(bottomRightMinusOne(elementBounds(frame, "header_1")), bottomRightMinusOne(elementBounds(frame, "header_2")));
EXPECT_EQ(" Header 2.", selectionAsString(frame));
// Can't extend the selection part-way into an editable element.
frame->executeScript(WebScriptSource("selectElement('footer_2');"));
EXPECT_EQ("Footer 2.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionStart(topLeft(elementBounds(frame, "editable_2")), true));
+ frame->selectRange(bottomRightMinusOne(elementBounds(frame, "footer_2")), topLeft(elementBounds(frame, "editable_2")));
EXPECT_EQ(" [ Footer 1. Footer 2.", selectionAsString(frame));
// Can extend the selection completely across editable elements.
frame->executeScript(WebScriptSource("selectElement('footer_2');"));
EXPECT_EQ("Footer 2.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionStart(topLeft(elementBounds(frame, "header_2")), true));
+ frame->selectRange(bottomRightMinusOne(elementBounds(frame, "footer_2")), topLeft(elementBounds(frame, "header_2")));
EXPECT_EQ("Header 2. ] [ Editable 1. Editable 2. ] [ Footer 1. Footer 2.", selectionAsString(frame));
// If the selection is editable text, we can't extend it into non-editable text.
frame->executeScript(WebScriptSource("selectElement('editable_2');"));
EXPECT_EQ("Editable 2.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionStart(topLeft(elementBounds(frame, "header_2")), true));
+ frame->selectRange(bottomRightMinusOne(elementBounds(frame, "editable_2")), topLeft(elementBounds(frame, "header_2")));
EXPECT_EQ("[ Editable 1. Editable 2.", selectionAsString(frame));
webView->close();
}
-TEST_F(WebFrameTest, MoveSelectionEnd)
+TEST_F(WebFrameTest, SelectRangeCanMoveSelectionEnd)
{
registerMockedHttpURLLoad("text_selection.html");
WebView* webView = createWebViewForTextSelection(m_baseURL + "text_selection.html");
WebFrame* frame = webView->mainFrame();
- // moveSelectionEnd() always returns false if there's no selection.
- EXPECT_FALSE(frame->moveSelectionEnd(topLeft(elementBounds(frame, "header_1")), false));
- EXPECT_FALSE(frame->moveSelectionEnd(topLeft(elementBounds(frame, "header_1")), true));
-
// Select first span. We can move the end to include the second span.
frame->executeScript(WebScriptSource("selectElement('header_1');"));
EXPECT_EQ("Header 1.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionEnd(bottomRightMinusOne(elementBounds(frame, "header_2")), false));
+ frame->selectRange(topLeft(elementBounds(frame, "header_1")), bottomRightMinusOne(elementBounds(frame, "header_2")));
EXPECT_EQ("Header 1. Header 2.", selectionAsString(frame));
- // If allowCollapsedSelection=false we can't move the selection end beyond the current start.
- // We end up with a single character selected.
+ // We can move the start and end together.
frame->executeScript(WebScriptSource("selectElement('header_2');"));
EXPECT_EQ("Header 2.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionEnd(topLeft(elementBounds(frame, "header_2")), false));
- EXPECT_EQ("H", selectionAsString(frame));
-
- // If allowCollapsedSelection=true we can move the start and end together.
- frame->executeScript(WebScriptSource("selectElement('header_2');"));
- EXPECT_EQ("Header 2.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionEnd(topLeft(elementBounds(frame, "header_2")), true));
+ frame->selectRange(topLeft(elementBounds(frame, "header_2")), topLeft(elementBounds(frame, "header_2")));
EXPECT_EQ("", selectionAsString(frame));
// Selection is a caret, not empty.
EXPECT_FALSE(frame->selectionRange().isNull());
- EXPECT_TRUE(frame->moveSelectionEnd(bottomRightMinusOne(elementBounds(frame, "header_2")), true));
- EXPECT_EQ("Header 2.", selectionAsString(frame));
- // If allowCollapsedSelection=true we can move the end across the start.
+ // We can move the end across the start.
frame->executeScript(WebScriptSource("selectElement('header_2');"));
EXPECT_EQ("Header 2.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionEnd(topLeft(elementBounds(frame, "header_1")), true));
+ frame->selectRange(topLeft(elementBounds(frame, "header_2")), topLeft(elementBounds(frame, "header_1")));
EXPECT_EQ("Header 1. ", selectionAsString(frame));
// Can't extend the selection part-way into an editable element.
frame->executeScript(WebScriptSource("selectElement('header_1');"));
EXPECT_EQ("Header 1.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionEnd(bottomRightMinusOne(elementBounds(frame, "editable_1")), true));
+ frame->selectRange(topLeft(elementBounds(frame, "header_1")), bottomRightMinusOne(elementBounds(frame, "editable_1")));
EXPECT_EQ("Header 1. Header 2. ] ", selectionAsString(frame));
// Can extend the selection completely across editable elements.
frame->executeScript(WebScriptSource("selectElement('header_1');"));
EXPECT_EQ("Header 1.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionEnd(bottomRightMinusOne(elementBounds(frame, "footer_1")), true));
+ frame->selectRange(topLeft(elementBounds(frame, "header_1")), bottomRightMinusOne(elementBounds(frame, "footer_1")));
EXPECT_EQ("Header 1. Header 2. ] [ Editable 1. Editable 2. ] [ Footer 1.", selectionAsString(frame));
// If the selection is editable text, we can't extend it into non-editable text.
frame->executeScript(WebScriptSource("selectElement('editable_1');"));
EXPECT_EQ("Editable 1.", selectionAsString(frame));
- EXPECT_TRUE(frame->moveSelectionEnd(bottomRightMinusOne(elementBounds(frame, "footer_1")), true));
+ frame->selectRange(topLeft(elementBounds(frame, "editable_1")), bottomRightMinusOne(elementBounds(frame, "footer_1")));
EXPECT_EQ("Editable 1. Editable 2. ]", selectionAsString(frame));
webView->close();
}
-TEST_F(WebFrameTest, MoveCaret)
-{
- registerMockedHttpURLLoad("text_selection.html");
- WebView* webView = createWebViewForTextSelection(m_baseURL + "text_selection.html");
- WebFrame* frame = webView->mainFrame();
-
- // moveCaret() returns false if there's no selection, or if it isn't editable.
- EXPECT_FALSE(frame->moveCaret(topLeft(elementBounds(frame, "editable"))));
- frame->executeScript(WebScriptSource("selectElement('header_1');"));
- EXPECT_EQ("Header 1.", selectionAsString(frame));
- EXPECT_FALSE(frame->moveCaret(topLeft(elementBounds(frame, "editable"))));
-
- // Select the editable text span. Now moveCaret() works.
- frame->executeScript(WebScriptSource("selectElement('editable_1');"));
- EXPECT_EQ("Editable 1.", selectionAsString(frame));
-
- EXPECT_TRUE(frame->moveCaret(topLeft(elementBounds(frame, "editable_1"))));
- EXPECT_EQ("", selectionAsString(frame));
- EXPECT_FALSE(frame->selectionRange().isNull());
- EXPECT_TRUE(frame->moveSelectionEnd(bottomRightMinusOne(elementBounds(frame, "editable_1")), false));
- EXPECT_EQ("Editable 1.", selectionAsString(frame));
-
- EXPECT_TRUE(frame->moveCaret(bottomRightMinusOne(elementBounds(frame, "editable_2"))));
- EXPECT_EQ("", selectionAsString(frame));
- EXPECT_FALSE(frame->selectionRange().isNull());
- EXPECT_TRUE(frame->moveSelectionStart(topLeft(elementBounds(frame, "editable_2")), false));
- EXPECT_EQ("Editable 2.", selectionAsString(frame));
-
- // Caret is pinned at the start of the editable region.
- EXPECT_TRUE(frame->moveCaret(topLeft(elementBounds(frame, "header_1"))));
- EXPECT_EQ("", selectionAsString(frame));
- EXPECT_FALSE(frame->selectionRange().isNull());
- EXPECT_TRUE(frame->moveSelectionEnd(bottomRightMinusOne(elementBounds(frame, "editable_1")), false));
- EXPECT_EQ("[ Editable 1.", selectionAsString(frame));
-
- // Caret is pinned at the end of the editable region.
- EXPECT_TRUE(frame->moveCaret(bottomRightMinusOne(elementBounds(frame, "footer_2"))));
- EXPECT_EQ("", selectionAsString(frame));
- EXPECT_FALSE(frame->selectionRange().isNull());
- EXPECT_TRUE(frame->moveSelectionStart(topLeft(elementBounds(frame, "editable_2")), false));
- EXPECT_EQ("Editable 2. ]", selectionAsString(frame));
-
- webView->close();
-}
-
class DisambiguationPopupTestWebViewClient : public WebViewClient {
public:
virtual bool didTapMultipleTargets(const WebGestureEvent&, const WebVector<WebRect>& targetRects) OVERRIDE