1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:08:10 +00:00

LibWeb: Process style sheets in document order

Until now we would simply apply stylesheets in the order they finished
loading. This patch adds a StyleSheetList object that hangs off of each
Document and contains all the style sheets in document order.

There's still a lot of work to do for a proper cascade, but at least
this makes us consistently wrong every time. :^)
This commit is contained in:
Andreas Kling 2020-06-04 16:06:32 +02:00
parent ec1891837f
commit 959de19418
11 changed files with 120 additions and 7 deletions

View file

@ -68,12 +68,20 @@ void HTMLLinkElement::resource_did_load()
dbg() << "HTMLLinkElement: Failed to parse stylesheet: " << href();
return;
}
document().add_sheet(*sheet);
// Transfer the rules from the successfully parsed sheet into the sheet we've already inserted.
m_style_sheet->rules() = sheet->rules();
document().update_style();
}
void HTMLLinkElement::load_stylesheet(const URL& url)
{
// First insert an empty style sheet in the document sheet list.
// There's probably a nicer way to do this, but this ensures that sheets are in document order.
m_style_sheet = StyleSheet::create({});
document().style_sheets().add_sheet(*m_style_sheet);
LoadRequest request;
request.set_url(url);
set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request));