Title: [97368] trunk/Source/WebKit/chromium
Revision
97368
Author
[email protected]
Date
2011-10-13 09:12:48 -0700 (Thu, 13 Oct 2011)

Log Message

[chromium] Add a selectionBounds() method to WebWidget.
https://bugs.webkit.org/show_bug.cgi?id=69028

Patch by Peng Huang <[email protected]> on 2011-10-13
Reviewed by Darin Fisher.

* public/WebWidget.h:
(WebKit::WebWidget::selectionBounds):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::selectionRange):
(WebKit::WebViewImpl::selectionBounds):
* src/WebViewImpl.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (97367 => 97368)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-10-13 15:57:09 UTC (rev 97367)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-10-13 16:12:48 UTC (rev 97368)
@@ -1,3 +1,17 @@
+2011-10-13  Peng Huang  <[email protected]>
+
+        [chromium] Add a selectionBounds() method to WebWidget.
+        https://bugs.webkit.org/show_bug.cgi?id=69028
+
+        Reviewed by Darin Fisher.
+
+        * public/WebWidget.h:
+        (WebKit::WebWidget::selectionBounds):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::selectionRange):
+        (WebKit::WebViewImpl::selectionBounds):
+        * src/WebViewImpl.h:
+
 2011-10-13  Kent Tamura  <[email protected]>
 
         Cleanup of HTMLSelectElement

Modified: trunk/Source/WebKit/chromium/public/WebWidget.h (97367 => 97368)


--- trunk/Source/WebKit/chromium/public/WebWidget.h	2011-10-13 15:57:09 UTC (rev 97367)
+++ trunk/Source/WebKit/chromium/public/WebWidget.h	2011-10-13 16:12:48 UTC (rev 97368)
@@ -42,7 +42,6 @@
 namespace WebKit {
 
 class WebInputEvent;
-class WebRange;
 class WebString;
 struct WebPoint;
 template <typename T> class WebVector;
@@ -149,15 +148,23 @@
     // otherwise the anchor index will be the same value of the focus index.
     virtual bool getSelectionOffsetsAndTextInEditableContent(WebString&, size_t& focus, size_t& anchor) const { return false; }
 
+    // FIXME: It has been replaced by selectionBounds. Remove it when chromium
+    // switches to selectionBounds.
     // Returns the current caret bounds of this WebWidget. The selection bounds
     // will be returned if a selection range is available.
     virtual WebRect caretOrSelectionBounds() { return WebRect(); }
 
+    // FIXME: It has been replaced by selectionBounds. Remove it when chromium
+    // switches to selectionBounds.
     // Returns the start and end point for the current selection, aligned to the
     // bottom of the selected line. start and end are the logical beginning and
     // ending positions of the selection. Visually, start may lie after end.
     virtual bool selectionRange(WebPoint& start, WebPoint& end) const { return false; }
 
+    // Returns the start and end bounds of the current selection.
+    // If the selection range is empty, it returns the caret bounds.
+    virtual bool selectionBounds(WebRect& start, WebRect& end) 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 (97367 => 97368)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2011-10-13 15:57:09 UTC (rev 97367)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2011-10-13 16:12:48 UTC (rev 97368)
@@ -295,7 +295,7 @@
     m_autofillClient = autofillClient;
 }
 
-void WebViewImpl::setDevToolsAgentClient(WebDevToolsAgentClient* devToolsClient) 
+void WebViewImpl::setDevToolsAgentClient(WebDevToolsAgentClient* devToolsClient)
 {
     if (devToolsClient)
         m_devToolsAgent = adoptPtr(new WebDevToolsAgentImpl(this, devToolsClient));
@@ -1568,34 +1568,51 @@
 
 bool WebViewImpl::selectionRange(WebPoint& start, WebPoint& end) const
 {
+    WebRect startRect, endRect;
+    if (!selectionBounds(startRect, endRect))
+        return false;
+    start.x = startRect.x;
+    start.y = startRect.y + startRect.height - 1;
+    end.x = endRect.x + endRect.width - 1;
+    end.y = endRect.y + endRect.height - 1;
+    return true;
+}
+
+bool WebViewImpl::selectionBounds(WebRect& start, WebRect& end) const
+{
     const Frame* frame = focusedWebCoreFrame();
-    if (!frame || !frame->selection()->isRange())
+    if (!frame)
         return false;
+    FrameSelection* selection = frame->selection();
+    if (!selection)
+        return false;
+
+    if (selection->isCaret()) {
+        start = end = frame->view()->contentsToWindow(selection->absoluteCaretBounds());
+        return true;
+    }
+
     RefPtr<Range> selectedRange = frame->selection()->toNormalizedRange();
     if (!selectedRange)
         return false;
+
     RefPtr<Range> range(Range::create(selectedRange->startContainer()->document(),
                                       selectedRange->startContainer(),
                                       selectedRange->startOffset(),
                                       selectedRange->startContainer(),
                                       selectedRange->startOffset()));
+    start = frame->editor()->firstRectForRange(range.get());
 
-    IntRect rect = frame->editor()->firstRectForRange(range.get());
-    start.x = rect.x();
-    start.y = rect.y() + rect.height() - 1;
-
     range = Range::create(selectedRange->endContainer()->document(),
                           selectedRange->endContainer(),
                           selectedRange->endOffset(),
                           selectedRange->endContainer(),
                           selectedRange->endOffset());
+    end = frame->editor()->firstRectForRange(range.get());
 
-    rect = frame->editor()->firstRectForRange(range.get());
-    end.x = rect.x() + rect.width() - 1;
-    end.y = rect.y() + rect.height() - 1;
-
     start = frame->view()->contentsToWindow(start);
     end = frame->view()->contentsToWindow(end);
+
     if (!frame->selection()->selection().isBaseFirst())
         std::swap(start, end);
     return true;

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (97367 => 97368)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.h	2011-10-13 15:57:09 UTC (rev 97367)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h	2011-10-13 16:12:48 UTC (rev 97368)
@@ -120,8 +120,13 @@
     virtual bool compositionRange(size_t* location, size_t* length);
     virtual WebTextInputType textInputType();
     virtual bool getSelectionOffsetsAndTextInEditableContent(WebString&, size_t& focus, size_t& anchor) const;
+    // FIXME: It has been replaced by selectionBounds. Remove it when chromium
+    // switches to selectionBounds.
     virtual WebRect caretOrSelectionBounds();
+    // FIXME: It has been replaced by selectionBounds. Remove it when chromium
+    // switches to selectionBounds.
     virtual bool selectionRange(WebPoint& start, WebPoint& end) const;
+    virtual bool selectionBounds(WebRect& start, WebRect& end) const;
     virtual bool caretOrSelectionRange(size_t* location, size_t* length);
     virtual void setTextDirection(WebTextDirection direction);
     virtual bool isAcceleratedCompositingActive() const;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to