Title: [145335] trunk/Source/WebKit2
Revision
145335
Author
[email protected]
Date
2013-03-10 16:12:02 -0700 (Sun, 10 Mar 2013)

Log Message

Add bundle API to get the current selection as a WKDOMRange
https://bugs.webkit.org/show_bug.cgi?id=111947
<rdar://problem/13205460>

Reviewed by Gavin Barraclough.

* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.h:
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
(-[WKWebProcessPlugInBrowserContextController selectedRange]):
Add new selectedRange property.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::frameWithSelection):
(WebKit::WebPage::currentSelectionAsRange):
* WebProcess/WebPage/WebPage.h:
Get the range by finding the frame that has a selection, and then normalizing it.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (145334 => 145335)


--- trunk/Source/WebKit2/ChangeLog	2013-03-10 22:37:37 UTC (rev 145334)
+++ trunk/Source/WebKit2/ChangeLog	2013-03-10 23:12:02 UTC (rev 145335)
@@ -1,3 +1,22 @@
+2013-03-10  Sam Weinig  <[email protected]>
+
+        Add bundle API to get the current selection as a WKDOMRange
+        https://bugs.webkit.org/show_bug.cgi?id=111947
+        <rdar://problem/13205460>
+
+        Reviewed by Gavin Barraclough.
+
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.h:
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
+        (-[WKWebProcessPlugInBrowserContextController selectedRange]):
+        Add new selectedRange property.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::frameWithSelection):
+        (WebKit::WebPage::currentSelectionAsRange):
+        * WebProcess/WebPage/WebPage.h:
+        Get the range by finding the frame that has a selection, and then normalizing it.
+
 2013-03-10  Tim Horton  <[email protected]>
 
         Add a heuristic to determine the “primary” snapshotted plugin

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.h (145334 => 145335)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.h	2013-03-10 22:37:37 UTC (rev 145334)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.h	2013-03-10 23:12:02 UTC (rev 145335)
@@ -29,12 +29,15 @@
 #import <WebKit2/WKBase.h>
 
 @class WKDOMDocument;
+@class WKDOMRange;
 
 WK_EXPORT
 @interface WKWebProcessPlugInBrowserContextController : NSObject
 
 @property(readonly) WKDOMDocument *mainFrameDocument;
 
+@property(readonly) WKDOMRange *selectedRange;
+
 @end
 
 #endif // defined(__LP64__) && defined(__clang__)

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm (145334 => 145335)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm	2013-03-10 22:37:37 UTC (rev 145334)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm	2013-03-10 23:12:02 UTC (rev 145335)
@@ -72,6 +72,15 @@
     return WebKit::toWKDOMDocument(webCoreMainFrame->document());
 }
 
+- (WKDOMRange *)selectedRange
+{
+    RefPtr<WebCore::Range> range = WebKit::toImpl(self._bundlePageRef)->currentSelectionAsRange();
+    if (!range)
+        return nil;
+
+    return WebKit::toWKDOMRange(range.get());
+}
+
 @end
 
 @implementation WKWebProcessPlugInBrowserContextController (Private)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (145334 => 145335)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2013-03-10 22:37:37 UTC (rev 145334)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2013-03-10 23:12:02 UTC (rev 145335)
@@ -2110,7 +2110,6 @@
     send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
 }
 
-#if PLATFORM(MAC)
 static Frame* frameWithSelection(Page* page)
 {
     for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
@@ -2120,7 +2119,6 @@
 
     return 0;
 }
-#endif
 
 void WebPage::getSelectionAsWebArchiveData(uint64_t callbackID)
 {
@@ -3973,4 +3971,13 @@
 }
 #endif // ENABLE(PRIMARY_SNAPSHOTTED_PLUGIN_HEURISTIC)
 
+PassRefPtr<Range> WebPage::currentSelectionAsRange()
+{
+    Frame* frame = frameWithSelection(m_page.get());
+    if (!frame)
+        return 0;
+
+    return frame->selection()->toNormalizedRange();
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (145334 => 145335)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2013-03-10 22:37:37 UTC (rev 145334)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2013-03-10 23:12:02 UTC (rev 145335)
@@ -284,6 +284,8 @@
     WebCore::Frame* mainFrame() const; // May return 0.
     WebCore::FrameView* mainFrameView() const; // May return 0.
 
+    PassRefPtr<WebCore::Range> currentSelectionAsRange();
+
 #if ENABLE(NETSCAPE_PLUGIN_API)
     PassRefPtr<Plugin> createPlugin(WebFrame*, WebCore::HTMLPlugInElement*, const Plugin::Parameters&);
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to