LibWeb/CSS: Allow setting StyleValues on CSSStyleProperties directly

This is used by StylePropertyMap - we already have verified that the
value is acceptable for the property before this point.
This commit is contained in:
Sam Atkins 2025-10-02 13:42:02 +01:00 committed by Andreas Kling
commit 7778f3b279
Notes: github-actions[bot] 2025-10-04 20:58:25 +00:00
3 changed files with 32 additions and 0 deletions

View file

@ -402,6 +402,35 @@ RefPtr<StyleValue const> CSSStyleProperties::get_property_style_value(PropertyID
return get_property_style_value(PropertyNameAndID::from_id(property_id));
}
WebIDL::ExceptionOr<void> CSSStyleProperties::set_property_style_value(PropertyNameAndID const& property, NonnullRefPtr<StyleValue const> style_value)
{
if (is_computed()) {
return WebIDL::NoModificationAllowedError::create(realm(), "Cannot modify properties in result of getComputedStyle()"_utf16);
}
if (property.is_custom_property()) {
m_custom_properties.remove(property.name());
m_custom_properties.set(property.name(),
StyleProperty {
Important::No,
PropertyID::Custom,
style_value,
property.name() });
return {};
}
m_properties.remove_first_matching([&property](StyleProperty const& style_property) {
return style_property.property_id == property.id();
});
m_properties.append(StyleProperty {
.important = Important::No,
.property_id = property.id(),
.value = move(style_value),
});
return {};
}
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertyvalue
Optional<StyleProperty> CSSStyleProperties::get_property_internal(PropertyNameAndID const& property) const
{