mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
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.
This commit is contained in:
parent
f354fd72f1
commit
1c829e0417
6 changed files with 163 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -18,6 +19,7 @@ MediaQueryList::MediaQueryList(DOM::Document& document, NonnullRefPtrVector<Medi
|
|||
, m_document(document)
|
||||
, m_media(move(media))
|
||||
{
|
||||
evaluate();
|
||||
}
|
||||
|
||||
MediaQueryList::~MediaQueryList()
|
||||
|
@ -35,10 +37,23 @@ String MediaQueryList::media() const
|
|||
// https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-matches
|
||||
bool MediaQueryList::matches() const
|
||||
{
|
||||
// TODO: Implement me :^)
|
||||
for (auto& media : m_media) {
|
||||
if (media.matches())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MediaQueryList::evaluate()
|
||||
{
|
||||
bool now_matches = false;
|
||||
for (auto& media : m_media) {
|
||||
now_matches = now_matches || media.evaluate(m_document.window());
|
||||
}
|
||||
|
||||
return now_matches;
|
||||
}
|
||||
|
||||
JS::Object* MediaQueryList::create_wrapper(JS::GlobalObject& global_object)
|
||||
{
|
||||
return wrap(global_object, *this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue