summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/Painting/Paintable.cpp16
-rw-r--r--Userland/Libraries/LibWeb/Painting/Paintable.h33
2 files changed, 49 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.cpp b/Userland/Libraries/LibWeb/Painting/Paintable.cpp
index be83683e74..d53563cc0a 100644
--- a/Userland/Libraries/LibWeb/Painting/Paintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/Paintable.cpp
@@ -46,4 +46,20 @@ Optional<HitTestResult> Paintable::hit_test(Gfx::FloatPoint const&, HitTestType)
return {};
}
+Paintable const* Paintable::first_child() const
+{
+ auto* layout_child = m_layout_node.first_child();
+ for (; layout_child && !layout_child->paintable(); layout_child = layout_child->next_sibling())
+ ;
+ return layout_child ? layout_child->paintable() : nullptr;
+}
+
+Paintable const* Paintable::next_sibling() const
+{
+ auto* layout_node = m_layout_node.next_sibling();
+ for (; layout_node && !layout_node->paintable(); layout_node = layout_node->next_sibling())
+ ;
+ return layout_node ? layout_node->paintable() : nullptr;
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.h b/Userland/Libraries/LibWeb/Painting/Paintable.h
index 2a8b13866a..ea4cd28f26 100644
--- a/Userland/Libraries/LibWeb/Painting/Paintable.h
+++ b/Userland/Libraries/LibWeb/Painting/Paintable.h
@@ -49,6 +49,33 @@ class Paintable : public RefCounted<Paintable> {
public:
virtual ~Paintable() = default;
+ Paintable const* first_child() const;
+ Paintable const* next_sibling() const;
+
+ template<typename U, typename Callback>
+ IterationDecision for_each_in_inclusive_subtree_of_type(Callback callback) const
+ {
+ if (is<U>(*this)) {
+ if (callback(static_cast<const U&>(*this)) == IterationDecision::Break)
+ return IterationDecision::Break;
+ }
+ for (auto* child = first_child(); child; child = child->next_sibling()) {
+ if (child->template for_each_in_inclusive_subtree_of_type<U>(callback) == IterationDecision::Break)
+ return IterationDecision::Break;
+ }
+ return IterationDecision::Continue;
+ }
+
+ template<typename U, typename Callback>
+ IterationDecision for_each_in_subtree_of_type(Callback callback) const
+ {
+ for (auto* child = first_child(); child; child = child->next_sibling()) {
+ if (child->template for_each_in_inclusive_subtree_of_type<U>(callback) == IterationDecision::Break)
+ return IterationDecision::Break;
+ }
+ return IterationDecision::Continue;
+ }
+
virtual void paint(PaintContext&, PaintPhase) const { }
virtual void before_children_paint(PaintContext&, PaintPhase) const { }
virtual void after_children_paint(PaintContext&, PaintPhase) const { }
@@ -91,6 +118,9 @@ public:
return *m_containing_block;
}
+ template<typename T>
+ bool fast_is() const = delete;
+
protected:
explicit Paintable(Layout::Node const& layout_node)
: m_layout_node(layout_node)
@@ -112,4 +142,7 @@ inline DOM::Node const* HitTestResult::dom_node() const
return paintable->dom_node();
}
+template<>
+inline bool Paintable::fast_is<PaintableBox>() const { return m_layout_node.is_box(); }
+
}