LibWeb: Remove unnecessary ComputedProperties::maybe_null_property

We know that all (longhand) properties have a value so this is
unnecessary.
This commit is contained in:
Callum Law 2025-08-25 16:55:07 +12:00 committed by Jelle Raaijmakers
commit 912ffc3f84
Notes: github-actions[bot] 2025-08-26 10:18:59 +00:00
6 changed files with 15 additions and 39 deletions

View file

@ -187,15 +187,9 @@ Optional<StyleProperty> CSSStyleProperties::property(PropertyID property_id) con
if (!layout_node) {
auto style = element.document().style_computer().compute_style(element, pseudo_element);
// FIXME: This is a stopgap until we implement shorthand -> longhand conversion.
auto const* value = style->maybe_null_property(property_id);
if (!value) {
dbgln("FIXME: CSSStyleProperties::property(property_id={:#x}) No value for property ID in newly computed style case.", to_underlying(property_id));
return {};
}
return StyleProperty {
.property_id = property_id,
.value = *value,
.value = style->property(property_id),
};
}

View file

@ -159,16 +159,6 @@ StyleValue const& ComputedProperties::property(PropertyID property_id, WithAnima
return *m_property_values[to_underlying(property_id) - to_underlying(first_longhand_property_id)];
}
StyleValue const* ComputedProperties::maybe_null_property(PropertyID property_id) const
{
VERIFY(property_id >= first_longhand_property_id && property_id <= last_longhand_property_id);
if (auto animated_value = m_animated_property_values.get(property_id); animated_value.has_value())
return animated_value.value();
return m_property_values[to_underlying(property_id) - to_underlying(first_longhand_property_id)];
}
Variant<LengthPercentage, NormalGap> ComputedProperties::gap_value(PropertyID id) const
{
auto const& value = property(id);

View file

@ -66,7 +66,6 @@ public:
Yes,
};
StyleValue const& property(PropertyID, WithAnimationsApplied = WithAnimationsApplied::Yes) const;
StyleValue const* maybe_null_property(PropertyID) const;
void revert_property(PropertyID, ComputedProperties const& style_for_revert);
GC::Ptr<CSSStyleDeclaration const> animation_name_source() const { return m_animation_name_source; }

View file

@ -1348,23 +1348,23 @@ static void compute_transitioned_properties(ComputedProperties const& style, DOM
}
auto normalize_transition_length_list = [&properties, &style](PropertyID property, auto make_default_value) {
auto const* style_value = style.maybe_null_property(property);
auto const& style_value = style.property(property);
StyleValueVector list;
if (style_value && !style_value->is_value_list()) {
if (!style_value.is_value_list()) {
for (size_t i = 0; i < properties.size(); i++)
list.append(*style_value);
list.append(style_value);
return list;
}
if (!style_value || !style_value->is_value_list() || style_value->as_value_list().size() == 0) {
if (style_value.as_value_list().size() == 0) {
auto default_value = make_default_value();
for (size_t i = 0; i < properties.size(); i++)
list.append(default_value);
return list;
}
auto const& value_list = style_value->as_value_list();
auto const& value_list = style_value.as_value_list();
for (size_t i = 0; i < properties.size(); i++)
list.append(value_list.value_at(i, true));
@ -2617,14 +2617,12 @@ GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::Element& elem
// Animation declarations [css-animations-2]
auto animation_name = [&]() -> Optional<String> {
auto const animation_name = computed_style->maybe_null_property(PropertyID::AnimationName);
if (!animation_name)
auto const& animation_name = computed_style->property(PropertyID::AnimationName);
if (animation_name.is_keyword() && animation_name.to_keyword() == Keyword::None)
return OptionalNone {};
if (animation_name->is_keyword() && animation_name->to_keyword() == Keyword::None)
return OptionalNone {};
if (animation_name->is_string())
return animation_name->as_string().string_value().to_string();
return animation_name->to_string(SerializationMode::Normal);
if (animation_name.is_string())
return animation_name.as_string().string_value().to_string();
return animation_name.to_string(SerializationMode::Normal);
}();
if (animation_name.has_value()) {

View file

@ -676,12 +676,8 @@ static CSS::RequiredInvalidationAfterStyleChange compute_required_invalidation(C
for (auto i = to_underlying(CSS::first_longhand_property_id); i <= to_underlying(CSS::last_longhand_property_id); ++i) {
auto property_id = static_cast<CSS::PropertyID>(i);
auto old_value = old_style.maybe_null_property(property_id);
auto new_value = new_style.maybe_null_property(property_id);
if (!old_value && !new_value)
continue;
invalidation |= CSS::compute_property_invalidation(property_id, old_value, new_value);
invalidation |= CSS::compute_property_invalidation(property_id, old_style.property(property_id), new_style.property(property_id));
}
return invalidation;
}
@ -810,7 +806,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_inherited_style()
// FIXME: We should use the specified value rather than the cascaded value as the cascaded value may include
// unresolved CSS-wide keywords (e.g. 'initial' or 'inherit') rather than the resolved value.
auto const& preabsolutized_value = m_cascaded_properties->property(property_id);
RefPtr old_value = computed_properties->maybe_null_property(property_id);
RefPtr old_value = computed_properties->property(property_id);
// Update property if it uses relative units as it might have been affected by a change in ancestor element style.
if (preabsolutized_value && preabsolutized_value->is_length() && preabsolutized_value->as_length().length().is_font_relative()) {
auto is_inherited = computed_properties->is_property_inherited(property_id);
@ -842,7 +838,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_inherited_style()
document().style_computer().absolutize_values(*computed_properties);
for (auto [property_id, old_value] : old_values_with_relative_units) {
auto new_value = computed_properties->maybe_null_property(static_cast<CSS::PropertyID>(property_id));
auto const& new_value = computed_properties->property(static_cast<CSS::PropertyID>(property_id));
invalidation |= CSS::compute_property_invalidation(static_cast<CSS::PropertyID>(property_id), old_value, new_value);
}

View file

@ -328,8 +328,7 @@ void ConnectionFromClient::debug_request(u64 page_id, ByteString request, ByteSt
auto dump_style = [](String const& title, Web::CSS::ComputedProperties const& style, HashMap<FlyString, Web::CSS::StyleProperty> const& custom_properties) {
dbgln("+ {}", title);
for (size_t i = to_underlying(Web::CSS::first_longhand_property_id); i < to_underlying(Web::CSS::last_longhand_property_id); ++i) {
auto property = style.maybe_null_property(static_cast<Web::CSS::PropertyID>(i));
dbgln("| {} = {}", Web::CSS::string_from_property_id(static_cast<Web::CSS::PropertyID>(i)), property ? property->to_string(Web::CSS::SerializationMode::Normal) : ""_string);
dbgln("| {} = {}", Web::CSS::string_from_property_id(static_cast<Web::CSS::PropertyID>(i)), style.property(static_cast<Web::CSS::PropertyID>(i)).to_string(Web::CSS::SerializationMode::Normal));
}
for (auto const& [name, property] : custom_properties) {
dbgln("| {} = {}", name, property.value->to_string(Web::CSS::SerializationMode::Normal));