mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-05 07:39:16 +00:00
54 lines
2.1 KiB
C++
54 lines
2.1 KiB
C++
/*
|
|
* Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
|
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
// https://drafts.css-houdini.org/css-typed-om-1/#csshwb
|
|
class CSSHWB final : public ColorStyleValue {
|
|
public:
|
|
static ValueComparingNonnullRefPtr<CSSHWB const> create(ValueComparingNonnullRefPtr<StyleValue const> h, ValueComparingNonnullRefPtr<StyleValue const> w, ValueComparingNonnullRefPtr<StyleValue const> b, ValueComparingRefPtr<StyleValue const> alpha = {})
|
|
{
|
|
// alpha defaults to 1
|
|
if (!alpha)
|
|
return adopt_ref(*new (nothrow) CSSHWB(move(h), move(w), move(b), NumberStyleValue::create(1)));
|
|
|
|
return adopt_ref(*new (nothrow) CSSHWB(move(h), move(w), move(b), alpha.release_nonnull()));
|
|
}
|
|
virtual ~CSSHWB() override = default;
|
|
|
|
StyleValue const& h() const { return *m_properties.h; }
|
|
StyleValue const& w() const { return *m_properties.w; }
|
|
StyleValue const& b() const { return *m_properties.b; }
|
|
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:
|
|
CSSHWB(ValueComparingNonnullRefPtr<StyleValue const> h, ValueComparingNonnullRefPtr<StyleValue const> w, ValueComparingNonnullRefPtr<StyleValue const> b, ValueComparingNonnullRefPtr<StyleValue const> alpha)
|
|
: ColorStyleValue(ColorType::HWB, ColorSyntax::Modern)
|
|
, m_properties { .h = move(h), .w = move(w), .b = move(b), .alpha = move(alpha) }
|
|
{
|
|
}
|
|
|
|
struct Properties {
|
|
ValueComparingNonnullRefPtr<StyleValue const> h;
|
|
ValueComparingNonnullRefPtr<StyleValue const> w;
|
|
ValueComparingNonnullRefPtr<StyleValue const> b;
|
|
ValueComparingNonnullRefPtr<StyleValue const> alpha;
|
|
bool operator==(Properties const&) const = default;
|
|
} m_properties;
|
|
};
|
|
|
|
}
|