summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/MediaQuery.h
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-12-30 14:25:30 +0000
committerAndreas Kling <kling@serenityos.org>2022-01-02 15:43:51 +0100
commitb6fe7cc324ed625dbc879d5bdca730405464ca89 (patch)
treebab47b19d92d0d6cbde204755c45c6a3a1b0e37c /Userland/Libraries/LibWeb/CSS/MediaQuery.h
parentae4f0000c8e7dcfc20a8f186b547a30b005b8904 (diff)
downloadserenity-b6fe7cc324ed625dbc879d5bdca730405464ca89.zip
LibWeb: Make MediaCondition a top-level type and add factory methods
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/MediaQuery.h')
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaQuery.h50
1 files changed, 29 insertions, 21 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.h b/Userland/Libraries/LibWeb/CSS/MediaQuery.h
index 14e7b92b77..b6eef1fdfb 100644
--- a/Userland/Libraries/LibWeb/CSS/MediaQuery.h
+++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.h
@@ -112,6 +112,33 @@ private:
Optional<MediaFeatureValue> m_value {};
};
+// https://www.w3.org/TR/mediaqueries-4/#media-conditions
+struct MediaCondition {
+ enum class Type {
+ Single,
+ And,
+ Or,
+ Not,
+ GeneralEnclosed,
+ };
+
+ static NonnullOwnPtr<MediaCondition> from_general_enclosed(GeneralEnclosed&&);
+ static NonnullOwnPtr<MediaCondition> from_feature(MediaFeature&&);
+ static NonnullOwnPtr<MediaCondition> from_not(NonnullOwnPtr<MediaCondition>&&);
+ static NonnullOwnPtr<MediaCondition> from_and_list(NonnullOwnPtrVector<MediaCondition>&&);
+ static NonnullOwnPtr<MediaCondition> from_or_list(NonnullOwnPtrVector<MediaCondition>&&);
+
+ MatchResult evaluate(DOM::Window const&) const;
+ String to_string() const;
+
+private:
+ MediaCondition() { }
+ Type type;
+ Optional<MediaFeature> feature;
+ NonnullOwnPtrVector<MediaCondition> conditions;
+ Optional<GeneralEnclosed> general_enclosed;
+};
+
class MediaQuery : public RefCounted<MediaQuery> {
friend class Parser;
@@ -135,25 +162,6 @@ public:
Speech,
};
- // https://www.w3.org/TR/mediaqueries-4/#media-conditions
- struct MediaCondition {
- enum class Type {
- Single,
- And,
- Or,
- Not,
- GeneralEnclosed,
- };
-
- Type type;
- Optional<MediaFeature> feature;
- NonnullOwnPtrVector<MediaCondition> conditions;
- Optional<GeneralEnclosed> general_enclosed;
-
- MatchResult evaluate(DOM::Window const&) const;
- String to_string() const;
- };
-
static NonnullRefPtr<MediaQuery> create_not_all();
static NonnullRefPtr<MediaQuery> create() { return adopt_ref(*new MediaQuery); }
@@ -188,8 +196,8 @@ struct Formatter<Web::CSS::MediaFeature> : Formatter<StringView> {
};
template<>
-struct Formatter<Web::CSS::MediaQuery::MediaCondition> : Formatter<StringView> {
- ErrorOr<void> format(FormatBuilder& builder, Web::CSS::MediaQuery::MediaCondition const& media_condition)
+struct Formatter<Web::CSS::MediaCondition> : Formatter<StringView> {
+ ErrorOr<void> format(FormatBuilder& builder, Web::CSS::MediaCondition const& media_condition)
{
return Formatter<StringView>::format(builder, media_condition.to_string());
}