Smart magnification gesture sometimes shoots to the middle of the page
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Apr 2015 18:57:25 +0000 (18:57 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Apr 2015 18:57:25 +0000 (18:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143296
<rdar://problem/18209280>

Reviewed by Dean Jackson.

* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::didCollectGeometryForSmartMagnificationGesture):
Constrain the target rect to the viewport, and if it had overflowed the viewport,
scroll halfway towards the gesture origin.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182245 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm

index 617649e..aac8395 100644 (file)
@@ -1,3 +1,16 @@
+2015-04-01  Timothy Horton  <timothy_horton@apple.com>
+
+        Smart magnification gesture sometimes shoots to the middle of the page
+        https://bugs.webkit.org/show_bug.cgi?id=143296
+        <rdar://problem/18209280>
+
+        Reviewed by Dean Jackson.
+
+        * UIProcess/mac/ViewGestureControllerMac.mm:
+        (WebKit::ViewGestureController::didCollectGeometryForSmartMagnificationGesture):
+        Constrain the target rect to the viewport, and if it had overflowed the viewport,
+        scroll halfway towards the gesture origin.
+
 2015-03-31  Simon Fraser  <simon.fraser@apple.com>
 
         Remove scrolling tree dependency on wheel event handler counts, and use fast scrolling even when there are wheel handlers
index 69d2c6b..5546e51 100644 (file)
@@ -224,10 +224,20 @@ void ViewGestureController::didCollectGeometryForSmartMagnificationGesture(Float
 
     double targetMagnification = visibleContentRect.width() / unscaledTargetRect.width();
 
+    FloatRect unscaledVisibleContentRect = visibleContentRect;
+    unscaledVisibleContentRect.scale(1 / currentScaleFactor);
+    FloatRect viewportConstrainedUnscaledTargetRect = unscaledTargetRect;
+    viewportConstrainedUnscaledTargetRect.intersect(unscaledVisibleContentRect);
+
+    if (unscaledTargetRect.width() > viewportConstrainedUnscaledTargetRect.width())
+        viewportConstrainedUnscaledTargetRect.setX(unscaledVisibleContentRect.x() + (origin.x() / currentScaleFactor) - viewportConstrainedUnscaledTargetRect.width() / 2);
+    if (unscaledTargetRect.height() > viewportConstrainedUnscaledTargetRect.height())
+        viewportConstrainedUnscaledTargetRect.setY(unscaledVisibleContentRect.y() + (origin.y() / currentScaleFactor) - viewportConstrainedUnscaledTargetRect.height() / 2);
+
     // For replaced elements like images, we want to fit the whole element
     // in the view, so scale it down enough to make both dimensions fit if possible.
     if (isReplacedElement)
-        targetMagnification = std::min(targetMagnification, static_cast<double>(visibleContentRect.height() / unscaledTargetRect.height()));
+        targetMagnification = std::min(targetMagnification, static_cast<double>(visibleContentRect.height() / viewportConstrainedUnscaledTargetRect.height()));
 
     targetMagnification = std::min(std::max(targetMagnification, minMagnification), maxMagnification);
 
@@ -241,7 +251,7 @@ void ViewGestureController::didCollectGeometryForSmartMagnificationGesture(Float
             targetMagnification = 1;
     }
 
-    FloatRect targetRect(unscaledTargetRect);
+    FloatRect targetRect(viewportConstrainedUnscaledTargetRect);
     targetRect.scale(targetMagnification);
     FloatPoint targetOrigin(visibleContentRect.center());
     targetOrigin.moveBy(-targetRect.center());