diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-10-03 19:39:48 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-05 18:51:39 +0200 |
commit | 1c829e0417ede6ae70cde68269e25afa363df48f (patch) | |
tree | 694f943f69bb77126192b06784ebe41fe57f01bc /Userland/Libraries/LibWeb/CSS/MediaList.cpp | |
parent | f354fd72f1518b250f7e1de6f1ab8f61da557396 (diff) | |
download | serenity-1c829e0417ede6ae70cde68269e25afa363df48f.zip |
LibWeb: Implement MediaQuery matching :^)
Currently, `evaluate()` recalculates whether the MediaQuery matches or
not, and stores it in `m_matches`, which users can query using
`matches()`. This allows us to know when the match-state changes, which
is required to fire MediaQueryList's change event.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/MediaList.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/MediaList.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.cpp b/Userland/Libraries/LibWeb/CSS/MediaList.cpp index aa8097f256..b723800519 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaList.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaList.cpp @@ -67,4 +67,21 @@ void MediaList::delete_medium(String medium) // FIXME: If nothing was removed, then throw a NotFoundError exception. } +bool MediaList::evaluate(DOM::Window const& window) +{ + for (auto& media : m_media) + media.evaluate(window); + + return matches(); +} + +bool MediaList::matches() const +{ + for (auto& media : m_media) { + if (media.matches()) + return true; + } + return false; +} + } |