LibWeb: Add a constant for the number of longhand properties

We use this in multiple places (and will in more places in the future)
so it's worth having as a constant from a clarity point of view
This commit is contained in:
Callum Law 2025-08-24 14:26:17 +12:00 committed by Jelle Raaijmakers
commit fba4187c8f
Notes: github-actions[bot] 2025-08-26 10:19:56 +00:00
4 changed files with 4 additions and 4 deletions

View file

@ -128,7 +128,7 @@ size_t CSSStyleProperties::length() const
if (is_computed()) { if (is_computed()) {
if (!owner_node().has_value()) if (!owner_node().has_value())
return 0; return 0;
return to_underlying(last_longhand_property_id) - to_underlying(first_longhand_property_id) + 1; return number_of_longhand_properties;
} }
return m_properties.size(); return m_properties.size();

View file

@ -1058,7 +1058,7 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optional<CSS::
auto compute_keyframe_values = [refresh, &computed_properties, &element, &pseudo_element, this](auto const& keyframe_values) { auto compute_keyframe_values = [refresh, &computed_properties, &element, &pseudo_element, this](auto const& keyframe_values) {
HashMap<PropertyID, RefPtr<StyleValue const>> result; HashMap<PropertyID, RefPtr<StyleValue const>> result;
HashMap<PropertyID, PropertyID> longhands_set_by_property_id; HashMap<PropertyID, PropertyID> longhands_set_by_property_id;
auto property_is_set_by_use_initial = MUST(Bitmap::create(to_underlying(last_longhand_property_id) - to_underlying(first_longhand_property_id) + 1, false)); auto property_is_set_by_use_initial = MUST(Bitmap::create(number_of_longhand_properties, false));
auto property_is_logical_alias_including_shorthands = [&](PropertyID property_id) { auto property_is_logical_alias_including_shorthands = [&](PropertyID property_id) {
if (property_is_shorthand(property_id)) if (property_is_shorthand(property_id))

View file

@ -150,7 +150,6 @@ WebIDL::UnsignedLong StylePropertyMapReadOnly::size() const
// value on this" // value on this"
// Ensure style is computed on the element before we try to read it. // Ensure style is computed on the element before we try to read it.
element.document().update_style(); element.document().update_style();
auto longhands_count = to_underlying(last_longhand_property_id) - to_underlying(first_longhand_property_id) + 1;
// Some custom properties set on the element might also be in the registered custom properties set, so we // Some custom properties set on the element might also be in the registered custom properties set, so we
// want the size of the union of the two sets. // want the size of the union of the two sets.
@ -160,7 +159,7 @@ WebIDL::UnsignedLong StylePropertyMapReadOnly::size() const
for (auto const& [key, _] : element.document().registered_custom_properties()) for (auto const& [key, _] : element.document().registered_custom_properties())
custom_properties.set(key); custom_properties.set(key);
return longhands_count + custom_properties.size(); return number_of_longhand_properties + custom_properties.size();
}, },
[](GC::Ref<CSSStyleDeclaration> const& declaration) { return declaration->length(); }); [](GC::Ref<CSSStyleDeclaration> const& declaration) { return declaration->length(); });
} }

View file

@ -300,6 +300,7 @@ constexpr PropertyID first_inherited_longhand_property_id = PropertyID::@first_i
constexpr PropertyID last_inherited_longhand_property_id = PropertyID::@last_inherited_longhand_property_id@; constexpr PropertyID last_inherited_longhand_property_id = PropertyID::@last_inherited_longhand_property_id@;
constexpr PropertyID first_longhand_property_id = PropertyID::@first_longhand_property_id@; constexpr PropertyID first_longhand_property_id = PropertyID::@first_longhand_property_id@;
constexpr PropertyID last_longhand_property_id = PropertyID::@last_longhand_property_id@; constexpr PropertyID last_longhand_property_id = PropertyID::@last_longhand_property_id@;
constexpr size_t number_of_longhand_properties = to_underlying(last_longhand_property_id) - to_underlying(first_longhand_property_id) + 1;
enum class Quirk { enum class Quirk {
// https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk // https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk