mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:47:35 +00:00
LibWeb: Make Painting::Box virtual and add Painting::BoxWithLines
BlockContainer paint boxes are the only ones that have line boxes associated, so let's not waste memory on line boxes in all the other types of boxes. This also adds Layout::Box::paint_box() and the more tightly typed Layout::BlockContainer::paint_box() to get at the paint box from the corresponding layout box.
This commit is contained in:
parent
9f5cbcaad3
commit
7af03df4c3
11 changed files with 79 additions and 26 deletions
|
@ -9,6 +9,24 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
Box::Box(Layout::Box const& layout_box)
|
||||
: m_layout_box(layout_box)
|
||||
{
|
||||
}
|
||||
|
||||
Box::~Box()
|
||||
{
|
||||
}
|
||||
|
||||
BoxWithLines::BoxWithLines(Layout::BlockContainer const& layout_box)
|
||||
: Box(layout_box)
|
||||
{
|
||||
}
|
||||
|
||||
BoxWithLines::~BoxWithLines()
|
||||
{
|
||||
}
|
||||
|
||||
void Box::set_offset(const Gfx::FloatPoint& offset)
|
||||
{
|
||||
if (m_offset == offset)
|
||||
|
@ -30,7 +48,7 @@ void Box::set_content_size(Gfx::FloatSize const& size)
|
|||
Gfx::FloatPoint Box::effective_offset() const
|
||||
{
|
||||
if (m_containing_line_box_fragment.has_value()) {
|
||||
auto const& fragment = m_layout_box.containing_block()->m_paint_box->line_boxes()[m_containing_line_box_fragment->line_box_index].fragments()[m_containing_line_box_fragment->fragment_index];
|
||||
auto const& fragment = m_layout_box.containing_block()->paint_box()->line_boxes()[m_containing_line_box_fragment->line_box_index].fragments()[m_containing_line_box_fragment->fragment_index];
|
||||
return fragment.offset();
|
||||
}
|
||||
return m_offset;
|
||||
|
|
|
@ -20,10 +20,7 @@ public:
|
|||
return adopt_own(*new Box(layout_box));
|
||||
}
|
||||
|
||||
explicit Box(Layout::Box const& layout_box)
|
||||
: m_layout_box(layout_box)
|
||||
{
|
||||
}
|
||||
virtual ~Box();
|
||||
|
||||
Layout::Box const& m_layout_box;
|
||||
|
||||
|
@ -39,11 +36,6 @@ public:
|
|||
Gfx::FloatPoint m_offset;
|
||||
Gfx::FloatSize m_content_size;
|
||||
|
||||
Vector<Layout::LineBox> const& line_boxes() const { return m_line_boxes; }
|
||||
void set_line_boxes(Vector<Layout::LineBox>&& line_boxes) { m_line_boxes = move(line_boxes); }
|
||||
|
||||
Vector<Layout::LineBox> m_line_boxes;
|
||||
|
||||
// Some boxes hang off of line box fragments. (inline-block, inline-table, replaced, etc)
|
||||
Optional<Layout::LineBoxFragmentCoordinate> m_containing_line_box_fragment;
|
||||
|
||||
|
@ -112,6 +104,29 @@ public:
|
|||
void set_overflow_data(Optional<OverflowData> data) { m_overflow_data = move(data); }
|
||||
void set_containing_line_box_fragment(Optional<Layout::LineBoxFragmentCoordinate>);
|
||||
|
||||
StackingContext* stacking_context() { return m_stacking_context; }
|
||||
StackingContext const* stacking_context() const { return m_stacking_context; }
|
||||
void set_stacking_context(NonnullOwnPtr<Painting::StackingContext> context) { m_stacking_context = move(context); }
|
||||
StackingContext* enclosing_stacking_context();
|
||||
|
||||
protected:
|
||||
explicit Box(Layout::Box const&);
|
||||
|
||||
private:
|
||||
OwnPtr<Painting::StackingContext> m_stacking_context;
|
||||
};
|
||||
|
||||
class BoxWithLines : public Box {
|
||||
public:
|
||||
static NonnullOwnPtr<BoxWithLines> create(Layout::BlockContainer const& block_container)
|
||||
{
|
||||
return adopt_own(*new BoxWithLines(block_container));
|
||||
}
|
||||
virtual ~BoxWithLines() override;
|
||||
|
||||
Vector<Layout::LineBox> const& line_boxes() const { return m_line_boxes; }
|
||||
void set_line_boxes(Vector<Layout::LineBox>&& line_boxes) { m_line_boxes = move(line_boxes); }
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_fragment(Callback callback) const
|
||||
{
|
||||
|
@ -123,12 +138,10 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
StackingContext* stacking_context() { return m_stacking_context; }
|
||||
StackingContext const* stacking_context() const { return m_stacking_context; }
|
||||
void set_stacking_context(NonnullOwnPtr<Painting::StackingContext> context) { m_stacking_context = move(context); }
|
||||
StackingContext* enclosing_stacking_context();
|
||||
private:
|
||||
BoxWithLines(Layout::BlockContainer const&);
|
||||
|
||||
OwnPtr<Painting::StackingContext> m_stacking_context;
|
||||
Vector<Layout::LineBox> m_line_boxes;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue