1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:47:35 +00:00

LibWeb: Let HTML::EventLoop drive the firing of resize events

This commit is contained in:
Andreas Kling 2021-10-03 16:42:03 +02:00
parent 81ef2b646e
commit 6e341cd696
4 changed files with 38 additions and 11 deletions

View file

@ -57,6 +57,7 @@
#include <LibWeb/Page/BrowsingContext.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/SVG/TagNames.h>
#include <LibWeb/UIEvents/EventNames.h>
#include <LibWeb/UIEvents/KeyboardEvent.h>
#include <LibWeb/UIEvents/MouseEvent.h>
@ -1083,4 +1084,25 @@ String Document::visibility_state() const
return hidden() ? "hidden" : "visible";
}
// https://drafts.csswg.org/cssom-view/#run-the-resize-steps
void Document::run_the_resize_steps()
{
// 1. If docs viewport has had its width or height changed
// (e.g. as a result of the user resizing the browser window, or changing the page zoom scale factor,
// or an iframe elements dimensions are changed) since the last time these steps were run,
// fire an event named resize at the Window object associated with doc.
if (!browsing_context())
return;
auto viewport_size = browsing_context()->viewport_rect().size();
if (m_last_viewport_size == viewport_size)
return;
m_last_viewport_size = viewport_size;
dispatch_event(DOM::Event::create(UIEvents::EventNames::resize));
update_layout();
}
}

View file

@ -301,6 +301,8 @@ public:
bool hidden() const;
String visibility_state() const;
void run_the_resize_steps();
private:
explicit Document(const AK::URL&);
@ -388,6 +390,9 @@ private:
// https://html.spec.whatwg.org/#page-showing
bool m_page_showing { false };
// Used by run_the_resize_steps().
Gfx::IntSize m_last_viewport_size;
};
}