diff options
author | allan.jensen@nokia.com <allan.jensen@nokia.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2012-09-17 15:02:41 +0000 |
---|---|---|
committer | allan.jensen@nokia.com <allan.jensen@nokia.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2012-09-17 15:02:41 +0000 |
commit | 599d33ceb61725336b7b7dd62b6480c6b0bb1622 (patch) | |
tree | 338e256cada8e8a8efeb7f2877369ca2431fa5eb /third_party/WebKit | |
parent | 815d3df21d44083d29b9bd2bfba24b31d42e9f5d (diff) | |
download | chromium_src-599d33ceb61725336b7b7dd62b6480c6b0bb1622.zip chromium_src-599d33ceb61725336b7b7dd62b6480c6b0bb1622.tar.gz chromium_src-599d33ceb61725336b7b7dd62b6480c6b0bb1622.tar.bz2 |
[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:
git-svn-id: svn://svn.chromium.org/blink/trunk@128757 bbb929c8-8fbe-4397-9dbb-9b2b20218538
Diffstat (limited to 'third_party/WebKit')
6 files changed, 82 insertions, 27 deletions
diff --git a/third_party/WebKit/LayoutTests/ChangeLog b/third_party/WebKit/LayoutTests/ChangeLog index ea09efe..47f4135 100644 --- a/third_party/WebKit/LayoutTests/ChangeLog +++ b/third_party/WebKit/LayoutTests/ChangeLog @@ -1,3 +1,17 @@ +2012-09-17 Allan Sandfeld Jensen <allan.jensen@nokia.com> + + [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 <christophe.dumez@intel.com> [EFL] Clean up Skipped list diff --git a/third_party/WebKit/LayoutTests/touchadjustment/resources/touchadjustment.js b/third_party/WebKit/LayoutTests/touchadjustment/resources/touchadjustment.js index 547546c..f9b7d9d 100644 --- a/third_party/WebKit/LayoutTests/touchadjustment/resources/touchadjustment.js +++ b/third_party/WebKit/LayoutTests/touchadjustment/resources/touchadjustment.js @@ -64,7 +64,6 @@ function shouldBeWithin(adjustedPoint, targetArea) { } } - function testTouchPoint(touchpoint, targetNode, allowTextNodes) { var adjustedNode = internals.touchNodeAdjustedToBestClickableNode(touchpoint.left, touchpoint.top, touchpoint.width, touchpoint.height, document); @@ -81,6 +80,12 @@ function testTouchPointContextMenu(touchpoint, targetNode, allowTextNodes) 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); diff --git a/third_party/WebKit/LayoutTests/touchadjustment/rotated-node-expected.txt b/third_party/WebKit/LayoutTests/touchadjustment/rotated-node-expected.txt index f035cb7..87f5f84 100644 --- a/third_party/WebKit/LayoutTests/touchadjustment/rotated-node-expected.txt +++ b/third_party/WebKit/LayoutTests/touchadjustment/rotated-node-expected.txt @@ -20,6 +20,12 @@ PASS adjusted node was DIV#rotated. 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 diff --git a/third_party/WebKit/LayoutTests/touchadjustment/rotated-node.html b/third_party/WebKit/LayoutTests/touchadjustment/rotated-node.html index 3401637..372582f 100644 --- a/third_party/WebKit/LayoutTests/touchadjustment/rotated-node.html +++ b/third_party/WebKit/LayoutTests/touchadjustment/rotated-node.html @@ -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'; } } diff --git a/third_party/WebKit/Source/WebCore/ChangeLog b/third_party/WebKit/Source/WebCore/ChangeLog index a7105a9..e987e30 100644 --- a/third_party/WebKit/Source/WebCore/ChangeLog +++ b/third_party/WebKit/Source/WebCore/ChangeLog @@ -1,3 +1,18 @@ +2012-09-17 Allan Sandfeld Jensen <allan.jensen@nokia.com> + + [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 <yurys@chromium.org> Unreviewed. Fix Mac compilation. diff --git a/third_party/WebKit/Source/WebCore/page/TouchAdjustment.cpp b/third_party/WebKit/Source/WebCore/page/TouchAdjustment.cpp index 1dd3492..4aeb343 100644 --- a/third_party/WebKit/Source/WebCore/page/TouchAdjustment.cpp +++ b/third_party/WebKit/Source/WebCore/page/TouchAdjustment.cpp @@ -357,6 +357,20 @@ FloatPoint contentsToWindow(FrameView *view, FloatPoint pt) 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 @@ bool snapTo(const SubtargetGeometry& geom, const IntPoint& touchPoint, const Int 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 @@ bool snapTo(const SubtargetGeometry& geom, const IntPoint& touchPoint, const Int } // 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); - - FloatSize pullDirection = center - touchPoint; - float distanceToCenter = pullDirection.diagonalLength(); + FloatPoint center = quad.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); + adjustPointToRect(center, touchArea); + adjustedPoint = roundedIntPoint(center); - 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 |