Changeset 128757 in webkit


Ignore:
Timestamp:
Sep 17, 2012 8:02:41 AM (12 years ago)
Author:
allan.jensen@nokia.com
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:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r128753 r128757  
     12012-09-17  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
     2
     3        [TouchAdjustment] Adjusted point outside bounds for non-rectilinear targets
     4        https://bugs.webkit.org/show_bug.cgi?id=96098
     5
     6        Reviewed by Antonio Gomes.
     7
     8        Expands the test of rotated nodes to also perform checks of the validity of the adjusted points.
     9
     10        * touchadjustment/resources/touchadjustment.js:
     11        (adjustTouchPoint):
     12        * touchadjustment/rotated-node-expected.txt:
     13        * touchadjustment/rotated-node.html:
     14
    1152012-09-17  Christophe Dumez  <christophe.dumez@intel.com>
    216
  • trunk/LayoutTests/touchadjustment/resources/touchadjustment.js

    r126284 r128757  
    6565}
    6666
    67 
    6867function testTouchPoint(touchpoint, targetNode, allowTextNodes)
    6968{
     
    8079        adjustedNode = adjustedNode.parentNode;
    8180    shouldBeNode(adjustedNode, targetNode);
     81}
     82
     83function adjustTouchPoint(touchpoint)
     84{
     85    var adjustedPoint = internals.touchPositionAdjustedToBestClickableNode(touchpoint.left, touchpoint.top, touchpoint.width, touchpoint.height, document);
     86    return adjustedPoint;
    8287}
    8388
  • trunk/LayoutTests/touchadjustment/rotated-node-expected.txt

    r124351 r128757  
    2121PASS adjusted node was DIV#container.
    2222PASS adjusted node was DIV#container.
     23
     24Adjusted point within bounds
     25PASS adjusted point was within (0,-20)x(40,40)
     26PASS adjusted point was within (40,40)x(40,40)
     27PASS adjusted point was within (-40,40)x(80,40)
     28PASS adjusted point was within (50,-20)x(40,80)
    2329PASS successfullyParsed is true
    2430
  • trunk/LayoutTests/touchadjustment/rotated-node.html

    r124351 r128757  
    4747    {
    4848        debug('Direct Touches');
    49        
     49
    5050        testTouchPoint(touchPoint(30, 30, 20), e.rotated);
    5151        testTouchPoint(touchPoint(20, 30, 20), e.rotated);
     
    7676    }
    7777
     78    function testAdjustedPoints()
     79    {
     80        debug('\nAdjusted point within bounds');
     81        var adjustedPoint = adjustTouchPoint(touchPoint(20, 0, 20))
     82        shouldBeWithin(adjustedPoint, touchPoint(20, 0, 20));
     83
     84        adjustedPoint = adjustTouchPoint(touchPoint(60, 60, 20))
     85        shouldBeWithin(adjustedPoint, touchPoint(60, 60, 20));
     86
     87        adjustedPoint = adjustTouchPoint(touchPoint(0, 60, 40, 20))
     88        shouldBeWithin(adjustedPoint, touchPoint(0, 60, 40, 20));
     89
     90        adjustedPoint = adjustTouchPoint(touchPoint(70, 20, 20, 40))
     91        shouldBeWithin(adjustedPoint, touchPoint(70, 20, 20, 40));
     92    }
     93
    7894    function runTests()
    7995    {
     
    8399            testDirectTouches();
    84100            testAdjustedTouches();
     101            testAdjustedPoints()
    85102            e.container.style.display = 'none';
    86103        }
  • trunk/Source/WebCore/ChangeLog

    r128754 r128757  
     12012-09-17  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
     2
     3        [TouchAdjustment] Adjusted point outside bounds for non-rectilinear targets
     4        https://bugs.webkit.org/show_bug.cgi?id=96098
     5
     6        Reviewed by Antonio Gomes.
     7
     8        Simplifies how snapTo tries to restrict the adjustment to the touch-area, and
     9        at the same fix it to give better guarantees.
     10
     11        Test: touchadjustment/rotated-node.html
     12
     13        * page/TouchAdjustment.cpp:
     14        (WebCore::TouchAdjustment::snapTo):
     15
    1162012-09-17  Yury Semikhatsky  <yurys@chromium.org>
    217
  • trunk/Source/WebCore/page/TouchAdjustment.cpp

    r128222 r128757  
    358358}
    359359
     360// Adjusts 'point' to the nearest point inside rect, and leaves it unchanged if already inside.
     361void adjustPointToRect(FloatPoint& point, const FloatRect& rect)
     362{
     363    if (point.x() < rect.x())
     364        point.setX(rect.x());
     365    else if (point.x() > rect.maxX())
     366        point.setX(rect.maxX());
     367
     368    if (point.y() < rect.y())
     369        point.setY(rect.y());
     370    else if (point.y() > rect.maxY())
     371        point.setY(rect.maxY());
     372}
     373
    360374bool snapTo(const SubtargetGeometry& geom, const IntPoint& touchPoint, const IntRect& touchArea, IntPoint& adjustedPoint)
    361375{
     
    379393    }
    380394
    381     // Non-rectilinear element.
     395    // The following code tries to adjust the point to place inside a both the touchArea and the non-rectilinear quad.
     396    // FIXME: This will return the point inside the touch area that is the closest to the quad center, but does not
     397    // guarantee that the point will be inside the quad. Corner-cases exist where the quad will intersect but this
     398    // will fail to adjust the point to somewhere in the intersection.
     399
    382400    // Convert quad from content to window coordinates.
    383401    FloatPoint p1 = contentsToWindow(view, quad.p1());
     
    393411
    394412    // Pull point towards the center of the element.
    395     float cx = 0.25 * (p1.x() + p2.x() + p3.x() + p4.x());
    396     float cy = 0.25 * (p1.y() + p2.y() + p3.y() + p4.y());
    397     FloatPoint center = FloatPoint(cx, cy);
    398 
    399     FloatSize pullDirection = center - touchPoint;
    400     float distanceToCenter = pullDirection.diagonalLength();
    401 
    402     // Use distance from center to corner of touch area to limit adjustment distance.
    403     float dx = 0.5f * touchArea.width();
    404     float dy = 0.5f * touchArea.height();
    405     float touchRadius = sqrt(dx * dx + dy * dy);
    406 
    407     float scaleFactor = touchRadius / distanceToCenter;
    408     if (scaleFactor > 1)
    409         scaleFactor = 1;
    410     pullDirection.scale(scaleFactor);
    411 
    412     int x = static_cast<int>(touchPoint.x() + pullDirection.width());
    413     int y = static_cast<int>(touchPoint.y() + pullDirection.height());
    414     IntPoint point(x, y);
    415 
    416     if (quad.containsPoint(point)) {
    417         adjustedPoint = point;
    418         return true;
    419     }
    420     return false;
     413    FloatPoint center = quad.center();
     414
     415    adjustPointToRect(center, touchArea);
     416    adjustedPoint = roundedIntPoint(center);
     417
     418    return quad.containsPoint(adjustedPoint);
    421419}
    422420
Note: See TracChangeset for help on using the changeset viewer.