From c8550da9c54d819b8c436a7fd69685415e0a1f5f Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Sun, 31 Oct 2021 17:27:35 +0000 Subject: LibWeb: Add Web::CSS::PreferredColorScheme enum --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../Libraries/LibWeb/CSS/PreferredColorScheme.cpp | 33 ++++++++++++++++++++++ .../Libraries/LibWeb/CSS/PreferredColorScheme.h | 23 +++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 Userland/Libraries/LibWeb/CSS/PreferredColorScheme.cpp create mode 100644 Userland/Libraries/LibWeb/CSS/PreferredColorScheme.h 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 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +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 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::CSS { + +enum class PreferredColorScheme { + Auto, + Dark, + Light, +}; + +PreferredColorScheme preferred_color_scheme_from_string(String const&); +StringView preferred_color_scheme_to_string(PreferredColorScheme); + +} -- cgit v1.2.3