Implement node.moveBefore()
This implements the atomic move method for DOM nodes. This allows moving
elements within the DOM without running the full remove and insertion
steps, allowing more seamless behaviour such as CSS transitions
continuing from where they are rather than restarting.
Spec: https://dom.spec.whatwg.org/#dom-parentnode-movebefore
Testing: Existing WPTs
---------
Signed-off-by: Luke Warlow <lwarlow@igalia.com>
Implement "getPublicKey" operations of ECDSA and ECDH. The steps are
implemented at the new submodule `ec_common` shared by ECDSA and ECDH.
To make the operations functioning, they are also registered at
`GetPublicKeyAlgorithm`.
Specification:
https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-getPublicKey
Testing: Pass WPT tests that were expected to fail.
Fixes: Part of #43072
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Servo side of https://github.com/servo/stylo/pull/322.
Update the WPT expectation following the changes to make `::placeholder`
public and adding property restriction to `::placeholder` and
`::marker`. Additionally ensure that `getComputedStyle` works for
`::placeholder`.
Testing: Existing WPTs
Fixes: #43034Fixes: #43035Fixes: #19808
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Implement "getPublicKey" operations of RSASSA-PKCS1-v1_5, RSA-PSS and
RSA-OAEP. The steps are implemented at `rsa_common.rs` shared by the
three RSA algorithms.
To make the operations functioning, they are also registered at
`GetPublicKeyAlgorithm`.
Specification:
https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-getPublicKey
Testing: Pass WPT tests that were expected to fail.
Fixes: Part of #43072
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
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>
Implement the `getPublicKey` method of the `SubtleCrypto` interface.
This patch includes:
- Implementing the steps of the `getPublicKey` method.
- Adding the new "getPublicKey" operation to the internal object
`supportedAlgorithms`, for registering cryptographic algorithms that
support "getPublicKey" operation, and used by the `getPublicKey` method
to check whether the cryptographic algorithm supports "getPublicKey"
operation and perform the operation if it is supported.
- Implementing the "getPublicKey" operation of X25519 for demonstrating
and testing the functionality of the `getPublicKey` method.
Specification:
<https://wicg.github.io/webcrypto-modern-algos/#SubtleCrypto-method-getPublicKey>
Testing: Pass WPT tests that were expected to fail.
Fixes: Part of #43072
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Moves the `Drop` logic for `GPURenderPipeline` into a dedicated helper
struct, `DroppableGPURenderPipeline`.
The associated `Bindings.conf` entry is
removed as direct `Drop` is no longer needed for this type.
Testing: WebGpu tests just cover its cases
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
This introduces a `CollectionSource` trait as an alternative to
`CollectionFilter` in `HTMLCollection`, allowing collections to provide
elements directly via a custom iterator rather than filtering a full
subtree traversal, which would otherwise be rather inefficient for
smaller iterable sequences of options that can be determined without
traversing the whole subtree again.
The newly implemented `selectedOptions` attribute on the `<select>`
element uses this to iterate only the element's list of options that are
marked as selected.
Testing: 14 assertions in the existing WPT went from failing to passing.
Fixes#15522.
---------
Signed-off-by: Jacob Adam <software@jacobadam.net>
- Use modern Rust conveniences such as `unwrap_or_default`
- Unabbreviate `attr`
- Unify the lowercase ASCII name assertion and make it a debug assertion
- Use `unreachable!` instead of panic
- Expose two attribute getters that follow the behavior of two
specification concepts and what we expect internally in Servo:
- One that takes a namespace, but does not require lowercase attribute
names. ([specification
concept](https://dom.spec.whatwg.org/#concept-element-attributes-get-by-namespace>))
- One that does not take a namespace, but does require lowercase
attribute names. ([specification
concept](https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name))
Testing: This should not really change behavior so should be covered by
existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Accepting the name of the event as a `DOMString` means that when events
are constructed from within Servo (for instance via input event
handling), the static strings are converted to an owned `String`
wrapped in a `DOMString` and then finally converted to an `Atom` in
`Event`. This makes it so that all non-generated `Event` constructors
accept `Atom`, which can avoid a conversion entirely when the atom
already exists on the Stylo atoms list and eliminate one in-memory copy
in the case that it isn't on the atom list.
Eventually, all event names can be on the atom list and we can eliminate
all copies. This is a tiny optimization, but also makes the code much
friendlier everywhere.
Testing: This should not change behavior so should be covered by
existing test.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This change makes it possible to focus boxes with overflow via the
keyboard. These boxes should be focusable areas, yet are not focusable
via the mouse. Instead they can be focused via sequential tab
navigation.
Testing: This fixes a WPT test.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
These two commands are intertwined with the delete command. By
implementing them now, it becomes easier to triage actual
implementation issues in the delete command.
Part of #25005
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Rather than overwriting the CSP list from a fetch header response, we
should add a policy from a meta element to the global CSP list (if it
exists).
Fixes#36822
Supersedes and closes#36828
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Co-authored-by: Emmanuel Paul Elom <elomemmanuel007@gmail.com>
This abstracts out a common helper to determine focusable area kind
which is used by `Element::is_click_focusable`,
`Element::is_sequentially_focusable`, and `Element::is_focusable_area`.
This avoid having the latter depend on the former two, which was the
reverse of what the specification said. The helper is necessary because
the specification defines click and sequential focusability as subsets
of focusable elements, but going from "This is a focusable element" to
determining what kind of focusable element something is requires
duplicating a lot of the logic that was used to determine that something
is a focusable area.
It's likely that the specification needs more work here to improve the
definition (and indeed to unify all of the places that talk about what
elements are focusable areas). For now, this just tries to make our code
more similar to the text.
See: whatwg/html#4607
Testing: This shouldn't change behavior, so should be tested by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This change adds support for the `accesskey` HTML attribute the
corresponding behavior defined by the HTML standard. In addition to a
new map holding a mapping between access key characters and a rooted
reference to elements that use them, it adds a struct to represent the
"Command" concept from the specification [^1], which seems to be used
for `accesskey`. Not all command facets are implemented as some seem to
be unused in the specification.
[^1]:
https://html.spec.whatwg.org/multipage/interactive-elements.html#commands
Testing: This causes most access key tests to start passing. One test
now
only partially completes, because of a bug in the way that we fire
synthetic
mouse events.
Fixes: This is part of #25001.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
The conversion of strings was wrong for `--foo` where it should become
`-Foo`. Instead, it was consuming both the `--` and then would encounter
a `f`.
This moves the relevant algorithms to DOMStringMap and adds
corresponding spec comments to explain what's going on.
This does make us closer to passing
`html/dom/elements/global-attributes/dataset-delete.html` but
unfortunately it still fails because of #12978
Prior to this fix, the value of `d.dataset['-foo']` wasn't undefined.
However, we now fail the assertion where the attribute should remain,
despite the call to delete.
That's because per `LegacyOverrideBuiltIns` we should be checking the
existence of which properties it can delete, before it actually deletes
the attribute. Right now, we do it regardless if it is a valid property
and thus we incorrectly delete the attribute.
Testing: No change in tests, since the test in question has more
assertions that require more fixes
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
Add support for navigation requests ("navigateTo", "goBack", and
"goForward") over the Remote Debugging Protocol. These may be sent by a
UI client in response to user input (for example the address bar in the
Firefox inspector), or they can be used to automate navigation during
unit tests.
This currently only supports navigation within the URL domain at which
servoshell is initially launched, due to a bug in servo's
`BrowsingContextActor` implementation. (Unit tests covering a fix for
that issue will depend on this change.)
Testing: The behavior of all 3 new message types is covered by a new
test case—`test_navigation`—in the devtools unit test suite.
Fixes: #38668
---------
Signed-off-by: Brent Schroeter <contact@brentsch.com>
Co-authored-by: eri <eri@igalia.com>
Pass `ListFrames` back to devtools
Testing: existing test passes
Fixes: part of #36027
Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Co-authored-by: eri <eri@igalia.com>
We currently use `String` to store cryptographic algorithm name in
subtle dictionaries in WebCrypto code. The algorithm normalization
guarantees that there are only a limited number of possible strings that
can be assigned to the name fields.
We switch to use the `CryptoAlgorithm` enum, which contains all possible
algorithm names, to represent these values. This reduces string
comparison and saves a small amount of memory.
The constant string `ALG_*` in `subtlecrypto.rs`, which are the
recognized algorithm name for the algorithms, are also removed since
they are already embedded in the `CryptoAlgorithm` enum.
Testing: Refactoring. Existing tests suffice.
Fixes: Part of #42579
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
These were some of the remaining failures for link elements. They
concern attribute handling and when to run fetches.
1. We shouldn't refetch on media changes, but immediately apply the
effect. This is already the case for style elements
2. We shouldn't refetch when attribute values are the same
3. We shouldn't fetch when the type attribute doesn't match
4. We should fetch, even if the media doesn't match. Only when the media
is then changed, we should re-evaluate.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This implements an two types:
- Efficient Tree Iterator that can be used without rooting when
possible.
- UnrootedDom that can be used while not rooting while capturing a NoGC.
We:
- introduce new methods in 'script/dom/node.rs' to get the correct
iterator.
- introduce methods in 'script/dom/node.rs' to get the unrooted children
in an 'UnrootedDom' container.
We use the new TreeIterator in 'script/dom/document.rs' Open.
Testing: WPT tests should catch this but careful review is required.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This continues implementation of the delete command for
document.execCommand. Unfortunately, since these algorithms are vast
(30+ steps) and partial implementation leads to lots of issues, this PR
is "draw the rest of the owl".
I have tried to keep things manageable, by only implementing a couple of
extra steps in the delete command, so that we can focus on the "Delete
the selection" part.
To do that, several algorithms had to be implemented. Most of these
algorithms are required both by commands and by algorithms themselves,
which is why they are now exposed on a trait.
Additionally, all code now uses `cx`, to make sure it is up-to-date with
the ongoing migration and since some of the DOM API's it needs to call
already require `cx`.
Part of #25005
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This change implements listing all frames from youngest to oldest. This
is in order to send correct frame message from thread actor
This is needed for our upcoming work!
Testing: Current tests are passing + manual test
Fixes: #36027
Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Co-authored-by: eri <eri@igalia.com>
As requested during the review of
https://github.com/servo/servo/pull/42991. These functions are currently
called `{to, from}_layout_js` or sometimes `get_jsmanaged` - this change
unifies them as `{to, from}_layout_dom` for clarity.
Testing: Covered by existing tests
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
In layout calculation within script, Instead of relying on the computed
values for overflow, query the overflow from layout for its used value
to accurately reflect whether an element establish a scroll container.
This query will be used for `IntersectionObserver` as well.
Testing: There are new `IntersectionObserver` WPT failures:
- `intersection-observer/isIntersecting-change-events.html`
- `intersection-observer/containing-block.html`
The failures are more than likely a false positive because intersection
observation steps wasn't supposed to trigger a reflow, but it was
before. It could be caused by the implementation of
`IntersectionObserver` in major UAs being a little bit different from
the spec in the calculation of `threshold` and `isIntersecting` .
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This changes makes it so that keyboard and click focusability are two
separate concepts in `script`. Some elements may be focusable only by
the keyboard and some only by the click events.
In addition, the `SEQUENTIALLY_FOCUSABLE` `Node` flag is removed in
favor of a
more specification-aligned approach of checking lazily if an element is
a focusable area. This allows moving the focus fixup steps to their
correct place, asynchronously during "update the rendering" and
synchronously during `unbind_from_tree`.
Testing: This causes some WPT tests to start passing and some to start
failing:
- Two subtests tests in
`tests/wpt/meta/css/css-conditional/container-queries/` because
we do not implement support for container queries. These are legitimate
failures
and they are compensated by a good subtest pass in the same file.
- A few subtests in `/html/interaction/focus/tabindex-focus-flag.html`
because now
we do not allow focusing non-rendering elements. The failures are HTML
elements with
`<svg>` which we do not rendering and `<summary>` elements of
`<details>` which
need special handling we do not implement yet.
- `html/semantics/forms/the-fieldset-element/disabled-003.html`: Some of
these tests
start to fail, but they are not spec compliant and browser properly
implementing
the asynchronous focus fixup rule also fail them.
Fixes: #31870.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Improvements to command button implementation
- Correctly handle the button's optional value concept
- Add the button as the source value for the CommandEvent
- Fix handling of buttons in auto state
Testing: Existing tests
Signed-off-by: Luke Warlow <lwarlow@igalia.com>
Moves the `Drop` logic for `GPURenderPassEncoder` into a dedicated
helper struct, `DroppableGPURenderPassEncoder`. This ensures that DOM
types do not directly implement `Drop`, aligning with the policy for
resource management in the DOM. The associated `Bindings.conf` entry is
removed as direct `Drop` is no longer needed for this type.
Testing: WebGPU tests just cover its cases
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Stylo has ready-to-use apis for `Node::querySelector` and
`Node::querySelectorAll`. We currently instead set up our own selector
queries, which is neither as correct nor as performant, so this change
makes servo use the stylo interfaces instead.
This change contains a fair amount of unsafe code - review with caution!
Notably, this makes the tab component from the astro framework work
correctly in servo (https://starlight.astro.build/components/tabs/).
I've seen that (broken) component on multiple websites.
Fixes https://github.com/servo/servo/issues/41105
Testing: New tests start to pass
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
We introduce a new type of callback, LazyGenericCallback and use it in
websocket initialization.
The basic requirement is that for websocket the place where the callback
is called and where it is constructed are over several functions,
including async functions. To make this generic, we implement
LazyGenericCallback and a GeneralCallbackSetter. The CallbackSetter can
be used to set the callback which then will be transfered to the
LazyGenericCallback which calls it on messages send to it.
Finally, we use this to "Generify" the initialization of WebSockets.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Testing: We have new tests for LazyGenericCallback and wpt test run
here: https://github.com/Narfinger/servo/actions/runs/21246091767
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Co-authored-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com>
The frontend connection metadata was not consistently synchronized with
backend object store state during open/upgrade, and upgrade abort did
not fully restore the connection object store set in all cases.
Testing: More indexeddb tests should pass.
part of https://github.com/servo/servo/issues/40983
---------
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
DomRefCell::borrow inside of layout code is risky because it leads to
memory races if the code is ever called from layout worker threads. This
can be caught via TSAN, but we can also catch it deterministically in CI
by using our existing thread state debug assertions correctly.
Testing: Existing WPT test coverage is sufficient.
Fixes: #42962
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
In the WebCrypto modern algorithm specification, the issue
(https://github.com/WICG/webcrypto-modern-algos/issues/47) on algorithm
name referencing in the export key operation of ML-KEM had been resolved
by the following commit in the specification repository:
705f8ec6ce
Our implementation actually matches the new specification. We simply
update the specification text, with some minor refactoring accordingly.
This is equivalent the changes on ML-KEM in #42918 in which I forgot to
include the counterpart for ML-DSA :(
Testing: Refactoring. Existing tests suffice.
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Testing: New tests start to pass. Most related tests still fail because
we dispatch mouse and pointer events in the wrong order.
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Moves the `Drop` logic for `GPURenderBundle` into a dedicated helper
struct, `DroppableGPURenderBundle`. This change ensures that
`GPURenderBundle` itself does not directly implement `Drop`, aligning
with the policy to prevent direct `Drop` implementations on DOM types.
Removes the `allowDropImpl` configuration for `GPURenderBundle` from
script bindings.
Testing: WebGPU tests cover all related cases
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
This changes `Element::selector_flags` from `Cell<ElementSelectorFlags>`
to `AtomicUsize`, thus avoiding the risk of data races.
Testing: Tested manually. We don't run tests using TSAN builds.
Fixes: #37495
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Adds support for more pointer events: pointerenter, pointerout,
pointerleave, pointerover
Also add global event handlers that were missing.
Testing: WPT expectations are updated.
cc @yezhizhen
Signed-off-by: webbeef <me@webbeef.org>