mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:57:45 +00:00
LibWeb: Prune old paintable pointers from layout tree after relayout
When text paintables shift around in the tree due to line wrapping, we may end up in a situation where some text node does not generate a paintable (due to being all whitespace, for example), even though in the previous layout pass, it *did* generate a paintable. To prevent holding on to old paintables in such cases, we now do a pass in LayoutState::commit() where we explicitly detach all old paintables from the layout tree.
This commit is contained in:
parent
390da2985f
commit
6d7a2f5cc9
3 changed files with 48 additions and 0 deletions
|
@ -218,6 +218,14 @@ void LayoutState::commit(Box& root)
|
|||
// Only the top-level LayoutState should ever be committed.
|
||||
VERIFY(!m_parent);
|
||||
|
||||
// NOTE: In case this is a relayout of an existing tree, we start by detaching the old paint tree
|
||||
// from the layout tree. This is done to ensure that we don't end up with any old-tree pointers
|
||||
// when text paintables shift around in the tree.
|
||||
root.for_each_in_inclusive_subtree_of_type<Layout::TextNode>([&](Layout::TextNode& text_node) {
|
||||
text_node.set_paintable(nullptr);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
HashTable<Layout::TextNode*> text_nodes;
|
||||
|
||||
Vector<Painting::PaintableWithLines&> paintables_with_lines;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue