Changeset 167836 in webkit


Ignore:
Timestamp:
Apr 25, 2014 5:12:29 PM (10 years ago)
Author:
benjamin@webkit.org
Message:

[iOS][WK2] Add an intermediary view to do the target transform and adjustment transform
https://bugs.webkit.org/show_bug.cgi?id=132175

Patch by Benjamin Poulain <bpoulain@apple.com> on 2014-04-25
Reviewed by Enrica Casucci.

Some utility views of WKContentView account for the transforms between the content view
and the utility view.

Since the dynamic resize relies on setting subLayerTransforms, it is getting in the way.

This patch adds a layer in between for the animation. That way the content view remains
unscaled.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _didCommitLayerTree:WebKit::]):
(-[WKWebView _dynamicViewportUpdateChangedTargetToScale:position:]):
(-[WKWebView _beginAnimatedResizeWithUpdates:]):
(-[WKWebView _endAnimatedResize]):

Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r167835 r167836  
     12014-04-25  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        [iOS][WK2] Add an intermediary view to do the target transform and adjustment transform
     4        https://bugs.webkit.org/show_bug.cgi?id=132175
     5
     6        Reviewed by Enrica Casucci.
     7
     8        Some utility views of WKContentView account for the transforms between the content view
     9        and the utility view.
     10
     11        Since the dynamic resize relies on setting subLayerTransforms, it is getting in the way.
     12
     13        This patch adds a layer in between for the animation. That way the content view remains
     14        unscaled.
     15
     16        * UIProcess/API/Cocoa/WKWebView.mm:
     17        (-[WKWebView _didCommitLayerTree:WebKit::]):
     18        (-[WKWebView _dynamicViewportUpdateChangedTargetToScale:position:]):
     19        (-[WKWebView _beginAnimatedResizeWithUpdates:]):
     20        (-[WKWebView _endAnimatedResize]):
     21
    1222014-04-25  Enrica Casucci  <enrica@apple.com>
    223
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r167735 r167836  
    107107    BOOL _isAnimatingResize;
    108108    CATransform3D _resizeAnimationTransformAdjustments;
     109    RetainPtr<UIView> _resizeAnimationView;
    109110    CGFloat _lastAdjustmentForScroller;
    110111    CGFloat _keyboardVerticalOverlap;
     
    459460
    460461    if (_isAnimatingResize) {
    461         [_contentView layer].sublayerTransform = _resizeAnimationTransformAdjustments;
     462        [_resizeAnimationView layer].sublayerTransform = _resizeAnimationTransformAdjustments;
    462463        return;
    463464    }
     
    484485{
    485486    if (_isAnimatingResize) {
    486         double currentTargetScale = [[_contentView layer] affineTransform].a;
     487        CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
     488        double currentTargetScale = animatingScaleTarget * [[_contentView layer] transform].m11;
    487489        double scale = newScale / currentTargetScale;
    488490        _resizeAnimationTransformAdjustments = CATransform3DMakeScale(scale, scale, 0);
     
    493495        CGPoint currentContentOffset = [_scrollView contentOffset];
    494496
    495         _resizeAnimationTransformAdjustments.m41 = (currentContentOffset.x - newContentOffset.x) / currentTargetScale;
    496         _resizeAnimationTransformAdjustments.m42 = (currentContentOffset.y - newContentOffset.y) / currentTargetScale;
     497        _resizeAnimationTransformAdjustments.m41 = (currentContentOffset.x - newContentOffset.x) / animatingScaleTarget;
     498        _resizeAnimationTransformAdjustments.m42 = (currentContentOffset.y - newContentOffset.y) / animatingScaleTarget;
    497499    }
    498500}
     
    13301332    _resizeAnimationTransformAdjustments = CATransform3DIdentity;
    13311333
     1334    _resizeAnimationView = adoptNS([[UIView alloc] init]);
     1335    [_scrollView addSubview:_resizeAnimationView.get()];
     1336    [_resizeAnimationView addSubview:_contentView.get()];
     1337
    13321338    CGRect oldBounds = self.bounds;
    13331339    CGSize oldMinimumLayoutSize = oldBounds.size;
     
    13541360
    13551361    // Compute the new scale to keep the current content width in the scrollview.
    1356     CGFloat oldWebViewWidthInContentViewCoordinates = oldBounds.size.width / contentZoomScale(self);
     1362    CGFloat currentScale = contentZoomScale(self);
     1363    CGFloat oldWebViewWidthInContentViewCoordinates = oldBounds.size.width / currentScale;
    13571364    CGFloat visibleContentViewWidthInContentCoordinates = std::min(contentSizeInContentViewCoordinates.width, oldWebViewWidthInContentViewCoordinates);
    13581365    CGFloat targetScale = newBounds.size.width / visibleContentViewWidthInContentCoordinates;
    1359     [_scrollView setZoomScale:targetScale];
     1366    CGFloat resizeAnimationViewAnimationScale = targetScale / currentScale;
     1367    [_resizeAnimationView setTransform:CGAffineTransformMakeScale(resizeAnimationViewAnimationScale, resizeAnimationViewAnimationScale)];
    13601368
    13611369    // Compute a new position to keep the content centered.
     
    14001408{
    14011409    if (!_customContentView) {
     1410        [_scrollView addSubview:_contentView.get()];
     1411
    14021412        CALayer *contentViewLayer = [_contentView layer];
    14031413        CATransform3D resizeAnimationTransformAdjustements = _resizeAnimationTransformAdjustments;
     
    14051415        contentViewLayer.sublayerTransform = CATransform3DIdentity;
    14061416
    1407         CGFloat currentScale = contentZoomScale(self);
     1417        CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
     1418        CGFloat currentScale = [[_resizeAnimationView layer] transform].m11 * [[_contentView layer] transform].m11;
    14081419        CGPoint currentScrollOffset = [_scrollView contentOffset];
    14091420        [_scrollView setZoomScale:adjustmentScale * currentScale];
    14101421
    1411         double horizontalScrollAdjustement = _resizeAnimationTransformAdjustments.m41 * currentScale;
    1412         double verticalScrollAdjustment = _resizeAnimationTransformAdjustments.m42 * currentScale;
     1422        double horizontalScrollAdjustement = _resizeAnimationTransformAdjustments.m41 * animatingScaleTarget;
     1423        double verticalScrollAdjustment = _resizeAnimationTransformAdjustments.m42 * animatingScaleTarget;
    14131424
    14141425        [_scrollView setContentOffset:CGPointMake(currentScrollOffset.x - horizontalScrollAdjustement, currentScrollOffset.y - verticalScrollAdjustment)];
     1426
     1427        [_resizeAnimationView removeFromSuperview];
     1428        _resizeAnimationView = nil;
    14151429    }
    14161430
Note: See TracChangeset for help on using the changeset viewer.