From 28fabd4728a01a73118b7e721b30d783a14fee44 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 15 Sep 2021 14:53:44 +0200 Subject: [PATCH] LibWeb: Make Layout::Node::paint() pure virtual In the past, the base class implementation of this was used to descend into subtrees and paint children. That is now taken care of by StackingContext::paint_descendants() instead, and nothing used this. --- Userland/Libraries/LibWeb/Layout/BreakNode.cpp | 4 ++++ Userland/Libraries/LibWeb/Layout/BreakNode.h | 2 ++ Userland/Libraries/LibWeb/Layout/Node.cpp | 14 -------------- Userland/Libraries/LibWeb/Layout/Node.h | 2 +- Userland/Libraries/LibWeb/Layout/TextNode.cpp | 4 ++++ Userland/Libraries/LibWeb/Layout/TextNode.h | 1 + 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/BreakNode.cpp b/Userland/Libraries/LibWeb/Layout/BreakNode.cpp index 2cd02d44a4..cbc1c543e1 100644 --- a/Userland/Libraries/LibWeb/Layout/BreakNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/BreakNode.cpp @@ -26,4 +26,8 @@ void BreakNode::split_into_lines(InlineFormattingContext& context, LayoutMode) line_box.add_fragment(*this, 0, 0, 0, context.containing_block().line_height()); } +void BreakNode::paint(PaintContext&, PaintPhase) +{ +} + } diff --git a/Userland/Libraries/LibWeb/Layout/BreakNode.h b/Userland/Libraries/LibWeb/Layout/BreakNode.h index 873f55ae30..6d0bc97396 100644 --- a/Userland/Libraries/LibWeb/Layout/BreakNode.h +++ b/Userland/Libraries/LibWeb/Layout/BreakNode.h @@ -19,6 +19,8 @@ public: const HTML::HTMLBRElement& dom_node() const { return verify_cast(*Node::dom_node()); } private: + virtual void paint(PaintContext&, PaintPhase) override; + virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override; }; diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index ba43029c98..8284060552 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -83,20 +83,6 @@ bool Node::establishes_stacking_context() const return false; } -void Node::paint(PaintContext& context, PaintPhase phase) -{ - if (!is_visible()) - return; - - before_children_paint(context, phase); - - for_each_child_in_paint_order([&](auto& child) { - child.paint(context, phase); - }); - - after_children_paint(context, phase); -} - HitTestResult Node::hit_test(const Gfx::IntPoint& position, HitTestType type) const { HitTestResult result; diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index 0825b7d99c..3fbffce705 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -92,7 +92,7 @@ public: virtual bool handle_mousewheel(Badge, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta); virtual void before_children_paint(PaintContext&, PaintPhase) {}; - virtual void paint(PaintContext&, PaintPhase); + virtual void paint(PaintContext&, PaintPhase) = 0; virtual void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const { } virtual void after_children_paint(PaintContext&, PaintPhase) {}; diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.cpp b/Userland/Libraries/LibWeb/Layout/TextNode.cpp index 53922dced1..13f005fcb4 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/TextNode.cpp @@ -414,4 +414,8 @@ Optional TextNode::ChunkIterator::try_commit_chunk(Utf8View::It return {}; } +void TextNode::paint(PaintContext&, PaintPhase) +{ +} + } diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.h b/Userland/Libraries/LibWeb/Layout/TextNode.h index 86bdb554b7..fe561fba58 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.h +++ b/Userland/Libraries/LibWeb/Layout/TextNode.h @@ -63,6 +63,7 @@ private: void split_into_lines_by_rules(InlineFormattingContext&, LayoutMode, bool do_collapse, bool do_wrap_lines, bool do_respect_linebreaks); void paint_cursor_if_needed(PaintContext&, const LineBoxFragment&) const; void paint_text_decoration(Gfx::Painter&, LineBoxFragment const&) const; + virtual void paint(PaintContext&, PaintPhase) override; String m_text_for_rendering; };