<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[167836] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/167836">167836</a></dd>
<dt>Author</dt> <dd>benjamin@webkit.org</dd>
<dt>Date</dt> <dd>2014-04-25 17:12:29 -0700 (Fri, 25 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[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 &lt;bpoulain@apple.com&gt; 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]):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (167835 => 167836)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-04-26 00:06:15 UTC (rev 167835)
+++ trunk/Source/WebKit2/ChangeLog        2014-04-26 00:12:29 UTC (rev 167836)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2014-04-25  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
+
+        [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]):
+
</ins><span class="cx"> 2014-04-25  Enrica Casucci  &lt;enrica@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION (iOS WebKit2): Selection is not being repainted during live resize.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (167835 => 167836)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-04-26 00:06:15 UTC (rev 167835)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-04-26 00:12:29 UTC (rev 167836)
</span><span class="lines">@@ -106,6 +106,7 @@
</span><span class="cx">     bool _isChangingObscuredInsetsInteractively;
</span><span class="cx">     BOOL _isAnimatingResize;
</span><span class="cx">     CATransform3D _resizeAnimationTransformAdjustments;
</span><ins>+    RetainPtr&lt;UIView&gt; _resizeAnimationView;
</ins><span class="cx">     CGFloat _lastAdjustmentForScroller;
</span><span class="cx">     CGFloat _keyboardVerticalOverlap;
</span><span class="cx"> 
</span><span class="lines">@@ -458,7 +459,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (_isAnimatingResize) {
</span><del>-        [_contentView layer].sublayerTransform = _resizeAnimationTransformAdjustments;
</del><ins>+        [_resizeAnimationView layer].sublayerTransform = _resizeAnimationTransformAdjustments;
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -483,7 +484,8 @@
</span><span class="cx"> - (void)_dynamicViewportUpdateChangedTargetToScale:(double)newScale position:(CGPoint)newScrollPosition
</span><span class="cx"> {
</span><span class="cx">     if (_isAnimatingResize) {
</span><del>-        double currentTargetScale = [[_contentView layer] affineTransform].a;
</del><ins>+        CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
+        double currentTargetScale = animatingScaleTarget * [[_contentView layer] transform].m11;
</ins><span class="cx">         double scale = newScale / currentTargetScale;
</span><span class="cx">         _resizeAnimationTransformAdjustments = CATransform3DMakeScale(scale, scale, 0);
</span><span class="cx"> 
</span><span class="lines">@@ -492,8 +494,8 @@
</span><span class="cx">         newContentOffset.y -= _obscuredInsets.top;
</span><span class="cx">         CGPoint currentContentOffset = [_scrollView contentOffset];
</span><span class="cx"> 
</span><del>-        _resizeAnimationTransformAdjustments.m41 = (currentContentOffset.x - newContentOffset.x) / currentTargetScale;
-        _resizeAnimationTransformAdjustments.m42 = (currentContentOffset.y - newContentOffset.y) / currentTargetScale;
</del><ins>+        _resizeAnimationTransformAdjustments.m41 = (currentContentOffset.x - newContentOffset.x) / animatingScaleTarget;
+        _resizeAnimationTransformAdjustments.m42 = (currentContentOffset.y - newContentOffset.y) / animatingScaleTarget;
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1329,6 +1331,10 @@
</span><span class="cx">     _isAnimatingResize = YES;
</span><span class="cx">     _resizeAnimationTransformAdjustments = CATransform3DIdentity;
</span><span class="cx"> 
</span><ins>+    _resizeAnimationView = adoptNS([[UIView alloc] init]);
+    [_scrollView addSubview:_resizeAnimationView.get()];
+    [_resizeAnimationView addSubview:_contentView.get()];
+
</ins><span class="cx">     CGRect oldBounds = self.bounds;
</span><span class="cx">     CGSize oldMinimumLayoutSize = oldBounds.size;
</span><span class="cx">     if (_hasStaticMinimumLayoutSize)
</span><span class="lines">@@ -1353,10 +1359,12 @@
</span><span class="cx">     [_scrollView setMaximumZoomScale:std::max(newBounds.size.width / contentSizeInContentViewCoordinates.width, [_scrollView maximumZoomScale])];
</span><span class="cx"> 
</span><span class="cx">     // Compute the new scale to keep the current content width in the scrollview.
</span><del>-    CGFloat oldWebViewWidthInContentViewCoordinates = oldBounds.size.width / contentZoomScale(self);
</del><ins>+    CGFloat currentScale = contentZoomScale(self);
+    CGFloat oldWebViewWidthInContentViewCoordinates = oldBounds.size.width / currentScale;
</ins><span class="cx">     CGFloat visibleContentViewWidthInContentCoordinates = std::min(contentSizeInContentViewCoordinates.width, oldWebViewWidthInContentViewCoordinates);
</span><span class="cx">     CGFloat targetScale = newBounds.size.width / visibleContentViewWidthInContentCoordinates;
</span><del>-    [_scrollView setZoomScale:targetScale];
</del><ins>+    CGFloat resizeAnimationViewAnimationScale = targetScale / currentScale;
+    [_resizeAnimationView setTransform:CGAffineTransformMakeScale(resizeAnimationViewAnimationScale, resizeAnimationViewAnimationScale)];
</ins><span class="cx"> 
</span><span class="cx">     // Compute a new position to keep the content centered.
</span><span class="cx">     CGPoint originalContentCenter = oldUnobscuredContentRect.center();
</span><span class="lines">@@ -1399,19 +1407,25 @@
</span><span class="cx"> - (void)_endAnimatedResize
</span><span class="cx"> {
</span><span class="cx">     if (!_customContentView) {
</span><ins>+        [_scrollView addSubview:_contentView.get()];
+
</ins><span class="cx">         CALayer *contentViewLayer = [_contentView layer];
</span><span class="cx">         CATransform3D resizeAnimationTransformAdjustements = _resizeAnimationTransformAdjustments;
</span><span class="cx">         CGFloat adjustmentScale = resizeAnimationTransformAdjustements.m11;
</span><span class="cx">         contentViewLayer.sublayerTransform = CATransform3DIdentity;
</span><span class="cx"> 
</span><del>-        CGFloat currentScale = contentZoomScale(self);
</del><ins>+        CGFloat animatingScaleTarget = [[_resizeAnimationView layer] transform].m11;
+        CGFloat currentScale = [[_resizeAnimationView layer] transform].m11 * [[_contentView layer] transform].m11;
</ins><span class="cx">         CGPoint currentScrollOffset = [_scrollView contentOffset];
</span><span class="cx">         [_scrollView setZoomScale:adjustmentScale * currentScale];
</span><span class="cx"> 
</span><del>-        double horizontalScrollAdjustement = _resizeAnimationTransformAdjustments.m41 * currentScale;
-        double verticalScrollAdjustment = _resizeAnimationTransformAdjustments.m42 * currentScale;
</del><ins>+        double horizontalScrollAdjustement = _resizeAnimationTransformAdjustments.m41 * animatingScaleTarget;
+        double verticalScrollAdjustment = _resizeAnimationTransformAdjustments.m42 * animatingScaleTarget;
</ins><span class="cx"> 
</span><span class="cx">         [_scrollView setContentOffset:CGPointMake(currentScrollOffset.x - horizontalScrollAdjustement, currentScrollOffset.y - verticalScrollAdjustment)];
</span><ins>+
+        [_resizeAnimationView removeFromSuperview];
+        _resizeAnimationView = nil;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     _resizeAnimationTransformAdjustments = CATransform3DIdentity;
</span></span></pre>
</div>
</div>

</body>
</html>