diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-12-30 14:25:30 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-02 15:43:51 +0100 |
commit | b6fe7cc324ed625dbc879d5bdca730405464ca89 (patch) | |
tree | bab47b19d92d0d6cbde204755c45c6a3a1b0e37c /Userland/Libraries/LibWeb/CSS/MediaQuery.cpp | |
parent | ae4f0000c8e7dcfc20a8f186b547a30b005b8904 (diff) | |
download | serenity-b6fe7cc324ed625dbc879d5bdca730405464ca89.zip |
LibWeb: Make MediaCondition a top-level type and add factory methods
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/MediaQuery.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/MediaQuery.cpp | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp index 53e286adcd..c45a238ef4 100644 --- a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp +++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp @@ -139,7 +139,52 @@ bool MediaFeature::evaluate(DOM::Window const& window) const VERIFY_NOT_REACHED(); } -String MediaQuery::MediaCondition::to_string() const +NonnullOwnPtr<MediaCondition> MediaCondition::from_general_enclosed(GeneralEnclosed&& general_enclosed) +{ + auto result = new MediaCondition; + result->type = Type::GeneralEnclosed; + result->general_enclosed = move(general_enclosed); + + return adopt_own(*result); +} + +NonnullOwnPtr<MediaCondition> MediaCondition::from_feature(MediaFeature&& feature) +{ + auto result = new MediaCondition; + result->type = Type::Single; + result->feature = move(feature); + + return adopt_own(*result); +} + +NonnullOwnPtr<MediaCondition> MediaCondition::from_not(NonnullOwnPtr<MediaCondition>&& condition) +{ + auto result = new MediaCondition; + result->type = Type::Not; + result->conditions.append(move(condition)); + + return adopt_own(*result); +} + +NonnullOwnPtr<MediaCondition> MediaCondition::from_and_list(NonnullOwnPtrVector<MediaCondition>&& conditions) +{ + auto result = new MediaCondition; + result->type = Type::And; + result->conditions = move(conditions); + + return adopt_own(*result); +} + +NonnullOwnPtr<MediaCondition> MediaCondition::from_or_list(NonnullOwnPtrVector<MediaCondition>&& conditions) +{ + auto result = new MediaCondition; + result->type = Type::Or; + result->conditions = move(conditions); + + return adopt_own(*result); +} + +String MediaCondition::to_string() const { StringBuilder builder; builder.append('('); @@ -165,7 +210,7 @@ String MediaQuery::MediaCondition::to_string() const return builder.to_string(); } -MatchResult MediaQuery::MediaCondition::evaluate(DOM::Window const& window) const +MatchResult MediaCondition::evaluate(DOM::Window const& window) const { switch (type) { case Type::Single: |