Commit graph

10106 commits

Author SHA1 Message Date
Domenico Rizzo
b8738074d1
[#26488] Refactored RTCDataChannel for safer dropping and added Promise comment (#37332)
Fixes (partially) #26488 and apply the
https://github.com/servo/servo/pull/37324#discussion_r2133989190
comment.

Testing: No tests added
Fixes: Partially #26488

---------

Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
2025-06-13 12:20:45 +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
Simon Wülker
6cac782fb1
Support exporting shadow parts with the exportparts attribute (#37345)
The attribute is implemented as a new `AttrValue` variant containing the
mappings of exported part names
(https://github.com/servo/stylo/pull/197).

Take a look at the [MDN
page](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/exportparts)
for more information about the attribute.


Testing: Covered by WPT
Fixes: https://github.com/servo/servo/issues/35349

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-06-13 11:32:20 +00:00
Gregory Terzian
730fe35b42
AbortController: integrate with stream piping. (#37244)
Start using abort signal in Use in
https://streams.spec.whatwg.org/#readablestream-pipe-to-signal

Part of https://github.com/servo/servo/issues/34866

Will also cover https://github.com/servo/servo/issues/37230 and
https://github.com/servo/servo/issues/37232

---------

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
2025-06-13 09:52:38 +00:00
atbrakhi
7a801f0ef5
DevTools: Implement support for showing source_content in Debugger > Source panel (#36774)
This patch adds support for showing source_content in `Debugger >
Source` panel. This works by handling the clients `source` messages in
the source actor. These source actors are already advertised as resource
via the watcher, populating the source list. We also update the
`sources` handler in thread actor for future work in thread debugging.

Note: while this PR also adds support for showing worker script
source_content, worker has been broken (See
https://github.com/servo/servo/issues/37012). I was able to confirm the
`content_type` and `source_content` for worker script in logs.


![image](https://github.com/user-attachments/assets/bd53ea29-003a-4b5e-a3e8-6e280afa4671)

Fixes: part of https://github.com/servo/servo/issues/36027

---------

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
2025-06-13 09:31:33 +00:00
Martin Robinson
23acb623c8
script: Allow reflows that do not produce display lists (#37186)
This change has two parts which depend on each other:

1. An early exit in the layout process, which allows for skipping
   display list construction entirely when nothing would change.
2. A simplification and unification of the way that "fake" animation
   frames are triggered. Now this happens on an entire ScriptThread at
   once and is based on whether or not any Pipeline triggered a display
   list update.

   Animations are never canceled in the compositor when the Pipeline
   isn't updating, instead the fake animation frame is triggered far
   enough in the future that an unexpected compositor tick will cancel
   it. This could happen, for instance, if some other Pipeline in some
   other ScriptThread produced a new display list for a tick. This makes
   everything simpler about these ticks.

The goal is that in a future change the ScriptThread-based animation
ticks will be made more generic so that they can throttle the number of
"update the rendering" calls triggered by script.

This should make Servo do a lot less work when moving the cursor over a
page. Before it would constantly produce new display lists.

Fixes: #17029.
Testing: This should not cause any web observable changes. The fact that
all WPT tests keep passing is the test for this change.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-06-12 19:25:04 +00:00
Kingsley Yung
b28e796647
Implement MicrotaskRunnable for DefaultTeeReadRequestMicrotask (#37404)
Implement `MicrotaskRunnable` for `DefaultTeeReadRequestMicrotask` to
run the microtask, instead of using its own ad-hoc mechanism via
`DefaultTeeReadRequestMicrotask::microtask_chunk_steps`.

Testing: No need for this refactoring.
Fixes: #37246

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-06-12 10:46:31 +00:00
Jason Tsai
41bed9840a
feat(script): create import map parse result (#37405)
Implement import map parser
Spec:
https://html.spec.whatwg.org/multipage/#create-an-import-map-parse-result

- Create an import map parse result
- Sorting and normalizing a module specifier map
- Sorting and normalizing scopes
- Normalizing a module integrity map

Testing: should pass current WPT
Fixes: part of https://github.com/servo/servo/issues/37316

---------

Signed-off-by: Jason Tsai <git@pews.dev>
Co-authored-by: Wu Yu Wei <yuweiwu@pm.me>
2025-06-12 09:34:31 +00:00
Martin Robinson
fab958258e
script: Remove unused Window::page_clip_rect (#37394)
This value was used when rendering was not done by WebRender. Nowadays,
we do not need this page clip rect concept and it is completely
unused.

Testing: This just remove dead code, so should be covered by existing
tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-06-11 13:08:33 +00:00
JoeDow
bda3e23c74
Fix potential clippy warning for NodeDamage enum variant (#37391)
The default of `enum-variant-name-threshold` is 3, so adding any new
variants will lead to the lint being triggered, reference:

[enum_variant_names](https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names).
This PR fix this potential clippy lint warning for facilitate the
addition of new variant in following PR about incremental box tree
update.

Testing: No logic changed, just covered by existing WPT tests
Fixes: None

Signed-off-by: sharpshooter_pt <ibluegalaxy_taoj@163.com>
2025-06-11 09:53:15 +00:00
Josh Matthews
73361d0f5f
script: Replace use of UnsafeCell in WeakRangeVec. (#37327)
I can't find any historical motivation for the use of UnsafeCell in the
implementation of WeakRangeVec from #8506. We can replace all the uses
of unsafe in this code by using RefCell, and the resulting code is
easier to understand.

Testing: Existing WPT tests using Ranges show no behaviour changes.
Fixes: #37276

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-06-11 04:01:12 +00:00
Andrei Volykhin
7f536e8092
imagebitmap: Add missing basic functionality (#37025)
Add missing basic functionality for ImageBitmap
https://html.spec.whatwg.org/multipage/#imagebitmap
including new variant of creation bitmap with source rectangle
https://html.spec.whatwg.org/multipage/#dom-createimagebitmap
but without support of cropping bitmap data with formatting.

Add ImageBitmap to CanvasImageSource union type
https://html.spec.whatwg.org/multipage/#canvasimagesource

Add ImageBitmap to TexImageSource for WebGL
https://registry.khronos.org/webgl/specs/latest/1.0/index.html

Testing: Improvements in the following WPT tests
 - html/canvas/element/manual/imagebitmap/*
 - html/canvas/element/manual/wide-gamut-canvas/*
 - html/semantics/embedded-content/the-canvas-element/*
 - webgl/tests/conformance/textures/image_bitmap_from*
 - webmessaging/postMessage_cross_domain_image_transfer_2d.sub.htm

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

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-06-09 14:28:30 +00:00
Euclid Ye
a3c792e5aa
servoshell: Do not focus and raise new auxiliary WebDriver-created WebViews (#37284)
For Desktop port of `request_open_auxiliary_webview`, stay on the
original WebView if the request originates WebDriver.

This is to make sure `webdriver_server::handle_new_window` does not
focus the new window, according to spec. See
c7eba2dbba/tests/wpt/tests/webdriver/tests/classic/new_window/new_window.py (L31-L37)

**To clarify**: this won't change the behaviour when user interacts, but
only affects WebDriver [New
Window](https://w3c.github.io/webdriver/#new-window).

Testing: `./mach test-wpt -r --log-raw "D:/servo log/all.txt"
./tests/wpt/tests/webdriver/tests/classic --product servodriver` based
on 96b0973037

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-06-09 11:07:09 +00:00
Simon Wülker
0fa3de3937
Support ::part selector (#37307)
This is pretty much just wiring up the necessary stylo methods. Note
that the `exportparts` attribute is not yet supported, I'll do that in a
followup change

Testing: Covered by existing web platform tests.
This is the first half of https://github.com/servo/servo/issues/35349

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

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-06-09 10:17:28 +00:00
Tim van der Lippe
63cfeb3a18
Report URI with POST fetch request (#37209)
Part of #4577

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-06-08 18:44:55 +00:00
Sam K
a625420b23
Change canvas/context/snapshot size from u64 -> u32 (#36827)
Replaces uses of `euclid::default::Size2D<u64>` with
`euclid::default::Size2D<u32>` for the canvas/context/snapshot.

This PR includes changes to the following components:
 - canvas
 - pixels
 - script
 - script_bindings
 - shared/canvas
 - shared/snapshot

Testing: https://github.com/hashcatHitman/servo/actions/runs/15426115391
(as of 892edc0048)

Fixes: #36706

---------

Signed-off-by: hashcatHitman <155700084+hashcatHitman@users.noreply.github.com>
2025-06-07 14:37:21 +00:00
Jason Tsai
47f9fbd8c7
feat(script): add Supports() to htmlscriptelement (#37313)
Add static method `Supports` to `HTMLScriptElement`.

Part of #37262
Testing: relative WPT tests should become `PASS`

Signed-off-by: Jason Tsai <git@pews.dev>
2025-06-07 07:00:02 +00:00
Domenico Rizzo
352e4bfcf1
[#26499] Refactors HTMLMediaElement drop logic (#37310)
Testing: No tests added
Fixes: Partially #26488

Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
2025-06-07 05:51:59 +00:00
Andrei Volykhin
b81f1b135b
htmlmediaelement: Support seek requests for non seekable fetch context (#37264)
According to specification the data:// URL protocol doesn't support
range request
so be able make any seek request to required content position let's
allow
for non seekable fetch context discard fetched content bytes until seek
offset.
https://fetch.spec.whatwg.org/#scheme-fetch

Some scheme URLs (like data:// URL) doesn't expose "Content-Length"
header in response
so the total expected size of the stream is unknown and it causes some
additional
seek request (SeekData) from the media player. Try to post configure
stream size
after we reached fetch EOS response.

Related source code which breaks WPT tests:

[tests/wpt/tests/html/canvas/element/manual/imagebitmap/common.sub.js#L56-L78](https://github.com/servo/servo/tree/main/tests/wpt/tests/html/canvas/element/manual/imagebitmap/common.sub.js#L56-L78)

Testing: Improvements in the following tests:
 - html/canvas/element/manual/imagebitmap/createImageBitmap*

Fixes: https://github.com/servo/servo/issues/32645
Fixes: https://github.com/servo/servo/issues/32745
Fixes: https://github.com/servo/servo/issues/34119
Fixes: https://github.com/servo/servo/issues/34120
Fixes: https://github.com/servo/servo/issues/34151

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-06-06 21:52:24 +00:00
webbeef
a1f43ab06d
Revert "Implement Input UA Shadow DOM (#37065)" (#37296)
This reverts commit 5580704438.

Let's re-land that fix when a working solution is found. Keeping that
regression makes it hard to evaluate other potential improvements.

Signed-off-by: webbeef <me@webbeef.org>
2025-06-06 15:23:08 +00:00
Shubham Gupta
aff2a85372
Add support for parsing and applying viewport <meta> (#35901)
This patch comprises following steps:
1. Parses the `viewport` Attribute from `<meta>`.
2. Creates a `ViewportDescription` struct.
3. Populate values into Viewport struct.
4. Pass & Stash Viewport Description to Webview.
5. Process parsed values of `viewport <meta>`

Testing: Tested locally.
Fixes: #36159

---------

Signed-off-by: Shubham Gupta <shubham13297@gmail.com>
Signed-off-by: Xiaocheng Hu <xiaochengh.work@gmail.com>
Co-authored-by: Xiaocheng Hu <xiaochengh.work@gmail.com>
2025-06-06 15:13:51 +00:00
Ngo Iok Ui (Wu Yu Wei)
ba33fd1318
HTMLScriptElement: add ScriptType::ImportMap (#37291)
HTMLScriptElement: add `ScriptType::ImportMap`

Part of #37262
This covers most steps that are related to import map.

Testing: Existing WPT on HTMLScriptElement should remain the same.

---------

Signed-off-by: Yu Wei Wu <yuweiwu@YunoMacBook-Air.local>
Co-authored-by: Yu Wei Wu <yuweiwu@YunoMacBook-Air.local>
2025-06-06 14:38:30 +00:00
Simon Wülker
32cffbc985
Fix timing of change events for <select> elements (#37293)
Fixes two silly bugs in the implementation of `<select>` elements.
* We did not fire `input` events
* We fired `change` events *before* updating the selected value

Both of these are only relevant when the embedder selects a value, so
due to our lack of webdriver support we can't test them.

With these changes it is possible to switch the language on
https://toolbox.googleapps.com/apps/main/.

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-06-06 14:01:12 +00:00
Simon Wülker
430f65584d
Don't drain ranges across shadow boundaries (#37281)
The [live range pre remove
steps](https://dom.spec.whatwg.org/#live-range-pre-remove-steps) state
that:

> For each [live range](https://dom.spec.whatwg.org/#concept-live-range)
whose [start
node](https://dom.spec.whatwg.org/#concept-range-start-node) is an
[inclusive
descendant](https://dom.spec.whatwg.org/#concept-tree-inclusive-descendant)
of node, set its
[start](https://dom.spec.whatwg.org/#concept-range-start) to (parent,
index).

Elements in a shadow tree are not inclusive descendants of their hosts -
meaning we should not bubble ranges across shadow boundaries.

Includes a small fix to `Node::ranges_is_empty` which makes servo do
less work on DOM mutations, as well as some changes to `range.rs` to
match the spec better. I made these changes during debugging and they
don't feel like they're worth their own PR.

Testing: Covered by WPT

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-06-06 07:54:02 +00: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
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
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
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](https://github.com/yezhizhen/servo/actions/runs/15385994907), 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
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
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
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
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
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
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
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](https://github.com/pewsheen/servo/actions/runs/15209389525/job/42784179519))
Fixes: https://github.com/servo/servo/issues/37084

---------

Signed-off-by: Jason Tsai <git@pews.dev>
2025-05-27 02:27:13 +00:00