DevTools was collecting CSS rules by walking stylesheets and matching
selector text. This ignored cascade order and did not correctly handle
rules inside layer blocks.
This change uses computed values (rule tree) to get the actual applied
rules in cascade order. It then maps those rules back to CSSStyleRule
using the declaration block identity, and walks the CSSOM to get
selector text and layer ancestry.
This fills ancestor_data with layer names and lets the inspector show
layered rules correctly.
Testing:
- Verified using the minimized testcase from the issue
- Verified on https://www.sharyap.com/
- Confirmed that rules inside layer blocks are now shown with correct
order and hierarchy.
Fixes: #43541
Signed-off-by: arabson99 <arabiusman99@gmail.com>
Rather than specifying a cx for every single CSS property from Stylo, we
instead make it implicit. This allows us to remove the `CanGc::note()`
from the macro and pass in the `cx` as normal.
We can use a similar approach for setters in other elements where we use
the setter macros.
Part of #42812
Testing: It compiles
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This continues #43045
Changelog:
- Upstream:
74ddab4091...6de1071549
- Servo fixups:
9f2f4f3f1b...6cfce6f329
Stylo tracking issue: https://github.com/servo/stylo/issues/347
Summary of improvements:
- Adding support for the CSS-wide `revert-rule` keyword
- `::details-content` becomes element-backed, thus accepting nested
pseudo-elements like `::details-content::before`.
- Custom properties can now be registered using dashed idents in their
syntax
- Various `attr()` improvements
Testing: Various WPT improvements
---------
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Follow up of https://github.com/servo/servo/pull/43226
This also allows us to remove some `mut` declaration.
Fix some unintended Chinese quotation mark.
Testing: This is a micro-optimization which does not change visible
behaviour.
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Move `CSSGroupingRule` methods from `CanGc` to `&mut JSContext`.
Testing: Just refactor.
Fixes: Part of #42638
Signed-off-by: Jayanta Pradhan <pradhanjayanta91@gmail.com>
Move `CSSStyleRule::Style` from `CanGc` to `&mut JSContext`. Also fix
the caller in `devtools.rs` to pass `cx` directly.
Testing: Refactoring, It compiles.
Fixes: Part of #42638
Signed-off-by: arabson99 <arabiusman99@gmail.com>
Move `CSSKeyframesRule` methods (`CssRules`, `AppendRule`, `DeleteRule`,
`FindRule`) from `CanGc` to `&mut JSContext`.
Testing: It compiles.
Fixes: Part of #42638
Signed-off-by: arabson99 <arabiusman99@gmail.com>
Move `CSSNestedDeclarations::Style` from `CanGc` to `&mut JSContext`.
Testing: It compiles.
Fixes: Part of #42638
Signed-off-by: arabson99 <arabiusman99@gmail.com>
Move `CSSKeyframeRule::Style` from `CanGc` to `&mut JSContext`.
Testing: Just a refactor, Existing tests suffice.
Fixes: Part of #42638
Signed-off-by: arabson99 <arabiusman99@gmail.com>
This method is the same as `DOMString::from` with a `String` argument
and `From` and `Into` are preferred when writing modern Rust.
Testing: This should not change behavior and is thus covered by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Demonstrate how to change some methods:
- [from `InRealm` to `&mut
CurrentRealm`](0132fc0fbe)
- [from `CanGc` to `&mut
JSContext`](36e5b32ee1)
Testing: Just refactor, should be covered by WPT.
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Use snakecase to be consistent. Also these names are normally quite long
already.
Testing: Just renaming.
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Implementation for parsing the font-variation-settings and including
them in the fontface rule-set, currently they are discarded and
annotated with a TODO
Related: https://github.com/servo/servo/issues/41591
Testing: Tests are included for the changes to be implemented, as
suggested they currently fail and thats the starting point.
Signed-off-by: Osoro Bironga <fanosoro@gmail.com>
Changed most #[allow]s to #[expect]s, mainly for
clippy::too_many_arguments
Removed unfulfilled expectations
This is my first opensource contribution, so please let me know if
anything should
be done differently.
Testing: Refactor
Part of: #40838
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: TimurBora <timurborisov5561@gmail.com>
Co-authored-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
Creates a new `css.rs` module in `components/script` with helper
functions for CSS value parsing.
Callers no longer need to manually specify document URL, quirks mode,
and error reporter.
Testing: `./mach check`
Fixes: #41541
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
Rebase of #37021 with review comments applied. These changes bundle up
the required information from the relevant global when a stylesheet is
added so that any requests for web fonts match the specification.
Testing: Newly passing tests.
Fixes: #36590
---------
Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
I used find and replace to finish the job. All this PR does is replace
all `Error::<error_name>` occurrences with `Error::<error_name>(None)`.
Testing: Refactor
Fixes: #39053
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
There are multiple motivating factors for this change:
1. `tracing-rs` can and is commonly used for structured logging, to gain
understanding in what is happening in concurrent code. We would like to
attempt to make a distinction of the performance tracing related usage
and the logging related usage.
2. This reduces boilerplate code. We don't have to feature guard every
span anymore, since the macro will do it for us.
3. This makes it easier to add multiple options for the trace backend
(i.e. exchanging tracing-rs for hitrace on OpenHarmony or System Tracing
in Android), or something entirely custom.
4. This makes it easier to add further compile-time options to control
the amount of tracing. E.g. a future PR could add options to enable
tracing based on environment variables set at compile time. Tracing adds
runtime overhead, even if the runtime switch is disabled, so having more
fine-grained options to partially enabled tracing could be useful.
Testing: Tested manually by building with and without the `tracing`
feature. In CI we also build with the tracing feature in the HarmonyOS
build. We don't have any automated tests for the correctness / presence
of the traced entries.
---------
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This change is a rework of #22478, originally authored by @vimpunk.
It adds parsing of CSS in parallel with the main script thread. The
big idea here is that when the transfer of stylesheet bytes is
finished, the actual parsing is pushed to a worker thread from the Stylo
thread pool. This also applies for subsequent loads triggered by
`@import` statements.
The design is quite similar to the previous PR with a few significant
changes:
- Error handling works properly. The `CSSErrorReporter` is a crossbeam
`Sender` and a `PipelineId` so it can be trivially cloned and sent to
the worker thread.
- Generation checking is done both before and after parsing, in order
to both remove the race condition and avoid extra work when the
generations do not match.
- The design is reworked a bit to avoid code duplication, dropping added
lines from 345 to 160.
- Now that `process_response_eof` gives up ownership to the
`FetchResponseListener`, this change avoids all extra copies.
Testing: This shouldn't change observable behavior, so is covered
by existing tests.
Fixes: #20721Closes: #22478
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: mandreyel <mandreyel@protonmail.com>
Adds an optional error message to HierarchyRequestError
Testing: refactor
Fixes: one item in #39053
---------
Signed-off-by: Austin Willis <austinwillis8@gmail.com>
HTMLStyleElement was creating stylesheets using the URI of the document,
ignoring `<base>`.
To avoid having to create the UrlExtraData twice (or clone it), this
inlines the `stylesheetcontents_create_callback`.
Testing: 2 WPT are now passing
Fixes: #40550
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Adding an optional message to be attached to a IndexSizeError.
The enum definition of IndexSize is now `IndexSize(Option<String>)`.
Future PRs should probably add more appropriate messages to some of the
`IndexSize(None)`s.
Testing: Just a refactor
Fixes: Partially #39053
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
Servo has a lot of comments like this:
```rust
// https://example-spec.com/#do-the-thing
fn do_the_thing() {}
```
and I keep turning these into doc comments whenever I'm working close to
one of them. Doing so allows me to hover over a function call in an IDE
and open its specification without having to jump to the function
definition first. This change fixes all of these comments at once.
This was done using `find components -name '*.rs' -exec perl -i -0777
-pe 's|^([ \t]*)// (https?://.*)\n\1(fn )|\1/// <$2>\n\1$3|mg' {} +`.
Note that these comments should be doc comments even within trait `impl`
blocks, because rustdoc will use them as fallback documentation when the
method definition on the trait does not have documentation.
Testing: Comments only, no testing required
Preparation for https://github.com/servo/servo/pull/39552
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Moves interfaces defined by the CSS spec to the `script/dom/css/` module
from `script/dom/`.
Testing: Just a refactor shouldn't need any testing
Fixes: Partially #38901
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>