Title: [128757] trunk
Revision
128757
Author
[email protected]
Date
2012-09-17 08:02:41 -0700 (Mon, 17 Sep 2012)

Log Message

[TouchAdjustment] Adjusted point outside bounds for non-rectilinear targets
https://bugs.webkit.org/show_bug.cgi?id=96098

Reviewed by Antonio Gomes.

Source/WebCore:

Simplifies how snapTo tries to restrict the adjustment to the touch-area, and
at the same fix it to give better guarantees.

Test: touchadjustment/rotated-node.html

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

LayoutTests:

Expands the test of rotated nodes to also perform checks of the validity of the adjusted points.

* touchadjustment/resources/touchadjustment.js:
(adjustTouchPoint):
* touchadjustment/rotated-node-expected.txt:
* touchadjustment/rotated-node.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (128756 => 128757)


--- trunk/LayoutTests/ChangeLog	2012-09-17 15:00:42 UTC (rev 128756)
+++ trunk/LayoutTests/ChangeLog	2012-09-17 15:02:41 UTC (rev 128757)
@@ -1,3 +1,17 @@
+2012-09-17  Allan Sandfeld Jensen  <[email protected]>
+
+        [TouchAdjustment] Adjusted point outside bounds for non-rectilinear targets
+        https://bugs.webkit.org/show_bug.cgi?id=96098
+
+        Reviewed by Antonio Gomes.
+
+        Expands the test of rotated nodes to also perform checks of the validity of the adjusted points.
+
+        * touchadjustment/resources/touchadjustment.js:
+        (adjustTouchPoint):
+        * touchadjustment/rotated-node-expected.txt:
+        * touchadjustment/rotated-node.html:
+
 2012-09-17  Christophe Dumez  <[email protected]>
 
         [EFL] Clean up Skipped list

Modified: trunk/LayoutTests/touchadjustment/resources/touchadjustment.js (128756 => 128757)


--- trunk/LayoutTests/touchadjustment/resources/touchadjustment.js	2012-09-17 15:00:42 UTC (rev 128756)
+++ trunk/LayoutTests/touchadjustment/resources/touchadjustment.js	2012-09-17 15:02:41 UTC (rev 128757)
@@ -64,7 +64,6 @@
     }
 }
 
-
 function testTouchPoint(touchpoint, targetNode, allowTextNodes)
 {
     var adjustedNode = internals.touchNodeAdjustedToBestClickableNode(touchpoint.left, touchpoint.top, touchpoint.width, touchpoint.height, document);
@@ -81,6 +80,12 @@
     shouldBeNode(adjustedNode, targetNode);
 }
 
+function adjustTouchPoint(touchpoint)
+{
+    var adjustedPoint = internals.touchPositionAdjustedToBestClickableNode(touchpoint.left, touchpoint.top, touchpoint.width, touchpoint.height, document);
+    return adjustedPoint;
+}
+
 function adjustTouchPointContextMenu(touchpoint)
 {
     var adjustedPoint = internals.touchPositionAdjustedToBestContextMenuNode(touchpoint.left, touchpoint.top, touchpoint.width, touchpoint.height, document);

Modified: trunk/LayoutTests/touchadjustment/rotated-node-expected.txt (128756 => 128757)


--- trunk/LayoutTests/touchadjustment/rotated-node-expected.txt	2012-09-17 15:00:42 UTC (rev 128756)
+++ trunk/LayoutTests/touchadjustment/rotated-node-expected.txt	2012-09-17 15:02:41 UTC (rev 128757)
@@ -20,6 +20,12 @@
 Near Misses
 PASS adjusted node was DIV#container.
 PASS adjusted node was DIV#container.
+
+Adjusted point within bounds
+PASS adjusted point was within (0,-20)x(40,40)
+PASS adjusted point was within (40,40)x(40,40)
+PASS adjusted point was within (-40,40)x(80,40)
+PASS adjusted point was within (50,-20)x(40,80)
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/touchadjustment/rotated-node.html (128756 => 128757)


--- trunk/LayoutTests/touchadjustment/rotated-node.html	2012-09-17 15:00:42 UTC (rev 128756)
+++ trunk/LayoutTests/touchadjustment/rotated-node.html	2012-09-17 15:02:41 UTC (rev 128757)
@@ -46,7 +46,7 @@
     function testDirectTouches()
     {
         debug('Direct Touches');
-        
+
         testTouchPoint(touchPoint(30, 30, 20), e.rotated);
         testTouchPoint(touchPoint(20, 30, 20), e.rotated);
         testTouchPoint(touchPoint(40, 30, 20), e.rotated);
@@ -75,6 +75,22 @@
         testTouchPoint(touchPoint(70, 60, 20), e.container);
     }
 
+    function testAdjustedPoints()
+    {
+        debug('\nAdjusted point within bounds');
+        var adjustedPoint = adjustTouchPoint(touchPoint(20, 0, 20))
+        shouldBeWithin(adjustedPoint, touchPoint(20, 0, 20));
+
+        adjustedPoint = adjustTouchPoint(touchPoint(60, 60, 20))
+        shouldBeWithin(adjustedPoint, touchPoint(60, 60, 20));
+
+        adjustedPoint = adjustTouchPoint(touchPoint(0, 60, 40, 20))
+        shouldBeWithin(adjustedPoint, touchPoint(0, 60, 40, 20));
+
+        adjustedPoint = adjustTouchPoint(touchPoint(70, 20, 20, 40))
+        shouldBeWithin(adjustedPoint, touchPoint(70, 20, 20, 40));
+    }
+
     function runTests()
     {
         document.addEventListener('click', function() {}, false);
@@ -82,6 +98,7 @@
             description(document.title);
             testDirectTouches();
             testAdjustedTouches();
+            testAdjustedPoints()
             e.container.style.display = 'none';
         }
     }

Modified: trunk/Source/WebCore/ChangeLog (128756 => 128757)


--- trunk/Source/WebCore/ChangeLog	2012-09-17 15:00:42 UTC (rev 128756)
+++ trunk/Source/WebCore/ChangeLog	2012-09-17 15:02:41 UTC (rev 128757)
@@ -1,3 +1,18 @@
+2012-09-17  Allan Sandfeld Jensen  <[email protected]>
+
+        [TouchAdjustment] Adjusted point outside bounds for non-rectilinear targets
+        https://bugs.webkit.org/show_bug.cgi?id=96098
+
+        Reviewed by Antonio Gomes.
+
+        Simplifies how snapTo tries to restrict the adjustment to the touch-area, and 
+        at the same fix it to give better guarantees.
+
+        Test: touchadjustment/rotated-node.html
+
+        * page/TouchAdjustment.cpp:
+        (WebCore::TouchAdjustment::snapTo):
+
 2012-09-17  Yury Semikhatsky  <[email protected]>
 
         Unreviewed. Fix Mac compilation.

Modified: trunk/Source/WebCore/page/TouchAdjustment.cpp (128756 => 128757)


--- trunk/Source/WebCore/page/TouchAdjustment.cpp	2012-09-17 15:00:42 UTC (rev 128756)
+++ trunk/Source/WebCore/page/TouchAdjustment.cpp	2012-09-17 15:02:41 UTC (rev 128757)
@@ -357,6 +357,20 @@
     return FloatPoint(adjusted.x(), adjusted.y());
 }
 
+// Adjusts 'point' to the nearest point inside rect, and leaves it unchanged if already inside.
+void adjustPointToRect(FloatPoint& point, const FloatRect& rect)
+{
+    if (point.x() < rect.x())
+        point.setX(rect.x());
+    else if (point.x() > rect.maxX())
+        point.setX(rect.maxX());
+
+    if (point.y() < rect.y())
+        point.setY(rect.y());
+    else if (point.y() > rect.maxY())
+        point.setY(rect.maxY());
+}
+
 bool snapTo(const SubtargetGeometry& geom, const IntPoint& touchPoint, const IntRect& touchArea, IntPoint& adjustedPoint)
 {
     FrameView* view = geom.node()->document()->view();
@@ -378,7 +392,11 @@
         return false;
     }
 
-    // Non-rectilinear element.
+    // The following code tries to adjust the point to place inside a both the touchArea and the non-rectilinear quad.
+    // FIXME: This will return the point inside the touch area that is the closest to the quad center, but does not
+    // guarantee that the point will be inside the quad. Corner-cases exist where the quad will intersect but this
+    // will fail to adjust the point to somewhere in the intersection.
+
     // Convert quad from content to window coordinates.
     FloatPoint p1 = contentsToWindow(view, quad.p1());
     FloatPoint p2 = contentsToWindow(view, quad.p2());
@@ -392,32 +410,12 @@
     }
 
     // Pull point towards the center of the element.
-    float cx = 0.25 * (p1.x() + p2.x() + p3.x() + p4.x());
-    float cy = 0.25 * (p1.y() + p2.y() + p3.y() + p4.y());
-    FloatPoint center = FloatPoint(cx, cy);
+    FloatPoint center = quad.center();
 
-    FloatSize pullDirection = center - touchPoint;
-    float distanceToCenter = pullDirection.diagonalLength();
+    adjustPointToRect(center, touchArea);
+    adjustedPoint = roundedIntPoint(center);
 
-    // Use distance from center to corner of touch area to limit adjustment distance.
-    float dx = 0.5f * touchArea.width();
-    float dy = 0.5f * touchArea.height();
-    float touchRadius = sqrt(dx * dx + dy * dy);
-
-    float scaleFactor = touchRadius / distanceToCenter;
-    if (scaleFactor > 1)
-        scaleFactor = 1;
-    pullDirection.scale(scaleFactor);
-
-    int x = static_cast<int>(touchPoint.x() + pullDirection.width());
-    int y = static_cast<int>(touchPoint.y() + pullDirection.height());
-    IntPoint point(x, y);
-
-    if (quad.containsPoint(point)) {
-        adjustedPoint = point;
-        return true;
-    }
-    return false;
+    return quad.containsPoint(adjustedPoint);
 }
 
 // A generic function for finding the target node with the lowest distance metric. A distance metric here is the result
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to