Changeset 83113 in webkit


Ignore:
Timestamp:
Apr 6, 2011 3:38:43 PM (13 years ago)
Author:
bweinstein@apple.com
Message:

WebKit2: Support Windows 7 Gestures
https://bugs.webkit.org/show_bug.cgi?id=49824
<rdar://problem/8689728>

Reviewed by Adam Roben.

Source/WebCore:

Move WindowTouch.h from WebKit/win, so it can be used in both WebKit and WebKit2.

  • WebCore.vcproj/WebCore.vcproj:
  • platform/win/WindowsTouch.h: Copied from WebKit/win/WindowsTouch.h.

Source/WebKit/win:

Move WindowsTouch.h from WebKit/win to WebCore/platform/win, so it can be
used in both WebKit and WebKit2.

  • WebKit.vcproj/WebKit.vcproj: Remove WindowsTouch.h.
  • WebView.cpp: Include WindowsTouch.h from WebCore instead of WebKit.
  • WindowsTouch.h: Removed.

Source/WebKit2:

Port code from WebKit1 -> WebKit2 to handle Windows 7 gestures.

The UIProcess gets a WM_GESTURENOTIFY message, it sends a sync message to the WebProcess to ask
if we should allow panning. The WebProcess checks if we're in a scrollable area, and the mouse
isn't over a scrollbar.

The UIProcess then gets a WM_GESTURE message, and if it is a pan gesture, it sends a message to
the WebProcess to scroll by the amount fingers have moved since the last WM_GESTURE messeage. The
X and Y are reversed because panning up -> moving the page down, and vice versa.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::gestureWillBegin): Send a sync message to the WebProcess

to initialize the gesture. The WebProcess returns whether or not we can start a pan
gesture from where we are.

(WebKit::WebPageProxy::gestureDidScroll): Send a message to the WebProcess to scroll by

pan gesture.

(WebKit::WebPageProxy::gestureDidEnd): Send a message to the WebProcess that the gesture has ended.

  • UIProcess/WebPageProxy.h:
  • UIProcess/win/WebView.cpp:

(WebKit::WebView::wndProc): Add WM_GESTURE and WM_GESTURENOTIFY handlers.
(WebKit::WebView::WebView): Initialize two new variables.
(WebKit::WebView::onGestureNotify): Figure out which gestures we should support based on where

the gesture is beginning.

(WebKit::WebView::onGesture): Support starting a gesture, ending a gesture, and panning.

  • UIProcess/win/WebView.h:
  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in: Add messages needed for gestures.
  • WebProcess/WebPage/win/WebPageWin.cpp:

(WebKit::WebPage::gestureWillBegin): Set the node that the gesture started on (so we

know which layer to scroll if the user pans), and determine whether or not we should allow
panning. If the page can't scroll, or the user is on a scrollbar, disallow panning.

(WebKit::WebPage::gestureDidScroll): Scroll the enclosing layer of the element the gesture

started on.

(WebKit::WebPage::gestureDidEnd): Clear the node the gesture started on.

Location:
trunk/Source
Files:
13 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r83108 r83113  
     12011-04-06  Brian Weinstein  <bweinstein@apple.com>
     2
     3        Reviewed by Adam Roben.
     4
     5        WebKit2: Support Windows 7 Gestures
     6        https://bugs.webkit.org/show_bug.cgi?id=49824
     7        <rdar://problem/8689728>
     8       
     9        Move WindowTouch.h from WebKit/win, so it can be used in both WebKit and WebKit2.
     10
     11        * WebCore.vcproj/WebCore.vcproj:
     12        * platform/win/WindowsTouch.h: Copied from WebKit/win/WindowsTouch.h.
     13
    1142011-04-06  Alexis Menard  <alexis.menard@openbossa.org>
    215
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r83079 r83113  
    2656926569                                        >
    2657026570                                </File>
     26571                                <File
     26572                                        RelativePath="..\platform\win\WindowsTouch.h"
     26573                                        >
     26574                                </File>
    2657126575                        </Filter>
    2657226576                        <Filter
  • trunk/Source/WebKit/win/ChangeLog

    r82962 r83113  
     12011-04-06  Brian Weinstein  <bweinstein@apple.com>
     2
     3        Reviewed by Adam Roben.
     4
     5        WebKit2: Support Windows 7 Gestures
     6        https://bugs.webkit.org/show_bug.cgi?id=49824
     7        <rdar://problem/8689728>
     8       
     9        Move WindowsTouch.h from WebKit/win to WebCore/platform/win, so it can be
     10        used in both WebKit and WebKit2.
     11
     12        * WebKit.vcproj/WebKit.vcproj: Remove WindowsTouch.h.
     13        * WebView.cpp: Include WindowsTouch.h from WebCore instead of WebKit.
     14        * WindowsTouch.h: Removed.
     15
    1162011-04-05  Martin Robinson  <mrobinson@igalia.com>
    217
  • trunk/Source/WebKit/win/WebKit.vcproj/WebKit.vcproj

    r82477 r83113  
    700700                                >
    701701                        </File>
    702                         <File
    703                                 RelativePath="..\WindowsTouch.h"
    704                                 >
    705                         </File>
    706702                </Filter>
    707703                <Filter
  • trunk/Source/WebKit/win/WebView.cpp

    r82870 r83113  
    5959#include "WebPreferences.h"
    6060#include "WebScriptWorld.h"
    61 #include "WindowsTouch.h"
    6261#include "resource.h"
    6362#include <JavaScriptCore/APICast.h>
     
    132131#include <WebCore/TypingCommand.h>
    133132#include <WebCore/WindowMessageBroadcaster.h>
     133#include <WebCore/WindowsTouch.h>
    134134#include <wtf/Threading.h>
    135135
  • trunk/Source/WebKit2/ChangeLog

    r83110 r83113  
     12011-04-06  Brian Weinstein  <bweinstein@apple.com>
     2
     3        Reviewed by Adam Roben.
     4
     5        WebKit2: Support Windows 7 Gestures
     6        https://bugs.webkit.org/show_bug.cgi?id=49824
     7        <rdar://problem/8689728>
     8       
     9        Port code from WebKit1 -> WebKit2 to handle Windows 7 gestures.
     10       
     11        The UIProcess gets a WM_GESTURENOTIFY message, it sends a sync message to the WebProcess to ask
     12        if we should allow panning. The WebProcess checks if we're in a scrollable area, and the mouse
     13        isn't over a scrollbar.
     14
     15        The UIProcess then gets a WM_GESTURE message, and if it is a pan gesture, it sends a message to
     16        the WebProcess to scroll by the amount fingers have moved since the last WM_GESTURE messeage. The
     17        X and Y are reversed because panning up -> moving the page down, and vice versa.
     18
     19        * UIProcess/WebPageProxy.cpp:
     20        (WebKit::WebPageProxy::gestureWillBegin): Send a sync message to the WebProcess
     21            to initialize the gesture. The WebProcess returns whether or not we can start a pan
     22            gesture from where we are.
     23        (WebKit::WebPageProxy::gestureDidScroll): Send a message to the WebProcess to scroll by
     24            pan gesture.
     25        (WebKit::WebPageProxy::gestureDidEnd): Send a message to the WebProcess that the gesture has ended.
     26        * UIProcess/WebPageProxy.h:
     27        * UIProcess/win/WebView.cpp:
     28        (WebKit::WebView::wndProc): Add WM_GESTURE and WM_GESTURENOTIFY handlers.
     29        (WebKit::WebView::WebView): Initialize two new variables.
     30        (WebKit::WebView::onGestureNotify): Figure out which gestures we should support based on where
     31            the gesture is beginning.
     32        (WebKit::WebView::onGesture): Support starting a gesture, ending a gesture, and panning.
     33        * UIProcess/win/WebView.h:
     34        * WebProcess/WebPage/WebPage.h:
     35        * WebProcess/WebPage/WebPage.messages.in: Add messages needed for gestures.
     36        * WebProcess/WebPage/win/WebPageWin.cpp:
     37        (WebKit::WebPage::gestureWillBegin): Set the node that the gesture started on (so we
     38            know which layer to scroll if the user pans), and determine whether or not we should allow
     39            panning. If the page can't scroll, or the user is on a scrollbar, disallow panning.
     40        (WebKit::WebPage::gestureDidScroll): Scroll the enclosing layer of the element the gesture
     41            started on.
     42        (WebKit::WebPage::gestureDidEnd): Clear the node the gesture started on.
     43
    1442011-04-06  Jeff Miller  <jeffm@apple.com>
    245
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r82970 r83113  
    668668    return text;
    669669}
     670
     671bool WebPageProxy::gestureWillBegin(const IntPoint& point)
     672{
     673    bool canBeginPanning;
     674    process()->sendSync(Messages::WebPage::GestureWillBegin(point), Messages::WebPage::GestureWillBegin::Reply(canBeginPanning), m_pageID);
     675    return canBeginPanning;
     676}
     677
     678void WebPageProxy::gestureDidScroll(const IntSize& size)
     679{
     680    process()->send(Messages::WebPage::GestureDidScroll(size), m_pageID);
     681}
     682
     683void WebPageProxy::gestureDidEnd()
     684{
     685    process()->send(Messages::WebPage::GestureDidEnd(), m_pageID);
     686}
    670687#endif
    671688
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r83004 r83113  
    273273    WebCore::IntRect firstRectForCharacterInSelectedRange(int);
    274274    String getSelectedText();
     275
     276    bool gestureWillBegin(const WebCore::IntPoint&);
     277    void gestureDidScroll(const WebCore::IntSize&);
     278    void gestureDidEnd();
    275279#endif
    276280#if ENABLE(TILED_BACKING_STORE)
  • trunk/Source/WebKit2/UIProcess/win/WebView.cpp

    r81895 r83113  
    5252#include <WebCore/WebCoreInstanceHandle.h>
    5353#include <WebCore/WindowMessageBroadcaster.h>
     54#include <WebCore/WindowsTouch.h>
    5455#include <wtf/text/WTFString.h>
    5556
     
    6869};
    6970
     71// Soft link functions for gestures and panning.
     72SOFT_LINK_LIBRARY(USER32);
     73SOFT_LINK_OPTIONAL(USER32, GetGestureInfo, BOOL, WINAPI, (HGESTUREINFO, PGESTUREINFO));
     74SOFT_LINK_OPTIONAL(USER32, SetGestureConfig, BOOL, WINAPI, (HWND, DWORD, UINT, PGESTURECONFIG, UINT));
     75SOFT_LINK_OPTIONAL(USER32, CloseGestureInfoHandle, BOOL, WINAPI, (HGESTUREINFO));
     76
    7077using namespace WebCore;
    7178
     
    157164    case WM_VSCROLL:
    158165        lResult = onVerticalScroll(hWnd, message, wParam, lParam, handled);
     166        break;
     167    case WM_GESTURENOTIFY:
     168        lResult = onGestureNotify(hWnd, message, wParam, lParam, handled);
     169        break;
     170    case WM_GESTURE:
     171        lResult = onGesture(hWnd, message, wParam, lParam, handled);
    159172        break;
    160173    case WM_SYSKEYDOWN:
     
    255268    , m_findIndicatorCallback(0)
    256269    , m_findIndicatorCallbackContext(0)
     270    , m_lastPanX(0)
     271    , m_lastPanY(0)
    257272{
    258273    registerWebViewWindowClass();
     
    478493
    479494    handled = true;
     495    return 0;
     496}
     497
     498LRESULT WebView::onGestureNotify(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& handled)
     499{
     500    // We shouldn't be getting any gesture messages without SetGestureConfig soft-linking correctly.
     501    ASSERT(SetGestureConfigPtr());
     502
     503    GESTURENOTIFYSTRUCT* gn = reinterpret_cast<GESTURENOTIFYSTRUCT*>(lParam);
     504
     505    POINT localPoint = { gn->ptsLocation.x, gn->ptsLocation.y };
     506    ::ScreenToClient(m_window, &localPoint);
     507
     508    bool canPan = m_page->gestureWillBegin(localPoint);
     509
     510    DWORD dwPanWant = GC_PAN | GC_PAN_WITH_INERTIA | GC_PAN_WITH_GUTTER;
     511    DWORD dwPanBlock = GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY;
     512    if (canPan)
     513        dwPanWant |= GC_PAN_WITH_SINGLE_FINGER_VERTICALLY;
     514    else
     515        dwPanBlock |= GC_PAN_WITH_SINGLE_FINGER_VERTICALLY;
     516
     517    GESTURECONFIG gc = { GID_PAN, dwPanWant, dwPanBlock };
     518    return SetGestureConfigPtr()(m_window, 0, 1, &gc, sizeof(gc));
     519}
     520
     521LRESULT WebView::onGesture(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool& handled)
     522{
     523    ASSERT(GetGestureInfoPtr());
     524    ASSERT(CloseGestureInfoHandlePtr());
     525
     526    if (!GetGestureInfoPtr() || !CloseGestureInfoHandlePtr()) {
     527        handled = false;
     528        return 0;
     529    }
     530
     531    HGESTUREINFO gestureHandle = reinterpret_cast<HGESTUREINFO>(lParam);
     532    GESTUREINFO gi = {0};
     533    gi.cbSize = sizeof(GESTUREINFO);
     534
     535    if (!GetGestureInfoPtr()(gestureHandle, &gi)) {
     536        handled = false;
     537        return 0;
     538    }
     539
     540    switch (gi.dwID) {
     541    case GID_BEGIN:
     542        m_lastPanX = gi.ptsLocation.x;
     543        m_lastPanY = gi.ptsLocation.y;
     544        break;
     545    case GID_END:
     546        m_page->gestureDidEnd();
     547        break;
     548    case GID_PAN: {
     549        int currentX = gi.ptsLocation.x;
     550        int currentY = gi.ptsLocation.y;
     551
     552        // Reverse the calculations because moving your fingers up should move the screen down, and
     553        // vice-versa.
     554        int deltaX = m_lastPanX - currentX;
     555        int deltaY = m_lastPanY - currentY;
     556
     557        m_lastPanX = currentX;
     558        m_lastPanY = currentY;
     559
     560        m_page->gestureDidScroll(IntSize(deltaX, deltaY));
     561
     562        // FIXME <rdar://problem/9244367>: Support window bounce (both horizontal and vertical),
     563        // if the uesr has scrolled past the end of the document. scollByPanGesture would need to
     564        // be a sync message to support this, because we would need to know how far we scrolled
     565        // past the end of the document.
     566
     567        CloseGestureInfoHandlePtr()(gestureHandle);
     568
     569        handled = true;
     570        return 0;
     571    }
     572    default:
     573        break;
     574    }
     575
     576    // If we get to this point, the gesture has not been handled. We forward
     577    // the call to DefWindowProc by returning false, and we don't need to
     578    // to call CloseGestureInfoHandle.
     579    // http://msdn.microsoft.com/en-us/library/dd353228(VS.85).aspx
     580    handled = false;
    480581    return 0;
    481582}
  • trunk/Source/WebKit2/UIProcess/win/WebView.h

    r82398 r83113  
    9898    LRESULT onHorizontalScroll(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
    9999    LRESULT onVerticalScroll(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
     100    LRESULT onGestureNotify(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
     101    LRESULT onGesture(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
    100102    LRESULT onKeyEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
    101103    LRESULT onPaintEvent(HWND hWnd, UINT message, WPARAM, LPARAM, bool& handled);
     
    220222    // (see https://bugs.webkit.org/show_bug.cgi?id=29264)
    221223    DWORD m_lastDropEffect;
     224
     225    int m_lastPanX;
     226    int m_lastPanY;
    222227};
    223228
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r83081 r83113  
    323323    void firstRectForCharacterInSelectedRange(const uint64_t characterPosition, WebCore::IntRect& resultRect);
    324324    void getSelectedText(WTF::String&);
     325
     326    void gestureWillBegin(const WebCore::IntPoint& point, bool& canBeginPanning);
     327    void gestureDidScroll(const WebCore::IntSize& size);
     328    void gestureDidEnd();
    325329#endif
    326330
     
    570574    // Our view's window (in the UI process).
    571575    HWND m_nativeWindow;
     576
     577    RefPtr<WebCore::Node> m_gestureTargetNode;
    572578#endif
    573579   
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r82733 r83113  
    202202    FirstRectForCharacterInSelectedRange(uint64_t characterPosition) -> (WebCore::IntRect resultRect)
    203203    GetSelectedText() -> (WTF::String text)
     204
     205    GestureWillBegin(WebCore::IntPoint point) -> (bool canBeginPanning)
     206    GestureDidScroll(WebCore::IntSize size)
     207    GestureDidEnd()
    204208#endif
    205209#if PLATFORM(QT)
  • trunk/Source/WebKit2/WebProcess/WebPage/win/WebPageWin.cpp

    r81895 r83113  
    3434#include <WebCore/Frame.h>
    3535#include <WebCore/FrameView.h>
     36#include <WebCore/HitTestRequest.h>
     37#include <WebCore/HitTestResult.h>
    3638#include <WebCore/KeyboardEvent.h>
    3739#include <WebCore/Page.h>
    3840#include <WebCore/PlatformKeyboardEvent.h>
     41#include <WebCore/RenderLayer.h>
     42#include <WebCore/RenderView.h>
    3943#include <WebCore/ResourceHandle.h>
    4044#include <WebCore/Settings.h>
     
    352356}
    353357
     358void WebPage::gestureWillBegin(const WebCore::IntPoint& point, bool& canBeginPanning)
     359{
     360    bool hitScrollbar = false;
     361
     362    HitTestRequest request(HitTestRequest::ReadOnly);
     363    for (Frame* childFrame = m_page->mainFrame(); childFrame; childFrame = EventHandler::subframeForTargetNode(m_gestureTargetNode.get())) {
     364        ScrollView* scollView = childFrame->view();
     365        if (!scollView)
     366            break;
     367       
     368        RenderView* renderView = childFrame->document()->renderView();
     369        if (!renderView)
     370            break;
     371
     372        RenderLayer* layer = renderView->layer();
     373        if (!layer)
     374            break;
     375
     376        HitTestResult result = scollView->windowToContents(point);
     377        layer->hitTest(request, result);
     378        m_gestureTargetNode = result.innerNode();
     379
     380        if (!hitScrollbar)
     381            hitScrollbar = result.scrollbar();
     382    }
     383
     384    if (hitScrollbar) {
     385        canBeginPanning = false;
     386        return;
     387    }
     388
     389    if (!m_gestureTargetNode) {
     390        canBeginPanning = false;
     391        return;
     392    }
     393
     394    for (RenderObject* renderer = m_gestureTargetNode->renderer(); renderer; renderer = renderer->parent()) {
     395        if (renderer->isBox() && toRenderBox(renderer)->canBeScrolledAndHasScrollableArea()) {
     396            canBeginPanning = true;
     397            return;
     398        }
     399    }
     400
     401    canBeginPanning = false;
     402}
     403
     404void WebPage::gestureDidScroll(const WebCore::IntSize& size)
     405{
     406    if (!m_gestureTargetNode || !m_gestureTargetNode->renderer() || !m_gestureTargetNode->renderer()->enclosingLayer())
     407        return;
     408
     409    m_gestureTargetNode->renderer()->enclosingLayer()->scrollByRecursively(size.width(), size.height());
     410}
     411
     412void WebPage::gestureDidEnd()
     413{
     414    m_gestureTargetNode = nullptr;
     415}
     416
    354417} // namespace WebKit
Note: See TracChangeset for help on using the changeset viewer.