mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:07:34 +00:00
LibWeb: Handle disabling of StyleSheet HTMLLinkElements
We now can handle dynamic updating of the disabled attribute of a <link> of the stylesheet type. We do this by hooking the adding and removing attribute's handlers and dynamically loading/removing the stylesheet if it has been enabled/disabled.
This commit is contained in:
parent
c884aa3f25
commit
d6bb110d89
2 changed files with 36 additions and 3 deletions
|
@ -29,6 +29,9 @@ HTMLLinkElement::~HTMLLinkElement() = default;
|
||||||
|
|
||||||
void HTMLLinkElement::inserted()
|
void HTMLLinkElement::inserted()
|
||||||
{
|
{
|
||||||
|
if (has_attribute(AttributeNames::disabled) && (m_relationship & Relationship::Stylesheet))
|
||||||
|
return;
|
||||||
|
|
||||||
HTMLElement::inserted();
|
HTMLElement::inserted();
|
||||||
|
|
||||||
if (m_relationship & Relationship::Stylesheet && !(m_relationship & Relationship::Alternate)) {
|
if (m_relationship & Relationship::Stylesheet && !(m_relationship & Relationship::Alternate)) {
|
||||||
|
@ -92,6 +95,9 @@ void HTMLLinkElement::parse_attribute(FlyString const& name, String const& value
|
||||||
m_relationship |= Relationship::Icon;
|
m_relationship |= Relationship::Icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (name == HTML::AttributeNames::disabled && (m_relationship & Relationship::Stylesheet) && m_loaded_style_sheet)
|
||||||
|
document().style_sheets().remove_sheet(*m_loaded_style_sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLLinkElement::resource_did_fail()
|
void HTMLLinkElement::resource_did_fail()
|
||||||
|
@ -112,6 +118,16 @@ void HTMLLinkElement::resource_did_load()
|
||||||
resource_did_load_favicon();
|
resource_did_load_favicon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HTMLLinkElement::did_remove_attribute(FlyString const& attr)
|
||||||
|
{
|
||||||
|
if (attr == HTML::AttributeNames::disabled && (m_relationship & Relationship::Stylesheet)) {
|
||||||
|
if (!resource())
|
||||||
|
inserted();
|
||||||
|
else
|
||||||
|
resource_did_load_stylesheet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HTMLLinkElement::resource_did_load_stylesheet()
|
void HTMLLinkElement::resource_did_load_stylesheet()
|
||||||
{
|
{
|
||||||
VERIFY(m_relationship & Relationship::Stylesheet);
|
VERIFY(m_relationship & Relationship::Stylesheet);
|
||||||
|
@ -128,10 +144,16 @@ void HTMLLinkElement::resource_did_load_stylesheet()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* sheet = parse_css_stylesheet(CSS::Parser::ParsingContext(document(), resource()->url()), resource()->encoded_data());
|
CSS::CSSStyleSheet* sheet = m_loaded_style_sheet;
|
||||||
if (!sheet) {
|
if (!sheet) {
|
||||||
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Failed to parse stylesheet: {}", resource()->url());
|
sheet = parse_css_stylesheet(CSS::Parser::ParsingContext(document(), resource()->url()), resource()->encoded_data());
|
||||||
return;
|
|
||||||
|
if (!sheet) {
|
||||||
|
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Failed to parse stylesheet: {}", resource()->url());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_loaded_style_sheet = sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
sheet->set_owner_node(this);
|
sheet->set_owner_node(this);
|
||||||
|
@ -179,4 +201,10 @@ bool HTMLLinkElement::load_favicon_and_use_if_window_is_active()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HTMLLinkElement::visit_edges(Cell::Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
visitor.visit(m_loaded_style_sheet);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,10 @@ private:
|
||||||
virtual void resource_did_fail() override;
|
virtual void resource_did_fail() override;
|
||||||
virtual void resource_did_load() override;
|
virtual void resource_did_load() override;
|
||||||
|
|
||||||
|
// ^ HTMLElement
|
||||||
|
virtual void did_remove_attribute(FlyString const&) override;
|
||||||
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
void resource_did_load_stylesheet();
|
void resource_did_load_stylesheet();
|
||||||
void resource_did_load_favicon();
|
void resource_did_load_favicon();
|
||||||
|
|
||||||
|
@ -54,6 +58,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
RefPtr<Resource> m_preload_resource;
|
RefPtr<Resource> m_preload_resource;
|
||||||
|
JS::GCPtr<CSS::CSSStyleSheet> m_loaded_style_sheet;
|
||||||
|
|
||||||
Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
|
Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
|
||||||
unsigned m_relationship { 0 };
|
unsigned m_relationship { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue