mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Auto merge of #17539 - jyc:simplify-an-b, r=emilio
Simplify <an+b> in selector args when serializing. <!-- Please describe your changes on the following line: --> --- <!-- 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 - [X] These changes is part of a series to fix #17182 <!-- Either: --> I am running this to identify what tests will fail; as the other PRs in the series are merged, I believe the tests that pass will change as well. - [ ] 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/17539) <!-- Reviewable:end -->
This commit is contained in:
commit
81f6b9a1c7
3 changed files with 28 additions and 37 deletions
|
@ -871,6 +871,23 @@ impl ToCss for Combinator {
|
||||||
impl<Impl: SelectorImpl> ToCss for Component<Impl> {
|
impl<Impl: SelectorImpl> ToCss for Component<Impl> {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
use self::Component::*;
|
use self::Component::*;
|
||||||
|
|
||||||
|
/// Serialize <an+b> values (part of the CSS Syntax spec, but currently only used here).
|
||||||
|
/// https://drafts.csswg.org/css-syntax-3/#serialize-an-anb-value
|
||||||
|
fn write_affine<W>(dest: &mut W, a: i32, b: i32) -> fmt::Result where W: fmt::Write {
|
||||||
|
match (a, b) {
|
||||||
|
(0, 0) => dest.write_char('0'),
|
||||||
|
|
||||||
|
(1, 0) => dest.write_char('n'),
|
||||||
|
(_, 0) => write!(dest, "{}n", a),
|
||||||
|
|
||||||
|
(0, _) => write!(dest, "{}", b),
|
||||||
|
(1, _) => write!(dest, "n{:+}", b),
|
||||||
|
(-1, _) => write!(dest, "-n{:+}", b),
|
||||||
|
(_, _) => write!(dest, "{}n{:+}", a, b),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Combinator(ref c) => {
|
Combinator(ref c) => {
|
||||||
c.to_css(dest)
|
c.to_css(dest)
|
||||||
|
@ -935,10 +952,17 @@ impl<Impl: SelectorImpl> ToCss for Component<Impl> {
|
||||||
FirstOfType => dest.write_str(":first-of-type"),
|
FirstOfType => dest.write_str(":first-of-type"),
|
||||||
LastOfType => dest.write_str(":last-of-type"),
|
LastOfType => dest.write_str(":last-of-type"),
|
||||||
OnlyOfType => dest.write_str(":only-of-type"),
|
OnlyOfType => dest.write_str(":only-of-type"),
|
||||||
NthChild(a, b) => write!(dest, ":nth-child({}n{:+})", a, b),
|
NthChild(a, b) | NthLastChild(a, b) | NthOfType(a, b) | NthLastOfType(a, b) => {
|
||||||
NthLastChild(a, b) => write!(dest, ":nth-last-child({}n{:+})", a, b),
|
match *self {
|
||||||
NthOfType(a, b) => write!(dest, ":nth-of-type({}n{:+})", a, b),
|
NthChild(_, _) => dest.write_str(":nth-child(")?,
|
||||||
NthLastOfType(a, b) => write!(dest, ":nth-last-of-type({}n{:+})", a, b),
|
NthLastChild(_, _) => dest.write_str(":nth-last-child(")?,
|
||||||
|
NthOfType(_, _) => dest.write_str(":nth-of-type(")?,
|
||||||
|
NthLastOfType(_, _) => dest.write_str(":nth-last-of-type(")?,
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
write_affine(dest, a, b)?;
|
||||||
|
dest.write_char(')')
|
||||||
|
}
|
||||||
NonTSPseudoClass(ref pseudo) => pseudo.to_css(dest),
|
NonTSPseudoClass(ref pseudo) => pseudo.to_css(dest),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
[selectorSerialize.htm]
|
|
||||||
type: testharness
|
|
||||||
[:nth-child serialization produces canonical form]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[single pseudo (simple) selector "nth-child" which accepts arguments in the sequence of simple selectors that is not a universal selector]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[single pseudo (simple) selector "nth-last-child" which accepts arguments in the sequence of simple selectors that is not a universal selector]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[single pseudo (simple) selector "nth-of-child" which accepts arguments in the sequence of simple selectors that is not a universal selector]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[single pseudo (simple) selector ":nth-last-of-type" which accepts arguments in the sequence of simple selectors that is not a universal selector]
|
|
||||||
expected: FAIL
|
|
|
@ -1,17 +0,0 @@
|
||||||
[selectorSerialize.html]
|
|
||||||
type: testharness
|
|
||||||
[:nth-child serialization produces canonical form]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[single pseudo (simple) selector "nth-child" which accepts arguments in the sequence of simple selectors that is not a universal selector]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[single pseudo (simple) selector "nth-last-child" which accepts arguments in the sequence of simple selectors that is not a universal selector]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[single pseudo (simple) selector "nth-of-child" which accepts arguments in the sequence of simple selectors that is not a universal selector]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[single pseudo (simple) selector ":nth-last-of-type" which accepts arguments in the sequence of simple selectors that is not a universal selector]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue