mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 16:58:58 +00:00
LibWeb/CSS: Add LengthOrAutoOrCalculated
It's `LengthOrCalculated` for places that want `<length> | auto`.
This commit is contained in:
parent
1a3246b560
commit
577564a1a2
Notes:
github-actions[bot]
2025-09-04 12:33:48 +00:00
Author: https://github.com/AtkinsSJ
Commit: 577564a1a2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6043
3 changed files with 36 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
|
@ -67,6 +68,30 @@ NonnullRefPtr<StyleValue const> LengthOrCalculated::create_style_value() const
|
|||
return LengthStyleValue::create(value());
|
||||
}
|
||||
|
||||
Optional<LengthOrAuto> LengthOrAutoOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_length(context).map([](auto& length) { return LengthOrAuto { length }; });
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> LengthOrAutoOrCalculated::create_style_value() const
|
||||
{
|
||||
auto const& length_or_auto = value();
|
||||
if (length_or_auto.is_auto())
|
||||
return KeywordStyleValue::create(Keyword::Auto);
|
||||
return LengthStyleValue::create(length_or_auto.length());
|
||||
}
|
||||
|
||||
bool LengthOrAutoOrCalculated::is_auto() const
|
||||
{
|
||||
return !is_calculated() && value().is_auto();
|
||||
}
|
||||
|
||||
LengthOrCalculated LengthOrAutoOrCalculated::without_auto() const
|
||||
{
|
||||
VERIFY(!is_auto());
|
||||
return value().length();
|
||||
}
|
||||
|
||||
Optional<double> NumberOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_number_deprecated(context);
|
||||
|
|
|
@ -154,6 +154,16 @@ public:
|
|||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
};
|
||||
|
||||
class LengthOrAutoOrCalculated : public CalculatedOr<LengthOrAutoOrCalculated, LengthOrAuto> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
||||
Optional<LengthOrAuto> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, CalculationResolutionContext const&) const;
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
bool is_auto() const;
|
||||
LengthOrCalculated without_auto() const;
|
||||
};
|
||||
|
||||
class NumberOrCalculated : public CalculatedOr<NumberOrCalculated, double> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
|
|
@ -311,6 +311,7 @@ class KeywordStyleValue;
|
|||
class Length;
|
||||
class LengthBox;
|
||||
class LengthOrAuto;
|
||||
class LengthOrAutoOrCalculated;
|
||||
class LengthOrCalculated;
|
||||
class LengthPercentage;
|
||||
class LengthStyleValue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue