1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:57:35 +00:00

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.
This commit is contained in:
Sam Atkins 2021-10-08 17:02:47 +01:00 committed by Andreas Kling
parent df08b25b3f
commit 439d978ea5
6 changed files with 49 additions and 3 deletions

View file

@ -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);
}
}