LibWeb: Fix iframes flickering on window resize

After finishing layout, iframe layout boxes (FrameBox) get notified
about their new size by LayoutState::commit(). This information is
forwarded to the nested browsing context, where it can be used for
layout of the nested document.

The problem here was that we notified the FrameBox twice. Once when
assigning the used offset to its paintable, and once when assigning its
size. Because the offset was assigned first, we ended up telling the
FrameBox "btw, your size is 0x0". This caused us to throw away all
the layout information we had for the nested document.

We'd then say "actually, your size is 300x200" (or something) but by
then it was already too late, and we had to do a full relayout.
This caused iframes to flicker as every time their containing document
was laid out, we'd nuke the iframe layout and redo it (on a zero timer).

The fix is pleasantly simple: we didn't need to inform the nested
document of its offset in the containing document's layout anyway. Only
its size is relevant. So we can simply remove the first call, which
removes the bogus 0x0 temporary size.

Note that iframes may still flicker if they change size in the
containing document. That's a separate issue that will require more
finesse to solve. However, this fixes a very noticeable common case.
This commit is contained in:
Andreas Kling 2023-05-15 12:06:40 +02:00
parent 44049f5ad5
commit 990e7219d6
Notes: sideshowbarker 2024-07-17 08:25:15 +09:00
4 changed files with 5 additions and 6 deletions

View File

@ -38,7 +38,7 @@ public:
virtual ~Box() override;
virtual void did_set_rect() { }
virtual void did_set_content_size() { }
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;

View File

@ -28,9 +28,9 @@ void FrameBox::prepare_for_replaced_layout()
set_intrinsic_height(dom_node().attribute(HTML::AttributeNames::height).to_int().value_or(150));
}
void FrameBox::did_set_rect()
void FrameBox::did_set_content_size()
{
ReplacedBox::did_set_rect();
ReplacedBox::did_set_content_size();
VERIFY(dom_node().nested_browsing_context());
dom_node().nested_browsing_context()->set_size(paintable_box()->content_size());

View File

@ -26,7 +26,7 @@ public:
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
private:
virtual void did_set_rect() override;
virtual void did_set_content_size() override;
};
}

View File

@ -63,13 +63,12 @@ PaintableWithLines::~PaintableWithLines()
void PaintableBox::set_offset(CSSPixelPoint offset)
{
m_offset = offset;
layout_box().did_set_rect();
}
void PaintableBox::set_content_size(CSSPixelSize size)
{
m_content_size = size;
layout_box().did_set_rect();
layout_box().did_set_content_size();
}
CSSPixelPoint PaintableBox::effective_offset() const