ladybird/Libraries/LibWeb/CSS/StyleValues/TreeCountingFunctionStyleValue.h
Callum Law 831e471444 LibWeb: Support top-level tree counting functions
Adds support for `sibling-index()` and `sibling-count()` when parsing
`<number>` and `<integer>`. This is achieved by a new
`TreeCountingFunctionStyleValue` class which is converted within
`absolutized` to `NumberStyleValue` and `IntegerStyleValue` respectively

There are still a few kinks to work out in order to support these
everywhere, namely:
 - There are some `StyleValue`s which aren't absolutized (i.e. those
   which are stored within another `StyleValue` without an
   `absolutize()` method.
 - We don't have a way to represent this new `StyleValue` within
   `{Number,Integer}OrCalculated`. This would be fixed if we were to
   instead just use the `StyleValue` classes until style computation at
   which time they would be absolutized into their respective
   primitives (double, i64, etc) bypassing the need for *OrCalculated
   entirely.
2025-10-20 16:12:08 +01:00

51 lines
1.4 KiB
C++

/*
* Copyright (c) 2025, Callum Law <callumlaw1709@outlook.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/StyleValues/StyleValue.h>
namespace Web::CSS {
class TreeCountingFunctionStyleValue final : public StyleValue {
public:
enum class TreeCountingFunction : u8 {
SiblingCount,
SiblingIndex
};
enum class ComputedType : u8 {
Number,
Integer
};
static ValueComparingNonnullRefPtr<TreeCountingFunctionStyleValue const> create(TreeCountingFunction function, ComputedType computed_type)
{
return adopt_ref(*new (nothrow) TreeCountingFunctionStyleValue(function, computed_type));
}
virtual ~TreeCountingFunctionStyleValue() override = default;
virtual String to_string(SerializationMode) const override;
size_t resolve(TreeCountingFunctionResolutionContext const&) const;
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const&) const override;
virtual bool equals(StyleValue const& other) const override;
private:
TreeCountingFunctionStyleValue(TreeCountingFunction function, ComputedType computed_type)
: StyleValue(Type::TreeCountingFunction)
, m_function(function)
, m_computed_type(computed_type)
{
}
TreeCountingFunction m_function;
ComputedType m_computed_type;
};
}