Commit graph

145 commits

Author SHA1 Message Date
Bobby Holley
5a421d7c5f Use drain() over IntoIter on a few SmallVecs.
This is all the ones I could find in style/ and selectors/.
2017-08-02 15:42:57 -07:00
Corey Farwell
befe538472 Utilize match_ignore_ascii_case! in more places. 2017-07-29 09:58:09 +00:00
Emilio Cobos Álvarez
a885655210
selectors: Fix note_next_sequence.
Selector-matching can backtrack when looking for ancestor combinators, so we
can't just arrive there once and forget.

Also, there was a further problem before this patch, which was that
note_next_sequence was called _before_ checking whether all simple selectors
matched, so the sequence you could get there is just wrong.

Bug: 1384020
Reviewed-by: canaltinova
MozReview-Commit-ID: 6g0ibb8EfBU
2017-07-26 00:28:11 +02:00
Simon Sapin
eb98ae6e04 Update cssparser to 0.18
https://github.com/servo/rust-cssparser/pull/171
2017-07-24 11:39:12 +02:00
Emilio Cobos Álvarez
f879ebcc99
selectors: Don't track class and id ancestor hashes in quirks mode.
It's incorrect to track classes and id selectors in a quirks-mode document,
since they should match case-insensitively.

Bug: 1382812
Reviewed-by: bholley
MozReview-Commit-ID: 4uvrfYsWb1v
2017-07-20 22:42:35 +02:00
bors-servo
81f6b9a1c7 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 -->
2017-07-19 03:59:50 -07:00
Jonathan Chan
f0e83f6d8a Simplify <an+b> in selector args when serializing. 2017-07-18 11:53:52 -07:00
Jonathan Chan
1301bcdf10 Omit serializing the universal selector when possible.
If omitting the universal selector in the serialization is possible, we
should do it so we obtain a shorter serialization (to match the behavior
asserted in cssom/serialize-namespaced-type-selectors.html).

For example, if someone writes *|*::before and there is no default
namespace, we should serialize to ::before; however, if there is a
default namespace, we should serialize to *|*::before.
(This is the test case "Universal selector in any namespace followed by
pseudo element).

This matches the behavior implemented by WebKit; that one case in
particular isn't implemented by Gecko, but other cases where the
universal selector should be elided are implemented by Gecko but were not
previously by Servo.
2017-07-17 10:52:17 -07:00
Jonathan Chan
989b707623 Elide the explicit any namespace prefix when lacking default namespace.
Once again it seems we don't need to preserve the original prefix name,
and this lets to_css serialize to the shortest form when there is no
default namespace and the *| prefix is used.

Selectors § 6.1.1 says:

    Element type selectors that have no namespace component (no namespace
    separator) represent elements without regard to the element's namespace
    (equivalent to "*|") unless a default namespace has been declared for
    namespaced selectors (e.g. in CSS, in the style sheet). If a default
    namespace has been declared, such selectors will represent only elements
    in the default namespace.

Then if there is no default namespace, *| (which we write as
QNamePrefix::ExplicitAnyNamespace) is equivalent to what we write as
QNamePrefix::ImplicitAnyNamespace; the latter has a shorter
serialization, so we should use that.
2017-07-17 10:43:24 -07:00
Jonathan Chan
bd5ff3b4ce Replace Namespace components which map to the default namespace with DefaultNamespace.
It seems we don't need to preserve the original prefix name, and this
conveniently leads to_css to now implement CSSOM's requirement to elide
the namespace prefix during serialization when it maps to the default
namespace.

https://drafts.csswg.org/cssom/#serialize-a-simple-selector
2017-07-14 12:19:03 -07:00
Emilio Cobos Álvarez
445b8fb3e8
style: Remove SelectorAndHashes. 2017-07-13 05:44:55 +02:00
Emilio Cobos Álvarez
dee4aea264
style: Remove hashes from style rules and dependencies.
Dependencies are very numerous, and now we shouldn't be getting so many of them.

Style rules just don't need them, so it's a waste of memory.
2017-07-13 05:44:53 +02:00
bors-servo
4b6e79337e Auto merge of #17538 - jyc:selectorText, r=Manishearth
Implement CSSStyleRule.selectorText.

We parse when assigning using the namespaces of the stylesheet. It isn't
clear if the spec says to do that (Firefox doesn't support the setter at
all, Chrome does, Safari doesn't); the spec issue is here:
https://github.com/w3c/csswg-drafts/issues/1511

Also fix ToCss implementation of AttrSelectorOperator to not pad with
spaces, to conform with CSSOM. This means we have to update some unit
tests that expect operators with spaces around them in attribute
selectors to roundtrip.

See the "attribute selector" section of "Serializing Selectors" here:
https://drafts.csswg.org/cssom/#serializing-selectors

CSSStyleRule.selectorText is specified here:
https://drafts.csswg.org/cssom/#dom-cssstylerule-selectortext

<!-- 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/17538)
<!-- Reviewable:end -->
2017-07-12 11:08:35 -07:00
bors-servo
ce52c16a8f Auto merge of #17687 - upsuper:tree-pseudo, r=heycam
Support parsing ::-moz-tree-* pseudo-elements selector

This is the Servo side change of [bug 1348488](https://bugzilla.mozilla.org/show_bug.cgi?id=1348488).

<!-- 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/17687)
<!-- Reviewable:end -->
2017-07-12 03:35:37 -07:00
Xidorn Quan
441487cec2 Update test in selectors to match types for Gecko. 2017-07-12 20:33:13 +10:00
Jonathan Chan
92ec8f15f0 Implement CSSStyleRule.selectorText.
We parse when assigning using the namespaces of the stylesheet. It isn't
clear if the spec says to do that (Firefox doesn't support the setter at
all, Chrome does, Safari doesn't); the spec issue is here:
https://github.com/w3c/csswg-drafts/issues/1511

Also fix ToCss implementation of AttrSelectorOperator to not pad with
spaces, to conform with CSSOM. This means we have to update some unit
tests that expect operators with spaces around them in attribute
selectors to roundtrip.

See the "attribute selector" section of "Serializing Selectors" here:
https://drafts.csswg.org/cssom/#serializing-selectors

CSSStyleRule.selectorText is specified here:
https://drafts.csswg.org/cssom/#dom-cssstylerule-selectortext
2017-07-12 01:03:58 -07:00
Emilio Cobos Álvarez
6d6c80e79b
style: Remove StyleRelations.
They're unused now. We can add them back if needed.

MozReview-Commit-ID: 92Y2Na0ZbVn
2017-07-12 09:26:55 +02:00
Emilio Cobos Álvarez
95a2ac51c4
style: Remove unused AFFECTED_BY_PSEUDO_ELEMENTS StyleRelation.
MozReview-Commit-ID: yHldvHm87b
2017-07-12 08:39:25 +02:00
Xidorn Quan
38577fd6ee Allow selector parser to specify pseudo-element which can be used with single-colon syntax. 2017-07-12 15:07:25 +10:00
Xidorn Quan
706d54401e Add functional pseudo-element support to selectors crate. 2017-07-12 15:07:24 +10:00
Xidorn Quan
d138fd1a32 Slightly simplify parse_one_simple_selector. 2017-07-12 15:07:22 +10:00
bors-servo
8fa2a262dc Auto merge of #17658 - emilio:nesting-level, r=bholley
selectors: Avoid looking at MatchingMode if the selector isn't the topmost.

Also, switch the hover quirk to the same mechanism.

Bug: 1379696
Reviewed-By: bholley
MozReview-Commit-ID: KrmNqNyASf6

<!-- 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/17658)
<!-- Reviewable:end -->
2017-07-10 19:16:35 -07:00
Emilio Cobos Álvarez
1f2b79bc30
selectors: Avoid looking at MatchingMode if the selector isn't the topmost.
Also, switch the hover quirk to the same mechanism.

Bug: 1379696
Reviewed-By: bholley
MozReview-Commit-ID: KrmNqNyASf6
2017-07-11 03:52:07 +02:00
Josh Matthews
0b43d0072c stylo: Update rust-cssparser; extract more specific error types when reporting (bug 1352669). 2017-07-10 20:46:12 -04:00
Gecko Backout
32269fa7cc Backed out changeset fec394734f83 (bug 17624) for build bustage a=backout CLOSED TREE
Backs out https://github.com/servo/servo/pull/17624
2017-07-06 21:58:15 +00:00
Josh Matthews
f5a3830ea2 stylo: Update rust-cssparser; extract more specific error types when reporting (bug 1352669). 2017-07-06 14:32:37 -04:00
Simon Sapin
7e0254b530 Drive-by fix "unused import" warning. 2017-07-05 13:58:06 +02:00
Matt Wismer
288143fadf Correct bloom hash bitpacking documentation
The two 12 bit keys add to 24 bits, which leaves 8 bits free in each word. (And 8 * 3 = 24, to pack in the fourth hash.)
2017-06-22 21:26:14 -04:00
bors-servo
efed75ae5a Auto merge of #17484 - canaltinova:upup, r=emilio
Bump cssparser version to 0.16.1 in toml files

<!-- 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

<!-- 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/17484)
<!-- Reviewable:end -->
2017-06-22 16:52:00 -07:00
Nazım Can Altınova
5362c5ee74 Bump cssparser version to 0.16.1 in toml files 2017-06-22 15:44:03 -07:00
Bobby Holley
71e76a054d Be smarter when clearing the bloom filter. 2017-06-21 19:53:16 -07:00
Bobby Holley
28c35ac9df Improve bloom microbenchmarks.
The current code is mostly bechmarking Rust's default hash routines for
integers, which is not interesting to us. We add generating function
that jumps around "enough" and also add benchmarks for clear().

It's hard to read too much into the numbers because we can't reliably
simulate L1/L2 cache behavior with cargo bench, but the results show
about 40ns for clear() about 2ns for insert, and about 1.5ns for
contains/remove. This informs our thinking in the next patch.
2017-06-21 19:53:15 -07:00
Bobby Holley
5b857686e2 Make selectors benchmark tests work again. 2017-06-21 19:53:15 -07:00
Simon Sapin
7f4c846321 Less unsafe in selectors::builder.
MozReview-Commit-ID: 7IIyio8WAa7
2017-06-20 11:59:11 -07:00
Bobby Holley
1104cdc580 Invert the order of each compound selector.
MozReview-Commit-ID: JkBjqyYgbrB
2017-06-20 11:59:11 -07:00
Bobby Holley
1fc1d64e80 Hoist specificity computation into a new private builder module.
This patch doesn't modify any of the code because making a few things pub. I
did this first to make the next patch easier to audit.

MozReview-Commit-ID: 7PYxoS5bVGN
2017-06-20 11:59:11 -07:00
Bobby Holley
1d242ad760 Store selectors in matching order, rather than parse order.
We add a slow in-place reverse during parsing to achieve this for now, which
gets fixed up later on.

MozReview-Commit-ID: 42QkOzSgV3T
2017-06-20 11:59:10 -07:00
Bobby Holley
fac5aeb092 Stop creating unnecessarily-large SmallVecs for specific tasks.
MozReview-Commit-ID: IM9aAjSeJI9
2017-06-20 11:59:10 -07:00
Bobby Holley
db8f59407f Hoist sink into selectors.
It probably makes more sense (eventually) to put it in SmallVec.

MozReview-Commit-ID: AIBKCLiMNN2
2017-06-20 11:59:10 -07:00
Bobby Holley
2159d48382 Stop using parse_compound_selector for negation parsing.
This makes the code easier to work with, and fixes a bug where we don't currently
reject pseudo-elements within :not().

MozReview-Commit-ID: Cgl9w0PBsN3
2017-06-20 11:59:09 -07:00
cku
727725ac3d Stylo: Correct style match for element instances under a use-element tree. 2017-06-20 18:07:36 +08:00
Simon Sapin
316cd35767 Untry 2017-06-18 13:21:51 +02:00
Simon Sapin
b83afdedc8 Upgrade cssparser to 0.15 2017-06-16 15:05:46 +02:00
Bastien Orivel
76d8573393 Bump serde to 1.0 2017-06-16 13:31:18 +02:00
Nazım Can Altınova
57d02dc0e9
Handle PseudoElement case in :active and :hover quirk 2017-06-13 17:22:39 +03:00
Emilio Cobos Álvarez
4434509088
style: Add an AllLinksVisitedAndUnvisited for invalidation.
Otherwise, tests like the following fail, given we always match as unvisited,
and we'd never mark the link as needing invalidation.

<!doctype html>
<style>
a {
  color: red !important;
}

.foo :visited {
  color: green !important;
}
</style>
<div>
  <a href="https://google.es">visit me</a>
  <button onclick="this.parentNode.className = 'foo'">Then click me</button>
</div>

Bug: 1368240
MozReview-Commit-ID: LDv6S28c4ju
2017-06-13 13:27:06 +02:00
Emilio Cobos Álvarez
151b636562
style: Add a way to match a single compound selector.
Also improve the ergonomics of matches_complex_selector.

Bug: 1368240
MozReview-Commit-ID: 9DWDvyZmetM
2017-06-13 10:58:47 +02:00
Simon Sapin
b82713924c Pre-compute classes and IDs case-sensitivity 2017-06-13 00:36:12 +02:00
Simon Sapin
9316c41bf7 Make MatchingContext::quirks_mode field private, add read-only accessor. 2017-06-13 00:35:56 +02:00
Simon Sapin
700aaf2bd6 Move MatchingContext to a new module 2017-06-13 00:31:29 +02:00