diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index e8b60157a1..f066b6f74a 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -264,6 +264,7 @@ class PerformanceTiming; } namespace Web::Painting { +enum class PaintPhase; class Box; } @@ -299,7 +300,6 @@ class WebSocket; namespace Web::Layout { enum class LayoutMode; -enum class PaintPhase; class BlockContainer; class BlockFormattingContext; class Box; diff --git a/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp b/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp index 517dac4606..414b82c1b5 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp @@ -34,7 +34,7 @@ bool BlockContainer::should_clip_overflow() const return computed_values().overflow_x() != CSS::Overflow::Visible && computed_values().overflow_y() != CSS::Overflow::Visible; } -void BlockContainer::paint(PaintContext& context, PaintPhase phase) +void BlockContainer::paint(PaintContext& context, Painting::PaintPhase phase) { if (!is_visible()) return; @@ -64,7 +64,7 @@ void BlockContainer::paint(PaintContext& context, PaintPhase phase) } // FIXME: Merge this loop with the above somehow.. - if (phase == PaintPhase::FocusOutline) { + if (phase == Painting::PaintPhase::FocusOutline) { for (auto& line_box : m_paint_box->m_line_boxes) { for (auto& fragment : line_box.fragments()) { auto* node = fragment.layout_node().dom_node(); diff --git a/Userland/Libraries/LibWeb/Layout/BlockContainer.h b/Userland/Libraries/LibWeb/Layout/BlockContainer.h index 2eda20df56..3cd353a9af 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockContainer.h +++ b/Userland/Libraries/LibWeb/Layout/BlockContainer.h @@ -18,7 +18,7 @@ public: BlockContainer(DOM::Document&, DOM::Node*, CSS::ComputedValues); virtual ~BlockContainer() override; - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override; diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index 34d0fb4602..0ef918b209 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -34,21 +34,21 @@ Box::~Box() { } -void Box::paint(PaintContext& context, PaintPhase phase) +void Box::paint(PaintContext& context, Painting::PaintPhase phase) { if (!is_visible()) return; - if (phase == PaintPhase::Background) { + if (phase == Painting::PaintPhase::Background) { paint_background(context); paint_box_shadow(context); } - if (phase == PaintPhase::Border) { + if (phase == Painting::PaintPhase::Border) { paint_border(context); } - if (phase == PaintPhase::Overlay && dom_node() && document().inspected_node() == dom_node()) { + if (phase == Painting::PaintPhase::Overlay && dom_node() && document().inspected_node() == dom_node()) { auto content_rect = m_paint_box->absolute_rect(); auto margin_box = box_model().margin_box(); @@ -88,7 +88,7 @@ void Box::paint(PaintContext& context, PaintPhase phase) context.painter().draw_text(enclosing_int_rect(size_text_rect), size_text, Gfx::TextAlignment::Center, context.palette().color(Gfx::ColorRole::TooltipText)); } - if (phase == PaintPhase::FocusOutline && dom_node() && dom_node()->is_element() && verify_cast(*dom_node()).is_focused()) { + if (phase == Painting::PaintPhase::FocusOutline && dom_node() && dom_node()->is_element() && verify_cast(*dom_node()).is_focused()) { context.painter().draw_rect(enclosing_int_rect(m_paint_box->absolute_rect()), context.palette().focus_outline()); } } @@ -217,7 +217,7 @@ bool Box::is_body() const return dom_node() && dom_node() == document().body(); } -StackingContext* Box::enclosing_stacking_context() +Painting::StackingContext* Box::enclosing_stacking_context() { for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) { if (!is(ancestor)) @@ -232,7 +232,7 @@ StackingContext* Box::enclosing_stacking_context() VERIFY_NOT_REACHED(); } -void Box::before_children_paint(PaintContext& context, PaintPhase phase) +void Box::before_children_paint(PaintContext& context, Painting::PaintPhase phase) { NodeWithStyleAndBoxModelMetrics::before_children_paint(context, phase); // FIXME: Support more overflow variations. @@ -242,7 +242,7 @@ void Box::before_children_paint(PaintContext& context, PaintPhase phase) } } -void Box::after_children_paint(PaintContext& context, PaintPhase phase) +void Box::after_children_paint(PaintContext& context, Painting::PaintPhase phase) { NodeWithStyleAndBoxModelMetrics::after_children_paint(context, phase); // FIXME: Support more overflow variations. diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index 3c6e11a900..b3ede364c7 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -30,12 +30,12 @@ public: bool is_body() const; - StackingContext* stacking_context() { return m_stacking_context; } - const StackingContext* stacking_context() const { return m_stacking_context; } - void set_stacking_context(NonnullOwnPtr context) { m_stacking_context = move(context); } - StackingContext* enclosing_stacking_context(); + Painting::StackingContext* stacking_context() { return m_stacking_context; } + Painting::StackingContext const* stacking_context() const { return m_stacking_context; } + void set_stacking_context(NonnullOwnPtr context) { m_stacking_context = move(context); } + Painting::StackingContext* enclosing_stacking_context(); - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; virtual void paint_border(PaintContext& context); virtual void paint_box_shadow(PaintContext& context); virtual void paint_background(PaintContext& context); @@ -50,8 +50,8 @@ public: bool has_intrinsic_height() const { return intrinsic_height().has_value(); } bool has_intrinsic_aspect_ratio() const { return intrinsic_aspect_ratio().has_value(); } - virtual void before_children_paint(PaintContext&, PaintPhase) override; - virtual void after_children_paint(PaintContext&, PaintPhase) override; + virtual void before_children_paint(PaintContext&, Painting::PaintPhase) override; + virtual void after_children_paint(PaintContext&, Painting::PaintPhase) override; virtual ~Box() override; @@ -64,7 +64,7 @@ protected: private: virtual bool is_box() const final { return true; } - OwnPtr m_stacking_context; + OwnPtr m_stacking_context; }; template<> diff --git a/Userland/Libraries/LibWeb/Layout/BreakNode.cpp b/Userland/Libraries/LibWeb/Layout/BreakNode.cpp index ca4081ad54..3097e2df80 100644 --- a/Userland/Libraries/LibWeb/Layout/BreakNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/BreakNode.cpp @@ -20,7 +20,7 @@ BreakNode::~BreakNode() { } -void BreakNode::paint(PaintContext&, PaintPhase) +void BreakNode::paint(PaintContext&, Painting::PaintPhase) { } diff --git a/Userland/Libraries/LibWeb/Layout/BreakNode.h b/Userland/Libraries/LibWeb/Layout/BreakNode.h index 5ab8c869a9..31672f3041 100644 --- a/Userland/Libraries/LibWeb/Layout/BreakNode.h +++ b/Userland/Libraries/LibWeb/Layout/BreakNode.h @@ -20,7 +20,7 @@ public: private: virtual bool is_break_node() const final { return true; } - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; }; template<> diff --git a/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp b/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp index ba2bbd3544..ec59cfa77f 100644 --- a/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/ButtonBox.cpp @@ -31,14 +31,14 @@ void ButtonBox::prepare_for_replaced_layout() set_intrinsic_height(font().glyph_height()); } -void ButtonBox::paint(PaintContext& context, PaintPhase phase) +void ButtonBox::paint(PaintContext& context, Painting::PaintPhase phase) { if (!is_visible()) return; LabelableNode::paint(context, phase); - if (phase == PaintPhase::Foreground) { + if (phase == Painting::PaintPhase::Foreground) { auto text_rect = enclosing_int_rect(m_paint_box->absolute_rect()); if (m_being_pressed) text_rect.translate_by(1, 1); diff --git a/Userland/Libraries/LibWeb/Layout/ButtonBox.h b/Userland/Libraries/LibWeb/Layout/ButtonBox.h index 04c999e84e..29a73778d1 100644 --- a/Userland/Libraries/LibWeb/Layout/ButtonBox.h +++ b/Userland/Libraries/LibWeb/Layout/ButtonBox.h @@ -17,7 +17,7 @@ public: virtual ~ButtonBox() override; virtual void prepare_for_replaced_layout() override; - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; const HTML::HTMLInputElement& dom_node() const { return static_cast(LabelableNode::dom_node()); } HTML::HTMLInputElement& dom_node() { return static_cast(LabelableNode::dom_node()); } diff --git a/Userland/Libraries/LibWeb/Layout/CanvasBox.cpp b/Userland/Libraries/LibWeb/Layout/CanvasBox.cpp index c79fde12b7..df0364e063 100644 --- a/Userland/Libraries/LibWeb/Layout/CanvasBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/CanvasBox.cpp @@ -25,14 +25,14 @@ void CanvasBox::prepare_for_replaced_layout() set_intrinsic_height(dom_node().height()); } -void CanvasBox::paint(PaintContext& context, PaintPhase phase) +void CanvasBox::paint(PaintContext& context, Painting::PaintPhase phase) { if (!is_visible()) return; ReplacedBox::paint(context, phase); - if (phase == PaintPhase::Foreground) { + if (phase == Painting::PaintPhase::Foreground) { // FIXME: This should be done at a different level. Also rect() does not include padding etc! if (!context.viewport_rect().intersects(enclosing_int_rect(m_paint_box->absolute_rect()))) return; diff --git a/Userland/Libraries/LibWeb/Layout/CanvasBox.h b/Userland/Libraries/LibWeb/Layout/CanvasBox.h index 9f41fe2110..3e1d9a5ab5 100644 --- a/Userland/Libraries/LibWeb/Layout/CanvasBox.h +++ b/Userland/Libraries/LibWeb/Layout/CanvasBox.h @@ -17,7 +17,7 @@ public: virtual ~CanvasBox() override; virtual void prepare_for_replaced_layout() override; - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; const HTML::HTMLCanvasElement& dom_node() const { return static_cast(ReplacedBox::dom_node()); } }; diff --git a/Userland/Libraries/LibWeb/Layout/CheckBox.cpp b/Userland/Libraries/LibWeb/Layout/CheckBox.cpp index 517c37fa7b..bd33cbc357 100644 --- a/Userland/Libraries/LibWeb/Layout/CheckBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/CheckBox.cpp @@ -27,14 +27,14 @@ CheckBox::~CheckBox() { } -void CheckBox::paint(PaintContext& context, PaintPhase phase) +void CheckBox::paint(PaintContext& context, Painting::PaintPhase phase) { if (!is_visible()) return; LabelableNode::paint(context, phase); - if (phase == PaintPhase::Foreground) { + if (phase == Painting::PaintPhase::Foreground) { Gfx::StylePainter::paint_check_box(context.painter(), enclosing_int_rect(m_paint_box->absolute_rect()), context.palette(), dom_node().enabled(), dom_node().checked(), m_being_pressed); } } diff --git a/Userland/Libraries/LibWeb/Layout/CheckBox.h b/Userland/Libraries/LibWeb/Layout/CheckBox.h index 48f5cbe415..927398ae82 100644 --- a/Userland/Libraries/LibWeb/Layout/CheckBox.h +++ b/Userland/Libraries/LibWeb/Layout/CheckBox.h @@ -16,7 +16,7 @@ public: CheckBox(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr); virtual ~CheckBox() override; - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; const HTML::HTMLInputElement& dom_node() const { return static_cast(LabelableNode::dom_node()); } HTML::HTMLInputElement& dom_node() { return static_cast(LabelableNode::dom_node()); } diff --git a/Userland/Libraries/LibWeb/Layout/FrameBox.cpp b/Userland/Libraries/LibWeb/Layout/FrameBox.cpp index ee5c3569f3..21809bc6c8 100644 --- a/Userland/Libraries/LibWeb/Layout/FrameBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/FrameBox.cpp @@ -32,11 +32,11 @@ void FrameBox::prepare_for_replaced_layout() set_intrinsic_height(dom_node().attribute(HTML::AttributeNames::height).to_int().value_or(150)); } -void FrameBox::paint(PaintContext& context, PaintPhase phase) +void FrameBox::paint(PaintContext& context, Painting::PaintPhase phase) { ReplacedBox::paint(context, phase); - if (phase == PaintPhase::Foreground) { + if (phase == Painting::PaintPhase::Foreground) { auto* hosted_document = dom_node().content_document_without_origin_check(); if (!hosted_document) return; diff --git a/Userland/Libraries/LibWeb/Layout/FrameBox.h b/Userland/Libraries/LibWeb/Layout/FrameBox.h index d055bd07a1..43b08d55d1 100644 --- a/Userland/Libraries/LibWeb/Layout/FrameBox.h +++ b/Userland/Libraries/LibWeb/Layout/FrameBox.h @@ -16,7 +16,7 @@ public: FrameBox(DOM::Document&, DOM::Element&, NonnullRefPtr); virtual ~FrameBox() override; - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; virtual void prepare_for_replaced_layout() override; const HTML::HTMLIFrameElement& dom_node() const { return verify_cast(ReplacedBox::dom_node()); } diff --git a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp index d682cc7c3a..e568355f80 100644 --- a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp @@ -72,7 +72,7 @@ void ImageBox::prepare_for_replaced_layout() } } -void ImageBox::paint(PaintContext& context, PaintPhase phase) +void ImageBox::paint(PaintContext& context, Painting::PaintPhase phase) { if (!is_visible()) return; @@ -83,7 +83,7 @@ void ImageBox::paint(PaintContext& context, PaintPhase phase) ReplacedBox::paint(context, phase); - if (phase == PaintPhase::Foreground) { + if (phase == Painting::PaintPhase::Foreground) { if (renders_as_alt_text()) { auto& image_element = verify_cast(dom_node()); context.painter().set_font(Gfx::FontDatabase::default_font()); diff --git a/Userland/Libraries/LibWeb/Layout/ImageBox.h b/Userland/Libraries/LibWeb/Layout/ImageBox.h index 733c839de0..1bc4591c9a 100644 --- a/Userland/Libraries/LibWeb/Layout/ImageBox.h +++ b/Userland/Libraries/LibWeb/Layout/ImageBox.h @@ -20,7 +20,7 @@ public: virtual ~ImageBox() override; virtual void prepare_for_replaced_layout() override; - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; const DOM::Element& dom_node() const { return static_cast(ReplacedBox::dom_node()); } diff --git a/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp b/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp index f58258532c..c11f7055aa 100644 --- a/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp +++ b/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp @@ -24,7 +24,7 @@ InitialContainingBlock::~InitialContainingBlock() void InitialContainingBlock::build_stacking_context_tree() { - set_stacking_context(make(*this, nullptr)); + set_stacking_context(make(*this, nullptr)); for_each_in_inclusive_subtree_of_type([&](Box& box) { if (&box == this) @@ -35,7 +35,7 @@ void InitialContainingBlock::build_stacking_context_tree() } auto* parent_context = box.enclosing_stacking_context(); VERIFY(parent_context); - box.set_stacking_context(make(box, parent_context)); + box.set_stacking_context(make(box, parent_context)); return IterationDecision::Continue; }); } diff --git a/Userland/Libraries/LibWeb/Layout/InlineNode.cpp b/Userland/Libraries/LibWeb/Layout/InlineNode.cpp index 16ddd6206a..6771458651 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineNode.cpp @@ -27,11 +27,11 @@ InlineNode::~InlineNode() { } -void InlineNode::paint(PaintContext& context, PaintPhase phase) +void InlineNode::paint(PaintContext& context, Painting::PaintPhase phase) { auto& painter = context.painter(); - if (phase == PaintPhase::Background) { + if (phase == Painting::PaintPhase::Background) { auto top_left_border_radius = computed_values().border_top_left_radius(); auto top_right_border_radius = computed_values().border_top_right_radius(); auto bottom_right_border_radius = computed_values().border_bottom_right_radius(); @@ -74,7 +74,7 @@ void InlineNode::paint(PaintContext& context, PaintPhase phase) }); } - if (phase == PaintPhase::Border) { + if (phase == Painting::PaintPhase::Border) { auto top_left_border_radius = computed_values().border_top_left_radius(); auto top_right_border_radius = computed_values().border_top_right_radius(); auto bottom_right_border_radius = computed_values().border_bottom_right_radius(); @@ -114,7 +114,7 @@ void InlineNode::paint(PaintContext& context, PaintPhase phase) // FIXME: We check for a non-null dom_node(), since pseudo-elements have a null one and were getting // highlighted incorrectly. A better solution will be needed if we want to inspect them too. - if (phase == PaintPhase::Overlay && dom_node() && document().inspected_node() == dom_node()) { + if (phase == Painting::PaintPhase::Overlay && dom_node() && document().inspected_node() == dom_node()) { // FIXME: This paints a double-thick border between adjacent fragments, where ideally there // would be none. Once we implement non-rectangular outlines for the `outline` CSS // property, we can use that here instead. diff --git a/Userland/Libraries/LibWeb/Layout/InlineNode.h b/Userland/Libraries/LibWeb/Layout/InlineNode.h index 330f7caff0..898e8c3a5c 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineNode.h +++ b/Userland/Libraries/LibWeb/Layout/InlineNode.h @@ -15,7 +15,7 @@ public: InlineNode(DOM::Document&, DOM::Element*, NonnullRefPtr); virtual ~InlineNode() override; - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; private: template diff --git a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp index 87b485f9f4..cb66bc7dc3 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp @@ -15,7 +15,7 @@ namespace Web::Layout { -void LineBoxFragment::paint(PaintContext& context, PaintPhase phase) +void LineBoxFragment::paint(PaintContext& context, Painting::PaintPhase phase) { for (auto* ancestor = layout_node().parent(); ancestor; ancestor = ancestor->parent()) { if (!ancestor->is_visible()) diff --git a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.h b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.h index bb9977c332..69dd4d726f 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.h +++ b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.h @@ -55,7 +55,7 @@ public: float absolute_x() const { return absolute_rect().x(); } - void paint(PaintContext&, PaintPhase); + void paint(PaintContext&, Painting::PaintPhase); bool ends_in_whitespace() const; bool is_justifiable_whitespace() const; diff --git a/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp b/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp index 06f67ec0ca..5c7970c630 100644 --- a/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp @@ -55,9 +55,9 @@ ListItemMarkerBox::~ListItemMarkerBox() { } -void ListItemMarkerBox::paint(PaintContext& context, PaintPhase phase) +void ListItemMarkerBox::paint(PaintContext& context, Painting::PaintPhase phase) { - if (phase != PaintPhase::Foreground) + if (phase != Painting::PaintPhase::Foreground) return; auto enclosing = enclosing_int_rect(m_paint_box->absolute_rect()); diff --git a/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.h b/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.h index 0e2b3d4a2b..2ba5892802 100644 --- a/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.h +++ b/Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.h @@ -16,7 +16,7 @@ public: explicit ListItemMarkerBox(DOM::Document&, CSS::ListStyleType, size_t index, NonnullRefPtr); virtual ~ListItemMarkerBox() override; - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; Gfx::Bitmap const* list_style_image_bitmap() const; String const& text() const { return m_text; } diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index 9d88ebc79c..06e8d69d91 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -26,14 +26,6 @@ enum class LayoutMode { OnlyRequiredLineBreaks, }; -enum class PaintPhase { - Background, - Border, - Foreground, - FocusOutline, - Overlay, -}; - struct HitTestResult { RefPtr layout_node; int index_in_node { 0 }; @@ -92,10 +84,10 @@ public: virtual void handle_mousemove(Badge, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers); virtual bool handle_mousewheel(Badge, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y); - virtual void before_children_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) {}; + virtual void before_children_paint(PaintContext&, Painting::PaintPhase) {}; + virtual void paint(PaintContext&, Painting::PaintPhase) = 0; + virtual void paint_fragment(PaintContext&, const LineBoxFragment&, Painting::PaintPhase) const { } + virtual void after_children_paint(PaintContext&, Painting::PaintPhase) {}; // These are used to optimize hot is variants for some classes where dynamic_cast is too slow. virtual bool is_box() const { return false; } diff --git a/Userland/Libraries/LibWeb/Layout/Progress.cpp b/Userland/Libraries/LibWeb/Layout/Progress.cpp index 873dd51961..1a54d3bb5f 100644 --- a/Userland/Libraries/LibWeb/Layout/Progress.cpp +++ b/Userland/Libraries/LibWeb/Layout/Progress.cpp @@ -21,12 +21,12 @@ Progress::~Progress() { } -void Progress::paint(PaintContext& context, PaintPhase phase) +void Progress::paint(PaintContext& context, Painting::PaintPhase phase) { if (!is_visible()) return; - if (phase == PaintPhase::Foreground) { + if (phase == Painting::PaintPhase::Foreground) { // FIXME: This does not support floating point value() and max() Gfx::StylePainter::paint_progressbar(context.painter(), enclosing_int_rect(m_paint_box->absolute_rect()), context.palette(), 0, dom_node().max(), dom_node().value(), ""); } diff --git a/Userland/Libraries/LibWeb/Layout/Progress.h b/Userland/Libraries/LibWeb/Layout/Progress.h index a7dc36495e..48398f49df 100644 --- a/Userland/Libraries/LibWeb/Layout/Progress.h +++ b/Userland/Libraries/LibWeb/Layout/Progress.h @@ -16,7 +16,7 @@ public: Progress(DOM::Document&, HTML::HTMLProgressElement&, NonnullRefPtr); virtual ~Progress() override; - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; const HTML::HTMLProgressElement& dom_node() const { return static_cast(LabelableNode::dom_node()); } HTML::HTMLProgressElement& dom_node() { return static_cast(LabelableNode::dom_node()); } diff --git a/Userland/Libraries/LibWeb/Layout/RadioButton.cpp b/Userland/Libraries/LibWeb/Layout/RadioButton.cpp index d41775cc27..f70e7ff806 100644 --- a/Userland/Libraries/LibWeb/Layout/RadioButton.cpp +++ b/Userland/Libraries/LibWeb/Layout/RadioButton.cpp @@ -26,14 +26,14 @@ RadioButton::~RadioButton() { } -void RadioButton::paint(PaintContext& context, PaintPhase phase) +void RadioButton::paint(PaintContext& context, Painting::PaintPhase phase) { if (!is_visible()) return; LabelableNode::paint(context, phase); - if (phase == PaintPhase::Foreground) { + if (phase == Painting::PaintPhase::Foreground) { Gfx::StylePainter::paint_radio_button(context.painter(), enclosing_int_rect(m_paint_box->absolute_rect()), context.palette(), dom_node().checked(), m_being_pressed); } } diff --git a/Userland/Libraries/LibWeb/Layout/RadioButton.h b/Userland/Libraries/LibWeb/Layout/RadioButton.h index 24f8c4e30e..7d8fce50a8 100644 --- a/Userland/Libraries/LibWeb/Layout/RadioButton.h +++ b/Userland/Libraries/LibWeb/Layout/RadioButton.h @@ -16,7 +16,7 @@ public: RadioButton(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr); virtual ~RadioButton() override; - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; const HTML::HTMLInputElement& dom_node() const { return static_cast(LabelableNode::dom_node()); } HTML::HTMLInputElement& dom_node() { return static_cast(LabelableNode::dom_node()); } diff --git a/Userland/Libraries/LibWeb/Layout/SVGBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGBox.cpp index 6e9b70f714..9c0c7a8299 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGBox.cpp @@ -6,6 +6,7 @@ #include #include +#include namespace Web::Layout { @@ -14,18 +15,18 @@ SVGBox::SVGBox(DOM::Document& document, SVG::SVGElement& element, NonnullRefPtr< { } -void SVGBox::before_children_paint(PaintContext& context, PaintPhase phase) +void SVGBox::before_children_paint(PaintContext& context, Painting::PaintPhase phase) { Node::before_children_paint(context, phase); - if (phase != PaintPhase::Foreground) + if (phase != Painting::PaintPhase::Foreground) return; context.svg_context().save(); } -void SVGBox::after_children_paint(PaintContext& context, PaintPhase phase) +void SVGBox::after_children_paint(PaintContext& context, Painting::PaintPhase phase) { Node::after_children_paint(context, phase); - if (phase != PaintPhase::Foreground) + if (phase != Painting::PaintPhase::Foreground) return; context.svg_context().restore(); } diff --git a/Userland/Libraries/LibWeb/Layout/SVGBox.h b/Userland/Libraries/LibWeb/Layout/SVGBox.h index ee0aaea8e3..998be6dd4a 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGBox.h +++ b/Userland/Libraries/LibWeb/Layout/SVGBox.h @@ -20,8 +20,8 @@ public: SVG::SVGElement& dom_node() { return verify_cast(*Box::dom_node()); } SVG::SVGElement const& dom_node() const { return verify_cast(*Box::dom_node()); } - virtual void before_children_paint(PaintContext& context, PaintPhase phase) override; - virtual void after_children_paint(PaintContext& context, PaintPhase phase) override; + virtual void before_children_paint(PaintContext& context, Painting::PaintPhase phase) override; + virtual void after_children_paint(PaintContext& context, Painting::PaintPhase phase) override; private: virtual bool is_svg_box() const final { return true; } diff --git a/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp index f5e2f28593..549cdfdd3f 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp @@ -19,14 +19,14 @@ SVGGeometryBox::SVGGeometryBox(DOM::Document& document, SVG::SVGGeometryElement& { } -void SVGGeometryBox::paint(PaintContext& context, PaintPhase phase) +void SVGGeometryBox::paint(PaintContext& context, Painting::PaintPhase phase) { if (!is_visible()) return; SVGGraphicsBox::paint(context, phase); - if (phase != PaintPhase::Foreground) + if (phase != Painting::PaintPhase::Foreground) return; auto& geometry_element = dom_node(); diff --git a/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.h b/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.h index e53ee44df5..234b8ccb27 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.h +++ b/Userland/Libraries/LibWeb/Layout/SVGGeometryBox.h @@ -19,7 +19,7 @@ public: SVG::SVGGeometryElement& dom_node() { return verify_cast(SVGGraphicsBox::dom_node()); } SVG::SVGGeometryElement const& dom_node() const { return verify_cast(SVGGraphicsBox::dom_node()); } - virtual void paint(PaintContext& context, PaintPhase phase) override; + virtual void paint(PaintContext& context, Painting::PaintPhase phase) override; float viewbox_scaling() const; Gfx::FloatPoint viewbox_origin() const; diff --git a/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp index 3126330793..ae0f4b421b 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp @@ -5,6 +5,7 @@ */ #include +#include namespace Web::Layout { @@ -13,10 +14,10 @@ SVGGraphicsBox::SVGGraphicsBox(DOM::Document& document, SVG::SVGGraphicsElement& { } -void SVGGraphicsBox::before_children_paint(PaintContext& context, PaintPhase phase) +void SVGGraphicsBox::before_children_paint(PaintContext& context, Painting::PaintPhase phase) { SVGBox::before_children_paint(context, phase); - if (phase != PaintPhase::Foreground) + if (phase != Painting::PaintPhase::Foreground) return; auto& graphics_element = verify_cast(dom_node()); diff --git a/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.h b/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.h index 2605cb93cd..928a85d20f 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.h +++ b/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.h @@ -20,7 +20,7 @@ public: SVG::SVGGraphicsElement& dom_node() { return verify_cast(SVGBox::dom_node()); } SVG::SVGGraphicsElement const& dom_node() const { return verify_cast(SVGBox::dom_node()); } - virtual void before_children_paint(PaintContext& context, PaintPhase phase) override; + virtual void before_children_paint(PaintContext& context, Painting::PaintPhase phase) override; }; } diff --git a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp index 6a6b3f8561..39077e3430 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp @@ -14,9 +14,9 @@ SVGSVGBox::SVGSVGBox(DOM::Document& document, SVG::SVGSVGElement& element, Nonnu { } -void SVGSVGBox::before_children_paint(PaintContext& context, PaintPhase phase) +void SVGSVGBox::before_children_paint(PaintContext& context, Painting::PaintPhase phase) { - if (phase != PaintPhase::Foreground) + if (phase != Painting::PaintPhase::Foreground) return; if (!context.has_svg_context()) @@ -25,10 +25,10 @@ void SVGSVGBox::before_children_paint(PaintContext& context, PaintPhase phase) SVGGraphicsBox::before_children_paint(context, phase); } -void SVGSVGBox::after_children_paint(PaintContext& context, PaintPhase phase) +void SVGSVGBox::after_children_paint(PaintContext& context, Painting::PaintPhase phase) { SVGGraphicsBox::after_children_paint(context, phase); - if (phase != PaintPhase::Foreground) + if (phase != Painting::PaintPhase::Foreground) return; context.clear_svg_context(); } diff --git a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.h b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.h index 5a1cf124d1..b02e595186 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.h +++ b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.h @@ -18,8 +18,8 @@ public: SVG::SVGSVGElement& dom_node() { return verify_cast(SVGGraphicsBox::dom_node()); } - virtual void before_children_paint(PaintContext& context, PaintPhase phase) override; - virtual void after_children_paint(PaintContext& context, PaintPhase phase) override; + virtual void before_children_paint(PaintContext& context, Painting::PaintPhase phase) override; + virtual void after_children_paint(PaintContext& context, Painting::PaintPhase phase) override; virtual bool can_have_children() const override { return true; } }; diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.cpp b/Userland/Libraries/LibWeb/Layout/TextNode.cpp index a86ecf2533..90772aa773 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/TextNode.cpp @@ -113,11 +113,11 @@ void TextNode::paint_text_decoration(Gfx::Painter& painter, LineBoxFragment cons } } -void TextNode::paint_fragment(PaintContext& context, const LineBoxFragment& fragment, PaintPhase phase) const +void TextNode::paint_fragment(PaintContext& context, const LineBoxFragment& fragment, Painting::PaintPhase phase) const { auto& painter = context.painter(); - if (phase == PaintPhase::Foreground) { + if (phase == Painting::PaintPhase::Foreground) { auto fragment_absolute_rect = fragment.absolute_rect(); painter.set_font(font()); @@ -366,7 +366,7 @@ Optional TextNode::ChunkIterator::try_commit_chunk(Utf8View::It return {}; } -void TextNode::paint(PaintContext&, PaintPhase) +void TextNode::paint(PaintContext&, Painting::PaintPhase) { } diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.h b/Userland/Libraries/LibWeb/Layout/TextNode.h index fc1599402b..3cc072a184 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.h +++ b/Userland/Libraries/LibWeb/Layout/TextNode.h @@ -23,7 +23,7 @@ public: const String& text_for_rendering() const { return m_text_for_rendering; } - virtual void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const override; + virtual void paint_fragment(PaintContext&, const LineBoxFragment&, Painting::PaintPhase) const override; struct Chunk { Utf8View view; @@ -60,7 +60,7 @@ private: virtual void handle_mousemove(Badge, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override; void paint_cursor_if_needed(PaintContext&, const LineBoxFragment&) const; void paint_text_decoration(Gfx::Painter&, LineBoxFragment const&) const; - virtual void paint(PaintContext&, PaintPhase) override; + virtual void paint(PaintContext&, Painting::PaintPhase) override; String m_text_for_rendering; }; diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index 20a6ca82be..9b4ef3b83f 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -13,9 +13,9 @@ #include #include -namespace Web::Layout { +namespace Web::Painting { -StackingContext::StackingContext(Box& box, StackingContext* parent) +StackingContext::StackingContext(Layout::Box& box, StackingContext* parent) : m_box(box) , m_parent(parent) { @@ -34,7 +34,7 @@ StackingContext::StackingContext(Box& box, StackingContext* parent) } } -void StackingContext::paint_descendants(PaintContext& context, Node& box, StackingContextPaintPhase phase) +void StackingContext::paint_descendants(PaintContext& context, Layout::Node& box, StackingContextPaintPhase phase) { if (phase == StackingContextPaintPhase::Foreground) box.before_children_paint(context, PaintPhase::Foreground); @@ -42,7 +42,7 @@ void StackingContext::paint_descendants(PaintContext& context, Node& box, Stacki box.for_each_child([&](auto& child) { if (child.establishes_stacking_context()) return; - bool child_is_inline_or_replaced = child.is_inline() || is(child); + bool child_is_inline_or_replaced = child.is_inline() || is(child); switch (phase) { case StackingContextPaintPhase::BackgroundAndBorders: if (!child_is_inline_or_replaced && !child.is_floating() && !child.is_positioned()) { @@ -147,7 +147,7 @@ void StackingContext::paint(PaintContext& context) } } -HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestType type) const +Layout::HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, Layout::HitTestType type) const { // NOTE: Hit testing basically happens in reverse painting order. // https://www.w3.org/TR/CSS22/visuren.html#z-index @@ -162,7 +162,7 @@ HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestTy return result; } - HitTestResult result; + Layout::HitTestResult result; // 6. the child stacking contexts with stack level 0 and the positioned descendants with stack level 0. m_box.for_each_in_subtree_of_type([&](Layout::Box const& box) { if (box.is_positioned() && !box.stacking_context()) { @@ -176,7 +176,7 @@ HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestTy return result; // 5. the in-flow, inline-level, non-positioned descendants, including inline tables and inline blocks. - if (m_box.children_are_inline() && is(m_box)) { + if (m_box.children_are_inline() && is(m_box)) { auto result = m_box.hit_test(position, type); if (result.layout_node) return result; @@ -218,7 +218,7 @@ HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestTy // 1. the background and borders of the element forming the stacking context. if (m_box.m_paint_box->absolute_border_box_rect().contains(position.to_type())) { - return HitTestResult { + return Layout::HitTestResult { .layout_node = m_box, }; } diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.h b/Userland/Libraries/LibWeb/Painting/StackingContext.h index 980b0a13e1..089d6c4fc1 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.h +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.h @@ -9,11 +9,19 @@ #include #include -namespace Web::Layout { +namespace Web::Painting { + +enum class PaintPhase { + Background, + Border, + Foreground, + FocusOutline, + Overlay, +}; class StackingContext { public: - StackingContext(Box&, StackingContext* parent); + StackingContext(Layout::Box&, StackingContext* parent); StackingContext* parent() { return m_parent; } const StackingContext* parent() const { return m_parent; } @@ -26,14 +34,14 @@ public: FocusAndOverlay, }; - void paint_descendants(PaintContext&, Node&, StackingContextPaintPhase); + void paint_descendants(PaintContext&, Layout::Node&, StackingContextPaintPhase); void paint(PaintContext&); - HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const; + Layout::HitTestResult hit_test(Gfx::IntPoint const&, Layout::HitTestType) const; void dump(int indent = 0) const; private: - Box& m_box; + Layout::Box& m_box; StackingContext* const m_parent { nullptr }; Vector m_children;