1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:27:45 +00:00

LibWeb: Use a Variant for calc() percentage_basis

Depending on the type of the calc() expression, the percentage_basis has
to be the same dimension type. Several places were already passing `
{}` for this, so let's make that an empty Variant instead of an
undefined Length. :^)
This commit is contained in:
Sam Atkins 2022-02-18 12:07:09 +00:00 committed by Andreas Kling
parent 8aa1c7f5b0
commit 1093d6e2c3
2 changed files with 30 additions and 28 deletions

View file

@ -691,21 +691,23 @@ public:
float value;
};
using PercentageBasis = Variant<Empty, Length>;
class CalculationResult {
public:
CalculationResult(Variant<Number, Length, Percentage> value)
: m_value(move(value))
{
}
void add(CalculationResult const& other, Layout::Node const*, Length const& percentage_basis);
void subtract(CalculationResult const& other, Layout::Node const*, Length const& percentage_basis);
void add(CalculationResult const& other, Layout::Node const*, PercentageBasis const& percentage_basis);
void subtract(CalculationResult const& other, Layout::Node const*, PercentageBasis const& percentage_basis);
void multiply_by(CalculationResult const& other, Layout::Node const*);
void divide_by(CalculationResult const& other, Layout::Node const*);
Variant<Number, Length, Percentage> const& value() const { return m_value; }
private:
void add_or_subtract_internal(SumOperation op, CalculationResult const& other, Layout::Node const*, Length const& percentage_basis);
void add_or_subtract_internal(SumOperation op, CalculationResult const& other, Layout::Node const*, PercentageBasis const& percentage_basis);
Variant<Number, Length, Percentage> m_value;
};
@ -722,14 +724,14 @@ public:
Variant<Number, NonnullOwnPtr<CalcNumberSum>> value;
String to_string() const;
Optional<ResolvedType> resolved_type() const;
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
};
struct CalcValue {
Variant<Number, Length, Percentage, NonnullOwnPtr<CalcSum>> value;
String to_string() const;
Optional<ResolvedType> resolved_type() const;
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
};
// This represents that: https://www.w3.org/TR/css-values-3/#calc-syntax
@ -743,7 +745,7 @@ public:
String to_string() const;
Optional<ResolvedType> resolved_type() const;
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
};
struct CalcNumberSum {
@ -756,7 +758,7 @@ public:
String to_string() const;
Optional<ResolvedType> resolved_type() const;
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
};
struct CalcProduct {
@ -765,7 +767,7 @@ public:
String to_string() const;
Optional<ResolvedType> resolved_type() const;
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
};
struct CalcSumPartWithOperator {
@ -778,7 +780,7 @@ public:
String to_string() const;
Optional<ResolvedType> resolved_type() const;
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
};
struct CalcProductPartWithOperator {
@ -787,7 +789,7 @@ public:
String to_string() const;
Optional<ResolvedType> resolved_type() const;
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
};
struct CalcNumberProduct {
@ -796,7 +798,7 @@ public:
String to_string() const;
Optional<ResolvedType> resolved_type() const;
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
};
struct CalcNumberProductPartWithOperator {
@ -805,7 +807,7 @@ public:
String to_string() const;
Optional<ResolvedType> resolved_type() const;
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
};
struct CalcNumberSumPartWithOperator {
@ -818,7 +820,7 @@ public:
String to_string() const;
Optional<ResolvedType> resolved_type() const;
CalculationResult resolve(Layout::Node const*, Length const& percentage_basis) const;
CalculationResult resolve(Layout::Node const*, PercentageBasis const& percentage_basis) const;
};
static NonnullRefPtr<CalculatedStyleValue> create(NonnullOwnPtr<CalcSum> calc_sum, ResolvedType resolved_type)