Bug 1391169 Part 1: Servo-side change Selector to_css function to handle combinators in between universal selectors.

MozReview-Commit-ID: EyVrSAICPm
This commit is contained in:
Brad Werth 2017-08-25 13:53:23 -07:00 committed by Brad Werth
parent 15c57e8d54
commit 51f3a16e19
2 changed files with 18 additions and 12 deletions

View file

@ -787,8 +787,8 @@ impl<Impl: SelectorImpl> ToCss for Selector<Impl> {
// 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, we continue to the next iteration of the // If we are in this case, after we have serialized the universal
// `for compound in compound_selectors` loop. // 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 |
@ -796,6 +796,7 @@ impl<Impl: SelectorImpl> ToCss for Selector<Impl> {
&Component::DefaultNamespace(_) => (true, 1), &Component::DefaultNamespace(_) => (true, 1),
_ => (true, 0), _ => (true, 0),
}; };
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 pseudo // We have to be careful here, because if there is a pseudo
@ -811,7 +812,8 @@ impl<Impl: SelectorImpl> ToCss for Selector<Impl> {
for simple in compound.iter() { for simple in compound.iter() {
simple.to_css(dest)?; simple.to_css(dest)?;
} }
continue // Skip step 2, which is an "otherwise".
perform_step_2 = false;
} }
(_, _) => (), (_, _) => (),
} }
@ -826,17 +828,19 @@ impl<Impl: SelectorImpl> ToCss for Selector<Impl> {
// 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.
for simple in compound.iter() { if perform_step_2 {
if let Component::ExplicitUniversalType = *simple { for simple in compound.iter() {
// Can't have a namespace followed by a pseudo-element if let Component::ExplicitUniversalType = *simple {
// selector followed by a universal selector in the same // Can't have a namespace followed by a pseudo-element
// compound selector, so we don't have to worry about the // selector followed by a universal selector in the same
// real namespace being in a different `compound`. // compound selector, so we don't have to worry about the
if can_elide_namespace { // real namespace being in a different `compound`.
continue if can_elide_namespace {
continue
}
} }
simple.to_css(dest)?;
} }
simple.to_css(dest)?;
} }
} }

View file

@ -25,4 +25,6 @@ fn test_selectors() {
assert_roundtrip!(parse_selector, "svg|circle"); assert_roundtrip!(parse_selector, "svg|circle");
assert_roundtrip!(parse_selector, "p:before", "p::before"); assert_roundtrip!(parse_selector, "p:before", "p::before");
assert_roundtrip!(parse_selector, "[border=\"0\"]:-servo-nonzero-border ~ ::-servo-details-summary"); assert_roundtrip!(parse_selector, "[border=\"0\"]:-servo-nonzero-border ~ ::-servo-details-summary");
assert_roundtrip!(parse_selector, "* > *");
assert_roundtrip!(parse_selector, "*|* + *", "* + *");
} }