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

LibWeb: Evaluate @media rules

We now evaluate the conditions of `@media` rules at the same point in
the HTML event loop as evaluation of `MediaQueryList`s. This is not
strictly to spec, but since the spec doesn't actually say when to do
this, it seems to make the most sense. In any case, it works! :^)
This commit is contained in:
Sam Atkins 2021-10-08 20:21:46 +01:00 committed by Andreas Kling
parent 57a25139a5
commit 5098cd22a4
8 changed files with 47 additions and 2 deletions

View file

@ -126,4 +126,34 @@ bool CSSRuleList::for_first_not_loaded_import_rule(Function<void(CSSImportRule&)
return false;
}
void CSSRuleList::evaluate_media_queries(DOM::Window const& window)
{
for (auto& rule : m_rules) {
switch (rule.type()) {
case CSSRule::Type::Style:
break;
case CSSRule::Type::Import: {
auto& import_rule = verify_cast<CSSImportRule>(rule);
if (import_rule.has_import_result())
import_rule.loaded_style_sheet()->evaluate_media_queries(window);
break;
}
case CSSRule::Type::Media: {
auto& media_rule = verify_cast<CSSMediaRule>(rule);
if (media_rule.evaluate(window))
media_rule.css_rules().evaluate_media_queries(window);
break;
}
case CSSRule::Type::Supports: {
auto& supports_rule = verify_cast<CSSSupportsRule>(rule);
if (supports_rule.condition_matches())
supports_rule.css_rules().evaluate_media_queries(window);
break;
}
case CSSRule::Type::__Count:
VERIFY_NOT_REACHED();
}
}
}
}