/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Tobias Christiansen * Copyright (c) 2021-2025, Sam Atkins * Copyright (c) 2022-2023, MacDue * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include namespace Web::CSS { class KeywordStyleValue : public StyleValueWithDefaultOperators { public: static ValueComparingNonnullRefPtr create(Keyword keyword) { switch (keyword) { case Keyword::Inherit: { static ValueComparingNonnullRefPtr const inherit_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Inherit)); return inherit_instance; } case Keyword::Initial: { static ValueComparingNonnullRefPtr const initial_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Initial)); return initial_instance; } case Keyword::Revert: { static ValueComparingNonnullRefPtr const revert_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Revert)); return revert_instance; } case Keyword::RevertLayer: { static ValueComparingNonnullRefPtr const revert_layer_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::RevertLayer)); return revert_layer_instance; } case Keyword::Unset: { static ValueComparingNonnullRefPtr const unset_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Unset)); return unset_instance; } default: return adopt_ref(*new (nothrow) KeywordStyleValue(keyword)); } } virtual ~KeywordStyleValue() override = default; Keyword keyword() const { return m_keyword; } static bool is_color(Keyword); virtual bool has_color() const override; virtual Optional to_color(ColorResolutionContext) const override; virtual String to_string(SerializationMode) const override; virtual Vector tokenize() const override; virtual GC::Ref reify(JS::Realm&, String const& associated_property) const override; bool properties_equal(KeywordStyleValue const& other) const { return m_keyword == other.m_keyword; } private: explicit KeywordStyleValue(Keyword keyword) : StyleValueWithDefaultOperators(Type::Keyword) , m_keyword(keyword) { } Keyword m_keyword { Keyword::Invalid }; }; inline Keyword StyleValue::to_keyword() const { if (is_keyword()) return static_cast(*this).keyword(); return Keyword::Invalid; } }