LibWeb: Invalidate style (and rule cache) on MediaList changes

This makes dynamic changes to a style sheet's media attribute actually
take effect immediately.
This commit is contained in:
Andreas Kling 2025-03-04 14:50:11 +01:00 committed by Andreas Kling
parent 80c0a16597
commit 6606eecce5
Notes: github-actions[bot] 2025-03-04 18:08:34 +00:00
12 changed files with 109 additions and 3 deletions

View file

@ -7,6 +7,8 @@
*/
#include <LibWeb/Bindings/HTMLStyleElementPrototype.h>
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLStyleElement.h>
namespace Web::HTML {
@ -77,6 +79,18 @@ 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()
{