[iOS][WK2] Add an intermediary view to do the target transform and adjustment transform
authorbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 26 Apr 2014 00:12:29 +0000 (00:12 +0000)
committerbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 26 Apr 2014 00:12:29 +0000 (00:12 +0000)
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]):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

index 0faeada..50ed374 100644 (file)
@@ -1,3 +1,24 @@
+2014-04-25  Benjamin Poulain  <bpoulain@apple.com>
+
+        [iOS][WK2] Add an intermediary view to do the target transform and adjustment transform
+        https://bugs.webkit.org/show_bug.cgi?id=132175
+
+        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]):
+
 2014-04-25  Enrica Casucci  <enrica@apple.com>
 
         REGRESSION (iOS WebKit2): Selection is not being repainted during live resize.
 2014-04-25  Enrica Casucci  <enrica@apple.com>
 
         REGRESSION (iOS WebKit2): Selection is not being repainted during live resize.
index 5f29c31..366ca68 100644 (file)
     bool _isChangingObscuredInsetsInteractively;
     BOOL _isAnimatingResize;
     CATransform3D _resizeAnimationTransformAdjustments;
     bool _isChangingObscuredInsetsInteractively;
     BOOL _isAnimatingResize;
     CATransform3D _resizeAnimationTransformAdjustments;
+    RetainPtr<UIView> _resizeAnimationView;
     CGFloat _lastAdjustmentForScroller;
     CGFloat _keyboardVerticalOverlap;
 
     CGFloat _lastAdjustmentForScroller;
     CGFloat _keyboardVerticalOverlap;
 
@@ -458,7 +459,7 @@ static CGFloat contentZoomScale(WKWebView* webView)
         return;
 
     if (_isAnimatingResize) {
         return;
 
     if (_isAnimatingResize) {
-        [_contentView layer].sublayerTransform = _resizeAnimationTransformAdjustments;
+        [_resizeAnimationView layer].sublayerTransform = _resizeAnimationTransformAdjustments;
         return;
     }
 
         return;
     }
 
@@ -483,7 +484,8 @@ static CGFloat contentZoomScale(WKWebView* webView)
 - (void)_dynamicViewportUpdateChangedTargetToScale:(double)newScale position:(CGPoint)newScrollPosition
 {
     if (_isAnimatingResize) {
 - (void)_dynamicViewportUpdateChangedTargetToScale:(double)newScale position:(CGPoint)newScrollPosition
 {
     if (_isAnimatingResize) {
-        double currentTargetScale = [[_contentView layer] affineTransform].a;
+        CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
+        double currentTargetScale = animatingScaleTarget * [[_contentView layer] transform].m11;
         double scale = newScale / currentTargetScale;
         _resizeAnimationTransformAdjustments = CATransform3DMakeScale(scale, scale, 0);
 
         double scale = newScale / currentTargetScale;
         _resizeAnimationTransformAdjustments = CATransform3DMakeScale(scale, scale, 0);
 
@@ -492,8 +494,8 @@ static CGFloat contentZoomScale(WKWebView* webView)
         newContentOffset.y -= _obscuredInsets.top;
         CGPoint currentContentOffset = [_scrollView contentOffset];
 
         newContentOffset.y -= _obscuredInsets.top;
         CGPoint currentContentOffset = [_scrollView contentOffset];
 
-        _resizeAnimationTransformAdjustments.m41 = (currentContentOffset.x - newContentOffset.x) / currentTargetScale;
-        _resizeAnimationTransformAdjustments.m42 = (currentContentOffset.y - newContentOffset.y) / currentTargetScale;
+        _resizeAnimationTransformAdjustments.m41 = (currentContentOffset.x - newContentOffset.x) / animatingScaleTarget;
+        _resizeAnimationTransformAdjustments.m42 = (currentContentOffset.y - newContentOffset.y) / animatingScaleTarget;
     }
 }
 
     }
 }
 
@@ -1329,6 +1331,10 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
     _isAnimatingResize = YES;
     _resizeAnimationTransformAdjustments = CATransform3DIdentity;
 
     _isAnimatingResize = YES;
     _resizeAnimationTransformAdjustments = CATransform3DIdentity;
 
+    _resizeAnimationView = adoptNS([[UIView alloc] init]);
+    [_scrollView addSubview:_resizeAnimationView.get()];
+    [_resizeAnimationView addSubview:_contentView.get()];
+
     CGRect oldBounds = self.bounds;
     CGSize oldMinimumLayoutSize = oldBounds.size;
     if (_hasStaticMinimumLayoutSize)
     CGRect oldBounds = self.bounds;
     CGSize oldMinimumLayoutSize = oldBounds.size;
     if (_hasStaticMinimumLayoutSize)
@@ -1353,10 +1359,12 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
     [_scrollView setMaximumZoomScale:std::max(newBounds.size.width / contentSizeInContentViewCoordinates.width, [_scrollView maximumZoomScale])];
 
     // Compute the new scale to keep the current content width in the scrollview.
     [_scrollView setMaximumZoomScale:std::max(newBounds.size.width / contentSizeInContentViewCoordinates.width, [_scrollView maximumZoomScale])];
 
     // Compute the new scale to keep the current content width in the scrollview.
-    CGFloat oldWebViewWidthInContentViewCoordinates = oldBounds.size.width / contentZoomScale(self);
+    CGFloat currentScale = contentZoomScale(self);
+    CGFloat oldWebViewWidthInContentViewCoordinates = oldBounds.size.width / currentScale;
     CGFloat visibleContentViewWidthInContentCoordinates = std::min(contentSizeInContentViewCoordinates.width, oldWebViewWidthInContentViewCoordinates);
     CGFloat targetScale = newBounds.size.width / visibleContentViewWidthInContentCoordinates;
     CGFloat visibleContentViewWidthInContentCoordinates = std::min(contentSizeInContentViewCoordinates.width, oldWebViewWidthInContentViewCoordinates);
     CGFloat targetScale = newBounds.size.width / visibleContentViewWidthInContentCoordinates;
-    [_scrollView setZoomScale:targetScale];
+    CGFloat resizeAnimationViewAnimationScale = targetScale / currentScale;
+    [_resizeAnimationView setTransform:CGAffineTransformMakeScale(resizeAnimationViewAnimationScale, resizeAnimationViewAnimationScale)];
 
     // Compute a new position to keep the content centered.
     CGPoint originalContentCenter = oldUnobscuredContentRect.center();
 
     // Compute a new position to keep the content centered.
     CGPoint originalContentCenter = oldUnobscuredContentRect.center();
@@ -1399,19 +1407,25 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
 - (void)_endAnimatedResize
 {
     if (!_customContentView) {
 - (void)_endAnimatedResize
 {
     if (!_customContentView) {
+        [_scrollView addSubview:_contentView.get()];
+
         CALayer *contentViewLayer = [_contentView layer];
         CATransform3D resizeAnimationTransformAdjustements = _resizeAnimationTransformAdjustments;
         CGFloat adjustmentScale = resizeAnimationTransformAdjustements.m11;
         contentViewLayer.sublayerTransform = CATransform3DIdentity;
 
         CALayer *contentViewLayer = [_contentView layer];
         CATransform3D resizeAnimationTransformAdjustements = _resizeAnimationTransformAdjustments;
         CGFloat adjustmentScale = resizeAnimationTransformAdjustements.m11;
         contentViewLayer.sublayerTransform = CATransform3DIdentity;
 
-        CGFloat currentScale = contentZoomScale(self);
+        CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
+        CGFloat currentScale = [[_resizeAnimationView layer] transform].m11 * [[_contentView layer] transform].m11;
         CGPoint currentScrollOffset = [_scrollView contentOffset];
         [_scrollView setZoomScale:adjustmentScale * currentScale];
 
         CGPoint currentScrollOffset = [_scrollView contentOffset];
         [_scrollView setZoomScale:adjustmentScale * currentScale];
 
-        double horizontalScrollAdjustement = _resizeAnimationTransformAdjustments.m41 * currentScale;
-        double verticalScrollAdjustment = _resizeAnimationTransformAdjustments.m42 * currentScale;
+        double horizontalScrollAdjustement = _resizeAnimationTransformAdjustments.m41 * animatingScaleTarget;
+        double verticalScrollAdjustment = _resizeAnimationTransformAdjustments.m42 * animatingScaleTarget;
 
         [_scrollView setContentOffset:CGPointMake(currentScrollOffset.x - horizontalScrollAdjustement, currentScrollOffset.y - verticalScrollAdjustment)];
 
         [_scrollView setContentOffset:CGPointMake(currentScrollOffset.x - horizontalScrollAdjustement, currentScrollOffset.y - verticalScrollAdjustment)];
+
+        [_resizeAnimationView removeFromSuperview];
+        _resizeAnimationView = nil;
     }
 
     _resizeAnimationTransformAdjustments = CATransform3DIdentity;
     }
 
     _resizeAnimationTransformAdjustments = CATransform3DIdentity;