Commit graph

127 commits

Author SHA1 Message Date
Emilio Cobos Álvarez
31e8e418ea Miscellaneous build / tidy fixes. 2021-02-26 17:53:55 +01:00
Mihai Alexandru Michis
e9c1d490a9 style: Fix lint error in matching.rs a=lint-fix
CLOSED TREE
2021-02-26 16:44:05 +01:00
Sylvestre Ledru
a95ce79554 style: Fix clippy warnings
Depends on D96634

Differential Revision: https://phabricator.services.mozilla.com/D96636
2021-02-26 16:44:05 +01:00
Emilio Cobos Álvarez
191d5226a3 style: Implement complex :not().
This fixes the failures in bug 1671573 and just works thanks to the
invalidation improvements I did for :is / :where.

Added a couple tests for invalidation which is the tricky bit. 001 is a
very straight-forward test, 002 is the :is test but with :is() replaced
by double-:not().

This also fixes default namespaces inside :is() / :where(), which are
supposed to get ignored, but aren't. Added tests for that and for the
pre-existing :not() behavior which Chrome doesn't quite get right.

Differential Revision: https://phabricator.services.mozilla.com/D94142
2021-02-26 16:44:05 +01:00
Emilio Cobos Álvarez
89c2e39dd9 style: Minor cleanup: Use shorthand initialization in selectors.
Differential Revision: https://phabricator.services.mozilla.com/D90049
2021-02-26 16:44:05 +01:00
Emilio Cobos Álvarez
4cf9aeeaf7 style: Manually tweak inlining in stateless pseudo selector matching.
This addresses a minor regression in bloom-matching.html. The common
case here is that there's no selector to the right of the
pseudo-element, so keep that path inline, while keeping all other checks
out of line.

Differential Revision: https://phabricator.services.mozilla.com/D76793
2020-06-04 01:50:36 +02:00
Emilio Cobos Álvarez
bd23e05c47 style: Fix a no-longer valid assumption in pseudo-element matching / invalidation code.
After bug 1632647, we can have pseudo-classes inside :not / :is /
:where, which the invalidation and matching code weren't handling.

Add a few tests for this stuff working as expected.

Differential Revision: https://phabricator.services.mozilla.com/D76160
2020-06-04 01:50:36 +02:00
Emilio Cobos Álvarez
83ea321096 style: Implement parsing / selector-matching for :is() and :where().
This implements the easy / straight-forward parts of the :where / :is
selectors.

The biggest missing piece is to handle properly invalidation when there
are combinators present inside the :where. That's the hard part of this,
actually.

But this is probably worth landing in the interim. This fixes some of
the visitors that were easy to fix.

Differential Revision: https://phabricator.services.mozilla.com/D70788
2020-04-18 03:48:15 +02:00
Emilio Cobos Álvarez
846996ae7e style: Make :host::part work in the same shadow tree as the part.
Differential Revision: https://phabricator.services.mozilla.com/D68249
2020-04-16 16:35:07 +02:00
Emilio Cobos Álvarez
e3009a4de9
style: Implement shadow part forwarding (minus invalidation).
Some of the stuff, in particular inside GeckoBindings stuff should be
refactored to be less ugly and duplicate a bit less code, but the rest of the
code should be landable as is.

Some invalidation changes are already needed because we weren't matching with
the right shadow host during invalidation (which made existing ::part() tests
fail).

Pending invalidation work:

 * Making exportparts work right on the snapshots.
 * Invalidating parts from descendant hosts.

They're not very hard but I need to think how to best implement it:

 * Maybe get rid of ShadowRoot::mParts and just walk DOM descendants in the
   Shadow DOM.

 * Maybe implement a ElementHasExportPartsAttr much like HasPartAttr and use
   that to keep the list of elements.

 * Maybe invalidate :host and ::part() together in here[1]

 * Maybe something else.

Opinions?

[1]: https://searchfox.org/mozilla-central/rev/131338e5017bc0283d86fb73844407b9a2155c98/servo/components/style/invalidation/element/invalidator.rs#561

Differential Revision: https://phabricator.services.mozilla.com/D53730
2019-11-30 20:45:03 +01:00
Emilio Cobos Álvarez
7965ddefa6 style: Support multiple parts in ::part() selectors.
Differential Revision: https://phabricator.services.mozilla.com/D48753
2019-11-04 13:36:32 +01:00
Evgeniy Reizner
6f1df517e0 style: Do not use borrowed types in the selectors::Element trait.
Closes #22972
Closes #23463
2019-06-04 01:04:03 -04:00
Emilio Cobos Álvarez
43444db8a8 style: Cleanup selector-matching for nested pseudo-elements, match ::slotted correctly when there's no selector before it, and add tests.
D29542 fixed the bogus checks that was making nested pseudo-elements match
author rules. This adds tests and ends up being just a cleanup, though as it
turns out we it also fixes an issue with ::slotted() matched from
Element.matches.

Differential Revision: https://phabricator.services.mozilla.com/D27529
2019-05-29 16:14:26 +02:00
Emilio Cobos Álvarez
a23ad3be50 style: Add parsing support for ::part().
Disabled for now of course. This should be pretty uncontroversial I'd think.

Differential Revision: https://phabricator.services.mozilla.com/D28060
2019-05-07 12:55:44 +02:00
Simon Sapin
be69f9c3e6 Rustfmt has changed its default style :/ 2018-12-28 13:17:47 +01:00
Emilio Cobos Álvarez
273705d7fb style: Fix tidy issues. 2018-12-16 13:35:09 +01:00
Emilio Cobos Álvarez
7f5a9e0f45 style: Handle nested slots correctly in slotted matching and invalidation.
The patch and test should be pretty much self-descriptive.

Differential Revision: https://phabricator.services.mozilla.com/D14063
2018-12-16 13:35:06 +01:00
Jan Andre Ikenmeyer
1d6fe65401
Update MPL license to https (part 4) 2018-11-19 14:47:27 +01:00
Simon Sapin
a15d33a10e cargo fix --edition 2018-11-10 17:47:28 +01:00
Pyfisch
cb07debcb6 Format remaining files 2018-11-06 22:30:31 +01:00
Anshul Malik
a28c642fc7 format components/selectors 2018-09-12 00:24:20 +05:30
Cameron McCormack
62419adaaa
style: Shrink selectors::Component to 24 bytes.
This saves about 37 KiB of memory across the UA style sheets.

Bug: 1475197
Reviewed-by: emilio
2018-08-08 01:36:53 +02:00
Emilio Cobos Álvarez
02d27ad3dd
style: Make svg:use use an actual shadow tree.
This fixes a couple fuzz bugs and prevents special-casing <svg:use> even more in
bug 1431255.

Unfortunately not as many hacks went away as I'd have hoped, since we still need
to match document rules, see the linked SVGWG issues.

But blocks_ancestor_combinators goes away, which is nice since it's on a very
hot path.

Bug: 1450250
Reviewed-by: heycam
Differential Revision: https://phabricator.services.mozilla.com/D2154

MozReview-Commit-ID: C4mthjoSNFh
2018-07-24 03:30:12 +02:00
Emilio Cobos Álvarez
aca724ec79
style: Remove unneeded combinator check in selector-matching.
The combinator doesn't change during the loop, no need to check it.

Bug: 1471063
Reviewed-by: xidorn
MozReview-Commit-ID: KIAt0WiEOtI
2018-07-01 00:06:17 +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
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
9fa2618197
style: Add infrastructure to match :host. 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
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
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
Xidorn Quan
d0fd92221c Optimize selector matching for some common cases. 2018-01-17 09:46:57 +11: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
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
Emilio Cobos Álvarez
e4bb3a102e
style: Remove useless type parameter. 2017-12-08 02:56:02 +01: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
Emilio Cobos Álvarez
18ac41fe87
style: Inline a bunch of stuff, fixup indentation of a couple things.
MozReview-Commit-ID: CgUNMeBDOCw
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
2017-11-04 11:34:40 +01:00
Gecko Backout
8f8fd517ed Backed out changeset dbd300f4d75b for build bustage. r=backout on a CLOSED TREE
Backs out https://github.com/servo/servo/pull/19108
2017-11-03 23:56:42 +00:00
Emilio Cobos Álvarez
bcc9c62620
style: Inline a bunch of stuff, fixup indentation of a couple things.
MozReview-Commit-ID: CgUNMeBDOCw
2017-11-03 14:18:49 +01:00
Bastien Orivel
29b4eec141 Bump bitflags to 1.0 in every servo crate 2017-10-30 23:36:06 +01:00