1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:27:46 +00:00

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.
This commit is contained in:
Andreas Kling 2022-03-10 15:50:57 +01:00
parent 0500dbc3f6
commit 053766d79c
34 changed files with 133 additions and 95 deletions

View file

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

View file

@ -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>);

View file

@ -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));
}
}
}

View file

@ -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;
}

View file

@ -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;
});
}

View file

@ -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;
}
}

View file

@ -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 };