mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 00:29:15 +00:00
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:
parent
6fd24c2a68
commit
c9cd795257
Notes:
github-actions[bot]
2025-02-13 19:53:28 +00:00
Author: https://github.com/awesomekling
Commit: c9cd795257
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3558
Reviewed-by: https://github.com/AtkinsSJ ✅
7 changed files with 78 additions and 23 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue