Changeset 135789 in webkit


Ignore:
Timestamp:
Nov 26, 2012, 4:56:30 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

LongPress and LongTap gestures should start drag/drop and open context menu respectively.
https://bugs.webkit.org/show_bug.cgi?id=101545

Patch by Varun Jain <varunjain@chromium.org> on 2012-11-26
Reviewed by Antonio Gomes.

For LongPress, we simulate drag by sending a mouse down and mouse drag
events. If a drag is not started (because maybe there is no draggable
element), then we show context menu instead (which is the current
behavior for LongPress). For LongTap, we use the existing functions that
LongPress uses to summon the context menu. LongPress initiated drag and
drop can be enabled/disabled by the platform using the Setting
touchDragDropEnabled which is disabled by default.

Source/WebCore:

Tests: fast/events/touch/gesture/context-menu-on-long-tap.html

fast/events/touch/gesture/long-press-on-draggable-element-triggers-drag.html

  • page/EventHandler.cpp:

(WebCore::EventHandler::EventHandler):
(WebCore::EventHandler::clear):
(WebCore::EventHandler::handleMouseDraggedEvent):
(WebCore::EventHandler::handleGestureEvent):
(WebCore::EventHandler::handleGestureLongPress):
(WebCore::EventHandler::handleGestureLongTap):
(WebCore):
(WebCore::EventHandler::handleGestureForTextSelectionOrContextMenu):
(WebCore::EventHandler::adjustGesturePosition):
(WebCore::EventHandler::handleDrag):

  • page/EventHandler.h:

(EventHandler):

  • page/Settings.in:

Source/WebKit/chromium:

  • public/WebSettings.h:
  • src/WebSettingsImpl.cpp:

(WebKit::WebSettingsImpl::setTouchDragDropEnabled):
(WebKit):

  • src/WebSettingsImpl.h:

(WebSettingsImpl):

Tools:

  • DumpRenderTree/chromium/TestRunner/src/EventSender.cpp:

(WebTestRunner):
(WebTestRunner::EventSender::EventSender):
(WebTestRunner::EventSender::gestureLongTap):
(WebTestRunner::EventSender::gestureEvent):

  • DumpRenderTree/chromium/TestRunner/src/EventSender.h:

(EventSender):

  • DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp:

(WebTestRunner::TestRunner::TestRunner):
(WebTestRunner::TestRunner::setTouchDragDropEnabled):
(WebTestRunner):

  • DumpRenderTree/chromium/TestRunner/src/TestRunner.h:

(TestRunner):

LayoutTests:

  • fast/events/touch/gesture/context-menu-on-long-tap.html: Added.
  • fast/events/touch/gesture/long-press-on-draggable-element-triggers-drag.html: Added.
  • platform/chromium/fast/events/touch/gesture/context-menu-on-long-tap-expected.txt: Added.
  • platform/chromium/fast/events/touch/gesture/long-press-on-draggable-element-triggers-drag-expected.txt: Added.
  • touchadjustment/touch-links-longpress-expected.txt:
  • touchadjustment/touch-links-longpress.html:
Location:
trunk
Files:
4 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r135783 r135789  
     12012-11-26  Varun Jain  <varunjain@chromium.org>
     2
     3        LongPress and LongTap gestures should start drag/drop and open context menu respectively.
     4        https://bugs.webkit.org/show_bug.cgi?id=101545
     5
     6        Reviewed by Antonio Gomes.
     7
     8        For LongPress, we simulate drag by sending a mouse down and mouse drag
     9        events. If a drag is not started (because maybe there is no draggable
     10        element), then we show context menu instead (which is the current
     11        behavior for LongPress). For LongTap, we use the existing functions that
     12        LongPress uses to summon the context menu. LongPress initiated drag and
     13        drop can be enabled/disabled by the platform using the Setting
     14        touchDragDropEnabled which is disabled by default.
     15
     16        * fast/events/touch/gesture/context-menu-on-long-tap.html: Added.
     17        * fast/events/touch/gesture/long-press-on-draggable-element-triggers-drag.html: Added.
     18        * platform/chromium/fast/events/touch/gesture/context-menu-on-long-tap-expected.txt: Added.
     19        * platform/chromium/fast/events/touch/gesture/long-press-on-draggable-element-triggers-drag-expected.txt: Added.
     20        * touchadjustment/touch-links-longpress-expected.txt:
     21        * touchadjustment/touch-links-longpress.html:
     22
    1232012-11-26  Roger Fong  <roger_fong@apple.com>
    224
  • trunk/LayoutTests/touchadjustment/touch-links-longpress-expected.txt

    r124642 r135789  
    1 Tests if a long press gesture on links will trigger a context menu when touch adjustment is used.
     1Tests if a long press gesture on links will trigger a drag/drop when touch adjustment is used.
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
  • trunk/LayoutTests/touchadjustment/touch-links-longpress.html

    r132929 r135789  
    22<html>
    33<head>
    4     <title>Touch Adjustment : Testing that a context menu will appear on a long press - bug 92914</title>
     4    <title>Touch Adjustment : Testing that a drag/drop will start on a long press - bug 92914</title>
    55    <script src="../fast/js/resources/js-test-pre.js"></script>
    66    <script src="resources/touchadjustment.js"></script>
     
    3232    });
    3333
    34     document.oncontextmenu = function() { debug("PASS"); }
     34    document.ondragstart = function(e) { debug("PASS"); e.preventDefault();}
    3535
    3636    function testLongPress(touchpoint)
     
    9090    {
    9191        if (window.testRunner && window.internals && internals.touchNodeAdjustedToBestClickableNode) {
    92             description('Tests if a long press gesture on links will trigger a context menu when touch adjustment is used.');
     92            testRunner.setTouchDragDropEnabled(true);
     93            description('Tests if a long press gesture on links will trigger a drag/drop when touch adjustment is used.');
    9394            testDirectTouches();
    9495            testIndirectTouches();
  • trunk/Source/WebCore/ChangeLog

    r135788 r135789  
     12012-11-26  Varun Jain  <varunjain@chromium.org>
     2
     3        LongPress and LongTap gestures should start drag/drop and open context menu respectively.
     4        https://bugs.webkit.org/show_bug.cgi?id=101545
     5
     6        Reviewed by Antonio Gomes.
     7
     8        For LongPress, we simulate drag by sending a mouse down and mouse drag
     9        events. If a drag is not started (because maybe there is no draggable
     10        element), then we show context menu instead (which is the current
     11        behavior for LongPress). For LongTap, we use the existing functions that
     12        LongPress uses to summon the context menu. LongPress initiated drag and
     13        drop can be enabled/disabled by the platform using the Setting
     14        touchDragDropEnabled which is disabled by default.
     15
     16        Tests: fast/events/touch/gesture/context-menu-on-long-tap.html
     17               fast/events/touch/gesture/long-press-on-draggable-element-triggers-drag.html
     18
     19        * page/EventHandler.cpp:
     20        (WebCore::EventHandler::EventHandler):
     21        (WebCore::EventHandler::clear):
     22        (WebCore::EventHandler::handleMouseDraggedEvent):
     23        (WebCore::EventHandler::handleGestureEvent):
     24        (WebCore::EventHandler::handleGestureLongPress):
     25        (WebCore::EventHandler::handleGestureLongTap):
     26        (WebCore):
     27        (WebCore::EventHandler::handleGestureForTextSelectionOrContextMenu):
     28        (WebCore::EventHandler::adjustGesturePosition):
     29        (WebCore::EventHandler::handleDrag):
     30        * page/EventHandler.h:
     31        (EventHandler):
     32        * page/Settings.in:
     33
    1342012-11-26  Andreas Kling  <akling@apple.com>
    235
  • trunk/Source/WebCore/page/EventHandler.cpp

    r135650 r135789  
    349349    , m_mouseMovedDurationRunningAverage(0)
    350350    , m_baseEventType(PlatformEvent::NoType)
     351    , m_didStartDrag(false)
     352    , m_didLongPressInvokeContextMenu(false)
    351353{
    352354}
     
    402404    m_mouseMovedDurationRunningAverage = 0;
    403405    m_baseEventType = PlatformEvent::NoType;
     406    m_didStartDrag = false;
     407    m_didLongPressInvokeContextMenu = false;
    404408}
    405409
     
    712716bool EventHandler::handleMouseDraggedEvent(const MouseEventWithHitTestResults& event)
    713717{
    714     if (handleDrag(event))
     718    if (handleDrag(event, ShouldCheckDragHysteresis))
    715719        return true;
    716720
     
    25972601    case PlatformEvent::GestureLongPress:
    25982602        return handleGestureLongPress(gestureEvent);
     2603    case PlatformEvent::GestureLongTap:
     2604        return handleGestureLongTap(gestureEvent);
    25992605    case PlatformEvent::GestureTwoFingerTap:
    26002606        return handleGestureTwoFingerTap(gestureEvent);
     
    26482654bool EventHandler::handleGestureLongPress(const PlatformGestureEvent& gestureEvent)
    26492655{
     2656#if ENABLE(DRAG_SUPPORT)
     2657    if (m_frame->settings() && m_frame->settings()->touchDragDropEnabled()) {
     2658        IntPoint adjustedPoint = gestureEvent.position();
     2659#if ENABLE(TOUCH_ADJUSTMENT)
     2660        adjustGesturePosition(gestureEvent, adjustedPoint);
     2661#endif
     2662        PlatformMouseEvent mouseDownEvent(adjustedPoint, gestureEvent.globalPosition(), LeftButton, PlatformEvent::MousePressed, 0, false, false, false, false, WTF::currentTime());
     2663        handleMousePressEvent(mouseDownEvent);
     2664        PlatformMouseEvent mouseDragEvent(adjustedPoint, gestureEvent.globalPosition(), LeftButton, PlatformEvent::MouseMoved, 0, false, false, false, false, WTF::currentTime());
     2665        HitTestRequest request(HitTestRequest::ReadOnly);
     2666        MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseDragEvent);
     2667        m_didStartDrag = false;
     2668        handleDrag(mev, DontCheckDragHysteresis);
     2669        if (m_didStartDrag)
     2670            return true;
     2671    }
     2672#endif
    26502673    return handleGestureForTextSelectionOrContextMenu(gestureEvent);
     2674}
     2675
     2676bool EventHandler::handleGestureLongTap(const PlatformGestureEvent& gestureEvent)
     2677{
     2678#if ENABLE(CONTEXT_MENUS) && !OS(ANDROID)
     2679    if (!m_didLongPressInvokeContextMenu)
     2680        return sendContextMenuEventForGesture(gestureEvent);
     2681#endif
     2682    return false;
    26512683}
    26522684
     
    26642696#endif
    26652697#if ENABLE(CONTEXT_MENUS)
     2698    m_didLongPressInvokeContextMenu = (gestureEvent.type() == PlatformEvent::GestureLongPress);
    26662699    return sendContextMenuEventForGesture(gestureEvent);
    26672700#else
     
    27612794        break;
    27622795    case PlatformEvent::GestureLongPress:
     2796    case PlatformEvent::GestureLongTap:
    27632797    case PlatformEvent::GestureTwoFingerTap:
    27642798        bestContextMenuNodeForTouchPoint(gestureEvent.position(), IntSize(gestureEvent.area().width() / 2, gestureEvent.area().height() / 2), adjustedPoint, targetNode);
     
    33313365}
    33323366
    3333 bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event)
     3367bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, CheckDragHysteresis checkDragHysteresis)
    33343368{
    33353369    if (event.event().button() != LeftButton || event.event().type() != PlatformEvent::MouseMoved) {
     
    34103444    }
    34113445
    3412     if (!dragHysteresisExceeded(event.event().position()))
     3446    if (checkDragHysteresis == ShouldCheckDragHysteresis && !dragHysteresisExceeded(event.event().position()))
    34133447        return true;
    34143448   
     
    34613495        Page* page = m_frame->page();
    34623496        DragController* dragController = page ? page->dragController() : 0;
    3463         bool startedDrag = dragController && dragController->startDrag(m_frame, dragState(), srcOp, event.event(), m_mouseDownPos);
     3497        m_didStartDrag = dragController && dragController->startDrag(m_frame, dragState(), srcOp, event.event(), m_mouseDownPos);
    34643498        // In WebKit2 we could reenter this code and start another drag.
    34653499        // On OS X this causes problems with the ownership of the pasteboard
    34663500        // and the promised types.
    3467         if (startedDrag) {
     3501        if (m_didStartDrag) {
    34683502            m_mouseDownMayStartDrag = false;
    34693503            return true;
  • trunk/Source/WebCore/page/EventHandler.h

    r135414 r135789  
    9292enum HitTestScrollbars { ShouldHitTestScrollbars, DontHitTestScrollbars };
    9393enum AppendTrailingWhitespace { ShouldAppendTrailingWhitespace, DontAppendTrailingWhitespace };
     94enum CheckDragHysteresis { ShouldCheckDragHysteresis, DontCheckDragHysteresis };
    9495
    9596class EventHandler {
     
    171172    bool handleGestureTap(const PlatformGestureEvent&);
    172173    bool handleGestureLongPress(const PlatformGestureEvent&);
     174    bool handleGestureLongTap(const PlatformGestureEvent&);
    173175    bool handleGestureTwoFingerTap(const PlatformGestureEvent&);
    174176    bool handleGestureScrollUpdate(const PlatformGestureEvent&);
     
    308310    void freeClipboard();
    309311
    310     bool handleDrag(const MouseEventWithHitTestResults&);
     312    bool handleDrag(const MouseEventWithHitTestResults&, CheckDragHysteresis);
    311313#endif
    312314    bool handleMouseUp(const MouseEventWithHitTestResults&);
     
    469471    double m_mouseMovedDurationRunningAverage;
    470472    PlatformEvent::Type m_baseEventType;
     473    bool m_didStartDrag;
     474    bool m_didLongPressInvokeContextMenu;
    471475};
    472476
  • trunk/Source/WebCore/page/Settings.in

    r135414 r135789  
    165165webSecurityEnabled initial=true
    166166spatialNavigationEnabled initial=false
     167
     168# This setting adds a means to enable/disable touch initiated drag & drop. If
     169# enabled, the user can initiate drag using long press.
     170touchDragDropEnabled initial=false
  • trunk/Source/WebKit/chromium/ChangeLog

    r135787 r135789  
     12012-11-26  Varun Jain  <varunjain@chromium.org>
     2
     3        LongPress and LongTap gestures should start drag/drop and open context menu respectively.
     4        https://bugs.webkit.org/show_bug.cgi?id=101545
     5
     6        Reviewed by Antonio Gomes.
     7
     8        For LongPress, we simulate drag by sending a mouse down and mouse drag
     9        events. If a drag is not started (because maybe there is no draggable
     10        element), then we show context menu instead (which is the current
     11        behavior for LongPress). For LongTap, we use the existing functions that
     12        LongPress uses to summon the context menu. LongPress initiated drag and
     13        drop can be enabled/disabled by the platform using the Setting
     14        touchDragDropEnabled which is disabled by default.
     15
     16        * public/WebSettings.h:
     17        * src/WebSettingsImpl.cpp:
     18        (WebKit::WebSettingsImpl::setTouchDragDropEnabled):
     19        (WebKit):
     20        * src/WebSettingsImpl.h:
     21        (WebSettingsImpl):
     22
    1232012-11-26  Yusuf Ozuysal  <yusufo@google.com>
    224
  • trunk/Source/WebKit/chromium/public/WebSettings.h

    r135414 r135789  
    159159    virtual void setTextAutosizingFontScaleFactor(float) = 0;
    160160    virtual void setTextDirectionSubmenuInclusionBehaviorNeverIncluded() = 0;
     161    virtual void setTouchDragDropEnabled(bool) = 0;
    161162    virtual void setUnifiedTextCheckerEnabled(bool) = 0;
    162163    virtual void setUserStyleSheetLocation(const WebURL&) = 0;
  • trunk/Source/WebKit/chromium/src/WebSettingsImpl.cpp

    r135414 r135789  
    347347}
    348348
     349void WebSettingsImpl::setTouchDragDropEnabled(bool enabled)
     350{
     351    m_settings->setTouchDragDropEnabled(enabled);
     352}
     353
    349354void WebSettingsImpl::setOfflineWebApplicationCacheEnabled(bool enabled)
    350355{
  • trunk/Source/WebKit/chromium/src/WebSettingsImpl.h

    r135414 r135789  
    154154    virtual void setTextAutosizingFontScaleFactor(float);
    155155    virtual void setTextDirectionSubmenuInclusionBehaviorNeverIncluded();
     156    virtual void setTouchDragDropEnabled(bool);
    156157    virtual void setUnifiedTextCheckerEnabled(bool);
    157158    virtual void setUserStyleSheetLocation(const WebURL&);
  • trunk/Tools/ChangeLog

    r135752 r135789  
     12012-11-26  Varun Jain  <varunjain@chromium.org>
     2
     3        LongPress and LongTap gestures should start drag/drop and open context menu respectively.
     4        https://bugs.webkit.org/show_bug.cgi?id=101545
     5
     6        Reviewed by Antonio Gomes.
     7
     8        For LongPress, we simulate drag by sending a mouse down and mouse drag
     9        events. If a drag is not started (because maybe there is no draggable
     10        element), then we show context menu instead (which is the current
     11        behavior for LongPress). For LongTap, we use the existing functions that
     12        LongPress uses to summon the context menu. LongPress initiated drag and
     13        drop can be enabled/disabled by the platform using the Setting
     14        touchDragDropEnabled which is disabled by default.
     15
     16        * DumpRenderTree/chromium/TestRunner/src/EventSender.cpp:
     17        (WebTestRunner):
     18        (WebTestRunner::EventSender::EventSender):
     19        (WebTestRunner::EventSender::gestureLongTap):
     20        (WebTestRunner::EventSender::gestureEvent):
     21        * DumpRenderTree/chromium/TestRunner/src/EventSender.h:
     22        (EventSender):
     23        * DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp:
     24        (WebTestRunner::TestRunner::TestRunner):
     25        (WebTestRunner::TestRunner::setTouchDragDropEnabled):
     26        (WebTestRunner):
     27        * DumpRenderTree/chromium/TestRunner/src/TestRunner.h:
     28        (TestRunner):
     29
    1302012-11-26  Christophe Dumez  <christophe.dumez@intel.com>
    231
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/EventSender.cpp

    r135436 r135789  
    297297    bindMethod("gestureTapCancel", &EventSender::gestureTapCancel);
    298298    bindMethod("gestureLongPress", &EventSender::gestureLongPress);
     299    bindMethod("gestureLongTap", &EventSender::gestureLongTap);
    299300    bindMethod("gestureTwoFingerTap", &EventSender::gestureTwoFingerTap);
    300301    bindMethod("zoomPageIn", &EventSender::zoomPageIn);
     
    11381139}
    11391140
     1141void EventSender::gestureLongTap(const CppArgumentList& arguments, CppVariant* result)
     1142{
     1143    result->setNull();
     1144    gestureEvent(WebInputEvent::GestureLongTap, arguments);
     1145}
     1146
    11401147void EventSender::gestureTwoFingerTap(const CppArgumentList& arguments, CppVariant* result)
    11411148{
     
    12071214        event.y = point.y;
    12081215        if (arguments.size() >= 4) {
    1209             event.data.tapDown.width = static_cast<float>(arguments[2].toDouble());
    1210             event.data.tapDown.height = static_cast<float>(arguments[3].toDouble());
     1216            event.data.longPress.width = static_cast<float>(arguments[2].toDouble());
     1217            event.data.longPress.height = static_cast<float>(arguments[3].toDouble());
     1218        }
     1219        break;
     1220    case WebInputEvent::GestureLongTap:
     1221        event.x = point.x;
     1222        event.y = point.y;
     1223        if (arguments.size() >= 4) {
     1224            event.data.longPress.width = static_cast<float>(arguments[2].toDouble());
     1225            event.data.longPress.height = static_cast<float>(arguments[3].toDouble());
    12111226        }
    12121227        break;
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/EventSender.h

    r135436 r135789  
    112112    void gestureTapCancel(const CppArgumentList&, CppVariant*);
    113113    void gestureLongPress(const CppArgumentList&, CppVariant*);
     114    void gestureLongTap(const CppArgumentList&, CppVariant*);
    114115    void gestureTwoFingerTap(const CppArgumentList&, CppVariant*);
    115116    void gestureEvent(WebKit::WebInputEvent::Type, const CppArgumentList&);
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp

    r135184 r135789  
    9999    bindMethod("setTextDirection", &TestRunner::setTextDirection);
    100100    bindMethod("textSurroundingNode", &TestRunner::textSurroundingNode);
     101    bindMethod("setTouchDragDropEnabled", &TestRunner::setTouchDragDropEnabled);
    101102
    102103    // Properties.
     
    665666}
    666667
     668void TestRunner::setTouchDragDropEnabled(const CppArgumentList& arguments, CppVariant* result)
     669{
     670    result->setNull();
     671    if (arguments.size() != 1 || !arguments[0].isBool())
     672        return;
     673
     674    m_webView->settings()->setTouchDragDropEnabled(arguments[0].toBoolean());
     675}
     676
    667677void TestRunner::workerThreadCount(CppVariant* result)
    668678{
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.h

    r135184 r135789  
    148148    // length to retrieve.
    149149    void textSurroundingNode(const CppArgumentList&, CppVariant*);
     150    void setTouchDragDropEnabled(const CppArgumentList&, CppVariant*);
    150151
    151152    ///////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.