diff --git a/Libraries/LibWeb/CSS/MediaQueryList.cpp b/Libraries/LibWeb/CSS/MediaQueryList.cpp index 63d4ac0e2e0..eff66cc109e 100644 --- a/Libraries/LibWeb/CSS/MediaQueryList.cpp +++ b/Libraries/LibWeb/CSS/MediaQueryList.cpp @@ -54,6 +54,14 @@ bool MediaQueryList::matches() const if (m_media.is_empty()) return true; + bool did_match = false; + for (auto const& media : m_media) { + if (media->matches()) { + did_match = true; + break; + } + } + // NOTE: If our document is inside a frame, we need to update layout // since that may cause our frame (and thus viewport) to resize. if (auto container_document = m_document->container_document()) { @@ -61,12 +69,18 @@ bool MediaQueryList::matches() const const_cast(this)->evaluate(); } + bool now_matches = false; for (auto& media : m_media) { - if (media->matches()) - return true; + if (media->matches()) { + now_matches = true; + break; + } } - return false; + if (did_match != now_matches) + m_has_changed_state = true; + + return now_matches; } bool MediaQueryList::evaluate() diff --git a/Libraries/LibWeb/CSS/MediaQueryList.h b/Libraries/LibWeb/CSS/MediaQueryList.h index 546de78e34e..f2cde1ecfd5 100644 --- a/Libraries/LibWeb/CSS/MediaQueryList.h +++ b/Libraries/LibWeb/CSS/MediaQueryList.h @@ -32,6 +32,9 @@ public: void set_onchange(WebIDL::CallbackType*); WebIDL::CallbackType* onchange(); + [[nodiscard]] Optional const& has_changed_state() const { return m_has_changed_state; } + void set_has_changed_state(bool has_changed_state) { m_has_changed_state = has_changed_state; } + private: MediaQueryList(DOM::Document&, Vector>&&); @@ -40,6 +43,8 @@ private: GC::Ref m_document; Vector> m_media; + + mutable Optional m_has_changed_state { false }; }; } diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index fdd1b6a4261..c269838b6a8 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -3293,7 +3293,10 @@ void Document::evaluate_media_queries_and_report_changes() bool did_match = media_query_list->matches(); bool now_matches = media_query_list->evaluate(); - if (did_match != now_matches) { + auto did_change_internally = media_query_list->has_changed_state(); + media_query_list->set_has_changed_state(false); + + if (did_change_internally == true || did_match != now_matches) { CSS::MediaQueryListEventInit init; init.media = media_query_list->media(); init.matches = now_matches; diff --git a/Libraries/LibWeb/HTML/NavigableContainer.cpp b/Libraries/LibWeb/HTML/NavigableContainer.cpp index faa536bc2bc..63b309ff3c8 100644 --- a/Libraries/LibWeb/HTML/NavigableContainer.cpp +++ b/Libraries/LibWeb/HTML/NavigableContainer.cpp @@ -109,6 +109,9 @@ WebIDL::ExceptionOr NavigableContainer::create_new_child_navigable(GC::Ptr // 11. Let traversable be parentNavigable's traversable navigable. auto traversable = parent_navigable->traversable_navigable(); + // AD-HOC: Let the initial about:blank document inherit the system visibility state from traversable. + document->update_the_visibility_state(traversable->system_visibility_state()); + // 12. Append the following session history traversal steps to traversable: traversable->append_session_history_traversal_steps(GC::create_function(heap(), [traversable, navigable, parent_navigable, history_entry, after_session_history_update] { // 1. Let parentDocState be parentNavigable's active session history entry's document state. diff --git a/Tests/LibWeb/Layout/expected/misc/create-iframes-using-innerhtml.txt b/Tests/LibWeb/Layout/expected/misc/create-iframes-using-innerhtml.txt index df1a8b45737..2b4731e81ab 100644 --- a/Tests/LibWeb/Layout/expected/misc/create-iframes-using-innerhtml.txt +++ b/Tests/LibWeb/Layout/expected/misc/create-iframes-using-innerhtml.txt @@ -13,16 +13,46 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline frag 7 from NavigableContainerViewport start: 0, length: 0, rect: [18,228 10x10] baseline: 30 frag 8 from NavigableContainerViewport start: 0, length: 0, rect: [18,258 10x10] baseline: 30 frag 9 from NavigableContainerViewport start: 0, length: 0, rect: [18,288 10x10] baseline: 30 - NavigableContainerViewport