Implement support to center selection on a page for WebKit2.
authoradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Jul 2011 17:42:12 +0000 (17:42 +0000)
committeradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Jul 2011 17:42:12 +0000 (17:42 +0000)
        https://bugs.webkit.org/show_bug.cgi?id=64481

        Reviewed by Anders Carlsson.

        * UIProcess/API/C/WKPage.cpp:
        (WKPageCenterSelectionInVisibleArea): Added.  Call WebPageProxy::centerSelectionInVisibleArea().
        * UIProcess/API/C/WKPage.h:
        * UIProcess/WebPageProxy.cpp:
        (WebKit::WebPageProxy::centerSelectionInVisibleArea): Send message to the WebProcess to center selection.
        * UIProcess/WebPageProxy.h:
        * WebProcess/WebPage/WebPage.cpp:
        (WebKit::WebPage::centerSelectionInVisibleArea): Get the FrameSelection from the main frame and call
        revealSelection() to center it.
        * WebProcess/WebPage/WebPage.h:
        * WebProcess/WebPage/WebPage.messages.in: Add the CenterSelectionInVisibleArea message.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@91012 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPage.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index 5a00474..fa1c82b 100644 (file)
@@ -1,3 +1,22 @@
+2011-07-14  Ada Chan  <adachan@apple.com>
+
+        Implement support to center selection on a page for WebKit2.
+        https://bugs.webkit.org/show_bug.cgi?id=64481
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageCenterSelectionInVisibleArea): Added.  Call WebPageProxy::centerSelectionInVisibleArea().
+        * UIProcess/API/C/WKPage.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::centerSelectionInVisibleArea): Send message to the WebProcess to center selection.
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::centerSelectionInVisibleArea): Get the FrameSelection from the main frame and call
+        revealSelection() to center it.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in: Add the CenterSelectionInVisibleArea message.
+
 2011-07-14  MORITA Hajime  <morrita@google.com>
 
         Unreviewed, rolling out r90976, r90981, and r90985.
index 3bf709a..0de10ef 100644 (file)
@@ -354,6 +354,11 @@ void WKPageSetMaintainsInactiveSelection(WKPageRef pageRef, bool newValue)
     return toImpl(pageRef)->setMaintainsInactiveSelection(newValue);
 }
 
+void WKPageCenterSelectionInVisibleArea(WKPageRef pageRef)
+{
+    return toImpl(pageRef)->centerSelectionInVisibleArea();
+}
+
 void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
 {
     toImpl(pageRef)->findString(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
index f75763a..7d5c908 100644 (file)
@@ -367,6 +367,7 @@ WK_EXPORT bool WKPageHasSelectedRange(WKPageRef page);
 WK_EXPORT bool WKPageIsContentEditable(WKPageRef page);
 
 WK_EXPORT void WKPageSetMaintainsInactiveSelection(WKPageRef page, bool maintainsInactiveSelection);
+WK_EXPORT void WKPageCenterSelectionInVisibleArea(WKPageRef page);
     
 WK_EXPORT void WKPageFindString(WKPageRef page, WKStringRef string, WKFindOptions findOptions, unsigned maxMatchCount);
 WK_EXPORT void WKPageHideFindUI(WKPageRef page);
index 924225b..90abd5e 100644 (file)
@@ -1006,6 +1006,14 @@ void WebPageProxy::scrollBy(ScrollDirection direction, ScrollGranularity granula
     process()->send(Messages::WebPage::ScrollBy(direction, granularity), m_pageID);
 }
 
+void WebPageProxy::centerSelectionInVisibleArea()
+{
+    if (!isValid())
+        return;
+
+    process()->send(Messages::WebPage::CenterSelectionInVisibleArea(), m_pageID);
+}
+
 void WebPageProxy::receivedPolicyDecision(PolicyAction action, WebFrameProxy* frame, uint64_t listenerID)
 {
     if (!isValid())
index 0e5877d..d4cee6c 100644 (file)
@@ -351,6 +351,7 @@ public:
 #endif
 
     void scrollBy(WebCore::ScrollDirection, WebCore::ScrollGranularity);
+    void centerSelectionInVisibleArea();
 
     String pageTitle() const;
     const String& toolTip() const { return m_toolTip; }
index 8f27ecd..6bb44e5 100644 (file)
@@ -1233,6 +1233,15 @@ void WebPage::scrollBy(uint32_t scrollDirection, uint32_t scrollGranularity)
     scroll(m_page.get(), static_cast<ScrollDirection>(scrollDirection), static_cast<ScrollGranularity>(scrollGranularity));
 }
 
+void WebPage::centerSelectionInVisibleArea()
+{
+    Frame* coreFrame = m_mainFrame->coreFrame();
+    if (!coreFrame)
+        return;
+
+    coreFrame->selection()->revealSelection(ScrollAlignment::alignCenterAlways);
+}
+
 void WebPage::setActive(bool isActive)
 {
     m_page->focusController()->setActive(isActive);
index b7e930e..001240e 100644 (file)
@@ -153,6 +153,8 @@ public:
 
     void scrollBy(uint32_t scrollDirection, uint32_t scrollGranularity);
 
+    void centerSelectionInVisibleArea();
+
 #if ENABLE(INSPECTOR)
     WebInspector* inspector();
 #endif
index ee35142..c8ca4eb 100644 (file)
@@ -45,6 +45,7 @@ messages -> WebPage {
     ContextMenuHidden()
 
     ScrollBy(uint32_t scrollDirection, uint32_t scrollGranularity)
+    CenterSelectionInVisibleArea()
 
     GoBack(uint64_t backForwardItemID, WebKit::SandboxExtension::Handle sandboxExtensionHandle)
     GoForward(uint64_t backForwardItemID, WebKit::SandboxExtension::Handle sandboxExtensionHandle)