Ver código fonte

LibWeb: Move StackingContext and PaintPhase into the Painting namespace

Andreas Kling 3 anos atrás
pai
commit
f0d833a3d7
41 arquivos alterados com 105 adições e 103 exclusões
  1. 1 1
      Userland/Libraries/LibWeb/Forward.h
  2. 2 2
      Userland/Libraries/LibWeb/Layout/BlockContainer.cpp
  3. 1 1
      Userland/Libraries/LibWeb/Layout/BlockContainer.h
  4. 8 8
      Userland/Libraries/LibWeb/Layout/Box.cpp
  5. 8 8
      Userland/Libraries/LibWeb/Layout/Box.h
  6. 1 1
      Userland/Libraries/LibWeb/Layout/BreakNode.cpp
  7. 1 1
      Userland/Libraries/LibWeb/Layout/BreakNode.h
  8. 2 2
      Userland/Libraries/LibWeb/Layout/ButtonBox.cpp
  9. 1 1
      Userland/Libraries/LibWeb/Layout/ButtonBox.h
  10. 2 2
      Userland/Libraries/LibWeb/Layout/CanvasBox.cpp
  11. 1 1
      Userland/Libraries/LibWeb/Layout/CanvasBox.h
  12. 2 2
      Userland/Libraries/LibWeb/Layout/CheckBox.cpp
  13. 1 1
      Userland/Libraries/LibWeb/Layout/CheckBox.h
  14. 2 2
      Userland/Libraries/LibWeb/Layout/FrameBox.cpp
  15. 1 1
      Userland/Libraries/LibWeb/Layout/FrameBox.h
  16. 2 2
      Userland/Libraries/LibWeb/Layout/ImageBox.cpp
  17. 1 1
      Userland/Libraries/LibWeb/Layout/ImageBox.h
  18. 2 2
      Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp
  19. 4 4
      Userland/Libraries/LibWeb/Layout/InlineNode.cpp
  20. 1 1
      Userland/Libraries/LibWeb/Layout/InlineNode.h
  21. 1 1
      Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp
  22. 1 1
      Userland/Libraries/LibWeb/Layout/LineBoxFragment.h
  23. 2 2
      Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp
  24. 1 1
      Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.h
  25. 4 12
      Userland/Libraries/LibWeb/Layout/Node.h
  26. 2 2
      Userland/Libraries/LibWeb/Layout/Progress.cpp
  27. 1 1
      Userland/Libraries/LibWeb/Layout/Progress.h
  28. 2 2
      Userland/Libraries/LibWeb/Layout/RadioButton.cpp
  29. 1 1
      Userland/Libraries/LibWeb/Layout/RadioButton.h
  30. 5 4
      Userland/Libraries/LibWeb/Layout/SVGBox.cpp
  31. 2 2
      Userland/Libraries/LibWeb/Layout/SVGBox.h
  32. 2 2
      Userland/Libraries/LibWeb/Layout/SVGGeometryBox.cpp
  33. 1 1
      Userland/Libraries/LibWeb/Layout/SVGGeometryBox.h
  34. 3 2
      Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp
  35. 1 1
      Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.h
  36. 4 4
      Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp
  37. 2 2
      Userland/Libraries/LibWeb/Layout/SVGSVGBox.h
  38. 3 3
      Userland/Libraries/LibWeb/Layout/TextNode.cpp
  39. 2 2
      Userland/Libraries/LibWeb/Layout/TextNode.h
  40. 8 8
      Userland/Libraries/LibWeb/Painting/StackingContext.cpp
  41. 13 5
      Userland/Libraries/LibWeb/Painting/StackingContext.h

+ 1 - 1
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;

+ 2 - 2
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();

+ 1 - 1
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;
 

+ 8 - 8
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::Element>(*dom_node()).is_focused()) {
+    if (phase == Painting::PaintPhase::FocusOutline && dom_node() && dom_node()->is_element() && verify_cast<DOM::Element>(*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<Box>(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.

+ 8 - 8
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<StackingContext> 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<Painting::StackingContext> 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<StackingContext> m_stacking_context;
+    OwnPtr<Painting::StackingContext> m_stacking_context;
 };
 
 template<>

+ 1 - 1
Userland/Libraries/LibWeb/Layout/BreakNode.cpp

@@ -20,7 +20,7 @@ BreakNode::~BreakNode()
 {
 }
 
-void BreakNode::paint(PaintContext&, PaintPhase)
+void BreakNode::paint(PaintContext&, Painting::PaintPhase)
 {
 }
 

+ 1 - 1
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<>

+ 2 - 2
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);

+ 1 - 1
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<const HTML::HTMLInputElement&>(LabelableNode::dom_node()); }
     HTML::HTMLInputElement& dom_node() { return static_cast<HTML::HTMLInputElement&>(LabelableNode::dom_node()); }

+ 2 - 2
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;

+ 1 - 1
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<const HTML::HTMLCanvasElement&>(ReplacedBox::dom_node()); }
 };

+ 2 - 2
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);
     }
 }

+ 1 - 1
Userland/Libraries/LibWeb/Layout/CheckBox.h

@@ -16,7 +16,7 @@ public:
     CheckBox(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr<CSS::StyleProperties>);
     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<const HTML::HTMLInputElement&>(LabelableNode::dom_node()); }
     HTML::HTMLInputElement& dom_node() { return static_cast<HTML::HTMLInputElement&>(LabelableNode::dom_node()); }

+ 2 - 2
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;

+ 1 - 1
Userland/Libraries/LibWeb/Layout/FrameBox.h

@@ -16,7 +16,7 @@ public:
     FrameBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
     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<HTML::HTMLIFrameElement>(ReplacedBox::dom_node()); }

+ 2 - 2
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<HTML::HTMLImageElement>(dom_node());
             context.painter().set_font(Gfx::FontDatabase::default_font());

+ 1 - 1
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<const DOM::Element&>(ReplacedBox::dom_node()); }
 

+ 2 - 2
Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp

@@ -24,7 +24,7 @@ InitialContainingBlock::~InitialContainingBlock()
 
 void InitialContainingBlock::build_stacking_context_tree()
 {
-    set_stacking_context(make<StackingContext>(*this, nullptr));
+    set_stacking_context(make<Painting::StackingContext>(*this, nullptr));
 
     for_each_in_inclusive_subtree_of_type<Box>([&](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<StackingContext>(box, parent_context));
+        box.set_stacking_context(make<Painting::StackingContext>(box, parent_context));
         return IterationDecision::Continue;
     });
 }

+ 4 - 4
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.

+ 1 - 1
Userland/Libraries/LibWeb/Layout/InlineNode.h

@@ -15,7 +15,7 @@ public:
     InlineNode(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
     virtual ~InlineNode() override;
 
-    virtual void paint(PaintContext&, PaintPhase) override;
+    virtual void paint(PaintContext&, Painting::PaintPhase) override;
 
 private:
     template<typename Callback>

+ 1 - 1
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())

+ 1 - 1
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;

+ 2 - 2
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());

+ 1 - 1
Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.h

@@ -16,7 +16,7 @@ public:
     explicit ListItemMarkerBox(DOM::Document&, CSS::ListStyleType, size_t index, NonnullRefPtr<CSS::StyleProperties>);
     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; }

+ 4 - 12
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<Node> layout_node;
     int index_in_node { 0 };
@@ -92,10 +84,10 @@ public:
     virtual void handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint&, unsigned buttons, unsigned modifiers);
     virtual bool handle_mousewheel(Badge<EventHandler>, 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<T> variants for some classes where dynamic_cast is too slow.
     virtual bool is_box() const { return false; }

+ 2 - 2
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(), "");
     }

+ 1 - 1
Userland/Libraries/LibWeb/Layout/Progress.h

@@ -16,7 +16,7 @@ public:
     Progress(DOM::Document&, HTML::HTMLProgressElement&, NonnullRefPtr<CSS::StyleProperties>);
     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<const HTML::HTMLProgressElement&>(LabelableNode::dom_node()); }
     HTML::HTMLProgressElement& dom_node() { return static_cast<HTML::HTMLProgressElement&>(LabelableNode::dom_node()); }

+ 2 - 2
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);
     }
 }

+ 1 - 1
Userland/Libraries/LibWeb/Layout/RadioButton.h

@@ -16,7 +16,7 @@ public:
     RadioButton(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr<CSS::StyleProperties>);
     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<const HTML::HTMLInputElement&>(LabelableNode::dom_node()); }
     HTML::HTMLInputElement& dom_node() { return static_cast<HTML::HTMLInputElement&>(LabelableNode::dom_node()); }

+ 5 - 4
Userland/Libraries/LibWeb/Layout/SVGBox.cpp

@@ -6,6 +6,7 @@
 
 #include <LibGfx/Painter.h>
 #include <LibWeb/Layout/SVGBox.h>
+#include <LibWeb/Painting/StackingContext.h>
 
 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();
 }

+ 2 - 2
Userland/Libraries/LibWeb/Layout/SVGBox.h

@@ -20,8 +20,8 @@ public:
     SVG::SVGElement& dom_node() { return verify_cast<SVG::SVGElement>(*Box::dom_node()); }
     SVG::SVGElement const& dom_node() const { return verify_cast<SVG::SVGElement>(*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; }

+ 2 - 2
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();

+ 1 - 1
Userland/Libraries/LibWeb/Layout/SVGGeometryBox.h

@@ -19,7 +19,7 @@ public:
     SVG::SVGGeometryElement& dom_node() { return verify_cast<SVG::SVGGeometryElement>(SVGGraphicsBox::dom_node()); }
     SVG::SVGGeometryElement const& dom_node() const { return verify_cast<SVG::SVGGeometryElement>(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;

+ 3 - 2
Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp

@@ -5,6 +5,7 @@
  */
 
 #include <LibWeb/Layout/SVGGraphicsBox.h>
+#include <LibWeb/Painting/StackingContext.h>
 
 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<SVG::SVGGraphicsElement>(dom_node());

+ 1 - 1
Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.h

@@ -20,7 +20,7 @@ public:
     SVG::SVGGraphicsElement& dom_node() { return verify_cast<SVG::SVGGraphicsElement>(SVGBox::dom_node()); }
     SVG::SVGGraphicsElement const& dom_node() const { return verify_cast<SVG::SVGGraphicsElement>(SVGBox::dom_node()); }
 
-    virtual void before_children_paint(PaintContext& context, PaintPhase phase) override;
+    virtual void before_children_paint(PaintContext& context, Painting::PaintPhase phase) override;
 };
 
 }

+ 4 - 4
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();
 }

+ 2 - 2
Userland/Libraries/LibWeb/Layout/SVGSVGBox.h

@@ -18,8 +18,8 @@ public:
 
     SVG::SVGSVGElement& dom_node() { return verify_cast<SVG::SVGSVGElement>(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; }
 };

+ 3 - 3
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::Chunk> TextNode::ChunkIterator::try_commit_chunk(Utf8View::It
     return {};
 }
 
-void TextNode::paint(PaintContext&, PaintPhase)
+void TextNode::paint(PaintContext&, Painting::PaintPhase)
 {
 }
 

+ 2 - 2
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<EventHandler>, 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;
 };

+ 8 - 8
Userland/Libraries/LibWeb/Painting/StackingContext.cpp

@@ -13,9 +13,9 @@
 #include <LibWeb/Painting/Box.h>
 #include <LibWeb/Painting/StackingContext.h>
 
-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<ReplacedBox>(child);
+        bool child_is_inline_or_replaced = child.is_inline() || is<Layout::ReplacedBox>(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>([&](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<BlockContainer>(m_box)) {
+    if (m_box.children_are_inline() && is<Layout::BlockContainer>(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<float>())) {
-        return HitTestResult {
+        return Layout::HitTestResult {
             .layout_node = m_box,
         };
     }

+ 13 - 5
Userland/Libraries/LibWeb/Painting/StackingContext.h

@@ -9,11 +9,19 @@
 #include <AK/Vector.h>
 #include <LibWeb/Layout/Node.h>
 
-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<StackingContext*> m_children;