LibWeb/CSS: Make all children of CSSLabLike share the create()
method
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
Small code deduplication. NFC.
This commit is contained in:
parent
9b44a99617
commit
15121d63ad
Notes:
github-actions[bot]
2024-10-28 19:36:47 +00:00
Author: https://github.com/LucasChollet Commit: https://github.com/LadybirdBrowser/ladybird/commit/15121d63ade Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2001
2 changed files with 14 additions and 24 deletions
|
@ -3310,7 +3310,7 @@ RefPtr<CSSStyleValue> Parser::parse_lab_color_value(TokenStream<ComponentValue>&
|
|||
|
||||
auto& color_values = *maybe_color_values;
|
||||
|
||||
return CSSLab::create(color_values[0].release_nonnull(),
|
||||
return CSSLabLike::create<CSSLab>(color_values[0].release_nonnull(),
|
||||
color_values[1].release_nonnull(),
|
||||
color_values[2].release_nonnull(),
|
||||
color_values[3].release_nonnull());
|
||||
|
@ -3330,7 +3330,7 @@ RefPtr<CSSStyleValue> Parser::parse_oklab_color_value(TokenStream<ComponentValue
|
|||
|
||||
auto& color_values = *maybe_color_values;
|
||||
|
||||
return CSSOKLab::create(color_values[0].release_nonnull(),
|
||||
return CSSLabLike::create<CSSOKLab>(color_values[0].release_nonnull(),
|
||||
color_values[1].release_nonnull(),
|
||||
color_values[2].release_nonnull(),
|
||||
color_values[3].release_nonnull());
|
||||
|
|
|
@ -13,6 +13,16 @@ namespace Web::CSS {
|
|||
|
||||
class CSSLabLike : public CSSColorValue {
|
||||
public:
|
||||
template<typename T>
|
||||
static ValueComparingNonnullRefPtr<T> create(ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingRefPtr<CSSStyleValue> alpha = {})
|
||||
{
|
||||
// alpha defaults to 1
|
||||
if (!alpha)
|
||||
alpha = NumberStyleValue::create(1);
|
||||
|
||||
return adopt_ref(*new (nothrow) T({}, move(l), move(a), move(b), alpha.release_nonnull()));
|
||||
}
|
||||
|
||||
virtual ~CSSLabLike() override = default;
|
||||
|
||||
CSSStyleValue const& l() const { return *m_properties.l; }
|
||||
|
@ -41,20 +51,10 @@ protected:
|
|||
// https://drafts.css-houdini.org/css-typed-om-1/#cssoklab
|
||||
class CSSOKLab final : public CSSLabLike {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<CSSOKLab> create(ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingRefPtr<CSSStyleValue> alpha = {})
|
||||
{
|
||||
// alpha defaults to 1
|
||||
if (!alpha)
|
||||
return adopt_ref(*new (nothrow) CSSOKLab(move(l), move(a), move(b), NumberStyleValue::create(1)));
|
||||
|
||||
return adopt_ref(*new (nothrow) CSSOKLab(move(l), move(a), move(b), alpha.release_nonnull()));
|
||||
}
|
||||
|
||||
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const override;
|
||||
virtual String to_string() const override;
|
||||
|
||||
private:
|
||||
CSSOKLab(ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingNonnullRefPtr<CSSStyleValue> alpha)
|
||||
CSSOKLab(Badge<CSSLabLike>, ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingNonnullRefPtr<CSSStyleValue> alpha)
|
||||
: CSSLabLike(ColorType::OKLab, move(l), move(a), move(b), move(alpha))
|
||||
{
|
||||
}
|
||||
|
@ -63,20 +63,10 @@ private:
|
|||
// https://drafts.css-houdini.org/css-typed-om-1/#csslab
|
||||
class CSSLab final : public CSSLabLike {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<CSSLab> create(ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingRefPtr<CSSStyleValue> alpha = {})
|
||||
{
|
||||
// alpha defaults to 1
|
||||
if (!alpha)
|
||||
return adopt_ref(*new (nothrow) CSSLab(move(l), move(a), move(b), NumberStyleValue::create(1)));
|
||||
|
||||
return adopt_ref(*new (nothrow) CSSLab(move(l), move(a), move(b), alpha.release_nonnull()));
|
||||
}
|
||||
|
||||
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const override;
|
||||
virtual String to_string() const override;
|
||||
|
||||
private:
|
||||
CSSLab(ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingNonnullRefPtr<CSSStyleValue> alpha)
|
||||
CSSLab(Badge<CSSLabLike>, ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingNonnullRefPtr<CSSStyleValue> alpha)
|
||||
: CSSLabLike(ColorType::Lab, move(l), move(a), move(b), move(alpha))
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue