Changeset 169109 in webkit


Ignore:
Timestamp:
May 20, 2014 6:56:27 AM (10 years ago)
Author:
Antti Koivisto
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.

Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r169095 r169109  
     12014-05-20  Antti Koivisto  <antti@apple.com>
     2
     3        Double-tap zoom does not take obscuring insets into account
     4        https://bugs.webkit.org/show_bug.cgi?id=133116
     5        <rdar://problem/16765604>
     6
     7        Reviewed by Anders Carlsson.
     8
     9        * UIProcess/API/Cocoa/WKWebView.mm:
     10        (-[WKWebView _zoomToRect:WebCore::atScale:origin:WebCore::]):
     11       
     12            Compute the zoom target taking insets into account.
     13
    1142014-05-19  Gavin Barraclough  <baraclough@apple.com>
    215
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r169023 r169109  
    597597- (void)_zoomToRect:(WebCore::FloatRect)targetRect atScale:(double)scale origin:(WebCore::FloatPoint)origin
    598598{
    599     WebCore::FloatSize unobscuredContentSize([self _contentRectForUserInteraction].size);
    600     WebCore::FloatSize targetRectSizeAfterZoom = targetRect.size();
    601     targetRectSizeAfterZoom.scale(scale);
    602 
    603     // Center the target rect in the scroll view.
    604     // If the target doesn't fit in the scroll view, center on the gesture location instead.
    605     WebCore::FloatPoint zoomCenter = targetRect.center();
    606 
    607     if (targetRectSizeAfterZoom.width() > unobscuredContentSize.width())
    608         zoomCenter.setX(origin.x());
    609     if (targetRectSizeAfterZoom.height() > unobscuredContentSize.height())
    610         zoomCenter.setY(origin.y());
    611 
    612     [self _zoomToPoint:zoomCenter atScale:scale];
     599    // FIMXE: Some of this could be shared with _scrollToRect.
     600    const double visibleRectScaleChange = contentZoomScale(self) / scale;
     601    const WebCore::FloatRect visibleRect([self convertRect:self.bounds toView:_contentView.get()]);
     602    const WebCore::FloatRect unobscuredRect([self _contentRectForUserInteraction]);
     603
     604    const WebCore::FloatSize topLeftObscuredInsetAfterZoom((unobscuredRect.minXMinYCorner() - visibleRect.minXMinYCorner()) * visibleRectScaleChange);
     605    const WebCore::FloatSize bottomRightObscuredInsetAfterZoom((visibleRect.maxXMaxYCorner() - unobscuredRect.maxXMaxYCorner()) * visibleRectScaleChange);
     606
     607    const WebCore::FloatSize unobscuredRectSizeAfterZoom(unobscuredRect.size() * visibleRectScaleChange);
     608
     609    // Center to the target rect.
     610    WebCore::FloatPoint unobscuredRectLocationAfterZoom = targetRect.location() - (unobscuredRectSizeAfterZoom - targetRect.size()) * 0.5;
     611
     612    // Center to the tap point instead in case the target rect won't fit in a direction.
     613    if (targetRect.width() > unobscuredRectSizeAfterZoom.width())
     614        unobscuredRectLocationAfterZoom.setX(origin.x() - unobscuredRectSizeAfterZoom.width() / 2);
     615    if (targetRect.height() > unobscuredRectSizeAfterZoom.height())
     616        unobscuredRectLocationAfterZoom.setY(origin.y() - unobscuredRectSizeAfterZoom.height() / 2);
     617
     618    // We have computed where we want the unobscured rect to be. Now adjust for the obscuring insets.
     619    WebCore::FloatRect visibleRectAfterZoom(unobscuredRectLocationAfterZoom, unobscuredRectSizeAfterZoom);
     620    visibleRectAfterZoom.move(-topLeftObscuredInsetAfterZoom);
     621    visibleRectAfterZoom.expand(topLeftObscuredInsetAfterZoom + bottomRightObscuredInsetAfterZoom);
     622
     623    [self _zoomToPoint:visibleRectAfterZoom.center() atScale:scale];
    613624}
    614625
Note: See TracChangeset for help on using the changeset viewer.