LibWeb/CSS: Use NumericCalculationNode for constants

Having multiple kinds of node that hold numeric values made things more
complicated than they needed to be, and we were already converting
ConstantCalculationNodes to NumericCalculationNodes in the first
simplification pass that happens at parse-time, so they didn't exist
after that.

As noted, the spec allows for other contexts to introduce their own
numeric keywords, which might be resolved later than parse-time. We'll
need a different mechanism to support those, but
ConstantCalculationNode could not have done so anyway.
This commit is contained in:
Sam Atkins 2025-02-25 16:37:10 +00:00 committed by Andreas Kling
commit f97ac33cb3
Notes: github-actions[bot] 2025-02-27 20:43:53 +00:00
6 changed files with 45 additions and 140 deletions

View file

@ -128,17 +128,6 @@ private:
// https://www.w3.org/TR/css-values-4/#calculation-tree
class CalculationNode : public RefCounted<CalculationNode> {
public:
// https://drafts.csswg.org/css-values-4/#calc-constants
// https://drafts.csswg.org/css-values-4/#calc-error-constants
enum class ConstantType {
E,
Pi,
NaN,
Infinity,
MinusInfinity,
};
static Optional<ConstantType> constant_type_from_string(StringView);
enum class Type {
Numeric,
// NOTE: Currently, any value with a `var()` or `attr()` function in it is always an
@ -162,10 +151,6 @@ public:
Abs,
Sign,
// Constant Nodes
// https://drafts.csswg.org/css-values-4/#calc-constants
Constant,
// Trigonometric functions, a sub-type of operator node
// https://drafts.csswg.org/css-values-4/#trig-funcs
Sin,
@ -260,6 +245,7 @@ private:
class NumericCalculationNode final : public CalculationNode {
public:
static NonnullRefPtr<NumericCalculationNode> create(NumericValue, CalculationContext const&);
static RefPtr<NumericCalculationNode> from_keyword(Keyword, CalculationContext const&);
~NumericCalculationNode();
virtual String to_string() const override;
@ -461,24 +447,6 @@ private:
NonnullRefPtr<CalculationNode> m_value;
};
class ConstantCalculationNode final : public CalculationNode {
public:
static NonnullRefPtr<ConstantCalculationNode> create(CalculationNode::ConstantType);
~ConstantCalculationNode();
virtual String to_string() const override;
virtual bool contains_percentage() const override { return false; }
virtual CalculatedStyleValue::CalculationResult resolve(CalculationResolutionContext const&) const override;
virtual NonnullRefPtr<CalculationNode> with_simplified_children(CalculationContext const&, CalculationResolutionContext const&) const override { return *this; }
virtual void dump(StringBuilder&, int indent) const override;
virtual bool equals(CalculationNode const&) const override;
private:
ConstantCalculationNode(ConstantType);
CalculationNode::ConstantType m_constant;
};
class SinCalculationNode final : public CalculationNode {
public:
static NonnullRefPtr<SinCalculationNode> create(NonnullRefPtr<CalculationNode>);