The main goal here is to have layout not depend on `ServoLayoutElement`
directly and instead use the layout DOM interface exposed by
`layout-api`.
This change allows layout to determine if replaced content
is the root of a user agent widget without having to access
`ServoDangerousStyleShadowRoot` which isn't really safe to use in layout
code. `LayoutElement::shadow_root()` is now no longer exposed to layout.
Testing: This should not change behavior, so should be covered by
existing test.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This change is a minor cleanup of the way that layout flushes the
stylesheets of shadow roots. This avoids exposing so many public methods
in our and gradually to stop using Stylo's `TShadowRoot` in layout
entirely.
Testing: This should not change behavior, so should be covered by
existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Servo has lots of `LayoutXYZHelper` traits that are used to define
additional methods on `LayoutDom<XYZ>`. We can replace them with `impl
LayoutDom<XYZ>` blocks, reducing the number of LoC and making it easier
to add or modify methods.
Testing: These should be covered by existing tests
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
During traversal, exclude shadow roots.
Analysis:
Each shadow root is processed twice:
- via host: Element::bind_to_tree()
- Via iterator
In total, this would be
```math
\sum_{i=0}^{N-1} 2^i = 2^N - 1
```
Testing: Added a test.
Fixes: https://github.com/servo/servo/issues/43998
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Co-authored-by: webbeef <me@webbeef.org>
A lot (and I mean, really a lot) depends on these constructors.
Therefore, this is the one spaghetti ball that I could extract and
convert all `can_gc` to `cx`. There are some new introductions of
`temp_cx` in the callbacks of the servo parser, but we already had some
in other callbacks.
Part of #40600
Testing: It compiles
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
`DocumentOrShadowRoot#activeElement` should return retargeted results.
What that means is that if the DOM anchor of the `Document`'s focused
focusable area is within a shadow root, `Document#activeElement` should
return the shadow host. This change implements that behavior, properly
returning the `activeElement` from both `Document` and `ShadowRoot`.
Testing: This causes a decent number of WPT tests and subtests to start
passing. One subtest starts to fail, because it uses the `autofocus`
attribute
which we do not yet support.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
I only wanted to get `&mut JSContext` in microtask chunk and checkpoint,
but this in turn needed `&mut JSContext` in servoparser, which then
caused need for even more changes in script.
I tried to limit the size by putting some `temp_cx` in:
- drops of `LoadBlocker`, `GenericAutoEntryScript`
- methods of `VirtualMethods`
- methods of `FetchResponseListener`
Testing: Just refactor, but should be covered by WPT tests.
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This continues #41916
Changelog:
- Upstream:
360787fff5...7cd2a178d3
- Servo fixups:
e4d50e905e...d9831d464b
Stylo tracking issue: https://github.com/servo/stylo/issues/305
In particular, this adds support for `alignment-baseline` and
`baseline-shift`, and turns `vertical-align` into a shorthand of them.
This also introduces `vertical-align: center`.
Testing: Various tests improve. Some internal tests are updated because
they were wrong. And some fail because we don't support presentation
attributes on SVG elements.
---------
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
A template element should set the host of a DocumentFragment. However,
it didn't have a host yet. That's because ShadowRoot declares a host
attribute which returns Element, but its property is declared on
DocumentFragment.
Therefore, define the host on DocumentFragment instead and use it in all
relevant points for shadow roots. Then, update the pre-insert validity
check to use the correct host-including variant of inclusive ancestors.
Lastly, set the host of the template to wire it all up.
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Added calls to download web font from stylesheet when stylesheets are
added to shadow root.
Testing: Manual testing. Added a new WPT testcase
---------
Signed-off-by: Minghua Wu <michael.wu1107@gmail.com>
This implementation is not actually specified (see #40973 and
https://github.com/w3c/csswg-drafts/issues/556), but the implementation
that we have is backwards. Other retargeting uses that describe
"retarget _something_ against _another thing_" map to
`something.retarget(another_thing)`, but what the current code was doing
for element[s]FromPoint was the equivalent of "retarget _this_ against
each element", which is obviously wrong.
Testing: Newly-passing tests.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Add Contents::ReplacedWithWidget for video elements with UA control
widget, to allow Traverse into the children of video element during Box
Tree Construction, Generate
IndependentFormattingContextContent::ReplacedWithWidgets, to store both
the `ReplacedContents` and `BlockFormattingContext`. During fragment
tree generation process, first layout the Image Fragment, and then
Layout the Inner Controls BlockFormattingContext. Doing this allow us to
determine the size of Inner Controls widget based on the size of the
Image Fragment. Minor Fix: ::before/::after pseudo elment should be
suppress for replaced element.
Testing: Should show the controls widget for `<video controls></video>`,
and should not affect any existing WPT test. Since how to display UA
widget of Video Element is not defined in the spec, expectedly there has
no existing WPT test that testing this.
Fixes https://github.com/servo/servo/issues/40452
Fixes https://github.com/servo/servo/issues/31414
---------
Signed-off-by: rayguo17 <tin.tun.aung1@huawei.com>
This is last step toward enabling the default rustc
`unsafe_op_in_unsafe_fn` warning for the script crate. It wraps the
remaining unsafe code in `unsafe {}` and removes the line disabling this
warning from `script`'s `Cargo.toml`. In addition, two variables are
renamed from `v` to something slightly more descriptive.
Testing: This should not change behavior so is covered by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Removes some unneeded lints, especially `#[allow(unsafe_code)]`.
Testing: Refactor
Part of: #40383
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
Within the same tree, only one `<details>` element with the same name
may be open at a time. Before this change, this invariant was not
enforced.
I've added a `HashMap` to `Document` and `ShadowRoot` which maps from a
name to the a list of details elements with the same name. This map
allows us to find conflicting details elements without having to
traverse the whole tree. Of course this only works when the tree is a
document tree or a shadow tree, so we still have to fall back to
`traverse_preorder` in some cases (which I believe to be uncommon).
This is ready for review, but I'd like to wait until
https://github.com/servo/servo/pull/40271 is merged to not cause
unnecessary merge conflicts.
Testing: New web platform tests start to pass
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
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>
Each shadow root holds a map of slot names to slot elements. Slot
elements dynamically register and unregister themselves at their
respective shadow root when they are bound and unbound from the tree.
Previously, they were doing this too often. When a slot element is
unbound from the tree then it might still be connected to its shadow
root, in case the entire shadow tree is being unbound.
Fixing this requires the slot element to know whether it was in a shadow
tree prior to `bind_to_tree` being called (then it's already registered
and doesn't need to do so again), and whether it will be in a shadow
tree after `unbind_from_tree` is called (then there's no need to
unregister).
Testing: This change adds a new web platform test
Fixes: https://github.com/servo/servo/issues/40242
---------
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>
Regular shadow roots can never be detached once they are created.
However we were specifically detaching shadow roots from media elements
when they were disconnected. This is actually one of the very few
aspects of shadow roots that predate the implementation work I did
earlier this year.
I'm not sure why we ever did this. Maybe its for efficiency reasons,
because keeping the shadow tree around is not necessary when the media
element is not connected. But I can't imagine this yields any benefits,
especially since you would have to reconstruct the shadow tree when the
media element is re-connected (as is the case in the crash we observe).
For simplicities sake, I have completely removed this functionality.
Doing so ends up simplifying the code quite a bit.
Testing: This change adds a new crashtest
Fixes https://github.com/servo/servo/issues/36722
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Follow the HTML specification and take into account that the HTML
`<image>/<source>` element inserting/removal steps should only be
counted as relevant mutations for `<image>` element if the parent of the
inclusive ancestor that was inserted/removed is the parent `<picture>`
element.
See <https://html.spec.whatwg.org/multipage/#relevant-mutations>.
Testing: Improvements in the following tests
-
html/semantics/embedded-content/the-img-element/relevant-mutations.html
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
For duplicate style sheets with identical content, `StylesheetContents`
can be reused to avoid redundant parsing of the inline style sheets.
Since duplicate stylesheets is a common case with web components, this
change will significantly improve performance. Additionally, the cache
hit rate of stylo's `CascadeDataCache` can now be significantly
improved.
When shared `StylesheetContents` is modified, copy-on-write will occur
to avoid affecting other sharers. And then updates the references to
`CssRule` or `PropertyDeclarationBlock` stored in the CSSOMs to ensure
that modifications are made only on the new copy.
Signed-off-by: sharpshooter_pt <ibluegalaxy_taoj@163.com>
This change fix this bugs: modify stylesheet of shadow tree does not
take effect if there is no other Dom change within the shadow tree
happens.
Fixes: This change fix some bugs reported by this issue #38211.
Testing: This fixes some subtests in
`/css/cssom/CSSStyleSheet-constructable.html` and
`/css/cssom/CSSStyleSheet-constructable-disallow-import.tentative.html`,
and make some subtest failed in
`/css/cssom/CSSStyleSheet-constructable-baseURL.html`, because the
`BaseUrl` is not yet supported for `CSSStylesheet`.
Signed-off-by: sharpshooter_pt <ibluegalaxy_taoj@163.com>
This shows up sometimes in code reviews, so it makes sense that tidy
enforces it. `rustfmt` supports this via comment normalization, but it
does many other things and is still an unstable feature (with bugs).
Testing: There are new tidy tests for this change.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Also make TrustedHTML work the same as TrustedScript by
only taking 1 `&str` to make things easier.
Part of #36258
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This is a follow-up to #38532 which simply defaulted to an empty string
as the spec's WebIDL doesn't mark `innerHTML` as `Throws`. However,
since the absence of `Throws` in the spec doesn't imply no-throw, we can
mark this as fallible in our WebIDL. This makes the `ShadowRoot`'s
implementation match `Element`'s `innerHTML`.
Testing: Same as #38532.
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Testing: [Try run][1] did not reveal any test failures. There doesn't
seem to be any straightforward failure scenarios that can be triggered
in `xml5ever` that are not IO errors and the xml_serialize method simply
serializes to a String buffer.
[1]:
https://github.com/servo/servo/actions/runs/16824267959/job/47657275606l
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Instead of running "update the rendering" at every IPC message, only run
it when a timeout has occured in script. In addition, avoid updating the
rendering if a rendering update isn't necessary. This should greatly
reduce the amount of processing that has to happen in script.
Because we are running many fewer calls to "update the rendering" it is
reasonable now to ensure that these always work the same way. In
particular, we always run rAF and update the animation timeline when
updating the ernder
In addition, pull the following things out of reflow:
- Code dealing with informing the Constellation that a Pipeline has
become Idle when waiting for a screenshot.
- Detecting when it is time to fulfill the `document.fonts.ready`
promise.
The latter means that reflow can never cause a garbage collection,
making timing of reflows more consistent and simplifying many callsites
that need to do script queries.
Followup changes will seek to simplify the way that ScriptThread-driven
animation timeouts happen even simpler.
Testing: In general, this should not change testable behavior so much,
though it
does seem to fix one test. The main improvement here should be that
the ScriptThread does less work.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Spec:
https://drafts.csswg.org/cssom/#dom-documentorshadowroot-adoptedstylesheets
Implement `DocumentOrShadowDOM.adoptedStylesheet`. Due to
`ObservableArray` being a massive issue on its own, it will be as it was
a `FrozenArray` at first. This approach is similar to how Gecko
implement adopted stylesheet. See
https://phabricator.services.mozilla.com/D144547#change-IXyOzxxFn8sU.
All of the changes will be gated behind a preference
`dom_adoptedstylesheet_enabled`.
Adopted stylesheet is implemented by adding the setter and getter of it.
While the getter works like a normal attribute getter, the setter need
to consider the inner working of document and shadow root StylesheetSet,
specifically the ordering and the invalidations. Particularly for
setter, we will clear all of the adopted stylesheet within the
StylesheetSet and readd them. Possible optimization exist, but the focus
should be directed to implementing `ObservableArray`.
More context about the implementations
https://hackmd.io/vtJAn4UyS_O0Idvk5dCO_w.
Testing: Existing WPT Coverage
Fixes: https://github.com/servo/servo/issues/37561
---------
Signed-off-by: Jo Steven Novaryo <jo.steven.novaryo@huawei.com>
Refactor `documentotshadowroot::StyleSheetInDocument`, renaming it into
`ServoStylesheetInDocument` to avoid confusion with Stylo's
`StylesheetInDocument` trait.
To support constructed stylesheet. The `ServoStylesheetInDocument.owner`
would contains enum of:
- `Dom<Element>` - for stylesheet parsed from an element.
- `Dom<CSSStylesheet>` - for constructed stylesheet.
Testing: No WPT regression.
Fixes: #38133
---------
Signed-off-by: Jo Steven Novaryo <jo.steven.novaryo@huawei.com>
The default of `enum-variant-name-threshold` is 3, so adding any new
variants will lead to the lint being triggered, reference:
[enum_variant_names](https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names).
This PR fix this potential clippy lint warning for facilitate the
addition of new variant in following PR about incremental box tree
update.
Testing: No logic changed, just covered by existing WPT tests
Fixes: None
Signed-off-by: sharpshooter_pt <ibluegalaxy_taoj@163.com>
This makes it much faster to traverse over the slot descendants of
a shadow root, which is a fairly costly part of "assign slottables to a tree".
This reduces the time it takes for the results to load on wpt.fyi from
over 3 minutes to about 5 seconds.
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>