Title: [169109] trunk/Source/WebKit2
Revision
169109
Author
[email protected]
Date
2014-05-20 06:56:27 -0700 (Tue, 20 May 2014)

Log Message

Double-tap zoom does not take obscuring insets into account
https://bugs.webkit.org/show_bug.cgi?id=133116
<rdar://problem/16765604>

Reviewed by Anders Carlsson.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _zoomToRect:WebCore::atScale:origin:WebCore::]):
        
    Compute the zoom target taking insets into account.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (169108 => 169109)


--- trunk/Source/WebKit2/ChangeLog	2014-05-20 13:15:50 UTC (rev 169108)
+++ trunk/Source/WebKit2/ChangeLog	2014-05-20 13:56:27 UTC (rev 169109)
@@ -1,3 +1,16 @@
+2014-05-20  Antti Koivisto  <[email protected]>
+
+        Double-tap zoom does not take obscuring insets into account
+        https://bugs.webkit.org/show_bug.cgi?id=133116
+        <rdar://problem/16765604>
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _zoomToRect:WebCore::atScale:origin:WebCore::]):
+        
+            Compute the zoom target taking insets into account.
+
 2014-05-19  Gavin Barraclough  <[email protected]>
 
         WebKit2/iOS: parented view should be considered hidden if app is backgrounded

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (169108 => 169109)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-05-20 13:15:50 UTC (rev 169108)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-05-20 13:56:27 UTC (rev 169109)
@@ -596,20 +596,31 @@
 
 - (void)_zoomToRect:(WebCore::FloatRect)targetRect atScale:(double)scale origin:(WebCore::FloatPoint)origin
 {
-    WebCore::FloatSize unobscuredContentSize([self _contentRectForUserInteraction].size);
-    WebCore::FloatSize targetRectSizeAfterZoom = targetRect.size();
-    targetRectSizeAfterZoom.scale(scale);
+    // FIMXE: Some of this could be shared with _scrollToRect.
+    const double visibleRectScaleChange = contentZoomScale(self) / scale;
+    const WebCore::FloatRect visibleRect([self convertRect:self.bounds toView:_contentView.get()]);
+    const WebCore::FloatRect unobscuredRect([self _contentRectForUserInteraction]);
 
-    // Center the target rect in the scroll view.
-    // If the target doesn't fit in the scroll view, center on the gesture location instead.
-    WebCore::FloatPoint zoomCenter = targetRect.center();
+    const WebCore::FloatSize topLeftObscuredInsetAfterZoom((unobscuredRect.minXMinYCorner() - visibleRect.minXMinYCorner()) * visibleRectScaleChange);
+    const WebCore::FloatSize bottomRightObscuredInsetAfterZoom((visibleRect.maxXMaxYCorner() - unobscuredRect.maxXMaxYCorner()) * visibleRectScaleChange);
 
-    if (targetRectSizeAfterZoom.width() > unobscuredContentSize.width())
-        zoomCenter.setX(origin.x());
-    if (targetRectSizeAfterZoom.height() > unobscuredContentSize.height())
-        zoomCenter.setY(origin.y());
+    const WebCore::FloatSize unobscuredRectSizeAfterZoom(unobscuredRect.size() * visibleRectScaleChange);
 
-    [self _zoomToPoint:zoomCenter atScale:scale];
+    // Center to the target rect.
+    WebCore::FloatPoint unobscuredRectLocationAfterZoom = targetRect.location() - (unobscuredRectSizeAfterZoom - targetRect.size()) * 0.5;
+
+    // Center to the tap point instead in case the target rect won't fit in a direction.
+    if (targetRect.width() > unobscuredRectSizeAfterZoom.width())
+        unobscuredRectLocationAfterZoom.setX(origin.x() - unobscuredRectSizeAfterZoom.width() / 2);
+    if (targetRect.height() > unobscuredRectSizeAfterZoom.height())
+        unobscuredRectLocationAfterZoom.setY(origin.y() - unobscuredRectSizeAfterZoom.height() / 2);
+
+    // We have computed where we want the unobscured rect to be. Now adjust for the obscuring insets.
+    WebCore::FloatRect visibleRectAfterZoom(unobscuredRectLocationAfterZoom, unobscuredRectSizeAfterZoom);
+    visibleRectAfterZoom.move(-topLeftObscuredInsetAfterZoom);
+    visibleRectAfterZoom.expand(topLeftObscuredInsetAfterZoom + bottomRightObscuredInsetAfterZoom);
+
+    [self _zoomToPoint:visibleRectAfterZoom.center() atScale:scale];
 }
 
 static WebCore::FloatPoint constrainContentOffset(WebCore::FloatPoint contentOffset, WebCore::FloatSize contentSize, WebCore::FloatSize unobscuredContentSize)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to