mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:37:35 +00:00
LibWeb: Add actual document loading for the CSS (at)import rule
This commit is contained in:
parent
54617e1a91
commit
183ebaee91
11 changed files with 229 additions and 56 deletions
|
@ -45,6 +45,11 @@ public:
|
|||
|
||||
const URL& url() const { return m_url; }
|
||||
|
||||
bool has_import_result() const { return !m_style_sheet.is_null(); }
|
||||
RefPtr<StyleSheet> loaded_style_sheet() { return m_style_sheet; }
|
||||
const RefPtr<StyleSheet> loaded_style_sheet() const { return m_style_sheet; }
|
||||
void set_style_sheet(const RefPtr<StyleSheet>& style_sheet) { m_style_sheet = style_sheet; }
|
||||
|
||||
virtual StringView class_name() const { return "CSSImportRule"; };
|
||||
virtual Type type() const { return Type::Import; };
|
||||
|
||||
|
@ -52,6 +57,7 @@ private:
|
|||
CSSImportRule(URL);
|
||||
|
||||
URL m_url;
|
||||
RefPtr<StyleSheet> m_style_sheet;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <AK/TypeCasts.h>
|
||||
#include <LibWeb/CSS/CSSImportRule.h>
|
||||
#include <LibWeb/CSS/CSSRule.h>
|
||||
#include <LibWeb/Loader/Resource.h>
|
||||
|
||||
|
@ -52,9 +53,32 @@ public:
|
|||
for (auto& rule : m_rules)
|
||||
if (rule.type() == CSSRule::Type::Style) {
|
||||
callback(downcast<StyleRule>(rule));
|
||||
} else if (rule.type() == CSSRule::Type::Import) {
|
||||
const CSSImportRule& import_rule = downcast<CSSImportRule>(rule);
|
||||
if (import_rule.has_import_result())
|
||||
import_rule.loaded_style_sheet()->for_each_effective_style_rule(callback);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
bool for_first_not_loaded_import_rule(Callback callback)
|
||||
{
|
||||
for (auto& rule : m_rules)
|
||||
if (rule.type() == CSSRule::Type::Import) {
|
||||
CSSImportRule& import_rule = downcast<CSSImportRule>(rule);
|
||||
if (!import_rule.has_import_result()) {
|
||||
callback(import_rule);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (import_rule.loaded_style_sheet()->for_first_not_loaded_import_rule(callback)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
explicit StyleSheet(NonnullRefPtrVector<CSSRule>&&);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue