mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
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:
parent
15c57e8d54
commit
51f3a16e19
2 changed files with 18 additions and 12 deletions
|
@ -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,6 +828,7 @@ 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.
|
||||||
|
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
|
||||||
|
@ -839,6 +842,7 @@ impl<Impl: SelectorImpl> ToCss for Selector<Impl> {
|
||||||
simple.to_css(dest)?;
|
simple.to_css(dest)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 3. If this is not the last part of the chain of the selector
|
// 3. If this is not the last part of the chain of the selector
|
||||||
// append a single SPACE (U+0020), followed by the combinator
|
// append a single SPACE (U+0020), followed by the combinator
|
||||||
|
|
|
@ -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, "*|* + *", "* + *");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue