Commit graph

261 commits

Author SHA1 Message Date
Emilio Cobos Álvarez
572a93142f
style: Add diagnostics.
Bug: 1416282
Reviewed-by: xidorn
MozReview-Commit-ID: GTnFyZnXR84
2018-06-12 12:15:16 -07:00
Emilio Cobos Álvarez
8821ad72f4
style: Make pseudo-elements work with :host.
Imported WebKit's test as a WPT.

Bug: 1465291
Reviewed-by: xidorn
MozReview-Commit-ID: 19ZThuoqKLW
2018-06-12 12:15:10 -07:00
Xidorn Quan
09b22ab2dc
style: Allow 16% false positives in test bloom::create_and_insert_some_stuff.
It seems that the result of hash algorithm used in bloom filter depends
on the pointer length. On 64bit platforms, there are 135 false positives
in the first part of that test, and 8 in the second part. However, on
32bit platforms, the numbers become 157 and 16 correspondingly.

16 is still less than 20% in the second part, so all fine, but 157 is
slightly larger than 15% in the test assertion. Given it is what we are
shipping, we probably should just accept this and loosen the assertion.

Bug: 1457524
Reviewed-by: heycam
MozReview-Commit-ID: 9kFXBzLFAzE
2018-05-05 16:22:47 +02:00
Bobby Holley
c99bcdd4b8 Run rustfmt on selectors, servo_arc, and style.
This was generated with:

./mach cargo fmt --package selectors &&
./mach cargo fmt --package servo_arc &&
./mach cargo fmt --package style

Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
2018-04-10 17:35:15 -07:00
Bobby Holley
f7ae1a37e3 Manual fixups so that the rustfmt output won't trigger tidy. 2018-04-10 17:33:25 -07:00
Emilio Cobos Álvarez
eaefaa890e
style: Implement the functional :host(..) selector.
We could invalidate in a slightly more fine-grained way, but I don't think it's
worth the churn vs. keeping the special-cases minimal.

Bug: 1452640
Reviewed-by: xidorn
MozReview-Commit-ID: 5DkQrgwg9GW
2018-04-10 08:04:09 +02:00
Emilio Cobos Álvarez
db5db13559
style: Implement the non-functional :host selector.
Kinda tricky because :host only matches rules on the shadow root where the rules
come from. So we need to be careful during invalidation and style sharing.

I didn't use the non_ts_pseudo_class_list bits because as soon as we implement
the :host(..) bits we're going to need to special-case it anyway.

The general schema is the following:

 * Rightmost featureless :host selectors are handled inserting them in the
   host_rules hashmap. Note that we only insert featureless stuff there. We
   could insert all of them and just filter during matching, but that's slightly
   annoying.

 * The other selectors, like non-featureless :host or what not, are added to the
   normal cascade data. This is harmless, since the shadow host rules are never
   matched against the host, so we know they'll just never match, and avoids
   adding more special-cases.

 * Featureless :host selectors to the left of a combinator are handled during
   matching, in the special-case of next_element_for_combinator in selectors.
   This prevents this from being more invasive, and keeps the usual fast path
   slim, but it's a bit hard to match the spec and the implementation.

   We could keep a copy of the SelectorIter instead in the matching context to
   make the handling of featureless-ness explicit in match_non_ts_pseudo_class,
   but we'd still need the special-case anyway, so I'm not fond of it.

 * We take advantage of one thing that makes this sound. As you may have
   noticed, if you had `root` element which is a ShadowRoot, and you matched
   something like `div:host` against it, using a MatchingContext with
   current_host == root, we'd incorrectly report a match. But this is impossible
   due to the following constraints:

    * Shadow root rules aren't matched against the host during styling (except
      these featureless selectors).

    * DOM APIs' current_host needs to be the _containing_ host, not the element
      itself if you're a Shadow host.

Bug: 992245
Reviewed-by: xidorn
MozReview-Commit-ID: KayYNfTXb5h
2018-04-09 12:19:05 +02:00
Emilio Cobos Álvarez
1eab5927a5
selectors: Don't serialize :nth-child(-n) as -1n. 2018-04-07 14:54:23 +02:00
bors-servo
d232705106
Auto merge of #20454 - emilio:rustup, r=SimonSapin
Update to rust version 1.26.0-nightly (188e693b3 2018-03-26)

<!-- 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/20454)
<!-- Reviewable:end -->
2018-03-29 09:12:45 -04:00
Bastien Orivel
0918ac8cc7 Bump env_logger to 0.5 and log to 0.4 in every servo crate 2018-03-28 19:50:58 +02:00
Emilio Cobos Álvarez
48ad41cfb5
Remove useless AsciiExt imports.
These warn with the next Nightly.
2018-03-27 10:30:02 +02:00
Emilio Cobos Álvarez
9fa2618197
style: Add infrastructure to match :host. 2018-03-14 15:10:05 +01:00
Emilio Cobos Álvarez
1654f297ca
style: Tidy a couple things. 2018-03-14 15:10:05 +01:00
Emilio Cobos Álvarez
01e8a9bd35
style: Change the order we match selectors on invalidation to match normal order.
This changes the order to match the normal selector-matching order, which is
usually faster.

That is, when matching div:nth-child(2), for example, before this patch we'd
first try to match :nth-child(2), and only then div.

This patch makes us walk until the end or the next combinator, and only then
match backwards, matching first div, then :nth-child.

Bug: 1443814
Reviewed-by: bholley
2018-03-09 00:10:16 +01:00
Emilio Cobos Álvarez
76dd4ae05e
style: Reindent yet another function. 2018-02-24 22:45:53 +01:00
Emilio Cobos Álvarez
adf1c9fcfd
selectors: Indent two function declarations. 2018-02-24 22:45:39 +01:00
Emilio Cobos Álvarez
7ab4b21bc3
selectors: Remove the get_ prefix from get_local_name and get_namespace. 2018-02-24 22:45:38 +01:00
Emilio Cobos Álvarez
61e60a87e5
selectors: Never match ::slotted on <slot>s.
This fixes the test from https://github.com/w3c/web-platform-tests/pull/9212 in
Gecko.
2018-01-27 17:57:17 +01:00
bors-servo
6fc71a7644 Auto merge of #19822 - emilio:less-match-public, r=KiChjang
style: More tiny selector-matching cleanup

See each commit individually.

<!-- 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/19822)
<!-- Reviewable:end -->
2018-01-19 23:05:18 -06:00
Emilio Cobos Álvarez
c384c21cb6
style: Make the MatchingMode in MatchingContext private.
It used to be the case that MatchingContext was immutable and thus we didn't
care to have accessors.

This is no longer true, so let's make this code a bit nicer.
2018-01-20 02:26:59 +01:00
Emilio Cobos Álvarez
e74fad6259
style: Handle correctly document state invalidation inside negation. 2018-01-20 02:10:57 +01:00
bors-servo
0d7d02fca7 Auto merge of #19817 - emilio:matching-context-visited, r=nox
style: Track the visited-handling-mode on the MatchingContext.

This fixes bugs where we're not passing the value around correctly, like from
::-moz-any.

This is a fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1431539.

<!-- 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/19817)
<!-- Reviewable:end -->
2018-01-19 12:50:00 -06:00
Emilio Cobos Álvarez
9f00a2fdc0
selectors: add an is_nested method to MatchingContext, instead of nesting_level. 2018-01-19 13:32:44 +01:00
Emilio Cobos Álvarez
8e25c9e674
style: Track the visited-handling-mode on the MatchingContext.
Instead of on the stack.

This fixes bugs where we're not passing the value around correctly, like from
::-moz-any.

This is a fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1431539.
2018-01-19 13:22:37 +01:00
Emilio Cobos Álvarez
e4f08ee2bb
selectors: Add a MatchingContext::nest function, make nesting_level private. 2018-01-19 12:40:17 +01:00
Emilio Cobos Álvarez
88d2982e23
style: Convert matches_hover_and_active_quirk to an enum.
This is in preparation of a bit of refactoring in selectors too.
2018-01-19 12:18:54 +01:00
Emilio Cobos Álvarez
bbe7ff86da
selectors: Simplify SelectorIter::next. 2018-01-18 23:50:03 +01:00
Xidorn Quan
d0fd92221c Optimize selector matching for some common cases. 2018-01-17 09:46:57 +11:00
Simon Sapin
befadc563a Prepare to publish selectors 0.19.0 to crates.io 2018-01-12 18:13:50 +01:00
Simon Sapin
358bac953d Move Visit trait bounds to where they’re needed 2018-01-12 15:44:07 +01:00
Simon Sapin
1a6010f19f Document selectors::Visit 2018-01-12 15:40:16 +01:00
Simon Sapin
c14b766ff5 Rename SelectorMethods to Visit, after its one method. 2018-01-12 15:26:56 +01:00
Simon Sapin
79f93cfb5b The selectors crate has had many contributors 2018-01-12 15:11:00 +01:00
Simon Sapin
116a6de59c Make OpaqueElement’s field private.
It’s not used anywhere, and this reduces the public API surface.
2018-01-12 15:11:00 +01:00
Simon Sapin
7d1dc7286a Move selectors size_of tests to Stylo tests 2018-01-12 15:10:56 +01:00
Simon Sapin
5d920df460 Move PrecomputedHash bounds to where they’re actually needed. 2018-01-12 15:10:47 +01:00
Simon Sapin
b0003f77e4 Prepare servo_arc for publication on crates.io 2018-01-12 15:10:44 +01:00
Simon Sapin
5a82a1d455 Reverse the dependency between selectors and malloc_size_of 2018-01-12 15:10:04 +01:00
Simon Sapin
0929f72709 Re-enable selectors doctests
Closes #16710, which was actually fixed by
6dff251e35 in #19395.
This exercises that fix.

Green AppVeyor build: https://ci.appveyor.com/project/servo/servo/build/1.0.24124
2018-01-12 14:42:38 +01:00
Emilio Cobos Álvarez
335ca47361
style: Use Default for ExtraStyleData instead of Option. 2018-01-12 12:08:47 +01:00
Emilio Cobos Álvarez
1e27f2883b
selectors: Allow defining an implementation-dependent field in the matching context. 2018-01-12 12:08:38 +01:00
Emilio Cobos Álvarez
5115cbd1c0
style: Store ::slotted rules separately on the cascade data, since they may cross the shadow boundary.
MozReview-Commit-ID: EY9nK3169vv
2018-01-09 14:26:02 +01:00
Emilio Cobos Álvarez
b556ddbf55
style: Don't support a list of selectors in ::slotted yet.
Bug: 1425757
Reviewed-by: xidorn
MozReview-Commit-ID: G0I0gM2sWTh
2017-12-20 15:55:09 +01:00
bors-servo
370f5acf6d Auto merge of #19558 - emilio:sadness, r=heycam
selectors: Manually inline any(..) in matches_selector_list.

Since the compiler refuses to inline the inner closure even with -O3, which is
sad :(.

Sad try run:

  https://treeherder.mozilla.org/perf.html#/compare?originalProject=try&originalRevision=c2724c47e98f990826327da05220cd83b772d144&newProject=try&newRevision=52ac88b40a08a5ef6a629bd681f2e5a444b75f54&framework=1

<!-- 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/19558)
<!-- Reviewable:end -->
2017-12-14 10:19:23 -06:00
Emilio Cobos Álvarez
ddd3d126e9
selectors: Manually inline any(..) in matches_selector_list.
Since the compiler refuses to inline the inner closure even with -O3, which is
sad :(.

Sad try run:

  https://treeherder.mozilla.org/perf.html#/compare?originalProject=try&originalRevision=c2724c47e98f990826327da05220cd83b772d144&newProject=try&newRevision=52ac88b40a08a5ef6a629bd681f2e5a444b75f54&framework=1
2017-12-14 06:32:48 +01:00
Emilio Cobos Álvarez
7886e033aa
selectors: Add parsing support for ::slotted().
Without turning it on yet, of course.

The reason why I didn't use the general PseudoElement mechanism is because this
pseudo is a bit of its own thing, and I found easier to make ::selectors know
about it (because you need to jump to the assigned slot) than the other way
around.

Also, we need to support ::slotted(..)::before and such, and supporting multiple
pseudo-elements like that breaks some other invariants around the SelectorMap,
and fixing those would require special-casing slotted a lot more in other parts
of the code.

Let me know if you think otherwise.

I also don't like much the boolean tuple return value, but I plan to do some
cleanup in the area in a bit, so it should go away soon, I'd hope.
2017-12-14 06:28:11 +01:00
bors-servo
c6bf85eca9 Auto merge of #19536 - emilio:compound-selector-list, r=mbrubeck
style: Move the code to parse a list of compound selectors.

I'll need this for ::slotted().

<!-- 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/19536)
<!-- Reviewable:end -->
2017-12-09 17:15:14 -06:00
Emilio Cobos Álvarez
b1f25a2b1f
style: Move the code to parse a list of compound selectors.
I'll need this for ::slotted().
2017-12-09 16:47:37 +01:00
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
Emilio Cobos Álvarez
3119db724a
selectors: Simplify :visited by only using the "is inside link" information.
Right now we go through a lot of hoops to see if we ever see a relevant link.

However, that information is not needed: if the element is a link, we'll always
need to compute its visited style because its its own relevant link.

If the element inherits from a link, we need to also compute the visited style
anyway.

So the "has a relevant link been found" is pretty useless when we know what are
we inheriting from.

The branches at the beginning of matches_complex_selector_internal were
affecting performance, and there are no good reasons to keep them.

I've verified that this passes all the visited tests in mozilla central, and
that the test-cases too-flaky to be landed still pass.
2017-12-08 05:35:12 +01:00