Title: [142011] trunk/Source/WebKit/chromium
Revision
142011
Author
commit-qu...@webkit.org
Date
2013-02-06 11:07:27 -0800 (Wed, 06 Feb 2013)

Log Message

[Chromium] WebWidget should expose a way to determine the start/end of the selection bounds
https://bugs.webkit.org/show_bug.cgi?id=108667

Patch by Chris Hopman <cjhop...@chromium.org> on 2013-02-06
Reviewed by Darin Fisher.

WebWidget::selectionBounds() returns the anchor and focus of the
selection. This matches the arguments to WebFrame::selectRange().
Add WebWidget::isSelectionAnchorFirst so that a caller can convert the
anchor/focus to start/end.

* public/WebWidget.h:
(WebWidget):
(WebKit::WebWidget::isSelectionAnchorFirst):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::isSelectionAnchorFirst):
(WebKit):
* src/WebViewImpl.h:
* tests/WebViewTest.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (142010 => 142011)


--- trunk/Source/WebKit/chromium/ChangeLog	2013-02-06 18:56:35 UTC (rev 142010)
+++ trunk/Source/WebKit/chromium/ChangeLog	2013-02-06 19:07:27 UTC (rev 142011)
@@ -1,3 +1,24 @@
+2013-02-06  Chris Hopman  <cjhop...@chromium.org>
+
+        [Chromium] WebWidget should expose a way to determine the start/end of the selection bounds
+        https://bugs.webkit.org/show_bug.cgi?id=108667
+
+        Reviewed by Darin Fisher.
+
+        WebWidget::selectionBounds() returns the anchor and focus of the
+        selection. This matches the arguments to WebFrame::selectRange().
+        Add WebWidget::isSelectionAnchorFirst so that a caller can convert the
+        anchor/focus to start/end.
+
+        * public/WebWidget.h:
+        (WebWidget):
+        (WebKit::WebWidget::isSelectionAnchorFirst):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::isSelectionAnchorFirst):
+        (WebKit):
+        * src/WebViewImpl.h:
+        * tests/WebViewTest.cpp:
+
 2013-02-06  Alec Flett  <alecfl...@chromium.org>
 
         IndexedDB: Stub out SharedBuffer version of put()

Modified: trunk/Source/WebKit/chromium/public/WebWidget.h (142010 => 142011)


--- trunk/Source/WebKit/chromium/public/WebWidget.h	2013-02-06 18:56:35 UTC (rev 142010)
+++ trunk/Source/WebKit/chromium/public/WebWidget.h	2013-02-06 19:07:27 UTC (rev 142011)
@@ -198,6 +198,10 @@
     // If the selection range is empty, it returns false.
     virtual bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const { return false; }
 
+    // Returns true if the selection range is nonempty and its anchor is first
+    // (i.e its anchor is its start).
+    virtual bool isSelectionAnchorFirst() const { return false; }
+
     // Fetch the current selection range of this WebWidget. If there is no
     // selection, it will output a 0-length range with the location at the
     // caret. Returns true and fills the out-paramters on success; returns false

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (142010 => 142011)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2013-02-06 18:56:35 UTC (rev 142010)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2013-02-06 19:07:27 UTC (rev 142011)
@@ -2418,6 +2418,17 @@
     return true;
 }
 
+bool WebViewImpl::isSelectionAnchorFirst() const
+{
+    const Frame* frame = focusedWebCoreFrame();
+    if (!frame)
+        return false;
+    FrameSelection* selection = frame->selection();
+    if (!selection)
+        return false;
+    return selection->selection().isBaseFirst();
+}
+
 bool WebViewImpl::setEditableSelectionOffsets(int start, int end)
 {
     const Frame* focused = focusedWebCoreFrame();

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (142010 => 142011)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.h	2013-02-06 18:56:35 UTC (rev 142010)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h	2013-02-06 19:07:27 UTC (rev 142011)
@@ -172,6 +172,7 @@
     virtual WebColor backgroundColor() const;
     virtual bool selectionBounds(WebRect& anchor, WebRect& focus) const;
     virtual bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const;
+    virtual bool isSelectionAnchorFirst() const;
     virtual bool caretOrSelectionRange(size_t* location, size_t* length);
     virtual void setTextDirection(WebTextDirection direction);
     virtual bool isAcceleratedCompositingActive() const;

Modified: trunk/Source/WebKit/chromium/tests/WebViewTest.cpp (142010 => 142011)


--- trunk/Source/WebKit/chromium/tests/WebViewTest.cpp	2013-02-06 18:56:35 UTC (rev 142010)
+++ trunk/Source/WebKit/chromium/tests/WebViewTest.cpp	2013-02-06 19:07:27 UTC (rev 142011)
@@ -456,6 +456,23 @@
     webView->close();
 }
 
+TEST_F(WebViewTest, IsSelectionAnchorFirst)
+{
+    URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("input_field_populated.html"));
+    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "input_field_populated.html");
+    WebFrame* frame = webView->mainFrame();
+
+    webView->setInitialFocus(false);
+    webView->setEditableSelectionOffsets(4, 10);
+    EXPECT_TRUE(webView->isSelectionAnchorFirst());
+    WebRect anchor;
+    WebRect focus;
+    webView->selectionBounds(anchor, focus);
+    frame->selectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y));
+    EXPECT_FALSE(webView->isSelectionAnchorFirst());
+    webView->close();
+}
+
 TEST_F(WebViewTest, ResetScrollAndScaleState)
 {
     URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("hello_world.html"));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to