mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 15:47:35 +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
52
Userland/Libraries/LibWeb/Painting/Box.cpp
Normal file
52
Userland/Libraries/LibWeb/Painting/Box.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Layout/BlockContainer.h>
|
||||
#include <LibWeb/Painting/Box.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
||||
void Box::set_offset(const Gfx::FloatPoint& offset)
|
||||
{
|
||||
if (m_offset == offset)
|
||||
return;
|
||||
m_offset = offset;
|
||||
// FIXME: This const_cast is gross.
|
||||
const_cast<Layout::Box&>(m_layout_box).did_set_rect();
|
||||
}
|
||||
|
||||
void Box::set_content_size(Gfx::FloatSize const& size)
|
||||
{
|
||||
if (m_content_size == size)
|
||||
return;
|
||||
m_content_size = size;
|
||||
// FIXME: This const_cast is gross.
|
||||
const_cast<Layout::Box&>(m_layout_box).did_set_rect();
|
||||
}
|
||||
|
||||
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];
|
||||
return fragment.offset();
|
||||
}
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
Gfx::FloatRect Box::absolute_rect() const
|
||||
{
|
||||
Gfx::FloatRect rect { effective_offset(), content_size() };
|
||||
for (auto* block = m_layout_box.containing_block(); block; block = block->containing_block())
|
||||
rect.translate_by(block->m_paint_box->effective_offset());
|
||||
return rect;
|
||||
}
|
||||
|
||||
void Box::set_containing_line_box_fragment(Optional<Layout::LineBoxFragmentCoordinate> fragment_coordinate)
|
||||
{
|
||||
m_containing_line_box_fragment = fragment_coordinate;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue