TouchAdjustment does not correct for frame position
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Mar 2012 12:23:57 +0000 (12:23 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Mar 2012 12:23:57 +0000 (12:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82043

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

Source/WebCore:

Convert geometry to window coordinates before calculating distance.

Test: touchadjustment/iframe.html

* page/TouchAdjustment.cpp:
(WebCore::TouchAdjustment::distanceSquaredToTargetCenterLine):

LayoutTests:

Add test that will fail if frame position is not adjusted for.

* touchadjustment/iframe-expected.txt: Added.
* touchadjustment/iframe.html: Added.
* touchadjustment/resources/inner-frame.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/touchadjustment/iframe-expected.txt [new file with mode: 0644]
LayoutTests/touchadjustment/iframe.html [new file with mode: 0644]
LayoutTests/touchadjustment/resources/inner-frame.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/TouchAdjustment.cpp

index cc0cc37..8d10702 100644 (file)
@@ -1,3 +1,16 @@
+2012-03-23  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
+
+        TouchAdjustment does not correct for frame position
+        https://bugs.webkit.org/show_bug.cgi?id=82043
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Add test that will fail if frame position is not adjusted for.
+
+        * touchadjustment/iframe-expected.txt: Added.
+        * touchadjustment/iframe.html: Added.
+        * touchadjustment/resources/inner-frame.html: Added.
+
 2012-03-23  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [Qt] Unreviewed gardening, skip a failing test.
diff --git a/LayoutTests/touchadjustment/iframe-expected.txt b/LayoutTests/touchadjustment/iframe-expected.txt
new file mode 100644 (file)
index 0000000..743d1f8
--- /dev/null
@@ -0,0 +1,13 @@
+
+Test touch-adjustment on links in an iframe. Making sure we iframe position is correctly adjusted for.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Test fat direct touches.
+PASS adjustedNode.id is "a1"
+PASS adjustedNode.id is "a2"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/touchadjustment/iframe.html b/LayoutTests/touchadjustment/iframe.html
new file mode 100644 (file)
index 0000000..74fd4df
--- /dev/null
@@ -0,0 +1,51 @@
+<html>
+<head>
+    <script src="../fast/js/resources/js-test-pre.js"></script>
+    <style>
+        #myframe { position: absolute; left: 200px; top: 100px; width: 400px; height: 300px;}
+    </style>
+</head>
+<body onload="runTests()">
+
+<iframe id=myframe src="resources/inner-frame.html"></iframe>
+
+<p id='description'></p>
+<div id='console'></div>
+
+<script>
+    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()
+    {
+        debug('Test fat direct touches.');
+
+        adjustedNode = testRoundTouch(260, 200, 200);
+        shouldBeEqualToString('adjustedNode.id', 'a1');
+
+        adjustedNode = testRoundTouch(340, 200, 200);
+        shouldBeEqualToString('adjustedNode.id', 'a2');
+
+    }
+    function runTests()
+    {
+        if (window.layoutTestController && window.internals && internals.touchNodeAdjustedToBestClickableNode) {
+            description('Test touch-adjustment on links in an iframe. Making sure we iframe position is correctly adjusted for.');
+            layoutTestController.dumpAsText();
+            layoutTestController.waitUntilDone();
+            testDirectTouches();
+            isSuccessfullyParsed();
+            layoutTestController.notifyDone();
+        }
+    }
+</script>
+</body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/touchadjustment/resources/inner-frame.html b/LayoutTests/touchadjustment/resources/inner-frame.html
new file mode 100644 (file)
index 0000000..f31215a
--- /dev/null
@@ -0,0 +1,16 @@
+<html>
+<head>
+    <style>
+        div {position: absolute; }
+    </style>
+</head>
+<body>
+<div id=d1 style="width:200px;">
+    <a href="#1" id=a1>Link 1</a>
+</div>
+<div id=d2 style="left:200px;width:200px;">
+    <a href="#2" id=a2>Link 2</a>
+</div>
+</table>
+</body>
+</html>
\ No newline at end of file
index 07cdfa5..25382ab 100644 (file)
@@ -1,3 +1,17 @@
+2012-03-23  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
+
+        TouchAdjustment does not correct for frame position
+        https://bugs.webkit.org/show_bug.cgi?id=82043
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Convert geometry to window coordinates before calculating distance.
+
+        Test: touchadjustment/iframe.html
+
+        * page/TouchAdjustment.cpp:
+        (WebCore::TouchAdjustment::distanceSquaredToTargetCenterLine):
+
 2012-03-23  Vlad Voicu  <vladv@rosedu.org>
 
         Fixed minor WebInspector display issue
index 1f651b2..f601f4a 100644 (file)
@@ -24,6 +24,7 @@
 #include "ContainerNode.h"
 #include "FloatPoint.h"
 #include "FloatQuad.h"
+#include "FrameView.h"
 #include "HTMLLabelElement.h"
 #include "HTMLNames.h"
 #include "IntPoint.h"
@@ -174,6 +175,10 @@ float distanceSquaredToTargetCenterLine(const IntPoint& touchHotspot, const IntR
     // and gives the same result in all untransformed cases, and in transformed cases still
     // gives a better distance-function than the distance to the center-point.
     IntRect rect = subtarget.boundingBox();
+    ASSERT(subtarget.node()->document());
+    ASSERT(subtarget.node()->document()->view());
+    // Convert from frame coordinates to window coordinates.
+    rect = subtarget.node()->document()->view()->contentsToWindow(rect);
 
     return rect.distanceSquaredFromCenterLineToPoint(touchHotspot);
 }