mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +00:00
LibWeb: Move CSSRule iteration to CSSRuleList
CSSStyleSheet is no longer the only class that contains a list of rules, so this will save duplicating the logic in multiple places.
This commit is contained in:
parent
bc0ef5f69d
commit
df08b25b3f
4 changed files with 40 additions and 24 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue