Title: [242669] trunk/Source/WebCore
Revision
242669
Author
[email protected]
Date
2019-03-08 18:35:54 -0800 (Fri, 08 Mar 2019)

Log Message

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:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (242668 => 242669)


--- 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)
@@ -1,3 +1,23 @@
+2019-03-08  Simon Fraser  <[email protected]>
+
+        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:]):
+
 2019-03-08  Chris Dumez  <[email protected]>
 
         Add support for Device Orientation / Motion permission API

Modified: trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeFixedNode.mm (242668 => 242669)


--- 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)
@@ -31,7 +31,7 @@
 #import "Logging.h"
 #import "ScrollingStateFixedNode.h"
 #import "ScrollingTree.h"
-#import <QuartzCore/CALayer.h>
+#import "WebCoreCALayerExtras.h"
 #import <wtf/text/TextStream.h>
 
 namespace WebCore {
@@ -63,16 +63,8 @@
         m_constraints = fixedStateNode.viewportConstraints();
 }
 
-namespace ScrollingTreeFixedNodeInternal {
-static inline CGPoint operator*(CGPoint& a, const CGSize& b)
-{
-    return CGPointMake(a.x * b.width, a.y * b.height);
-}
-}
-
 void ScrollingTreeFixedNode::relatedNodeScrollPositionDidChange(const ScrollingTreeScrollingNode&, const FloatRect& layoutViewport, FloatSize& cumulativeDelta)
 {
-    using namespace ScrollingTreeFixedNodeInternal;
     FloatPoint layerPosition = m_constraints.layerPositionForViewportRect(layoutViewport);
 
     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()));
@@ -79,19 +71,7 @@
 
     layerPosition -= cumulativeDelta;
 
-    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];
+    [m_layer _web_setLayerTopLeftPosition:layerPosition - m_constraints.alignmentOffset()];
     cumulativeDelta += layerPosition - m_constraints.layerPositionAtLastLayout();
 }
 

Modified: trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeStickyNode.mm (242668 => 242669)


--- 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)
@@ -33,7 +33,7 @@
 #import "ScrollingTree.h"
 #import "ScrollingTreeFrameScrollingNode.h"
 #import "ScrollingTreeOverflowScrollingNode.h"
-#import <QuartzCore/CALayer.h>
+#import "WebCoreCALayerExtras.h"
 #import <wtf/text/TextStream.h>
 
 namespace WebCore {
@@ -65,16 +65,8 @@
         m_constraints = stickyStateNode.viewportConstraints();
 }
 
-namespace ScrollingTreeStickyNodeInternal {
-static inline CGPoint operator*(CGPoint& a, const CGSize& b)
-{
-    return CGPointMake(a.x * b.width, a.y * b.height);
-}
-}
-
 void ScrollingTreeStickyNode::relatedNodeScrollPositionDidChange(const ScrollingTreeScrollingNode&, const FloatRect& layoutViewport, FloatSize& cumulativeDelta)
 {
-    using namespace ScrollingTreeStickyNodeInternal;
     FloatRect constrainingRect;
 
     auto* enclosingScrollingNode = enclosingScrollingNodeIncludingSelf();
@@ -87,13 +79,9 @@
 
     LOG_WITH_STREAM(Scrolling, stream << "ScrollingTreeStickyNode " << scrollingNodeID() << " relatedNodeScrollPositionDidChange: new viewport " << layoutViewport << " constrainingRectAtLastLayout " << m_constraints.constrainingRectAtLastLayout() << " last layer pos " << m_constraints.layerPositionAtLastLayout());
 
-    FloatPoint layerPosition = m_constraints.layerPositionForConstrainingRect(constrainingRect);
+    FloatPoint layerPosition = m_constraints.layerPositionForConstrainingRect(constrainingRect) - m_constraints.alignmentOffset();
+    [m_layer _web_setLayerTopLeftPosition:layerPosition];
 
-    CGRect layerBounds = [m_layer bounds];
-    CGPoint anchorPoint = [m_layer anchorPoint];
-    CGPoint newPosition = layerPosition - m_constraints.alignmentOffset() + anchorPoint * layerBounds.size;
-    [m_layer setPosition:newPosition];
-
     cumulativeDelta += layerPosition - m_constraints.layerPositionAtLastLayout();
 }
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.h (242668 => 242669)


--- 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)
@@ -28,6 +28,7 @@
 @interface CALayer (WebCoreCALayerExtras)
 
 - (void)web_disableAllActions;
+- (void)_web_setLayerTopLeftPosition:(CGPoint)position;
 + (CALayer *)_web_renderLayerWithContextID:(uint32_t)contextID;
 
 @end

Modified: trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.mm (242668 => 242669)


--- 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)
@@ -56,6 +56,21 @@
     };
 }
 
+- (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];
+}
+
 + (CALayer *)_web_renderLayerWithContextID:(uint32_t)contextID
 {
     CALayerHost *layerHost = [CALayerHost layer];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to