This PR moves current path handling from canvas paint thread to script's
`CanvasState`. Because we used manual impl for arcto and some prechecks
for early fail before sending IPC we also needed to fix some bugs in
Path impl.
Testing: Existing WPT tests
work towards #38022
try run: https://github.com/sagudev/servo/actions/runs/16316090028
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Refactor `documentotshadowroot::StyleSheetInDocument`, renaming it into
`ServoStylesheetInDocument` to avoid confusion with Stylo's
`StylesheetInDocument` trait.
To support constructed stylesheet. The `ServoStylesheetInDocument.owner`
would contains enum of:
- `Dom<Element>` - for stylesheet parsed from an element.
- `Dom<CSSStylesheet>` - for constructed stylesheet.
Testing: No WPT regression.
Fixes: #38133
---------
Signed-off-by: Jo Steven Novaryo <jo.steven.novaryo@huawei.com>
Implement `SafeFromJSValConvertible`, a safe wrapper for
`ToJSValConvertible`. And, replace unsafe `ToJSValConvertible` with
`SafeFromJSValConvertible` in `script/dom` to reduce the amount of
unsafe code in `script`.
This would support the implementation of `AdoptedStylesheet` where we
will need to have a setter/getter of sequence, that was implemented by
`any` types.
Part of https://github.com/servo/servo/issues/37951
Signed-off-by: Jo Steven Novaryo <jo.steven.novaryo@huawei.com>
This method is unused. `rustc` didn't complain because it was marked as
`pub` (which it shouldn't have been). A few of the surrounding methods
were also `pub`, which this change fixes.
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
- Add `handler any user prompt` step for all commands.
- Enable webdriver tests which were blocked by `handle any user prompt`
step.
---------
Signed-off-by: batu_hoang <hoang.binh.trong@huawei.com>
Workers created from Blobs inherit their CSP. Now we inherit the CSP and
set the correct base API url. The base API url should be used when
determining the
report-uri endpoint. Otherwise, the blob URL would be used as a base,
which is invalid and the report wouldn't be sent.
Also create a helper method to concatenate two optionals of CSPList,
which was used in several places.
Part of #4577
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
- Updating the WheelEvent initialization to correctly handle keyboard
modifiers when the wheel event is triggered. The changes ensure that the
modifiers (Ctrl, Alt, Shift, Meta) are properly set based on the current
state of the keyboard when the wheel event is created. This is
particularly important for scenarios where the wheel event is influenced
by key presses, such as scrolling with the Ctrl key pressed to zoom in
or out.
- Updating the `screen_point` and `client_point` as it was always 0,0
before. Now, it shows the correct position of the mouse pointer while
triggering the wheel event.
Test: Manual Test case and existing WPT tests
(classic/perform_actions/wheel.py[test_scroll_with_key_pressed])
Fixes: #37827
Signed-off-by: abdelrahman1234567 <abdelrahman.hossameldin.awadalla@huawei.com>
A lot of shared functions were scattered around the dom files; I moved
them into `indexed_db.rs` for clarity.
Fixes: Nothing to my knowledge, just a cleanup
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
We already store transform in context state, so let's just use this when
querying instead of using IPC to ask canvas paint thread.
Testing: Existing WPT tests
work towards #38022
try run: https://github.com/sagudev/servo/actions/runs/16299182583
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Remove size bound from safe to jsval trait, apply to script/dom, with
the exception of windowproxy.
Second part of https://github.com/servo/servo/issues/37951
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
*Describe the changes that this pull request makes here. This will be
the commit message.*
Testing: *Describe how this pull request is tested or why it doesn't
require tests*
Fixes: *Link to an issue this pull requests fixes or remove this line if
there is no issue*
Many object store related operations require the transaction to be
checked: to ensure it is still active, and, if the operation is a write,
that the transaction is not read-only. I've added the
`check_transaction` method to perform these checks.
Additionally `Clear` was still half-implemented, so I went ahead and
implemented that.
---------
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
- Move the 2 hash maps used to manage channels in their own struct.
- The constellation is still in charge of origin checks since it holds
the pipeline information required.
- BroadcastMsg is renamed to BroadcastChannelMsg for consistency.
Testing: covered by existing tests.
Fixes: #38060
Signed-off-by: webbeef <me@webbeef.org>
Add support of the ImageBitmapRenderingContext as "bitmaprenderer"
canvas context mode to RenderingContext/OffscreenRenderingContext
https://html.spec.whatwg.org/multipage/#imagebitmaprenderingcontext
It is initial implementation with public interface API but without
any display presentation support for HTMLCanvasElement.
Testing: Improvements in the following tests:
-
html/canvas/element/manual/imagebitmap/createImageBitmap-origin.sub.html
- html/canvas/offscreen/manual/text/canvas.2d.offscreen*
-
html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap.nocrash.html
- imagebitmap-renderingcontext/*
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
When script thread executes script sent from webdriver, if an alert
appears, webdriver can stop waiting for the script response and process
the next command.
This PR allows script thread to fail to send response for
`ExecuteScript` if the channel is closed.
cc: @xiaochengh
Signed-off-by: batu_hoang <hoang.binh.trong@huawei.com>
Digging into several crashing tests revealed that committing
transactions is a fallible operation. Propagating those errors led to
exposing many new errors caused by the IDBRequest implementation
assuming that all successful responses contained a structured clone. The
end result is a bunch of new test failures that were previously hidden.
Testing: Existing test coverage is sufficient.
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Introduce a safe wrapper trait for the unsafe `ToJSValConvertible`, and
use it in `script/dom` where the default `T` implementation works.
Part of https://github.com/servo/servo/issues/37951
---------
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
These changes introduce a new kind of task that uses a variation of the
`task!` syntax. Existing `task!` usages create task structs that have a
`Send` bound, which requires the use of `Trusted<T>` to reference a DOM
object T inside of the task closure. The new syntax replaces the `Send`
bound with a `JSTraceable` bound, which requires explicit capture
clauses with types. This looks like:
```rust
task!(ScriptPrepare: {script: DomRoot<HTMLScriptElement>} |script| {
script.prepare(CanGc::note());
}),
```
The capture clauses must list every value that will be referenced from
the closure's environment—these values are moved into fields in the
generated task structure, which allows them to be traced by the GC as
part of a generated JSTraceable implementation. Since the closure itself
is not a `move` closure, any attempts to reference values not explicitly
captured will generate a borrow checker error since the closure requires
the `'static` lifetime.
Testing: Existing WPT tests exercise these code paths. I also attempted
to write incorrect tasks that capture references or use values not
explicitly captured, and the compiler correctly errors out.
Fixes: part of #35517
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
1. Some rounding was wrongly used which can be a source of inaccuracy.
2. Use `window.InnerWidth` instead of `body.ClientWidth` according to
spec.
Testing: Many new passing cases.
Fixes: Part of #38042.
---------
Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This change aims to reduce the scope of incremental box tree
construction. Previously, when text content changed, the parent node
would always be marked as requiring box tree reconstruction; now, it is
adjusted to only mark the parent node as needing to recollect its box
tree children.
Testing: This should not change observable behavior and is thus covered
by existing WPT tests.
Signed-off-by: sharpshooter_pt <ibluegalaxy_taoj@163.com>
Similar to #37960, previously, `AvailHeight`, `AvailWidth`, `Height`,
`Width` ask compositor for screen metrics. This PR moves the request to
embedder.
This simplifies code, and reduces workload of compositor, which is
busier most of time.
Testing: No behaviour change. Updated some tests. `Width/Height` matches
other browsers.
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
These changes reduce the number of times we need to query layout for the
same information when creating mouse/pointer events.
Testing: No new tests required for maintaining existing behaviour.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This change allows the compiler to recognize if any read-only operations
are missing an implementation when processing a readonly transaction.
Testing: The existing behaviour is unchanged, so current tests suffice.
The new code is unused and cannot be tested.
Fixes: part of #6963
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This was a bit confusing at first, but the report-only only
had an effect if it was used in conjunction with the regular
CSP header. This is incorrect, as the report-only header
can be present on its own.
Additionally, there was double-logic for parsing the CSP list
values, since we can only concatenate CSP lists if we have
an initial value, which requires a concrete policy value.
Therefore, abstract that way by looping over both headers and
handling the case where initially it is `None` and, if the
CSP header is not present, still `None` when we parse
the `report-only` header.
Additionally, update a WPT test. It was expecting the image
to load, yet was showing the fail image.
Part of #4577
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This PR removes existing path(segment) abstractions in favor of
`kurbo::BezPath`, well actually wrapped `kurbo::BezPath`, to ensure
building of valid paths. This allows us better Path2D building in script
and doing all validation and segmentation there and also allows us
remove blocking is_point_in_path on Path2D as we can now do this in
script. Current path is still done on canvas thread side as it will be
harder to move to script (will be done as a follow up), but it now uses
this new path abstraction.
Using kurbo also allows us to ditch our manual svgpath parser with the
one provided by kurbo.
Same code is stolen from: https://github.com/servo/servo/pull/36821.
Testing: Existing WPT tests
Fixes: #37904
wpt run: https://github.com/sagudev/servo/actions/runs/16172191716
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Add Constraint DOMException to handle the name conflict error in
`IDBDatabase::createObjectStore` method.
Testing: `./mach test-wpt tests/wpt/tests/IndexedDB/`, but it seems
there are many test failures even in main branch already ([related
comment](https://github.com/servo/servo/pull/37605#issuecomment-2993889163)).
Fixes: #37571
---------
Signed-off-by: iamlockon <xdddxyyyxzzz123@gmail.com>
Previously, `screenX`, `screenY`, `outerHeight`, `outerWidth`, `moveBy`,
`resizeBy` ask compositor for window rectangle, which then return
"inner" rectangle after consulting Embedder.
This PR
1. removes `GetClientWindowRect` from compositor, and directly let
script ask embedder.
2. add `window_size` to `ScreenGeometry`
3. add a lot of docs to `ScreenGeometry`
Testing: `tests\wpt\mozilla\tests\mozilla\window_resizeTo.html` can now
pass for Headed Window.
Fixes: #37824
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
There is a new default cargo clippy lint, `unsafe_op_in_unsafe_fn`,
which requires unsafe code to be wrapped in unsafe blocks, even inside
functions marked as unsafe. The lint is disabled as much of our code
doesn't fulfill this contract. The thing itself is pretty useful in
order to gradually remove unsafety, so this change starts adding
`unsafe` blocks so we can eventually enable this lint.
Testing: This doesn't change behavior so existings tests should suffice.
Fixes: This is part of #35955.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Console messages on OHOS/Android targets were duplicated.
Originally messages were on the debug level directed to stdout and then
redirected to the logger. https://github.com/servo/servo/pull/37912
changed this behavior recently.
Testing: Tested by looking at the debug log of certain things.
ohos-speedometer for example.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
The scripted_caller only has information if the context is coming
from a script. If an element fetch listener processes CSP
violations, then this information doesn't exist. Instead, we should
use the global URL and the line number. WPT tests don't appear
to expect a column number, as they are all zero. Not all elements
are updated, as I am not actually sure all of them need it.
The source position remains an Option, since there are also code
paths that don't correspond to element or script sources. Maybe
in the future we can always determine the source position, but
let's take small steps towards that.
Part of #4577
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
The iterator produced by Node::inclusive_ancestors roots the items but
rev_version just drop and unroot them right away. This patch makes it
possible to work on the Node references instead to avoid rooting.
*Describe the changes that this pull request makes here. This will be
the commit message.*
Testing: *Describe how this pull request is tested or why it doesn't
require tests*
Fixes: *Link to an issue this pull requests fixes or remove this line if
there is no issue*
Signed-off-by: webbeef <me@webbeef.org>
The cookie-rs library parses the cookie expiry date based on the format
from RFC 2616 (for HTTP/1.1), which is stricter than the format from RFC
6265 (for HTTP cookie).
This patch implements the cookie expiry date algorithm from RFC 6265.
When Cookie::parse fails in parsing the expiry date, we try to parse the
expiry again with this algorithm, to provide extra compatibility with
legacy systems.
Testing: Pass a WPT test that was expected to fail before, and add a
unit test.
Fixes: #36452
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
A recent update in the spec (https://github.com/whatwg/dom/pull/1079)
introduced new rules for name validation of attribute, element, and
doctype. This PR implements the new name validation rules in
`components/script/dom/bindings/domname.rs`. The old XML name validation
rules are not fully removed because there remains a few usage of it in
`ProcessingInstructions` and `xpath`.
Testing: Covered by WPT tests
Fixes: #37746
---------
Signed-off-by: minghuaw <michael.wu1107@gmail.com>
Signed-off-by: Minghua Wu <michael.wu1107@gmail.com>
Co-authored-by: Xiaocheng Hu <xiaochengh.work@gmail.com>
Improves the implementation of keys to a point where key ranges can be
implemented as well.
Due to me making branching mistakes I'll have to cherry-pick out the
first commit (it's from #37682)
---------
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Does not yet handle failures of endpoints, which requires us to update
metadata. I don't see that metadata being used anywhere, so I am not
sure if there is WPT coverage for it.
Part of #37238
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
When a style change does not chang the structure of the box tree, it is
possible to skip box tree rebuilding for an element. This change adds
support for reusing old box trees when no element has that type of
damage. In order to make this happen, there needs to be a type of
"empty" `LayoutDamage` that just indicates that a fragment tree layout
is necessary.
This is the first step toward incremental fragment tree layout.
Testing: This should not change observable behavior and thus is covered
by
existing WPT tests. Performance numbers to follow.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Implement internal pseudo element, which would be resolved as a
"Implemented Pseudo Element" within style computation. This is an
concrete element that would has a primary style after the style
computation, but could match and style resolved like an pseudo element.
Therefore, it would have a different behavior compared to how does
`pseudo`s that `ServoLayoutNode` had. Where they would not have a
concrete element behind it. Note that, due to the nature of these pseudo
elements residing inside a UA widget, these pseudo elements would
therefore not be accessible in JavaScript by default.
This kind of element is required in order to implement the [form control
pseudo element](https://drafts.csswg.org/css-forms-1/#pseudo-elements)
like `::placeholder`, `::color-swatch`, `::field-text`, etc.
See [this docs](https://hackmd.io/@ChaKweTiau/BJ3zRdLQlg) for more
details of the implementation.
Then, the implemented pseudo element is utilized to implement style
matching for input `type=text`.
Servo's side of: https://github.com/servo/stylo/pull/212
Testing: No WPT regression.
---------
Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
During the object (de)serialization steps on structured cloning
https://html.spec.whatwg.org/multipage/#safe-passing-of-structured-data
it is possible to throw a JS exception.
`self.postMessage({ get whatever() { throw customError } }));`
Require to propagate a pending JS exception and not throw the default
"DataCloneError" DOM exception.
Testing: Improvements in the following tests
- html/infrastructure/safe-passing-of-structured-data/*
- html/webappapis/structured-clone/structured-clone.any.js*
- wasm/serialization/arraybuffer/transfer.window.js
- webmessaging/without-ports/026.html
- workers/semantics/structured-clone/dedicated.html
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
The structured cloning with transfer list
https://html.spec.whatwg.org/multipage/#structuredserializewithtransfer
throws a "DataCloneError" DOM expection by default if
serialization/transferral
is not possible, but a platform object can throw a custom excepton on
its serialization/transfer steps.
One example is OffscreenCanvas, which can throw
an "InvalidStateError" exception if the context mode is not none on
transfer steps.
https://html.spec.whatwg.org/multipage/#the-offscreencanvas-interface:transfer-steps
Testing: Improvements in the following tests
-
html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transferrable*
Fixes: #37919
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
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>