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>
A new event `PlayerEvent::DurationChanged` has been added to the media
engine to simplify handling changes in the duration of a media stream
(sometimes the duration could be inaccurate or even determined by the
media engine with significant delay after the initial metadata was
ready).
This new event eliminates the need to check conditions for two
consecutive `MetadataUpdated` events (the initial metadata and the
metadata with the changed duration) during the loading phase.
servo-media:
- Add new `PlayerEvent::DurationChanged` event
(https://github.com/servo/media/pull/461)
Testing: No expected changes in test results
Fixes: https://github.com/servo/servo/issues/40626
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
The two are semantically equivalent, but `find_map` is more concise.
Testing: Covered by existing tests
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Follow the HTML specification and split the previous `playback position`
to `current playback position` (a time on the media timeline) and
`official playbac position` (an approximation of the current playback
position that is kept stable while scripts are running) which must be
set to `the current playback position` any time the user agent provides
a stable state.
See https://html.spec.whatwg.org/multipage/#current-playback-position
See https://html.spec.whatwg.org/multipage/#official-playback-position
Note that at this point, there are no difference between the `current`
and `official` playback positions (as the time on the media timeline),
except the `seek` case.
Testing: Improvements in the following tests
-
html/semantics/embedded-content/media-elements/seeking/seek-to-max-value.htm
-
html/semantics/embedded-content/media-elements/seeking/seek-to-negative-time.htm
Fixes: https://github.com/servo/servo/issues/34496
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
Following the HTML specification, a new internal method,
`ended_playback`, has been added to differentiate it from the `ended`
attribute:
- `ended_playback`: playback has ended for the `forward/backward`
directions
- `ended` attribute: playback has ended for the `forward` direction
See https://html.spec.whatwg.org/multipage/#ended-playback
Added descriptions for the steps of the `Play`, `Pause`,
`internal_play_steps` (new), `internal_pause_steps`,
`notify_about_playing`, `change_ready_state` methods.
Testing: No expected changes in test results.
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
The `seek` method isn't explicitly exposed in the API, but is called
from various places (`currentTime`, `fastSeek`, by the `media metadata`
event) and doesn't itself create new DOM objects, so the `canGC`
argument can be omitted.
It was previously required because calling the `Seekable` method creates
a new `TimeRanges` object, but it will now be replaced by the internal
`seekable` method to avoid interaction with the JavaScript engine (and
potential garbage collector).
The `earlyest possible position` method has been changed to match the
specification and use `seekable` instead of `played`. See
https://html.spec.whatwg.org/multipage/#earliest-possible-position
Testing: No expected changes in tests
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
Updated the `PlayerEvent::PositionChanged/SeekDone` events to support
precise position timestamps (u64 -> f64).
Also set precise time value (seconds with fractional part) for the
HTMLMediaElement `duration` from media metadata to sync with
`PlayerEvent` changes.
servo-media:
- Pass precise position timestamp within PlayerEvent
(https://github.com/servo/media/pull/460)
Testing: No expected changes in test results
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
Have more of the code follow the same path calling
`ScriptThread::spawn_pipeline`. Somewhat tricky was that the `origin` of
the new Pipeline was being determined in several different places, but
all in a consistent way for different types of page loads. This change
makes it is so that the origin is always determined in the same place.
This change is preparation for splitting out the creation of a new
`ScriptThread` and the spawning of its first pipeline.
Testing: This should not change observable behavior, so is covered by
existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Adds an optional error message to HierarchyRequestError
Testing: refactor
Fixes: one item in #39053
---------
Signed-off-by: Austin Willis <austinwillis8@gmail.com>
The goal of this change is to prevent having to copy so much data out of
listeners when a fetch completes, which will be particularly important
for off-the-main thread parsing of CSS (see #22478). This change has
pros and cons:
Pros:
- This makes the design of the `FetchResponseListener` a great deal
simpler.
They no longer individually store a dummy `ResourceFetchTiming` that is
only replaced right before `process_response_eof`.
- The creation of the `Arc<Mutex<FetchResponseListener>>` in the
`NetworkListener` is abstracted away from clients and now they just
pass the `FetchResponseListener` to the fetch methods in the global.
Cons:
- Now each `FetchResponseListener` must explicitly call `submit_timing`
instead of having the `NetworkListener` do it. This is arguably a bit
easier to follow in the code.
- Since the internal data of the `NetworkListener` is now an
`Arc<Mutex<Option<FetchResponseListener>>>`, when the fetching code
needs to share state with the `NetworkListener` it either needs to
share an `Option` or some sort of internal state. In one case I've
stored the `Option` and in another case, I've stored a new inner
shared value.
Testing: This should not change observable behavior and is thus covered
by existing tests.
Fixes: #22550
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Add context menu options for images, links, and editable text areas. In
addition add the ability to show menu options that are disabled. This
also improves the visual style of the context menu in egui as part of
supporting disabled options.
Testing: This has been manually tested, but we could we should be able
to
easily add unit tests when enriching the API with information about the
active element under context menus.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.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>
Add missing description for steps of legacy <audio> constructor with a
small refactoring, avoiding unnecessary `upcast` from `HTMLAudioElement`
to `Element`.
See https://html.spec.whatwg.org/multipage/media.html#dom-audio
Testing: No expected changes in tests (added steps description).
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
For some specific cases (one of them see below) where are requirement to
identify the reason of the attribute mutation (by whom/why it was
changed - by cloning, parser or directly), so the following `reason`
parameter was added to `AttributeMutation::Set` option.
Note that for the HTMLMediaElement the internal `muted` state should be
set to true when the element is created and the element has a `muted`
content attribute specified (should be done once on the first attribute
mutation caused by parser or cloning).
See https://html.spec.whatwg.org/multipage/#dom-media-muted
Testing: Improvements in the following tests
-
html/semantics/embedded-content/media-elements/user-interface/muted.html
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
Use `InputEvent` for text input and set appropriate values for the
`composed`, `data`, `isComposing`, and `inputType` attributes. Use a
placeholder for `dataTransfer` attribute and `getTargetRanges` function,
as they are only applicable to contenteditable, which isn't implemented.
Testing: I added two tests under `tests/wpt/mozilla/tests/input-events`
based on the similarly named ones for contenteditable under
`tests/wpt/tests/input-events`.
Fixes: https://github.com/servo/servo/issues/36398
---------
Signed-off-by: Excitable Snowball <excitablesnowball@gmail.com>
Follow the specification and allow to render media controls (expose a
user interface to the user) without any HTMLMediaElement `readyState`
precondition.
The media controls be shown for the following examples without specified
media source (e.g. without `src` attribute).
```
<audio controls></audio>
<video controls>/<video>
```
See https://html.spec.whatwg.org/multipage/media.html#user-interface
For media controls UI don't define root `div` element's style `width`
property from the video natural size (`videoWidth/Height` IDL attributes
which return `0` if `readyState` is `HAVE_NOTHING`).
When the `media` element is adopted between different documents need
adopt the media controls id, so media controls UI
will keep access to the whilelist of media controls identifiers via
`document.servoGetMediaControls(id)` API.
Testing: Improvements in the following tests
-
html/rendering/replaced-elements/embedded-content-rendering-rules/audio-controls-00*
-
html/semantics/the-button-element/command-and-commandfor/on-audio-behavior.tentative.html
-
html/semantics/the-button-element/command-and-commandfor/on-audio-invalid-behavior.tentative.html
Note that `Invoker Commands` API is not yet supported so these `command
and commandfor` tests should fail, but due to previous bug with delayed
media controls shown up. The invoker `onClick` function send actions
with mouse events
(move/up/down) to the test driver at the position of the button element
(via getBoundingClientRect), but before test driver
will handle these actions the mediadata is received and media controls
are shown up with "play" button at this position.
So the media control "play" button is clicked instead of the button, and
it triggers media element `pause` state change.
See https://open-ui.org/components/invokers.explainer/
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
Adds a wrapper type for vectors that can contain large response bodies
to prevent flooding debug logs with the contents of those bodies.
Testing: Can't test debug log output.
Fixes: #37769
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
The thing that this message does is to spawn a pipeline in a
`ScriptThread`. I believe that the `AttachLayout` name is a relic of a
different time. The corresponding procedure in the `Constellation` is
already called `Pipeline::spawn`.
Testing: This is just a rename, so existing tests should cover this
change.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This PR adds context menu support with clickable menu items in the
Minibrowser. The menu appears on right click and supports basic
navigation actions (Back, Forward, Reload).
Testing: We already have tests for ContextMenu in WebView API test.
Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
RasterImage is now not seralizeable and backed by Vec<u8> storage. Add a
new struct `SharedRasterImage` that allows serializeing. This can be
constructed from RasterImage. This introduces some more copying but I
think the tradeoff is ok. Newly introduced copies are for favicon
response to the embedder and EmbedderNotifications.
Testing: Should not change functionality, so covered by existing tests.
Fixes: https://github.com/servo/servo/issues/39626 and related issues.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.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>
`FetchReponseListener` has traditionally lived in `net` even though it
is only used in `script` currently. Because of the two way dependency,
it has also use a lot of templating to implement something pretty basic
(call methods on a trait object).
This change moves the trait to `script` and removes several levels of
templating, making the code quite a bit shorter and easier to
understand.
This change is preparation for fixing #22550 and implementing
off-the-main-thread CSS parsing.
Testing: This should not change any behavior so is covered by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Previously, the `ImageCache` would inform consumers of changes to image
availability by messaging an IPC channel. This isn't great, because it
requires serialization and deserialization. Nowadays, `ImageCache`s are
always owned by the same `Global` that uses them. This change replaces
the IPC channel with callback that implements `Send`.
For the case of normal HTML document images, the results are still sent
over the pre-existing Crossbeam channel that was connected via an IPC
route. A followup change might eliminate that channel entirely.
Testing: This should not change observable behavior so is covered by
existing tests.
Fixes: #24338.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Removes some unneeded lints, especially `#[allow(unsafe_code)]`.
Testing: Refactor
Part of: #40383
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
Instead of having the `ImageCache` return the broken image icon for
failed loads, have `HTMLImageElement` explicitly request it. This means
that the image is loaded on demand (reducing the usage of resources) and
also simplifying the interface of the `ImageCache` greatly.
In addition, the display of the broken image icon is improved, more
closely matching other browsers. A test for this display (which was
falsely passing before) is updated to reflect the new display of the
broken image icon.
Testing: There is a Servo-specific test for this change. Some WPT tests
start to fail as well. Before these were not properly loading the broken
image icon so they were failing before, just in a hidden way.
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Partially implement dialog.showModal()
Follow-ups will be needed to further implement proper dialog
functionality but this makes a good start.
Testing: Existing WPTs cover this.
---------
Signed-off-by: Luke Warlow <lwarlow@igalia.com>
The HTMLMediaElement should stop playback of any previously playing
media resource on running media element loading algorithm or before
attempt to load next source child.
This step will reset media player (including release of the underlying
media resources and media frames from the video renderer).
The closure for marshalling the incoming GLPLayer messages from ROUTER
("router-proxy") thread to script thread will use
`Weak<MediaFrameRenderer>` instead of `Trusted<HTMLMediaElement>` to
break circular references dependency (decouple ownership).
The media frame renderer will track the media player id to be able
ignore async locking render call with new frame after playback of any
previously playing media was stopped.
Testing: No WPT test expectation changes
Fixes (partially): https://github.com/servo/servo/issues/40243
Fixes (partially): https://github.com/servo/servo/issues/40265
Fixes: https://github.com/servo/servo/issues/37173
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.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>
This change makes it so that the `HTMLCanvasElement` is responsible for
managing the `ImageKey` for associated `RenderingContext`s. Only
canvases display their contents into WebRender directly, so this makes
it so that keys are not generated for `OffscreenCanvas`.
The main goal here is that `ImageKey`s are always associated with a
particular `WebView`, which isn't possible in the various canvas
backends yet. This is important because each `WebView` may soon have a
different WebRender instance entirely with its own set of `ImageKey`s.
This also allows for clearing `ImageKey`s when canvases are disconnected
from the DOM in a future change. One tricky thing here is placeholder
canvases, which are meant to be driven from workers.
It seems that the implementation isn't correct for these at the moment
as they need to be updated to the specification. Instead, what is
happening is that any existing context / image is completely lost when
converting to an `OffscreenCanvas`.
Testing: This shouldn't change observable behavior, so is covered by
existing tests.
Fixes: This is part of #40261.
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Prevent the running of the iframe load event steps for the initial
about:blank document. Part of
https://github.com/servo/servo/issues/31973
Testing:
/html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/iframe-nosrc.html
Fixes: It is expected that the intermittent issue of 34819 will go away,
but I will leave it open so we can close it when we realize it isn't
being mentioned by PR's anymore.
https://github.com/servo/servo/issues/34819
---------
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
This change fixes the Servo-specific FileAPI tests which need the
special `SelectFiles` API. In addition, file selection is now totally
asynchronous, so update the tests to handle this.
Testing: This change fixes some tests.
Fixes: #40348.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
script: add `CanGc` as argument to
`VirtualMethods.post_connection_steps`
Testing: These changes do not require tests because they are a refactor.
Addresses part of https://github.com/servo/servo/issues/34573
Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.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>
script: add CanGc as argument to VirtualMethods::children_changed
Testing: These changes do not require tests because they are a refactor.
Addresses part of https://github.com/servo/servo/issues/34573
Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
Fixes the getters for `formMethod` on `<input>` and `<button>` elements
providing a missing value default when they shouldn't.
Testing: 2 new passing tests in `html/dom/reflection-forms.html`.
Fixes: #8302. (`formEnctype` seems to have already been fixed since that
issue was filed.)
---------
Signed-off-by: lumiscosity <averyrudelphe@gmail.com>
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 performance spec to the
`script/dom/performance/` module from `script/dom/`.
Testing: Just a refactor shouldn't need any testing
Fixes: Partially #38901
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
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>
When changing the 'volume' attribute of media element, should also call
`set_volume()` api of underlying player if it is valid value.
Testing: No Test is required, as this should not affect any WPT Test
Fixes: N/A
---------
Signed-off-by: rayguo17 <rayguo17@gmail.com>
Signed-off-by: TIN TUN AUNG <62133983+rayguo17@users.noreply.github.com>
Co-authored-by: Euclid Ye <yezhizhenjiakang@gmail.com>
The remainder of this algorithm updates the slottables assigned slot and
the slots assigned nodes, but neither operation will do anything if the
slottables didn't change. This should be a slight performance
improvement.
Testing: Covered by existing tests
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This splits `Snapshot` into two structs:
- `Snapshot`: A non-serializable owned image buffer that might contain
either shared memory or a `Vec<u8>`. When mutated the shared memory
version is converted into a `Vec<u8>` avoiding a copy of the data
until absolutely necessary.
- `SharedSnapshot`: A serialzable version of `Snapshot` that contains
only shared memory and is suitable for sending across IPC channels.
This version is cheaply convertible from and to owned `Snapshot`s as
long as the source is also a shared memory `Snapshot`.
In addition, it does copyless conversions of `RasterImage` into
`Snapshot`s (including for frame offsets in animated images). Finally,
there are a few minor changes to try harder not to have to do a
`transform()` operation.
Testing: This should not change observable behavior, so is covered by
existing
tests. It should come with a mild performance improvement and open up
the
opportunity for others.
Fixes: #36594.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Follow the HTML specification and add the missing 'name' and 'areas' IDL
attributes to HTMLMapElement.
https://html.spec.whatwg.org/multipage/#htmlmapelement
Testing: Improvements in the following WPT tests
- custom-elements/reactions/customized-builtins/HTMLMapElement.html
- html/dom/idlharness.https.html
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>