mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:07:34 +00:00
LibWeb: Add Painting::Box and move things from Layout::Box into it
The "paintable" state in Layout::Box was actually not safe to access until after layout had been performed. As a first step towards making this harder to mess up accidentally, this patch moves painting information from Layout::Box to a new class: Painting::Box. Every layout can have a corresponding paint box, and it holds the final used metrics determined by layout. The paint box is created and populated by FormattingState::commit(). I've also added DOM::Node::paint_box() as a convenient way to access the paint box (if available) of a given DOM node. Going forward, I believe this will allow us to better separate data that belongs to layout vs painting, and also open up opportunities for naturally invalidating caches in the paint box (since it's reconstituted by every layout.)
This commit is contained in:
parent
db404af6df
commit
a4d51b3dc2
35 changed files with 365 additions and 293 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -21,64 +21,7 @@ struct LineBoxFragmentCoordinate {
|
|||
|
||||
class Box : public NodeWithStyleAndBoxModelMetrics {
|
||||
public:
|
||||
struct OverflowData {
|
||||
Gfx::FloatRect scrollable_overflow_rect;
|
||||
Gfx::FloatPoint scroll_offset;
|
||||
};
|
||||
|
||||
const Gfx::FloatRect absolute_rect() const;
|
||||
|
||||
Gfx::FloatPoint effective_offset() const;
|
||||
|
||||
void set_offset(const Gfx::FloatPoint& offset);
|
||||
void set_offset(float x, float y) { set_offset({ x, y }); }
|
||||
|
||||
Gfx::FloatSize const& content_size() const { return m_content_size; }
|
||||
void set_content_size(Gfx::FloatSize const&);
|
||||
void set_content_size(float width, float height) { set_content_size({ width, height }); }
|
||||
|
||||
void set_content_width(float width) { set_content_size(width, content_height()); }
|
||||
void set_content_height(float height) { set_content_size(content_width(), height); }
|
||||
float content_width() const { return m_content_size.width(); }
|
||||
float content_height() const { return m_content_size.height(); }
|
||||
|
||||
Gfx::FloatRect absolute_padding_box_rect() const
|
||||
{
|
||||
auto absolute_rect = this->absolute_rect();
|
||||
Gfx::FloatRect rect;
|
||||
rect.set_x(absolute_rect.x() - box_model().padding.left);
|
||||
rect.set_width(content_width() + box_model().padding.left + box_model().padding.right);
|
||||
rect.set_y(absolute_rect.y() - box_model().padding.top);
|
||||
rect.set_height(content_height() + box_model().padding.top + box_model().padding.bottom);
|
||||
return rect;
|
||||
}
|
||||
|
||||
Gfx::FloatRect absolute_border_box_rect() const
|
||||
{
|
||||
auto padded_rect = this->absolute_padding_box_rect();
|
||||
Gfx::FloatRect rect;
|
||||
rect.set_x(padded_rect.x() - box_model().border.left);
|
||||
rect.set_width(padded_rect.width() + box_model().border.left + box_model().border.right);
|
||||
rect.set_y(padded_rect.y() - box_model().border.top);
|
||||
rect.set_height(padded_rect.height() + box_model().border.top + box_model().border.bottom);
|
||||
return rect;
|
||||
}
|
||||
|
||||
float border_box_width() const
|
||||
{
|
||||
auto border_box = box_model().border_box();
|
||||
return content_width() + border_box.left + border_box.right;
|
||||
}
|
||||
|
||||
float border_box_height() const
|
||||
{
|
||||
auto border_box = box_model().border_box();
|
||||
return content_height() + border_box.top + border_box.bottom;
|
||||
}
|
||||
|
||||
float absolute_x() const { return absolute_rect().x(); }
|
||||
float absolute_y() const { return absolute_rect().y(); }
|
||||
Gfx::FloatPoint absolute_position() const { return absolute_rect().location(); }
|
||||
OwnPtr<Painting::Box> m_paint_box;
|
||||
|
||||
bool is_out_of_flow(FormattingContext const&) const;
|
||||
|
||||
|
@ -87,8 +30,6 @@ public:
|
|||
|
||||
bool is_body() const;
|
||||
|
||||
void set_containing_line_box_fragment(Optional<LineBoxFragmentCoordinate>);
|
||||
|
||||
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); }
|
||||
|
@ -109,45 +50,21 @@ public:
|
|||
bool has_intrinsic_height() const { return intrinsic_height().has_value(); }
|
||||
bool has_intrinsic_aspect_ratio() const { return intrinsic_aspect_ratio().has_value(); }
|
||||
|
||||
bool has_overflow() const { return m_overflow_data.has_value(); }
|
||||
|
||||
Optional<Gfx::FloatRect> scrollable_overflow_rect() const
|
||||
{
|
||||
if (!m_overflow_data.has_value())
|
||||
return {};
|
||||
return m_overflow_data->scrollable_overflow_rect;
|
||||
}
|
||||
|
||||
void set_overflow_data(Optional<OverflowData> data) { m_overflow_data = move(data); }
|
||||
|
||||
virtual void before_children_paint(PaintContext&, PaintPhase) override;
|
||||
virtual void after_children_paint(PaintContext&, PaintPhase) override;
|
||||
|
||||
protected:
|
||||
Box(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
|
||||
: NodeWithStyleAndBoxModelMetrics(document, node, move(style))
|
||||
{
|
||||
}
|
||||
|
||||
Box(DOM::Document& document, DOM::Node* node, CSS::ComputedValues computed_values)
|
||||
: NodeWithStyleAndBoxModelMetrics(document, node, move(computed_values))
|
||||
{
|
||||
}
|
||||
virtual ~Box() override;
|
||||
|
||||
virtual void did_set_rect() { }
|
||||
|
||||
protected:
|
||||
Box(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
|
||||
Box(DOM::Document&, DOM::Node*, CSS::ComputedValues);
|
||||
|
||||
private:
|
||||
virtual bool is_box() const final { return true; }
|
||||
|
||||
Gfx::FloatPoint m_offset;
|
||||
Gfx::FloatSize m_content_size;
|
||||
|
||||
// Some boxes hang off of line box fragments. (inline-block, inline-table, replaced, etc)
|
||||
Optional<LineBoxFragmentCoordinate> m_containing_line_box_fragment;
|
||||
|
||||
OwnPtr<StackingContext> m_stacking_context;
|
||||
|
||||
Optional<OverflowData> m_overflow_data;
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue