Commit graph

424 commits

Author SHA1 Message Date
Martin Robinson
14a2c43c75
style: Reduce Servo's diff with upstream to_shmem (#31349)
This is part of getting Servo using an version of style closer to
upstream. This change reverts some changes we made to `to_shmem` and
`to_shmem_derive` in order to reduce our diff with upstream stylo.
2024-02-14 11:17:00 +00:00
Oriol Brufau
29f6170564 Further changes required by Servo 2023-11-24 08:57:14 +01:00
Emilio Cobos Álvarez
3da2db1c53 style: Remove the never_matches field from attr selectors
It's an extra branch which in practice we almost never take, plus extra
checks during parsing.

Differential Revision: https://phabricator.services.mozilla.com/D180529
2023-11-24 08:57:14 +01:00
Emilio Cobos Álvarez
54a783db17 style: Add a way to optimize the "attribute in no namespace exists" check
Go through the slow path by default. No behavior change.

Differential Revision: https://phabricator.services.mozilla.com/D180528
2023-11-24 08:57:14 +01:00
David Shin
ae5e0d49d8 style: Move ANCHORS_RELATIVE_SELECTOR out of nsINode flags
Move the flag to ComputedValueFlags, like `CONSIDERED_RELATIVE_SELECTOR`.

Differential Revision: https://phabricator.services.mozilla.com/D180726
2023-11-24 08:57:14 +01:00
Emilio Cobos Álvarez
ad72081ac8 style: Rustfmt servo/. r=zrhoffman
$ find servo -name '*.rs' | xargs rustup run nightly rustfmt

Depends on D179380

Differential Revision: https://phabricator.services.mozilla.com/D179381
2023-11-24 08:57:14 +01:00
David Shin
ff8100d396 style: Correct style sharing handling for any element that considered :has() in selector matching
For any element that anchors a `:has()` selector (i.e. Matches a selector that
contains a `:has()` on its rightmost side), we prevent style sharing altogether,
as evaluation of the `:has()` selector is required in the first place to
determine style sharing.

On the other hand, any element matching a rule containing `:has()` without
anchoring it can do style sharing for siblings, but not cousins.

Differential Revision: https://phabricator.services.mozilla.com/D176836
2023-11-24 08:57:14 +01:00
Emilio Cobos Álvarez
ad81122fcf style: More gracefully deal with broken calls into selector matching
If this happens again, it might be worth not matching rather than
potentially crashing. Though I guess crashing is a very good way getting
it reported soon...

Differential Revision: https://phabricator.services.mozilla.com/D178921
2023-11-24 08:57:14 +01:00
Emilio Cobos Álvarez
b329d547be style: Properly increase the nesting level when matching :nth-child(of) selectors
Differential Revision: https://phabricator.services.mozilla.com/D178920
2023-11-24 08:57:14 +01:00
Emilio Cobos Álvarez
7c4ec6e9cc style: [css-nesting] Do a first pass at parsing nested rules mixed with declarations
Plumb everything up. This factors out declaration and rule parsing so
we share the code with the regular declaration parser.

This could be made a bit nicer in the future. We need to decide what to
do for @page and @keyframe (it seems conditional rules inside ought to
work, but that's not so easy because per spec we create a nested style
rule).

But this is a first pass that passes a good chunk of the tests. There
are other fixups to cssom, and I think some of the tests we fail are
actually wrong...

Differential Revision: https://phabricator.services.mozilla.com/D178266
2023-11-24 08:57:14 +01:00
David Shin
9c58f0c635 style: Disallow :has selector nesting
Unlike the `ParseRelative` flag, which turns on relative selector parsing for
that parsing level only, the newly added `DISALLOW_RELATIVE_SELECTOR` flag
propagates through nested parsing calls.

Differential Revision: https://phabricator.services.mozilla.com/D176807
2023-11-24 08:57:14 +01:00
Oriol Brufau
d44f772dc3 Further changes required by Servo 2023-11-21 15:36:35 +01:00
Emilio Cobos Álvarez
93e0711194 style: [css-nesting] Process nested rules at cascade data rebuild
More nesting plumbing. Still does nothing because we don't parse the
nested rules.

Should be trivial to prove this patch doesn't change any behavior so
far, but I want to land it on its own because it can have performance
implications.

This follows the pattern of what we do with other rules like layers and
container conditions, that is, keep the ancestor selectors in a stack,
and poke at the last one in order to replace the ancestor.

This changes the behavior of replace_parent_selector as with the newer
version of the spec, stuff like:

  div {
    .foo {
      stuff
    }
  }

Should work as `div .foo`. A test is added for this case.

Differential Revision: https://phabricator.services.mozilla.com/D176560
2023-11-21 15:36:35 +01:00
Zach Hoffman
dcfef6cdbb style: Remove MatchingContext mutability FIXME that no longer applies
Differential Revision: https://phabricator.services.mozilla.com/D175028
2023-11-21 15:36:35 +01:00
Emilio Cobos Álvarez
0917ee3f9b style: Fix some spec links
Trivial, comment-only

Differential Revision: https://phabricator.services.mozilla.com/D174474
2023-11-21 15:36:35 +01:00
David Shin
3756e3b027 style: :has relative selector matching, with no caching/filtering
Differential Revision: https://phabricator.services.mozilla.com/D172019
2023-11-21 15:36:35 +01:00
Oriol Brufau
3914ff627e Further changes required by Servo 2023-11-21 15:36:35 +01:00
Zach Hoffman
356e886d26 style: Record attribute dependencies within the selector list of :nth-child(... of <selector list>)
There are separate filters for IDs, classes, attribute local names, and
element state.

Also, we invalidate siblings of elements matched against the selector
list of :nth-child(... of <selector list>) by marking matched elements
with NODE_HAS_SLOW_SELECTOR_NTH_OF.

The only remaining invalidation case invalidation case is
`:nth-child(An+B of :has())` (bug 1818155), which should not block
shipping `layout.css.nth-child-of.enabled`, because :has(...) is still
being implemented (bug 418039).

Depends on D172352

Differential Revision: https://phabricator.services.mozilla.com/D171936
2023-11-21 15:36:35 +01:00
Zach Hoffman
744b21e72a style: Apply selector flags to the shadow root
Because restyle events cannot be posted for non-element nodes like the
shadow root, a child's siblings are restyled directly if its parent has
NODE_HAS_SLOW_SELECTOR or NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS but that
parent is the shadow root.

Drive-by, but braces were also added to some single-line "if" statements
in RestyleManager.

Differential Revision: https://phabricator.services.mozilla.com/D172352
2023-11-21 15:36:35 +01:00
Oriol Brufau
664e44385e Further changes required by Servo 2023-11-21 15:36:35 +01:00
David Shin
f7b29ac432 style: Parsing for relative selectors in :has()
Differential Revision: https://phabricator.services.mozilla.com/D171358
2023-11-21 15:36:35 +01:00
Jan-Niklas Jaeschke
896aac5e4a style: Basic implementation of Custom Highlight API
Added WebIDL interfaces as per spec, added some necessary changes to support maplike and setlike structures to be accessed from C++.

Added `::highlight(foo)` pseudo element to CSS engine.

Implemented Highlight as new kind of `Selection` using `HighlightType::eHighlight`. This implies Selections being added/removed during runtime (one `Selection` object per highlight identifier), therefore a dynamic container for highlight `Selection` objects was added to `nsFrameSelection`. Also, the painting code queries the highlight style for highlight Selections.

Implementation is currently hidden behind a pref `dom.customHighlightAPI.enabled`.

Differential Revision: https://phabricator.services.mozilla.com/D164203
2023-11-06 09:35:57 +01:00
Emilio Cobos Álvarez
29c6094c80 style: [css-nesting] Parse parent selector
This parses the ampersand as a parent selector behind an
(off-by-default) selectors feature.

The plan is to call replace_parent_selector while we're doing the
CascadeData rebuilds, which is where we can have all the ancestor
nesting information.

No behavior change.

Differential Revision: https://phabricator.services.mozilla.com/D167237
2023-11-06 09:35:57 +01:00
Oriol Brufau
bb55e923bb Further changes required by Servo 2023-11-06 09:35:57 +01:00
Tiaan Louw
4559546fbb style: Add lab(), lch(), oklab(), oklch() to specified colors
Use new changes from cssparser and use the new lab/lch/oklab/oklch color
formats.

Introduced a new color type AbsoluteColor.  It represents any kind of
color that has absolute numerical values.  It is also tied to a color
space and therefore can be trivially converted to another color space.

Differential Revision: https://phabricator.services.mozilla.com/D163579
2023-11-06 09:35:57 +01:00
Zach Hoffman
fa297196ef style: Reuse list_matches_complex_selector() where possible
It can be reused for the Is, Where, and Negation components.

Differential Revision: https://phabricator.services.mozilla.com/D166267
2023-11-06 09:35:57 +01:00
Zach Hoffman
93de6edbc9 style: Apply slow selector flags before matching
This patch fixes a bug introduced by bug 1808228/D166266, where, if an
element does not initially match :nth-child(An+B of selector list) or
:nth-last-child(An+B of selector list), changing a sibling or ancestor
will not invalidate that element.

Differential Revision: https://phabricator.services.mozilla.com/D166982
2023-11-06 09:35:57 +01:00
Zach Hoffman
3076481c52 style: Implement selector matching for :nth-child(An+B of selector list) and :nth-last-child(An+B of selector list)
Since we have been using a single hash map to cache all :nth-child
indices (with no selector list), each different selector will need its
own cache.

As a side note, this patch does not address invalidation.

Differential Revision: https://phabricator.services.mozilla.com/D166266
2023-11-04 08:17:09 +01:00
Zach Hoffman
39b056cf70 style: Move nth-related logic to the NthSelectorData type for reuse
Drive-by, but selector_list_specificity() was also renamed to
max_selector_list_specificity().

Differential Revision: https://phabricator.services.mozilla.com/D166263
2023-11-04 08:17:09 +01:00
Zach Hoffman
1c8408e97e style: Implement parsing and serialization for nth-child(An+B of selector list) and :nth-last-child(An+B of selector list)
:nth-{,last-}child parsing is disabled by default for now by pref
layout.css.nth-child-of.enabled.

Differential Revision: https://phabricator.services.mozilla.com/D165895
2023-11-04 08:17:09 +01:00
Emilio Cobos Álvarez
bc438d725f style: Minor clean-ups and fixes on top of the previous patch
This makes the matching / parsing more self-contained, and I believe
it's generally easier to follow. Also addresses review comments from the
previous patch.

Differential Revision: https://phabricator.services.mozilla.com/D165861
2023-11-04 08:17:09 +01:00
Zach Hoffman
211761ad88 style: Represent FirstChild, FirstOfType, LastChild, LastOfType, OnlyChild, and OnlyOfType as functionless Nth variants
Like bug 1808226, this doesn't change any behavior, it just simplifies matching.

I also added a WPT JavaScript test for :only-of-type, since dedicated WPT
JavScript tests already exist for the other pseudo-classes this patch
touches.

Differential Revision: https://phabricator.services.mozilla.com/D165859
2023-11-04 08:17:09 +01:00
Zach Hoffman
281ae0748f style: Store values for :nth- selectors in dedicated struct NthSelectorData
To accomplish this, all :nth- Components were replaced with type Nth,
which uses NthSelectorData.

Using NthSelectorData will make it easier to add selector lists for :nth
selectors later on, but this change by itself shouldn't change any
behavior.

Differential Revision: https://phabricator.services.mozilla.com/D165831
2023-11-04 08:17:09 +01:00
Emilio Cobos Álvarez
92742f7f90 style: Avoid generic soup and extra reference count bumps
This makes me a bit happier about the previous patch :)

Differential Revision: https://phabricator.services.mozilla.com/D165236
2023-11-04 08:17:09 +01:00
Emilio Cobos Álvarez
b6d9b77a15 style: Speed up selector matching with already-lowercase local name selectors
This makes relatively simple changes so that we check lowercase-ness of
local-name selectors first. If so, we don't need to check whether we're
an HTML element in an HTML document, which requires a fair bit of
pointer-chasing.

Differential Revision: https://phabricator.services.mozilla.com/D163627
2023-11-04 08:17:09 +01:00
Ting-Yu Lin
3da52edffc style: Run "cargo +nightly fmt" for style components in servo
The directories changed:
* servo/components/selectors/
* servo/components/style/
* servo/components/style_derive/
* servo/ports/geckolib/

Per review request, disable rustfmt in `components_to_transform_3d_matrix()` to
preserve the format for a call to `Transform3D::new`.

My mozilla-central is at
https://hg.mozilla.org/mozilla-central/rev/d1ae84015c22f2034435b47194fdced878072035

My nightly rust is 1.66.0-nightly (8b705839c 2022-09-26).

Differential Revision: https://phabricator.services.mozilla.com/D158234
2023-11-03 08:59:49 +01:00
Emilio Cobos Álvarez
9f6341b83a style: Disallow forgiving selector-parsing in @supports
As per spec, see https://github.com/w3c/csswg-drafts/issues/7280

Differential Revision: https://phabricator.services.mozilla.com/D156468
2023-11-03 08:59:49 +01:00
Tiaan Louw
3d0cf4dbf9 style: Add simple parsing and matching support for :has
Parsing is behind a config value `layout.css.has-selectors.enabled`. This
change does not support p:has(> a) combinators, but will handle them
gracefully, just not matching on them.

Differential Revision: https://phabricator.services.mozilla.com/D149515
2023-10-02 14:37:19 +00:00
Mike Hommey
48749641d3 style: Update derive_more to 0.99.17
Limit its features to those we actually use, which turns out is none for
webrender_api.

Differential Revision: https://phabricator.services.mozilla.com/D148734
2023-10-02 14:37:19 +00:00
Emilio Cobos Álvarez
898cafb5a5 style: Use debug_unreachable!() in matches_simple_selector
This shrinks the function by avoiding generating rather noisy panic
code.

Depends on D145486

Differential Revision: https://phabricator.services.mozilla.com/D145487
2023-10-02 14:37:19 +00:00
Emilio Cobos Álvarez
2302d828a5 style: Reorder some variants
This doesn't make a difference, I was hoping it would allow us to remove the
special-casey code we have here:

  https://searchfox.org/mozilla-central/rev/997a56b018662e2940c99bbaf57a6ac9d1aa5422/servo/components/selectors/matching.rs#610-632

But it doesn't. Still I think it doesn't hurt tho, shouldn't change behavior.

Depends on D145485

Differential Revision: https://phabricator.services.mozilla.com/D145486
2023-10-02 14:37:19 +00:00
Emilio Cobos Álvarez
2939bf1a12 style: Simplify a bit hot selector-matching loop
Note that element.clone() is just copying a couple pointers.

Have a single place where we compute the next element and check for linky-ness.
This saves a couple checks (very very minor win in the micro-benchmark I've
been looking at, but consistent).

Depends on D145484

Differential Revision: https://phabricator.services.mozilla.com/D145485
2023-10-02 14:37:19 +00:00
Emilio Cobos Álvarez
a21762fc5b style: Compute hover / active quirk state lazily
This makes the inner function much smaller which improves selector-matching
performance very mildly for the benchmarks I've been looking at. Also, this
should help selector matching on quirks mode by only doing this when we
actually find :hover / :active pseudo-classes.

Differential Revision: https://phabricator.services.mozilla.com/D145484
2023-10-02 14:37:19 +00:00
Emilio Cobos Álvarez
653245c94e style: Avoid some clone()s in selector parsing now that lifetimes are non-lexical
Differential Revision: https://phabricator.services.mozilla.com/D123622
2023-10-02 14:37:19 +00:00
Samson
711dbbd4af
remove extern crate (#30311)
* remove extern crate

* Update components/script_plugins/lib.rs

Co-authored-by: Martin Robinson <mrobinson@igalia.com>

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2023-09-08 12:11:31 +00:00
Samson
c0bee7cb86
Format toml files (#30112)
* Add taplo fmt config for toml fmt

* fmt toml files

* Add even-better-toml to extensions recommendations
2023-08-17 15:07:43 +00:00
Oriol Brufau
a162204fee Avoid complaints from ./mach test-tidy 2023-08-16 17:46:41 +02:00
Oriol Brufau
a7699d9034 Further changes required by Servo 2023-08-16 17:46:41 +02:00
Emilio Cobos Álvarez
4878422c93 style: Simplify selector flags setup even more
In my investigation for bug 1766439, I am digging into why selector
matching regressed.

It doesn't help that the selector-matching code is instantiated a
gazillion times (so there's a ton of copies of the relevant functions).

This was needed in the past because we had different ways of setting the
selector flags on elements, but I unified that recently and now we only
need to either set them or not. That is the kind of thing that
MatchingContext is really good for, so pass that instead on
MatchingContext creation.

Differential Revision: https://phabricator.services.mozilla.com/D145428
2023-08-16 17:46:41 +02:00
Oriol Brufau
d6ae8dc112
Revert "Backport several style changes from Gecko (5) (#30099)" (#30104)
This reverts commit 8e15389cae.
2023-08-16 06:24:42 +00:00