mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:07:35 +00:00
LibWeb: Parse css math constants
This commit is contained in:
parent
f8527e1cad
commit
ba7af82c5c
3 changed files with 124 additions and 0 deletions
|
@ -115,6 +115,16 @@ private:
|
|||
// https://www.w3.org/TR/css-values-4/#calculation-tree
|
||||
class 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,
|
||||
};
|
||||
|
||||
enum class Type {
|
||||
Numeric,
|
||||
// NOTE: Currently, any value with a `var()` or `attr()` function in it is always an
|
||||
|
@ -138,6 +148,10 @@ public:
|
|||
Abs,
|
||||
Sign,
|
||||
|
||||
// Constant Nodes
|
||||
// https://drafts.csswg.org/css-values-4/#calc-constants
|
||||
Constant,
|
||||
|
||||
// This only exists during parsing.
|
||||
Unparsed,
|
||||
};
|
||||
|
@ -354,4 +368,22 @@ private:
|
|||
NonnullOwnPtr<CalculationNode> m_value;
|
||||
};
|
||||
|
||||
class ConstantCalculationNode final : public CalculationNode {
|
||||
public:
|
||||
static ErrorOr<NonnullOwnPtr<ConstantCalculationNode>> create(CalculationNode::ConstantType);
|
||||
~ConstantCalculationNode();
|
||||
|
||||
virtual ErrorOr<String> to_string() const override;
|
||||
virtual Optional<CalculatedStyleValue::ResolvedType> resolved_type() const override;
|
||||
virtual bool contains_percentage() const override { return false; };
|
||||
virtual CalculatedStyleValue::CalculationResult resolve(Optional<Length::ResolutionContext const&> context, CalculatedStyleValue::PercentageBasis const&) const override;
|
||||
virtual ErrorOr<void> for_each_child_node(Function<ErrorOr<void>(NonnullOwnPtr<CalculationNode>&)> const&) override;
|
||||
|
||||
virtual ErrorOr<void> dump(StringBuilder&, int indent) const override;
|
||||
|
||||
private:
|
||||
ConstantCalculationNode(ConstantType);
|
||||
CalculationNode::ConstantType m_constant;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue