Handle two-finger tap gestures in the same way as long-press gestures
authortdanderson@chromium.org <tdanderson@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Oct 2012 21:54:16 +0000 (21:54 +0000)
committertdanderson@chromium.org <tdanderson@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Oct 2012 21:54:16 +0000 (21:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=99947

Reviewed by Adam Barth.

Source/WebCore:

Currently a long-press gesture is used to dispatch a context menu (for platforms
defining CONTEXT_MENUS) or to select text (for Android). Additionally, for platforms
defining TOUCH_ADJUSTMENT, gesture target fuzzing is performed on the location and
touch area of the long-press gesture.

This CL will cause two-finger tap gestures to be handled in the same way as long-press
gestures. The location and touch area of a two-finger tap gesture will correspond to
the location and touch area of the first finger down; the location/area of the second
finger will be ignored.

Test: touchadjustment/touch-links-two-finger-tap.html

* page/EventHandler.cpp:
(WebCore::EventHandler::handleGestureLongPress):
(WebCore):
(WebCore::EventHandler::handleGestureForTextSelectionOrContextMenu):
(WebCore::EventHandler::handleGestureTwoFingerTap):
(WebCore::EventHandler::adjustGesturePosition):
* page/EventHandler.h:
(EventHandler):

Source/WebKit/chromium:

Set the area of a two-finger tap gesture to be the area of the enclosing
rectangle for the first finger down.

* src/WebInputEventConversion.cpp:
(WebKit::PlatformGestureEventBuilder::PlatformGestureEventBuilder):

LayoutTests:

New layout test for dispatching context menus on a two-finger tap
gesture when touch adjustment is enabled.

* touchadjustment/touch-links-two-finger-tap-expected.txt: Added.
* touchadjustment/touch-links-two-finger-tap.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/touchadjustment/touch-links-two-finger-tap-expected.txt [new file with mode: 0644]
LayoutTests/touchadjustment/touch-links-two-finger-tap.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/EventHandler.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebInputEventConversion.cpp

index 95e5ab4..d538c5c 100644 (file)
@@ -1,3 +1,16 @@
+2012-10-24  Terry Anderson  <tdanderson@chromium.org>
+
+        Handle two-finger tap gestures in the same way as long-press gestures
+        https://bugs.webkit.org/show_bug.cgi?id=99947
+
+        Reviewed by Adam Barth.
+
+        New layout test for dispatching context menus on a two-finger tap
+        gesture when touch adjustment is enabled.
+
+        * touchadjustment/touch-links-two-finger-tap-expected.txt: Added.
+        * touchadjustment/touch-links-two-finger-tap.html: Added.
+
 2012-10-24  Chris Fleizach  <cfleizach@apple.com>
 
         AX:When aria-label is used, the text under an element is still appearing as the AXTitle
diff --git a/LayoutTests/touchadjustment/touch-links-two-finger-tap-expected.txt b/LayoutTests/touchadjustment/touch-links-two-finger-tap-expected.txt
new file mode 100644 (file)
index 0000000..be17819
--- /dev/null
@@ -0,0 +1,17 @@
+Tests if a two finger tap gesture on links will trigger a context menu when touch adjustment is used.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Testing direct hits.
+PASS
+PASS
+PASS
+Testing indirect hits.
+PASS
+PASS
+PASS
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/touchadjustment/touch-links-two-finger-tap.html b/LayoutTests/touchadjustment/touch-links-two-finger-tap.html
new file mode 100644 (file)
index 0000000..4ae9b8f
--- /dev/null
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>Touch Adjustment : Testing that a context menu will appear on a two-finger tap - bug 99947</title>
+    <script src="../fast/js/resources/js-test-pre.js"></script>
+    <script src="resources/touchadjustment.js"></script>
+    <style>
+        #sandbox {
+            position: absolute;
+            left: 0px;
+            top: 0px;
+        }
+    </style>
+</head>
+
+<body>
+
+<div id="sandbox">
+<p><a href="" id="link1">I</a> propose to consider <a href="" id="link2">the question</a>, "Can machines think?"<br>This should begin with definitions of the meaning of the terms "machine" and <a href="" id="link3">"think."</a></p>
+</div>
+
+<p id='description'></p>
+<div id='console'></div>
+
+<script>
+    var element;
+    var adjustedNode;
+    // Set up shortcut access to elements
+    var e = {};
+    ['sandbox', 'link1', 'link2', 'link3'].forEach(function(a) {
+        e[a] = document.getElementById(a);
+    });
+
+    document.oncontextmenu = function() { debug("PASS"); }
+
+    function testTwoFingerTap(touchpoint)
+    {
+        if (eventSender.gestureTwoFingerTap)
+            eventSender.gestureTwoFingerTap(touchpoint.left, touchpoint.top);
+        else
+            debug("gestureTwoFingerTap not implemented by this platform.");
+    }
+
+    function testDirectTouch(element)
+    {
+        // Touch directly in the center of the element.
+        var touchpoint = offsetTouchPoint(findAbsoluteBounds(element), 'center', 0, 20, 30);
+        testTwoFingerTap(touchpoint);
+    }
+
+    function testIndirectTouch(element)
+    {
+        // Touch just right of the element.
+        var touchpoint = offsetTouchPoint(findAbsoluteBounds(element), 'right', 10, 30, 20);
+        testTwoFingerTap(touchpoint);
+    }
+
+    function testDirectTouches()
+    {
+        debug('Testing direct hits.');
+        testDirectTouch(e.link1);
+        testDirectTouch(e.link2);
+        testDirectTouch(e.link3);
+    }
+
+    function testIndirectTouches()
+    {
+        debug('Testing indirect hits.');
+        testIndirectTouch(e.link1);
+        testIndirectTouch(e.link2);
+        testIndirectTouch(e.link3);
+    }
+
+    function runTests()
+    {
+        if (window.testRunner && window.internals && internals.touchNodeAdjustedToBestClickableNode) {
+            description('Tests if a two finger tap gesture on links will trigger a context menu when touch adjustment is used.');
+            testDirectTouches();
+            testIndirectTouches();
+            e.sandbox.style.display = 'none';
+        }
+    }
+    runTests();
+</script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index 67b5128..e28c80e 100644 (file)
@@ -1,3 +1,31 @@
+2012-10-24  Terry Anderson  <tdanderson@chromium.org>
+
+        Handle two-finger tap gestures in the same way as long-press gestures
+        https://bugs.webkit.org/show_bug.cgi?id=99947
+
+        Reviewed by Adam Barth.
+
+        Currently a long-press gesture is used to dispatch a context menu (for platforms 
+        defining CONTEXT_MENUS) or to select text (for Android). Additionally, for platforms 
+        defining TOUCH_ADJUSTMENT, gesture target fuzzing is performed on the location and 
+        touch area of the long-press gesture.
+
+        This CL will cause two-finger tap gestures to be handled in the same way as long-press 
+        gestures. The location and touch area of a two-finger tap gesture will correspond to 
+        the location and touch area of the first finger down; the location/area of the second 
+        finger will be ignored.
+
+        Test: touchadjustment/touch-links-two-finger-tap.html
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::handleGestureLongPress):
+        (WebCore):
+        (WebCore::EventHandler::handleGestureForTextSelectionOrContextMenu):
+        (WebCore::EventHandler::handleGestureTwoFingerTap):
+        (WebCore::EventHandler::adjustGesturePosition):
+        * page/EventHandler.h:
+        (EventHandler):
+
 2012-10-24  Chris Fleizach  <cfleizach@apple.com>
 
         AX:When aria-label is used, the text under an element is still appearing as the AXTitle
index 09fb0a9..4befe04 100644 (file)
@@ -2574,6 +2574,11 @@ bool EventHandler::handleGestureTap(const PlatformGestureEvent& gestureEvent)
 
 bool EventHandler::handleGestureLongPress(const PlatformGestureEvent& gestureEvent)
 {
+    return handleGestureForTextSelectionOrContextMenu(gestureEvent);
+}
+
+bool EventHandler::handleGestureForTextSelectionOrContextMenu(const PlatformGestureEvent& gestureEvent)
+{
 #if OS(ANDROID)
     IntPoint hitTestPoint = m_frame->view()->windowToContents(gestureEvent.position());
     HitTestResult result = hitTestResultAtPoint(hitTestPoint, true);
@@ -2593,11 +2598,7 @@ bool EventHandler::handleGestureLongPress(const PlatformGestureEvent& gestureEve
 
 bool EventHandler::handleGestureTwoFingerTap(const PlatformGestureEvent& gestureEvent)
 {
-#if ENABLE(CONTEXT_MENUS)
-    return sendContextMenuEventForGesture(gestureEvent);
-#else
-    return false;
-#endif
+    return handleGestureForTextSelectionOrContextMenu(gestureEvent);
 }
 
 bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gestureEvent)
@@ -2670,6 +2671,7 @@ bool EventHandler::adjustGesturePosition(const PlatformGestureEvent& gestureEven
         bestClickableNodeForTouchPoint(gestureEvent.position(), IntSize(gestureEvent.area().width() / 2, gestureEvent.area().height() / 2), adjustedPoint, targetNode);
         break;
     case PlatformEvent::GestureLongPress:
+    case PlatformEvent::GestureTwoFingerTap:
         bestContextMenuNodeForTouchPoint(gestureEvent.position(), IntSize(gestureEvent.area().width() / 2, gestureEvent.area().height() / 2), adjustedPoint, targetNode);
         break;
     default:
index 9a361f2..86938e0 100644 (file)
@@ -365,6 +365,7 @@ private:
 #if ENABLE(GESTURE_EVENTS)
     bool handleGestureScrollCore(const PlatformGestureEvent&, PlatformWheelEventGranularity, bool latchedWheel);
     bool handleGestureTapDown();
+    bool handleGestureForTextSelectionOrContextMenu(const PlatformGestureEvent&);
 #endif
 
     Frame* m_frame;
index 1962545..a85ad3a 100644 (file)
@@ -1,3 +1,16 @@
+2012-10-24  Terry Anderson  <tdanderson@chromium.org>
+
+        Handle two-finger tap gestures in the same way as long-press gestures
+        https://bugs.webkit.org/show_bug.cgi?id=99947
+
+        Reviewed by Adam Barth.
+
+        Set the area of a two-finger tap gesture to be the area of the enclosing
+        rectangle for the first finger down.
+
+        * src/WebInputEventConversion.cpp:
+        (WebKit::PlatformGestureEventBuilder::PlatformGestureEventBuilder):
+
 2012-10-24  Eric Uhrhane  <ericu@chromium.org>
 
         https://bugs.webkit.org/show_bug.cgi?id=99202
index 0f4f6d5..8ff2e21 100644 (file)
@@ -171,6 +171,7 @@ PlatformGestureEventBuilder::PlatformGestureEventBuilder(Widget* widget, const W
         break;
     case WebInputEvent::GestureTwoFingerTap:
         m_type = PlatformEvent::GestureTwoFingerTap;
+        m_area = IntSize(e.data.twoFingerTap.firstFingerWidth, e.data.twoFingerTap.firstFingerHeight);
         break;
     case WebInputEvent::GestureLongPress:
         m_type = PlatformEvent::GestureLongPress;