2023-03-24 15:04:24 +00:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2023-03-24 15:04:24 +00:00
|
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
2025-07-10 12:17:27 +01:00
|
|
|
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
|
2023-03-24 15:04:24 +00:00
|
|
|
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-08-14 14:06:03 +01:00
|
|
|
#include <LibWeb/CSS/Keyword.h>
|
2025-08-08 10:11:51 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
2023-03-24 15:04:24 +00:00
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
2025-08-08 10:28:41 +01:00
|
|
|
class KeywordStyleValue : public StyleValueWithDefaultOperators<KeywordStyleValue> {
|
2023-03-24 15:04:24 +00:00
|
|
|
public:
|
2025-08-08 10:28:41 +01:00
|
|
|
static ValueComparingNonnullRefPtr<KeywordStyleValue const> create(Keyword keyword)
|
2023-03-24 15:04:24 +00:00
|
|
|
{
|
2024-08-14 15:00:10 +01:00
|
|
|
switch (keyword) {
|
|
|
|
case Keyword::Inherit: {
|
2025-08-08 10:28:41 +01:00
|
|
|
static ValueComparingNonnullRefPtr<KeywordStyleValue const> const inherit_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Inherit));
|
2024-08-14 15:00:10 +01:00
|
|
|
return inherit_instance;
|
|
|
|
}
|
|
|
|
case Keyword::Initial: {
|
2025-08-08 10:28:41 +01:00
|
|
|
static ValueComparingNonnullRefPtr<KeywordStyleValue const> const initial_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Initial));
|
2024-08-14 15:00:10 +01:00
|
|
|
return initial_instance;
|
|
|
|
}
|
|
|
|
case Keyword::Revert: {
|
2025-08-08 10:28:41 +01:00
|
|
|
static ValueComparingNonnullRefPtr<KeywordStyleValue const> const revert_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Revert));
|
2024-08-14 15:00:10 +01:00
|
|
|
return revert_instance;
|
|
|
|
}
|
2024-09-11 20:13:44 +08:00
|
|
|
case Keyword::RevertLayer: {
|
2025-08-08 10:28:41 +01:00
|
|
|
static ValueComparingNonnullRefPtr<KeywordStyleValue const> const revert_layer_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::RevertLayer));
|
2024-09-11 20:13:44 +08:00
|
|
|
return revert_layer_instance;
|
|
|
|
}
|
2024-08-14 15:00:10 +01:00
|
|
|
case Keyword::Unset: {
|
2025-08-08 10:28:41 +01:00
|
|
|
static ValueComparingNonnullRefPtr<KeywordStyleValue const> const unset_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Unset));
|
2024-08-14 15:00:10 +01:00
|
|
|
return unset_instance;
|
|
|
|
}
|
|
|
|
default:
|
2025-08-08 10:28:41 +01:00
|
|
|
return adopt_ref(*new (nothrow) KeywordStyleValue(keyword));
|
2024-08-14 15:00:10 +01:00
|
|
|
}
|
2023-03-24 15:04:24 +00:00
|
|
|
}
|
2025-08-08 10:28:41 +01:00
|
|
|
virtual ~KeywordStyleValue() override = default;
|
2023-03-24 15:04:24 +00:00
|
|
|
|
2024-08-14 14:06:03 +01:00
|
|
|
Keyword keyword() const { return m_keyword; }
|
2023-03-24 15:04:24 +00:00
|
|
|
|
2024-08-14 14:06:03 +01:00
|
|
|
static bool is_color(Keyword);
|
2023-03-24 15:04:24 +00:00
|
|
|
virtual bool has_color() const override;
|
2025-07-19 11:31:07 +12:00
|
|
|
virtual Optional<Color> to_color(ColorResolutionContext) const override;
|
2024-12-07 00:59:49 +01:00
|
|
|
virtual String to_string(SerializationMode) const override;
|
2025-07-10 12:17:27 +01:00
|
|
|
virtual Vector<Parser::ComponentValue> tokenize() const override;
|
2025-08-14 12:44:03 +01:00
|
|
|
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const override;
|
2023-03-24 15:04:24 +00:00
|
|
|
|
2025-08-08 10:28:41 +01:00
|
|
|
bool properties_equal(KeywordStyleValue const& other) const { return m_keyword == other.m_keyword; }
|
2023-03-24 15:04:24 +00:00
|
|
|
|
|
|
|
private:
|
2025-08-08 10:28:41 +01:00
|
|
|
explicit KeywordStyleValue(Keyword keyword)
|
2024-08-14 11:46:56 +01:00
|
|
|
: StyleValueWithDefaultOperators(Type::Keyword)
|
2024-08-14 14:06:03 +01:00
|
|
|
, m_keyword(keyword)
|
2023-03-24 15:04:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-08-14 14:06:03 +01:00
|
|
|
Keyword m_keyword { Keyword::Invalid };
|
2023-03-24 15:04:24 +00:00
|
|
|
};
|
|
|
|
|
2025-08-08 10:11:51 +01:00
|
|
|
inline Keyword StyleValue::to_keyword() const
|
2025-01-27 21:09:12 +01:00
|
|
|
{
|
|
|
|
if (is_keyword())
|
2025-08-08 10:28:41 +01:00
|
|
|
return static_cast<KeywordStyleValue const&>(*this).keyword();
|
2025-01-27 21:09:12 +01:00
|
|
|
return Keyword::Invalid;
|
|
|
|
}
|
|
|
|
|
2023-03-24 15:04:24 +00:00
|
|
|
}
|