⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 242669 in webkit


Ignore:
Timestamp:
Mar 8, 2019, 6:35:54 PM (7 years ago)
Author:
Simon Fraser
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:]):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r242664 r242669  
     12019-03-08  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Share some code that sets CALayer positions
     4        https://bugs.webkit.org/show_bug.cgi?id=195485
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Share some code between ScrollingTreeStickyNode and ScrollingTreeFixedNode that sets the position
     9        of a CALayer given the top-left location.
     10
     11        * page/scrolling/cocoa/ScrollingTreeFixedNode.mm:
     12        (WebCore::ScrollingTreeFixedNode::relatedNodeScrollPositionDidChange):
     13        (WebCore::ScrollingTreeFixedNodeInternal::operator*): Deleted.
     14        * page/scrolling/cocoa/ScrollingTreeStickyNode.mm:
     15        (WebCore::ScrollingTreeStickyNode::relatedNodeScrollPositionDidChange):
     16        (WebCore::ScrollingTreeStickyNodeInternal::operator*): Deleted.
     17        * platform/graphics/cocoa/WebCoreCALayerExtras.h:
     18        * platform/graphics/cocoa/WebCoreCALayerExtras.mm:
     19        (-[CALayer _web_setLayerTopLeftPosition:]):
     20
    1212019-03-08  Chris Dumez  <cdumez@apple.com>
    222
  • trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeFixedNode.mm

    r242132 r242669  
    3232#import "ScrollingStateFixedNode.h"
    3333#import "ScrollingTree.h"
    34 #import <QuartzCore/CALayer.h>
     34#import "WebCoreCALayerExtras.h"
    3535#import <wtf/text/TextStream.h>
    3636
     
    6464}
    6565
    66 namespace ScrollingTreeFixedNodeInternal {
    67 static inline CGPoint operator*(CGPoint& a, const CGSize& b)
    68 {
    69     return CGPointMake(a.x * b.width, a.y * b.height);
    70 }
    71 }
    72 
    7366void ScrollingTreeFixedNode::relatedNodeScrollPositionDidChange(const ScrollingTreeScrollingNode&, const FloatRect& layoutViewport, FloatSize& cumulativeDelta)
    7467{
    75     using namespace ScrollingTreeFixedNodeInternal;
    7668    FloatPoint layerPosition = m_constraints.layerPositionForViewportRect(layoutViewport);
    7769
     
    8072    layerPosition -= cumulativeDelta;
    8173
    82     CGRect layerBounds = [m_layer bounds];
    83     CGPoint anchorPoint = [m_layer anchorPoint];
    84     CGPoint newPosition = layerPosition - m_constraints.alignmentOffset() + anchorPoint * layerBounds.size;
    85 
    86     if (isnan(newPosition.x) || isnan(newPosition.y)) {
    87         WTFLogAlways("Attempt to call [CALayer setPosition] with NaN: newPosition=(%f, %f) layerPosition=(%f, %f) alignmentOffset=(%f, %f)",
    88             newPosition.x, newPosition.y, layerPosition.x(), layerPosition.y(),
    89             m_constraints.alignmentOffset().width(), m_constraints.alignmentOffset().height());
    90         ASSERT_NOT_REACHED();
    91         return;
    92     }
    93 
    94     [m_layer setPosition:newPosition];
     74    [m_layer _web_setLayerTopLeftPosition:layerPosition - m_constraints.alignmentOffset()];
    9575    cumulativeDelta += layerPosition - m_constraints.layerPositionAtLastLayout();
    9676}
  • trunk/Source/WebCore/page/scrolling/cocoa/ScrollingTreeStickyNode.mm

    r242132 r242669  
    3434#import "ScrollingTreeFrameScrollingNode.h"
    3535#import "ScrollingTreeOverflowScrollingNode.h"
    36 #import <QuartzCore/CALayer.h>
     36#import "WebCoreCALayerExtras.h"
    3737#import <wtf/text/TextStream.h>
    3838
     
    6666}
    6767
    68 namespace ScrollingTreeStickyNodeInternal {
    69 static inline CGPoint operator*(CGPoint& a, const CGSize& b)
    70 {
    71     return CGPointMake(a.x * b.width, a.y * b.height);
    72 }
    73 }
    74 
    7568void ScrollingTreeStickyNode::relatedNodeScrollPositionDidChange(const ScrollingTreeScrollingNode&, const FloatRect& layoutViewport, FloatSize& cumulativeDelta)
    7669{
    77     using namespace ScrollingTreeStickyNodeInternal;
    7870    FloatRect constrainingRect;
    7971
     
    8880    LOG_WITH_STREAM(Scrolling, stream << "ScrollingTreeStickyNode " << scrollingNodeID() << " relatedNodeScrollPositionDidChange: new viewport " << layoutViewport << " constrainingRectAtLastLayout " << m_constraints.constrainingRectAtLastLayout() << " last layer pos " << m_constraints.layerPositionAtLastLayout());
    8981
    90     FloatPoint layerPosition = m_constraints.layerPositionForConstrainingRect(constrainingRect);
    91 
    92     CGRect layerBounds = [m_layer bounds];
    93     CGPoint anchorPoint = [m_layer anchorPoint];
    94     CGPoint newPosition = layerPosition - m_constraints.alignmentOffset() + anchorPoint * layerBounds.size;
    95     [m_layer setPosition:newPosition];
     82    FloatPoint layerPosition = m_constraints.layerPositionForConstrainingRect(constrainingRect) - m_constraints.alignmentOffset();
     83    [m_layer _web_setLayerTopLeftPosition:layerPosition];
    9684
    9785    cumulativeDelta += layerPosition - m_constraints.layerPositionAtLastLayout();
  • trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.h

    r221543 r242669  
    2929
    3030- (void)web_disableAllActions;
     31- (void)_web_setLayerTopLeftPosition:(CGPoint)position;
    3132+ (CALayer *)_web_renderLayerWithContextID:(uint32_t)contextID;
    3233
  • trunk/Source/WebCore/platform/graphics/cocoa/WebCoreCALayerExtras.mm

    r221543 r242669  
    5757}
    5858
     59- (void)_web_setLayerTopLeftPosition:(CGPoint)position
     60{
     61    CGSize layerSize = [self bounds].size;
     62    CGPoint anchorPoint = [self anchorPoint];
     63    CGPoint newPosition = CGPointMake(position.x + anchorPoint.x * layerSize.width, position.y + anchorPoint.y * layerSize.height);
     64    if (isnan(newPosition.x) || isnan(newPosition.y)) {
     65        WTFLogAlways("Attempt to call [CALayer setPosition] with NaN: newPosition=(%f, %f) position=(%f, %f) anchorPoint=(%f, %f)",
     66            newPosition.x, newPosition.y, position.x, position.y, anchorPoint.x, anchorPoint.y);
     67        ASSERT_NOT_REACHED();
     68        return;
     69    }
     70   
     71    [self setPosition:newPosition];
     72}
     73
    5974+ (CALayer *)_web_renderLayerWithContextID:(uint32_t)contextID
    6075{
Note: See TracChangeset for help on using the changeset viewer.