mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:47:43 +00:00
LibWeb: Actually incorporate style from imported style sheets
This commit is contained in:
parent
1b262f8c89
commit
7b55d79d3a
5 changed files with 40 additions and 2 deletions
7
Tests/LibWeb/Layout/expected/css-import-rule.txt
Normal file
7
Tests/LibWeb/Layout/expected/css-import-rule.txt
Normal 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>
|
5
Tests/LibWeb/Layout/input/css-import-rule-sheet-1.css
Normal file
5
Tests/LibWeb/Layout/input/css-import-rule-sheet-1.css
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
@import "css-import-rule-sheet-2.css";
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: green;
|
||||||
|
}
|
3
Tests/LibWeb/Layout/input/css-import-rule-sheet-2.css
Normal file
3
Tests/LibWeb/Layout/input/css-import-rule-sheet-2.css
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
body {
|
||||||
|
font-size: 50px;
|
||||||
|
}
|
7
Tests/LibWeb/Layout/input/css-import-rule.html
Normal file
7
Tests/LibWeb/Layout/input/css-import-rule.html
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<style>
|
||||||
|
@import "css-import-rule-sheet-1.css";
|
||||||
|
* {
|
||||||
|
font-family: 'SerenitySans';
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
Crazy
|
|
@ -19,6 +19,7 @@
|
||||||
#include <LibGfx/Font/VectorFont.h>
|
#include <LibGfx/Font/VectorFont.h>
|
||||||
#include <LibGfx/Font/WOFF/Font.h>
|
#include <LibGfx/Font/WOFF/Font.h>
|
||||||
#include <LibWeb/CSS/CSSFontFaceRule.h>
|
#include <LibWeb/CSS/CSSFontFaceRule.h>
|
||||||
|
#include <LibWeb/CSS/CSSImportRule.h>
|
||||||
#include <LibWeb/CSS/CSSStyleRule.h>
|
#include <LibWeb/CSS/CSSStyleRule.h>
|
||||||
#include <LibWeb/CSS/Parser/Parser.h>
|
#include <LibWeb/CSS/Parser/Parser.h>
|
||||||
#include <LibWeb/CSS/SelectorEngine.h>
|
#include <LibWeb/CSS/SelectorEngine.h>
|
||||||
|
@ -131,6 +132,19 @@ static CSSStyleSheet& quirks_mode_stylesheet(DOM::Document const& document)
|
||||||
return *sheet;
|
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>
|
template<typename Callback>
|
||||||
void StyleComputer::for_each_stylesheet(CascadeOrigin cascade_origin, Callback callback) const
|
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()));
|
callback(quirks_mode_stylesheet(document()));
|
||||||
}
|
}
|
||||||
if (cascade_origin == CascadeOrigin::Author) {
|
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);
|
callback(*sheet);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue