ladybird/Libraries/LibWeb/CSS/StyleValues/KeywordStyleValue.h
Andreas Kling 164ed80244 Meta: Enable exit-time destructor warnings for libraries
Enable -Wexit-time-destructors for all in-tree library targets and
update process-lifetime library statics so they no longer register
exit-time destructors. Long-lived caches, lookup tables, singleton
registries, and generated constants now use NeverDestroyed or leaked
references where the data is intended to live until process exit.

Update LibWeb, LibLine, and the binding generators so regenerated
sources follow the same rule instead of reintroducing destructed
statics.
2026-06-04 19:20:49 +02:00

90 lines
3.3 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2021-2026, Sam Atkins <sam@ladybird.org>
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/Keyword.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
namespace Web::CSS {
class KeywordStyleValue : public StyleValueWithDefaultOperators<KeywordStyleValue> {
public:
static ValueComparingNonnullRefPtr<KeywordStyleValue const> create(Keyword keyword)
{
switch (keyword) {
case Keyword::Inherit: {
static auto const& inherit_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Inherit)).leak_ref();
return inherit_instance;
}
case Keyword::Initial: {
static auto const& initial_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Initial)).leak_ref();
return initial_instance;
}
case Keyword::Revert: {
static auto const& revert_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Revert)).leak_ref();
return revert_instance;
}
case Keyword::RevertLayer: {
static auto const& revert_layer_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::RevertLayer)).leak_ref();
return revert_layer_instance;
}
case Keyword::Unset: {
static auto const& unset_instance = adopt_ref(*new (nothrow) KeywordStyleValue(Keyword::Unset)).leak_ref();
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<Color> to_color(ColorResolutionContext) const override;
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const&) const override;
virtual void serialize(StringBuilder&, SerializationMode) const override;
virtual Vector<Parser::ComponentValue> tokenize() const override;
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const override;
bool properties_equal(KeywordStyleValue const& other) const { return m_keyword == other.m_keyword; }
virtual bool is_computationally_independent() const override
{
if (is_css_wide_keyword())
return false;
// FIXME: Are there any other color keywords which aren't computationally independent?
if (first_is_one_of(m_keyword, Keyword::Accentcolor, Keyword::Accentcolortext))
return false;
// FIXME: Are there any other keywords which aren't computationally independent?
return true;
}
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<KeywordStyleValue const&>(*this).keyword();
return Keyword::Invalid;
}
}