LibWeb: Let HTML::EventLoop drive the firing of resize
events
This commit is contained in:
parent
81ef2b646e
commit
6e341cd696
Notes:
sideshowbarker
2024-07-18 04:38:32 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6e341cd6962
4 changed files with 38 additions and 11 deletions
|
@ -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 doc’s 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 element’s 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -153,7 +153,10 @@ void EventLoop::process()
|
|||
|
||||
// FIXME: 6. For each fully active Document in docs, flush autofocus candidates for that Document if its browsing context is a top-level browsing context.
|
||||
|
||||
// FIXME: 7. For each fully active Document in docs, run the resize steps for that Document, passing in now as the timestamp. [CSSOMVIEW]
|
||||
// 7. For each fully active Document in docs, run the resize steps for that Document, passing in now as the timestamp. [CSSOMVIEW]
|
||||
for_each_fully_active_document_in_docs([&](DOM::Document& document) {
|
||||
document.run_the_resize_steps();
|
||||
});
|
||||
|
||||
// FIXME: 8. For each fully active Document in docs, run the scroll steps for that Document, passing in now as the timestamp. [CSSOMVIEW]
|
||||
|
||||
|
|
|
@ -5,16 +5,15 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/HTMLCollection.h>
|
||||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
||||
#include <LibWeb/Layout/BreakNode.h>
|
||||
#include <LibWeb/Layout/InitialContainingBlock.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
#include <LibWeb/Page/BrowsingContext.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWeb/UIEvents/EventNames.h>
|
||||
|
||||
namespace Web {
|
||||
|
||||
|
@ -83,10 +82,6 @@ void BrowsingContext::set_viewport_rect(Gfx::IntRect const& rect)
|
|||
|
||||
if (m_size != rect.size()) {
|
||||
m_size = rect.size();
|
||||
if (active_document()) {
|
||||
active_document()->window().dispatch_event(DOM::Event::create(UIEvents::EventNames::resize));
|
||||
active_document()->update_layout();
|
||||
}
|
||||
did_change = true;
|
||||
}
|
||||
|
||||
|
@ -99,6 +94,9 @@ void BrowsingContext::set_viewport_rect(Gfx::IntRect const& rect)
|
|||
for (auto* client : m_viewport_clients)
|
||||
client->browsing_context_did_set_viewport_rect(rect);
|
||||
}
|
||||
|
||||
// Schedule the HTML event loop to ensure that a `resize` event gets fired.
|
||||
HTML::main_thread_event_loop().schedule();
|
||||
}
|
||||
|
||||
void BrowsingContext::set_size(Gfx::IntSize const& size)
|
||||
|
@ -106,13 +104,12 @@ void BrowsingContext::set_size(Gfx::IntSize const& size)
|
|||
if (m_size == size)
|
||||
return;
|
||||
m_size = size;
|
||||
if (active_document()) {
|
||||
active_document()->window().dispatch_event(DOM::Event::create(UIEvents::EventNames::resize));
|
||||
active_document()->update_layout();
|
||||
}
|
||||
|
||||
for (auto* client : m_viewport_clients)
|
||||
client->browsing_context_did_set_viewport_rect(viewport_rect());
|
||||
|
||||
// Schedule the HTML event loop to ensure that a `resize` event gets fired.
|
||||
HTML::main_thread_event_loop().schedule();
|
||||
}
|
||||
|
||||
void BrowsingContext::set_viewport_scroll_offset(Gfx::IntPoint const& offset)
|
||||
|
|
Loading…
Add table
Reference in a new issue