Commit graph

28539 commits

Author SHA1 Message Date
Yu Wei Wu
3d41e26d7d Add ScriptType::ImportMap
Signed-off-by: Yu Wei Wu <yuweiwu@YunoMacBook-Air.local>
2025-06-06 19:37:10 +09:00
Aokingo
c7eba2dbba
Fix ReadableStream cancel error message (#37282)
Align error message with WHATWG Streams spec by changing:  
- `'stream is not locked'` to `'stream is locked'` 

This will match the step 2 of the readablestream cancel method that
requires the correct TypeError when the stream is locked.

Signed-off-by: Alice Okingo <annekadiso@gmail.com>
2025-06-06 02:32:59 +00:00
Domenico Rizzo
6d99c09499
[#26488] Moves the FetchCanceller to a separate droppable struct, in Event Source (#37261)
Testing: No tests added.
Fixes: partially fixes #26488

Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
2025-06-05 16:07:26 +00:00
webbeef
36e78d1a3d
Use a VecDeque to manage timers (#37080)
Profiling speedometer 2.1 on a quad core Intel N100, we spend quite some
time in Vec::insert when adding new timers. This is mostly because one
of the tests creates a large number of timers (> 10k).

Switching to a VecDeque solves that and gets a ~2% score improvement on
that device.

Signed-off-by: webbeef <me@webbeef.org>
2025-06-05 07:53:18 +00:00
Kenzie Raditya Tirtarahardja
d66e4fc459
Implement wb element send keys for file input (#37224)
We can now send keys to file input, which results in uploading file with
given filename. Needs
`pref=dom_testing_html_input_element_select_files_enabled` flag to work.

https://w3c.github.io/webdriver/#element-send-keys

Testing:
`tests/wpt/meta/webdriver/tests/classic/element_send_keys/{events,
file_upload}.py.`

Signed-off-by: PotatoCP <kenzieradityatirtarahardja18@gmail.com>
2025-06-05 06:48:14 +00:00
sagudev
ffe9163892
canvas: ensure there is a subpath in PathBuilderRef (#37251)
This is also required by spec:
https://html.spec.whatwg.org/multipage/canvas.html#ensure-there-is-a-subpath
and if we not ensure it vello will trigger debug asserts. Enforcing this
at `PathBuilderRef` is the lowest possible level that avoids misuse (and
avoids IPC messages if we were to do this in content process) while
still keeping it from backend.

Testing: There are tests in WPT
Split of https://github.com/servo/servo/pull/36821
try run: 1544904469

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-06-05 02:47:37 +00:00
sagudev
c01f65affb
canvas: Use Cow<[u8]> for bytes() getter (#37249)
I fell into trap of over-generalization in
https://github.com/servo/servo/pull/36793, but
https://github.com/servo/servo/pull/36821 showed `Cow<[u8]>` is all we
need (to reuse existing vec alloc or pass on a slice).

Testing: There are WPT tests, but it's just refactor so rust keeps us
safe.
Split of https://github.com/servo/servo/pull/36821

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-06-04 15:16:28 +00:00
eri
9083d58061
devtools: Fix inspector on Firefox 139 (#37247)
Added a `target_type` field so that Firefox 139 is happy with showing
the inspector. In the future, this should probably include other
`TARGET_TYPES` like watcher and process.

Testing: Manually tested the inspector in Firefox 139 (not sure if we
have automatic devtools tests now).
Fixes: #37242

Signed-off-by: eri <eri@inventati.org>
2025-06-04 12:11:53 +00:00
Taym Haddadi
aff38cdbd0
Dom: Implement AbortSignal ThrowIfAborted method (#37245)
Implement the ThrowIfAborted method of AbortSignal; part of
https://github.com/servo/servo/issues/36935.

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
2025-06-04 11:48:25 +00:00
batu_hoang
e0d96163c7
Fix events filter in wait_for_user_agent_handling_complete (#37241)
Fix a mistake from https://github.com/servo/servo/pull/37095
cc: @xiaochengh

Signed-off-by: batu_hoang <longvatrong111@gmail.com>
2025-06-04 06:39:31 +00:00
batu_hoang
b422a65a00
Add retry for hit tests with expired epoch in result (#37085)
Follow up to [hit_test failed occasionally when the touch event is
sent](https://github.com/servo/servo/issues/35788#top) and
https://github.com/servo/servo/issues/36676#issuecomment-2882917136,
this PR adds a retry for hit tests with expired epoch in result.

Hit tests with outdated epoch mean it is too early to perform the hit
test.

Solution: retry hit test for the event on the next webrender frame.
The retry should guarantee that:

- Keep the correct order of events
- Retry time is not too long

Test cases: `./mach test-wpt --product servodriver -r
tests\wpt\tests\webdriver\tests\classic\element_click\events.py`

cc: @xiaochengh , @yezhizhen

---------

Signed-off-by: batu_hoang <longvatrong111@gmail.com>
2025-06-04 05:56:20 +00:00
batu_hoang
5ef66ce386
Fix webdriver wait for response from constellation (#37095)
Webdriver actions only wait for response from constellation if
`dispatch_tick_actions` sends at least 1 event.

Testing: 
`./mach test-wpt -r --product servodriver
./tests/wpt/tests/webdriver/tests/classic/perform_actions/perform.py `

cc: @xiaochengh, @yezhizhen

Signed-off-by: batu_hoang <longvatrong111@gmail.com>
2025-06-03 11:51:12 +00:00
Simon Wülker
8937542fe3
Implement the size presentational hint for <hr> elements (#37211)
This presentational hint either sets the width values of all borders,
removes the bottom border or sets the height of the element, depending
on the context.

This change also implements the corresponding idl attribute (and the
`noshade` attribute, which does nothing in html5)

Testing: Adds new web platform tests

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-06-03 11:22:44 +00:00
Gregory Terzian
b4035cc88e
dom: implement abort signal reason method (#37227)
Implement the `reason` method of `AbortSignal`; part of
https://github.com/servo/servo/issues/36935.

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
2025-06-03 09:35:51 +00:00
batu_hoang
ad95a74389
Implement actions_by_tick for webdriver (#37153)
Implement `actions by tick` according to the spec. 
The major change is `dispatch_actions` should receive a `actions by
ticks` as param.

https://w3c.github.io/webdriver/#dispatching-actions
> The algorithm to [dispatch
actions](https://w3c.github.io/webdriver/#dfn-dispatch-actions) takes a
list of actions grouped by
[tick](https://w3c.github.io/webdriver/#dfn-ticks), and then causes each
action to be run at the appropriate point in the sequence.

Reference for types in webdriver:
https://hackmd.io/b59NiPcLR_Gagh7r6r7BEw?view

cc: @xiaochengh

---------

Signed-off-by: batu_hoang <longvatrong111@gmail.com>
2025-06-03 08:20:00 +00:00
Euclid Ye
56c0ad8420
Consistently use Dom in native promise handlers (#37226)
Use `Dom` instead of `DomRoot` for fields of
`TransmitBodyPromiseRejectionHandler` to reduce redundant work by GC,
according to discussion in
https://github.com/servo/servo/issues/33604#issuecomment-2931524400

Fixes: #33604

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-06-03 07:41:34 +00:00
Andrei Volykhin
8d086b9fe5
htmlmediaelement: Fix fetch request race on "seek-data" event (#37002)
On execution media element load algorithm

https://html.spec.whatwg.org/multipage/media.html#media-element-load-algorithm
we can observe race condition between parallel running fetch requests:
R1: (media element) initial request (see "resource_fetch_algorithm"
function)
R2: (gstreamer) duration "seek-data" request (see PlayerEvent::SeekData)
 R3: (gstreamer) continue on last interrupted time "seek-data" request

At time there are only one current fetch context for media element but
because resource fetch and cancellation are async operations need
to identify (by request id) and skip processing outdated fetch request
(fetch listener callbacks).

Async load in background sequence (stream content length = 2757913):
```
R1 (seek-offset=0):          [------------------------------X]
R2 (seek-offset=2757866):          [---------Y]
                               AS-****-+++-AE
R3 (seek-offset=98304):                         [----------------Z]
                                             BS-****-+++BE

R1 (seek-offset=0):          [------X]
R2 (seek-offset=2757866):                [--------Y] (discarded data)
                                     AS-****---------+++-AE

- A*/B* performed seeks (*** seek lock, +++ flush buffer queue + reset EOS)
  (on Gstreamer streaming thread)
- X/Y/Z "end-of-stream" events from fetch requests
  (on Servo script thread)
```

All incoming input data from different requests are mixed and
pushed to active media player, plus abnormal behaviour due to
intermixed X/Y/Z "end-of-stream" events.

To handle it properly we will unblock seek lock on "seek-data" event
(on script thread) as soon as possible (GStreamer will be able
to flush buffer queue and reset EOS state) and introduce buffered data
source
to delay pushing input data/EOS event until media player will be
actually ready.

Testing: Improvements to the following tests:
-
/html/canvas/element/manual/imagebitmap/createImageBitmap-origin.sub.html
-
/html/semantics/embedded-content/the-canvas-element/security.pattern.fillStyle.sub.html

Fixes: https://github.com/servo/servo/issues/31931
Fixes: https://github.com/servo/servo/issues/36989

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-06-02 19:39:38 +00:00
Ville Lindholm
8cfb6e33fe
XPath: implement lang() and id() core functions (#34594)
XPath's `lang()` and `id()` functions were still unimplemented.

Also:
* Add WPT tests for `id()`.
* Fix uniqueness check in `NodesetHelpers::document_order_unique`.
* Tweak the AST a bit to make it clearer to express "no predicates".
* Fix a parsing bug where "/" was attempted before "//", leaving the
"//" branch as always unused.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #34593 
- [x] There are tests for these changes

---------

Signed-off-by: Ville Lindholm <ville@lindholm.dev>
2025-06-02 19:00:13 +00:00
Gregory Terzian
1dfc14d2fb
dom: implement aborted method of abort signal (#37218)
Implement the `aborted` member of `AbortSignal`. Part of
https://github.com/servo/servo/issues/36935

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
2025-06-02 18:57:57 +00:00
Gregory Terzian
99add66f8e
dom: implement signal method on abort controller (#37217)
Part of https://github.com/servo/servo/issues/34866

The "Finish current stub for AbortController" item.

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
2025-06-02 13:20:57 +00:00
Euclid Ye
c28394f476
script: Upgrade node_ids to pipeline_to_node_ids to track the owner pipeline of the node (#37213)
Upgrade `ScriptThread::node_ids` to `pipeline_to_node_ids` to track the
owner pipeline of the node
This will enable webdriver to know if it is requesting element from
other origins and properly distinguish "stale element reference" from
"no such element".

Testing: [Action
run](1538599490), no
regression. We can now pass WebDriver "cross origin" tests.

Fixes: #35749

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-06-02 12:26:45 +00:00
Tim van der Lippe
f710e2cab4
net: Perform CSP checks on fetch responses. (#37154)
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#37200
Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728
Part of servo/servo#4577

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
2025-06-01 17:25:13 +00:00
Tunahan Karlibas
ed888e284b
script: Set HTTP status code when aborting an XMLHttpRequest (#37190)
Correctly set status when aborting a XMLHttpRequest.

Testing: WPT test xhr/abort-during-done.window.html

---------

Signed-off-by: Tunahan Karlibas <dvt.tnhn.krlbs@icloud.com>
2025-06-01 15:37:46 +00:00
Michael Rees
280b34bbd8
Split handle_player_event into smaller functions (#37113)
Split HTMLMediaElement::handle_player_event into smaller functions
(#37109)

As requested, I also did a quick pass over the entire file looking for
if/else blocks that could be converted into early returns, but only
found two. Both of those have been changed here.

Testing: This doesn't require (new) tests because it is a reorganization
of existing code.
Fixes: #37109: HTMLMediaElement::handle_player_event is too big

---------

Signed-off-by: Michael Rees <mrees@noeontheend.com>
2025-06-01 12:49:09 +00:00
atbrakhi
568d24d4e3
DevTools: Fix empty debugger > source panel (#37197)
This patch fixes the source panel in the DevTools that was broken due to
missing breakpoint actor implementation. The client was sending messages
to the breakpoint actor that didn't exist in Servo, resulting in
"unknown actor"
warnings in the logs(See logs in issue description)

To fix this this patch implements the `BreakpointListActor` that handles
`setBreakpoint` and `setActiveEventBreakpoints` messages with empty
replies. This PR does not implement `breakpoint` functionality

<img width="1512" alt="image"
src="https://github.com/user-attachments/assets/ac4985a6-9fd3-4854-a491-b39241e19d13"
/>



Fixes: https://github.com/servo/servo/issues/37196

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
2025-05-31 06:51:03 +00:00
Gregory Terzian
8a808f89fd
dom: implement signal abort on controller and signal (#37192)
Part of https://github.com/servo/servo/issues/34866

Implement signal abort, and part of running abort steps.

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
2025-05-31 06:32:46 +00:00
Oriol Brufau
de2da3b1e1
layout: Split overflow calculation after fragment tree construction (#37203)
Instead of computing scrollable overflow while constructing the fragment
tree, we will now do it later. In the future this will also allow to
only recalculate the overflow without rebuilding the tree when transform
properties change, but that's left for a follow-up.

Stylo PR: https://github.com/servo/stylo/pull/194

Testing: One test is now passing (more investigation is needed), but
otherwise this isn't expected to have any effect.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-05-30 19:41:05 +00:00
Narfinger
13a980ff22
Constellation can now optionally report memory usage when the page is loaded. (#37151)
The constellation can now tell the memory reporter to report the memory
to a trace file when a page is loaded.
Additionally, we amend the memory reporter to allow a simple message
where it will report the memory to a tracing provider (at the moment
only OHOS/hitrace is supported but easy extension is possible).

I am not sure if this is the right approach or if the embedder should
decide to have the memory reporting done.

Testing: This does not change functionality of any of the rendering.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-05-30 17:15:06 +00:00
Steven Novaryo
5580704438
Implement Input type=text UA Shadow DOM (#37065)
Implement Shadow Tree construction for input `type=text`, adding a text
control inner editor container and placeholder container. Subsequently,
due to the changes of the DOM tree structure, the changes will add a new
NodeFlag `IS_TEXT_CONTROL_INNER_EDITOR` to handle the following cases.
- If a mouse click button event hits a text control inner editor, it
will redirect the focus target to its shadow host.
- In text run's construction, the text control inner editor container
queries the selection from its shadow host. This is later used to
resolve caret and selection painting in the display list.

This will be the first step of fixing input `type=text` and other
single-line text input element widgets. Such as, implementing
`::placeholder` selector.



Testing: Existing WPT test and new Servo specific appearance WPT.
Fixes: #36307

---------

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
2025-05-30 12:02:10 +00:00
Martin Robinson
578c52fe2b
constellation: Wait for canvas thread to shut down before shutting down system font service (#37182)
The canvas thread might need access to the system font service before it
shuts down. Ensure that it finishes shutting down before triggering the
shutdown of the system font service. This should avoid issues where
canvas tries to access fonts right before shutting down.

Fixes: #36849.
Testing: Since this fixes a flaky crash on shutdown, there isn't a good
way to write a test for it.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-05-30 11:44:16 +00:00
Kenzie Raditya Tirtarahardja
871630606f
Send synthetic keydown/keyup at ime_insert_text (#37175)
At `egl/app_state.rs`, send keydown and keyup with PROCESS KEY when
inserting text. This fixes OHOS input event, but maybe also for Android
in the future (if it implements `ime_insert_text`). We will get input
event since keydown is dispatched
(https://github.com/servo/servo/pull/37078).

This implementation is similar to
[Chromium's](https://source.chromium.org/chromium/chromium/src/+/main:content/public/android/java/src/org/chromium/content/browser/input/ImeAdapterImpl.java;drc=404e8d654e8b26336d2cb103b9c21faecbf7f73a;bpv=1;bpt=1;l=851?gsn=sendCompositionToNative&gs=KYTHE%3A%2F%2Fkythe%3A%2F%2Fchromium.googlesource.com%2Fcodesearch%2Fchromium%2Fsrc%2F%2Fmain%3Flang%3Djava%3Fpath%3Dorg.chromium.content.browser.input.ImeAdapterImpl%23d840961d441fd4bb569f9689c86da91fb714c0c153366e3198a85e9c7a098dce)
Android key event.

Testing: manually checked on OHOS device
For: https://github.com/servo/servo/issues/36259, but only in OHOS

Signed-off-by: PotatoCP <kenzieradityatirtarahardja.18@gmail.com>
Co-authored-by: PotatoCP <kenzieradityatirtarahardja.18@gmail.com>
Co-authored-by: stevennovaryo <steven.novaryo@gmail.com>
2025-05-30 02:06:15 +00:00
Martin Robinson
559ba4b3ee
script: Let canvas serialization to image fail gracefully (#37184)
Instead of panicking when serialization of canvas to image data (whether
through `toBlob()` or via `toDataURL()`), properly handle failed
serialization. This is an implementation of the appropriate error
handling from the specification text.

Testing: This change includes a new Serov-specific test, because it is
impossible to know what the canvas size limits are of all browsers.
Fixes: #36840.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-05-29 16:09:05 +00:00
Tim van der Lippe
36e4886da1
Implement basics of link preloading (#37036)
These changes allow a minimal set of checks for font-src
CSP checks to pass.

Part of #4577
Part of #35035

---------

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-05-29 11:26:27 +00:00
Martin Robinson
9dc1391bef
compositor: Add an initial RefreshDriver (#37169)
This adds a *very* basic implementation of the `RefreshDriver` concept
to the Servo renderer. The initial idea is that controls the frequency
of display during animations. It eliminates the "slowdown" workaround
for WPT tests and now Servo animations don't move faster than 120 FPS
(observed to be slower in practice).

This establishes a base change which will be used to implement
non-display-list-producing layouts in a followup change.

Fixes #3406. (though much more work remains)
Testing: Covered by existing WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-05-29 10:43:49 +00:00
Andrei Volykhin
801ac9e22a
pixels: Add limitation to max image total bytes length (#37172)
Limit the maximum image allocation size to 2GB to minimize the
possibility of out of memory errors on some `ImageBitmap`, `ImageData`,
`Canvas`, and `OffscreenCanvas` operations such as construction,
`toBlob`, and `toDataURL`. Other browsers have similar limits:
 - Chromium: 2^32-1 (~4GB)
- Firefox: 2^31-1 (~2GB)

Testing: Improvements to the following tests:
-
`html/canvas/element/pixel-manipulation/2d.imageData.object.ctor.basics.html`
assert_throws_dom("INDEX_SIZE_ERR", function() { new ImageData(1 << 31,
1 << 31); });
-
`html/canvas/element/manual/imagebitmap/createImageBitmap-invalid-args.html`
   makeOversizedCanvas + makeOversizedOffscreenCanvas

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-05-29 10:43:27 +00:00
Fuguo
1f315e6c9c
Add a user agent style for the <slot> element (#37174)
In Chromium, the slot user agent stylesheet is located in
[html.css](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/resources/html.css;l=1654).

Testing: This change fixes
`tests/wpt/meta/shadow-dom/directionality-001.tentative.html.ini`.

Signed-off-by: kongbai1996 <1782765876@qq.com>
2025-05-29 08:20:01 +00:00
Kingsley Yung
be7efc94a3
Refactoring HTMLOptionElement::Text into iterative style (#37167)
The original implementation of `HTMLOptionElement::Text` is recursive,
and the program may run out of stack space for a sufficiently large
number of iterations. The patch switches to an iterative implementation,
with `TreeIterator`.

Note that, instead of the usual `while let Some(node) = iterator.next()`
approach, we use `while let Some(node) = iterator.peek()` with the newly
added `TreeIterator::peek` function. This is because the choice of the
next node depends on some checks performed inside the `while` block,
whereas the `next` function determines the next node before entering the
block.

Moreover, the `TreeIterator::peek` function is added, instead of
wrapping the iterator into `Peekable`. This is because we will lose
access to the `TreeIterator::next_skipping_children` function if we wrap
it into `Peekable`.

Testing: This refactoring has to pass the existing tests.
Fixes: #36959

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-05-28 17:58:33 +00:00
Andrei Volykhin
644138c1da
canvas: Add HTMLVideoElement to CanvasImageSource union type (#37135)
Follow to the specification and add HTMLVideoElement to
CanvasImageSource union type
to allow use it as image source for createPattern/drawImage operations.
https://html.spec.whatwg.org/multipage/#canvasimagesource

https://html.spec.whatwg.org/multipage/#dom-context-2d-createpattern
https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage

The HTMLVideoElement media resource has an associated origin:
- media provider object (MediaStream/MediaSource/Blob): CORS-same-origin
 - URL record: CORS-cross-origin/CORS-same-origin

https://html.spec.whatwg.org/multipage/media.html#media-resource

Testing:
 - html/canvas/element/*
 - html/semantics/embedded-content/the-canvas-element/*

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-05-28 12:04:01 +00:00
Euclid Ye
45072ae2e0
Let input JS event be dispatched by keydown instead of keypress (#37078)
1. Let `input` JS event be dispatched by `keydown` instead of
`keypress`, according to spec
2. Fire `input` event for Backspace and Delete. But do so only when
something is actually deleted

Testing: Manually tested and compared with other browsers.
Fixes: #37051
cc @xiaochengh

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-05-28 08:51:05 +00:00
Narfinger
2d3a7c87c2
Refactor the memory profiler code to return the struct. (#37155)
Refactor the memory profiler code to return the struct and handle the
serializing in servointernal page.
This allows other users of the memory profiler to see the whole report
without parsing json.

Testing: I do not know if the memory page is covered by tests.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-05-28 00:58:05 +00:00
Oriol Brufau
ac06b1cfcf
layout: Fix logic for transforms with non-invertible matrix (#37147)
When the the current transformation matrix of a box isn't invertible,
the box and its content shouldn't be displayed.

However, the logic was broken:
- It was only checking the `transform` property, but not individual
transform properties like `scale`.
- It was treating matrices with m₁₁=0 or m₂₂=0 and non-invertible, even
when they can still be invertible and have a visible outcome.
- When m₁₁=0 or m₂₂=0 weren't caused by `transform`, it was replacing
the matrix with the identity.

Testing: Adding new WPT
Fixes: #37146

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-05-27 18:36:33 +00:00
Domenico Rizzo
ce12f37474
[#26488] Moved Droppable code into a separate struct for CanvasRenderingContext2D (#37136)
This is part of incremental implementation of #26488 . The interface
involved in this PR is CanvasRenderingContext2D.

Testing: Test should be just implemented.
Fixes: Partially #26488

Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
2025-05-27 15:45:05 +00:00
Mukilan Thiyagarajan
8a20e42de4
Add support for static SVG images using resvg crate (#36721)
This change adds support for rendering static SVG images using the
`resvg` crate, allowing svg sources in the `img` tag and in CSS
`background` and `content` properties. There are some limitations in
using resvg:

1. There is no support for animations or interactivity as these would
require implementing the full DOM layer of SVG specification.
2. Only system fonts can be used for text rendering. There is some
mechanism to provide a custom font resolver to usvg, but that is not
explored in this change.
3. resvg's handling of certain edge cases involving lack of explicit
`width` and `height` on the root svg element deviates from what the
specification expects from browsers. For example, resvg uses the values
in `viewBox` to derive the missing width or height dimension, but
without scaling that dimension to preserve the aspect ratio. It also
doesn't allow overriding this behavior.

Demo screenshot:
![servo - resvg
img](https://github.com/user-attachments/assets/8ecb2de2-ab7c-48e2-9f08-2d09d2cb8791)

<details>
<summary>Source</summary>

```
<style>
 #svg1 {
   border: 1px solid red;
 }

 #svg2 {
   border: 1px solid red;
   width: 300px;
 }
 #svg3 {
   border: 1px solid red;
   width: 300px;
   height: 200px;
   object-fit: contain;
 }
 #svg4 {
   border: 1px solid red;
   width: 300px;
   height: 200px;
   object-fit: cover;
 }
 #svg5 {
   border: 1px solid red;
   width: 300px;
   height: 200px;
   object-fit: fill;
 }
 #svg6 {
   border: 1px solid red;
   width: 300px;
   height: 200px;
   object-fit: none;
 }
</style>
</head>
<body>
        <div>
          <img id="svg1" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
        </div>
        <div>
          <img id="svg2" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
          <img id="svg3" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
          <img id="svg4" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
        </div>
        <div>
          <img id="svg5" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
          <img id="svg6" src="https://raw.githubusercontent.com/servo/servo/refs/heads/main/resources/servo.svg" alt="Servo logo">
        </div>
</body>
```

</details>

---------

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-05-27 11:02:40 +00:00
Gregory Terzian
324196351e
script: stub AbortSignal (#37033)
This is a stub for `AbortSignal`, which we would like to merge first in
order to work in parallel on
https://github.com/servo/servo/issues/34866, and perhaps also
https://github.com/servo/servo/issues/36936

---------

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
Co-authored-by: Taym Haddadi <haddadi.taym@gmail.com>
2025-05-27 09:53:43 +00:00
Andrei Volykhin
86b3b16b4c
imagebitmap: Use snapshot::Snapshot as bitmap data (#37131)
Replace the holder of actual pixel data of the ImageBitmap interface
([[BitmapData]] slot) from Vec<u8> to snapshot::Snapshot (image bitmap
with metadata).
https://html.spec.whatwg.org/multipage/#the-imagebitmap-interface

It will allow to have all required information (e.g. size, pixel format,
alpha mode)
for further drawing processing to/from canvas2D output bitmap.

Testing: No required tests
Fixes: https://github.com/servo/servo/issues/34112

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-05-27 06:41:25 +00:00
Jason Tsai
d76b4a14df
refactor: merge cross_realm_transform_* fields into one (#37102)
In https://github.com/servo/servo/pull/36977, when transferring
`TransformStream`, `CrossRealmTransform::Writable` and
`CrossRealmTransform::Readable` are set to different message ports. The
message port will not be readable and writable at the same time when
transferring the stream, so we can now merge
`cross_realm_transform_readable` and `cross_realm_transform_writable`
into a single field `cross_realm_transform`.

Testing: WPT ([passed on try
branch](4278417951))
Fixes: https://github.com/servo/servo/issues/37084

---------

Signed-off-by: Jason Tsai <git@pews.dev>
2025-05-27 02:27:13 +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
Simon Wülker
41ecfb53a1
Rename Stylesheet::Type_ to Stylesheet::Type (#37126)
I'm not sure if `CodegenRust.py` was supposed to remove the underscore,
but we end up exposing `type_` to javascript which is obviously wrong.
There's no need to rename the method in the first place, because `Type`
(with a capital T) is not a rust keyword.

Testing: Covered by existing web platform tests

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-05-25 17:36:16 +00:00
Simon Wülker
70a2ea3a66
Complete keyword list in CodegenRust.py (#37127)
Newer keywords such as `async`/`await`/`gen` were missing from the list

There are no web platform APIs with these names, but it doesn't hurt to
keep the list up to date.

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-05-25 16:17:43 +00:00
Josh Matthews
3a04f4195e
script: Return global objects for DOM objects in the relevant realm (#37120)
DomObject::global is a tricky API because it's used pervasively but has
subtle requirements that are not documented and not yet enforced by the
type system (#36116). The method returns the relevant global object for
a given DOM object, but that operation is only meaningful if there is an
active realm. We usually, but not always, have an active realm.

This change avoids a footgun by following the principle of least
surprise. Rather than making every single caller of `something.global()`
both prove that there is an active realm and think about which realm
they want active, we implement the obvious behaviour: always activate
the realm of the callee before obtaining the relevant global.
 
Testing: Existing WPT coverage is sufficient; this method is called all
over the codebase.
Fixes: #37070 #27037

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-05-25 03:21:05 +00:00