Skip to content

Commit 053766d

Browse files
committed
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.
1 parent 0500dbc commit 053766d

34 files changed

+133
-95
lines changed

Userland/Libraries/LibWeb/DOM/Node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ size_t Node::length() const
10101010
return child_count();
10111011
}
10121012

1013-
Painting::Paintable const* Node::paint_box() const
1013+
Painting::PaintableBox const* Node::paint_box() const
10141014
{
10151015
if (!layout_node())
10161016
return nullptr;

Userland/Libraries/LibWeb/DOM/Node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Node
158158
const Layout::Node* layout_node() const { return m_layout_node; }
159159
Layout::Node* layout_node() { return m_layout_node; }
160160

161-
Painting::Paintable const* paint_box() const;
161+
Painting::PaintableBox const* paint_box() const;
162162

163163
void set_layout_node(Badge<Layout::Node>, Layout::Node*) const;
164164

Userland/Libraries/LibWeb/Forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class PerformanceTiming;
266266
namespace Web::Painting {
267267
enum class PaintPhase;
268268
class Paintable;
269+
class PaintableBox;
269270
class PaintableWithLines;
270271
}
271272

Userland/Libraries/LibWeb/Layout/Box.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ Box::~Box()
3434
{
3535
}
3636

37-
void Box::set_paint_box(OwnPtr<Painting::Paintable> paint_box)
38-
{
39-
m_paint_box = move(paint_box);
40-
}
41-
4237
// https://www.w3.org/TR/css-display-3/#out-of-flow
4338
bool Box::is_out_of_flow(FormattingContext const& formatting_context) const
4439
{
@@ -93,7 +88,12 @@ bool Box::is_body() const
9388

9489
OwnPtr<Painting::Paintable> Box::create_paintable() const
9590
{
96-
return Painting::Paintable::create(*this);
91+
return Painting::PaintableBox::create(*this);
92+
}
93+
94+
Painting::PaintableBox const* Box::paint_box() const
95+
{
96+
return static_cast<Painting::PaintableBox const*>(Node::paintable());
9797
}
9898

9999
}

Userland/Libraries/LibWeb/Layout/Box.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ struct LineBoxFragmentCoordinate {
2020

2121
class Box : public NodeWithStyleAndBoxModelMetrics {
2222
public:
23-
Painting::Paintable const* paint_box() const { return m_paint_box.ptr(); }
24-
void set_paint_box(OwnPtr<Painting::Paintable>);
25-
26-
OwnPtr<Painting::Paintable> m_paint_box;
23+
Painting::PaintableBox const* paint_box() const;
2724

2825
bool is_out_of_flow(FormattingContext const&) const;
2926

@@ -44,7 +41,7 @@ class Box : public NodeWithStyleAndBoxModelMetrics {
4441

4542
virtual void did_set_rect() { }
4643

47-
virtual OwnPtr<Painting::Paintable> create_paintable() const;
44+
virtual OwnPtr<Painting::Paintable> create_paintable() const override;
4845

4946
protected:
5047
Box(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);

Userland/Libraries/LibWeb/Layout/FormattingState.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,19 @@ void FormattingState::commit()
3838
node.box_model().border = { node_state.border_top, node_state.border_right, node_state.border_bottom, node_state.border_left };
3939
node.box_model().margin = { node_state.margin_top, node_state.margin_right, node_state.margin_bottom, node_state.margin_left };
4040

41+
node.set_paintable(node.create_paintable());
42+
4143
// For boxes, transfer all the state needed for painting.
4244
if (is<Layout::Box>(node)) {
4345
auto& box = static_cast<Layout::Box&>(node);
44-
box.set_paint_box(box.create_paintable());
45-
box.m_paint_box->set_offset(node_state.offset);
46-
box.m_paint_box->set_content_size(node_state.content_width, node_state.content_height);
47-
box.m_paint_box->set_overflow_data(move(node_state.overflow_data));
48-
box.m_paint_box->set_containing_line_box_fragment(node_state.containing_line_box_fragment);
46+
auto& paint_box = const_cast<Painting::PaintableBox&>(*box.paint_box());
47+
paint_box.set_offset(node_state.offset);
48+
paint_box.set_content_size(node_state.content_width, node_state.content_height);
49+
paint_box.set_overflow_data(move(node_state.overflow_data));
50+
paint_box.set_containing_line_box_fragment(node_state.containing_line_box_fragment);
4951

5052
if (is<Layout::BlockContainer>(box))
51-
static_cast<Painting::PaintableWithLines&>(*box.m_paint_box).set_line_boxes(move(node_state.line_boxes));
53+
static_cast<Painting::PaintableWithLines&>(paint_box).set_line_boxes(move(node_state.line_boxes));
5254
}
5355
}
5456
}

Userland/Libraries/LibWeb/Layout/FormattingState.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ struct FormattingState {
5555
float border_box_width() const { return border_box_left() + content_width + border_box_right(); }
5656
float border_box_height() const { return border_box_top() + content_height + border_box_bottom(); }
5757

58-
Optional<Painting::Paintable::OverflowData> overflow_data;
58+
Optional<Painting::PaintableBox::OverflowData> overflow_data;
5959

60-
Painting::Paintable::OverflowData& ensure_overflow_data()
60+
Painting::PaintableBox::OverflowData& ensure_overflow_data()
6161
{
6262
if (!overflow_data.has_value())
63-
overflow_data = Painting::Paintable::OverflowData {};
63+
overflow_data = Painting::PaintableBox::OverflowData {};
6464
return *overflow_data;
6565
}
6666

Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ void InitialContainingBlock::build_stacking_context_tree()
3333
VERIFY(!box.paint_box()->stacking_context());
3434
return IterationDecision::Continue;
3535
}
36-
auto* parent_context = const_cast<Painting::Paintable*>(box.paint_box())->enclosing_stacking_context();
36+
auto* parent_context = const_cast<Painting::PaintableBox*>(box.paint_box())->enclosing_stacking_context();
3737
VERIFY(parent_context);
38-
const_cast<Painting::Paintable*>(box.paint_box())->set_stacking_context(make<Painting::StackingContext>(box, parent_context));
38+
const_cast<Painting::PaintableBox*>(box.paint_box())->set_stacking_context(make<Painting::StackingContext>(box, parent_context));
3939
return IterationDecision::Continue;
4040
});
4141
}

Userland/Libraries/LibWeb/Layout/Node.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,4 +584,14 @@ NonnullRefPtr<NodeWithStyle> NodeWithStyle::create_anonymous_wrapper() const
584584
return wrapper;
585585
}
586586

587+
void Node::set_paintable(OwnPtr<Painting::Paintable> paintable)
588+
{
589+
m_paintable = move(paintable);
590+
}
591+
592+
OwnPtr<Painting::Paintable> Node::create_paintable() const
593+
{
594+
return nullptr;
595+
}
596+
587597
}

Userland/Libraries/LibWeb/Layout/Node.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class Node : public TreeNode<Node> {
5454
const DOM::Node* dom_node() const { return m_dom_node; }
5555
DOM::Node* dom_node() { return m_dom_node; }
5656

57+
Painting::Paintable const* paintable() const { return m_paintable; }
58+
void set_paintable(OwnPtr<Painting::Paintable>);
59+
60+
virtual OwnPtr<Painting::Paintable> create_paintable() const;
61+
5762
DOM::Document& document() { return m_document; }
5863
const DOM::Document& document() const { return m_document; }
5964

@@ -219,6 +224,7 @@ class Node : public TreeNode<Node> {
219224

220225
NonnullRefPtr<DOM::Document> m_document;
221226
RefPtr<DOM::Node> m_dom_node;
227+
OwnPtr<Painting::Paintable> m_paintable;
222228

223229
bool m_inline { false };
224230
bool m_has_style { false };

0 commit comments

Comments
 (0)