<!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>[242669] 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/242669">242669</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2019-03-08 18:35:54 -0800 (Fri, 08 Mar 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Share some code that sets CALayer positions
https://bugs.webkit.org/show_bug.cgi?id=195485

Reviewed by Zalan Bujtas.

Share some code between ScrollingTreeStickyNode and ScrollingTreeFixedNode that sets the position
of a CALayer given the top-left location.

* page/scrolling/cocoa/ScrollingTreeFixedNode.mm:
(WebCore::ScrollingTreeFixedNode::relatedNodeScrollPositionDidChange):
(WebCore::ScrollingTreeFixedNodeInternal::operator*): Deleted.
* page/scrolling/cocoa/ScrollingTreeStickyNode.mm:
(WebCore::ScrollingTreeStickyNode::relatedNodeScrollPositionDidChange):
(WebCore::ScrollingTreeStickyNodeInternal::operator*): Deleted.
* platform/graphics/cocoa/WebCoreCALayerExtras.h:
* platform/graphics/cocoa/WebCoreCALayerExtras.mm:
(-[CALayer _web_setLayerTopLeftPosition:]):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepagescrollingcocoaScrollingTreeFixedNodemm">trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeFixedNode.mm</a></li>
<li><a href="#trunkSourceWebCorepagescrollingcocoaScrollingTreeStickyNodemm">trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeStickyNode.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscocoaWebCoreCALayerExtrash">trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscocoaWebCoreCALayerExtrasmm">trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (242668 => 242669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2019-03-09 02:14:45 UTC (rev 242668)
+++ trunk/Source/WebCore/ChangeLog      2019-03-09 02:35:54 UTC (rev 242669)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2019-03-08  Simon Fraser  <simon.fraser@apple.com>
+
+        Share some code that sets CALayer positions
+        https://bugs.webkit.org/show_bug.cgi?id=195485
+
+        Reviewed by Zalan Bujtas.
+
+        Share some code between ScrollingTreeStickyNode and ScrollingTreeFixedNode that sets the position
+        of a CALayer given the top-left location.
+
+        * page/scrolling/cocoa/ScrollingTreeFixedNode.mm:
+        (WebCore::ScrollingTreeFixedNode::relatedNodeScrollPositionDidChange):
+        (WebCore::ScrollingTreeFixedNodeInternal::operator*): Deleted.
+        * page/scrolling/cocoa/ScrollingTreeStickyNode.mm:
+        (WebCore::ScrollingTreeStickyNode::relatedNodeScrollPositionDidChange):
+        (WebCore::ScrollingTreeStickyNodeInternal::operator*): Deleted.
+        * platform/graphics/cocoa/WebCoreCALayerExtras.h:
+        * platform/graphics/cocoa/WebCoreCALayerExtras.mm:
+        (-[CALayer _web_setLayerTopLeftPosition:]):
+
</ins><span class="cx"> 2019-03-08  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Add support for Device Orientation / Motion permission API
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingcocoaScrollingTreeFixedNodemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeFixedNode.mm (242668 => 242669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeFixedNode.mm      2019-03-09 02:14:45 UTC (rev 242668)
+++ trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeFixedNode.mm 2019-03-09 02:35:54 UTC (rev 242669)
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx"> #import "Logging.h"
</span><span class="cx"> #import "ScrollingStateFixedNode.h"
</span><span class="cx"> #import "ScrollingTree.h"
</span><del>-#import <QuartzCore/CALayer.h>
</del><ins>+#import "WebCoreCALayerExtras.h"
</ins><span class="cx"> #import <wtf/text/TextStream.h>
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -63,16 +63,8 @@
</span><span class="cx">         m_constraints = fixedStateNode.viewportConstraints();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-namespace ScrollingTreeFixedNodeInternal {
-static inline CGPoint operator*(CGPoint& a, const CGSize& b)
-{
-    return CGPointMake(a.x * b.width, a.y * b.height);
-}
-}
-
</del><span class="cx"> void ScrollingTreeFixedNode::relatedNodeScrollPositionDidChange(const ScrollingTreeScrollingNode&, const FloatRect& layoutViewport, FloatSize& cumulativeDelta)
</span><span class="cx"> {
</span><del>-    using namespace ScrollingTreeFixedNodeInternal;
</del><span class="cx">     FloatPoint layerPosition = m_constraints.layerPositionForViewportRect(layoutViewport);
</span><span class="cx"> 
</span><span class="cx">     LOG_WITH_STREAM(Scrolling, stream << "ScrollingTreeFixedNode " << scrollingNodeID() << " relatedNodeScrollPositionDidChange: new viewport " << layoutViewport << " viewportRectAtLastLayout " << m_constraints.viewportRectAtLastLayout() << " last layer pos " << m_constraints.layerPositionAtLastLayout() << " new offset from top " << (layoutViewport.y() - layerPosition.y()));
</span><span class="lines">@@ -79,19 +71,7 @@
</span><span class="cx"> 
</span><span class="cx">     layerPosition -= cumulativeDelta;
</span><span class="cx"> 
</span><del>-    CGRect layerBounds = [m_layer bounds];
-    CGPoint anchorPoint = [m_layer anchorPoint];
-    CGPoint newPosition = layerPosition - m_constraints.alignmentOffset() + anchorPoint * layerBounds.size;
-
-    if (isnan(newPosition.x) || isnan(newPosition.y)) {
-        WTFLogAlways("Attempt to call [CALayer setPosition] with NaN: newPosition=(%f, %f) layerPosition=(%f, %f) alignmentOffset=(%f, %f)",
-            newPosition.x, newPosition.y, layerPosition.x(), layerPosition.y(),
-            m_constraints.alignmentOffset().width(), m_constraints.alignmentOffset().height());
-        ASSERT_NOT_REACHED();
-        return;
-    }
-
-    [m_layer setPosition:newPosition];
</del><ins>+    [m_layer _web_setLayerTopLeftPosition:layerPosition - m_constraints.alignmentOffset()];
</ins><span class="cx">     cumulativeDelta += layerPosition - m_constraints.layerPositionAtLastLayout();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingcocoaScrollingTreeStickyNodemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeStickyNode.mm (242668 => 242669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeStickyNode.mm     2019-03-09 02:14:45 UTC (rev 242668)
+++ trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeStickyNode.mm        2019-03-09 02:35:54 UTC (rev 242669)
</span><span class="lines">@@ -33,7 +33,7 @@
</span><span class="cx"> #import "ScrollingTree.h"
</span><span class="cx"> #import "ScrollingTreeFrameScrollingNode.h"
</span><span class="cx"> #import "ScrollingTreeOverflowScrollingNode.h"
</span><del>-#import <QuartzCore/CALayer.h>
</del><ins>+#import "WebCoreCALayerExtras.h"
</ins><span class="cx"> #import <wtf/text/TextStream.h>
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -65,16 +65,8 @@
</span><span class="cx">         m_constraints = stickyStateNode.viewportConstraints();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-namespace ScrollingTreeStickyNodeInternal {
-static inline CGPoint operator*(CGPoint& a, const CGSize& b)
-{
-    return CGPointMake(a.x * b.width, a.y * b.height);
-}
-}
-
</del><span class="cx"> void ScrollingTreeStickyNode::relatedNodeScrollPositionDidChange(const ScrollingTreeScrollingNode&, const FloatRect& layoutViewport, FloatSize& cumulativeDelta)
</span><span class="cx"> {
</span><del>-    using namespace ScrollingTreeStickyNodeInternal;
</del><span class="cx">     FloatRect constrainingRect;
</span><span class="cx"> 
</span><span class="cx">     auto* enclosingScrollingNode = enclosingScrollingNodeIncludingSelf();
</span><span class="lines">@@ -87,13 +79,9 @@
</span><span class="cx"> 
</span><span class="cx">     LOG_WITH_STREAM(Scrolling, stream << "ScrollingTreeStickyNode " << scrollingNodeID() << " relatedNodeScrollPositionDidChange: new viewport " << layoutViewport << " constrainingRectAtLastLayout " << m_constraints.constrainingRectAtLastLayout() << " last layer pos " << m_constraints.layerPositionAtLastLayout());
</span><span class="cx"> 
</span><del>-    FloatPoint layerPosition = m_constraints.layerPositionForConstrainingRect(constrainingRect);
</del><ins>+    FloatPoint layerPosition = m_constraints.layerPositionForConstrainingRect(constrainingRect) - m_constraints.alignmentOffset();
+    [m_layer _web_setLayerTopLeftPosition:layerPosition];
</ins><span class="cx"> 
</span><del>-    CGRect layerBounds = [m_layer bounds];
-    CGPoint anchorPoint = [m_layer anchorPoint];
-    CGPoint newPosition = layerPosition - m_constraints.alignmentOffset() + anchorPoint * layerBounds.size;
-    [m_layer setPosition:newPosition];
-
</del><span class="cx">     cumulativeDelta += layerPosition - m_constraints.layerPositionAtLastLayout();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscocoaWebCoreCALayerExtrash"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.h (242668 => 242669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.h      2019-03-09 02:14:45 UTC (rev 242668)
+++ trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.h 2019-03-09 02:35:54 UTC (rev 242669)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> @interface CALayer (WebCoreCALayerExtras)
</span><span class="cx"> 
</span><span class="cx"> - (void)web_disableAllActions;
</span><ins>+- (void)_web_setLayerTopLeftPosition:(CGPoint)position;
</ins><span class="cx"> + (CALayer *)_web_renderLayerWithContextID:(uint32_t)contextID;
</span><span class="cx"> 
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscocoaWebCoreCALayerExtrasmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.mm (242668 => 242669)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.mm     2019-03-09 02:14:45 UTC (rev 242668)
+++ trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.mm        2019-03-09 02:35:54 UTC (rev 242669)
</span><span class="lines">@@ -56,6 +56,21 @@
</span><span class="cx">     };
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_web_setLayerTopLeftPosition:(CGPoint)position
+{
+    CGSize layerSize = [self bounds].size;
+    CGPoint anchorPoint = [self anchorPoint];
+    CGPoint newPosition = CGPointMake(position.x + anchorPoint.x * layerSize.width, position.y + anchorPoint.y * layerSize.height);
+    if (isnan(newPosition.x) || isnan(newPosition.y)) {
+        WTFLogAlways("Attempt to call [CALayer setPosition] with NaN: newPosition=(%f, %f) position=(%f, %f) anchorPoint=(%f, %f)",
+            newPosition.x, newPosition.y, position.x, position.y, anchorPoint.x, anchorPoint.y);
+        ASSERT_NOT_REACHED();
+        return;
+    }
+    
+    [self setPosition:newPosition];
+}
+
</ins><span class="cx"> + (CALayer *)_web_renderLayerWithContextID:(uint32_t)contextID
</span><span class="cx"> {
</span><span class="cx">     CALayerHost *layerHost = [CALayerHost layer];
</span></span></pre>
</div>
</div>

</body>
</html>