mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 01:06:01 +03:00
LibWeb: Add a way to ask if a PercentageOr<T> value contains percentages
Values that contain percentages require special treatment in various parts of layout. Previously we had no way of peeking into calc() values to see if their expression contains one or more percentages. That's the bulk of what we're adding here.
This commit is contained in:
parent
3dd11a007f
commit
55ad9591df
Notes:
sideshowbarker
2024-07-17 11:33:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/55ad9591df
@ -77,6 +77,15 @@ public:
|
||||
bool is_percentage() const { return m_value.template has<Percentage>(); }
|
||||
bool is_calculated() const { return m_value.template has<NonnullRefPtr<CalculatedStyleValue>>(); }
|
||||
|
||||
bool contains_percentage() const
|
||||
{
|
||||
if (is_percentage())
|
||||
return true;
|
||||
if (is_calculated())
|
||||
return calculated()->contains_percentage();
|
||||
return false;
|
||||
}
|
||||
|
||||
Percentage const& percentage() const
|
||||
{
|
||||
VERIFY(is_percentage());
|
||||
|
@ -2054,4 +2054,51 @@ NonnullRefPtr<StyleValue> BorderRadiusStyleValue::absolutized(Gfx::IntRect const
|
||||
return BorderRadiusStyleValue::create(absolutized_horizontal_radius, absolutized_vertical_radius);
|
||||
}
|
||||
|
||||
bool CalculatedStyleValue::contains_percentage() const
|
||||
{
|
||||
return m_expression->contains_percentage();
|
||||
}
|
||||
|
||||
bool CalculatedStyleValue::CalcSum::contains_percentage() const
|
||||
{
|
||||
if (first_calc_product->contains_percentage())
|
||||
return true;
|
||||
for (auto& part : zero_or_more_additional_calc_products) {
|
||||
if (part.contains_percentage())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CalculatedStyleValue::CalcSumPartWithOperator::contains_percentage() const
|
||||
{
|
||||
return value->contains_percentage();
|
||||
}
|
||||
|
||||
bool CalculatedStyleValue::CalcProduct::contains_percentage() const
|
||||
{
|
||||
if (first_calc_value.contains_percentage())
|
||||
return true;
|
||||
for (auto& part : zero_or_more_additional_calc_values) {
|
||||
if (part.contains_percentage())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CalculatedStyleValue::CalcProductPartWithOperator::contains_percentage() const
|
||||
{
|
||||
return value.visit(
|
||||
[](CalcValue const& value) { return value.contains_percentage(); },
|
||||
[](CalcNumberValue const&) { return false; });
|
||||
}
|
||||
|
||||
bool CalculatedStyleValue::CalcValue::contains_percentage() const
|
||||
{
|
||||
return value.visit(
|
||||
[](Percentage const&) { return true; },
|
||||
[](NonnullOwnPtr<CalcSum> const& sum) { return sum->contains_percentage(); },
|
||||
[](auto const&) { return false; });
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -609,6 +609,7 @@ public:
|
||||
String to_string() const;
|
||||
Optional<ResolvedType> resolved_type() const;
|
||||
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
|
||||
bool contains_percentage() const;
|
||||
};
|
||||
|
||||
// This represents that: https://www.w3.org/TR/css-values-3/#calc-syntax
|
||||
@ -623,6 +624,8 @@ public:
|
||||
String to_string() const;
|
||||
Optional<ResolvedType> resolved_type() const;
|
||||
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
|
||||
|
||||
bool contains_percentage() const;
|
||||
};
|
||||
|
||||
struct CalcNumberSum {
|
||||
@ -645,6 +648,7 @@ public:
|
||||
String to_string() const;
|
||||
Optional<ResolvedType> resolved_type() const;
|
||||
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
|
||||
bool contains_percentage() const;
|
||||
};
|
||||
|
||||
struct CalcSumPartWithOperator {
|
||||
@ -658,6 +662,7 @@ public:
|
||||
String to_string() const;
|
||||
Optional<ResolvedType> resolved_type() const;
|
||||
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
|
||||
bool contains_percentage() const;
|
||||
};
|
||||
|
||||
struct CalcProductPartWithOperator {
|
||||
@ -667,6 +672,8 @@ public:
|
||||
String to_string() const;
|
||||
Optional<ResolvedType> resolved_type() const;
|
||||
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
|
||||
|
||||
bool contains_percentage() const;
|
||||
};
|
||||
|
||||
struct CalcNumberProduct {
|
||||
@ -734,6 +741,8 @@ public:
|
||||
Optional<float> resolve_number();
|
||||
Optional<i64> resolve_integer();
|
||||
|
||||
bool contains_percentage() const;
|
||||
|
||||
private:
|
||||
explicit CalculatedStyleValue(NonnullOwnPtr<CalcSum> calc_sum, ResolvedType resolved_type)
|
||||
: StyleValue(Type::Calculated)
|
||||
|
Loading…
Reference in New Issue
Block a user