summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-10-08 17:02:47 +0100
committerAndreas Kling <kling@serenityos.org>2021-10-08 23:02:57 +0200
commit439d978ea52318bad67ff9097fa4551f1f14ece5 (patch)
tree3689c79a05562bbd6cb515fb1ea4a14936de3e1b /Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
parentdf08b25b3f49a3c9243ae7ec8d54192bcf4cf646 (diff)
downloadserenity-439d978ea52318bad67ff9097fa4551f1f14ece5.zip
LibWeb: Make style-rule iteration aware of CSSMediaRule
The logic is handled by `CSSGroupingRule` and `CSSConditionRule`, so `CSSMediaRule` only has to report if its condition matches. Right now, that condition is always false because we do not evaluate the media query.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp')
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
index ebb810806f..92f02249d5 100644
--- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
+++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp
@@ -6,6 +6,7 @@
#include <AK/TypeCasts.h>
#include <LibWeb/CSS/CSSImportRule.h>
+#include <LibWeb/CSS/CSSMediaRule.h>
#include <LibWeb/CSS/CSSRuleList.h>
#include <LibWeb/DOM/ExceptionOr.h>
@@ -79,12 +80,21 @@ DOM::ExceptionOr<void> CSSRuleList::remove_a_css_rule(u32 index)
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) {
+ switch (rule.type()) {
+ case CSSRule::Type::Style:
callback(verify_cast<CSSStyleRule>(rule));
- } else if (rule.type() == CSSRule::Type::Import) {
- const auto& import_rule = verify_cast<CSSImportRule>(rule);
+ break;
+ case CSSRule::Type::Import: {
+ auto const& import_rule = verify_cast<CSSImportRule>(rule);
if (import_rule.has_import_result())
import_rule.loaded_style_sheet()->for_each_effective_style_rule(callback);
+ break;
+ }
+ case CSSRule::Type::Media:
+ verify_cast<CSSMediaRule>(rule).for_each_effective_style_rule(callback);
+ break;
+ case CSSRule::Type::__Count:
+ VERIFY_NOT_REACHED();
}
}
}
@@ -102,6 +112,8 @@ bool CSSRuleList::for_first_not_loaded_import_rule(Function<void(CSSImportRule&)
if (import_rule.loaded_style_sheet()->for_first_not_loaded_import_rule(callback)) {
return true;
}
+ } else if (rule.type() == CSSRule::Type::Media) {
+ return verify_cast<CSSMediaRule>(rule).for_first_not_loaded_import_rule(callback);
}
}