mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Deindent the serialization loop.
Bug: 1471063 Reviewed-by: xidorn MozReview-Commit-ID: GPlUAx7YXVb
This commit is contained in:
parent
aca724ec79
commit
84280c5203
1 changed files with 64 additions and 63 deletions
|
@ -1007,72 +1007,73 @@ impl<Impl: SelectorImpl> ToCss for Selector<Impl> {
|
||||||
debug_assert!(!combinators_exhausted);
|
debug_assert!(!combinators_exhausted);
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom/#serializing-selectors
|
// https://drafts.csswg.org/cssom/#serializing-selectors
|
||||||
|
if compound.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if !compound.is_empty() {
|
// 1. If there is only one simple selector in the compound selectors
|
||||||
// 1. If there is only one simple selector in the compound selectors
|
// which is a universal selector, append the result of
|
||||||
// which is a universal selector, append the result of
|
// serializing the universal selector to s.
|
||||||
// serializing the universal selector to s.
|
//
|
||||||
//
|
// Check if `!compound.empty()` first--this can happen if we have
|
||||||
// Check if `!compound.empty()` first--this can happen if we have
|
// something like `... > ::before`, because we store `>` and `::`
|
||||||
// something like `... > ::before`, because we store `>` and `::`
|
// both as combinators internally.
|
||||||
// both as combinators internally.
|
//
|
||||||
//
|
// If we are in this case, after we have serialized the universal
|
||||||
// If we are in this case, after we have serialized the universal
|
// selector, we skip Step 2 and continue with the algorithm.
|
||||||
// selector, we skip Step 2 and continue with the algorithm.
|
let (can_elide_namespace, first_non_namespace) = match compound[0] {
|
||||||
let (can_elide_namespace, first_non_namespace) = match &compound[0] {
|
Component::ExplicitAnyNamespace |
|
||||||
&Component::ExplicitAnyNamespace |
|
Component::ExplicitNoNamespace |
|
||||||
&Component::ExplicitNoNamespace |
|
Component::Namespace(..) => (false, 1),
|
||||||
&Component::Namespace(_, _) => (false, 1),
|
Component::DefaultNamespace(..) => (true, 1),
|
||||||
&Component::DefaultNamespace(_) => (true, 1),
|
_ => (true, 0),
|
||||||
_ => (true, 0),
|
};
|
||||||
};
|
let mut perform_step_2 = true;
|
||||||
let mut perform_step_2 = true;
|
if first_non_namespace == compound.len() - 1 {
|
||||||
if first_non_namespace == compound.len() - 1 {
|
match (combinators.peek(), &compound[first_non_namespace]) {
|
||||||
match (combinators.peek(), &compound[first_non_namespace]) {
|
// We have to be careful here, because if there is a
|
||||||
// We have to be careful here, because if there is a
|
// pseudo element "combinator" there isn't really just
|
||||||
// pseudo element "combinator" there isn't really just
|
// the one simple selector. Technically this compound
|
||||||
// the one simple selector. Technically this compound
|
// selector contains the pseudo element selector as well
|
||||||
// selector contains the pseudo element selector as well
|
// -- Combinator::PseudoElement, just like
|
||||||
// -- Combinator::PseudoElement, just like
|
// Combinator::SlotAssignment, don't exist in the
|
||||||
// Combinator::SlotAssignment, don't exist in the
|
// spec.
|
||||||
// spec.
|
(Some(&&Component::Combinator(Combinator::PseudoElement)), _) |
|
||||||
(Some(&&Component::Combinator(Combinator::PseudoElement)), _) |
|
(Some(&&Component::Combinator(Combinator::SlotAssignment)), _) => (),
|
||||||
(Some(&&Component::Combinator(Combinator::SlotAssignment)), _) => (),
|
(_, &Component::ExplicitUniversalType) => {
|
||||||
(_, &Component::ExplicitUniversalType) => {
|
// Iterate over everything so we serialize the namespace
|
||||||
// Iterate over everything so we serialize the namespace
|
// too.
|
||||||
// too.
|
for simple in compound.iter() {
|
||||||
for simple in compound.iter() {
|
simple.to_css(dest)?;
|
||||||
simple.to_css(dest)?;
|
}
|
||||||
}
|
// Skip step 2, which is an "otherwise".
|
||||||
// Skip step 2, which is an "otherwise".
|
perform_step_2 = false;
|
||||||
perform_step_2 = false;
|
},
|
||||||
},
|
(_, _) => (),
|
||||||
(_, _) => (),
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// 2. Otherwise, for each simple selector in the compound selectors
|
||||||
// 2. Otherwise, for each simple selector in the compound selectors
|
// that is not a universal selector of which the namespace prefix
|
||||||
// that is not a universal selector of which the namespace prefix
|
// maps to a namespace that is not the default namespace
|
||||||
// maps to a namespace that is not the default namespace
|
// serialize the simple selector and append the result to s.
|
||||||
// serialize the simple selector and append the result to s.
|
//
|
||||||
//
|
// See https://github.com/w3c/csswg-drafts/issues/1606, which is
|
||||||
// See https://github.com/w3c/csswg-drafts/issues/1606, which is
|
// proposing to change this to match up with the behavior asserted
|
||||||
// proposing to change this to match up with the behavior asserted
|
// in cssom/serialize-namespaced-type-selectors.html, which the
|
||||||
// in cssom/serialize-namespaced-type-selectors.html, which the
|
// following code tries to match.
|
||||||
// following code tries to match.
|
if perform_step_2 {
|
||||||
if perform_step_2 {
|
for simple in compound.iter() {
|
||||||
for simple in compound.iter() {
|
if let Component::ExplicitUniversalType = *simple {
|
||||||
if let Component::ExplicitUniversalType = *simple {
|
// Can't have a namespace followed by a pseudo-element
|
||||||
// Can't have a namespace followed by a pseudo-element
|
// selector followed by a universal selector in the same
|
||||||
// selector followed by a universal selector in the same
|
// compound selector, so we don't have to worry about the
|
||||||
// compound selector, so we don't have to worry about the
|
// real namespace being in a different `compound`.
|
||||||
// real namespace being in a different `compound`.
|
if can_elide_namespace {
|
||||||
if can_elide_namespace {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
simple.to_css(dest)?;
|
|
||||||
}
|
}
|
||||||
|
simple.to_css(dest)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue