<!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>[183229] trunk/Source/WebCore</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/183229">183229</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2015-04-23 16:43:04 -0700 (Thu, 23 Apr 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Add a wrapper around the hosted AVPlayerLayer to intercept -setBounds:
https://bugs.webkit.org/show_bug.cgi?id=144129

Reviewed by Simon Fraser.

When passing the hosted AVPlayerLayer to the fullscreen controller, the new superlayer will
resize the hosted layer with a call to -setBounds:. But because this is a hosted layer, the
bonuds change has no effect. Instead, wrap the CALayerHost in another CALayer whose job it is
to intercept -setBounds: in the same way that WebAVVideoLayer did. In fact, we should just use
that wrapper class inside WebAVVideoLayer as well, to avoid duplicating code.

Drive-by Fix: Null-check m_videoElement in setVideoLayerFrame().

* platform/ios/WebVideoFullscreenInterfaceAVKit.h:
* platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
(-[WebCALayerHostWrapper setVideoSublayer:]):
(-[WebCALayerHostWrapper videoSublayer]):
(-[WebCALayerHostWrapper setBounds:]): Moved from WebAVVideoLayer.
(-[WebCALayerHostWrapper resolveBounds]): Ditto.
(-[WebAVVideoLayer setBounds:]): Moved to WebCALayerHostWrapper.
(WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal): Create the wrapper.
(WebVideoFullscreenInterfaceAVKit::cleanupFullscreenInternal): Clear the wrapper.
(-[WebAVVideoLayer resolveBounds]): Deleted. Moved to WebCALayerHostWrapper.
* platform/ios/WebVideoFullscreenModelVideoElement.mm:
(WebVideoFullscreenModelVideoElement::setVideoLayerFrame): Null-check m_videoElement.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKith">trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h</a></li>
<li><a href="#trunkSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKitmm">trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformiosWebVideoFullscreenModelVideoElementmm">trunk/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (183228 => 183229)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-04-23 23:18:03 UTC (rev 183228)
+++ trunk/Source/WebCore/ChangeLog        2015-04-23 23:43:04 UTC (rev 183229)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2015-04-23  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        [iOS] Add a wrapper around the hosted AVPlayerLayer to intercept -setBounds:
+        https://bugs.webkit.org/show_bug.cgi?id=144129
+
+        Reviewed by Simon Fraser.
+
+        When passing the hosted AVPlayerLayer to the fullscreen controller, the new superlayer will
+        resize the hosted layer with a call to -setBounds:. But because this is a hosted layer, the
+        bonuds change has no effect. Instead, wrap the CALayerHost in another CALayer whose job it is
+        to intercept -setBounds: in the same way that WebAVVideoLayer did. In fact, we should just use
+        that wrapper class inside WebAVVideoLayer as well, to avoid duplicating code.
+
+        Drive-by Fix: Null-check m_videoElement in setVideoLayerFrame().
+
+        * platform/ios/WebVideoFullscreenInterfaceAVKit.h:
+        * platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
+        (-[WebCALayerHostWrapper setVideoSublayer:]):
+        (-[WebCALayerHostWrapper videoSublayer]):
+        (-[WebCALayerHostWrapper setBounds:]): Moved from WebAVVideoLayer.
+        (-[WebCALayerHostWrapper resolveBounds]): Ditto.
+        (-[WebAVVideoLayer setBounds:]): Moved to WebCALayerHostWrapper.
+        (WebVideoFullscreenInterfaceAVKit::setupFullscreenInternal): Create the wrapper.
+        (WebVideoFullscreenInterfaceAVKit::cleanupFullscreenInternal): Clear the wrapper.
+        (-[WebAVVideoLayer resolveBounds]): Deleted. Moved to WebCALayerHostWrapper.
+        * platform/ios/WebVideoFullscreenModelVideoElement.mm:
+        (WebVideoFullscreenModelVideoElement::setVideoLayerFrame): Null-check m_videoElement.
+
</ins><span class="cx"> 2015-04-23  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Yellow highlight has gray background color when invoking Lookup on an address in a Google Maps drop down
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKith"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h (183228 => 183229)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h        2015-04-23 23:18:03 UTC (rev 183228)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h        2015-04-23 23:43:04 UTC (rev 183229)
</span><span class="lines">@@ -44,6 +44,7 @@
</span><span class="cx"> OBJC_CLASS UIView;
</span><span class="cx"> OBJC_CLASS CALayer;
</span><span class="cx"> OBJC_CLASS WebAVVideoLayer;
</span><ins>+OBJC_CLASS WebCALayerHostWrapper;
</ins><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span><span class="cx"> class String;
</span><span class="lines">@@ -128,6 +129,7 @@
</span><span class="cx">     RetainPtr&lt;AVPlayerViewController&gt; m_playerViewController;
</span><span class="cx">     RetainPtr&lt;CALayer&gt; m_videoLayer;
</span><span class="cx">     RetainPtr&lt;WebAVVideoLayer&gt; m_videoLayerContainer;
</span><ins>+    RetainPtr&lt;WebCALayerHostWrapper&gt; m_layerHostWrapper;
</ins><span class="cx">     WebVideoFullscreenModel* m_videoFullscreenModel { nullptr };
</span><span class="cx">     WebVideoFullscreenChangeObserver* m_fullscreenChangeObserver { nullptr };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosWebVideoFullscreenInterfaceAVKitmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm (183228 => 183229)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm        2015-04-23 23:18:03 UTC (rev 183228)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm        2015-04-23 23:43:04 UTC (rev 183229)
</span><span class="lines">@@ -566,6 +566,74 @@
</span><span class="cx"> @implementation WebAVMediaSelectionOption
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+
+@interface WebCALayerHostWrapper : CALayer
+@property (assign) WebVideoFullscreenModel* model;
+@end
+
+@implementation WebCALayerHostWrapper {
+    RetainPtr&lt;CALayer&gt; _videoSublayer;
+}
+
+- (void)setVideoSublayer:(CALayer*)videoSublayer
+{
+    _videoSublayer = videoSublayer;
+    [self addSublayer:videoSublayer];
+}
+
+- (CALayer*)videoSublayer
+{
+    return _videoSublayer.get();
+}
+
+- (void)setBounds:(CGRect)bounds
+{
+    if (CGRectEqualToRect(bounds, self.bounds))
+        return;
+
+    [super setBounds:bounds];
+
+    [_videoSublayer setPosition:CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds))];
+
+    if (!self.model)
+        return;
+
+    FloatRect videoFrame = self.model-&gt;videoLayerFrame();
+    FloatRect targetFrame;
+    switch (self.model-&gt;videoLayerGravity()) {
+    case WebCore::WebVideoFullscreenModel::VideoGravityResize:
+        targetFrame = bounds;
+        break;
+    case WebCore::WebVideoFullscreenModel::VideoGravityResizeAspect:
+        targetFrame = largestRectWithAspectRatioInsideRect(videoFrame.size().aspectRatio(), bounds);
+        break;
+    case WebCore::WebVideoFullscreenModel::VideoGravityResizeAspectFill:
+        targetFrame = smallestRectWithAspectRatioAroundRect(videoFrame.size().aspectRatio(), bounds);
+        break;
+    }
+    CATransform3D transform = CATransform3DMakeScale(targetFrame.width() / videoFrame.width(), targetFrame.height() / videoFrame.height(), 1);
+    [_videoSublayer setSublayerTransform:transform];
+
+    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(resolveBounds) object:nil];
+    [self performSelector:@selector(resolveBounds) withObject:nil afterDelay:[CATransaction animationDuration] + 0.1];
+}
+
+- (void)resolveBounds
+{
+    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(resolveBounds) object:nil];
+    if (!self.model)
+        return;
+
+    [CATransaction begin];
+    [CATransaction setAnimationDuration:0];
+
+    [_videoSublayer setSublayerTransform:CATransform3DIdentity];
+    self.model-&gt;setVideoLayerFrame([self bounds]);
+    
+    [CATransaction commit];
+}
+@end
+
</ins><span class="cx"> @interface WebAVVideoLayer : CALayer &lt;AVVideoLayer&gt;
</span><span class="cx"> +(WebAVVideoLayer *)videoLayer;
</span><span class="cx"> @property (nonatomic) AVVideoLayerGravity videoLayerGravity;
</span><span class="lines">@@ -632,45 +700,9 @@
</span><span class="cx">     [super setBounds:bounds];
</span><span class="cx"> 
</span><span class="cx">     [_videoSublayer setPosition:CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds))];
</span><del>-
-    if (![_avPlayerController delegate] || !_avPlayerViewController)
-        return;
-
-    FloatRect videoFrame = [_avPlayerController delegate]-&gt;videoLayerFrame();
-    FloatRect targetFrame;
-    switch ([_avPlayerController delegate]-&gt;videoLayerGravity()) {
-    case WebCore::WebVideoFullscreenModel::VideoGravityResize:
-        targetFrame = bounds;
-        break;
-    case WebCore::WebVideoFullscreenModel::VideoGravityResizeAspect:
-        targetFrame = largestRectWithAspectRatioInsideRect(videoFrame.size().aspectRatio(), bounds);
-        break;
-    case WebCore::WebVideoFullscreenModel::VideoGravityResizeAspectFill:
-        targetFrame = smallestRectWithAspectRatioAroundRect(videoFrame.size().aspectRatio(), bounds);
-        break;
-    }
-    CATransform3D transform = CATransform3DMakeScale(targetFrame.width() / videoFrame.width(), targetFrame.height() / videoFrame.height(), 1);
-    [_videoSublayer setSublayerTransform:transform];
-
-    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(resolveBounds) object:nil];
-    [self performSelector:@selector(resolveBounds) withObject:nil afterDelay:[CATransaction animationDuration] + 0.1];
</del><ins>+    [_videoSublayer setBounds:bounds];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)resolveBounds
-{
-    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(resolveBounds) object:nil];
-    if (!_avPlayerController || ![_avPlayerController delegate])
-        return;
-
-    [CATransaction begin];
-    [CATransaction setAnimationDuration:0];
-
-    [_videoSublayer setSublayerTransform:CATransform3DIdentity];
-    [_avPlayerController delegate]-&gt;setVideoLayerFrame([self bounds]);
-
-    [CATransaction commit];
-}
-
</del><span class="cx"> - (void)setVideoLayerGravity:(AVVideoLayerGravity)videoLayerGravity
</span><span class="cx"> {
</span><span class="cx">     _videoLayerGravity = videoLayerGravity;
</span><span class="lines">@@ -932,9 +964,13 @@
</span><span class="cx"> 
</span><span class="cx">     [m_videoLayer removeFromSuperlayer];
</span><span class="cx"> 
</span><ins>+    m_layerHostWrapper = adoptNS([[WebCALayerHostWrapper alloc] init]);
+    [m_layerHostWrapper setModel:m_videoFullscreenModel];
+    [m_layerHostWrapper setVideoSublayer:m_videoLayer.get()];
+
</ins><span class="cx">     m_videoLayerContainer = [WebAVVideoLayer videoLayer];
</span><span class="cx">     [m_videoLayerContainer setHidden:[m_playerController isExternalPlaybackActive]];
</span><del>-    [m_videoLayerContainer setVideoSublayer:m_videoLayer.get()];
</del><ins>+    [m_videoLayerContainer setVideoSublayer:m_layerHostWrapper.get()];
</ins><span class="cx"> 
</span><span class="cx">     CGSize videoSize = [m_playerController contentDimensions];
</span><span class="cx">     CGRect videoRect = CGRectMake(0, 0, videoSize.width, videoSize.height);
</span><span class="lines">@@ -1122,7 +1158,8 @@
</span><span class="cx">     [m_videoLayerContainer removeFromSuperlayer];
</span><span class="cx">     [m_videoLayerContainer setPlayerViewController:nil];
</span><span class="cx">     [[m_viewController view] removeFromSuperview];
</span><del>-    
</del><ins>+
+    m_layerHostWrapper = nil;
</ins><span class="cx">     m_videoLayer = nil;
</span><span class="cx">     m_videoLayerContainer = nil;
</span><span class="cx">     m_playerViewController = nil;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosWebVideoFullscreenModelVideoElementmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.mm (183228 => 183229)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.mm        2015-04-23 23:18:03 UTC (rev 183228)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenModelVideoElement.mm        2015-04-23 23:43:04 UTC (rev 183229)
</span><span class="lines">@@ -304,7 +304,8 @@
</span><span class="cx"> {
</span><span class="cx">     m_videoFrame = rect;
</span><span class="cx">     [m_videoFullscreenLayer setBounds:CGRect(rect)];
</span><del>-    m_videoElement-&gt;setVideoFullscreenFrame(rect);
</del><ins>+    if (m_videoElement)
+        m_videoElement-&gt;setVideoFullscreenFrame(rect);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> FloatRect WebVideoFullscreenModelVideoElement::videoLayerFrame() const
</span></span></pre>
</div>
</div>

</body>
</html>