WebKit2: Support window bounce when panning.
authorbweinstein@apple.com <bweinstein@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Apr 2011 19:42:26 +0000 (19:42 +0000)
committerbweinstein@apple.com <bweinstein@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Apr 2011 19:42:26 +0000 (19:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=58065
<rdar://problem/9244367>

Reviewed by Adam Roben.

Make gestureDidScroll synchronous, as once we scroll, we need to know
whether or not we are at the beginning or end of the scrollable document.

If we are at either end of the scrollable document, we call the Windows 7
API to bounce the window to give an indication that you are past an end
of the document.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::gestureDidScroll): Pass a boolean for the reply, and return it.
* UIProcess/WebPageProxy.h:
* UIProcess/win/WebView.cpp:
(WebKit::WebView::WebView): Inititalize a new variable.
(WebKit::WebView::onGesture): Once we send the message to scroll, check if have gone to
    an end of the document, and if we have, bounce the window.
* UIProcess/win/WebView.h:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in: GestureDidScroll is now sync.
* WebProcess/WebPage/win/WebPageWin.cpp:
(WebKit::WebPage::gestureDidScroll): When we are done scrolling, check if we have a vertical
    scrollbar and if we are at the beginning or the end of the scrollable document.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/win/WebView.cpp
Source/WebKit2/UIProcess/win/WebView.h
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/WebPage/win/WebPageWin.cpp

index ca1bd33..394aac5 100644 (file)
@@ -1,3 +1,32 @@
+2011-04-07  Brian Weinstein  <bweinstein@apple.com>
+
+        Reviewed by Adam Roben.
+
+        WebKit2: Support window bounce when panning.
+        https://bugs.webkit.org/show_bug.cgi?id=58065
+        <rdar://problem/9244367>
+        
+        Make gestureDidScroll synchronous, as once we scroll, we need to know
+        whether or not we are at the beginning or end of the scrollable document.
+        
+        If we are at either end of the scrollable document, we call the Windows 7
+        API to bounce the window to give an indication that you are past an end
+        of the document.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::gestureDidScroll): Pass a boolean for the reply, and return it.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/win/WebView.cpp:
+        (WebKit::WebView::WebView): Inititalize a new variable.
+        (WebKit::WebView::onGesture): Once we send the message to scroll, check if have gone to
+            an end of the document, and if we have, bounce the window.
+        * UIProcess/win/WebView.h:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in: GestureDidScroll is now sync.
+        * WebProcess/WebPage/win/WebPageWin.cpp:
+        (WebKit::WebPage::gestureDidScroll): When we are done scrolling, check if we have a vertical
+            scrollbar and if we are at the beginning or the end of the scrollable document.
+
 2011-04-07  Chang Shu  <cshu@webkit.org>
 
         Reviewed by Darin Adler.
index 084589f..49c0672 100644 (file)
@@ -670,14 +670,16 @@ String WebPageProxy::getSelectedText()
 
 bool WebPageProxy::gestureWillBegin(const IntPoint& point)
 {
-    bool canBeginPanning;
+    bool canBeginPanning = false;
     process()->sendSync(Messages::WebPage::GestureWillBegin(point), Messages::WebPage::GestureWillBegin::Reply(canBeginPanning), m_pageID);
     return canBeginPanning;
 }
 
-void WebPageProxy::gestureDidScroll(const IntSize& size)
+bool WebPageProxy::gestureDidScroll(const IntSize& size)
 {
-    process()->send(Messages::WebPage::GestureDidScroll(size), m_pageID);
+    bool atBeginningOrEndOfScrollableDocument = false;
+    process()->sendSync(Messages::WebPage::GestureDidScroll(size), Messages::WebPage::GestureDidScroll::Reply(atBeginningOrEndOfScrollableDocument), m_pageID);
+    return atBeginningOrEndOfScrollableDocument;
 }
 
 void WebPageProxy::gestureDidEnd()
index 6d162df..6868822 100644 (file)
@@ -274,7 +274,7 @@ public:
     String getSelectedText();
 
     bool gestureWillBegin(const WebCore::IntPoint&);
-    void gestureDidScroll(const WebCore::IntSize&);
+    bool gestureDidScroll(const WebCore::IntSize&);
     void gestureDidEnd();
 #endif
 #if ENABLE(TILED_BACKING_STORE)
index 9c0db72..4a2ec5f 100644 (file)
@@ -74,6 +74,11 @@ SOFT_LINK_OPTIONAL(USER32, GetGestureInfo, BOOL, WINAPI, (HGESTUREINFO, PGESTURE
 SOFT_LINK_OPTIONAL(USER32, SetGestureConfig, BOOL, WINAPI, (HWND, DWORD, UINT, PGESTURECONFIG, UINT));
 SOFT_LINK_OPTIONAL(USER32, CloseGestureInfoHandle, BOOL, WINAPI, (HGESTUREINFO));
 
+SOFT_LINK_LIBRARY(Uxtheme);
+SOFT_LINK_OPTIONAL(Uxtheme, BeginPanningFeedback, BOOL, WINAPI, (HWND));
+SOFT_LINK_OPTIONAL(Uxtheme, EndPanningFeedback, BOOL, WINAPI, (HWND, BOOL));
+SOFT_LINK_OPTIONAL(Uxtheme, UpdatePanningFeedback, BOOL, WINAPI, (HWND, LONG, LONG, BOOL));
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -269,6 +274,7 @@ WebView::WebView(RECT rect, WebContext* context, WebPageGroup* pageGroup, HWND p
     , m_findIndicatorCallbackContext(0)
     , m_lastPanX(0)
     , m_lastPanY(0)
+    , m_overPanY(0)
 {
     registerWebViewWindowClass();
 
@@ -522,8 +528,11 @@ LRESULT WebView::onGesture(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
 {
     ASSERT(GetGestureInfoPtr());
     ASSERT(CloseGestureInfoHandlePtr());
+    ASSERT(UpdatePanningFeedbackPtr());
+    ASSERT(BeginPanningFeedbackPtr());
+    ASSERT(EndPanningFeedbackPtr());
 
-    if (!GetGestureInfoPtr() || !CloseGestureInfoHandlePtr()) {
+    if (!GetGestureInfoPtr() || !CloseGestureInfoHandlePtr() || !UpdatePanningFeedbackPtr() || !BeginPanningFeedbackPtr() || !EndPanningFeedbackPtr()) {
         handled = false;
         return 0;
     }
@@ -557,12 +566,24 @@ LRESULT WebView::onGesture(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
         m_lastPanX = currentX;
         m_lastPanY = currentY;
 
-        m_page->gestureDidScroll(IntSize(deltaX, deltaY));
+        // Calculate the overpan for window bounce.
+        m_overPanY -= deltaY;
+
+        bool shouldBounceWindow = m_page->gestureDidScroll(IntSize(deltaX, deltaY));
+
+        if (gi.dwFlags & GF_BEGIN) {
+            BeginPanningFeedbackPtr()(m_window);
+            m_overPanY = 0;
+        } else if (gi.dwFlags & GF_END) {
+            EndPanningFeedbackPtr()(m_window, true);
+            m_overPanY = 0;
+        }
+
+        // FIXME: Support horizontal window bounce - <http://webkit.org/b/58068>.
+        // FIXME: Window Bounce doesn't undo until user releases their finger - <http://webkit.org/b/58069>.
 
-        // FIXME <rdar://problem/9244367>: Support window bounce (both horizontal and vertical), 
-        // if the uesr has scrolled past the end of the document. scollByPanGesture would need to 
-        // be a sync message to support this, because we would need to know how far we scrolled 
-        // past the end of the document.
+        if (shouldBounceWindow)
+            UpdatePanningFeedbackPtr()(m_window, 0, m_overPanY, gi.dwFlags & GF_INERTIA);
 
         CloseGestureInfoHandlePtr()(gestureHandle);
 
index 750a5bb..4b0ac91 100644 (file)
@@ -226,6 +226,8 @@ private:
 
     int m_lastPanX;
     int m_lastPanY;
+
+    int m_overPanY;
 };
 
 } // namespace WebKit
index f1b5b6c..e02ba9c 100644 (file)
@@ -323,8 +323,8 @@ public:
     void firstRectForCharacterInSelectedRange(const uint64_t characterPosition, WebCore::IntRect& resultRect);
     void getSelectedText(WTF::String&);
 
-    void gestureWillBegin(const WebCore::IntPoint& point, bool& canBeginPanning);
-    void gestureDidScroll(const WebCore::IntSize& size);
+    void gestureWillBegin(const WebCore::IntPoint&, bool& canBeginPanning);
+    void gestureDidScroll(const WebCore::IntSize&, bool& atBeginningOrEndOfDocument);
     void gestureDidEnd();
 #endif
 
index b9f2b17..1297477 100644 (file)
@@ -203,7 +203,7 @@ messages -> WebPage {
     GetSelectedText() -> (WTF::String text)
 
     GestureWillBegin(WebCore::IntPoint point) -> (bool canBeginPanning)
-    GestureDidScroll(WebCore::IntSize size)
+    GestureDidScroll(WebCore::IntSize size) -> (bool atBeginningOrEndOfScrollableDocument)
     GestureDidEnd()
 #endif
 #if PLATFORM(QT)
index fa53992..50003b1 100644 (file)
@@ -401,12 +401,28 @@ void WebPage::gestureWillBegin(const WebCore::IntPoint& point, bool& canBeginPan
     canBeginPanning = false;
 }
 
-void WebPage::gestureDidScroll(const WebCore::IntSize& size)
+void WebPage::gestureDidScroll(const IntSize& size, bool& atBeginningOrEndOfScrollableDocument)
 {
+    atBeginningOrEndOfScrollableDocument = false;
+
     if (!m_gestureTargetNode || !m_gestureTargetNode->renderer() || !m_gestureTargetNode->renderer()->enclosingLayer())
         return;
 
     m_gestureTargetNode->renderer()->enclosingLayer()->scrollByRecursively(size.width(), size.height());
+
+    Frame* frame = m_page->mainFrame();
+    if (!frame)
+        return;
+
+    ScrollView* view = frame->view();
+    if (!view)
+        return;
+
+    Scrollbar* verticalScrollbar = view->verticalScrollbar();
+    if (!verticalScrollbar)
+        return;
+
+    atBeginningOrEndOfScrollableDocument = !verticalScrollbar->currentPos() || verticalScrollbar->currentPos() >= verticalScrollbar->maximum();
 }
 
 void WebPage::gestureDidEnd()