Commit Graph

106 Commits

Author SHA1 Message Date
Martin Robinson
824f551f03 Rename IOCompositor to Paint (#41176)
For a long time, the "Compositor" hasn't done any compositing. This is
handled by WebRender. In addition the "Compositor" does many other
tasks. This change renames `IOCompositor` to `Paint`.

`Paint` is Servo's paint subsystem and contains multiple `Painter`s.
This change does not rename the crate; that will be done in a
followup change.

Testing: This just renames types and updates comments, so no new tests
are necessary.

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-12-10 15:09:49 +00:00
Narfinger
6f62269c8c Devtools: Switch to GenericChannel and GenericCallback (#41051)
Switch the devtools part to GenericCallback and GenericSender.
To keep the diff small the names where not changes as a Sender almost
fills the same requirement as a callback.

Testing: As this is mostly type changes, the compilation is the test but
also devtools seem to work fine with these changes. ./mach try run is
here: https://github.com/Narfinger/servo/actions/runs/19931697694

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-12-08 11:03:45 +00:00
Narfinger
b102434ce0 Use 'GenericSender' and 'GenericReceiver' for bluetooth main component (#41008)
Using generic channel for bluetooth module.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>

Testing: This should not change functionality.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-12-02 18:13:31 +00:00
Martin Robinson
2503684d84 constellation: Break the EventLoop dependency on the initial Pipeline (#40944)
Currently starting a script `EventLoop` depends on sending data about
the initial `Pipeline`. This change breaks this dependency. The goal
here is to:

1. Allow `ScriptThread`s to be shared between `WebView`s. This will
   allow more flexiblity with the way that `ScriptThread`s are created,
   which should allow us to perserve system resources by allowing them
   to be shared between `WebView`s. With this change, we can do away
   with the `InitialPipelineState` entirely, which was gather
   information necessary for both a new `EventLoop` and a new
   `Pipeline`. We no longer have to do many clones when reusing an
   existing even loop.
1. Simplify the way that `EventLoop`s and `Pipeline`s are spawned. Now
   `Pipeline`s are spawned in the same way no matter what.

Now the general order of operations when starting a pipeline is:

1. Get or create an event loop for the pipeline:
    - If the event loop needs to be spawn, spawned it in a new thread or
      process.
2. Send the spawn pipeline message to the event loop (kept alive via an
   `Rc`.

Testing: This should not change behavior in a way that is observable, so
should
be covered by existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-29 23:30:17 +00:00
Martin Robinson
08aad55ef7 script: Break the ScriptThread dependency on the initial Pipeline (#40918)
`ScriptThread`s start with an initial `Pipeline`, but that `Pipeline`
should not be used for any `ScriptThread` global data as a
`ScriptThread` can have any number of `Pipeline`s that come and go.
There's no architectural reason why a `ScriptThread` should be
associated with only a single `WebView`.

This change makes it so that the `ScriptThread` no longer uses the
`PipelineId` and the `WebViewId` of the initial `Pipeline` to initialize
itself. Instead a `ScriptEventLoopId` is used to uniquely identify every
`ScriptThread` in both the `ScriptThread` and the `Constellation`.
The remaining use was for crash reporting. Now when a crash happens, it
launches the sad tab in all `WebView`s that depeneded on that
`ScriptThread`.

This is a change which should allow simplifying the way that
`EventLoop`s/`ScriptThread`s are started in the `Constellation`, which
will be handled in a followup.

Testing: This shouldn't change behavior except in the case where a
`ScriptThread` is used in more than a single `WebView`, which should
work
properly now. I tested this change manually by running servoshell in
multiprocess mode while causing a panic to happen due to a null pointer
dereference. The sad tab appeared after this change, so things seem to
work
properly still. Testing crashes is tricky with the way we test servo
now.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-27 13:34:57 +00:00
Jan Varga
0899b87dd4 Fix inconsistent strum dependencies and imports (#40907)
The `scripts_traits` crate was the only crate depending on `strum` with
the
`derive` feature. This accidentally allowed other crates to import strum
macros via `strum::` without declaring their own dependency on
`strum_macros`,
causing compilation issues when running `./mach test-unit -p net`.

This PR makes the imports consistent across the code base by:
- replacing all `strum_macro::` imports with `strum::` imports
- removing strum_macro dependencies
- adding derive feature to the strum workspace

Testing: Unit tests continue to pass

Signed-off-by: Jan Varga <jvarga@igalia.com>
2025-11-26 21:37:55 +00:00
Martin Robinson
b334c9470b constellation: Reuse InitialScriptState and InitialPipelineState in UnprivilegedPipelineContent (#40529)
`UnprivilegedPipelineContent` contains all of the data necessary to
create a new `ScriptThread` with an initial `Pipeline` in a new
process. This change reuses the `InitialScriptState` and
`InitialPipelineState` structs inside `UnprivilegedPipelineContent` and
renames it to `NewScriptEventLoopProcessInfo` to clarify what it does.

In addition, `InitialScriptState` also repeated much of the data of
`NewPipelineInfo`, which is now deduplicated and passed separately to
the `ScriptThreadFactory`.

The overall goal here is to make `ScriptThread` and `Pipeline` creation
separate. A `ScriptThread` contains many `Pipeline`s which come and go,
so it should not depend on a single creation `Pipeline`. This is the
first step toward doing that.

Some inputs to `ScriptThreadFactory` differ based on whether the new
`ScriptThread` is created in a new process or not. This change makes it
so that these input are passed as extra arguments.

Finally these changes have revealed a couple members of data structures
that aren't used. These have been removed.

Testing: This is just a refactor and shouldn't change behavior so is
covered by existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-10 11:41:59 +00:00
Martin Robinson
dfc9819b38 script: Rename ScriptThreadMessage::AttachLayout to ScriptThreadMessage::SpawnPipeline (#40491)
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>
2025-11-08 11:16:58 +00:00
Shubham Gupta
71196c02ea Add basic IDL implementation for LargestContentfulPaint (#39714)
Add basic `IDL` implementation for `LargestContentfulPaint`

Testing: Tested locally
Fixes: N/A

<img width="800" height="210" alt="Screenshot from 2025-11-06 12-56-37"
src="https://github.com/user-attachments/assets/af453b8d-7605-4300-8c87-c2574feff81f"
/>

---------

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
2025-11-07 02:56:30 +00:00
Martin Robinson
fd54ce9059 script: Eagerly update the Device in Layout when it changes (#40432)
Instead of waiting for a reflow to update the `Device` in layout, update
it eagerly. This ensures that media queries can be answered correctly in
script before the next reflow. Also, it ensure that a new reflow is
triggered and reflects the change to the theme or viewport.

In addition, an unused viewport-related message from the Constellation
is removed. This would have needed to be updated by change, but since
it's unused I've just removed it.

This depends on https://github.com/servo/stylo/pull/260.

Testing: This fixes a WebView API test and improves

`/html/semantics/embedded-content/the-img-element/environment-changes/viewport-change.html`.

Fixes: #40395.
Fixes: #40129.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-05 21:17:23 +00:00
Martin Robinson
eed97f458b net: Associate every ImageCache with a WebView (#40376)
Every `ImageCache` should be assigned a `Pipeline` and a `WebView`, so
that it knows what WebRender instance to create image keys in. This
change accomplishes that by splitting the `ImageCache` trait into
`ImageCache` and `ImageCacheFactory`. There should only be one
`ImageCacheFactory` per process.

Testing: This should not change observable behavior and is thus covered
by
existing tests.

Fixes: This is part of #40261.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-04 08:26:05 +00:00
Shubham Gupta
9eb3a973ae Add support for LargestContentfulPaint PaintMetric (#39384)
Steps for calculating LCP:
1. When the pref for `largest_contentful_paint_enabled` is enabled,
`LargestContentfulPaintCandidateCollector` is created once per
LayoutThread using `viewport_size`.
2. While building the `display_list`, it send the pre-calculated
`clip_rect` and `bounds` to `LCPCollector` along with `transform` and
`LCPCandidateType` for `visual_rect` calculation for `LCPCandidates`.
3. After `visual_rect` calculation, update the `lcp_candidate` based on
`area` of `visual_rect` and send it to `compositor`.
4. Then among `lcp_candidates`, we find out the
`largest_contentful_paint` and send it to `paint_metric`
5. In addition to above `LCP` also uses `PaintMetricState` to save
console from spamming with duplicate entries.



This PR includes following commits better segregation of code
1. Add `LargestContentfulPaintCandidate` struct
2. Add `LargestContentfulPaintCandidateCollector`
6. Collect the `LargestContentfulPaintCandidates`when feature is
enabled.
7. Send the `LargestContentfulPaintCandidates` to compositor
8. Add `LargestContentfulPaintCalculator`
9. Calculates the `LargestContentfulPaint`
10. Send `LCP` to `PaintMetrics`
11. Disable `LCP` feature on user interaction


Elements considered for LCP in this PR:
- Image element
- An element with background image

Reference: https://github.com/servo/servo/pull/38041
Testing: Tested using
[perf-analysis-tools](https://github.com/servo/perf-analysis-tools) See
attached screenshot.
Fixes: None

Perfetto
<img width="2566" height="1151" alt="Screenshot from 2025-10-16
11-37-41"
src="https://github.com/user-attachments/assets/96e4f933-b39c-4ac7-833c-46dcc0c1671e"
/>


Console Output of Metric
<img width="1784" height="282" alt="Screenshot from 2025-10-16 11-33-16"
src="https://github.com/user-attachments/assets/441746a5-92ae-47c6-9022-f49114f23a2d"
/>

---------

Signed-off-by: Shubham Gupta <shubham.gupta@chromium.org>
Co-authored-by: boluochoufeng <1355990831@qq.com>
2025-10-31 08:58:22 +00:00
Martin Robinson
148ce3e9c7 constellation: Always include the WebViewId in Pipeline specific messages (#39974)
It would be useful for  the Constellation is ever going to store data
per-WebView for the purposes of making cleanup and resource management
easier. If that's ever going to happen the `WebView` needs to be passed
with all messages that need it. This change makes it so that messages to
the Constellation that require a Pipeline also carry a WebViewId. This
eliminates one way in which message handling might go wrong.

This avoids making the Constelaltion look up the `WebViewId` for many
messages
that it receives.

Testing: This should not change observable behavior, so should be
covered by existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-10-18 14:23:24 +00:00
Gregory Terzian
631a2b1268 constellation: add source browsing context info in forwarded post message (#39833)
For cross-document messaging, when the constellation forwards the
message, it can add the source browsing context and ancestry info to the
message. This saves a round-trip back to the constellation from script
later, and also allows for messages to be delivered when the source
pipeline is closed by the time of delivery(but not by the time of
forwarding by the constellation).

Testing: Updated various tests in
`/html/semantics/embedded-content/the-iframe-element/` WPT: from
TIMEOUT(because message was not delivered) or intermittent CRASH(because
the source pipeline would be closed by the time of attempted delivery.)
to FAIL.
Fixes: https://github.com/servo/servo/issues/39748

---------

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
2025-10-17 11:20:53 +00:00
shuppy
0d57fcb3e6 libservo: Merge file selection dialog into EmbedderControls (#39859)
in #39709, we introduced a single “form control” or “embedder control”
delegate that requests the embedder’s input for &lt;select> and
&lt;input type="color"> elements.

this patch partially merges &lt;input type="file"> elements into that
new system, and renames “form controls” to “embedder controls” for
consistency.

internally we continue to use a separate code path where the embedder
directly communicates with the file manager thread. subsequent work will
make the messages asynchronous via the constellation and script thread,
like other embedder controls.

Testing: this is currently tricky to write an automated test for; we
expect to write a WebDriver test for this once we make the communication
asynchronous

---------

Signed-off-by: delan azabani <dazabani@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-10-15 06:12:19 +00:00
Martin Robinson
b9b2111f34 libservo: Notify the embedder when an input event can't be sent to a Pipeline (#39810)
The `WebViewDelegate::notify_input_event_handled` method is called for
the
embedder when an input event's processing has finished within Servo.
This allows the embedder to chain the event up to parent widgets or do
some kind of post-processing such as the implementation of overridable
keybindings.

This change makes it so that this method is called even when an input
event cannot successfully be sent to a pipeline. This could happen when
an event is handled during navigation or perhaps during shutdown. In any
case, Servo should *always* tell the embedder when the event is done
processing so that they don't get eaten by the Servo widget.

Testing: This is very difficult to test as it only happens in very
specific
time-sensitive sitautions.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-10-12 09:26:38 +00:00
Martin Robinson
12e5d1b05e libservo: Unify notifications to the embedder that input events are handled (#39720)
Servo currently has three ways of notifying the embedder that input
events have been processed.

1. `WebViewDelegate::notify_keyboard_event`: This is used to implement
   overridable keybindings in servoshell. It notifies the embedder when
   a keyboard event has been processed, but not "handled" by the engine.
2. WebDriver's command message senders and receivers, this is used to
   let WebDriver wait until events have been handled to continue with
   script execution.
3. Touch event processing notifications: This is used to serialize touch
   event processing.

This change unifies the first two things with a new
`WebViewDelegate::notify_input_event_handled` API. This API informs the
embedder (via a generated id) that an input event has finished
processing and what the result of the processing was.

This allows embedders to do other things with events once they have been
processed. For example, embedders might want to chain unconsumed events
up to parent widgets or to add support for overridable keybindings.

As part of this the `canceled` flag in script's `Event` data structure
is turned into a `bitflags` mirror of the new API type to describe the
result of event handling.

Testing: This shouldn't change observable behavior and is thus covered
by existing tests.
The new API is consumed by servoshell, which uses it for tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-10-10 07:48:06 +00:00
Martin Robinson
89dfb3ee49 libservo: Make FormControl responses completely asynchronous (#39709)
Before responses to `FormControl` requests were handled synchronous in
script (ie they would block the page). This change makes it so that they
are handled asynchronously, with their responses filtering back through
the Constellation. This should fix many WPT tests when run with
WebDriver.

Testing: There are some WebDriver-based test for this, but they do
not quite pass yet. More investigation is required, but this is
necessary to get them to pass.
Fixes: #39652
Fixes: #37013

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Delan Azabani <dazabani@igalia.com>
2025-10-08 09:06:17 +00:00
Martin Robinson
6ffc0cd482 libservo: Add a WebView::take_screenshot() API and use it for reftests (#39583)
This change adds a new API to the `WebView` for capturing screenshots.
This makes it possible to:

 - use the reftest waiting infrastructure via the API
   easily.
 - take more than a single screenshot in one Servo run.
 - take screenshots, but still paint the `WebView` normally prior
   to the moment that the screenshot is ready, instead of preventing
   all non-screenshot-ready paints while taking a screenshot.

In addition, the previous infrastructure, the `wait_for_stable_image`
option is removed completely.

Testing: This change is tested by the passing of the WPT tests,
as they commonly use the screenshot feature.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Delan Azabani <dazabani@igalia.com>
2025-09-30 11:39:47 +00:00
Ashwin Naren
fef56fcc47 Consistently rename storage to webstorage to prevent confusion (#39550)
Add the prefix of "WebStorage" instead of "Storage" for all webstorage
spec related things. For example, a `struct` called `StorageManager`:
this could refer to either webstorage's thread manager or to the backend
for [the storage manager
interface](https://storage.spec.whatwg.org/#storagemanager). webstorage
is the full name of the spec, so I chose to keep that in the names of
files/structs to prevent confusion when storage manager is implemented.

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-09-29 17:13:34 +00:00
Ashwin Naren
d12dc23083 storage: Move storage related backend threads to their own crate (#39418)
This PR moves storage related APIs (currently just webstorage and
indexeddb) into their own crate. This reduces the congestion in the net
thread.

Related Zulip thread:
https://servo.zulipchat.com/#narrow/channel/263398-general/topic/indexedDB.20location/with/535911631

Sub PRs:
- [x] Move shared storage/net stuff to base (`IpcSend` and
`CoreResourcePool`) #39419

---------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-09-28 08:00:20 +00:00
Martin Robinson
ffdb7d3663 script: Chain up keyboard scrolling to parent <iframe>s (#39469)
When an `<iframe>` cannot scroll because the size of the frame is
greater than or
equal to the size of page contents, chain up the keyboard scroll
operation to the parent frame.

Testing: A new Servo-only WPT tests is added, though needs to be
manually
run with `--product servodriver`.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Delan Azabani <dazabani@igalia.com>
2025-09-25 11:16:41 +00:00
Narfinger
84465e7768 Removed FnvHash and transformed the rest to FxHashmap (#39233)
This should be the final PR for the Hash Function series that is
trivial.

Of note: I decided to transform `HashMapTracedValues<Atom,..>` to use
FxBuildHasher. This is likely not going to improve performance as Atom's
already have a unique u32 that is used as the Hash but it safes a few
bytes for the RandomState that is normally in the HashMap.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>

Testing: Hash function changes should not change functionality, we
slightly decrease the size and unit tests still work.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-09-10 13:34:54 +00:00
Narfinger
5c7ea4bdee constellation: Use FnvHashMap for hashmaps that use ids as keys (#39106)
FNV is faster for hashing less than 16 bytes of data and the
cryptographic properties of the default HashMap are not needed for the
various ids.

Testing: This does not change functionality.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-09-03 18:15:19 +00:00
Jonathan Schwender
f4dd2960b8 Add direct script to embedder channel (#39039)
This PR **removes** `ScriptToConstellationMessage::ForwardToEmbedder`,
and replaces it with an explicit `ScriptToEmbedderChannel`. This new
channel is based on `GenericCallback` and in single-process mode will
directly send the message the to the embedder and wake it. In
multi-process mode, the message is routed via the ROUTER, since waking
is only possible from the same process currently. This means in
multi-process mode there are likely no direct perf benefits, since we
still need to hop the message over the ROUTER (instead of over the
constellation).
In single-process mode we can directly send the message to the embedder,
which should provide a noticable latency improvement in all cases where
script is blocked waiting on the embedder to reply.

This does not change the way the embedder receives messages - the
receiving end is unchanged.

## How was sending messages to the embedder working before?

1. Script wraps it's message to the embedder in
`ScriptToConstellationMessage::ForwardToEmbedder` and sends it to
constellation.
2. The [constellation event loop] receives the message in
[handle_request]
3. If deserialization fails, [an error is logged and the message is
ignored]
4. Since our message came from script, it is handle in
[handle_request_from_script]
5. The message is logged with trace log level
6. If the pipeline is closed, [a warning is logged and the message
ignored]
7. The wrapped `EmbedderMsg` [is forwarded to the embedder]. Sending the
message also invokes `wake()` on the embedder eventloop waker.

[constellation event loop]:
2e1b2e7260/components/constellation/constellation.rs (L755)

[handle request]:
2e1b2e7260/components/constellation/constellation.rs (L1182)

[an error is logged and the message is ignored]:
2e1b2e7260/components/constellation/constellation.rs (L1252)

[handle_request_from_script]:
https://github.com/servo/servo/blob/main/components/constellation/constellation.rs#L1590
 
[a warning is logged and the message ignored]:
2e1b2e7260/components/constellation/constellation.rs (L1599)

[is forwarded to the embedder]:
2e1b2e7260/components/constellation/constellation.rs (L1701)

Testing: Communication between Script and Embedder is extensive, so this
should be covered by existing tests.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2025-09-02 06:33:44 +00:00
Josh Matthews
6565d982bd servoshell: Support runtime preference manipulation (#38159)
These changes add a custom servo:preferences URL that allows modifying
selected preferences at runtime. The goal of this work is to make it
easy to test pages while toggling experimental web platform features,
and support quickly changing the User-Agent header.

Testing: Manually verified that spacex.com loads correctly after
changing the user agent, and that https://polygon.io/ displays grid
elements correctly and no console errors with the experimental prefs
enabled.
Fixes: #35862

<img width="1136" height="880" alt="Screenshot 2025-07-18 at 1 06 23 AM"
src="https://github.com/user-attachments/assets/2d27c321-6ca0-43c3-a347-7bc4b55272df"
/>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-08-30 16:51:58 +00:00
Sam
8beef6c21f compositor: Allow canvas to upload rendered contents asynchronously (#37776)
Adds epoch to each WR image op command that is sent to compositor. The
renderer now has a `FrameDelayer` data structure that is responsible for
tracking when a frame is ready to be displayed. When asking canvases to
update their rendering, they are given an optional `Epoch` which denotes
the `Document`'s canvas epoch. When all image updates for that `Epoch`
are seen in the renderer, the frame can be displayed.

Testing: Existing WPT tests
Fixes: #35733

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-08-29 10:04:41 +00:00
Martin Robinson
4784ff0375 script: Ensure that leaving the WebView sets the cursor back to the default cursor (#38759)
This changes makes a variety of changes to ensure that the cursor is set
back to the default cursor when it leaves the `WebView`:

1. Display list updates can come after a mouse leaves the `WebView`, so
   when refreshing the cursor after the update, base the updated cursor
   on the last hovered location in the `DocumentEventHandler`, rather
   than the compositor. This allows us to catch when the last hovered
   position is `None` (ie the cursor has left the `WebView`).
2. When handling `MouseLeftViewport` events for the cursor leaving the
   entire WebView, properly set the
   MouseLeftViewport::focus_moving_to_another_iframe` on the input event
   passed to the script thread.
3. When moving out of the `WebView` entirely, explicitly ask the
   embedder to set the cursor back to the default.

Testing: This change adds a unit test verifying this behavior.
Fixes: #38710.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-08-22 07:49:56 +00:00
lumiscosity
39f3ce7a2e Make DOM geometry structs serializable (#38828)
Makes the following DOM geometry structs serializable:
- `DOMRect`
- `DOMRectReadOnly`
- `DOMQuad`
- `DOMMatrix`
- `DOMMatrixReadOnly`

Testing: Covered by WPT (`css/geometry/structured-serialization.html`).

---------

Signed-off-by: lumiscosity <averyrudelphe@gmail.com>
2025-08-21 23:19:42 +00:00
Josh Matthews
ed6bf196c9 constellation: Broadcast preference changes to all content processes (#38716)
Building on the preference observer work from #38649, we now
automatically install an observer when multiprocess mode is enabled.
This observer notifies the constellation of updated preferences, which
in turn notifies each content process so the changes will be reflected
into script/layout as expected. There's a unit test that verifies this
works correctly by checking a preference-gated WebIDL property before
and after the preference is toggled.

Testing: New unit test added.
Fixes: #35966

Depends on #38649.

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-08-20 06:43:16 +00:00
Jonathan Schwender
8587536755 Use GenericChannel for script_chan (#38645)
Motivation: 
Using our GenericChannel abstraction allows us to optimize IPC in
single-process mode to just use cross-beam channel.
To keep the diff low, and get early feedback, this PR only tackles a
single channel, but the intention is to port all ipc channels to the
generic channel, which allows us to skip serializing and deserializing
messages in single process mode.

Based on: 
- https://github.com/servo/servo/pull/38638
- https://github.com/servo/servo/pull/38636

Testing: Covered by existing tests

---------

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2025-08-19 09:59:20 +00:00
Martin Robinson
6651f37c05 script/compositor: Handle cursor updates from script (#38518)
Instead of using WebRender hit testing to update the cursor, base it on
layout hit tests. This allows removing the majority of WebRender hit
test items and finally opens up the possibility of adding support for
custom cursors. In addition, this change fixes an issue where cursors
were not set properly on areas of the viewport that extended past the
page content.

Testing: This is difficult to test as verifying that the cursor changed
properly is beyond the capabilities of Servo's test harnesses.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-08-07 18:49:38 +00:00
Narfinger
ca47cc2fa3 Add a basic caching mechanism for ImageKeys. (#37369)
This creates a new method in shared/compositing/lib to generate image
keys that are send over the webview. This does not immediately return
the keys but goes over the constellation to receive the keys from the
IOCompositor. To make this more efficient, we now cache the keys in
image_cache in a simple FIFO order. The old blocking method stays intact
for now but got renamed to make the blocking clear.
The blocking calls that are left are in:
- `components/canvas/canvas_data.rs`
- `components/script/dom/htmlmediaelement.rs`

Testing: WPT tests should cover this as this doesn't change any
functionality.
Fixes: Was mentioned in
https://github.com/servo/servo/issues/37161#issuecomment-2915750051 and
part of https://github.com/servo/servo/issues/37086

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
Co-authored-by: gterzian <2792687+gterzian@users.noreply.github.com>
2025-07-03 13:16:43 +00:00
Martin Robinson
c0970ea655 compositor: Wait for both Script and the Constellation when shutting down Pipelines (#37505)
Previously, the Constellation would immediately ask the Compositor to
shut down a pipeline, even before the ScriptThread finished shutting it
down. This meant that the Compositor might remove a Pipeline and then
re-add it if the ScriptThread sent a Pipeline-related message (such as a
new display list) in the meantime.

This change makes it so that the Compositor waits for both the
Constellation and the ScriptThread to finish shutting down a Pipeline
before removing its data. In addition, the Constellation no longer
synchronously waits on the Compositor when shutting down Pipelines. This
was important when the Compositor would talk to the ScriptThread
directly, but isn't necessary any longer.

Testing: This is very hard to test, because it depends on the creation
and destruction of many iframes and the particular timing of of all
the messaging between Servo bits. That said, this was tested manually
by observing the completion of Speedometer 2.1.
Fixes: #37458.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-06-17 09:56:31 +00:00
Martin Robinson
f451dccd0b layout: Store scroll offsets in the ScrollTree (#37428)
There are currently five places that scroll offsets are stored:

 - DOM: A set of scroll offsets used for script.
 - Layout: An array of scroll offsets that is used for tracking
   layout-side scroll offsets.
 - Layout: The scroll offsets stored in the `ScrollTree`. These are
   currently unset and unused.
 - Compositor: The scroll offsets stored in the `ScrollTree` mirrored
   from layout.
 - WebRender: The scrolled offsets stored in the WebRender spatial tree.

This change is the first step in combining the first three into the
layout `ScrollTree`. It eliminates the extra array of scroll offsets
stored in layout in favor of the storing them in the `ScrollTree`. A
followup change will eliminate the ones stored in the DOM.

- In addition the `ScrollState` data structure is eliminated as these
are
now stored in a `HashMap` everywhere when passing them via IPC.
- The offsests stored in layout can now never scroll past the boundaries
of the scrolled content.

Testing: This should not change behavior and is thus covered by existing
WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: stevennovaryo <steven.novaryo@gmail.com>
2025-06-13 12:01:27 +00:00
Martin Robinson
d3e57a513c constellation: Pass system theme to new Pipelines (#37132)
Previously, when the theme was set it was only set on currently active
`Window`s. This change makes setting the `Theme` stateful. Now the
`Constellation` tracks what theme is applied to a `WebView` and properly
passes that value to new `Pipeline`s when they are constructed. In
addition, the value is passed to layout when that is constructed as
well.

Testing: this change adds a unit test.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-05-26 12:05:38 +00:00
Narfinger
991be359a3 libservo: Allow embedders to execute JavaScript scripts via the API (#35720)
This change adds a new `WebView` API `evaluate_javascript()`, which
allows embedders to
execute JavaScript code and wait for a reply asynchronously. Ongoing
script execution is
tracked by a libservo `JavaScriptEvaluator` struct, which maps an id to
the callback passed
to the `evaluate_javascript()` method. The id is used to track the
script and its execution
through the other parts of Servo.

Testing: This changes includes `WebView` unit tests.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-05-13 12:54:18 +00:00
Fuguo
0c0ee04b8e Improve inter-document focus handling (#36649)
*Describe the changes that this pull request makes here. This will be
the commit message.*
rewritten the PR #28571
Implement
[Window#focus](https://html.spec.whatwg.org/multipage/#dom-window-focus),
[Window#blur](https://html.spec.whatwg.org/multipage/#dom-window-blur)
Testing: WPT
Fixes: #8981 #9421

---------

Signed-off-by: kongbai1996 <1782765876@qq.com>
Co-authored-by: yvt <i@yvt.jp>
2025-04-30 04:37:53 +00:00
Martin Robinson
cbc363bedd compositor: Tick animations for an entire WebView at once (#36662)
Previously, when processing animations, the compositor would sent a tick
message to each pipeline. This is an issue because now the
`ScriptThread` always processes rendering updates for all `Document`s in
order to ensure properly ordering. This change makes it so that tick
messages are sent for an entire WebView. This means that each
`ScriptThread` will always receive a single tick for every time that
animations are processed, no matter how many frames are animating. This
is the first step toward a refresh driver.

In addition, we discard the idea of ticking animation only for
animations and or only for request animation frame callbacks. The
`ScriptThread` can no longer make this distinction due to the
specification and the compositor shouldn't either.

This should not really change observable behavior, but should make Servo
more efficient when more than a single frame in a `ScriptThread` is
animting at once.

Testing: This is covered by existing WPT tests as it mainly just improve
animation efficiency in a particular case.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-04-24 19:03:14 +00:00
Jason Tsai
0eec22303b chore: remove unnecessary webrender_document in script (#36648)
remove `webrender_document` in script and constellation's pipeline

Testing: `webrender_document` in script crate is not being referenced
anywhere in the Servo, should be safe to remove.
Fixes: https://github.com/servo/servo/issues/36647

Signed-off-by: Jason Tsai <git@pews.dev>
2025-04-22 08:38:29 +00:00
Euclid Ye
46247a7621 Move click event trigger from embedding layer to ScriptThread (#36413)
1. Move click event trigger from embedding layer to `ScriptThread`
2. Previously, the logic is to trigger click event at same position as
`MouseButtonAction::Up` if `MouseButtonAction::Up` is within 10px of
`MouseButtonAction::Down`, in embedding layer. This PR ~~removes the
condition~~ moves the check to `ScriptThread`.

Testing: tested for webdriver with self written test case. Perform
actions of pointermove, pointerdown, pointerup in sequence. Click event
can now be triggered.
Fixes: #35395 

cc @xiaochengh @jdm 

For `MAYBE? TODO:` part I added, should we do it? I read the
[spec](https://w3c.github.io/uievents/#event-type-click), it doesn't
specify we have to implement MDN's way.

If we should work in the MDN's way, it also should be fixed in another
PR, as this PR doesn't regress anything. Also I am not sure what is the
best way to do it.
Should I handle it in
4d4f94936f/components/script/dom/document.rs (L1296-L1297)?

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-04-18 19:27:57 +00:00
Martin Robinson
0caa271176 compositing: Combine webrender_traits and compositing_traits (#36372)
These two traits both exposed different parts of the compositing API,
but now that the compositor doesn't depend directly on `script` any
longer and the `script_traits` crate has been split into the
`constellation_traits` crate, this can be finally be cleaned up without
causing circular dependencies. In addition, some unit tests for the
`IOPCompositor`'s scroll node tree are also moved into
`compositing_traits` as well.

Testing: This just combines two crates, so no new tests are necessary.
Fixes: #35984.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-04-06 17:34:18 +00:00
Martin Robinson
6031a12fd1 Move ScriptToConstellationMsg to constellation_traits (#36364)
This is the last big change necessary to create the
`constellation_traits` crate. This moves the data structure for messages
that originate from the `ScriptThread` and are sent to the
`Contellation` to `constellation_traits`, effectively splitting
`script_traits` in half. Before, `script_traits` was responsible for
exposing the API of both the `ScriptThread` and the `Constellation` to
the rest of Servo.

- Data structures that are used by `ScriptToConstellationMsg` are moved
  to `constellation_traits`. The dependency graph looks a bit like this:
  `script_layout_interface` depends on `script_traits` depends on
  `constellation_traits` depends on `embedder_traits`.
- Data structures that are used in the embedding layer
  (`UntrustedNodeAddress`, `CompositorHitTestResult`, `TouchEventResult`
  and `AnimationState`) are moved to embedder_traits, to avoid a
  dependency cycle between `webrender_traits` and
  `constellation_traits`.
- Types dealing with MessagePorts and serialization are moved to
  `constellation_traits::message_port`.

Testing: This is covered by existing tests as it just moves types
around.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-04-05 22:13:29 +00:00
Sebastian C
76edcff202 Check all ancestor navigable trustworthiness for mixed content (#36157)
Propagate through documents a flag that represents if any of the
ancestor navigables has a potentially trustworthy origin.

The "potentially trustworthy origin" concept appears to have gotten
confused in a couple of places and we were instead testing if a URL had
"potentially trustworthy" properties.

The main test for the ancestor navigables is
[mixed-content/nested-iframes](https://github.com/web-platform-tests/wpt/blob/master/mixed-content/nested-iframes.window.js)

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by
`[X]` when the step is complete, and replace `___` with appropriate
data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #36108 

<!-- Either: -->
- [X] There are tests for these changes

---------

Signed-off-by: Sebastian C <sebsebmc@gmail.com>
2025-04-05 05:38:24 +00:00
Martin Robinson
5a35e1faec constellation: Rename messages sent to the Constellation (#36341)
Messages that are sent to the `Constellation` have pretty ambiguous
names.
This change does two renames:

- `ConstellationMsg` → `EmbedderToConstellationMessage`
- `ScriptMsg` → `ScriptToConstellationMessage`

This naming reflects that the `Constellation` stands in between the
embedding layer and the script layer and can receive messages from both.
Soon both of these message types will live in `constellation_traits`,
reflecting the idea that the `_traits` variant for a crate is
responsible for exposing the API for that crate.

Testing: No new tests are necessary here as this just renames two enums.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-04-04 19:39:38 +00:00
Martin Robinson
fb344ba4e9 constellation: Stop assuming that the viewport is shared by all WebViews (#36312)
The `Constellation` previously held a `window_size` member, but this
assumes that all `WebView`s have the same size. This change removes that
assumption as well as making sure that all `WebView`s pass their size
and HiDIP scaling to the `Constellation` when they are created.

In addition

- `WindowSizeData` is renamed to `ViewportDetails`, as it was
holding more than just the size and it didn't necessarily correspond to
  a "window." It's used for tracking viewport data, whether for an
  `<iframe>` or the main `WebView` viewport.
- `ViewportDetails` is stored more consistently so that conceptually an
  `<iframe>` can also have its own HiDPI scaling. This isn't something
  we necessarily want, but it makes everything conceptually simpler.

The goal with this change is to work toward allowing per-`WebView` HiDPI
scaling and sizing. There are still some corresponding changes in the
compositor to make that happen, but they will in a subsequent change.

Testing: This is covered by existing tests. There should be no behavior
changes.
Fixes: This is part of #36232.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-04-04 17:06:34 +00:00
Martin Robinson
0d693114ad webgpu: Add a webgpu_traits crate (#36320)
This breaks the `script_traits` dependency  on `webgpu`. In general, the
`traits` crates shouldn't depend on Servo non-`traits` crates. This is
necessary to move "script to constellation" messages to the
`constellation_traits` crate, making it the entire API for talking to
the
constellation. This will break a circular dependency when that happens.

Testing: Successfully building is enough of a test for this one as
it is mainly moving types around.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-04-04 08:06:07 +00:00
Martin Robinson
4402b7cf8f libservo: Remove a couple EmbedderMethods (#36276)
- Remove `EmbedderMethods::get_user_agent_string`. This is now part of
  the `Preferences` data structure, which should allow it to be
  per-`WebView` in the future.
- Remove `EmbedderMethods::get_version_string`. This was used to include
  some data along with WebRender captures about the Servo version. This
  isn't really necessary and it was done to replace code in the past
  that output the WebRender version, so also isn't what the original
  code did. I think we can just remove this entirely.

The idea with these changes is that `EmbedderMethods` can be removed
in a followup and the rest of the methods can be added to
`ServoDelegate`. These two methods are ones that cannot be added to a
delegate as they are used during `Servo` initialization.

Testing: There is currently no testing for libservo. These changes are
meant
as preparation for adding a suite of `WebView` unit tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-04-01 22:59:50 +00:00
Tony
5a76906d64 Allow setting userscripts directly without the need of files (#35388)
* Allow settings userscripts through preferences

Signed-off-by: Tony <legendmastertony@gmail.com>

* mach fmt instead of cargo fmt

Signed-off-by: Tony <legendmastertony@gmail.com>

* Fix pref loading not working for array values

Signed-off-by: Tony <legendmastertony@gmail.com>

* Use pref! in userscripts instead

Signed-off-by: Tony <legendmastertony@gmail.com>

* Implement the model jdm suggested
- Remove userscripts from all places and move it to servoshell
- Add in `UserContentManager` struct and passing it through `Servo::new`
all the way down to script thread

Signed-off-by: Tony <legendmastertony@gmail.com>

* Apply suggestions from code review and format

Signed-off-by: Tony <legendmastertony@gmail.com>

* Revert unrelated change

Signed-off-by: Tony <legendmastertony@gmail.com>

---------

Signed-off-by: Tony <legendmastertony@gmail.com>
Signed-off-by: Tony <68118705+Legend-Master@users.noreply.github.com>
2025-03-27 03:00:08 +00:00
Josh Matthews
53a2e61fec Make DOMPoint and DOMPointReadOnly serializable (#35989)
* script: Make DOMPointReadOnly serializable.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make DOMPoint serializable.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Shrink worker script event.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Update components/script/dom/dompoint.rs

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-03-27 01:35:02 +00:00