Title: [287921] trunk/Source/WebCore
Revision
287921
Author
zimmerm...@webkit.org
Date
2022-01-12 05:05:38 -0800 (Wed, 12 Jan 2022)

Log Message

[LBSE] Begin layer-aware RenderSVGContainer implementation
https://bugs.webkit.org/show_bug.cgi?id=235100

Reviewed by Rob Buis.

Create RenderSVGContainer based on the downstream LBSE implementation.

This patch does not yet enable the creation of RenderSVGContainer
renderers if LBSE is enabled, since the derived classes, such as
RenderSVGHiddenContainer / RenderSVGViewportContainer / ..., are still
missing in LBSE.

Covered by existing tests, no change in behaviour.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* rendering/RenderObject.h:
(WebCore::RenderObject::isSVGContainer const):
* rendering/RenderTreeAsText.cpp:
(WebCore::write):
* rendering/svg/RenderSVGContainer.cpp: Added.
(WebCore::RenderSVGContainer::RenderSVGContainer):
(WebCore::RenderSVGContainer::layout):
(WebCore::RenderSVGContainer::calculateViewport):
(WebCore::RenderSVGContainer::layoutChildren):
(WebCore::RenderSVGContainer::styleDidChange):
(WebCore::RenderSVGContainer::selfWillPaint):
(WebCore::RenderSVGContainer::paint):
(WebCore::RenderSVGContainer::nodeAtPoint):
* rendering/svg/RenderSVGContainer.h: Added.
(WebCore::RenderSVGContainer::isObjectBoundingBoxValid const):
(WebCore::RenderSVGContainer::updateLayerInformation):
(WebCore::RenderSVGContainer::pointIsInsideViewportClip):
* rendering/svg/SVGBoundingBoxComputation.cpp:
(WebCore::SVGBoundingBoxComputation::computeDecoratedBoundingBox const):
(WebCore::SVGBoundingBoxComputation::handleRootOrContainer const):
* rendering/svg/SVGRenderTreeAsText.cpp:
(WebCore::writeSVGContainer):
* rendering/svg/SVGRenderTreeAsText.h:
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::attachInternal):
(WebCore::RenderTreeBuilder::detach):
* rendering/updating/RenderTreeBuilderSVG.cpp:
(WebCore::RenderTreeBuilder::SVG::attach):
(WebCore::RenderTreeBuilder::SVG::detach):
* rendering/updating/RenderTreeBuilderSVG.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287920 => 287921)


--- trunk/Source/WebCore/ChangeLog	2022-01-12 13:02:19 UTC (rev 287920)
+++ trunk/Source/WebCore/ChangeLog	2022-01-12 13:05:38 UTC (rev 287921)
@@ -1,3 +1,52 @@
+2022-01-12  Nikolas Zimmermann  <nzimmerm...@igalia.com>
+
+        [LBSE] Begin layer-aware RenderSVGContainer implementation
+        https://bugs.webkit.org/show_bug.cgi?id=235100
+
+        Reviewed by Rob Buis.
+
+        Create RenderSVGContainer based on the downstream LBSE implementation.
+
+        This patch does not yet enable the creation of RenderSVGContainer
+        renderers if LBSE is enabled, since the derived classes, such as
+        RenderSVGHiddenContainer / RenderSVGViewportContainer / ..., are still
+        missing in LBSE.
+
+        Covered by existing tests, no change in behaviour.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * rendering/RenderObject.h:
+        (WebCore::RenderObject::isSVGContainer const):
+        * rendering/RenderTreeAsText.cpp:
+        (WebCore::write):
+        * rendering/svg/RenderSVGContainer.cpp: Added.
+        (WebCore::RenderSVGContainer::RenderSVGContainer):
+        (WebCore::RenderSVGContainer::layout):
+        (WebCore::RenderSVGContainer::calculateViewport):
+        (WebCore::RenderSVGContainer::layoutChildren):
+        (WebCore::RenderSVGContainer::styleDidChange):
+        (WebCore::RenderSVGContainer::selfWillPaint):
+        (WebCore::RenderSVGContainer::paint):
+        (WebCore::RenderSVGContainer::nodeAtPoint):
+        * rendering/svg/RenderSVGContainer.h: Added.
+        (WebCore::RenderSVGContainer::isObjectBoundingBoxValid const):
+        (WebCore::RenderSVGContainer::updateLayerInformation):
+        (WebCore::RenderSVGContainer::pointIsInsideViewportClip):
+        * rendering/svg/SVGBoundingBoxComputation.cpp:
+        (WebCore::SVGBoundingBoxComputation::computeDecoratedBoundingBox const):
+        (WebCore::SVGBoundingBoxComputation::handleRootOrContainer const):
+        * rendering/svg/SVGRenderTreeAsText.cpp:
+        (WebCore::writeSVGContainer):
+        * rendering/svg/SVGRenderTreeAsText.h:
+        * rendering/updating/RenderTreeBuilder.cpp:
+        (WebCore::RenderTreeBuilder::attachInternal):
+        (WebCore::RenderTreeBuilder::detach):
+        * rendering/updating/RenderTreeBuilderSVG.cpp:
+        (WebCore::RenderTreeBuilder::SVG::attach):
+        (WebCore::RenderTreeBuilder::SVG::detach):
+        * rendering/updating/RenderTreeBuilderSVG.h:
+
 2022-01-12  Chris Lord  <cl...@igalia.com>
 
         [WPE] Enable WebGL ANGLE support

Modified: trunk/Source/WebCore/Sources.txt (287920 => 287921)


--- trunk/Source/WebCore/Sources.txt	2022-01-12 13:02:19 UTC (rev 287920)
+++ trunk/Source/WebCore/Sources.txt	2022-01-12 13:05:38 UTC (rev 287921)
@@ -2472,6 +2472,7 @@
 rendering/svg/LegacyRenderSVGRoot.cpp
 rendering/svg/LegacyRenderSVGShape.cpp
 rendering/svg/RenderSVGBlock.cpp
+rendering/svg/RenderSVGContainer.cpp
 rendering/svg/RenderSVGEllipse.cpp
 rendering/svg/RenderSVGForeignObject.cpp
 rendering/svg/RenderSVGGradientStop.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (287920 => 287921)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-01-12 13:02:19 UTC (rev 287920)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-01-12 13:05:38 UTC (rev 287921)
@@ -1239,6 +1239,7 @@
 		4358E8811360A31700E4748C /* FEDropShadow.h in Headers */ = {isa = PBXBuildFile; fileRef = 4358E87F1360A31700E4748C /* FEDropShadow.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4358E8861360A33B00E4748C /* SVGFEDropShadowElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4358E8831360A33B00E4748C /* SVGFEDropShadowElement.h */; };
 		436708C112D9CA4B00044234 /* RenderSVGBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = 4367088212D9CA4A00044234 /* RenderSVGBlock.h */; };
+		436708C433F8CA4C10044234 /* RenderSVGContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 4367077412D9BC4A00044234 /* RenderSVGContainer.h */; };
 		436708C312D9CA4B00044234 /* LegacyRenderSVGContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 4367088412D9CA4A00044234 /* LegacyRenderSVGContainer.h */; };
 		436708C512D9CA4B00044234 /* RenderSVGGradientStop.h in Headers */ = {isa = PBXBuildFile; fileRef = 4367088612D9CA4A00044234 /* RenderSVGGradientStop.h */; };
 		436708C712D9CA4B00044234 /* RenderSVGHiddenContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 4367088812D9CA4A00044234 /* RenderSVGHiddenContainer.h */; };
@@ -8983,8 +8984,10 @@
 		4358E8841360A33B00E4748C /* SVGFEDropShadowElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SVGFEDropShadowElement.idl; sourceTree = "<group>"; };
 		4367088112D9CA4A00044234 /* RenderSVGBlock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGBlock.cpp; sourceTree = "<group>"; };
 		4367088212D9CA4A00044234 /* RenderSVGBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGBlock.h; sourceTree = "<group>"; };
+		4367088442A9AC3B10044234 /* RenderSVGContainer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGContainer.cpp; sourceTree = "<group>"; };
 		4367088312D9CA4A00044234 /* LegacyRenderSVGContainer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LegacyRenderSVGContainer.cpp; sourceTree = "<group>"; };
 		4367088412D9CA4A00044234 /* LegacyRenderSVGContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LegacyRenderSVGContainer.h; sourceTree = "<group>"; };
+		4367077412D9BC4A00044234 /* RenderSVGContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGContainer.h; sourceTree = "<group>"; };
 		4367088512D9CA4A00044234 /* RenderSVGGradientStop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGGradientStop.cpp; sourceTree = "<group>"; };
 		4367088612D9CA4A00044234 /* RenderSVGGradientStop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGGradientStop.h; sourceTree = "<group>"; };
 		4367088712D9CA4A00044234 /* RenderSVGHiddenContainer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGHiddenContainer.cpp; sourceTree = "<group>"; };
@@ -18931,6 +18934,8 @@
 				4367088112D9CA4A00044234 /* RenderSVGBlock.cpp */,
 				4367088212D9CA4A00044234 /* RenderSVGBlock.h */,
 				CDF747EA270F6D88008FEEEC /* RenderSVGBlockInlines.h */,
+				4367088442A9AC3B10044234 /* RenderSVGContainer.cpp */,
+				4367077412D9BC4A00044234 /* RenderSVGContainer.h */,
 				2B42359F15250F6000DBBCD8 /* RenderSVGEllipse.cpp */,
 				2B4235A015250F6000DBBCD8 /* RenderSVGEllipse.h */,
 				43C092B912D9E4EE00A989C3 /* RenderSVGForeignObject.cpp */,
@@ -36738,6 +36743,7 @@
 				BC5EB6680E81CB7100B25965 /* RenderStyleConstants.h in Headers */,
 				436708C112D9CA4B00044234 /* RenderSVGBlock.h in Headers */,
 				CDF747EB270F6D88008FEEEC /* RenderSVGBlockInlines.h in Headers */,
+				436708C433F8CA4C10044234 /* RenderSVGContainer.h in Headers */,
 				2B365C841525119E0091D27B /* RenderSVGEllipse.h in Headers */,
 				43C092BC12D9E4EE00A989C3 /* RenderSVGForeignObject.h in Headers */,
 				436708C512D9CA4B00044234 /* RenderSVGGradientStop.h in Headers */,

Modified: trunk/Source/WebCore/rendering/RenderObject.h (287920 => 287921)


--- trunk/Source/WebCore/rendering/RenderObject.h	2022-01-12 13:02:19 UTC (rev 287920)
+++ trunk/Source/WebCore/rendering/RenderObject.h	2022-01-12 13:05:38 UTC (rev 287921)
@@ -329,6 +329,7 @@
     virtual bool isRenderSVGBlock() const { return false; };
     virtual bool isLegacySVGRoot() const { return false; }
     virtual bool isSVGRoot() const { return false; }
+    virtual bool isSVGContainer() const { return false; }
     virtual bool isLegacySVGContainer() const { return false; }
     virtual bool isSVGTransformableContainer() const { return false; }
     virtual bool isSVGViewportContainer() const { return false; }

Modified: trunk/Source/WebCore/rendering/RenderTreeAsText.cpp (287920 => 287921)


--- trunk/Source/WebCore/rendering/RenderTreeAsText.cpp	2022-01-12 13:02:19 UTC (rev 287920)
+++ trunk/Source/WebCore/rendering/RenderTreeAsText.cpp	2022-01-12 13:05:38 UTC (rev 287921)
@@ -59,6 +59,7 @@
 #include "RenderListMarker.h"
 #include "RenderQuote.h"
 #include "RenderRuby.h"
+#include "RenderSVGContainer.h"
 #include "RenderSVGGradientStop.h"
 #include "RenderSVGImage.h"
 #include "RenderSVGInlineText.h"
@@ -578,6 +579,12 @@
         writeSVGResourceContainer(ts, downcast<RenderSVGResourceContainer>(o), behavior);
         return;
     }
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+    if (is<RenderSVGContainer>(o)) {
+        writeSVGContainer(ts, downcast<RenderSVGContainer>(o), behavior);
+        return;
+    }
+#endif
     if (is<LegacyRenderSVGContainer>(o)) {
         writeSVGContainer(ts, downcast<LegacyRenderSVGContainer>(o), behavior);
         return;

Added: trunk/Source/WebCore/rendering/svg/RenderSVGContainer.cpp (0 => 287921)


--- trunk/Source/WebCore/rendering/svg/RenderSVGContainer.cpp	                        (rev 0)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGContainer.cpp	2022-01-12 13:05:38 UTC (rev 287921)
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmerm...@kde.org>
+ * Copyright (C) 2004, 2005, 2007, 2008 Rob Buis <b...@kde.org>
+ * Copyright (C) 2007 Eric Seidel <e...@webkit.org>
+ * Copyright (C) 2009 Google, Inc.  All rights reserved.
+ * Copyright (C) 2009 Dirk Schulze <k...@webkit.org>
+ * Copyright (C) 2020, 2021, 2022 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "RenderSVGContainer.h"
+
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+#include "GraphicsContext.h"
+#include "HitTestRequest.h"
+#include "HitTestResult.h"
+#include "LayoutRepainter.h"
+#include "RenderIterator.h"
+#include "RenderLayer.h"
+#include "RenderTreeBuilder.h"
+#include "RenderView.h"
+// FIXME: [LBSE] Upstream SVGContainerLayout
+// #include "SVGContainerLayout.h"
+#include "SVGRenderingContext.h"
+#include "SVGResources.h"
+#include "SVGResourcesCache.h"
+#include <wtf/IsoMallocInlines.h>
+#include <wtf/StackStats.h>
+
+namespace WebCore {
+
+WTF_MAKE_ISO_ALLOCATED_IMPL(RenderSVGContainer);
+
+RenderSVGContainer::RenderSVGContainer(SVGElement& element, RenderStyle&& style)
+    : RenderSVGModelObject(element, WTFMove(style))
+{
+}
+
+RenderSVGContainer::~RenderSVGContainer() = default;
+
+void RenderSVGContainer::layout()
+{
+    StackStats::LayoutCheckPoint layoutCheckPoint;
+    ASSERT(needsLayout());
+
+    LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
+
+    calculateViewport();
+
+    // Update layer transform before laying out children (SVG needs access to the transform matrices during layout for on-screen text font-size calculations).
+    // Eventually re-update if the transform reference box, relevant for transform-origin, has changed during layout.
+    {
+        // FIXME: [LBSE] Upstream SVGLayerTransformUpdater
+        // SVGLayerTransformUpdater transformUpdater(*this);
+        layoutChildren();
+    }
+
+    updateLayerInformation();
+
+    // Invalidate all resources of this client if our layout changed.
+    if (everHadLayout() && needsLayout())
+        SVGResourcesCache::clientLayoutChanged(*this);
+
+    repainter.repaintAfterLayout();
+    clearNeedsLayout();
+}
+
+void RenderSVGContainer::calculateViewport()
+{
+    // FIXME: [LBSE] Upstream SVGLengthContext changes
+    // element().updateLengthContext();
+}
+
+void RenderSVGContainer::layoutChildren()
+{
+    // FIXME: [LBSE] Upstream SVGContainerLayout
+    // SVGContainerLayout containerLayout(*this);
+    // containerLayout.layoutChildren(selfNeedsLayout() || SVGRenderSupport::filtersForceContainerLayout(*this));
+
+    SVGBoundingBoxComputation boundingBoxComputation(*this);
+    m_objectBoundingBox = boundingBoxComputation.computeDecoratedBoundingBox(SVGBoundingBoxComputation::objectBoundingBoxDecoration, &m_objectBoundingBoxValid);
+    m_strokeBoundingBox = boundingBoxComputation.computeDecoratedBoundingBox(SVGBoundingBoxComputation::strokeBoundingBoxDecoration);
+    setLayoutRect(enclosingLayoutRect(m_objectBoundingBox));
+
+    // FIXME: [LBSE] Upstream SVGContainerLayout
+    // containerLayout.positionChildrenRelativeToContainer();
+}
+
+void RenderSVGContainer::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
+{
+    RenderSVGModelObject::styleDidChange(diff, oldStyle);
+
+    // FIXME: [LBSE] Upstream RenderLayer changes
+    // if (hasLayer())
+    //     layer()->setIsOpportunisticStackingContext(true);
+}
+
+bool RenderSVGContainer::selfWillPaint()
+{
+    auto* resources = SVGResourcesCache::cachedResourcesForRenderer(*this);
+    return resources && resources->filter();
+}
+
+void RenderSVGContainer::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
+{
+    if (paintInfo.context().paintingDisabled())
+        return;
+
+    if (!paintInfo.shouldPaintWithinRoot(*this))
+        return;
+
+    if (style().display() == DisplayType::None)
+        return;
+
+    // FIXME: [LBSE] Upstream SVGRenderSupport changes
+    // if (!SVGRenderSupport::shouldPaintHiddenRenderer(*this))
+    //     return;
+
+    // Spec: groups w/o children still may render filter content.
+    if (!firstChild() && !selfWillPaint())
+        return;
+
+    if (paintInfo.phase == PaintPhase::ClippingMask) {
+        // FIXME: [LBSE] Upstream SVGRenderSupport changes
+        // SVGRenderSupport::paintSVGClippingMask(*this, paintInfo);
+        return;
+    }
+
+    auto adjustedPaintOffset = paintOffset + layoutLocation();
+    if (paintInfo.phase == PaintPhase::Mask) {
+        // FIXME: [LBSE] Upstream SVGRenderSupport changes
+        // SVGRenderSupport::paintSVGMask(*this, paintInfo, adjustedPaintOffset);
+        return;
+    }
+
+    auto visualOverflowRect = visualOverflowRectEquivalent();
+    visualOverflowRect.moveBy(adjustedPaintOffset);
+    if (!visualOverflowRect.intersects(paintInfo.rect))
+        return;
+
+    if (paintInfo.phase == PaintPhase::Outline || paintInfo.phase == PaintPhase::SelfOutline) {
+        // FIXME: [LBSE] Upstream outline painting
+        // paintSVGOutline(paintInfo, adjustedPaintOffset);
+    }
+}
+
+bool RenderSVGContainer::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
+{
+    auto adjustedLocation = accumulatedOffset + layoutLocation();
+
+    auto visualOverflowRect = visualOverflowRectEquivalent();
+    visualOverflowRect.moveBy(adjustedLocation);
+    if (!locationInContainer.intersects(visualOverflowRect))
+        return false;
+
+    auto localPoint = locationInContainer.point();
+    auto boundingBoxTopLeftCorner = flooredLayoutPoint(objectBoundingBox().minXMinYCorner());
+    auto coordinateSystemOriginTranslation = boundingBoxTopLeftCorner - adjustedLocation;
+    localPoint.move(coordinateSystemOriginTranslation);
+
+    if (!SVGRenderSupport::pointInClippingArea(*this, localPoint))
+        return false;
+
+    // Give RenderSVGViewportContainer a chance to apply its viewport clip.
+    if (!pointIsInsideViewportClip(localPoint))
+        return false;
+
+    SVGHitTestCycleDetectionScope hitTestScope(*this);
+    for (auto* child = lastChild(); child; child = child->previousSibling()) {
+        if (!child->hasLayer() && child->nodeAtPoint(request, result, locationInContainer, adjustedLocation, hitTestAction)) {
+            updateHitTestResult(result, locationInContainer.point() - toLayoutSize(adjustedLocation));
+            if (result.addNodeToListBasedTestResult(child->node(), request, locationInContainer, visualOverflowRect) == HitTestProgress::Stop)
+                return true;
+        }
+    }
+
+    // Accessibility wants to return SVG containers, if appropriate.
+    if (request.type() & HitTestRequest::Type::AccessibilityHitTest && m_objectBoundingBox.contains(localPoint)) {
+        updateHitTestResult(result, locationInContainer.point() - toLayoutSize(adjustedLocation));
+        if (result.addNodeToListBasedTestResult(nodeForHitTest(), request, locationInContainer, visualOverflowRect) == HitTestProgress::Stop)
+            return true;
+    }
+    
+    // Spec: Only graphical elements can be targeted by the mouse, period.
+    // 16.4: "If there are no graphics elements whose relevant graphics content is under the pointer (i.e., there is no target element), the event is not dispatched."
+    return false;
+}
+
+}
+
+#endif // ENABLE(LAYER_BASED_SVG_ENGINE)

Added: trunk/Source/WebCore/rendering/svg/RenderSVGContainer.h (0 => 287921)


--- trunk/Source/WebCore/rendering/svg/RenderSVGContainer.h	                        (rev 0)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGContainer.h	2022-01-12 13:05:38 UTC (rev 287921)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmerm...@kde.org>
+ * Copyright (C) 2004, 2005, 2007 Rob Buis <b...@kde.org>
+ * Copyright (C) 2009 Google, Inc.  All rights reserved.
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2020, 2021, 2022 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+#include "RenderSVGModelObject.h"
+#include "SVGBoundingBoxComputation.h"
+
+namespace WebCore {
+
+class SVGElement;
+
+class RenderSVGContainer : public RenderSVGModelObject {
+    WTF_MAKE_ISO_ALLOCATED(RenderSVGContainer);
+public:
+    virtual ~RenderSVGContainer();
+
+    void paint(PaintInfo&, const LayoutPoint&) override;
+    bool isObjectBoundingBoxValid() const { return m_objectBoundingBoxValid; }
+
+    FloatRect objectBoundingBox() const final { return m_objectBoundingBox; }
+    FloatRect strokeBoundingBox() const final { return m_strokeBoundingBox; }
+    FloatRect repaintRectInLocalCoordinates() const final { return SVGBoundingBoxComputation::computeRepaintBoundingBox(*this); }
+
+protected:
+    RenderSVGContainer(SVGElement&, RenderStyle&&);
+
+    const char* renderName() const override { return "RenderSVGContainer"; }
+    bool canHaveChildren() const final { return true; }
+
+    void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
+
+    void layout() override;
+    virtual void layoutChildren();
+    bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override;
+
+    virtual void updateLayerInformation() { }
+    virtual void calculateViewport();
+    virtual bool pointIsInsideViewportClip(const FloatPoint&) { return true; }
+
+    bool selfWillPaint();
+
+    bool m_objectBoundingBoxValid { false };
+    FloatRect m_objectBoundingBox;
+    FloatRect m_strokeBoundingBox;
+
+private:
+    bool isSVGContainer() const final { return true; }
+};
+
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderSVGContainer, isSVGContainer())
+
+#endif // ENABLE(LAYER_BASED_SVG_ENGINE)

Modified: trunk/Source/WebCore/rendering/svg/SVGBoundingBoxComputation.cpp (287920 => 287921)


--- trunk/Source/WebCore/rendering/svg/SVGBoundingBoxComputation.cpp	2022-01-12 13:02:19 UTC (rev 287920)
+++ trunk/Source/WebCore/rendering/svg/SVGBoundingBoxComputation.cpp	2022-01-12 13:05:38 UTC (rev 287921)
@@ -22,6 +22,7 @@
 
 #if ENABLE(LAYER_BASED_SVG_ENGINE)
 #include "RenderChildIterator.h"
+#include "RenderSVGContainer.h"
 #include "RenderSVGForeignObject.h"
 #include "RenderSVGImage.h"
 #include "RenderSVGInline.h"
@@ -63,9 +64,7 @@
 
     // - a container element (RenderSVGRoot / RenderSVGContainer)
     // - "use" (RenderSVGTransformableContainer)
-    // FIXME: [LBSE] Upstream new RenderSVGContainer implementation
-    // if (is<RenderSVGRoot>(m_renderer) || is<RenderSVGContainer>(m_renderer))
-    if (is<RenderSVGRoot>(m_renderer))
+    if (is<RenderSVGRoot>(m_renderer) || is<RenderSVGContainer>(m_renderer))
         return handleRootOrContainer(options, boundingBoxValid);
 
     // - "foreignObject"
@@ -141,10 +140,8 @@
         return layerTransform.isIdentity() ? std::nullopt : std::make_optional(WTFMove(layerTransform));
     };
 
-    auto uniteBoundingBoxRespectingValidity = [] (bool& boxValid, FloatRect& box, const RenderLayerModelObject& /* child */, const FloatRect& childBoundingBox) {
-        // FIXME: [LBSE] Upstream new RenderSVGContainer implementation
-        // bool isBoundingBoxValid = is<RenderSVGContainer>(child) ? downcast<RenderSVGContainer>(child).isObjectBoundingBoxValid() : true;
-        bool isBoundingBoxValid = true;
+    auto uniteBoundingBoxRespectingValidity = [] (bool& boxValid, FloatRect& box, const RenderLayerModelObject& child, const FloatRect& childBoundingBox) {
+        bool isBoundingBoxValid = is<RenderSVGContainer>(child) ? downcast<RenderSVGContainer>(child).isObjectBoundingBoxValid() : true;
         if (!isBoundingBoxValid)
             return;
 
@@ -168,7 +165,7 @@
     //    - Otherwise, set box to be the union of box and the result of invoking the algorithm to compute a bounding box with child
     //      as the element and the same values for space, fill, stroke, markers and clipped as the corresponding algorithm input values.
     for (auto& child : childrenOfType<RenderLayerModelObject>(m_renderer)) {
-        // FIXME: [LBSE] Upstream new RenderSVGContainer implementation
+        // FIXME: [LBSE] Upstream new RenderSVGHiddenContainer implementation
         // if (is<RenderSVGHiddenContainer>(child) || (is<RenderSVGShape>(child) && downcast<RenderSVGShape>(child).isRenderingDisabled()))
         if (is<RenderSVGShape>(child) && downcast<RenderSVGShape>(child).isRenderingDisabled())
             continue;
@@ -175,9 +172,8 @@
 
         SVGBoundingBoxComputation childBoundingBoxComputation(child);
         auto childBox = childBoundingBoxComputation.computeDecoratedBoundingBox(options);
-        // FIXME: Upstream new RenderSVGContainer implementation
-        // if (options.contains(DecorationOption::OverrideBoxWithFilterBoxForChildren) && is<RenderSVGContainer>(child))
-        //    childBoundingBoxComputation.adjustBoxForClippingAndEffects({ DecorationOption::OverrideBoxWithFilterBox }, childBox);
+        if (options.contains(DecorationOption::OverrideBoxWithFilterBoxForChildren) && is<RenderSVGContainer>(child))
+            childBoundingBoxComputation.adjustBoxForClippingAndEffects({ DecorationOption::OverrideBoxWithFilterBox }, childBox);
 
         if (auto layerTransform = transformationMatrixFromChild(child))
             childBox = layerTransform->mapRect(childBox);
@@ -200,7 +196,7 @@
     if (options.contains(DecorationOption::IncludeClippers) && m_renderer.hasNonVisibleOverflow()) {
         ASSERT(m_renderer.hasLayer());
 
-        // FIXME: [LBSE] Upstream new RenderSVGContainer / RenderSVGResourceMarker implementation
+        // FIXME: [LBSE] Upstream new RenderSVGViewportContainer / RenderSVGResourceMarker implementation
         // ASSERT(is<RenderSVGViewportContainer>(m_renderer) || is<RenderSVGResourceMarker>(m_renderer) || is<RenderSVGRoot>(m_renderer));
         ASSERT(is<RenderSVGRoot>(m_renderer));
 

Modified: trunk/Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp (287920 => 287921)


--- trunk/Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp	2022-01-12 13:02:19 UTC (rev 287920)
+++ trunk/Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp	2022-01-12 13:05:38 UTC (rev 287921)
@@ -36,6 +36,7 @@
 #include "NodeRenderStyle.h"
 #include "RenderImage.h"
 #include "RenderIterator.h"
+#include "RenderSVGContainer.h"
 #include "RenderSVGGradientStopInlines.h"
 #include "RenderSVGImage.h"
 #include "RenderSVGInlineText.h"
@@ -537,6 +538,17 @@
     writeChildren(ts, resource, behavior);
 }
 
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+void writeSVGContainer(TextStream& ts, const RenderSVGContainer& container, OptionSet<RenderAsTextFlag> behavior)
+{
+    writeStandardPrefix(ts, container, behavior);
+    writePositionAndStyle(ts, container, behavior);
+    ts << "\n";
+    writeResources(ts, container, behavior);
+    writeChildren(ts, container, behavior);
+}
+#endif
+
 void writeSVGContainer(TextStream& ts, const LegacyRenderSVGContainer& container, OptionSet<RenderAsTextFlag> behavior)
 {
     // Currently RenderSVGResourceFilterPrimitive has no meaningful output.

Modified: trunk/Source/WebCore/rendering/svg/SVGRenderTreeAsText.h (287920 => 287921)


--- trunk/Source/WebCore/rendering/svg/SVGRenderTreeAsText.h	2022-01-12 13:02:19 UTC (rev 287920)
+++ trunk/Source/WebCore/rendering/svg/SVGRenderTreeAsText.h	2022-01-12 13:05:38 UTC (rev 287921)
@@ -34,12 +34,13 @@
 class Color;
 class FloatRect;
 class FloatSize;
+class LegacyRenderSVGContainer;
 class LegacyRenderSVGRoot;
 class LegacyRenderSVGShape;
 class Node;
 class RenderImage;
 class RenderObject;
-class LegacyRenderSVGContainer;
+class RenderSVGContainer;
 class RenderSVGGradientStop;
 class RenderSVGImage;
 class RenderSVGInlineText;
@@ -59,6 +60,9 @@
 void writeSVGGradientStop(WTF::TextStream&, const RenderSVGGradientStop&, OptionSet<RenderAsTextFlag>);
 void writeSVGResourceContainer(WTF::TextStream&, const RenderSVGResourceContainer&, OptionSet<RenderAsTextFlag>);
 void writeSVGContainer(WTF::TextStream&, const LegacyRenderSVGContainer&, OptionSet<RenderAsTextFlag>);
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+void writeSVGContainer(WTF::TextStream&, const RenderSVGContainer&, OptionSet<RenderAsTextFlag>);
+#endif
 void writeSVGImage(WTF::TextStream&, const RenderSVGImage&, OptionSet<RenderAsTextFlag>);
 void writeSVGInlineText(WTF::TextStream&, const RenderSVGInlineText&, OptionSet<RenderAsTextFlag>);
 void writeSVGText(WTF::TextStream&, const RenderSVGText&, OptionSet<RenderAsTextFlag>);

Modified: trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp (287920 => 287921)


--- trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp	2022-01-12 13:02:19 UTC (rev 287920)
+++ trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp	2022-01-12 13:05:38 UTC (rev 287921)
@@ -49,6 +49,7 @@
 #include "RenderRuby.h"
 #include "RenderRubyBase.h"
 #include "RenderRubyRun.h"
+#include "RenderSVGContainer.h"
 #include "RenderSVGInline.h"
 #include "RenderSVGRoot.h"
 #include "RenderSVGText.h"
@@ -281,6 +282,13 @@
         return;
     }
 
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+    if (is<RenderSVGContainer>(parent)) {
+        svgBuilder().attach(downcast<RenderSVGContainer>(parent), WTFMove(child), beforeChild);
+        return;
+    }
+#endif
+
     if (is<LegacyRenderSVGContainer>(parent)) {
         svgBuilder().attach(downcast<LegacyRenderSVGContainer>(parent), WTFMove(child), beforeChild);
         return;
@@ -379,6 +387,11 @@
     if (is<RenderSVGInline>(parent))
         return svgBuilder().detach(downcast<RenderSVGInline>(parent), child);
 
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+    if (is<RenderSVGContainer>(parent))
+        return svgBuilder().detach(downcast<RenderSVGContainer>(parent), child);
+#endif
+
     if (is<LegacyRenderSVGContainer>(parent))
         return svgBuilder().detach(downcast<LegacyRenderSVGContainer>(parent), child);
 

Modified: trunk/Source/WebCore/rendering/updating/RenderTreeBuilderSVG.cpp (287920 => 287921)


--- trunk/Source/WebCore/rendering/updating/RenderTreeBuilderSVG.cpp	2022-01-12 13:02:19 UTC (rev 287920)
+++ trunk/Source/WebCore/rendering/updating/RenderTreeBuilderSVG.cpp	2022-01-12 13:05:38 UTC (rev 287921)
@@ -28,6 +28,7 @@
 
 #include "LegacyRenderSVGContainer.h"
 #include "LegacyRenderSVGRoot.h"
+#include "RenderSVGContainer.h"
 #include "RenderSVGInline.h"
 #include "RenderSVGRoot.h"
 #include "RenderSVGText.h"
@@ -50,6 +51,15 @@
     SVGResourcesCache::clientWasAddedToTree(childToAdd);
 }
 
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+void RenderTreeBuilder::SVG::attach(RenderSVGContainer& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild)
+{
+    auto& childToAdd = *child;
+    m_builder.attachToRenderElement(parent, WTFMove(child), beforeChild);
+    SVGResourcesCache::clientWasAddedToTree(childToAdd);
+}
+#endif
+
 void RenderTreeBuilder::SVG::attach(LegacyRenderSVGContainer& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild)
 {
     auto& childToAdd = *child;
@@ -117,6 +127,14 @@
     return takenChild;
 }
 
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+RenderPtr<RenderObject> RenderTreeBuilder::SVG::detach(RenderSVGContainer& parent, RenderObject& child)
+{
+    SVGResourcesCache::clientWillBeRemovedFromTree(child);
+    return m_builder.detachFromRenderElement(parent, child);
+}
+#endif
+
 RenderPtr<RenderObject> RenderTreeBuilder::SVG::detach(LegacyRenderSVGContainer& parent, RenderObject& child)
 {
     SVGResourcesCache::clientWillBeRemovedFromTree(child);

Modified: trunk/Source/WebCore/rendering/updating/RenderTreeBuilderSVG.h (287920 => 287921)


--- trunk/Source/WebCore/rendering/updating/RenderTreeBuilderSVG.h	2022-01-12 13:02:19 UTC (rev 287920)
+++ trunk/Source/WebCore/rendering/updating/RenderTreeBuilderSVG.h	2022-01-12 13:05:38 UTC (rev 287921)
@@ -29,8 +29,9 @@
 
 namespace WebCore {
 
+class LegacyRenderSVGContainer;
 class LegacyRenderSVGRoot;
-class LegacyRenderSVGContainer;
+class RenderSVGContainer;
 class RenderSVGInline;
 class RenderSVGRoot;
 class RenderSVGText;
@@ -40,20 +41,24 @@
 public:
     SVG(RenderTreeBuilder&);
 
+#if ENABLE(LAYER_BASED_SVG_ENGINE)
+    void attach(RenderSVGRoot& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
+    void attach(RenderSVGContainer& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
+#endif
     void attach(LegacyRenderSVGRoot& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
     void attach(LegacyRenderSVGContainer& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
     void attach(RenderSVGInline& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
+
+    void attach(RenderSVGText& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
+
 #if ENABLE(LAYER_BASED_SVG_ENGINE)
-    void attach(RenderSVGRoot& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
+    RenderPtr<RenderObject> detach(RenderSVGRoot& parent, RenderObject& child) WARN_UNUSED_RETURN;
+    RenderPtr<RenderObject> detach(RenderSVGContainer& parent, RenderObject& child) WARN_UNUSED_RETURN;
 #endif
-    void attach(RenderSVGText& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
-
     RenderPtr<RenderObject> detach(LegacyRenderSVGRoot& parent, RenderObject& child) WARN_UNUSED_RETURN;
     RenderPtr<RenderObject> detach(LegacyRenderSVGContainer& parent, RenderObject& child) WARN_UNUSED_RETURN;
     RenderPtr<RenderObject> detach(RenderSVGInline& parent, RenderObject& child) WARN_UNUSED_RETURN;
-#if ENABLE(LAYER_BASED_SVG_ENGINE)
-    RenderPtr<RenderObject> detach(RenderSVGRoot& parent, RenderObject& child) WARN_UNUSED_RETURN;
-#endif
+
     RenderPtr<RenderObject> detach(RenderSVGText& parent, RenderObject& child) WARN_UNUSED_RETURN;
 
 private:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to