summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/MediaList.cpp
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-10-03 19:39:48 +0100
committerAndreas Kling <kling@serenityos.org>2021-10-05 18:51:39 +0200
commit1c829e0417ede6ae70cde68269e25afa363df48f (patch)
tree694f943f69bb77126192b06784ebe41fe57f01bc /Userland/Libraries/LibWeb/CSS/MediaList.cpp
parentf354fd72f1518b250f7e1de6f1ab8f61da557396 (diff)
downloadserenity-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.cpp17
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;
+}
+
}