mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-19 02:10:26 +00:00
Registered custom properties only accept "computationally independent" values for their initial value
58 lines
1.8 KiB
C++
58 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2025, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/CSS/PercentageOr.h>
|
|
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
class FitContentStyleValue final : public StyleValue {
|
|
public:
|
|
static ValueComparingNonnullRefPtr<FitContentStyleValue const> create()
|
|
{
|
|
return adopt_ref(*new (nothrow) FitContentStyleValue());
|
|
}
|
|
static ValueComparingNonnullRefPtr<FitContentStyleValue const> create(LengthPercentage length_percentage)
|
|
{
|
|
return adopt_ref(*new (nothrow) FitContentStyleValue(move(length_percentage)));
|
|
}
|
|
virtual ~FitContentStyleValue() override = default;
|
|
|
|
virtual void serialize(StringBuilder& builder, SerializationMode mode) const override
|
|
{
|
|
if (!m_length_percentage.has_value()) {
|
|
builder.append("fit-content"sv);
|
|
return;
|
|
}
|
|
builder.append("fit-content("sv);
|
|
m_length_percentage->serialize(builder, mode);
|
|
builder.append(')');
|
|
}
|
|
|
|
bool equals(StyleValue const& other) const override
|
|
{
|
|
if (type() != other.type())
|
|
return false;
|
|
return m_length_percentage == other.as_fit_content().m_length_percentage;
|
|
}
|
|
|
|
virtual bool is_computationally_independent() const override { return !m_length_percentage.has_value() || m_length_percentage->is_computationally_independent(); }
|
|
|
|
[[nodiscard]] Optional<LengthPercentage> const& length_percentage() const { return m_length_percentage; }
|
|
|
|
private:
|
|
FitContentStyleValue(Optional<LengthPercentage> length_percentage = {})
|
|
: StyleValue(Type::FitContent)
|
|
, m_length_percentage(move(length_percentage))
|
|
{
|
|
}
|
|
|
|
Optional<LengthPercentage> m_length_percentage;
|
|
};
|
|
|
|
}
|