LibWeb: Implement CounterStyle::equals

This makes `ValueComparingRefPtr<CounterStyle>` work
This commit is contained in:
Callum Law 2026-04-07 16:18:17 +12:00 committed by Sam Atkins
parent 64ccb9a015
commit 595848b0fa
3 changed files with 32 additions and 1 deletions

View file

@ -80,6 +80,18 @@ NonnullRefPtr<CounterStyle const> CounterStyle::from_counter_style_definition(Co
});
}
bool CounterStyle::equals(CounterStyle const& other) const
{
return name() == other.name()
&& algorithm() == other.algorithm()
&& negative_sign() == other.negative_sign()
&& prefix() == other.prefix()
&& suffix() == other.suffix()
&& range() == other.range()
&& pad() == other.pad()
&& fallback() == other.fallback();
}
// https://drafts.csswg.org/css-counter-styles-3/#extended-range-optional
static String generate_an_initial_representation_for_extended_cjk_system(i64 value, ExtendedCJKCounterStyleAlgorithm::Type type, Array<FlyString, 10> const& digit_strings, Array<FlyString, 3> const& digit_marker_strings, Array<FlyString, 3> const& group_marker_strings)
{

View file

@ -38,6 +38,7 @@ public:
Optional<String> generate_an_initial_representation_for_the_counter_value(i64 value) const;
bool uses_a_negative_sign() const;
bool equals(CounterStyle const&) const;
virtual ~CounterStyle() = default;

View file

@ -13,6 +13,8 @@ namespace Web::CSS {
struct CounterStyleRangeEntry {
i32 start;
i32 end;
bool operator==(CounterStyleRangeEntry const&) const = default;
};
// https://drafts.csswg.org/css-counter-styles-3/#counter-style-symbols
@ -26,32 +28,46 @@ using CounterStyleSymbol = FlyString;
struct CounterStyleNegativeSign {
CounterStyleSymbol prefix;
CounterStyleSymbol suffix;
bool operator==(CounterStyleNegativeSign const&) const = default;
};
struct CounterStylePad {
i32 minimum_length;
CounterStyleSymbol symbol;
bool operator==(CounterStylePad const&) const = default;
};
struct AdditiveCounterStyleAlgorithm {
struct AdditiveTuple {
i32 weight;
CounterStyleSymbol symbol;
bool operator==(AdditiveTuple const&) const = default;
};
Vector<AdditiveTuple> symbol_list;
bool operator==(AdditiveCounterStyleAlgorithm const&) const = default;
};
struct FixedCounterStyleAlgorithm {
i32 first_symbol;
Vector<CounterStyleSymbol> symbol_list;
bool operator==(FixedCounterStyleAlgorithm const&) const = default;
};
struct GenericCounterStyleAlgorithm {
CounterStyleSystem type;
Vector<CounterStyleSymbol> symbol_list;
bool operator==(GenericCounterStyleAlgorithm const&) const = default;
};
struct EthiopicNumericCounterStyleAlgorithm { };
struct EthiopicNumericCounterStyleAlgorithm {
bool operator==(EthiopicNumericCounterStyleAlgorithm const&) const = default;
};
struct ExtendedCJKCounterStyleAlgorithm {
enum class Type : u8 {
@ -65,6 +81,8 @@ struct ExtendedCJKCounterStyleAlgorithm {
KoreanHanjaInformal,
KoreanHanjaFormal,
} type;
bool operator==(ExtendedCJKCounterStyleAlgorithm const&) const = default;
};
using CounterStyleAlgorithm = Variant<AdditiveCounterStyleAlgorithm, FixedCounterStyleAlgorithm, GenericCounterStyleAlgorithm, EthiopicNumericCounterStyleAlgorithm, ExtendedCJKCounterStyleAlgorithm>;