diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 5169b399eb8..e07c45bc0ce 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/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 diff --git a/Userland/Libraries/LibWeb/Layout/SVGForeignObjectBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGForeignObjectBox.cpp new file mode 100644 index 00000000000..5569a6127f0 --- /dev/null +++ b/Userland/Libraries/LibWeb/Layout/SVGForeignObjectBox.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024, Aliaksandr Kalenik + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::Layout { + +JS_DEFINE_ALLOCATOR(SVGForeignObjectBox); + +SVGForeignObjectBox::SVGForeignObjectBox(DOM::Document& document, SVG::SVGForeignObjectElement& element, NonnullRefPtr properties) + : BlockContainer(document, &element, properties) +{ +} + +JS::GCPtr SVGForeignObjectBox::create_paintable() const +{ + return Painting::SVGForeignObjectPaintable::create(*this); +} + +} diff --git a/Userland/Libraries/LibWeb/Layout/SVGForeignObjectBox.h b/Userland/Libraries/LibWeb/Layout/SVGForeignObjectBox.h new file mode 100644 index 00000000000..5e9412bc0dc --- /dev/null +++ b/Userland/Libraries/LibWeb/Layout/SVGForeignObjectBox.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, Aliaksandr Kalenik + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Web::Layout { + +class SVGForeignObjectBox final : public BlockContainer { + JS_CELL(SVGForeignObjectBox, BlockContainer); + JS_DECLARE_ALLOCATOR(SVGForeignObjectBox); + +public: + SVGForeignObjectBox(DOM::Document&, SVG::SVGForeignObjectElement&, NonnullRefPtr); + virtual ~SVGForeignObjectBox() override = default; + + SVG::SVGForeignObjectElement& dom_node() { return static_cast(*BlockContainer::dom_node()); } + SVG::SVGForeignObjectElement const& dom_node() const { return static_cast(*BlockContainer::dom_node()); } + + virtual JS::GCPtr create_paintable() const override; +}; + +} diff --git a/Userland/Libraries/LibWeb/Painting/SVGForeignObjectPaintable.cpp b/Userland/Libraries/LibWeb/Painting/SVGForeignObjectPaintable.cpp new file mode 100644 index 00000000000..60a2d6fc6e4 --- /dev/null +++ b/Userland/Libraries/LibWeb/Painting/SVGForeignObjectPaintable.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024, Aliaksandr Kalenik + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::Painting { + +JS_DEFINE_ALLOCATOR(SVGForeignObjectPaintable); + +JS::NonnullGCPtr SVGForeignObjectPaintable::create(Layout::SVGForeignObjectBox const& layout_box) +{ + return layout_box.heap().allocate_without_realm(layout_box); +} + +SVGForeignObjectPaintable::SVGForeignObjectPaintable(Layout::SVGForeignObjectBox const& layout_box) + : PaintableWithLines(layout_box) +{ +} + +Layout::SVGForeignObjectBox const& SVGForeignObjectPaintable::layout_box() const +{ + return static_cast(layout_node()); +} + +TraversalDecision SVGForeignObjectPaintable::hit_test(CSSPixelPoint position, HitTestType type, Function const& callback) const +{ + return PaintableWithLines::hit_test(position, type, callback); +} + +void SVGForeignObjectPaintable::paint(PaintContext& context, PaintPhase phase) const +{ + PaintableWithLines::paint(context, phase); +} + +} diff --git a/Userland/Libraries/LibWeb/Painting/SVGForeignObjectPaintable.h b/Userland/Libraries/LibWeb/Painting/SVGForeignObjectPaintable.h new file mode 100644 index 00000000000..88f6dc2e29d --- /dev/null +++ b/Userland/Libraries/LibWeb/Painting/SVGForeignObjectPaintable.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024, Aliaksandr Kalenik + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::Painting { + +class SVGForeignObjectPaintable final : public PaintableWithLines { + JS_CELL(SVGForeignObjectPaintable, PaintableWithLines); + JS_DECLARE_ALLOCATOR(SVGForeignObjectPaintable); + +public: + static JS::NonnullGCPtr create(Layout::SVGForeignObjectBox const&); + + virtual TraversalDecision hit_test(CSSPixelPoint, HitTestType, Function const& callback) const override; + + virtual void paint(PaintContext&, PaintPhase) const override; + + Layout::SVGForeignObjectBox const& layout_box() const; + +protected: + SVGForeignObjectPaintable(Layout::SVGForeignObjectBox const&); +}; + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp index 8804fb3ebf8..99e41422384 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -47,7 +48,7 @@ void SVGForeignObjectElement::visit_edges(Cell::Visitor& visitor) JS::GCPtr SVGForeignObjectElement::create_layout_node(NonnullRefPtr style) { - return heap().allocate_without_realm(document(), this, move(style)); + return heap().allocate_without_realm(document(), *this, move(style)); } void SVGForeignObjectElement::apply_presentational_hints(CSS::StyleProperties& style) const