1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 23:58:11 +00:00

LibWeb: Give CSSLoader a backpointer to its owner element

This allows CSSLoader to set up the style sheet owner node internally,
and avoids an awkward weak link between CSSLoader and Document.
This commit is contained in:
Andreas Kling 2021-03-08 15:43:03 +01:00
parent d07fcba69b
commit bc116f3b13
5 changed files with 17 additions and 16 deletions

View file

@ -36,7 +36,7 @@ namespace Web::HTML {
HTMLLinkElement::HTMLLinkElement(DOM::Document& document, QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
, m_css_loader(document)
, m_css_loader(*this)
{
m_css_loader.on_load = [&] {
document.update_style();
@ -53,10 +53,8 @@ void HTMLLinkElement::inserted_into(Node& node)
if (m_relationship & Relationship::Stylesheet && !(m_relationship & Relationship::Alternate)) {
m_css_loader.load_from_url(document().complete_url(href()));
if (auto sheet = m_css_loader.style_sheet()) {
sheet->set_owner_node(this);
if (auto sheet = m_css_loader.style_sheet())
document().style_sheets().add_sheet(sheet.release_nonnull());
}
}
}

View file

@ -55,8 +55,8 @@ private:
};
};
unsigned m_relationship { 0 };
CSSLoader m_css_loader;
unsigned m_relationship { 0 };
};
}

View file

@ -34,7 +34,7 @@ namespace Web::HTML {
HTMLStyleElement::HTMLStyleElement(DOM::Document& document, QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
, m_css_loader(document)
, m_css_loader(*this)
{
m_css_loader.on_load = [&] {
document.update_style();
@ -54,10 +54,8 @@ void HTMLStyleElement::children_changed()
});
m_css_loader.load_from_text(builder.to_string());
if (auto sheet = m_css_loader.style_sheet()) {
sheet->set_owner_node(this);
if (auto sheet = m_css_loader.style_sheet())
document().style_sheets().add_sheet(sheet.release_nonnull());
}
HTMLElement::children_changed();
}