summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-03-10 15:50:57 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-11 00:21:49 +0100
commit053766d79cc0916d073a96c3b4a515ba9d714cf6 (patch)
tree48f92ceeaeb5bc19dc262f6174749b249f1514f7 /Userland/Libraries/LibWeb
parent0500dbc3f6e132cc4cb25b53812e2e71d04ff326 (diff)
downloadserenity-053766d79cc0916d073a96c3b4a515ba9d714cf6.zip
LibWeb: Split Paintable into Paintable and PaintableBox
To prepare for paintable inline content, we take the basic painting functionality and hoist it into a base class.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.cpp2
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.h2
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
-rw-r--r--Userland/Libraries/LibWeb/Layout/Box.cpp12
-rw-r--r--Userland/Libraries/LibWeb/Layout/Box.h7
-rw-r--r--Userland/Libraries/LibWeb/Layout/FormattingState.cpp14
-rw-r--r--Userland/Libraries/LibWeb/Layout/FormattingState.h6
-rw-r--r--Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp4
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.cpp10
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.h6
-rw-r--r--Userland/Libraries/LibWeb/Painting/ButtonPaintable.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Painting/ButtonPaintable.h2
-rw-r--r--Userland/Libraries/LibWeb/Painting/CanvasPaintable.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Painting/CanvasPaintable.h2
-rw-r--r--Userland/Libraries/LibWeb/Painting/CheckBoxPaintable.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Painting/CheckBoxPaintable.h2
-rw-r--r--Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Painting/ImagePaintable.h2
-rw-r--r--Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp4
-rw-r--r--Userland/Libraries/LibWeb/Painting/MarkerPaintable.h2
-rw-r--r--Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.h2
-rw-r--r--Userland/Libraries/LibWeb/Painting/Paintable.cpp41
-rw-r--r--Userland/Libraries/LibWeb/Painting/Paintable.h39
-rw-r--r--Userland/Libraries/LibWeb/Painting/ProgressPaintable.cpp4
-rw-r--r--Userland/Libraries/LibWeb/Painting/ProgressPaintable.h2
-rw-r--r--Userland/Libraries/LibWeb/Painting/RadioButtonPaintable.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Painting/RadioButtonPaintable.h2
-rw-r--r--Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Painting/SVGPaintable.cpp8
-rw-r--r--Userland/Libraries/LibWeb/Painting/SVGPaintable.h2
-rw-r--r--Userland/Libraries/LibWeb/Painting/SVGSVGPaintable.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Painting/StackingContext.cpp8
34 files changed, 133 insertions, 95 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp
index 38cf828731..5241cb9f1d 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Node.cpp
@@ -1010,7 +1010,7 @@ size_t Node::length() const
return child_count();
}
-Painting::Paintable const* Node::paint_box() const
+Painting::PaintableBox const* Node::paint_box() const
{
if (!layout_node())
return nullptr;
diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h
index ad3af3129b..8b9b641de2 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.h
+++ b/Userland/Libraries/LibWeb/DOM/Node.h
@@ -158,7 +158,7 @@ public:
const Layout::Node* layout_node() const { return m_layout_node; }
Layout::Node* layout_node() { return m_layout_node; }
- Painting::Paintable const* paint_box() const;
+ Painting::PaintableBox const* paint_box() const;
void set_layout_node(Badge<Layout::Node>, Layout::Node*) const;
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index ccbd40db8a..f088b61bbe 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -266,6 +266,7 @@ class PerformanceTiming;
namespace Web::Painting {
enum class PaintPhase;
class Paintable;
+class PaintableBox;
class PaintableWithLines;
}
diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp
index d449f98a79..2707f59106 100644
--- a/Userland/Libraries/LibWeb/Layout/Box.cpp
+++ b/Userland/Libraries/LibWeb/Layout/Box.cpp
@@ -34,11 +34,6 @@ Box::~Box()
{
}
-void Box::set_paint_box(OwnPtr<Painting::Paintable> paint_box)
-{
- m_paint_box = move(paint_box);
-}
-
// https://www.w3.org/TR/css-display-3/#out-of-flow
bool Box::is_out_of_flow(FormattingContext const& formatting_context) const
{
@@ -93,7 +88,12 @@ bool Box::is_body() const
OwnPtr<Painting::Paintable> Box::create_paintable() const
{
- return Painting::Paintable::create(*this);
+ return Painting::PaintableBox::create(*this);
+}
+
+Painting::PaintableBox const* Box::paint_box() const
+{
+ return static_cast<Painting::PaintableBox const*>(Node::paintable());
}
}
diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h
index 730bebcbf4..d99765587b 100644
--- a/Userland/Libraries/LibWeb/Layout/Box.h
+++ b/Userland/Libraries/LibWeb/Layout/Box.h
@@ -20,10 +20,7 @@ struct LineBoxFragmentCoordinate {
class Box : public NodeWithStyleAndBoxModelMetrics {
public:
- Painting::Paintable const* paint_box() const { return m_paint_box.ptr(); }
- void set_paint_box(OwnPtr<Painting::Paintable>);
-
- OwnPtr<Painting::Paintable> m_paint_box;
+ Painting::PaintableBox const* paint_box() const;
bool is_out_of_flow(FormattingContext const&) const;
@@ -44,7 +41,7 @@ public:
virtual void did_set_rect() { }
- virtual OwnPtr<Painting::Paintable> create_paintable() const;
+ virtual OwnPtr<Painting::Paintable> create_paintable() const override;
protected:
Box(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingState.cpp b/Userland/Libraries/LibWeb/Layout/FormattingState.cpp
index d5078ef030..9e04b8166a 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingState.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FormattingState.cpp
@@ -38,17 +38,19 @@ void FormattingState::commit()
node.box_model().border = { node_state.border_top, node_state.border_right, node_state.border_bottom, node_state.border_left };
node.box_model().margin = { node_state.margin_top, node_state.margin_right, node_state.margin_bottom, node_state.margin_left };
+ node.set_paintable(node.create_paintable());
+
// For boxes, transfer all the state needed for painting.
if (is<Layout::Box>(node)) {
auto& box = static_cast<Layout::Box&>(node);
- box.set_paint_box(box.create_paintable());
- box.m_paint_box->set_offset(node_state.offset);
- box.m_paint_box->set_content_size(node_state.content_width, node_state.content_height);
- box.m_paint_box->set_overflow_data(move(node_state.overflow_data));
- box.m_paint_box->set_containing_line_box_fragment(node_state.containing_line_box_fragment);
+ auto& paint_box = const_cast<Painting::PaintableBox&>(*box.paint_box());
+ paint_box.set_offset(node_state.offset);
+ paint_box.set_content_size(node_state.content_width, node_state.content_height);
+ paint_box.set_overflow_data(move(node_state.overflow_data));
+ paint_box.set_containing_line_box_fragment(node_state.containing_line_box_fragment);
if (is<Layout::BlockContainer>(box))
- static_cast<Painting::PaintableWithLines&>(*box.m_paint_box).set_line_boxes(move(node_state.line_boxes));
+ static_cast<Painting::PaintableWithLines&>(paint_box).set_line_boxes(move(node_state.line_boxes));
}
}
}
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingState.h b/Userland/Libraries/LibWeb/Layout/FormattingState.h
index f1a802f6de..9779c90215 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingState.h
+++ b/Userland/Libraries/LibWeb/Layout/FormattingState.h
@@ -55,12 +55,12 @@ struct FormattingState {
float border_box_width() const { return border_box_left() + content_width + border_box_right(); }
float border_box_height() const { return border_box_top() + content_height + border_box_bottom(); }
- Optional<Painting::Paintable::OverflowData> overflow_data;
+ Optional<Painting::PaintableBox::OverflowData> overflow_data;
- Painting::Paintable::OverflowData& ensure_overflow_data()
+ Painting::PaintableBox::OverflowData& ensure_overflow_data()
{
if (!overflow_data.has_value())
- overflow_data = Painting::Paintable::OverflowData {};
+ overflow_data = Painting::PaintableBox::OverflowData {};
return *overflow_data;
}
diff --git a/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp b/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp
index 14ad05d18a..9e905a8d63 100644
--- a/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp
+++ b/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp
@@ -33,9 +33,9 @@ void InitialContainingBlock::build_stacking_context_tree()
VERIFY(!box.paint_box()->stacking_context());
return IterationDecision::Continue;
}
- auto* parent_context = const_cast<Painting::Paintable*>(box.paint_box())->enclosing_stacking_context();
+ auto* parent_context = const_cast<Painting::PaintableBox*>(box.paint_box())->enclosing_stacking_context();
VERIFY(parent_context);
- const_cast<Painting::Paintable*>(box.paint_box())->set_stacking_context(make<Painting::StackingContext>(box, parent_context));
+ const_cast<Painting::PaintableBox*>(box.paint_box())->set_stacking_context(make<Painting::StackingContext>(box, parent_context));
return IterationDecision::Continue;
});
}
diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp
index 03dfca9526..742969e6f3 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.cpp
+++ b/Userland/Libraries/LibWeb/Layout/Node.cpp
@@ -584,4 +584,14 @@ NonnullRefPtr<NodeWithStyle> NodeWithStyle::create_anonymous_wrapper() const
return wrapper;
}
+void Node::set_paintable(OwnPtr<Painting::Paintable> paintable)
+{
+ m_paintable = move(paintable);
+}
+
+OwnPtr<Painting::Paintable> Node::create_paintable() const
+{
+ return nullptr;
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h
index 7512d9e39d..5cb405df73 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.h
+++ b/Userland/Libraries/LibWeb/Layout/Node.h
@@ -54,6 +54,11 @@ public:
const DOM::Node* dom_node() const { return m_dom_node; }
DOM::Node* dom_node() { return m_dom_node; }
+ Painting::Paintable const* paintable() const { return m_paintable; }
+ void set_paintable(OwnPtr<Painting::Paintable>);
+
+ virtual OwnPtr<Painting::Paintable> create_paintable() const;
+
DOM::Document& document() { return m_document; }
const DOM::Document& document() const { return m_document; }
@@ -219,6 +224,7 @@ private:
NonnullRefPtr<DOM::Document> m_document;
RefPtr<DOM::Node> m_dom_node;
+ OwnPtr<Painting::Paintable> m_paintable;
bool m_inline { false };
bool m_has_style { false };
diff --git a/Userland/Libraries/LibWeb/Painting/ButtonPaintable.cpp b/Userland/Libraries/LibWeb/Painting/ButtonPaintable.cpp
index c05a80bf92..ed21c6db0b 100644
--- a/Userland/Libraries/LibWeb/Painting/ButtonPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/ButtonPaintable.cpp
@@ -16,13 +16,13 @@ NonnullOwnPtr<ButtonPaintable> ButtonPaintable::create(Layout::ButtonBox const&
}
ButtonPaintable::ButtonPaintable(Layout::ButtonBox const& layout_box)
- : Paintable(layout_box)
+ : PaintableBox(layout_box)
{
}
Layout::ButtonBox const& ButtonPaintable::layout_box() const
{
- return static_cast<Layout::ButtonBox const&>(m_layout_box);
+ return static_cast<Layout::ButtonBox const&>(layout_node());
}
void ButtonPaintable::paint(PaintContext& context, PaintPhase phase) const
@@ -30,7 +30,7 @@ void ButtonPaintable::paint(PaintContext& context, PaintPhase phase) const
if (!is_visible())
return;
- Paintable::paint(context, phase);
+ PaintableBox::paint(context, phase);
if (phase == PaintPhase::Foreground) {
auto text_rect = enclosing_int_rect(absolute_rect());
diff --git a/Userland/Libraries/LibWeb/Painting/ButtonPaintable.h b/Userland/Libraries/LibWeb/Painting/ButtonPaintable.h
index a8483594eb..724ebeb02c 100644
--- a/Userland/Libraries/LibWeb/Painting/ButtonPaintable.h
+++ b/Userland/Libraries/LibWeb/Painting/ButtonPaintable.h
@@ -11,7 +11,7 @@
namespace Web::Painting {
-class ButtonPaintable final : public Paintable {
+class ButtonPaintable final : public PaintableBox {
public:
static NonnullOwnPtr<ButtonPaintable> create(Layout::ButtonBox const&);
diff --git a/Userland/Libraries/LibWeb/Painting/CanvasPaintable.cpp b/Userland/Libraries/LibWeb/Painting/CanvasPaintable.cpp
index e2ff5039e9..ff4311bca9 100644
--- a/Userland/Libraries/LibWeb/Painting/CanvasPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/CanvasPaintable.cpp
@@ -14,13 +14,13 @@ NonnullOwnPtr<CanvasPaintable> CanvasPaintable::create(Layout::CanvasBox const&
}
CanvasPaintable::CanvasPaintable(Layout::CanvasBox const& layout_box)
- : Paintable(layout_box)
+ : PaintableBox(layout_box)
{
}
Layout::CanvasBox const& CanvasPaintable::layout_box() const
{
- return static_cast<Layout::CanvasBox const&>(m_layout_box);
+ return static_cast<Layout::CanvasBox const&>(layout_node());
}
void CanvasPaintable::paint(PaintContext& context, PaintPhase phase) const
@@ -28,7 +28,7 @@ void CanvasPaintable::paint(PaintContext& context, PaintPhase phase) const
if (!layout_box().is_visible())
return;
- Paintable::paint(context, phase);
+ PaintableBox::paint(context, phase);
if (phase == PaintPhase::Foreground) {
// FIXME: This should be done at a different level. Also rect() does not include padding etc!
diff --git a/Userland/Libraries/LibWeb/Painting/CanvasPaintable.h b/Userland/Libraries/LibWeb/Painting/CanvasPaintable.h
index c43707233a..d8669d0948 100644
--- a/Userland/Libraries/LibWeb/Painting/CanvasPaintable.h
+++ b/Userland/Libraries/LibWeb/Painting/CanvasPaintable.h
@@ -11,7 +11,7 @@
namespace Web::Painting {
-class CanvasPaintable final : public Paintable {
+class CanvasPaintable final : public PaintableBox {
public:
static NonnullOwnPtr<CanvasPaintable> create(Layout::CanvasBox const&);
diff --git a/Userland/Libraries/LibWeb/Painting/CheckBoxPaintable.cpp b/Userland/Libraries/LibWeb/Painting/CheckBoxPaintable.cpp
index 33e480f78e..7ae96f64e5 100644
--- a/Userland/Libraries/LibWeb/Painting/CheckBoxPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/CheckBoxPaintable.cpp
@@ -17,13 +17,13 @@ NonnullOwnPtr<CheckBoxPaintable> CheckBoxPaintable::create(Layout::CheckBox cons
}
CheckBoxPaintable::CheckBoxPaintable(Layout::CheckBox const& layout_box)
- : Paintable(layout_box)
+ : PaintableBox(layout_box)
{
}
Layout::CheckBox const& CheckBoxPaintable::layout_box() const
{
- return static_cast<Layout::CheckBox const&>(m_layout_box);
+ return static_cast<Layout::CheckBox const&>(layout_node());
}
void CheckBoxPaintable::paint(PaintContext& context, PaintPhase phase) const
@@ -31,7 +31,7 @@ void CheckBoxPaintable::paint(PaintContext& context, PaintPhase phase) const
if (!is_visible())
return;
- Paintable::paint(context, phase);
+ PaintableBox::paint(context, phase);
if (phase == PaintPhase::Foreground)
Gfx::StylePainter::paint_check_box(context.painter(), enclosing_int_rect(absolute_rect()), context.palette(), layout_box().dom_node().enabled(), layout_box().dom_node().checked(), layout_box().being_pressed());
diff --git a/Userland/Libraries/LibWeb/Painting/CheckBoxPaintable.h b/Userland/Libraries/LibWeb/Painting/CheckBoxPaintable.h
index 51cf9a5dbb..2f063bb538 100644
--- a/Userland/Libraries/LibWeb/Painting/CheckBoxPaintable.h
+++ b/Userland/Libraries/LibWeb/Painting/CheckBoxPaintable.h
@@ -11,7 +11,7 @@
namespace Web::Painting {
-class CheckBoxPaintable final : public Paintable {
+class CheckBoxPaintable final : public PaintableBox {
public:
static NonnullOwnPtr<CheckBoxPaintable> create(Layout::CheckBox const&);
diff --git a/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp b/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp
index ec5f445330..f94815432f 100644
--- a/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp
@@ -17,13 +17,13 @@ NonnullOwnPtr<ImagePaintable> ImagePaintable::create(Layout::ImageBox const& lay
}
ImagePaintable::ImagePaintable(Layout::ImageBox const& layout_box)
- : Paintable(layout_box)
+ : PaintableBox(layout_box)
{
}
Layout::ImageBox const& ImagePaintable::layout_box() const
{
- return static_cast<Layout::ImageBox const&>(m_layout_box);
+ return static_cast<Layout::ImageBox const&>(layout_node());
}
void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const
@@ -35,7 +35,7 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const
if (!context.viewport_rect().intersects(enclosing_int_rect(absolute_rect())))
return;
- Paintable::paint(context, phase);
+ PaintableBox::paint(context, phase);
if (phase == PaintPhase::Foreground) {
if (layout_box().renders_as_alt_text()) {
diff --git a/Userland/Libraries/LibWeb/Painting/ImagePaintable.h b/Userland/Libraries/LibWeb/Painting/ImagePaintable.h
index 8ede3c2514..3b73679831 100644
--- a/Userland/Libraries/LibWeb/Painting/ImagePaintable.h
+++ b/Userland/Libraries/LibWeb/Painting/ImagePaintable.h
@@ -11,7 +11,7 @@
namespace Web::Painting {
-class ImagePaintable final : public Paintable {
+class ImagePaintable final : public PaintableBox {
public:
static NonnullOwnPtr<ImagePaintable> create(Layout::ImageBox const&);
diff --git a/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp b/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp
index 5cffd99a87..2493c210f2 100644
--- a/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp
@@ -16,13 +16,13 @@ NonnullOwnPtr<MarkerPaintable> MarkerPaintable::create(Layout::ListItemMarkerBox
}
MarkerPaintable::MarkerPaintable(Layout::ListItemMarkerBox const& layout_box)
- : Paintable(layout_box)
+ : PaintableBox(layout_box)
{
}
Layout::ListItemMarkerBox const& MarkerPaintable::layout_box() const
{
- return static_cast<Layout::ListItemMarkerBox const&>(m_layout_box);
+ return static_cast<Layout::ListItemMarkerBox const&>(layout_node());
}
void MarkerPaintable::paint(PaintContext& context, PaintPhase phase) const
diff --git a/Userland/Libraries/LibWeb/Painting/MarkerPaintable.h b/Userland/Libraries/LibWeb/Painting/MarkerPaintable.h
index e4f38d542a..f0551c6b7a 100644
--- a/Userland/Libraries/LibWeb/Painting/MarkerPaintable.h
+++ b/Userland/Libraries/LibWeb/Painting/MarkerPaintable.h
@@ -11,7 +11,7 @@
namespace Web::Painting {
-class MarkerPaintable final : public Paintable {
+class MarkerPaintable final : public PaintableBox {
public:
static NonnullOwnPtr<MarkerPaintable> create(Layout::ListItemMarkerBox const&);
diff --git a/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.cpp b/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.cpp
index 5ef89071b2..a932bd36db 100644
--- a/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.cpp
@@ -18,18 +18,18 @@ NonnullOwnPtr<NestedBrowsingContextPaintable> NestedBrowsingContextPaintable::cr
}
NestedBrowsingContextPaintable::NestedBrowsingContextPaintable(Layout::FrameBox const& layout_box)
- : Paintable(layout_box)
+ : PaintableBox(layout_box)
{
}
Layout::FrameBox const& NestedBrowsingContextPaintable::layout_box() const
{
- return static_cast<Layout::FrameBox const&>(m_layout_box);
+ return static_cast<Layout::FrameBox const&>(layout_node());
}
void NestedBrowsingContextPaintable::paint(PaintContext& context, PaintPhase phase) const
{
- Paintable::paint(context, phase);
+ PaintableBox::paint(context, phase);
if (phase == PaintPhase::Foreground) {
auto* hosted_document = layout_box().dom_node().content_document_without_origin_check();
diff --git a/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.h b/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.h
index b524c090f4..4b4b46bba7 100644
--- a/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.h
+++ b/Userland/Libraries/LibWeb/Painting/NestedBrowsingContextPaintable.h
@@ -11,7 +11,7 @@
namespace Web::Painting {
-class NestedBrowsingContextPaintable final : public Paintable {
+class NestedBrowsingContextPaintable final : public PaintableBox {
public:
static NonnullOwnPtr<NestedBrowsingContextPaintable> create(Layout::FrameBox const&);
diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.cpp b/Userland/Libraries/LibWeb/Painting/Paintable.cpp
index 4471bd7a84..dd2b2c176b 100644
--- a/Userland/Libraries/LibWeb/Painting/Paintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/Paintable.cpp
@@ -13,17 +13,22 @@
namespace Web::Painting {
-Paintable::Paintable(Layout::Box const& layout_box)
- : m_layout_box(layout_box)
+NonnullOwnPtr<PaintableBox> PaintableBox::create(Layout::Box const& layout_box)
{
+ return adopt_own(*new PaintableBox(layout_box));
}
-Paintable::~Paintable()
+PaintableBox::PaintableBox(Layout::Box const& layout_box)
+ : Paintable(layout_box)
+{
+}
+
+PaintableBox::~PaintableBox()
{
}
PaintableWithLines::PaintableWithLines(Layout::BlockContainer const& layout_box)
- : Paintable(layout_box)
+ : PaintableBox(layout_box)
{
}
@@ -31,7 +36,7 @@ PaintableWithLines::~PaintableWithLines()
{
}
-void Paintable::set_offset(const Gfx::FloatPoint& offset)
+void PaintableBox::set_offset(const Gfx::FloatPoint& offset)
{
if (m_offset == offset)
return;
@@ -40,7 +45,7 @@ void Paintable::set_offset(const Gfx::FloatPoint& offset)
const_cast<Layout::Box&>(layout_box()).did_set_rect();
}
-void Paintable::set_content_size(Gfx::FloatSize const& size)
+void PaintableBox::set_content_size(Gfx::FloatSize const& size)
{
if (m_content_size == size)
return;
@@ -49,7 +54,7 @@ void Paintable::set_content_size(Gfx::FloatSize const& size)
const_cast<Layout::Box&>(layout_box()).did_set_rect();
}
-Gfx::FloatPoint Paintable::effective_offset() const
+Gfx::FloatPoint PaintableBox::effective_offset() const
{
if (m_containing_line_box_fragment.has_value()) {
auto const& fragment = layout_box().containing_block()->paint_box()->line_boxes()[m_containing_line_box_fragment->line_box_index].fragments()[m_containing_line_box_fragment->fragment_index];
@@ -58,7 +63,7 @@ Gfx::FloatPoint Paintable::effective_offset() const
return m_offset;
}
-Gfx::FloatRect Paintable::absolute_rect() const
+Gfx::FloatRect PaintableBox::absolute_rect() const
{
Gfx::FloatRect rect { effective_offset(), content_size() };
for (auto* block = layout_box().containing_block(); block; block = block->containing_block())
@@ -66,12 +71,12 @@ Gfx::FloatRect Paintable::absolute_rect() const
return rect;
}
-void Paintable::set_containing_line_box_fragment(Optional<Layout::LineBoxFragmentCoordinate> fragment_coordinate)
+void PaintableBox::set_containing_line_box_fragment(Optional<Layout::LineBoxFragmentCoordinate> fragment_coordinate)
{
m_containing_line_box_fragment = fragment_coordinate;
}
-Painting::StackingContext* Paintable::enclosing_stacking_context()
+Painting::StackingContext* PaintableBox::enclosing_stacking_context()
{
for (auto* ancestor = layout_box().parent(); ancestor; ancestor = ancestor->parent()) {
if (!is<Layout::Box>(ancestor))
@@ -86,7 +91,7 @@ Painting::StackingContext* Paintable::enclosing_stacking_context()
VERIFY_NOT_REACHED();
}
-void Paintable::paint(PaintContext& context, PaintPhase phase) const
+void PaintableBox::paint(PaintContext& context, PaintPhase phase) const
{
if (!is_visible())
return;
@@ -145,7 +150,7 @@ void Paintable::paint(PaintContext& context, PaintPhase phase) const
}
}
-void Paintable::paint_border(PaintContext& context) const
+void PaintableBox::paint_border(PaintContext& context) const
{
auto borders_data = BordersData {
.top = computed_values().border_top(),
@@ -156,7 +161,7 @@ void Paintable::paint_border(PaintContext& context) const
paint_all_borders(context, absolute_border_box_rect(), normalized_border_radius_data(), borders_data);
}
-void Paintable::paint_background(PaintContext& context) const
+void PaintableBox::paint_background(PaintContext& context) const
{
// If the body's background properties were propagated to the root element, do no re-paint the body's background.
if (layout_box().is_body() && document().html_element()->should_use_body_background_properties())
@@ -188,7 +193,7 @@ void Paintable::paint_background(PaintContext& context) const
Painting::paint_background(context, layout_box(), background_rect, background_color, background_layers, normalized_border_radius_data());
}
-void Paintable::paint_box_shadow(PaintContext& context) const
+void PaintableBox::paint_box_shadow(PaintContext& context) const
{
auto box_shadow_data = computed_values().box_shadow();
if (box_shadow_data.is_empty())
@@ -208,7 +213,7 @@ void Paintable::paint_box_shadow(PaintContext& context) const
Painting::paint_box_shadow(context, enclosing_int_rect(absolute_border_box_rect()), resolved_box_shadow_data);
}
-BorderRadiusData Paintable::normalized_border_radius_data() const
+BorderRadiusData PaintableBox::normalized_border_radius_data() const
{
return Painting::normalized_border_radius_data(layout_box(), absolute_border_box_rect(),
computed_values().border_top_left_radius(),
@@ -217,7 +222,7 @@ BorderRadiusData Paintable::normalized_border_radius_data() const
computed_values().border_bottom_left_radius());
}
-void Paintable::before_children_paint(PaintContext& context, PaintPhase) const
+void PaintableBox::before_children_paint(PaintContext& context, PaintPhase) const
{
// FIXME: Support more overflow variations.
if (computed_values().overflow_x() == CSS::Overflow::Hidden && computed_values().overflow_y() == CSS::Overflow::Hidden) {
@@ -226,7 +231,7 @@ void Paintable::before_children_paint(PaintContext& context, PaintPhase) const
}
}
-void Paintable::after_children_paint(PaintContext& context, PaintPhase) const
+void PaintableBox::after_children_paint(PaintContext& context, PaintPhase) const
{
// FIXME: Support more overflow variations.
if (computed_values().overflow_x() == CSS::Overflow::Hidden && computed_values().overflow_y() == CSS::Overflow::Hidden)
@@ -238,7 +243,7 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const
if (!is_visible())
return;
- Paintable::paint(context, phase);
+ PaintableBox::paint(context, phase);
if (m_line_boxes.is_empty())
return;
diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.h b/Userland/Libraries/LibWeb/Painting/Paintable.h
index 90975099c8..73cc9d5c1c 100644
--- a/Userland/Libraries/LibWeb/Painting/Paintable.h
+++ b/Userland/Libraries/LibWeb/Painting/Paintable.h
@@ -14,21 +14,38 @@
namespace Web::Painting {
class Paintable {
+ AK_MAKE_NONMOVABLE(Paintable);
+ AK_MAKE_NONCOPYABLE(Paintable);
+
public:
- static NonnullOwnPtr<Paintable> create(Layout::Box const& layout_box)
+ virtual ~Paintable() = default;
+
+ virtual void paint(PaintContext&, PaintPhase) const { }
+ virtual void before_children_paint(PaintContext&, PaintPhase) const { }
+ virtual void after_children_paint(PaintContext&, PaintPhase) const { }
+
+ Layout::Node const& layout_node() const { return m_layout_node; }
+
+protected:
+ explicit Paintable(Layout::Node const& layout_node)
+ : m_layout_node(layout_node)
{
- return adopt_own(*new Paintable(layout_box));
}
- virtual ~Paintable();
+private:
+ Layout::Node const& m_layout_node;
+};
- virtual void paint(PaintContext&, PaintPhase) const;
+class PaintableBox : public Paintable {
+public:
+ static NonnullOwnPtr<PaintableBox> create(Layout::Box const&);
+ virtual ~PaintableBox();
- bool is_visible() const { return layout_box().is_visible(); }
+ virtual void paint(PaintContext&, PaintPhase) const override;
- Layout::Box const& m_layout_box;
+ bool is_visible() const { return layout_box().is_visible(); }
- Layout::Box const& layout_box() const { return m_layout_box; }
+ Layout::Box const& layout_box() const { return static_cast<Layout::Box const&>(Paintable::layout_node()); }
auto const& box_model() const { return layout_box().box_model(); }
auto const& computed_values() const { return layout_box().computed_values(); }
@@ -118,11 +135,11 @@ public:
DOM::Node const* dom_node() const { return layout_box().dom_node(); }
DOM::Document const& document() const { return layout_box().document(); }
- virtual void before_children_paint(PaintContext&, PaintPhase) const;
- virtual void after_children_paint(PaintContext&, PaintPhase) const;
+ virtual void before_children_paint(PaintContext&, PaintPhase) const override;
+ virtual void after_children_paint(PaintContext&, PaintPhase) const override;
protected:
- explicit Paintable(Layout::Box const&);
+ explicit PaintableBox(Layout::Box const&);
virtual void paint_border(PaintContext&) const;
virtual void paint_background(PaintContext&) const;
@@ -134,7 +151,7 @@ private:
OwnPtr<Painting::StackingContext> m_stacking_context;
};
-class PaintableWithLines : public Paintable {
+class PaintableWithLines : public PaintableBox {
public:
static NonnullOwnPtr<PaintableWithLines> create(Layout::BlockContainer const& block_container)
{
diff --git a/Userland/Libraries/LibWeb/Painting/ProgressPaintable.cpp b/Userland/Libraries/LibWeb/Painting/ProgressPaintable.cpp
index de1f8cb7a7..266a4ee864 100644
--- a/Userland/Libraries/LibWeb/Painting/ProgressPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/ProgressPaintable.cpp
@@ -15,13 +15,13 @@ NonnullOwnPtr<ProgressPaintable> ProgressPaintable::create(Layout::Progress cons
}
ProgressPaintable::ProgressPaintable(Layout::Progress const& layout_box)
- : Paintable(layout_box)
+ : PaintableBox(layout_box)
{
}
Layout::Progress const& ProgressPaintable::layout_box() const
{
- return static_cast<Layout::Progress const&>(m_layout_box);
+ return static_cast<Layout::Progress const&>(layout_node());
}
void ProgressPaintable::paint(PaintContext& context, PaintPhase phase) const
diff --git a/Userland/Libraries/LibWeb/Painting/ProgressPaintable.h b/Userland/Libraries/LibWeb/Painting/ProgressPaintable.h
index 097132d352..122f5436ba 100644
--- a/Userland/Libraries/LibWeb/Painting/ProgressPaintable.h
+++ b/Userland/Libraries/LibWeb/Painting/ProgressPaintable.h
@@ -11,7 +11,7 @@
namespace Web::Painting {
-class ProgressPaintable final : public Paintable {
+class ProgressPaintable final : public PaintableBox {
public:
static NonnullOwnPtr<ProgressPaintable> create(Layout::Progress const&);
diff --git a/Userland/Libraries/LibWeb/Painting/RadioButtonPaintable.cpp b/Userland/Libraries/LibWeb/Painting/RadioButtonPaintable.cpp
index 47b5d4a09f..6feb8b9141 100644
--- a/Userland/Libraries/LibWeb/Painting/RadioButtonPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/RadioButtonPaintable.cpp
@@ -17,13 +17,13 @@ NonnullOwnPtr<RadioButtonPaintable> RadioButtonPaintable::create(Layout::RadioBu
}
RadioButtonPaintable::RadioButtonPaintable(Layout::RadioButton const& layout_box)
- : Paintable(layout_box)
+ : PaintableBox(layout_box)
{
}
Layout::RadioButton const& RadioButtonPaintable::layout_box() const
{
- return static_cast<Layout::RadioButton const&>(m_layout_box);
+ return static_cast<Layout::RadioButton const&>(layout_node());
}
void RadioButtonPaintable::paint(PaintContext& context, PaintPhase phase) const
@@ -31,7 +31,7 @@ void RadioButtonPaintable::paint(PaintContext& context, PaintPhase phase) const
if (!is_visible())
return;
- Paintable::paint(context, phase);
+ PaintableBox::paint(context, phase);
if (phase == PaintPhase::Foreground)
Gfx::StylePainter::paint_radio_button(context.painter(), enclosing_int_rect(absolute_rect()), context.palette(), layout_box().dom_node().checked(), layout_box().being_pressed());
diff --git a/Userland/Libraries/LibWeb/Painting/RadioButtonPaintable.h b/Userland/Libraries/LibWeb/Painting/RadioButtonPaintable.h
index bf356587eb..acd7f4eff0 100644
--- a/Userland/Libraries/LibWeb/Painting/RadioButtonPaintable.h
+++ b/Userland/Libraries/LibWeb/Painting/RadioButtonPaintable.h
@@ -11,7 +11,7 @@
namespace Web::Painting {
-class RadioButtonPaintable final : public Paintable {
+class RadioButtonPaintable final : public PaintableBox {
public:
static NonnullOwnPtr<RadioButtonPaintable> create(Layout::RadioButton const&);
diff --git a/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp b/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp
index f238b9a8a8..258cf0c6d0 100644
--- a/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp
@@ -23,7 +23,7 @@ SVGGeometryPaintable::SVGGeometryPaintable(Layout::SVGGeometryBox const& layout_
Layout::SVGGeometryBox const& SVGGeometryPaintable::layout_box() const
{
- return static_cast<Layout::SVGGeometryBox const&>(m_layout_box);
+ return static_cast<Layout::SVGGeometryBox const&>(layout_node());
}
void SVGGeometryPaintable::paint(PaintContext& context, PaintPhase phase) const
diff --git a/Userland/Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp b/Userland/Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp
index b13f202a64..4c4f3adb12 100644
--- a/Userland/Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp
@@ -16,7 +16,7 @@ SVGGraphicsPaintable::SVGGraphicsPaintable(Layout::SVGGraphicsBox const& layout_
Layout::SVGGraphicsBox const& SVGGraphicsPaintable::layout_box() const
{
- return static_cast<Layout::SVGGraphicsBox const&>(m_layout_box);
+ return static_cast<Layout::SVGGraphicsBox const&>(layout_node());
}
void SVGGraphicsPaintable::before_children_paint(PaintContext& context, PaintPhase phase) const
diff --git a/Userland/Libraries/LibWeb/Painting/SVGPaintable.cpp b/Userland/Libraries/LibWeb/Painting/SVGPaintable.cpp
index febe538e58..22f8898f5e 100644
--- a/Userland/Libraries/LibWeb/Painting/SVGPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/SVGPaintable.cpp
@@ -10,18 +10,18 @@
namespace Web::Painting {
SVGPaintable::SVGPaintable(Layout::SVGBox const& layout_box)
- : Paintable(layout_box)
+ : PaintableBox(layout_box)
{
}
Layout::SVGBox const& SVGPaintable::layout_box() const
{
- return static_cast<Layout::SVGBox const&>(m_layout_box);
+ return static_cast<Layout::SVGBox const&>(layout_node());
}
void SVGPaintable::before_children_paint(PaintContext& context, PaintPhase phase) const
{
- Paintable::before_children_paint(context, phase);
+ PaintableBox::before_children_paint(context, phase);
if (phase != PaintPhase::Foreground)
return;
context.svg_context().save();
@@ -29,7 +29,7 @@ void SVGPaintable::before_children_paint(PaintContext& context, PaintPhase phase
void SVGPaintable::after_children_paint(PaintContext& context, PaintPhase phase) const
{
- Paintable::after_children_paint(context, phase);
+ PaintableBox::after_children_paint(context, phase);
if (phase != PaintPhase::Foreground)
return;
context.svg_context().restore();
diff --git a/Userland/Libraries/LibWeb/Painting/SVGPaintable.h b/Userland/Libraries/LibWeb/Painting/SVGPaintable.h
index d429586485..f235b0c0ab 100644
--- a/Userland/Libraries/LibWeb/Painting/SVGPaintable.h
+++ b/Userland/Libraries/LibWeb/Painting/SVGPaintable.h
@@ -11,7 +11,7 @@
namespace Web::Painting {
-class SVGPaintable : public Paintable {
+class SVGPaintable : public PaintableBox {
public:
static NonnullOwnPtr<SVGPaintable> create(Layout::SVGBox const&);
diff --git a/Userland/Libraries/LibWeb/Painting/SVGSVGPaintable.cpp b/Userland/Libraries/LibWeb/Painting/SVGSVGPaintable.cpp
index 8871d1311d..0478d62cda 100644
--- a/Userland/Libraries/LibWeb/Painting/SVGSVGPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/SVGSVGPaintable.cpp
@@ -16,7 +16,7 @@ SVGSVGPaintable::SVGSVGPaintable(Layout::SVGSVGBox const& layout_box)
Layout::SVGSVGBox const& SVGSVGPaintable::layout_box() const
{
- return static_cast<Layout::SVGSVGBox const&>(m_layout_box);
+ return static_cast<Layout::SVGSVGBox const&>(layout_node());
}
void SVGSVGPaintable::before_children_paint(PaintContext& context, PaintPhase phase) const
diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp
index c79bda6708..67a9bfe01b 100644
--- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp
+++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp
@@ -47,8 +47,8 @@ StackingContext::StackingContext(Layout::Box& box, StackingContext* parent)
void StackingContext::paint_descendants(PaintContext& context, Layout::Node& box, StackingContextPaintPhase phase) const
{
if (phase == StackingContextPaintPhase::Foreground) {
- if (box.is_box())
- static_cast<Layout::Box const&>(box).m_paint_box->before_children_paint(context, PaintPhase::Foreground);
+ if (auto* paintable = box.paintable())
+ paintable->before_children_paint(context, PaintPhase::Foreground);
}
box.for_each_child([&](auto& child) {
@@ -100,8 +100,8 @@ void StackingContext::paint_descendants(PaintContext& context, Layout::Node& box
});
if (phase == StackingContextPaintPhase::Foreground) {
- if (box.is_box())
- static_cast<Layout::Box const&>(box).m_paint_box->after_children_paint(context, PaintPhase::Foreground);
+ if (auto* paintable = box.paintable())
+ paintable->after_children_paint(context, PaintPhase::Foreground);
}
}