mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-13 11:39:43 +00:00
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:
parent
6a74b01644
commit
f518811f73
Notes:
github-actions[bot]
2024-08-15 12:59:29 +00:00
Author: https://github.com/AtkinsSJ
Commit: f518811f73
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1076
12 changed files with 38 additions and 203 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue