Auto merge of #18344 - bradwerth:selectorSerialize, r=SimonSapin

Change selector::to_css function to handle combinators in between universal selectors.

https://bugzilla.mozilla.org/show_bug.cgi?id=1391169
https://reviewboard.mozilla.org/r/172368/

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18344)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-09-01 23:41:10 -05:00 committed by GitHub
commit fd95696d31
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 `::`
// both as combinators internally.
//
// If we are in this case, we continue to the next iteration of the
// `for compound in compound_selectors` loop.
// If we are in this case, after we have serialized the universal
// selector, we skip Step 2 and continue with the algorithm.
let (can_elide_namespace, first_non_namespace) = match &compound[0] {
&Component::ExplicitAnyNamespace |
&Component::ExplicitNoNamespace |
@ -796,6 +796,7 @@ impl<Impl: SelectorImpl> ToCss for Selector<Impl> {
&Component::DefaultNamespace(_) => (true, 1),
_ => (true, 0),
};
let mut perform_step_2 = true;
if first_non_namespace == compound.len() - 1 {
match (combinators.peek(), &compound[first_non_namespace]) {
// 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() {
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
// in cssom/serialize-namespaced-type-selectors.html, which the
// following code tries to match.
for simple in compound.iter() {
if let Component::ExplicitUniversalType = *simple {
// Can't have a namespace followed by a pseudo-element
// selector followed by a universal selector in the same
// compound selector, so we don't have to worry about the
// real namespace being in a different `compound`.
if can_elide_namespace {
continue
if perform_step_2 {
for simple in compound.iter() {
if let Component::ExplicitUniversalType = *simple {
// Can't have a namespace followed by a pseudo-element
// selector followed by a universal selector in the same
// compound selector, so we don't have to worry about the
// real namespace being in a different `compound`.
if can_elide_namespace {
continue
}
}
simple.to_css(dest)?;
}
simple.to_css(dest)?;
}
}