LibWeb: Actually incorporate style from imported style sheets

This commit is contained in:
Andreas Kling 2023-03-12 16:04:12 +01:00
parent 1b262f8c89
commit 7b55d79d3a
Notes: sideshowbarker 2024-07-17 07:43:44 +09:00
5 changed files with 40 additions and 2 deletions

View file

@ -0,0 +1,7 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x70.589843 children: not-inline
BlockContainer <body> at (8,8) content-size 784x54.589843 children: inline
line 0 width: 137.646484, height: 54.589843, bottom: 54.589843, baseline: 42.285156
frag 0 from TextNode start: 0, length: 5, rect: [8,8 137.646484x54.589843]
"Crazy"
TextNode <#text>

View file

@ -0,0 +1,5 @@
@import "css-import-rule-sheet-2.css";
body {
background: green;
}

View file

@ -0,0 +1,3 @@
body {
font-size: 50px;
}

View file

@ -0,0 +1,7 @@
<style>
@import "css-import-rule-sheet-1.css";
* {
font-family: 'SerenitySans';
}
</style>
Crazy

View file

@ -19,6 +19,7 @@
#include <LibGfx/Font/VectorFont.h>
#include <LibGfx/Font/WOFF/Font.h>
#include <LibWeb/CSS/CSSFontFaceRule.h>
#include <LibWeb/CSS/CSSImportRule.h>
#include <LibWeb/CSS/CSSStyleRule.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/SelectorEngine.h>
@ -131,6 +132,19 @@ static CSSStyleSheet& quirks_mode_stylesheet(DOM::Document const& document)
return *sheet;
}
static void collect_style_sheets(CSSStyleSheet const& sheet, Vector<JS::NonnullGCPtr<CSSStyleSheet const>>& sheets)
{
sheets.append(sheet);
for (auto const& rule : sheet.rules()) {
if (rule.type() == CSSRule::Type::Import) {
auto const& import_rule = static_cast<CSSImportRule const&>(rule);
if (auto const* imported_sheet = import_rule.loaded_style_sheet()) {
collect_style_sheets(*imported_sheet, sheets);
}
}
}
}
template<typename Callback>
void StyleComputer::for_each_stylesheet(CascadeOrigin cascade_origin, Callback callback) const
{
@ -140,9 +154,11 @@ void StyleComputer::for_each_stylesheet(CascadeOrigin cascade_origin, Callback c
callback(quirks_mode_stylesheet(document()));
}
if (cascade_origin == CascadeOrigin::Author) {
for (auto const& sheet : document().style_sheets().sheets()) {
Vector<JS::NonnullGCPtr<CSSStyleSheet const>> sheets;
for (auto const& sheet : document().style_sheets().sheets())
collect_style_sheets(sheet, sheets);
for (auto const& sheet : sheets)
callback(*sheet);
}
}
}