зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1669600 - Properly distinguish between empty children and no children in rule iterator. r=heycam
So that skip_children(), which just pops the stack and is used by the dynamic media query evaluation code, works as it should. Differential Revision: https://phabricator.services.mozilla.com/D92717
This commit is contained in:
Родитель
67788d6893
Коммит
ef5f4f8d29
|
@ -60,7 +60,7 @@ fn children_of_rule<'a, C>(
|
|||
quirks_mode: QuirksMode,
|
||||
guard: &'a SharedRwLockReadGuard<'_>,
|
||||
effective: &mut bool,
|
||||
) -> slice::Iter<'a, CssRule>
|
||||
) -> Option<slice::Iter<'a, CssRule>>
|
||||
where
|
||||
C: NestedRuleIterationCondition + 'static,
|
||||
{
|
||||
|
@ -73,38 +73,38 @@ where
|
|||
CssRule::Viewport(_) |
|
||||
CssRule::Keyframes(_) |
|
||||
CssRule::Page(_) |
|
||||
CssRule::FontFeatureValues(_) => [].iter(),
|
||||
CssRule::FontFeatureValues(_) => None,
|
||||
CssRule::Import(ref import_rule) => {
|
||||
let import_rule = import_rule.read_with(guard);
|
||||
if !C::process_import(guard, device, quirks_mode, import_rule) {
|
||||
*effective = false;
|
||||
return [].iter();
|
||||
return None;
|
||||
}
|
||||
import_rule.stylesheet.rules(guard).iter()
|
||||
Some(import_rule.stylesheet.rules(guard).iter())
|
||||
},
|
||||
CssRule::Document(ref doc_rule) => {
|
||||
let doc_rule = doc_rule.read_with(guard);
|
||||
if !C::process_document(guard, device, quirks_mode, doc_rule) {
|
||||
*effective = false;
|
||||
return [].iter();
|
||||
return None;
|
||||
}
|
||||
doc_rule.rules.read_with(guard).0.iter()
|
||||
Some(doc_rule.rules.read_with(guard).0.iter())
|
||||
},
|
||||
CssRule::Media(ref lock) => {
|
||||
let media_rule = lock.read_with(guard);
|
||||
if !C::process_media(guard, device, quirks_mode, media_rule) {
|
||||
*effective = false;
|
||||
return [].iter();
|
||||
return None;
|
||||
}
|
||||
media_rule.rules.read_with(guard).0.iter()
|
||||
Some(media_rule.rules.read_with(guard).0.iter())
|
||||
},
|
||||
CssRule::Supports(ref lock) => {
|
||||
let supports_rule = lock.read_with(guard);
|
||||
if !C::process_supports(guard, device, quirks_mode, supports_rule) {
|
||||
*effective = false;
|
||||
return [].iter();
|
||||
return None;
|
||||
}
|
||||
supports_rule.rules.read_with(guard).0.iter()
|
||||
Some(supports_rule.rules.read_with(guard).0.iter())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,9 @@ where
|
|||
continue;
|
||||
}
|
||||
|
||||
if !children.as_slice().is_empty() {
|
||||
if let Some(children) = children {
|
||||
// NOTE: It's important that `children` gets pushed even if
|
||||
// empty, so that `skip_children()` works as expected.
|
||||
self.stack.push(children);
|
||||
}
|
||||
|
||||
|
@ -306,6 +308,6 @@ impl<'a, 'b> EffectiveRulesIterator<'a, 'b> {
|
|||
rule: &'a CssRule,
|
||||
) -> Self {
|
||||
let children = children_of_rule::<AllRules>(rule, device, quirks_mode, guard, &mut false);
|
||||
EffectiveRulesIterator::new(device, quirks_mode, guard, children)
|
||||
EffectiveRulesIterator::new(device, quirks_mode, guard, children.unwrap_or([].iter()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<!doctype html>
|
||||
<title>Dynamic evaluation of media queries works fine in presence of empty media rule</title>
|
||||
<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
|
||||
<link rel="author" href="https://mozilla.org" title="Mozilla">
|
||||
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1669600">
|
||||
<link rel="help" href="https://drafts.csswg.org/mediaqueries-4/">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<iframe width=500 height=300 frameborder=0></iframe>
|
||||
<script>
|
||||
let iframe = document.querySelector("iframe");
|
||||
promise_test(async function (t) {
|
||||
await new Promise(resolve => {
|
||||
window.addEventListener("load", resolve);
|
||||
});
|
||||
let frameLoaded = new Promise(resolve => {
|
||||
iframe.addEventListener("load", resolve);
|
||||
});
|
||||
iframe.srcdoc = `
|
||||
<style>
|
||||
:root { background-color: red; }
|
||||
/* This one should never apply */
|
||||
@media (min-width: 1500px) {}
|
||||
/* This one should change and start matching */
|
||||
@media (max-width: 400px) {
|
||||
:root { background-color: lime; }
|
||||
}
|
||||
</style>
|
||||
`;
|
||||
await frameLoaded;
|
||||
|
||||
function getColor() {
|
||||
return iframe.contentWindow.getComputedStyle(iframe.contentDocument.documentElement).backgroundColor;
|
||||
}
|
||||
|
||||
assert_equals(getColor(), "rgb(255, 0, 0)", "Should start red");
|
||||
iframe.width = 400;
|
||||
assert_equals(getColor(), "rgb(0, 255, 0)", "Should turn green");
|
||||
});
|
||||
</script>
|
Загрузка…
Ссылка в новой задаче