Commit graph

162 commits

Author SHA1 Message Date
Emilio Cobos Álvarez
bf564e0238
style: Simplify naming and signatures of single-colon pseudo stuff.
Also drop a few FIXMEs while at it, since they look bogus.
2017-12-09 16:12:22 +01:00
Cameron McCormack
523ffd587d selectors: Allow white space in the brackets of an attribute selector. 2017-11-18 14:47:33 +08:00
Emilio Cobos Álvarez
28c04278e1
style: Sprinkle some inline in trivial methods.
These methods are instantiated by the Gecko library, and used during
querySelector, which means that they end up being super-hot in micro-benchmarks.

MozReview-Commit-ID: K1XJb0QyX5a
2017-11-15 13:45:32 +01:00
Simon Sapin
954b2cc3d8
Allow unused imports for AsciiExt in style code.
See #19128, this part is cherry-picked so Gecko can build with rust nightly.
2017-11-09 12:43:23 +01:00
Emilio Cobos Álvarez
e1aa829d67
selectors: Reformat signatures in the parser module.
I was doing something unrelated with this code, and each signature uses a
different style. This PR unifies them.
2017-10-22 16:33:04 +02:00
Matt Brubeck
efc3683cc7 Fix commonmark Markdown warnings in docs, part 1
Fixes warnings from rust-lang/rust#44229 when `--enable-commonmark` is
passed to rustdoc.

This is mostly a global find-and-replace for bare URIs on lines by
themselves in doc comments.
2017-10-17 11:24:57 -07:00
Emilio Cobos Álvarez
f1cc225e97
style: Use left-to-right indices in the invalidator.
This will make easier to create external invalidations, and also makes reasoning
about the invalidator a bit easier.
2017-10-16 08:54:00 +02:00
Simon Sapin
46ea99d54b CSS parsing error types: flatten nested enums somewhat 2017-10-10 13:28:30 +02:00
Simon Sapin
c0f8f15f39 Update to cssparser 0.22 (source location in error types) 2017-10-10 13:28:17 +02:00
Xidorn Quan
ab46a0bbe0 Add support for :scope pseudo-class 2017-10-09 22:04:08 +11:00
Nicholas Nethercote
32548e5312 Overhaul MallocSizeOf and related things.
This patch makes the MallocSizeOf stuff in Stylo work more like the HeapSizeOf
stuff already in Servo, except better. In particular, it adds deriving support
for MallocSizeOf, which will make it easier to improve coverage.

The patch does the following.

- Combines servo/components/style/stylesheets/memory.rs and the heapsize crate
  into a new crate, malloc_size_of.

- Forks the heapsize_derive crate, calling it malloc_size_of, so that
  MallocSizeOf can be derived.

- Both the new crates have MIT/Apache licenses, like heapsize, in case they are
  incorporated into heapsize in the future.

- Renames the methods within MallocSizeOf and the related traits so they are
  more concise.

- Removes MallocSizeOfWithGuard.

- Adds `derive(MallocSizeOf)` to a lot of types, in some cases replacing an
  equivalent or almost-equivalent hand-written implementation.

- Adds stuff so that Rc/Arc can be handled properly.
2017-09-12 12:37:51 +10:00
Nicholas Nethercote
61877b7316 Measure selectors.
This patch adds measurement of Selectors within StyleRule. This requires
exposing the pointer within ThinArc.

The patch also adds measurement of the several CssRule variants, in order to
measure nested CssRules (and PropertyDeclarationBlocks) within them:
DocumentRule, MediaRule, PageRule, SupportsRule.
2017-09-07 15:01:11 +10:00
Josh Matthews
3ae7781b5f Use a 1-element smallvec for selector lists. 2017-09-06 12:13:40 -07:00
Brad Werth
51f3a16e19 Bug 1391169 Part 1: Servo-side change Selector to_css function to handle combinators in between universal selectors.
MozReview-Commit-ID: EyVrSAICPm
2017-09-01 09:03:04 -07:00
Josh Matthews
4016371e1d Report more invalid selectors (bug 1384216). 2017-08-28 17:21:57 -07:00
Josh Matthews
9a7cceb0a1 Report invalid selectors (bug 1384216). 2017-08-28 17:21:07 -07:00
Josh Matthews
408c34a76d Report more specific invalid attribute selectors (bug 1384216). 2017-08-28 17:20:45 -07:00
Josh Matthews
73e903ad3c Report unexpected attribute selector tokens (bug 1384216). 2017-08-28 17:20:17 -07:00
Josh Matthews
8e20a6a110 Report unknown pseudos (bug 1384216). 2017-08-28 17:19:28 -07:00
Simon Sapin
dc5dfafbba Use Parser::skip_whitespace in a few places to make Parser::try rewind less.
Gecko’s CSS parsing microbenchmarks before:

```
  43.437 ±  0.391 ms    Stylo.Servo_StyleSheet_FromUTF8Bytes_Bench
  29.244 ±  0.042 ms    Stylo.Gecko_nsCSSParser_ParseSheet_Bench
 281.884 ±  0.028 ms    Stylo.Servo_DeclarationBlock_SetPropertyById_Bench
 426.242 ±  0.008 ms    Stylo.Servo_DeclarationBlock_SetPropertyById_WithInitialSpace_Bench
```

After:

```
  29.779 ±  0.254 ms    Stylo.Servo_StyleSheet_FromUTF8Bytes_Bench
  28.841 ±  0.031 ms    Stylo.Gecko_nsCSSParser_ParseSheet_Bench
 296.240 ±  4.744 ms    Stylo.Servo_DeclarationBlock_SetPropertyById_Bench
 293.855 ±  4.304 ms    Stylo.Servo_DeclarationBlock_SetPropertyById_WithInitialSpace_Bench
```
2017-08-26 01:44:45 +02:00
bors-servo
69e28f0709 Auto merge of #18225 - jdm:unused-visitor-argument, r=emilio
Remove unused selector visitor argument.

The real win here is avoiding cloning the iterator when nobody actually uses it.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] There are tests for these changes

<!-- 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/18225)
<!-- Reviewable:end -->
2017-08-25 01:10:03 -05:00
Josh Matthews
ffa9dd1c7c Remove unused selector visitor argument. 2017-08-24 18:17:25 -07:00
Clément DAVID
c5fe235112 order derivable traits lists
Ignoring :
 - **generated**.rs
 - python/tidy/servo_tidy_tests/rust_tidy.rs
2017-08-23 21:38:44 +02:00
Simon Sapin
b5a4b8d6a0 Upgrade to rustc 1.21.0-nightly (13d94d5fa 2017-08-10) 2017-08-15 14:10:44 +02:00
Simon Sapin
7382dad939 Update to cssparser 0.19, count line numbers during tokenization 2017-08-09 22:37:16 +02:00
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
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
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
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
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
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
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