Skip to content

Commit

Permalink
LibWeb: Support masking of SVGForeignObjectPaintable
Browse files Browse the repository at this point in the history
  • Loading branch information
kalenikaliaksandr committed Apr 25, 2024
1 parent 67e912f commit 5dd4efe
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <LibWeb/Layout/InlineNode.h>
#include <LibWeb/Layout/ListItemMarkerBox.h>
#include <LibWeb/Layout/ReplacedBox.h>
#include <LibWeb/Layout/SVGMaskBox.h>

namespace Web::Layout {

Expand Down Expand Up @@ -111,6 +112,9 @@ void InlineLevelIterator::compute_next()
return;
do {
m_next_node = next_inline_node_in_pre_order(*m_next_node, m_containing_block);
if (m_next_node && is<SVGMaskBox>(*m_next_node)) {
m_next_node = m_next_node->next_sibling();
}
} while (m_next_node && (!m_next_node->is_inline() && !m_next_node->is_out_of_flow(m_inline_formatting_context)));
}

Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/Layout/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class Node
virtual bool is_viewport() const { return false; }
virtual bool is_svg_box() const { return false; }
virtual bool is_svg_geometry_box() const { return false; }
virtual bool is_svg_mask_box() const { return false; }
virtual bool is_svg_svg_box() const { return false; }
virtual bool is_label() const { return false; }
virtual bool is_replaced_box() const { return false; }
Expand Down
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ void SVGFormattingContext::layout_svg_element(Box const& child)
bfc.run(child, LayoutMode::Normal, *m_available_space);
auto& child_state = m_state.get_mutable(child);
child_state.set_content_offset(child_state.offset.translated(m_svg_offset));
child.for_each_child_of_type<SVGMaskBox>([&](SVGMaskBox const& child) {
layout_svg_element(child);
});
} else if (is<SVGGraphicsBox>(child)) {
layout_graphics_element(static_cast<SVGGraphicsBox const&>(child));
}
Expand Down
5 changes: 5 additions & 0 deletions Userland/Libraries/LibWeb/Layout/SVGMaskBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ class SVGMaskBox : public SVGGraphicsBox {
SVGMaskBox(DOM::Document&, SVG::SVGMaskElement&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~SVGMaskBox() override = default;

virtual bool is_svg_mask_box() const override { return true; }

SVG::SVGMaskElement& dom_node() { return verify_cast<SVG::SVGMaskElement>(SVGGraphicsBox::dom_node()); }
SVG::SVGMaskElement const& dom_node() const { return verify_cast<SVG::SVGMaskElement>(SVGGraphicsBox::dom_node()); }

virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
};

template<>
inline bool Node::fast_is<SVGMaskBox>() const { return is_svg_mask_box(); }

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

#include <LibWeb/Layout/SVGForeignObjectBox.h>
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Painting/SVGMaskable.h>

namespace Web::Painting {

class SVGForeignObjectPaintable final : public PaintableWithLines {
class SVGForeignObjectPaintable final : public PaintableWithLines
, public SVGMaskable {
JS_CELL(SVGForeignObjectPaintable, PaintableWithLines);
JS_DECLARE_ALLOCATOR(SVGForeignObjectPaintable);

Expand All @@ -24,6 +26,11 @@ class SVGForeignObjectPaintable final : public PaintableWithLines {

Layout::SVGForeignObjectBox const& layout_box() const;

virtual JS::GCPtr<DOM::Node const> dom_node_of_svg() const override { return dom_node(); }
virtual Optional<CSSPixelRect> get_masking_area() const override { return SVGMaskable::get_masking_area_of_svg(); }
virtual Optional<Gfx::Bitmap::MaskKind> get_mask_type() const override { return SVGMaskable::get_mask_type_of_svg(); }
virtual RefPtr<Gfx::Bitmap> calculate_mask(PaintContext& paint_context, CSSPixelRect const& masking_area) const override { return SVGMaskable::calculate_mask_of_svg(paint_context, masking_area); }

protected:
SVGForeignObjectPaintable(Layout::SVGForeignObjectBox const&);
};
Expand Down

0 comments on commit 5dd4efe

Please sign in to comment.