LibWeb: Don't lose change events on MediaQueryList internal state change

MediaQueryList will now remember if a state change occurred when
evaluating its match state. This memory can then be used by the document
later on when it's updating all queries, to ensure that we don't forget
to fire at least one change event.

This also required plumbing the system visibility state to initial
about:blank documents, since otherwise they would be stuck in "hidden"
state indefinitely and never evaluate their media queries.
This commit is contained in:
Andreas Kling 2025-02-13 14:09:39 +01:00 committed by Andreas Kling
commit c9cd795257
Notes: github-actions[bot] 2025-02-13 19:53:28 +00:00
7 changed files with 78 additions and 23 deletions

View file

@ -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<MediaQueryList*>(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()