LibWeb: Use CSSKeywordValue for CSS-wide keywords

We previously had 4 single-instance StyleValues for these keywords.
CSS-Typed-OM expects them keywords to be exposed as CSSKeywordValue, so
it's simpler to treat them the same. The single-instance behaviour is
kept by having StyleValue::create() use a cached instance for each of
these.
This commit is contained in:
Sam Atkins 2024-08-14 15:00:10 +01:00 committed by Sam Atkins
commit f518811f73
Notes: github-actions[bot] 2024-08-15 12:59:29 +00:00
12 changed files with 38 additions and 203 deletions

View file

@ -15,11 +15,31 @@
namespace Web::CSS {
// https://drafts.css-houdini.org/css-typed-om-1/#csskeywordvalue
class CSSKeywordValue final : public StyleValueWithDefaultOperators<CSSKeywordValue> {
class CSSKeywordValue : public StyleValueWithDefaultOperators<CSSKeywordValue> {
public:
static ValueComparingNonnullRefPtr<CSSKeywordValue> create(Keyword keyword)
{
return adopt_ref(*new (nothrow) CSSKeywordValue(keyword));
// NOTE: We'll have to be much more careful with caching once we expose CSSKeywordValue to JS, as it's mutable.
switch (keyword) {
case Keyword::Inherit: {
static ValueComparingNonnullRefPtr<CSSKeywordValue> const inherit_instance = adopt_ref(*new (nothrow) CSSKeywordValue(Keyword::Inherit));
return inherit_instance;
}
case Keyword::Initial: {
static ValueComparingNonnullRefPtr<CSSKeywordValue> const initial_instance = adopt_ref(*new (nothrow) CSSKeywordValue(Keyword::Initial));
return initial_instance;
}
case Keyword::Revert: {
static ValueComparingNonnullRefPtr<CSSKeywordValue> const revert_instance = adopt_ref(*new (nothrow) CSSKeywordValue(Keyword::Revert));
return revert_instance;
}
case Keyword::Unset: {
static ValueComparingNonnullRefPtr<CSSKeywordValue> const unset_instance = adopt_ref(*new (nothrow) CSSKeywordValue(Keyword::Unset));
return unset_instance;
}
default:
return adopt_ref(*new (nothrow) CSSKeywordValue(keyword));
}
}
virtual ~CSSKeywordValue() override = default;