diff --git a/Tests/LibWeb/Layout/expected/css-import-rule.txt b/Tests/LibWeb/Layout/expected/css-import-rule.txt new file mode 100644 index 00000000000..075781c7b75 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/css-import-rule.txt @@ -0,0 +1,7 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x70.589843 children: not-inline + BlockContainer 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> diff --git a/Tests/LibWeb/Layout/input/css-import-rule-sheet-1.css b/Tests/LibWeb/Layout/input/css-import-rule-sheet-1.css new file mode 100644 index 00000000000..fd22bf27a4a --- /dev/null +++ b/Tests/LibWeb/Layout/input/css-import-rule-sheet-1.css @@ -0,0 +1,5 @@ +@import "css-import-rule-sheet-2.css"; + +body { + background: green; +} diff --git a/Tests/LibWeb/Layout/input/css-import-rule-sheet-2.css b/Tests/LibWeb/Layout/input/css-import-rule-sheet-2.css new file mode 100644 index 00000000000..636a7e34e42 --- /dev/null +++ b/Tests/LibWeb/Layout/input/css-import-rule-sheet-2.css @@ -0,0 +1,3 @@ +body { + font-size: 50px; +} diff --git a/Tests/LibWeb/Layout/input/css-import-rule.html b/Tests/LibWeb/Layout/input/css-import-rule.html new file mode 100644 index 00000000000..75a86737e7e --- /dev/null +++ b/Tests/LibWeb/Layout/input/css-import-rule.html @@ -0,0 +1,7 @@ + +Crazy diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 809fb427951..751cf0d73c0 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -131,6 +132,19 @@ static CSSStyleSheet& quirks_mode_stylesheet(DOM::Document const& document) return *sheet; } +static void collect_style_sheets(CSSStyleSheet const& sheet, Vector>& sheets) +{ + sheets.append(sheet); + for (auto const& rule : sheet.rules()) { + if (rule.type() == CSSRule::Type::Import) { + auto const& import_rule = static_cast(rule); + if (auto const* imported_sheet = import_rule.loaded_style_sheet()) { + collect_style_sheets(*imported_sheet, sheets); + } + } + } +} + template 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> sheets; + for (auto const& sheet : document().style_sheets().sheets()) + collect_style_sheets(sheet, sheets); + for (auto const& sheet : sheets) callback(*sheet); - } } }