This will help us make "update the rendering" a proper task.
Testing: Existing WPT tests.
try run: https://github.com/sagudev/servo/actions/runs/16085256131
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Follow the specification and make OffscreenCanvas objects are
transferable,
but not in case if there are a weak reference to placeholder canvas
element.
To handle it properly need to implement dedicated frame
provider/dispatcher
between canvas element (script thread) and offscreen canvas (dedicated
worker thread).
https://html.spec.whatwg.org/multipage/#the-offscreencanvas-interface:transferable-objects
Testing: Improvements in the following tests
-
html/canvas/element/drawing-images-to-the-canvas/2d.drawImage.detachedcanvas.html
-
html/canvas/offscreen/manual/convert-to-blob/offscreencanvas.convert.to.blob*
-
html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer*
-
html/infrastructure/safe-passing-of-structured-data/transfer-errors.window.js
Part of #24276
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
The specification moved around lately with how it defines its reports
and report bodies. They became dictionaries, but are currently missing
some fields [1].
Most tests won't be passing yet, since the `Reporting-Endpoints` header
isn't used yet. In fact, the specification leaves it up to the browser
to figure out when to run this task [2]. I am not sure if there some
background scheduling we can do here.
Confirmed with content-security-policy/reporting-api/
report-to-directive-allowed-in-meta.https.sub.html that the callback is
invoked. The test doesn't pass, since
the `describe_scripted_caller` is empty for HTML elements. Thus the
`source_file` is empty, whereas it should be equivalent to the current
document URL.
Part of #37328
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
[1]: https://github.com/w3c/reporting/issues/286
[2]: https://w3c.github.io/reporting/#report-delivery
Printing using log macro for Android and OhOS, while retaining original
stderr behavior for other platforms.
Fixes: #37877
Signed-off-by: abdelrahman1234567 <boudyalex321@gmail.com>
Before #37703 we were actually doing update rendering of canvases/images
as part of `allow_layout_if_necessary` so let's keep doing that until we
fix this properly as this will be much more involved and we want usable
canvases in the mean time.
Testing: Manual testing + WPT tests
Fixes: #37891
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
The will-navigate message tells the devtools client to expect a
navigation for a browsing context. This makes the network monitor clear
any previous entries and show the requests for the new page that is
loaded. In order to support this correctly, we need to send the
navigation notification from the constellation instead of the script
thread, otherwise we silently ignore navigations triggered by the
browser URL bar.
Testing: Ran servo in devtools mode , now the requests appear for new
loaded page
Fixes: https://github.com/servo/servo/issues/37334
---------
Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
This removes assumption about pixel format from backend abstraction to
actual backend implementation. This is important for vello.
Testing: WPT tests
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Follow the HTML speficication and add missing 'transferToImageBitmap'
method to OffscreenCanvas interface.
https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-transfertoimagebitmap
Testing: Improvements in the following tests
- html/canvas/offscreen/compositing/2d.composite.grid*
- html/canvas/offscreen/fill-and-stroke-styles/2d.gradient*
- html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas*
- html/canvas/offscreen/reset/2d.reset*
- html/canvas/offscreen/text/2d.text*
Fixes (partially): #34111
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
[RootCause]:Tochdown executes normally, but touchup fails during hittest
and does not send a touchup event to the script, causing the script to
save an incorrect number of active_touch_points. The application
receives an incorrect event.touches.length, causing a logic error and
preventing the carousel from sliding.
[Solution]:
When hit test on compositor fails, we also need to send the
EmbedderToConstellationMessage::ForwardInputEvent message to
constellation. In the script's handle_touch_event, if it exits early, we
also need to update active_touch_points.
Testing:
Fixes: #37763
---------
Signed-off-by: kongbai1996 <1782765876@qq.com>
This pull request introduces changes to the storage subsystem to:
- Isolate sessionStorage per top-level browsing context (WebViewId), in
addition to origin.
- Copy sessionStorage when creating a new auxiliary browsing context
without
noopener, as required by the corresponding spec
These changes bring Servo closer to spec compliance, matching expected
browser
behavior.
Testing: This work affects observable behavior. As a result, some
previously
failing WPT tests now pass. No new tests are added, since the behavior
is
already covered by existing web-platform-tests.
Fixes: #21291
---------
Signed-off-by: Jan Varga <jan.varga@gmail.com>
Dirty roots are never shadow roots, since we use the flat tree for
invalidation. The flat tree does not contain shadow roots.
Reverts https://github.com/servo/servo/pull/35132. When that patch was
submitted we used the DOM tree for invalidation, so it was possible to
encounter shadow roots.
Testing: Covered by
`shadow-dom/untriaged/events/event-dispatch/test-003.html`
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
`Node::dirty` already increments the version. `Node::rev_version`
traverses all ancestors, so it can end up being fairly expensive.
Testing: I'm not sure about WPT coverage but I think this change is
trivial enough to merge without tests.
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Follow the HTML speficication and add missing 'convertToBlob' method
to OffscreenCanvas interface.
https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-converttoblob
Testing: Improvements in the following tests
-
html/canvas/offscreen/manual/convert-to-blob/offscreencanvas.convert.to.blob*
-
html/canvas/offscreen/manual/wide-gamut-canvas/2d.color.space.p3.convertToBlobp3.canvas.html
Fixes: #24272
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
I introduced snapshot in #36119 to pack raw bytes and metadata together,
now we take the next step and require for user to always specify what
kind of byte data they want when calling `as_bytes` or `to_vec`
(basically joining transform and data). There are also valid usages when
one might require just one property of bytes (textures can generally
handle both RGBA and BGRA). There are also valid usages of using just
raw bytes (when cropping). This PR tries to make such usages more
obvious.
This will make it easier to fix stuff around 2d canvas (we do not want
to assume any bytes properties in abstraction).
Testing: Code is covered by WPT tests.
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
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>
This change:
- Adds a new type of LayoutDamage that signifies that a box needs its
children recollected, because one or more of them need to be rebuilt.
- During restyle damage propagation, propagate this new damage upward in
the tree. Then box tree construction should be able to preserve any
still-valid box tree nodes from box slots.
- During BlockLevelBox job finalization, if a box slot is valid and
there is not LayoutDamage to the element, use the old box slot,
ensuring that its fragment cache is invalidated.
Testing: This should not change observable behavior and thus is covered
by existing WPT tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: coding-joedow <ibluegalaxy_taoj@163.com>
Only Firefox has this quirk, Chrome and Safari don't. So it's simpler to
just remove it.
Testing: tested by WPT
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
We were also enforcing that in limited-quirks mode, but no other browser
does that. In fact, Blink and WebKit don't have this quirk at all, so we
should consider removing it too, but for now restrict it to quirks mode
like Firefox.
Testing: adding new tests
Part of #37813
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Follow the HTML specification and reject the pending image decode
promises
on any current request mutation.
https://html.spec.whatwg.org/multipage/#updating-the-image-data (step
18)
https://html.spec.whatwg.org/multipage/#dom-img-decode (step 3)
Fulfill and reject image decode promises by queueing
a global tasks on the DOM manipulation task source.
Testing: Improvements in the following tests
- html/semantics/embedded-content/the-img-element/decode/*
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
While this makes our implementation deviate slightly from the
specification, this clarifies an invariant with the code itself. This
helps to resolve some confusion as seen in
https://github.com/servo/servo/issues/37695#issuecomment-3013823350.
Testing: This should not change behavior and is thus covered by existing
WPT tests.
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Currently, HTMLImageElement uses as an image source
(ImageBitmapSource, CanvasImageSource, TexImageSource)
in various canvas2D/WebGL operations, and there is a small
inconsistency in how we get the image data of the 'img' element:
usability checking and retrieving the image data from the image cache.
To simplify and avoid state inconsistency between the window's image
cache and the 'img' element, let's retrieve the image data (as a raster)
from the HTMLImageElement itself.
Testing: No expected changes in testing results, except the
'drawimage_svg_image_with_foreign_object_does_not_taint.html'
which is 'false' passed because drawing of the non supported vector
image
is silently skip instead of throwing the 'InvalidState' exception
anymore.
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
1. Implement XPath Locator Strategy
2. Use it for "Find Element(s)", "Find Element(s) from Element", "Find
Element(s) from Shadow Root"
Testing: `tests\wpt\tests\webdriver\tests\classic\find_element*\find.py`
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Set the placeholder canvas element of offscreenCanvas to a weak
reference in transferControlToOffscreen()
Testing: I do not understand how to test it, suggestions appreciated
Fixes: https://github.com/servo/servo/issues/35626
---------
Signed-off-by: Rodion Borovyk <rodion.borovyk@gmail.com>
Cloned nodes were re-parsing already-parsed style attributes. As such,
they were also checking CSP, which shouldn't happen as the original node
already was checked for it.
Testing: The existing WPT test now mostly passes. It had two cases which
were passing in no browsers.
Fixes: Part of #4577
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
- Move some of the image handling code to a separate function.
- Move reflow event debugging into layout itself and use the `Debug`
implementation to print the event.
- A few other small cleanups
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: Oriol Brufau <obrufau@igalia.com>
All "Find Element ..." in
[spec](https://w3c.github.io/webdriver/#find-element-from-element) has
exactly same step has "Find Elements ...", except they extract the first
element if there is any. We now reuse the handler instead of running
numerous repetitive steps, same as what we did for ["Find Element from
Shadow
Root"](https://w3c.github.io/webdriver/#find-element-from-shadow-root)
in #37578.
This reduces binary size by 98KB for Release profile in Windows and
improves maintainability.
Testing: `./mach test-wpt -r
.\tests\wpt\tests\webdriver\tests\classic\find_element* --product
servodriver`
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This reduces the amount of work necessary when running layout, by making
restyle information optional in the `ReflowRequest`. When restyling
isn't
necessary, the option is `None`.
Testing: This shouldn't change any observable behavior and thus is
covered
by existing WPT tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
When parsing a html fragment, the initial parser state depends on
whether or not scripting is enabled. So far we've used the scripting
flag of the parser, but that is wrong - the parser's scripting flag is
always false, because the fragment document has no browsing context.
Instead we should use the scripting flag of the context element.
Testing: A new web platform test passes
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Before we only offered helper to add single image (no update or delete)
that got special IPC message, now we simplify this by offering all ops
helpers for dealing with single image (that happens most of the time),
that simply uses `update_images` under the hood. We also optimize for
this use case by using `SmallVec<[ImageUpdate; 1]>` to avoid alloc.
Testing: Just refactor, but code is covered by WPT tests
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Follow the HTML canvas specification and add missing
'setTransform(transform)' method to CanvasPattern interface.
https://html.spec.whatwg.org/multipage/#dom-canvaspattern-settransform
Testing: Improvements in the tests
- html/canvas/element/fill-and-stroke-styles/2d.pattern.transform*
- html/canvas/offscreen/fill-and-stroke-styles/2d.pattern.transform*
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This will allow Servo to add custom types of damage in the near future
which correspond to minor phases layout. The damage exposed by Stylo
only corresponds to the major layout phses. In the future, both phases
will likely be managed by Servo itself and implementors will need to
provide their own damage system entirely.
Testing: This shouldn't change behavior and thus is covered by existing
tests.
Stylo PR: https://github.com/servo/stylo/pull/207
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
- Make feature flag of smallvec global.
- Removed unused dependency of thinvec.
- Removed unused flag of hyper-util.
Reduces the binary size by an astonishing 3.352k.
Testing: Compilation 'tests' this change.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Instead of doing a restyle whenever layout is requested, only do one if
script believes that the `Document` has changed in a way that needs a
restyle. In addition, track the different reasons this might be the
case. This will be used later to provide better debugging output.
In layout, when a restyle isn't requested, provide:
- an early return if layout is up-to-date enough for the reflow goal.
- skipping restyle and reflow if it isn't necessary.
Testing: This should not change observable behavior, and thus is covered
by existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
1. Separate the handling of ["switch to parent
frame"](https://w3c.github.io/webdriver/#switch-to-parent-frame) from
the rest as the processing is a bit different
2. Implement "Select frame by 16-bits numbered ID" for ["switch to
frame"](https://w3c.github.io/webdriver/#switch-to-frame)
3. Implement other missing steps
Testing: All WebDriver Conformance test with new passing cases
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
The parts of step 22 were a bit scattered throughout the codebase, so
this
change moves them all to a single method which does three things:
1. Update all animating images
2. Flush all dirty canvases (2D, WebGL, and WebGPU)
3. Calls reflow on the `Document`
Testing: This shouldn't change behavior in any major way so it should
be covered by existing WPT tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
I updated webidl, and all changes that bring, currently we still not
support float16array (there is no support in FF either). Most notable
change is refactored new_*/Constructors methods, that should now handle
HeapBufferSource more properly (with less unsafe).
Testing: Existing WPT tests
try run: https://github.com/sagudev/servo/actions/runs/15806083404Fixes: #37618 (although not tested)
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Follow the HTML canvas specification and add missing
'setTransform(transform)' method to CanvasTransform interface.
https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform-matrix
The third-party WebIDL doesn't support different extended attributes
on different overloads of methods, so 'Throws' attribute was added
to another 'setTransform(...)' method.
https://bugzilla.mozilla.org/show_bug.cgi?id=1020975
Testing: Improvements in the tests
- css/geometry/DOMMatrix*
-
html/canvas/element/transformations/2d.transformation.setTransform.multiple.html
-
html/canvas/offscreen/transformations/2d.transformation.setTransform.multiple
New failing tests due to disabled 'paint worklet' feature
- css/css-paint-api/setTransform-00*.https.html
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
Removes a GC cleanup step on exit pipeline that took half a second at
the end
of the Speedmometer benchmark. As layout and script are now run serially
this
does not seem to be needed anymore. See also the very short discussion
on Zulip:
[#performance > GC in
handle_exit_pipeline](https://servo.zulipchat.com/#narrow/channel/416779-performance/topic/GC.20in.20handle_exit_pipeline/with/525697861).
Testing: Tested with Speedometer and the WPT tests should still work.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This change fixes an issue and makes a few more minor improvements to
the `ImageAnimationState`:
1. Image rooting and unrooted now happens in one step from
`Window::update_animations_post_reflow`.
2. The `node_to_animating_image_map` is now stored as a shared `RwLock`
so that it doesn't need to be taken and then replaced in the
`ImageAnimationState` during reflow. This should prevent a hypothetical
issue
where image animations are restarted during empty reflows.
3. General naming and idiomatic Rust usage improvements.
Testing: This doesn't really have any obvious behavioral changes,
because all
reflows currently trigger a restyle. It becomes a serious problem with
#37677
and this change fixes the failing test there.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
- Instead of eagerly computing `pageX` and `pageY`, collect the offset
from the content's initial containing block in the compositor and pass
that information through to `MouseEvent`. This prevents a layout flush
that was happening when eagerly trying to fetch `Document` scroll
offsets.
- Pass keyboard modifiers properly to `MouseEvent`.
- Now all this information is stored and passed as `Point2D` (typed) and
`Modifiers` which greatly reduces the amount of arguments that need to
be passed around.
Testing: It is difficult to test input events as they require WebDriver
which
isn't completely working yet. I have manually run Speedometer 2.1 and I
have
verified that this fixes the regression from #37601.
Fixes: #37601.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
With Rust 1.85 it is possible to const initialize Hashmaps if the hash
algorithm does not rely on a random seed.
Testing: No functional changes, covered by existing tests
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
These maps are keyed on pointers, so using FnvHashMap should be faster
and we don't need the collision resistance properties of the default
hasher.
These maps showed up as hot when profiling the testcase from
https://github.com/servo/servo/issues/37223#issuecomment-3000705438.
Switching the hashing algorithm reduces the time spent hashing, but
overall that is still only a fractional part of the testcase.
Testing: Functionality unchanged. Overall the performance change is to
small to show up in any of our automated performance tests. When
comparing the perf profile of the above linked testcase, one should see
a reduction of time spent hashing (inverse call stack)
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This makes it easier to add variants, I also added some spec links and
reordered enum variants to match the spec.
Testing: Just refactor, but the code is covered by WPT tests.
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Follow the WebGL specification and ignore the values of UNPACK_FLIP_Y,
UNPACK_PREMULTIPLY_ALPHA, and UNPACK_COLORSPACE_CONVERSION
if the TexImageSource is an ImageBitmap.
https://registry.khronos.org/webgl/specs/latest/1.0/#6.10
Testing: There are no dedicated test results changes without the PR
#37634
which unblocks new testing scenarios with premultiplied ImageBitmap from
Blob/Canvas/Image sources.
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This refactoring moves various CSP-related methods away from GlobalScope
and Document into a dedicated entrypoint. It also reduces the amount of
imports of the CSP crate, so that types are consolidated into this one
entrypoint. That way, we control how CSP code interacts with the script
crate.
For reviewing purposes, I split up the refactoring into separate
distinct commits that all move 1 method(group) into the new file.
Testing: no change in behavior, only a build improvement + code cleanup
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>