LibWeb: Add Web::CSS::PreferredColorScheme enum

This commit is contained in:
Sam Atkins 2021-10-31 17:27:35 +00:00 committed by Linus Groh
parent 079d9e2e0b
commit c8550da9c5
Notes: sideshowbarker 2024-07-18 01:40:30 +09:00
3 changed files with 57 additions and 0 deletions

View file

@ -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

View file

@ -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();
}
}

View file

@ -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);
}