Title: [97301] trunk/Source/WebKit/chromium
Revision
97301
Author
[email protected]
Date
2011-10-12 14:10:15 -0700 (Wed, 12 Oct 2011)

Log Message

[chromium] Add a setSelectionToRange() method to WebFrame.
https://bugs.webkit.org/show_bug.cgi?id=69846

Also add a method to WebRange to create a range given a frame and an
interval.

This will be used to implement the "replacement range" feature of OS X
IMEs, see http://codereview.chromium.org/8227018 (the change to
render_widget.cc).
The renderer will set the selection to the replacement range before
calling confirmComposition(). This matches how WK2 does this, see
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm,
WebPage::setComposition(). The function convertToRange() was taken
from there, too.

Reviewed by Darin Fisher.

* public/WebFrame.h:
(WebKit::WebFrame::setSelectionToRange):
* src/WebFrameImpl.cpp:
(WebKit::WebViewImpl::setSelectionToRange):
* src/WebFrameImpl.h:
(WebKit::WebViewImpl::setSelectionToRange):
* src/WebRange.cpp:
(WebRange::fromGlobalRange):
* src/WebRange.h:
(WebRange::fromGlobalRange):

Modified Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (97300 => 97301)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-10-12 21:08:04 UTC (rev 97300)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-10-12 21:10:15 UTC (rev 97301)
@@ -1,3 +1,33 @@
+2011-10-12  Nico Weber  <[email protected]>
+
+        [chromium] Add a setSelectionToRange() method to WebFrame.
+        https://bugs.webkit.org/show_bug.cgi?id=69846
+
+        Also add a method to WebRange to create a range given a frame and an
+        interval.
+
+        This will be used to implement the "replacement range" feature of OS X
+        IMEs, see http://codereview.chromium.org/8227018 (the change to
+        render_widget.cc).
+        The renderer will set the selection to the replacement range before
+        calling confirmComposition(). This matches how WK2 does this, see
+        Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm,
+        WebPage::setComposition(). The function convertToRange() was taken
+        from there, too.
+
+        Reviewed by Darin Fisher.
+
+        * public/WebFrame.h:
+        (WebKit::WebFrame::setSelectionToRange):
+        * src/WebFrameImpl.cpp:
+        (WebKit::WebViewImpl::setSelectionToRange):
+        * src/WebFrameImpl.h:
+        (WebKit::WebViewImpl::setSelectionToRange):
+        * src/WebRange.cpp:
+        (WebRange::fromGlobalRange):
+        * src/WebRange.h:
+        (WebRange::fromGlobalRange):
+
 2011-10-12  Sergey Glazunov  <[email protected]>
 
         ScriptController::executeIfJavaScriptURL gets confused by synchronous frame loads

Modified: trunk/Source/WebKit/chromium/public/WebFrame.h (97300 => 97301)


--- trunk/Source/WebKit/chromium/public/WebFrame.h	2011-10-12 21:08:04 UTC (rev 97300)
+++ trunk/Source/WebKit/chromium/public/WebFrame.h	2011-10-12 21:10:15 UTC (rev 97301)
@@ -382,6 +382,8 @@
 
     virtual WebRange markedRange() const = 0;
 
+    virtual void setSelectionToRange(const WebRange&) = 0;
+
     // Returns the frame rectangle in window coordinate space of the given text
     // range.
     virtual bool firstRectForCharacterRange(unsigned location, unsigned length, WebRect&) const = 0;

Modified: trunk/Source/WebKit/chromium/public/WebRange.h (97300 => 97301)


--- trunk/Source/WebKit/chromium/public/WebRange.h	2011-10-12 21:08:04 UTC (rev 97300)
+++ trunk/Source/WebKit/chromium/public/WebRange.h	2011-10-12 21:10:15 UTC (rev 97301)
@@ -40,6 +40,7 @@
 
 namespace WebKit {
 
+class WebFrame;
 class WebNode;
 class WebRangePrivate;
 class WebString;
@@ -70,6 +71,8 @@
     WEBKIT_EXPORT WebString toHTMLText() const;
     WEBKIT_EXPORT WebString toPlainText() const;
 
+    WEBKIT_EXPORT static WebRange fromDocumentRange(WebFrame*, int start, int length);
+
 #if WEBKIT_IMPLEMENTATION
     WebRange(const WTF::PassRefPtr<WebCore::Range>&);
     WebRange& operator=(const WTF::PassRefPtr<WebCore::Range>&);

Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp (97300 => 97301)


--- trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2011-10-12 21:08:04 UTC (rev 97300)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2011-10-12 21:10:15 UTC (rev 97301)
@@ -1101,6 +1101,14 @@
     return frame()->editor()->compositionRange();
 }
 
+void WebFrameImpl::setSelectionToRange(const WebRange& range)
+{
+    if (frame()->selection()->isContentEditable()) {
+        RefPtr<Range> replacementRange = PassRefPtr<Range>(range);
+        frame()->selection()->setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
+    }
+}
+
 bool WebFrameImpl::firstRectForCharacterRange(unsigned location, unsigned length, WebRect& rect) const
 {
     if ((location + length < location) && (location + length))

Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.h (97300 => 97301)


--- trunk/Source/WebKit/chromium/src/WebFrameImpl.h	2011-10-12 21:08:04 UTC (rev 97300)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.h	2011-10-12 21:10:15 UTC (rev 97301)
@@ -37,6 +37,7 @@
 #include "Frame.h"
 #include "FrameLoaderClientImpl.h"
 #include "PlatformString.h"
+#include <wtf/Compiler.h>
 #include <wtf/OwnPtr.h>
 #include <wtf/RefCounted.h>
 
@@ -148,6 +149,7 @@
     virtual void unmarkText();
     virtual bool hasMarkedText() const;
     virtual WebRange markedRange() const;
+    virtual void setSelectionToRange(const WebRange&) OVERRIDE;
     virtual bool firstRectForCharacterRange(unsigned location, unsigned length, WebRect&) const;
     virtual size_t characterIndexForPoint(const WebPoint&) const;
     virtual bool executeCommand(const WebString&, const WebNode& = WebNode());

Modified: trunk/Source/WebKit/chromium/src/WebRange.cpp (97300 => 97301)


--- trunk/Source/WebKit/chromium/src/WebRange.cpp	2011-10-12 21:08:04 UTC (rev 97300)
+++ trunk/Source/WebKit/chromium/src/WebRange.cpp	2011-10-12 21:10:15 UTC (rev 97301)
@@ -31,7 +31,11 @@
 #include "config.h"
 #include "WebRange.h"
 
+#include "Document.h"
+#include "Frame.h"
 #include "Range.h"
+#include "TextIterator.h"
+#include "WebFrameImpl.h"
 #include "WebNode.h"
 #include "WebString.h"
 #include <wtf/PassRefPtr.h>
@@ -86,6 +90,15 @@
     return m_private->text();
 }
 
+// static
+WebRange WebRange::fromDocumentRange(WebFrame* frame, int start, int length)
+{
+    WebCore::Frame* webFrame = static_cast<WebFrameImpl*>(frame)->frame();
+    Element* selectionRoot = webFrame->selection()->rootEditableElement();
+    Element* scope = selectionRoot ? selectionRoot : webFrame->document()->documentElement();
+    return TextIterator::rangeFromLocationAndLength(scope, start, length);
+}
+
 WebRange::WebRange(const WTF::PassRefPtr<WebCore::Range>& range)
     : m_private(static_cast<WebRangePrivate*>(range.releaseRef()))
 {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to