mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-05 15:49:15 +00:00
This reverts 0e3487b9ab
.
Back when I made that change, I thought we could make our StyleValue
classes match the typed-om definitions directly. However, they have
different requirements. Typed-om types need to be mutable and GCed,
whereas StyleValues are immutable and ideally wouldn't require a JS VM.
While I was already making such a cataclysmic change, I've moved it into
the StyleValues directory, because it *not* being there has bothered me
for a long time. 😅
54 lines
2.2 KiB
C++
54 lines
2.2 KiB
C++
/*
|
|
* Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
|
|
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
// https://drafts.css-houdini.org/css-typed-om-1/#csshsl
|
|
class CSSHSL final : public CSSColorValue {
|
|
public:
|
|
static ValueComparingNonnullRefPtr<CSSHSL const> create(ValueComparingNonnullRefPtr<StyleValue const> h, ValueComparingNonnullRefPtr<StyleValue const> s, ValueComparingNonnullRefPtr<StyleValue const> l, ValueComparingRefPtr<StyleValue const> alpha, ColorSyntax color_syntax)
|
|
{
|
|
// alpha defaults to 1
|
|
if (!alpha)
|
|
return adopt_ref(*new (nothrow) CSSHSL(move(h), move(s), move(l), NumberStyleValue::create(1), color_syntax));
|
|
|
|
return adopt_ref(*new (nothrow) CSSHSL(move(h), move(s), move(l), alpha.release_nonnull(), color_syntax));
|
|
}
|
|
virtual ~CSSHSL() override = default;
|
|
|
|
StyleValue const& h() const { return *m_properties.h; }
|
|
StyleValue const& s() const { return *m_properties.s; }
|
|
StyleValue const& l() const { return *m_properties.l; }
|
|
StyleValue const& alpha() const { return *m_properties.alpha; }
|
|
|
|
virtual Optional<Color> to_color(ColorResolutionContext color_resolution_context) const override;
|
|
|
|
virtual String to_string(SerializationMode) const override;
|
|
|
|
virtual bool equals(StyleValue const& other) const override;
|
|
|
|
private:
|
|
CSSHSL(ValueComparingNonnullRefPtr<StyleValue const> h, ValueComparingNonnullRefPtr<StyleValue const> s, ValueComparingNonnullRefPtr<StyleValue const> l, ValueComparingNonnullRefPtr<StyleValue const> alpha, ColorSyntax color_syntax)
|
|
: CSSColorValue(ColorType::HSL, color_syntax)
|
|
, m_properties { .h = move(h), .s = move(s), .l = move(l), .alpha = move(alpha) }
|
|
{
|
|
}
|
|
|
|
struct Properties {
|
|
ValueComparingNonnullRefPtr<StyleValue const> h;
|
|
ValueComparingNonnullRefPtr<StyleValue const> s;
|
|
ValueComparingNonnullRefPtr<StyleValue const> l;
|
|
ValueComparingNonnullRefPtr<StyleValue const> alpha;
|
|
bool operator==(Properties const&) const = default;
|
|
} m_properties;
|
|
};
|
|
|
|
}
|