LibWeb: Don't fire resize event until document actually resizes once

The first time Document learns its viewport size, we now suppress firing
of the resize event.

This fixes an issue on multiple websites that were not expecting resize
events to fire so early in the loading process.
This commit is contained in:
Andreas Kling 2024-07-10 07:41:29 +02:00 committed by Andreas Kling
parent 0cdbcfd8b0
commit 4e7558c88b
Notes: sideshowbarker 2024-07-17 02:05:41 +09:00
4 changed files with 18 additions and 2 deletions

View file

@ -0,0 +1 @@
resize count: 0

View file

@ -0,0 +1,12 @@
<script>
var resizeCount = 0;
onresize = function() {
++resizeCount;
}
</script>
<script src="include.js"></script>
<script>
test(() => {
println("resize count: " + resizeCount);
})
</script>

View file

@ -2553,11 +2553,14 @@ void Document::run_the_resize_steps()
// fire an event named resize at the Window object associated with doc.
auto viewport_size = viewport_rect().size().to_type<int>();
bool is_initial_size = !m_last_viewport_size.has_value();
if (m_last_viewport_size == viewport_size)
return;
m_last_viewport_size = viewport_size;
window()->dispatch_event(DOM::Event::create(realm(), UIEvents::EventNames::resize));
if (!is_initial_size)
window()->dispatch_event(DOM::Event::create(realm(), UIEvents::EventNames::resize));
schedule_layout_update();
}

View file

@ -786,7 +786,7 @@ private:
bool m_page_showing { false };
// Used by run_the_resize_steps().
Gfx::IntSize m_last_viewport_size;
Optional<Gfx::IntSize> m_last_viewport_size;
HashTable<ViewportClient*> m_viewport_clients;