ladybird/Userland/Libraries/LibWeb/Layout/Box.h
Andreas Kling 990e7219d6 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.
2023-05-15 14:08:08 +02:00

64 lines
1.7 KiB
C++

/*
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/OwnPtr.h>
#include <LibGfx/Rect.h>
#include <LibJS/Heap/Cell.h>
#include <LibWeb/Layout/Node.h>
namespace Web::Layout {
struct LineBoxFragmentCoordinate {
size_t line_box_index { 0 };
size_t fragment_index { 0 };
};
class Box : public NodeWithStyleAndBoxModelMetrics {
JS_CELL(Box, NodeWithStyleAndBoxModelMetrics);
public:
Painting::PaintableBox const* paintable_box() const;
virtual void set_needs_display() override;
bool is_body() const;
virtual Optional<CSSPixels> intrinsic_width() const { return {}; }
virtual Optional<CSSPixels> intrinsic_height() const { return {}; }
virtual Optional<float> intrinsic_aspect_ratio() const { return {}; }
bool has_intrinsic_width() const { return intrinsic_width().has_value(); }
bool has_intrinsic_height() const { return intrinsic_height().has_value(); }
bool has_intrinsic_aspect_ratio() const { return intrinsic_aspect_ratio().has_value(); }
virtual ~Box() override;
virtual void did_set_content_size() { }
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
bool is_scroll_container() const;
bool is_scrollable() const;
CSSPixelPoint scroll_offset() const { return m_scroll_offset; }
void set_scroll_offset(CSSPixelPoint);
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; }
CSSPixelPoint m_scroll_offset;
};
template<>
inline bool Node::fast_is<Box>() const { return is_box(); }
}