diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 08b5a3d294..1d50fd98d2 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -968,7 +968,7 @@ void Document::update_layout() if (!browsing_context()) return; - auto viewport_rect = browsing_context()->viewport_rect(); + auto viewport_rect = this->viewport_rect(); if (!m_layout_root) { Layout::TreeBuilder tree_builder; @@ -2101,10 +2101,7 @@ void Document::run_the_resize_steps() // 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().to_type(); + auto viewport_size = viewport_rect().size().to_type(); if (m_last_viewport_size == viewport_size) return; m_last_viewport_size = viewport_size; @@ -2987,6 +2984,13 @@ HTML::ListOfAvailableImages const& Document::list_of_available_images() const return *m_list_of_available_images; } +CSSPixelRect Document::viewport_rect() const +{ + if (auto* browsing_context = this->browsing_context()) + return browsing_context->viewport_rect(); + return CSSPixelRect {}; +} + JS::NonnullGCPtr Document::visual_viewport() { if (!m_visual_viewport) diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 68a5bcc4cc..14d49b9ac2 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -390,6 +390,7 @@ public: void add_media_query_list(JS::NonnullGCPtr); JS::NonnullGCPtr visual_viewport(); + [[nodiscard]] CSSPixelRect viewport_rect() const; bool has_focus() const;