2020-06-05 21:36:02 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-06-05 21:36:02 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-05 21:36:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibWeb/DOM/Document.h>
|
2020-11-22 14:53:01 +00:00
|
|
|
#include <LibWeb/Layout/FrameBox.h>
|
2023-02-25 10:04:29 +00:00
|
|
|
#include <LibWeb/Layout/Viewport.h>
|
2022-03-10 13:02:25 +00:00
|
|
|
#include <LibWeb/Painting/NestedBrowsingContextPaintable.h>
|
2020-06-05 21:36:02 +00:00
|
|
|
|
2020-11-22 14:53:01 +00:00
|
|
|
namespace Web::Layout {
|
2020-06-05 21:36:02 +00:00
|
|
|
|
2024-04-06 17:16:04 +00:00
|
|
|
JS_DEFINE_ALLOCATOR(FrameBox);
|
|
|
|
|
2024-10-26 15:42:27 +00:00
|
|
|
FrameBox::FrameBox(DOM::Document& document, DOM::Element& element, CSS::StyleProperties style)
|
2020-11-22 14:53:01 +00:00
|
|
|
: ReplacedBox(document, element, move(style))
|
2020-06-05 21:36:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-14 19:21:51 +00:00
|
|
|
FrameBox::~FrameBox() = default;
|
2020-06-05 21:36:02 +00:00
|
|
|
|
2020-11-22 14:53:01 +00:00
|
|
|
void FrameBox::prepare_for_replaced_layout()
|
2020-06-05 21:36:02 +00:00
|
|
|
{
|
|
|
|
// FIXME: Do proper error checking, etc.
|
2024-01-16 18:04:45 +00:00
|
|
|
set_natural_width(dom_node().get_attribute_value(HTML::AttributeNames::width).to_number<int>().value_or(300));
|
|
|
|
set_natural_height(dom_node().get_attribute_value(HTML::AttributeNames::height).to_number<int>().value_or(150));
|
2020-06-05 21:36:02 +00:00
|
|
|
}
|
|
|
|
|
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 10:06:40 +00:00
|
|
|
void FrameBox::did_set_content_size()
|
2020-06-05 21:36:02 +00:00
|
|
|
{
|
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 10:06:40 +00:00
|
|
|
ReplacedBox::did_set_content_size();
|
2020-06-05 21:36:02 +00:00
|
|
|
|
2024-01-20 18:41:57 +00:00
|
|
|
if (dom_node().content_navigable())
|
2024-06-03 14:53:55 +00:00
|
|
|
dom_node().content_navigable()->set_viewport_size(paintable_box()->content_size());
|
2020-06-05 21:36:02 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 11:51:49 +00:00
|
|
|
JS::GCPtr<Painting::Paintable> FrameBox::create_paintable() const
|
2022-03-10 13:02:25 +00:00
|
|
|
{
|
|
|
|
return Painting::NestedBrowsingContextPaintable::create(*this);
|
|
|
|
}
|
|
|
|
|
2020-06-05 21:36:02 +00:00
|
|
|
}
|