LibWeb: Invalidate style when media content attribute changes

Previously, we would only invalidate style when setting the `media` IDL
attribute; changing the attribute via `setAttribute()` and
`removeAttribute()` had no immediate effect.
This commit is contained in:
Tim Ledbetter 2025-03-22 11:33:59 +00:00 committed by Alexander Kalenik
parent 0b0f47e320
commit e1f6a170d5
Notes: github-actions[bot] 2025-03-22 16:04:49 +00:00
5 changed files with 62 additions and 16 deletions

View file

@ -52,6 +52,16 @@ void HTMLStyleElement::removed_from(Node* old_parent, Node& old_root)
Base::removed_from(old_parent, old_root);
}
void HTMLStyleElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
{
Base::attribute_changed(name, old_value, value, namespace_);
if (name == HTML::AttributeNames::media) {
if (auto* sheet = m_style_element_utils.sheet())
sheet->set_media(value.value_or({}));
}
}
// https://html.spec.whatwg.org/multipage/semantics.html#dom-style-disabled
bool HTMLStyleElement::disabled()
{
@ -79,18 +89,6 @@ void HTMLStyleElement::set_disabled(bool disabled)
sheet()->set_disabled(disabled);
}
String HTMLStyleElement::media() const
{
return attribute(HTML::AttributeNames::media).value_or(String {});
}
void HTMLStyleElement::set_media(String media)
{
(void)set_attribute(HTML::AttributeNames::media, media);
if (auto sheet = m_style_element_utils.sheet())
sheet->set_media(media);
}
// https://www.w3.org/TR/cssom/#dom-linkstyle-sheet
CSS::CSSStyleSheet* HTMLStyleElement::sheet()
{