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:
parent
0cdbcfd8b0
commit
4e7558c88b
Notes:
sideshowbarker
2024-07-17 02:05:41 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/4e7558c88b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/547
4 changed files with 18 additions and 2 deletions
1
Tests/LibWeb/Text/expected/no-window-resize-on-load.txt
Normal file
1
Tests/LibWeb/Text/expected/no-window-resize-on-load.txt
Normal file
|
@ -0,0 +1 @@
|
|||
resize count: 0
|
12
Tests/LibWeb/Text/input/no-window-resize-on-load.html
Normal file
12
Tests/LibWeb/Text/input/no-window-resize-on-load.html
Normal 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>
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue