Title: [292525] trunk/Source/WebCore
Revision
292525
Author
[email protected]
Date
2022-04-07 03:06:46 -0700 (Thu, 07 Apr 2022)

Log Message

Unify 'transform-box' reference box computation
https://bugs.webkit.org/show_bug.cgi?id=237554

Reviewed by Simon Fraser.

Currently the code to compute the reference box, according to the CSS 'transform-box'
property is sprinkled over various places: CSSComputedStyleDeclaration, SVGRenderSupport,
RenderBox, parts in RenderLayer.

Cleanup and unify the code in a new 'FloatRect referenceBoxRect(CSSBoxType) const' method.
RenderElement::referenceBoxRect(CSSBoxType) contains the SVG specific implementation, and
RenderBox::referenceBoxRect() the HTML/CSS one (previously named referenceBox()).

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292524 => 292525)


--- trunk/Source/WebCore/ChangeLog	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/ChangeLog	2022-04-07 10:06:46 UTC (rev 292525)
@@ -1,3 +1,57 @@
+2022-04-07  Nikolas Zimmermann  <[email protected]>
+
+        Unify 'transform-box' reference box computation
+        https://bugs.webkit.org/show_bug.cgi?id=237554
+
+        Reviewed by Simon Fraser.
+
+        Currently the code to compute the reference box, according to the CSS 'transform-box'
+        property is sprinkled over various places: CSSComputedStyleDeclaration, SVGRenderSupport,
+        RenderBox, parts in RenderLayer.
+
+        Cleanup and unify the code in a new 'FloatRect referenceBoxRect(CSSBoxType) const' method.
+        RenderElement::referenceBoxRect(CSSBoxType) contains the SVG specific implementation, and
+        RenderBox::referenceBoxRect() the HTML/CSS one (previously named referenceBox()).
+.
+        RenderElement provides an additional transfromReferenceBoxRect() helper which is used in
+        various places that previously manually converted the transform-box value into a CSSBoxType.
+
+        Remove code from SVGRenderSupport/CSSComputedStyleDeclaration that can now use the shared logic.
+
+        Covered by existing tests, no change in behaviour.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::computedTransform):
+        (WebCore::ComputedStyleExtractor::valueForPropertyInStyle):
+        (WebCore::transformReferenceBox): Deleted.
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::referenceBoxRect const):
+        (WebCore::RenderBox::hitTestClipPath const):
+        (WebCore::RenderBox::referenceBox const): Deleted.
+        * rendering/RenderBox.h:
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::referenceBoxRect const):
+        * rendering/RenderElement.h:
+        (WebCore::RenderElement::transformReferenceBoxRect const):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::referenceBoxRectForClipPath const):
+        (WebCore::RenderLayer::updateTransform):
+        (WebCore::RenderLayer::currentTransform const):
+        (WebCore::RenderLayer::perspectiveTransform const):
+        (WebCore::RenderLayer::perspectiveOrigin const):
+        (WebCore::RenderLayer::rendererNeedsPixelSnapping const):
+        (WebCore::RenderLayer::snapRectToDevicePixelsIfNeeded const):
+        (WebCore::RenderLayer::computeClipPath const):
+        (WebCore::RenderLayer::setupClipPath):
+        (WebCore::computeReferenceRectFromBox): Deleted.
+        (WebCore::computeReferenceBox): Deleted.
+        * rendering/RenderLayer.h:
+        * rendering/svg/SVGRenderSupport.cpp:
+        (WebCore::SVGRenderSupport::transformReferenceBox): Deleted.
+        * rendering/svg/SVGRenderSupport.h:
+        * svg/SVGGraphicsElement.cpp:
+        (WebCore::SVGGraphicsElement::animatedLocalTransform const):
+
 2022-04-07  Matt Woodrow  <[email protected]>
 
         Grid items that establish an independent formatting context should not be subgrids.

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (292524 => 292525)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2022-04-07 10:06:46 UTC (rev 292525)
@@ -568,17 +568,6 @@
     return box.style().boxSizing() == BoxSizing::BorderBox ? box.borderBoxRect() : box.computedCSSContentBoxRect();
 }
 
-static FloatRect transformReferenceBox(const RenderStyle& style, const RenderElement& renderer)
-{
-    if (is<RenderBox>(renderer))
-        return downcast<RenderBox>(renderer).referenceBox(transformBoxToCSSBoxType(style.transformBox()));
-
-    if (is<SVGElement>(renderer.element()))
-        return SVGRenderSupport::transformReferenceBox(renderer, downcast<SVGElement>(*renderer.element()), style);
-
-    return { };
-}
-
 static Ref<CSSFunctionValue> matrixTransformValue(const TransformationMatrix& transform, const RenderStyle& style)
 {
     RefPtr<CSSFunctionValue> transformValue;
@@ -631,7 +620,8 @@
         return CSSValuePool::singleton().createIdentifierValue(CSSValueNone);
 
     TransformationMatrix transform;
-    style.applyTransform(transform, transformReferenceBox(style, *renderer), { });
+    style.applyTransform(transform, renderer->transformReferenceBoxRect(style), { });
+
     // Note that this does not flatten to an affine transform if ENABLE(3D_TRANSFORMS) is off, by design.
 
     // FIXME: Need to print out individual functions (https://bugs.webkit.org/show_bug.cgi?id=23924)
@@ -3822,7 +3812,7 @@
         case CSSPropertyPerspectiveOrigin: {
             auto list = CSSValueList::createSpaceSeparated();
             if (renderer) {
-                auto box = transformReferenceBox(style, *renderer);
+                auto box = renderer->transformReferenceBoxRect(style);
                 list->append(zoomAdjustedPixelValue(minimumValueForLength(style.perspectiveOriginX(), box.width()), style));
                 list->append(zoomAdjustedPixelValue(minimumValueForLength(style.perspectiveOriginY(), box.height()), style));
             } else {
@@ -3878,7 +3868,7 @@
         case CSSPropertyTransformOrigin: {
             auto list = CSSValueList::createSpaceSeparated();
             if (renderer) {
-                auto box = transformReferenceBox(style, *renderer);
+                auto box = renderer->transformReferenceBoxRect(style);
                 list->append(zoomAdjustedPixelValue(minimumValueForLength(style.transformOriginX(), box.width()), style));
                 list->append(zoomAdjustedPixelValue(minimumValueForLength(style.transformOriginY(), box.height()), style));
                 if (style.transformOriginZ())

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (292524 => 292525)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2022-04-07 10:06:46 UTC (rev 292525)
@@ -771,9 +771,8 @@
     return { borderLeft() + paddingLeft() + scrollbarSpace, borderTop() + paddingTop() };
 }
 
-LayoutRect RenderBox::referenceBox(CSSBoxType boxType) const
+FloatRect RenderBox::referenceBoxRect(CSSBoxType boxType) const
 {
-    LayoutRect referenceBox;
     switch (boxType) {
     case CSSBoxType::ContentBox:
     case CSSBoxType::FillBox:
@@ -789,6 +788,8 @@
     case CSSBoxType::BoxMissing:
         return borderBoxRect();
     }
+
+    ASSERT_NOT_REACHED();
     return { };
 }
 
@@ -1465,7 +1466,7 @@
     switch (style().clipPath()->type()) {
     case PathOperation::Shape: {
         auto& clipPath = downcast<ShapePathOperation>(*style().clipPath());
-        auto referenceBoxRect = referenceBox(clipPath.referenceBox());
+        auto referenceBoxRect = this->referenceBoxRect(clipPath.referenceBox());
         if (!clipPath.pathForReferenceRect(referenceBoxRect).contains(hitTestLocationInLocalCoordinates, clipPath.windRule()))
             return false;
         break;

Modified: trunk/Source/WebCore/rendering/RenderBox.h (292524 => 292525)


--- trunk/Source/WebCore/rendering/RenderBox.h	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/rendering/RenderBox.h	2022-04-07 10:06:46 UTC (rev 292525)
@@ -167,8 +167,8 @@
     LayoutRect contentBoxRect() const;
     LayoutPoint contentBoxLocation() const;
 
-    // .https://drafts.csswg.org/css-transforms-1/#reference-box
-    LayoutRect referenceBox(CSSBoxType) const;
+    // https://www.w3.org/TR/css-transforms-1/#reference-box
+    FloatRect referenceBoxRect(CSSBoxType) const final;
 
     // The content box in absolute coords. Ignores transforms.
     IntRect absoluteContentBox() const;

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (292524 => 292525)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2022-04-07 10:06:46 UTC (rev 292525)
@@ -78,6 +78,7 @@
 #include "RenderView.h"
 #include "SVGElementTypeHelpers.h"
 #include "SVGImage.h"
+#include "SVGLengthContext.h"
 #include "SVGRenderSupport.h"
 #include "Settings.h"
 #include "ShadowRoot.h"
@@ -2406,5 +2407,38 @@
     return isFloatingOrOutOfFlowPositioned() || hasPotentiallyScrollableOverflow() || style().containsLayout() || paintContainmentApplies();
 }
 
+FloatRect RenderElement::referenceBoxRect(CSSBoxType boxType) const
+{
+    // CSS box model code is implemented in RenderBox::referenceBoxRect().
 
+    // For the legacy SVG engine, RenderElement is the only class that's
+    // present in the ancestor chain of all SVG renderers. In LBSE the
+    // common class is RenderLayerModelObject. Once the legacy SVG engine
+    // is removed this function should be moved to RenderLayerModelObject.
+    // As this method is used by both SVG engines, we need to place it
+    // here in RenderElement, as temporary solution.
+    if (!is<SVGElement>(element()))
+        return { };
+
+    switch (boxType) {
+    case CSSBoxType::BoxMissing:
+    case CSSBoxType::ContentBox:
+    case CSSBoxType::PaddingBox:
+    case CSSBoxType::FillBox:
+        return objectBoundingBox();
+    case CSSBoxType::BorderBox:
+    case CSSBoxType::MarginBox:
+    case CSSBoxType::StrokeBox:
+        return strokeBoundingBox();
+    case CSSBoxType::ViewBox:
+        // FIXME: [LBSE] Upstream: Cache the immutable SVGLengthContext per SVGElement, to avoid the repeated RenderSVGRoot size queries in determineViewport().
+        FloatSize viewportSize;
+        SVGLengthContext(downcast<SVGElement>(element())).determineViewport(viewportSize);
+        return { { }, viewportSize };
+    }
+
+    ASSERT_NOT_REACHED();
+    return { };
 }
+
+}

Modified: trunk/Source/WebCore/rendering/RenderElement.h (292524 => 292525)


--- trunk/Source/WebCore/rendering/RenderElement.h	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/rendering/RenderElement.h	2022-04-07 10:06:46 UTC (rev 292525)
@@ -258,6 +258,13 @@
     virtual void animationFinished(const String& /* name */) { }
     virtual void transformRelatedPropertyDidChange() { }
 
+    // https://www.w3.org/TR/css-transforms-1/#transform-box
+    FloatRect transformReferenceBoxRect(const RenderStyle& style) const { return referenceBoxRect(transformBoxToCSSBoxType(style.transformBox())); }
+    FloatRect transformReferenceBoxRect() const { return transformReferenceBoxRect(style()); }
+
+    // https://www.w3.org/TR/css-transforms-1/#reference-box
+    virtual FloatRect referenceBoxRect(CSSBoxType) const;
+
     virtual void suspendAnimations(MonotonicTime = MonotonicTime()) { }
     std::unique_ptr<RenderStyle> animatedStyle();
 

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (292524 => 292525)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2022-04-07 10:06:46 UTC (rev 292525)
@@ -1296,21 +1296,18 @@
 }
 #endif
 
-static inline LayoutRect computeReferenceRectFromBox(const RenderBox& box, CSSBoxType boxType, const LayoutSize& offsetFromRoot)
+FloatRect RenderLayer::referenceBoxRectForClipPath(CSSBoxType boxType, const LayoutSize& offsetFromRoot, const LayoutRect& rootRelativeBounds) const
 {
-    auto referenceBox = box.referenceBox(boxType);
-    referenceBox.move(offsetFromRoot);
-    return referenceBox;
-}
+    // FIXME: [LBSE] Upstream clipping support for SVG.
 
-static inline LayoutRect computeReferenceBox(const RenderObject& renderer, CSSBoxType boxType, const LayoutSize& offsetFromRoot, const LayoutRect& rootRelativeBounds)
-{
     // FIXME: Support different reference boxes for inline content.
     // https://bugs.webkit.org/show_bug.cgi?id=129047
-    if (!renderer.isBox())
+    if (!renderer().isBox())
         return rootRelativeBounds;
-    
-    return computeReferenceRectFromBox(downcast<RenderBox>(renderer), boxType, offsetFromRoot);
+
+    auto referenceBoxRect = renderer().referenceBoxRect(boxType);
+    referenceBoxRect.move(offsetFromRoot);
+    return referenceBoxRect;
 }
 
 void RenderLayer::updateTransform()
@@ -1332,19 +1329,14 @@
     if (hasTransform) {
         m_transform->makeIdentity();
 
-        // FIXME: [LBSE] Upstream reference box computation for RenderSVGModelObject derived renderers
-        FloatRect referenceBox;
-        if (is<RenderBox>(renderer())) {
-            referenceBox = snapRectToDevicePixels(downcast<RenderBox>(renderer()).referenceBox(transformBoxToCSSBoxType(renderer().style().transformBox())), renderer().document().deviceScaleFactor());
-            if (auto pathOperation = renderer().style().offsetPath()) {
-                if (is<BoxPathOperation>(pathOperation)) {
-                    auto boxPathOperation = downcast<BoxPathOperation>(pathOperation);
-                    boxPathOperation->setPathForReferenceRect(FloatRoundedRect(snapRectToDevicePixels(downcast<RenderBox>(renderer()).referenceBox(boxPathOperation->referenceBox()), renderer().document().deviceScaleFactor())));
-                }
-            }
+        if (auto pathOperation = renderer().style().offsetPath(); pathOperation && is<BoxPathOperation>(pathOperation)) {
+            auto& boxPathOperation = downcast<BoxPathOperation>(*pathOperation);
+            auto pathReferenceBoxRect = snapRectToDevicePixelsIfNeeded(renderer().referenceBoxRect(boxPathOperation.referenceBox()), renderer());
+            boxPathOperation.setPathForReferenceRect(FloatRoundedRect { pathReferenceBoxRect });
         }
 
-        renderer().applyTransform(*m_transform, referenceBox);
+        auto referenceBoxRect = snapRectToDevicePixelsIfNeeded(renderer().transformReferenceBoxRect(renderer().style()), renderer());
+        renderer().applyTransform(*m_transform, referenceBoxRect);
         makeMatrixRenderable(*m_transform, canRender3DTransforms());
     }
 
@@ -1373,11 +1365,10 @@
     auto styleable = Styleable::fromRenderer(renderBox);
     if ((styleable && styleable->isRunningAcceleratedTransformAnimation()) || !options.contains(RenderStyle::TransformOperationOption::TransformOrigin)) {
         std::unique_ptr<RenderStyle> animatedStyle = renderBox.animatedStyle();
-        auto pixelSnappedBorderRect = snapRectToDevicePixels(renderBox.referenceBox(transformBoxToCSSBoxType(animatedStyle->transformBox())), renderBox.document().deviceScaleFactor());
+        auto referenceBoxRect = snapRectToDevicePixelsIfNeeded(renderer().transformReferenceBoxRect(*animatedStyle), renderer());
 
         TransformationMatrix transform;
-        animatedStyle->applyTransform(transform, pixelSnappedBorderRect, options);
-
+        animatedStyle->applyTransform(transform, referenceBoxRect, options);
         makeMatrixRenderable(transform, canRender3DTransforms());
         return transform;
     }
@@ -1807,12 +1798,10 @@
     if (!style.hasPerspective())
         return { };
 
-    auto deviceScaleFactor = renderBox.document().deviceScaleFactor();
-    auto referenceBox = renderBox.referenceBox(transformBoxToCSSBoxType(style.transformBox()));
-    auto pixelSnappedReferenceBox = snapRectToDevicePixels(referenceBox, deviceScaleFactor);
-    auto snappedLayerRect = snapRectToDevicePixels(layerRect, deviceScaleFactor);
+    auto referenceBoxRect = snapRectToDevicePixelsIfNeeded(renderer().transformReferenceBoxRect(style), renderer());
+    auto snappedLayerRect = snapRectToDevicePixelsIfNeeded(layerRect, renderer());
 
-    auto perspectiveOrigin = pixelSnappedReferenceBox.location() - toFloatSize(snappedLayerRect.location()) + floatPointForLengthPoint(style.perspectiveOrigin(), pixelSnappedReferenceBox.size());
+    auto perspectiveOrigin = referenceBoxRect.location() - toFloatSize(snappedLayerRect.location()) + floatPointForLengthPoint(style.perspectiveOrigin(), referenceBoxRect.size());
 
     // A perspective origin of 0,0 makes the vanishing point in the center of the element.
     // We want it to be in the top-left, so subtract half the height and width.
@@ -1830,6 +1819,7 @@
 {
     if (!renderer().hasTransformRelatedProperty())
         return { };
+    // FIXME: This uses the wrong, transform-box unaware, geometry.
     return floatPointForLengthPoint(renderer().style().perspectiveOrigin(), rendererBorderBoxRect().size());
 }
 
@@ -3217,32 +3207,18 @@
 std::pair<Path, WindRule> RenderLayer::computeClipPath(const LayoutSize& offsetFromRoot, const LayoutRect& rootRelativeBoundsForNonBoxes) const
 {
     const RenderStyle& style = renderer().style();
-    float deviceScaleFactor = renderer().document().deviceScaleFactor();
 
     if (is<ShapePathOperation>(*style.clipPath())) {
         auto& clipPath = downcast<ShapePathOperation>(*style.clipPath());
-
-        LayoutRect referenceBox;
-        if (is<RenderBox>(renderer())) {
-            referenceBox = downcast<RenderBox>(renderer()).referenceBox(clipPath.referenceBox());
-            referenceBox.move(offsetFromRoot);
-#if ENABLE(LAYER_BASED_SVG_ENGINE)
-        } else if (is<RenderSVGModelObject>(renderer())) {
-            // FIXME: [LBSE] Upstream clipping support for RenderSVGModelObject derived renderers
-#endif
-        } else {
-            // Reference box for inlines is not well defined: https://github.com/w3c/csswg-drafts/issues/6383
-            referenceBox = rootRelativeBoundsForNonBoxes;
-        }
-
-        auto snappedReferenceBox = snapRectToDevicePixels(referenceBox, deviceScaleFactor);
-        return { clipPath.pathForReferenceRect(snappedReferenceBox), clipPath.windRule() };
+        auto referenceBoxRect = referenceBoxRectForClipPath(clipPath.referenceBox(), offsetFromRoot, rootRelativeBoundsForNonBoxes);
+        auto snappedReferenceBoxRect = snapRectToDevicePixelsIfNeeded(referenceBoxRect, renderer());
+        return { clipPath.pathForReferenceRect(snappedReferenceBoxRect), clipPath.windRule() };
     }
 
     if (is<BoxPathOperation>(*style.clipPath()) && is<RenderBox>(renderer())) {
         auto& clipPath = downcast<BoxPathOperation>(*style.clipPath());
 
-        auto shapeRect = computeRoundedRectForBoxShape(clipPath.referenceBox(), downcast<RenderBox>(renderer())).pixelSnappedRoundedRectForPainting(deviceScaleFactor);
+        auto shapeRect = computeRoundedRectForBoxShape(clipPath.referenceBox(), downcast<RenderBox>(renderer())).pixelSnappedRoundedRectForPainting(renderer().document().deviceScaleFactor());
         shapeRect.move(offsetFromRoot);
 
         return { clipPath.pathForReferenceRect(shapeRect), WindRule::NonZero };
@@ -3277,17 +3253,16 @@
         if (auto* clipperRenderer = renderer().ensureReferencedSVGResources().referencedClipperRenderer(renderer().document(), referenceClipPathOperation)) {
             // Use the border box as the reference box, even though this is not clearly specified: https://github.com/w3c/csswg-drafts/issues/5786.
             // clippedContentBounds is used as the reference box for inlines, which is also poorly specified: https://github.com/w3c/csswg-drafts/issues/6383.
-            auto referenceBox = computeReferenceBox(renderer(), CSSBoxType::BorderBox, offsetFromRoot, clippedContentBounds);
-            auto snappedReferenceBox = snapRectToDevicePixels(referenceBox, renderer().document().deviceScaleFactor());
+            auto referenceBox = referenceBoxRectForClipPath(CSSBoxType::BorderBox, offsetFromRoot, clippedContentBounds);
+            auto snappedReferenceBox = snapRectToDevicePixelsIfNeeded(referenceBox, renderer());
             auto offset = snappedReferenceBox.location();
 
-            auto snappedClippingBounds = snapRectToDevicePixels(clippedContentBounds, renderer().document().deviceScaleFactor());
+            auto snappedClippingBounds = snapRectToDevicePixelsIfNeeded(clippedContentBounds, renderer());
             snappedClippingBounds.moveBy(-offset);
 
             stateSaver.save();
             context.translate(offset);
-            FloatRect clipPathReferenceBox { { }, referenceBox.size() };
-            clipperRenderer->applyClippingToContext(context, renderer(), clipPathReferenceBox, snappedClippingBounds, renderer().style().effectiveZoom());
+            clipperRenderer->applyClippingToContext(context, renderer(), { { }, referenceBox.size() }, snappedClippingBounds, renderer().style().effectiveZoom());
             context.translate(-offset);
         }
     }

Modified: trunk/Source/WebCore/rendering/RenderLayer.h (292524 => 292525)


--- trunk/Source/WebCore/rendering/RenderLayer.h	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/rendering/RenderLayer.h	2022-04-07 10:06:46 UTC (rev 292525)
@@ -698,6 +698,8 @@
     WEBCORE_EXPORT IntRect absoluteBoundingBox() const;
     // Device pixel snapped bounding box relative to the root. absoluteBoundingBox() callers will be directed to this.
     FloatRect absoluteBoundingBoxForPainting() const;
+    // Returns the 'reference box' used for clip-path handling (different rules for inlines, wrt. to boxes).
+    FloatRect referenceBoxRectForClipPath(CSSBoxType, const LayoutSize& offsetFromRoot, const LayoutRect& rootRelativeBounds) const;
 
     // Bounds used for layer overlap testing in RenderLayerCompositor.
     LayoutRect overlapBounds() const;

Modified: trunk/Source/WebCore/rendering/RenderLayerModelObject.cpp (292524 => 292525)


--- trunk/Source/WebCore/rendering/RenderLayerModelObject.cpp	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/rendering/RenderLayerModelObject.cpp	2022-04-07 10:06:46 UTC (rev 292525)
@@ -318,5 +318,28 @@
 }
 #endif
 
+bool rendererNeedsPixelSnapping(const RenderLayerModelObject& renderer)
+{
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+    if (renderer.document().settings().layerBasedSVGEngineEnabled() && renderer.isSVGLayerAwareRenderer() && !renderer.isSVGRoot())
+        return false;
+#endif
+    return true;
+}
+
+FloatRect snapRectToDevicePixelsIfNeeded(const LayoutRect& rect, const RenderLayerModelObject& renderer)
+{
+    if (!rendererNeedsPixelSnapping(renderer))
+        return rect;
+    return snapRectToDevicePixels(rect, renderer.document().deviceScaleFactor());
+}
+
+FloatRect snapRectToDevicePixelsIfNeeded(const FloatRect& rect, const RenderLayerModelObject& renderer)
+{
+    if (!rendererNeedsPixelSnapping(renderer))
+        return rect;
+    return snapRectToDevicePixels(LayoutRect { rect }, renderer.document().deviceScaleFactor());
+}
+
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/rendering/RenderLayerModelObject.h (292524 => 292525)


--- trunk/Source/WebCore/rendering/RenderLayerModelObject.h	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/rendering/RenderLayerModelObject.h	2022-04-07 10:06:46 UTC (rev 292525)
@@ -96,6 +96,11 @@
     static bool s_layerWasSelfPainting;
 };
 
+// Pixel-snapping (== 'device pixel alignment') helpers.
+bool rendererNeedsPixelSnapping(const RenderLayerModelObject&);
+FloatRect snapRectToDevicePixelsIfNeeded(const LayoutRect&, const RenderLayerModelObject&);
+FloatRect snapRectToDevicePixelsIfNeeded(const FloatRect&, const RenderLayerModelObject&);
+
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderLayerModelObject, isRenderLayerModelObject())

Modified: trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp (292524 => 292525)


--- trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp	2022-04-07 10:06:46 UTC (rev 292525)
@@ -343,26 +343,6 @@
     return true;
 }
 
-FloatRect SVGRenderSupport::transformReferenceBox(const RenderElement& renderer, const SVGElement& element, const RenderStyle& style)
-{
-    switch (style.transformBox()) {
-    case TransformBox::BorderBox:
-        // For SVG elements without an associated CSS layout box, the used value for border-box is stroke-box.
-    case TransformBox::StrokeBox:
-        return renderer.strokeBoundingBox();
-    case TransformBox::ContentBox:
-        // For SVG elements without an associated CSS layout box, the used value for content-box is fill-box.
-    case TransformBox::FillBox:
-        return renderer.objectBoundingBox();
-    case TransformBox::ViewBox: {
-        FloatSize viewportSize;
-        SVGLengthContext(&element).determineViewport(viewportSize);
-        return FloatRect { { }, viewportSize };
-        }
-    }
-    return { };
-}
-
 inline FloatRect clipPathReferenceBox(const RenderElement& renderer, CSSBoxType boxType)
 {
     FloatRect referenceBox;

Modified: trunk/Source/WebCore/rendering/svg/SVGRenderSupport.h (292524 => 292525)


--- trunk/Source/WebCore/rendering/svg/SVGRenderSupport.h	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/rendering/svg/SVGRenderSupport.h	2022-04-07 10:06:46 UTC (rev 292525)
@@ -82,8 +82,6 @@
 
     static void styleChanged(RenderElement&, const RenderStyle*);
     
-    static FloatRect transformReferenceBox(const RenderElement&, const SVGElement&, const RenderStyle&);
-
 #if ENABLE(CSS_COMPOSITING)
     static bool isolatesBlending(const RenderStyle&);
     static void updateMaskedAncestorShouldIsolateBlending(const RenderElement&);

Modified: trunk/Source/WebCore/svg/SVGGraphicsElement.cpp (292524 => 292525)


--- trunk/Source/WebCore/svg/SVGGraphicsElement.cpp	2022-04-07 07:11:27 UTC (rev 292524)
+++ trunk/Source/WebCore/svg/SVGGraphicsElement.cpp	2022-04-07 10:06:46 UTC (rev 292525)
@@ -80,12 +80,10 @@
 
     // Honor any of the transform-related CSS properties if set.
     if (hasSpecifiedTransform || (style && (style->translate() || style->scale() || style->rotate()))) {
-        auto boundingBox = SVGRenderSupport::transformReferenceBox(*renderer(), *this, *style);
-        
         // Note: objectBoundingBox is an emptyRect for elements like pattern or clipPath.
         // See the "Object bounding box units" section of http://dev.w3.org/csswg/css3-transforms/
         TransformationMatrix transform;
-        style->applyTransform(transform, boundingBox);
+        style->applyTransform(transform, renderer()->transformReferenceBoxRect());
 
         // Flatten any 3D transform.
         matrix = transform.toAffineTransform();
@@ -100,7 +98,7 @@
 
     // If we didn't have the CSS "transform" property set, we must account for the "transform" attribute.
     if (!hasSpecifiedTransform && style) {
-        auto boundingBox = SVGRenderSupport::transformReferenceBox(*renderer(), *this, *style);
+        auto boundingBox = renderer()->transformReferenceBoxRect();
         auto t = floatPointForLengthPoint(style->transformOriginXY(), boundingBox.size()) + boundingBox.location();
         matrix.translate(t);
         matrix *= transform().concatenate();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to