diff options
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp | 34 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/CSSRuleList.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp | 25 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h | 1 |
4 files changed, 40 insertions, 24 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp index ecff5b9118..ebb810806f 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp @@ -4,6 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <AK/TypeCasts.h> +#include <LibWeb/CSS/CSSImportRule.h> #include <LibWeb/CSS/CSSRuleList.h> #include <LibWeb/DOM/ExceptionOr.h> @@ -74,4 +76,36 @@ DOM::ExceptionOr<void> CSSRuleList::remove_a_css_rule(u32 index) return {}; } +void CSSRuleList::for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const +{ + for (auto& rule : m_rules) { + if (rule.type() == CSSRule::Type::Style) { + callback(verify_cast<CSSStyleRule>(rule)); + } else if (rule.type() == CSSRule::Type::Import) { + const auto& import_rule = verify_cast<CSSImportRule>(rule); + if (import_rule.has_import_result()) + import_rule.loaded_style_sheet()->for_each_effective_style_rule(callback); + } + } +} + +bool CSSRuleList::for_first_not_loaded_import_rule(Function<void(CSSImportRule&)> const& callback) +{ + for (auto& rule : m_rules) { + if (rule.type() == CSSRule::Type::Import) { + auto& import_rule = verify_cast<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; +} + } diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.h b/Userland/Libraries/LibWeb/CSS/CSSRuleList.h index c91c721720..069d67909b 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.h +++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.h @@ -6,6 +6,7 @@ #pragma once +#include <AK/Function.h> #include <AK/Iterator.h> #include <AK/NonnullRefPtrVector.h> #include <AK/RefCounted.h> @@ -50,6 +51,9 @@ public: DOM::ExceptionOr<void> remove_a_css_rule(u32 index); DOM::ExceptionOr<unsigned> insert_a_css_rule(NonnullRefPtr<CSSRule>, u32 index); + void for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const; + bool for_first_not_loaded_import_rule(Function<void(CSSImportRule&)> const& callback); + private: explicit CSSRuleList(NonnullRefPtrVector<CSSRule>&&); diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index d4a3dcf065..b7dab97abd 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -4,7 +4,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include <LibWeb/CSS/CSSImportRule.h> #include <LibWeb/CSS/CSSStyleSheet.h> #include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/DOM/ExceptionOr.h> @@ -60,32 +59,12 @@ DOM::ExceptionOr<void> CSSStyleSheet::remove_rule(unsigned index) void CSSStyleSheet::for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const { - for (auto& rule : *m_rules) - if (rule.type() == CSSRule::Type::Style) { - callback(verify_cast<CSSStyleRule>(rule)); - } else if (rule.type() == CSSRule::Type::Import) { - const auto& import_rule = verify_cast<CSSImportRule>(rule); - if (import_rule.has_import_result()) - import_rule.loaded_style_sheet()->for_each_effective_style_rule(callback); - } + m_rules->for_each_effective_style_rule(callback); } bool CSSStyleSheet::for_first_not_loaded_import_rule(Function<void(CSSImportRule&)> const& callback) { - for (auto& rule : *m_rules) - if (rule.type() == CSSRule::Type::Import) { - auto& import_rule = verify_cast<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; + return m_rules->for_first_not_loaded_import_rule(callback); } } diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h index 576ee76fa0..dbbf197093 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h @@ -8,7 +8,6 @@ #include <AK/Function.h> #include <AK/NonnullRefPtrVector.h> -#include <AK/TypeCasts.h> #include <LibWeb/CSS/CSSRule.h> #include <LibWeb/CSS/CSSRuleList.h> #include <LibWeb/CSS/CSSStyleRule.h> |