mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 09:18:55 +00:00
LibWeb/CSS: Introduce a LengthOrAuto type
`clip: rect()` in particular wants this for its parameters.
This commit is contained in:
parent
381d3bf4e0
commit
f663c0a72d
Notes:
github-actions[bot]
2025-09-04 12:34:08 +00:00
Author: https://github.com/AtkinsSJ
Commit: f663c0a72d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6043
2 changed files with 51 additions and 0 deletions
|
@ -251,6 +251,48 @@ private:
|
||||||
double m_value { 0 };
|
double m_value { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LengthOrAuto {
|
||||||
|
public:
|
||||||
|
LengthOrAuto(Length length)
|
||||||
|
{
|
||||||
|
if (length.is_auto())
|
||||||
|
m_length = {};
|
||||||
|
else
|
||||||
|
m_length = move(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
static LengthOrAuto make_auto() { return LengthOrAuto { OptionalNone {} }; }
|
||||||
|
|
||||||
|
bool is_length() const { return m_length.has_value(); }
|
||||||
|
bool is_auto() const { return !m_length.has_value(); }
|
||||||
|
|
||||||
|
Length const& length() const { return m_length.value(); }
|
||||||
|
|
||||||
|
String to_string(SerializationMode mode = SerializationMode::Normal) const
|
||||||
|
{
|
||||||
|
if (is_auto())
|
||||||
|
return "auto"_string;
|
||||||
|
return m_length->to_string(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
CSSPixels to_px_or_zero(Layout::Node const& node) const
|
||||||
|
{
|
||||||
|
if (is_auto())
|
||||||
|
return 0;
|
||||||
|
return m_length->to_px(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(LengthOrAuto const&) const = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit LengthOrAuto(Optional<Length> maybe_length)
|
||||||
|
: m_length(move(maybe_length))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Length> m_length;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
@ -260,3 +302,11 @@ struct AK::Formatter<Web::CSS::Length> : Formatter<StringView> {
|
||||||
return Formatter<StringView>::format(builder, length.to_string());
|
return Formatter<StringView>::format(builder, length.to_string());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct AK::Formatter<Web::CSS::LengthOrAuto> : Formatter<StringView> {
|
||||||
|
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::LengthOrAuto const& length_or_auto)
|
||||||
|
{
|
||||||
|
return Formatter<StringView>::format(builder, length_or_auto.to_string());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -310,6 +310,7 @@ class InvalidationSet;
|
||||||
class KeywordStyleValue;
|
class KeywordStyleValue;
|
||||||
class Length;
|
class Length;
|
||||||
class LengthBox;
|
class LengthBox;
|
||||||
|
class LengthOrAuto;
|
||||||
class LengthOrCalculated;
|
class LengthOrCalculated;
|
||||||
class LengthPercentage;
|
class LengthPercentage;
|
||||||
class LengthStyleValue;
|
class LengthStyleValue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue