diff options
Diffstat (limited to 'Source/WebCore/page/TouchAdjustment.cpp')
-rw-r--r-- | Source/WebCore/page/TouchAdjustment.cpp | 48 |
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 |