summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-10-31 17:27:35 +0000
committerLinus Groh <mail@linusgroh.de>2021-10-31 18:39:13 +0100
commitc8550da9c54d819b8c436a7fd69685415e0a1f5f (patch)
tree667441d35be231567dcceda14bdc347af0cdef05 /Userland/Libraries
parent079d9e2e0b28c32bd3c33a475a1b23166953c7c3 (diff)
downloadserenity-c8550da9c54d819b8c436a7fd69685415e0a1f5f.zip
LibWeb: Add Web::CSS::PreferredColorScheme enum
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibWeb/CSS/PreferredColorScheme.cpp33
-rw-r--r--Userland/Libraries/LibWeb/CSS/PreferredColorScheme.h23
3 files changed, 57 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 7683b1f884..e48b7a7ed9 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -36,6 +36,7 @@ set(SOURCES
CSS/Parser/StyleRules.cpp
CSS/Parser/Token.cpp
CSS/Parser/Tokenizer.cpp
+ CSS/PreferredColorScheme.cpp
CSS/PropertyID.cpp
CSS/PropertyID.h
CSS/QuirksModeStyleSheetSource.cpp
diff --git a/Userland/Libraries/LibWeb/CSS/PreferredColorScheme.cpp b/Userland/Libraries/LibWeb/CSS/PreferredColorScheme.cpp
new file mode 100644
index 0000000000..50e4c65da4
--- /dev/null
+++ b/Userland/Libraries/LibWeb/CSS/PreferredColorScheme.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/CSS/PreferredColorScheme.h>
+
+namespace Web::CSS {
+
+PreferredColorScheme preferred_color_scheme_from_string(String const& value)
+{
+ if (value.equals_ignoring_case("light"))
+ return PreferredColorScheme::Light;
+ if (value.equals_ignoring_case("dark"))
+ return PreferredColorScheme::Dark;
+ return PreferredColorScheme::Auto;
+}
+
+StringView preferred_color_scheme_to_string(PreferredColorScheme value)
+{
+ switch (value) {
+ case PreferredColorScheme::Light:
+ return "light"sv;
+ case PreferredColorScheme::Dark:
+ return "dark"sv;
+ case PreferredColorScheme::Auto:
+ return "auto"sv;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/CSS/PreferredColorScheme.h b/Userland/Libraries/LibWeb/CSS/PreferredColorScheme.h
new file mode 100644
index 0000000000..aa975ed727
--- /dev/null
+++ b/Userland/Libraries/LibWeb/CSS/PreferredColorScheme.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/String.h>
+#include <AK/StringView.h>
+
+namespace Web::CSS {
+
+enum class PreferredColorScheme {
+ Auto,
+ Dark,
+ Light,
+};
+
+PreferredColorScheme preferred_color_scheme_from_string(String const&);
+StringView preferred_color_scheme_to_string(PreferredColorScheme);
+
+}