LibWeb: Update existing style object when setting style attribute

Previously any existing ElementInlineCSSStyleDeclaration would get
overwritten by e.setAttribute("style", ...), while it should be updated
instead.

This fixes 2 WPT subtests.
This commit is contained in:
Milo van der Tier 2024-11-25 14:35:56 +01:00 committed by Andreas Kling
parent be3a941f44
commit aa33acf3a2
Notes: github-actions[bot] 2024-11-25 16:18:19 +00:00
4 changed files with 25 additions and 9 deletions

View file

@ -513,6 +513,19 @@ void PropertyOwningCSSStyleDeclaration::set_the_declarations(Vector<StylePropert
m_custom_properties = move(custom_properties);
}
void ElementInlineCSSStyleDeclaration::set_declarations_from_text(StringView css_text)
{
// FIXME: What do we do if the element is null?
if (!m_element) {
dbgln("FIXME: Returning from ElementInlineCSSStyleDeclaration::declarations_from_text as m_element is null.");
return;
}
empty_the_declarations();
auto style = parse_css_style_attribute(CSS::Parser::ParsingContext(m_element->document()), css_text, *m_element.ptr());
set_the_declarations(style->properties(), style->custom_properties());
}
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
WebIDL::ExceptionOr<void> ElementInlineCSSStyleDeclaration::set_css_text(StringView css_text)
{
@ -526,11 +539,8 @@ WebIDL::ExceptionOr<void> ElementInlineCSSStyleDeclaration::set_css_text(StringV
// NOTE: See ResolvedCSSStyleDeclaration.
// 2. Empty the declarations.
empty_the_declarations();
// 3. Parse the given value and, if the return value is not the empty list, insert the items in the list into the declarations, in specified order.
auto style = parse_css_style_attribute(CSS::Parser::ParsingContext(m_element->document()), css_text, *m_element.ptr());
set_the_declarations(style->properties(), style->custom_properties());
set_declarations_from_text(css_text);
// 4. Update style attribute for the CSS declaration block.
update_style_attribute();