Explorar el Código

LibWeb: Add layout node and paintable for SVGForeignObjectElement

Introduces separate layout and paintable type for foreign element.
It is necessary to inherit SVGForeignObjectPaintable from SVGMaskable
in upcoming changes.
Aliaksandr Kalenik hace 1 año
padre
commit
7d05fe84bc

+ 2 - 0
Userland/Libraries/LibWeb/CMakeLists.txt

@@ -483,6 +483,7 @@ set(SOURCES
     Layout/ReplacedBox.cpp
     Layout/SVGBox.cpp
     Layout/SVGFormattingContext.cpp
+    Layout/SVGForeignObjectBox.cpp
     Layout/SVGGeometryBox.cpp
     Layout/SVGGraphicsBox.cpp
     Layout/SVGSVGBox.cpp
@@ -540,6 +541,7 @@ set(SOURCES
     Painting/PaintableFragment.cpp
     Painting/RadioButtonPaintable.cpp
     Painting/RecordingPainter.cpp
+    Painting/SVGForeignObjectPaintable.cpp
     Painting/SVGPathPaintable.cpp
     Painting/SVGGraphicsPaintable.cpp
     Painting/SVGMaskPaintable.cpp

+ 25 - 0
Userland/Libraries/LibWeb/Layout/SVGForeignObjectBox.cpp

@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/Layout/SVGForeignObjectBox.h>
+#include <LibWeb/Painting/SVGForeignObjectPaintable.h>
+#include <LibWeb/SVG/SVGSVGElement.h>
+
+namespace Web::Layout {
+
+JS_DEFINE_ALLOCATOR(SVGForeignObjectBox);
+
+SVGForeignObjectBox::SVGForeignObjectBox(DOM::Document& document, SVG::SVGForeignObjectElement& element, NonnullRefPtr<CSS::StyleProperties> properties)
+    : BlockContainer(document, &element, properties)
+{
+}
+
+JS::GCPtr<Painting::Paintable> SVGForeignObjectBox::create_paintable() const
+{
+    return Painting::SVGForeignObjectPaintable::create(*this);
+}
+
+}

+ 30 - 0
Userland/Libraries/LibWeb/Layout/SVGForeignObjectBox.h

@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Optional.h>
+#include <LibWeb/Layout/BlockContainer.h>
+#include <LibWeb/Layout/SVGGraphicsBox.h>
+#include <LibWeb/SVG/SVGForeignObjectElement.h>
+
+namespace Web::Layout {
+
+class SVGForeignObjectBox final : public BlockContainer {
+    JS_CELL(SVGForeignObjectBox, BlockContainer);
+    JS_DECLARE_ALLOCATOR(SVGForeignObjectBox);
+
+public:
+    SVGForeignObjectBox(DOM::Document&, SVG::SVGForeignObjectElement&, NonnullRefPtr<CSS::StyleProperties>);
+    virtual ~SVGForeignObjectBox() override = default;
+
+    SVG::SVGForeignObjectElement& dom_node() { return static_cast<SVG::SVGForeignObjectElement&>(*BlockContainer::dom_node()); }
+    SVG::SVGForeignObjectElement const& dom_node() const { return static_cast<SVG::SVGForeignObjectElement const&>(*BlockContainer::dom_node()); }
+
+    virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
+};
+
+}

+ 39 - 0
Userland/Libraries/LibWeb/Painting/SVGForeignObjectPaintable.cpp

@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/Painting/SVGForeignObjectPaintable.h>
+#include <LibWeb/SVG/SVGSVGElement.h>
+
+namespace Web::Painting {
+
+JS_DEFINE_ALLOCATOR(SVGForeignObjectPaintable);
+
+JS::NonnullGCPtr<SVGForeignObjectPaintable> SVGForeignObjectPaintable::create(Layout::SVGForeignObjectBox const& layout_box)
+{
+    return layout_box.heap().allocate_without_realm<SVGForeignObjectPaintable>(layout_box);
+}
+
+SVGForeignObjectPaintable::SVGForeignObjectPaintable(Layout::SVGForeignObjectBox const& layout_box)
+    : PaintableWithLines(layout_box)
+{
+}
+
+Layout::SVGForeignObjectBox const& SVGForeignObjectPaintable::layout_box() const
+{
+    return static_cast<Layout::SVGForeignObjectBox const&>(layout_node());
+}
+
+TraversalDecision SVGForeignObjectPaintable::hit_test(CSSPixelPoint position, HitTestType type, Function<TraversalDecision(HitTestResult)> const& callback) const
+{
+    return PaintableWithLines::hit_test(position, type, callback);
+}
+
+void SVGForeignObjectPaintable::paint(PaintContext& context, PaintPhase phase) const
+{
+    PaintableWithLines::paint(context, phase);
+}
+
+}

+ 31 - 0
Userland/Libraries/LibWeb/Painting/SVGForeignObjectPaintable.h

@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibWeb/Layout/SVGForeignObjectBox.h>
+#include <LibWeb/Painting/PaintableBox.h>
+
+namespace Web::Painting {
+
+class SVGForeignObjectPaintable final : public PaintableWithLines {
+    JS_CELL(SVGForeignObjectPaintable, PaintableWithLines);
+    JS_DECLARE_ALLOCATOR(SVGForeignObjectPaintable);
+
+public:
+    static JS::NonnullGCPtr<SVGForeignObjectPaintable> create(Layout::SVGForeignObjectBox const&);
+
+    virtual TraversalDecision hit_test(CSSPixelPoint, HitTestType, Function<TraversalDecision(HitTestResult)> const& callback) const override;
+
+    virtual void paint(PaintContext&, PaintPhase) const override;
+
+    Layout::SVGForeignObjectBox const& layout_box() const;
+
+protected:
+    SVGForeignObjectPaintable(Layout::SVGForeignObjectBox const&);
+};
+
+}

+ 2 - 1
Userland/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp

@@ -8,6 +8,7 @@
 #include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/CSS/Parser/Parser.h>
 #include <LibWeb/Layout/BlockContainer.h>
+#include <LibWeb/Layout/SVGForeignObjectBox.h>
 #include <LibWeb/SVG/AttributeNames.h>
 #include <LibWeb/SVG/SVGAnimatedLength.h>
 #include <LibWeb/SVG/SVGForeignObjectElement.h>
@@ -47,7 +48,7 @@ void SVGForeignObjectElement::visit_edges(Cell::Visitor& visitor)
 
 JS::GCPtr<Layout::Node> SVGForeignObjectElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
 {
-    return heap().allocate_without_realm<Layout::BlockContainer>(document(), this, move(style));
+    return heap().allocate_without_realm<Layout::SVGForeignObjectBox>(document(), *this, move(style));
 }
 
 void SVGForeignObjectElement::apply_presentational_hints(CSS::StyleProperties& style) const