1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +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:
Sam Atkins 2021-10-03 19:39:48 +01:00 committed by Andreas Kling
parent f354fd72f1
commit 1c829e0417
6 changed files with 163 additions and 1 deletions

View file

@ -53,6 +53,7 @@ public:
FlyString name;
RefPtr<StyleValue> value { nullptr };
bool evaluate(DOM::Window const&) const;
String to_string() const;
};
@ -69,12 +70,15 @@ public:
MediaFeature feature;
NonnullOwnPtrVector<MediaCondition> conditions;
bool evaluate(DOM::Window const&) const;
String to_string() const;
};
static NonnullRefPtr<MediaQuery> create_not_all();
static NonnullRefPtr<MediaQuery> create() { return adopt_ref(*new MediaQuery); }
bool matches() const { return m_matches; }
bool evaluate(DOM::Window const&);
String to_string() const;
private:
@ -84,6 +88,9 @@ private:
bool m_negated { false };
MediaType m_media_type { MediaType::All };
OwnPtr<MediaCondition> m_media_condition { nullptr };
// Cached value, updated by evaluate()
bool m_matches { false };
};
}