1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:47:45 +00:00

LibWeb: Ensure inline CSS loaded from HTML is ElementInline

This commit changes inline CSS loaded from style attributes of HTML
elements to be loaded as CSS::ElementInlineCSSStyleDeclaration instead
of CSS::CSSStyleDeclaration, fixing a crash when the style of that
element is changed from JavaScript.
This commit is contained in:
DoubleNegation 2021-07-23 10:35:39 +02:00 committed by Andreas Kling
parent afcd053b68
commit 0fdfdbed9f
3 changed files with 14 additions and 2 deletions

View file

@ -32,6 +32,12 @@ ElementInlineCSSStyleDeclaration::ElementInlineCSSStyleDeclaration(DOM::Element&
{
}
ElementInlineCSSStyleDeclaration::ElementInlineCSSStyleDeclaration(DOM::Element& element, CSSStyleDeclaration& declaration)
: CSSStyleDeclaration(move(declaration.m_properties), move(declaration.m_custom_properties))
, m_element(element.make_weak_ptr<DOM::Element>())
{
}
ElementInlineCSSStyleDeclaration::~ElementInlineCSSStyleDeclaration()
{
}

View file

@ -44,6 +44,7 @@ protected:
explicit CSSStyleDeclaration(Vector<StyleProperty>&&, HashMap<String, StyleProperty>&&);
private:
friend class ElementInlineCSSStyleDeclaration;
friend class Bindings::CSSStyleDeclarationWrapper;
Vector<StyleProperty> m_properties;
@ -53,6 +54,7 @@ private:
class ElementInlineCSSStyleDeclaration final : public CSSStyleDeclaration {
public:
static NonnullRefPtr<ElementInlineCSSStyleDeclaration> create(DOM::Element& element) { return adopt_ref(*new ElementInlineCSSStyleDeclaration(element)); }
static NonnullRefPtr<ElementInlineCSSStyleDeclaration> create_and_take_properties_from(DOM::Element& element, CSSStyleDeclaration& declaration) { return adopt_ref(*new ElementInlineCSSStyleDeclaration(element, declaration)); }
virtual ~ElementInlineCSSStyleDeclaration() override;
DOM::Element* element() { return m_element.ptr(); }
@ -60,6 +62,7 @@ public:
private:
explicit ElementInlineCSSStyleDeclaration(DOM::Element&);
explicit ElementInlineCSSStyleDeclaration(DOM::Element&, CSSStyleDeclaration&);
WeakPtr<DOM::Element> m_element;
};

View file

@ -158,9 +158,12 @@ void Element::parse_attribute(const FlyString& name, const String& value)
m_classes.unchecked_append(new_class);
}
} else if (name == HTML::AttributeNames::style) {
m_inline_style = parse_css_declaration(CSS::ParsingContext(document()), value);
auto parsed_style = parse_css_declaration(CSS::ParsingContext(document()), value);
if (!parsed_style.is_null()) {
m_inline_style = CSS::ElementInlineCSSStyleDeclaration::create_and_take_properties_from(*this, parsed_style.release_nonnull());
set_needs_style_update(true);
}
}
}
enum class StyleDifference {