summaryrefslogtreecommitdiff
path: root/Source/WebCore/page/TouchAdjustment.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-09-18 15:53:33 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2012-09-18 15:53:33 +0200
commit6bbb7fbbac94d0f511a7bd0cbd50854ab643bfb2 (patch)
treed9c68d1cca0b3e352f1e438561f3e504e641a08f /Source/WebCore/page/TouchAdjustment.cpp
parentd0424a769059c84ae20beb3c217812792ea6726b (diff)
downloadqtwebkit-6bbb7fbbac94d0f511a7bd0cbd50854ab643bfb2.tar.gz
Imported WebKit commit c7503cef7ecb236730d1309676ab9fc723fd061d (http://svn.webkit.org/repository/webkit/trunk@128886)
New snapshot with various build fixes
Diffstat (limited to 'Source/WebCore/page/TouchAdjustment.cpp')
-rw-r--r--Source/WebCore/page/TouchAdjustment.cpp48
1 files changed, 23 insertions, 25 deletions
diff --git a/Source/WebCore/page/TouchAdjustment.cpp b/Source/WebCore/page/TouchAdjustment.cpp
index 1dd349273..4aeb343af 100644
--- a/Source/WebCore/page/TouchAdjustment.cpp
+++ b/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