ladybird/Libraries/LibWeb/CSS/StyleValues/CSSLightDark.h
Callum Law 6a9c8d7767 LibWeb: Don't resolve colors with unresolved components
`CSSColorValue`s which have unresolved `calc` components should be able
to be resolved. Previously we would always resolve them but with
incorrect values.

This is useful as we will now be able to now whether we should serialize
colors in their normalized form or not.

Slight regression in that we now serialize (RGB, HSL and HWB) colors
with components that rely on compute-time information as an empty
string, but that will be fixed in the next commit.
2025-07-16 13:05:33 +01:00

43 lines
1.4 KiB
C++

/*
* Copyright (c) 2025, Ladybird contributors
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
namespace Web::CSS {
// https://drafts.csswg.org/css-color-5/#funcdef-light-dark
class CSSLightDark final : public CSSColorValue {
public:
virtual ~CSSLightDark() override = default;
static ValueComparingNonnullRefPtr<CSSLightDark const> create(ValueComparingNonnullRefPtr<CSSStyleValue const> light, ValueComparingNonnullRefPtr<CSSStyleValue const> dark)
{
return AK::adopt_ref(*new (nothrow) CSSLightDark(move(light), move(dark)));
}
virtual bool equals(CSSStyleValue const&) const override;
virtual Optional<Color> to_color(Optional<Layout::NodeWithStyle const&>, CalculationResolutionContext const&) const override;
virtual String to_string(SerializationMode) const override;
private:
CSSLightDark(ValueComparingNonnullRefPtr<CSSStyleValue const> light, ValueComparingNonnullRefPtr<CSSStyleValue const> dark)
: CSSColorValue(CSSColorValue::ColorType::LightDark, ColorSyntax::Modern)
, m_properties { .light = move(light), .dark = move(dark) }
{
}
struct Properties {
ValueComparingNonnullRefPtr<CSSStyleValue const> light;
ValueComparingNonnullRefPtr<CSSStyleValue const> dark;
bool operator==(Properties const&) const = default;
};
Properties m_properties;
};
} // Web::CSS