Touch adjustment forgets some subtarget quads.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Mar 2012 12:41:07 +0000 (12:41 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Mar 2012 12:41:07 +0000 (12:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82044

Patch by Allan Sandfeld Jensen <allan.jensen@nokia.com> on 2012-03-23
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Do not uncritically skip all nodes that are ancestors to other test results.
Instead return the inner-most element if multiple nodes have the same distance.

Test: touchadjustment/block-testing.html

* page/TouchAdjustment.cpp:
(WebCore::TouchAdjustment::compileSubtargetList):
(WebCore::TouchAdjustment::findNodeWithLowestDistanceMetric):

LayoutTests:

* touchadjustment/block-testing-expected.txt: Added.
* touchadjustment/block-testing.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/touchadjustment/block-testing-expected.txt [new file with mode: 0644]
LayoutTests/touchadjustment/block-testing.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/TouchAdjustment.cpp

index 8d10702054340cc0565577387563e36fea90c2e7..17da33d5bf7b48f414cd2b043ee6905491279fb6 100644 (file)
@@ -1,3 +1,13 @@
+2012-03-23  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
+
+        Touch adjustment forgets some subtarget quads.
+        https://bugs.webkit.org/show_bug.cgi?id=82044
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * touchadjustment/block-testing-expected.txt: Added.
+        * touchadjustment/block-testing.html: Added.
+
 2012-03-23  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
 
         TouchAdjustment does not correct for frame position
diff --git a/LayoutTests/touchadjustment/block-testing-expected.txt b/LayoutTests/touchadjustment/block-testing-expected.txt
new file mode 100644 (file)
index 0000000..f470611
--- /dev/null
@@ -0,0 +1,11 @@
+Some text. Some text. A link
+Test touch-adjustment on a block where we also touch the inner text and outside link.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS adjustedNode.id is "div1"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/touchadjustment/block-testing.html b/LayoutTests/touchadjustment/block-testing.html
new file mode 100644 (file)
index 0000000..91c1821
--- /dev/null
@@ -0,0 +1,57 @@
+<html>
+<head>
+    <script src="../fast/js/resources/js-test-pre.js"></script>
+    <style>
+        #div1 { position: absolute; left: 50px; top: 50px; width: 200px; height: 50px;}
+        #div2 { position: absolute; left: 50px; top: 100px; width: 200px; height: 50px;}
+    </style>
+</head>
+<body onload="runTests()">
+
+<div id=div1 onclick=doSomething>
+Some text.
+</div>
+
+<div id=div2>
+Some text. <a id=a1 href="#1">A link</a>
+</div>
+
+<p id='description'></p>
+<div id='console'></div>
+
+<script>
+    function doSomething() {
+        // Do something!
+    }
+
+    function testRoundTouch(x, y, radius)
+    {
+        var x = x - radius;
+        var y = y - radius;
+        var width = radius * 2;
+        var height = radius * 2;
+        var adjustedNode = internals.touchNodeAdjustedToBestClickableNode(x, y, width, height, document);
+        if (adjustedNode.nodeType == 3) // TEXT node
+            adjustedNode = adjustedNode.parentNode;
+        return adjustedNode;
+    }
+    function testDirectTouches()
+    {
+        adjustedNode = testRoundTouch(200, 90, 200);
+        shouldBeEqualToString('adjustedNode.id', 'div1');
+
+    }
+    function runTests()
+    {
+        if (window.layoutTestController && window.internals && internals.touchNodeAdjustedToBestClickableNode) {
+            description('Test touch-adjustment on a block where we also touch the inner text and outside link.');
+            layoutTestController.dumpAsText();
+            layoutTestController.waitUntilDone();
+            testDirectTouches();
+            isSuccessfullyParsed();
+            layoutTestController.notifyDone();
+        }
+    }
+</script>
+</body>
+</html>
\ No newline at end of file
index 25382ab56b8e1ecb102f2e969cf0af15d7835b71..5cab1ef3f8b9cd049b19ff57e708da50c25aeb3f 100644 (file)
@@ -1,3 +1,19 @@
+2012-03-23  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
+
+        Touch adjustment forgets some subtarget quads.
+        https://bugs.webkit.org/show_bug.cgi?id=82044
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Do not uncritically skip all nodes that are ancestors to other test results.
+        Instead return the inner-most element if multiple nodes have the same distance.
+
+        Test: touchadjustment/block-testing.html
+
+        * page/TouchAdjustment.cpp:
+        (WebCore::TouchAdjustment::compileSubtargetList):
+        (WebCore::TouchAdjustment::findNodeWithLowestDistanceMetric):
+
 2012-03-23  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
 
         TouchAdjustment does not correct for frame position
index f601f4a14fac9f01641e3537341ff24b839299c2..dd054618d0f80a80262685d8b0f4a997bb13b538 100644 (file)
@@ -119,10 +119,6 @@ void compileSubtargetList(const NodeList& intersectedNodes, SubtargetGeometryLis
     unsigned length = intersectedNodes.length();
     for (unsigned i = 0; i < length; ++i) {
         Node* const node = intersectedNodes.item(i);
-        if (responderMap.contains(node))
-            // Skip nodes that are direct ancestors of other candidates. They would hit-test
-            // against the same absolute quads.
-            continue;
         Vector<Node*> visitedNodes;
         Node* respondingNode = 0;
         for (Node* visitedNode = node; visitedNode; visitedNode = visitedNode->parentOrHostNode()) {
@@ -189,7 +185,6 @@ float distanceSquaredToTargetCenterLine(const IntPoint& touchHotspot, const IntR
 bool findNodeWithLowestDistanceMetric(Node*& targetNode, IntPoint& targetPoint, const IntPoint& touchHotspot, const IntRect& touchArea, SubtargetGeometryList& subtargets, DistanceFunction distanceFunction)
 {
     targetNode = 0;
-
     float bestDistanceMetric = INFINITY;
     SubtargetGeometryList::const_iterator it = subtargets.begin();
     const SubtargetGeometryList::const_iterator end = subtargets.end();
@@ -200,6 +195,10 @@ bool findNodeWithLowestDistanceMetric(Node*& targetNode, IntPoint& targetPoint,
             targetPoint = roundedIntPoint(it->quad().center());
             targetNode = node;
             bestDistanceMetric = distanceMetric;
+        } else if (distanceMetric == bestDistanceMetric) {
+            // Try to always return the inner-most element.
+            if (node->isDescendantOf(targetNode))
+                targetNode = node;
         }
     }