Add the ability to ask the WKPage if the main frame is pinned
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Feb 2011 21:29:19 +0000 (21:29 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Feb 2011 21:29:19 +0000 (21:29 +0000)
to the right or left hand side.
Part of <rdar://problem/9017043>.

Reviewed by Maciej Stachowiak.

* UIProcess/API/C/WKPage.cpp:
(WKPageIsPinnedToLeftSide):
(WKPageIsPinnedToRightSide):
* UIProcess/API/C/WKPage.h:
Add new API calls.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
(WebKit::WebPageProxy::close):
(WebKit::WebPageProxy::processDidCrash):
(WebKit::WebPageProxy::didChangeScrollOffsetPinningForMainFrame):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::isPinnedToLeftSide):
(WebKit::WebPageProxy::isPinnedToRightSide):
Initialize, reset and update the pinned state.

* UIProcess/WebPageProxy.messages.in:
Add message to update the pinned state.

* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::didChangeScrollOffset):
* WebProcess/WebCoreSupport/WebFrameLoaderClient.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
(WebKit::WebPage::didChangeScrollOffsetForMainFrame):
* WebProcess/WebPage/WebPage.h:
Cache the pinned state, and only update the UIProcess when it
changes.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@79025 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/UIProcess/WebPageProxy.messages.in
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h

index 7092e472909f603ffc0cba53e9b452895922ba52..2d73e029f7726bf302a90282cb4c529fba1e4db0 100644 (file)
@@ -1,3 +1,40 @@
+2011-02-18  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Maciej Stachowiak.
+
+        Add the ability to ask the WKPage if the main frame is pinned
+        to the right or left hand side.
+        Part of <rdar://problem/9017043>.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageIsPinnedToLeftSide):
+        (WKPageIsPinnedToRightSide):
+        * UIProcess/API/C/WKPage.h:
+        Add new API calls.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::WebPageProxy):
+        (WebKit::WebPageProxy::close):
+        (WebKit::WebPageProxy::processDidCrash):
+        (WebKit::WebPageProxy::didChangeScrollOffsetPinningForMainFrame):
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::isPinnedToLeftSide):
+        (WebKit::WebPageProxy::isPinnedToRightSide):
+        Initialize, reset and update the pinned state.
+
+        * UIProcess/WebPageProxy.messages.in:
+        Add message to update the pinned state.
+
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::didChangeScrollOffset):
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage):
+        (WebKit::WebPage::didChangeScrollOffsetForMainFrame):
+        * WebProcess/WebPage/WebPage.h:
+        Cache the pinned state, and only update the UIProcess when it
+        changes.
+
 2011-02-18  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Simon Fraser.
index 1dfc82045fb1f861dc2a4998140b101a3696df0e..b6c44aaa37d6a534c466a9121ab210e670fa5013 100644 (file)
@@ -306,6 +306,16 @@ bool WKPageHasVerticalScrollbar(WKPageRef pageRef)
     return toImpl(pageRef)->hasVerticalScrollbar();
 }
 
+bool WKPageIsPinnedToLeftSide(WKPageRef pageRef)
+{
+    return toImpl(pageRef)->isPinnedToLeftSide();
+}
+
+bool WKPageIsPinnedToRightSide(WKPageRef pageRef)
+{
+    return toImpl(pageRef)->isPinnedToRightSide();
+}
+
 void WKPageFindString(WKPageRef pageRef, WKStringRef string, WKFindOptions options, unsigned maxMatchCount)
 {
     toImpl(pageRef)->findString(toImpl(string)->string(), toFindOptions(options), maxMatchCount);
index 6132e85223d9f0b8877bf1825e9948446e908882..5a674fa40378c01a3a399025521d4ddd5be49ed0 100644 (file)
@@ -318,6 +318,9 @@ WK_EXPORT WKSize WKPageFixedLayoutSize(WKPageRef page);
 WK_EXPORT bool WKPageHasHorizontalScrollbar(WKPageRef page);
 WK_EXPORT bool WKPageHasVerticalScrollbar(WKPageRef page);
 
+WK_EXPORT bool WKPageIsPinnedToLeftSide(WKPageRef page);
+WK_EXPORT bool WKPageIsPinnedToRightSide(WKPageRef page);
+
 WK_EXPORT void WKPageFindString(WKPageRef page, WKStringRef string, WKFindOptions findOptions, unsigned maxMatchCount);
 WK_EXPORT void WKPageHideFindUI(WKPageRef page);
 WK_EXPORT void WKPageCountStringMatches(WKPageRef page, WKStringRef string, WKFindOptions findOptions, unsigned maxMatchCount);
index 2d2a29bef15da40deb4d4e8af5b7cc1b4a17a320..6bbc281cdf206e60bb3cf39e59737cf241d70dde 100644 (file)
@@ -145,6 +145,8 @@ WebPageProxy::WebPageProxy(PageClient* pageClient, WebContext* context, WebPageG
     , m_currentDragOperation(DragOperationNone)
     , m_mainFrameHasHorizontalScrollbar(false)
     , m_mainFrameHasVerticalScrollbar(false)
+    , m_mainFrameIsPinnedToLeftSide(false)
+    , m_mainFrameIsPinnedToRightSide(false)
 {
 #ifndef NDEBUG
     webPageProxyCounter.increment();
@@ -299,6 +301,9 @@ void WebPageProxy::close()
     m_mainFrameHasHorizontalScrollbar = false;
     m_mainFrameHasVerticalScrollbar = false;
 
+    m_mainFrameIsPinnedToLeftSide = false;
+    m_mainFrameIsPinnedToRightSide = false;
+
     invalidateCallbackMap(m_voidCallbacks);
     invalidateCallbackMap(m_dataCallbacks);
     invalidateCallbackMap(m_stringCallbacks);
@@ -2532,6 +2537,9 @@ void WebPageProxy::processDidCrash()
     m_mainFrameHasHorizontalScrollbar = false;
     m_mainFrameHasVerticalScrollbar = false;
 
+    m_mainFrameIsPinnedToLeftSide = false;
+    m_mainFrameIsPinnedToRightSide = false;
+
     invalidateCallbackMap(m_voidCallbacks);
     invalidateCallbackMap(m_dataCallbacks);
     invalidateCallbackMap(m_stringCallbacks);
@@ -2689,6 +2697,12 @@ void WebPageProxy::didChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar,
     m_pageClient->didChangeScrollbarsForMainFrame();
 }
 
+void WebPageProxy::didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide, bool pinnedToRightSide)
+{
+    m_mainFrameIsPinnedToLeftSide = pinnedToLeftSide;
+    m_mainFrameIsPinnedToRightSide = pinnedToRightSide;
+}
+
 void WebPageProxy::didFinishLoadingDataForCustomRepresentation(const CoreIPC::DataReference& dataReference)
 {
     m_pageClient->didFinishLoadingDataForCustomRepresentation(dataReference);
index ad3e8837b3db11dc6715a8621ab9a2c2d80992e9..3f5d896b697f88db3d49887874d5f9734e43e9eb 100644 (file)
@@ -273,6 +273,9 @@ public:
     bool hasHorizontalScrollbar() const { return m_mainFrameHasHorizontalScrollbar; }
     bool hasVerticalScrollbar() const { return m_mainFrameHasVerticalScrollbar; }
 
+    bool isPinnedToLeftSide() const { return m_mainFrameIsPinnedToLeftSide; }
+    bool isPinnedToRightSide() const { return m_mainFrameIsPinnedToRightSide; }
+
 #if PLATFORM(MAC)
     // Called by the web process through a message.
     void registerWebProcessAccessibilityToken(const CoreIPC::DataReference&);
@@ -496,6 +499,7 @@ private:
     void runModal() { m_uiClient.runModal(this); }
     void didCompleteRubberBandForMainFrame(const WebCore::IntSize&);
     void didChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar);
+    void didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide, bool pinnedToRightSide);
 
     void reattachToWebProcess();
     void reattachToWebProcessWithItem(WebBackForwardListItem*);
@@ -705,6 +709,9 @@ private:
     bool m_mainFrameHasHorizontalScrollbar;
     bool m_mainFrameHasVerticalScrollbar;
 
+    bool m_mainFrameIsPinnedToLeftSide;
+    bool m_mainFrameIsPinnedToRightSide;
+
     static WKPageDebugPaintFlags s_debugPaintFlags;
 };
 
index dfc04eeec2422045d4f046c2c4bce315dd2f5937..e4239bf619663d4231b1a1b83dd2eb85efcd1a0a 100644 (file)
@@ -57,6 +57,7 @@ messages -> WebPageProxy {
     RunModal()
     DidCompleteRubberBandForMainFrame(WebCore::IntSize initialOverhang)
     DidChangeScrollbarsForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar)
+    DidChangeScrollOffsetPinningForMainFrame(bool hasHorizontalScrollbar, bool hasVerticalScrollbar)
 
 #if ENABLE(TILED_BACKING_STORE)
     PageDidRequestScroll(WebCore::IntSize delta)
index 54151011984abb8665d571e8e8c9879322001658..64fe8b220df6e1665034bfa0053adb8f32cd4d39 100644 (file)
@@ -1293,6 +1293,18 @@ bool WebFrameLoaderClient::shouldUsePluginDocument(const String& /*mimeType*/) c
     return false;
 }
 
+void WebFrameLoaderClient::didChangeScrollOffset()
+{
+    WebPage* webPage = m_frame->page();
+    if (!webPage)
+        return;
+
+    if (!m_frame->isMainFrame())
+        return;
+
+    webPage->didChangeScrollOffsetForMainFrame();
+}
+
 PassRefPtr<FrameNetworkingContext> WebFrameLoaderClient::createNetworkingContext()
 {
     return WebFrameNetworkingContext::create(m_frame->coreFrame());
index 9070b3acc63df2611794bb3650bd0eebfc546adf..121ae0af2066b79be42d65f9265925333e8d13af 100644 (file)
@@ -213,7 +213,9 @@ private:
 #endif
     
     virtual bool shouldUsePluginDocument(const String& /*mimeType*/) const;
-    
+
+    virtual void didChangeScrollOffset();
+
     virtual PassRefPtr<WebCore::FrameNetworkingContext> createNetworkingContext();
 
     WebFrame* m_frame;
index 11339ef47046c8c79e123bc1dabc15e795595142..ff5399c6c4171a4d48d0c693faa58aad69f480bd 100644 (file)
@@ -156,6 +156,8 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
     , m_pageID(pageID)
     , m_canRunModal(parameters.canRunModal)
     , m_isRunningModal(false)
+    , m_cachedMainFrameIsPinnedToLeftSide(false)
+    , m_cachedMainFrameIsPinnedToRightSide(false)
 {
     ASSERT(m_pageID);
 
@@ -1680,6 +1682,23 @@ bool WebPage::mainFrameHasCustomRepresentation() const
     return static_cast<WebFrameLoaderClient*>(mainFrame()->coreFrame()->loader()->client())->frameHasCustomRepresentation();
 }
 
+void WebPage::didChangeScrollOffsetForMainFrame()
+{
+    Frame* frame = m_page->mainFrame();
+    IntPoint scrollPosition = frame->view()->scrollPosition();
+    IntPoint maximumScrollPosition = frame->view()->maximumScrollPosition();
+
+    bool isPinnedToLeftSide = (scrollPosition.x() <= 0);
+    bool isPinnedToRightSide = (scrollPosition.x() >= maximumScrollPosition.x());
+
+    if (isPinnedToLeftSide != m_cachedMainFrameIsPinnedToLeftSide || isPinnedToRightSide != m_cachedMainFrameIsPinnedToRightSide) {
+        send(Messages::WebPageProxy::DidChangeScrollOffsetPinningForMainFrame(isPinnedToLeftSide, isPinnedToRightSide));
+        
+        m_cachedMainFrameIsPinnedToLeftSide = isPinnedToLeftSide;
+        m_cachedMainFrameIsPinnedToRightSide = isPinnedToRightSide;
+    }
+}
+
 #if PLATFORM(MAC)
 
 void WebPage::addPluginView(PluginView* pluginView)
index 64696227b17c23daaab925cb11dc73832d864c2a..774d16411d55efa3658774ecb4db7ea824971710 100644 (file)
@@ -332,6 +332,8 @@ public:
 
     bool mainFrameHasCustomRepresentation() const;
 
+    void didChangeScrollOffsetForMainFrame();
+
     bool canRunModal() const { return m_canRunModal; }
     void runModal();
 
@@ -538,6 +540,9 @@ private:
 
     bool m_canRunModal;
     bool m_isRunningModal;
+
+    bool m_cachedMainFrameIsPinnedToLeftSide;
+    bool m_cachedMainFrameIsPinnedToRightSide;
 };
 
 } // namespace WebKit