aboutsummaryrefslogtreecommitdiffstats
path: root/components/shared/script/lib.rs
Commit message (Collapse)AuthorAgeFilesLines
* Refactor common boilerplate out of serialize/transfer implementations (#35831)Josh Matthews2025-03-151-30/+80
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * script: Create infrastructure for reducing hand-written serializable/transferrable implementations. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Clone all serializable DOM interfaces. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Deserialize all serializable DOM interfaces. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Serialize all serializable DOM interfaces. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Transfer-receive all transferable DOM interfaces. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Transfer all transferable DOM interfaces. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Extract boilerplate from serialize/deserialize implementations. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Extract boilerplate from transfer-receive. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Extract boilerplate from transfer operation. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Tidy fixes. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Check transferability of all DOM interfaces. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Clippy fixes. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Clippy fixes. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Remove unnecessary duplicate crate. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Use `strum` to iterate through enum variants and get their names (#35933)Martin Robinson2025-03-131-39/+4
| | | | | | | | `strum` allows us to avoid manually listing enum variant names and also to get their names as static strings. We cannot use this for all cases due to https://github.com/Peternator7/strum/issues/152, but we can still use it to remove a lot of code. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Migrate to the 2024 edition (#35755)Simon Wülker2025-03-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | * Migrate to 2024 edition Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Allow unsafe_op_in_unsafe_fn lint This lint warns by default in the 2024 edition, but is *way* too noisy for servo. We might enable it in the future, but not now. Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Compile using the 2024 edition Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
* Use new stylo crate renames (#35898)Nico Burns2025-03-121-1/+1
| | | Signed-off-by: Nico Burns <nico@nicoburns.com>
* base: Finish rename of `TopLevelBrowsingContextId` to `WebViewId` (#35896)Martin Robinson2025-03-111-6/+6
| | | | | | The `WebViewId` name is a lot more descriptive these days to the casual reader, so I think we can go ahead and finish the rename. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Update rustfmt to the 2024 style edition (#35764)Simon Wülker2025-03-031-3/+5
| | | | | | | | | | | | | * Use 2024 style edition Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Reformat all code Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
* Make auxiliary webviews exist in the constellation immediately (#35672)Delan Azabani2025-02-261-7/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To allow embedders to interact with webviews as soon as they are created, we need to ensure that they exist in both the compositor and the constellation before those interactions happen. #35662 does this for the compositor, while this patch does this for the constellation. When a webview opens another webview (via <a target>, <form target>, window.open(), etc), the embedder creates an “auxiliary” webview, which previously went as follows: - script create_auxiliary_browsing_context - libservo AllowOpeningWebView - embedder request_open_auxiliary_webview (→ constellation FocusWebView) - script create_auxiliary_browsing_context - constellation ScriptNewAuxiliary In that model, the constellation may receive FocusWebView before it receives ScriptNewAuxiliary. Now they are created as follows: - script create_auxiliary_browsing_context - constellation CreateAuxiliaryWebView - libservo AllowOpeningWebView - embedder request_open_auxiliary_webview (→ constellation FocusWebView) - constellation CreateAuxiliaryWebView - script create_auxiliary_browsing_context Since these messages are all synchronous and the constellation will have set up the webview before handling any new messages, the webview will always exist by the time we handle the embedder’s FocusWebView. Signed-off-by: Delan Azabani <dazabani@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Touch handler: Fix race condition and rate-limit move events (#35537)Bi Fuguo2025-02-251-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * TouchSequenceInfo is added to store information about a touch sequence. For details about TouchSequenceInfo, see the code comments. The handling_touch_move attribute is added to the TouchHandler, indicating that the script is processing the touch move event. When handling_touch_move is set to true, the touch move event does not need to be sent to the script thread. Signed-off-by: kongbai1996 <1782765876@qq.com> * move touch state, active_touch_point and handling_touch_move to TouchSequenceInfo form TouchHandler. remove TouchSequenceInfo end_sequence property, add Finished state mark sequence end. if preventDefault on touchup, do not prevent Fling. Signed-off-by: kongbai1996 <1782765876@qq.com> * Refactor Touchhandler - Add a newtype wrapper for the TouchSequenceId - Move more state back into the TouchSequenceState - Rename TouchAction to TouchMoveAction, since it only covers immediate actions now. Everything else is handled via state, since it needs to wait on the handler. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> * Fix test-tidy Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> * Fix clippy missing-default lint Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> * Fix remaining clippy lints Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> * Remove accidental committed test file Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> * Remove wrong todo comment (move events that are sent to script are just raw touchpoints, no merging needed) Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> * Fix preventdefault after long touch_down handler Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> --------- Signed-off-by: kongbai1996 <1782765876@qq.com> Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> Co-authored-by: Jonathan Schwender <schwenderjonathan@gmail.com>
* libservo: Move WebDriver messages to the `embedder` crate (#35602)Martin Robinson2025-02-241-55/+4
| | | | | | | | | | | | | | | | | | | | This is the first step toward moving the WebDriver implementation to servoshell. This move will make it possible to start testing the embedding API with WebDriver. See [this zulip thread][a] for more details. While WebDriver will be able to use a lot of API commands to do what it is doing now, there will still need to be some "cheat codes" for more gnarly access to `ScriptThread` details. That's why we likely won't be able to remove all WebDriver-specific messages from the API -- but maybe they will be useful for embedders somehow. A couple messages have to change as they depended on `script_traits` types, particularly those that used `WindowSizeData` and `LoadData`. I think this helps to encapsulate the WebDriver commands a bit more though. [a]: https://servo.zulipchat.com/#narrow/channel/437943-embedding/topic/webdriver.20as.20embedding.20api.20playgound Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Make WebBluetooth an optional feature. (#35479)Josh Matthews2025-02-181-0/+2
| | | Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* libservo: Expose a single `InputEvent` type and pass it to script (#35430)Martin Robinson2025-02-121-67/+17
| | | | | | | | | | | | | | | | | | | | | | | | This change exposes a single `InputEvent` type and now there is only a single delegate method for this `WebViewDelegate::notify_input_event`. - Clipboard events are now handled as `EditingAction` inpute events. In the future this can include things like "Select All", etc. In addition, many parts of the dance to pass these events can now be simplified due to this abstraction. - All forwarded events are handled the same way in the `Constellation`, though they may carry an optional hit test (for events that have a `point`) which affects which `Pipeline` they are sent to. - In the `ScriptThread` we now accept these `InputEvents` and use them everywhere. Now all "compositor events" are "input events". - This allows removing several data structures which are no longer necessary. - We no longer inform the embedder when an event was handled by a WebView as that was only important for a MDI feature that will no longer be so important the full-featured `WebView` API. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* servoshell: Move `headless` setting to ServoShellPreferences (#35377)Martin Robinson2025-02-071-2/+0
| | | | | | | | | | This is only used in servoshell, even though it was plumbed through script previously. It's just about how the `RenderingContext` is set up, which is something managed entirely outside of servo itself. In addition, make the name of `servo_shell_preferences` in `app.rs` more consistent with the rest of the codebase. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Add support for Upgrade request to a potentially trustworthy URL. (#34986)Shubham Gupta2025-02-051-1/+5
| | | | | | | | | | | | | | | | * Add support for Upgrade request to a potentially trustworthy URL. Signed-off-by: Shubham Gupta <shubham13297@gmail.com> * script: Support inheritable insecure request policy in documents and workers. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Shubham Gupta <shubham13297@gmail.com> Signed-off-by: Josh Matthews <josh@joshmatthews.net> Co-authored-by: Shubham Gupta <shubham.gupta@chromium.org> Co-authored-by: Josh Matthews <josh@joshmatthews.net>
* script_traits: Rename `ConstellationControlMsg` to `ScriptThreadMessage` ↵Martin Robinson2025-01-301-7/+7
| | | | | | | | | | | (#35226) At some point in the past this message was only sent from the `Constellation` to `script`, but nowadays this is sent from various parts of servo to the `ScriptThread`, so this is a better name. In particular, the current name makes it seeem like this message controls the `Constellation`, which it does not. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Include `WebViewId` into EmbedderMsg variants where possible (#35211)Delan Azabani2025-01-301-2/+6
| | | | | | | | | | | | | | | | | `EmbedderMsg` was previously paired with an implicit `Option<WebViewId>`, even though almost all variants were either always `Some` or always `None`, depending on whether there was a `WebView involved. This patch adds the `WebViewId` to as many `EmbedderMsg` variants as possible, so we can call their associated `WebView` delegate methods without needing to check and unwrap the `Option`. In many cases, this required more changes to plumb through the `WebViewId`. Notably, all `Request`s now explicitly need a `WebView` or not, in order to ensure that it is passed when appropriate. Signed-off-by: Delan Azabani <dazabani@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* libservo: Stop using `script_traits` in the embedding layer (#35185)Martin Robinson2025-01-281-201/+4
| | | | | | | | | | | | | | | Many types used directly in the `libservo` API are in the `script_traits` crate, which was created to break circular dependencies. Move all API exposed types to `embedder_traits` which now contains types exposed via the `libservo` embedding API. Also expose these at the root of the `libservo` `servo` crate so that the API won't break when they move around in the future. The idea with `embedder_traits` in the future is that it contains types that are available throughout servo because they are used in the embedding API and thus should have minimal dependencies on other Servo crates (a bit like `base`). Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Implement Clipboard Event Api (#33576)Gae242025-01-151-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * implement ClipboardEvent interface Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * draft implementation of clipboard events Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * handle received clipboard events inside html elemtents Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * use rustdoc style Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * fix compilation errors due to rebase Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * update arboard crate Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * improve paste events Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * code cleanup revert arboard crate's update, handle text only Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * restrict visibility of some methods to script crate Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * propagate CanGc argument Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * simplify handle_clipboard_msg Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * remove code duplication Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * fix potential borrow hazard Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * add clipboard_event pref, restore unit test code Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * retrict visibility of some document's methods Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * check if clipboardevent is trusted Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * enable clipboardevent Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> * fix compilation for egl ports Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com> --------- Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
* script: Move navigation fetching to the `ScriptThread` (#34919)Martin Robinson2025-01-101-6/+1
| | | | | | | | | | | | | | | | | | | | This allows reusing the asynchrnous fetch mechanism that we use for page resources and is likely a step toward removing the `FetchThread`. Benefits: - Reduces IPC traffic during navigation. Now instead of bouncing between the constellation and the `ScriptThread` responses are sent directly to the `ScriptThread`. - Allows cancelling loads after redirects, which was not possible before. There is the question of what to do when a redirect is cross-origin (#23037). This currently isn't handled properly as the `Constellation` sends data to the same `Pipeline` that initiated the load. This change doesn't fix this issue, but does make it more possible for the `ScriptThread` to shut down the pipeline and ask the `Constellation` to replace it with a new one. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* script: Refactor channels in `ScriptThread` into receivers and senders (#34776)Martin Robinson2024-12-261-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Create two new data structures in the `script` crate to hold senders and receiver: - `ScriptThreadSenders`: holds all outgoing channels from the `ScriptThread` including a channel to the `ScriptThread` itself. The ultimate goal with this is to reduce duplication by giving a boxed version of this this to `Window`s. - `ScriptThradReceivers`: holds all incoming channels to the `ScriptThread`. This isn't cloenable like the senders. This is used to abstract away `recv()` and `try_recv()` methods used to make the `ScriptThread` event loop easier to read. In addition: - The many duplicated `ScriptThread` self-senders for the `TaskManager` have been removed and, in general, a lot of boilerplate is removed as well. - Visibilty of all methods affected by this change is changed to `pub(crate)` in order to take advantage of dead code detection. Some dead code produced from macros is removed. - Some conversion code is refactord into implementations of the `From` trait. - The names of channels uses a standard "sender" and "receiver" naming as well as trying to be descriptive of where they go in `ScriptThread` as well as `InitialScriptState` Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* script: Make timers per-process (#34581)Martin Robinson2024-12-241-37/+0
| | | | | | | | | | | | | | | Before all timers were managed by the Constellation process, meaning that they had to trigger IPC calls to be scheduled and fired. Currently, timers are only used in the `ScriptThread`, so it makes sense that they are per-process. This change restores the timer thread functionality that existed before avoided entirely. Completion is done using a callback that is sent to the timer thread similarly to how fetch is done. This allows reusing the existing task queue without making any new channels. Fixes #15219. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Replace HistoryEntryReplacement with NavigationHistoryBehavior from the ↵shanehandley2024-12-181-6/+21
| | | | | navigation API (#34681) Signed-off-by: Shane Handley <shanehandley@fastmail.com>
* Upgrade Rust to 1.82.0 (#34592)Jonathan Schwender2024-12-121-0/+2
| | | | | | | | | | | | | | | | | | | | | * Fix deprecated PanicInfo alias Fixes: ```rust use of deprecated type alias `std::panic::PanicInfo`: use `PanicHookInfo` instead ``` Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> * build: upgrade rustc to 1.82.0 Tracking issue for the silenced lints: https://github.com/servo/servo/issues/34591 Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> --------- Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
* Add embedder event for preferred color scheme and respond to it in the ↵arthmis2024-12-121-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | LayoutThread (#34532) * respond to winit platform theme changed event and send it to the layout thread Signed-off-by: Lloyd Massiah <artmis9@protonmail.com> * refactoring viewport and theme change handling functions based on feedback Signed-off-by: Lloyd Massiah <artmis9@protonmail.com> * fixing issues reported by test-tidy Signed-off-by: Lloyd Massiah <artmis9@protonmail.com> * update stylo in order to use color_scheme function on Device Signed-off-by: Lloyd Massiah <artmis9@protonmail.com> --------- Signed-off-by: Lloyd Massiah <artmis9@protonmail.com> Co-authored-by: lazypassion <25536767+lazypassion@users.noreply.github.com>
* Allow running testharness/testdriver/reftests in servodriver (#34550)Josh Matthews2024-12-111-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Make servodriver a thin wrapper over the base webdriver browser/executor classes. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Make ServoWebDriverRefTestExecutor a thin shell over the webdriver reftest executor. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Wait for the initial load to complete when opening a new tab via webdriver. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Remove assumption of a single tab from the webdriver server. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Serialize all keys of JS objects when converting to webdriver values. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Cleanup, docs, etc. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Use webview terminology more consistently. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix flake8 errors. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
* Add `webgpu` feature flag (#34444)atbrakhi2024-12-051-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Move script gpu files into webgpu folder Signed-off-by: atbrakhi <atbrakhi@igalia.com> * Modify gpu webidls Signed-off-by: atbrakhi <atbrakhi@igalia.com> * move gpu realted webidl Signed-off-by: atbrakhi <atbrakhi@igalia.com> * add webgpu feature to script Signed-off-by: atbrakhi <atbrakhi@igalia.com> * add dummy implementation for gpucanvascontext Signed-off-by: atbrakhi <atbrakhi@igalia.com> * fmt Signed-off-by: atbrakhi <atbrakhi@igalia.com> * add skip-if CARGO_FEATURE_WEBGPU Signed-off-by: atbrakhi <atbrakhi@igalia.com> * Move NavigatorGPU and workerNavigator GPU to webgpu idl Signed-off-by: atbrakhi <atbrakhi@igalia.com> * fmt and cleanup Signed-off-by: atbrakhi <atbrakhi@igalia.com> * review fix Signed-off-by: atbrakhi <atbrakhi@igalia.com> * enable webgpu by default and also some fmt fix Signed-off-by: atbrakhi <atbrakhi@igalia.com> * Add pref back, fix imports, small cleanups Signed-off-by: atbrakhi <atbrakhi@igalia.com> --------- Signed-off-by: atbrakhi <atbrakhi@igalia.com>
* Remove referrer policy from document (#34263)shanehandley2024-11-191-3/+3
| | | | | | | | | | | | | | | | | | | | | * Remove the referrer policy from document and rely on its policy container Signed-off-by: Shane Handley <shanehandley@fastmail.com> * Make ReferrerPolicy non-optional, instead using a new enum value to represent the empty string case Signed-off-by: Shane Handley <shanehandley@fastmail.com> * Fix clippy issue Signed-off-by: Shane Handley <shanehandley@fastmail.com> * Fix usage of Option<ReferrerPolicy> in unit test Signed-off-by: Shane Handley <shanehandley@fastmail.com> --------- Signed-off-by: Shane Handley <shanehandley@fastmail.com>
* feat: `webxr` feature flag (#34241)Ngo Iok Ui (Wu Yu Wei)2024-11-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add webxr feature flag Add webxr feature flag to embedder_traits Add webxr flag to constellation Add webxr flag to compositor Add webxr flag to canvas Turn registry into optional Add webxr flag to servo lib Signed-off-by: Wu Yu Wei <yuweiwu@pm.me> Co-authored-by: august kline <me@augustkline.com> * Cargo fmt Signed-off-by: Wu Yu Wei <yuweiwu@pm.me> * Add missing license Signed-off-by: Wu Yu Wei <yuweiwu@pm.me> * Cargo clippy Signed-off-by: Wu Yu Wei <yuweiwu@pm.me> --------- Signed-off-by: Wu Yu Wei <yuweiwu@pm.me> Co-authored-by: august kline <me@augustkline.com>
* compositor: Create a single cross-process compositor API (#33619) (#33660)Martin Robinson2024-10-091-3/+5
| | | | | | | | | | | | | | | | | | | | | | Instead of exposing many different kinds of messages to the compositor that are routed through the constellation, expose a single message type which can be sent across IPC channels. In addition, this IPC channel and the route to the crossbeam channel with the compositor is created along with the `CompositorProxy`, simplifying what needs to be passed around during pipeline initialization. Previously, some image updates (from video) were sent over IPC with a special serialization routine and some were sent via crossbeam channels (canvas). Now all updates go over the IPC channel `IpcSharedMemory` is used to avoid serialization penalties. This should improve performance and reduce copies for video, but add a memory copy overhead for canvas. This will improve in the future when canvas renders directly into a texture. All-in-all this is a simplification which opens the path toward having a standard compositor API and reduces the number of duplicate messages and proxying that had to happen in libservo. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Revert "compositor: Create a single cross-process compositor API (#33619)" ↵Martin Robinson2024-10-041-5/+3
| | | | | | | | | (#33645) This reverts commit f2f5614ad64927aa82aa8937ae14a6086df49d2b. This is causing intermittent crashes: https://github.com/servo/servo/actions/runs/11167043809/job/31044255019 Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* compositor: Create a single cross-process compositor API (#33619)Martin Robinson2024-10-031-3/+5
| | | | | | | | | | | | | | | | | | | | | | Instead of exposing many different kinds of messages to the compositor that are routed through the constellation, expose a single message type which can be sent across IPC channels. In addition, this IPC channel and the route to the crossbeam channel with the compositor is created along with the `CompositorProxy`, simplifying what needs to be passed around during pipeline initialization. Previously, some image updates (from video) were sent over IPC with a special serialization routine and some were sent via crossbeam channels (canvas). Now all updates go over the IPC channel `IpcSharedMemory` is used to avoid serialization penalties. This should improve performance and reduce copies for video, but add a memory copy overhead for canvas. This will improve in the future when canvas renders directly into a texture. All-in-all this is a simplification which opens the path toward having a standard compositor API and reduces the number of duplicate messages and proxying that had to happen in libservo. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Trace more functions by adding perfetto tracing events (#33417)atbrakhi2024-09-131-1/+1
| | | Signed-off-by: atbrakhi <atbrakhi@igalia.com>
* script: Create a `CrossProcessInstant` to enable serializable monotonic time ↵Martin Robinson2024-09-051-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#33282) Up until now, Servo was using a very old version of time to get a cross-process monotonic timestamp (using `time::precise_time_ns()`). This change replaces the usage of old time with a new serializable monotonic time called `CrossProcessInstant` and uses it where `u64` timestamps were stored before. The standard library doesn't provide this functionality because it isn't something you can do reliably on all platforms. The idea is that we do our best and then fall back gracefully. This is a big change, because Servo was using `u64` timestamps all over the place some as raw values taken from `time::precise_time_ns()` and some as relative offsets from the "navigation start," which is a concept similar to DOM's `timeOrigin` (but not exactly the same). It's very difficult to fix this situation without fixing it everywhere as the `Instant` concept is supposed to be opaque. The good thing is that this change clears up all ambiguity when passing times as a `time::Duration` is unit agnostic and a `CrossProcessInstant` represents an absolute moment in time. The `time` version of `Duration` is used because it can both be negative and is also serializable. Good things: - No need too pass around `time` and `time_precise` any longer. `CrossProcessInstant` is also precise and monotonic. - The distinction between a time that is unset or at `0` (at some kind of timer epoch) is now gone. There still a lot of work to do to clean up timing, but this is the first step. In general, I've tried to preserve existing behavior, even when not spec compliant, as much as possible. I plan to submit followup PRs fixing some of the issues I've noticed. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* script: Stop using `time` in DOM timers (#33262)Martin Robinson2024-08-301-19/+3
| | | | | | This switches to using `std::time` types for DOM timer operations, which allows removing our custom time units in favor of `Duration`. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
* Gamepad: Implement GamepadHapticActuator (#32046)Daniel Adams2024-07-201-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Implement Servo side of GamepadHapticActuator Signed-off-by: Daniel Adams <msub2official@gmail.com> * Get build working Signed-off-by: Daniel Adams <msub2official@gmail.com> * Create effect handling on embedder side Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update tracing for GamepadHapticEffect Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update gilrs to point to commit with effect complete event Signed-off-by: Daniel Adams <msub2official@gmail.com> * Implement playing and preempting haptic effects Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update IDL to add trigger rumble Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update WPT expectations Signed-off-by: Daniel Adams <msub2official@gmail.com> * Handle stopping haptic effects from reset() Signed-off-by: Daniel Adams <msub2official@gmail.com> * ./mach fmt, fix test-tidy issues Signed-off-by: Daniel Adams <msub2official@gmail.com> * Add extra validity checks for trigger rumble Signed-off-by: Daniel Adams <msub2official@gmail.com> * Retrieve supported haptic effects from embedder Signed-off-by: Daniel Adams <msub2official@gmail.com> * Fix test expectations Signed-off-by: Daniel Adams <msub2official@gmail.com> * Add missing spec link, pin gilrs commit Signed-off-by: Daniel Adams <msub2official@gmail.com> * servoshell cargo formatting Signed-off-by: Daniel Adams <msub2official@gmail.com> * Fix Cargo.toml Signed-off-by: Daniel Adams <msub2official@gmail.com> * Additional comments, realm proof, naming Signed-off-by: Daniel Adams <msub2official@gmail.com> * ./mach fmt Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update gilrs rev to gilrs-core 0.5.12 release Signed-off-by: Daniel Adams <msub2official@gmail.com> * Implement sequence ids for gamepad haptic promises Signed-off-by: Daniel Adams <msub2official@gmail.com> * Take playing effect promise instead of cloning Signed-off-by: Daniel Adams <msub2official@gmail.com> * Implement listener for reset function Signed-off-by: Daniel Adams <msub2official@gmail.com> * Fix Cargo.lock Signed-off-by: Daniel Adams <msub2official@gmail.com> * Restructure IPC listeners, add comments, handle visibility change Signed-off-by: Daniel Adams <msub2official@gmail.com> * Check that haptic effect still exists before handling ff completion event Signed-off-by: Daniel Adams <msub2official@gmail.com> * Visibility steps, add InRealm bindings for promises Signed-off-by: Daniel Adams <msub2official@gmail.com> * Add Gamepad EmbedderMsg arms to egl servo_glue Signed-off-by: Daniel Adams <msub2official@gmail.com> --------- Signed-off-by: Daniel Adams <msub2official@gmail.com>
* clippy: Fix warnings in `shared` and `config`, `fonts`, `layout`, and ↵Martin Robinson2024-07-041-1/+1
| | | | `layout_2020` components (#32674)
* script: Implement the `FontFaceSet` DOM API (#32576)Mukilan Thiyagarajan2024-06-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a skeleton implementation of FontFaceSet interface with support for resolving the `document.fonts.ready` Promise when the loading of web fonts is completed. This change exposes new failures in the web platform tests. These were ERROR before the change because `document.fonts.ready` caused a `ReferenceError` causing the tests to be aborted and they now FAIL: - /css/CSS2/linebox/vertical-align-top-bottom-001.html - /css/css-flexbox/flex-one-sets-flex-basis-to-zero-px.html - /css/css-fonts/generic-family-keywords-001.html - /css/css-fonts/math-script-level-and-math-style/math-script-level-004.tentative.html - /css/css-fonts/math-script-level-and-math-style/math-script-level-002.tentative.html - /css/css-text/text-autospace/text-autospace-ligature-001.html - /css/css-values/calc-size/calc-size-width.tentative.html These were TIMEOUT before the change because `document.fonts.ready` was a ReferenceError and the tests were asynchronous (reftest-wait). These now FAIL because the assertions are now executed after fonts are loaded: - /css/css-fonts/matching/fixed-stretch-style-over-weight.html - /css/css-fonts/matching/range-descriptor-reversed.html - /css/css-fonts/matching/stretch-distance-over-weight-distance.html - /css/css-fonts/matching/style-ranges-over-weight-direction.html - /css/css-fonts/variations/variable-box-font.html - /css/css-fonts/variations/variable-gpos-m2b.html - /css/css-fonts/variations/variable-gsub.html - /css/css-fonts/variations/variable-opsz-size-adjust.html - /css/css-position/sticky/position-sticky-change-top.html - /css/css-position/sticky/position-sticky-fixed-ancestor.html - /css/css-position/sticky/position-sticky-flexbox.html - /css/css-position/sticky/position-sticky-grid.html - /css/css-position/sticky/position-sticky-inline.html - /css/css-position/sticky/position-sticky-rendering.html - /css/css-position/sticky/position-sticky-stacking-context.html - /css/css-position/sticky/position-sticky-table-td-left.html - /css/css-position/sticky/position-sticky-table-td-right.html - /css/css-position/sticky/position-sticky-table-tfoot-bottom.html - /css/css-position/sticky/position-sticky-table-th-right.html - /css/css-position/sticky/position-sticky-table-thead-top.html - /css/css-position/sticky/position-sticky-table-tr-bottom.html - /css/css-position/sticky/position-sticky-table-tr-top.html - /css/css-position/sticky/position-sticky-writing-modes.html - /css/css-pseudo/marker-intrinsic-contribution-001.html - /css/css-text/hyphens/hyphens-character.html These tests now PASS due to this patch: * FAIL -> PASS - /html/canvas/element/text/2d.text.draw.fill.maxWidth.fontface.html - /html/canvas/element/text/2d.text.measure.width.empty.html * TIMEOUT -> PASS - /css/css-fonts/variations/font-descriptor-range-reversed.html - /css/css-fonts/variations/variable-opsz.html - /css/css-position/sticky/position-sticky-table-th-left.html * ERROR -> PASS - /css/css-fonts/generic-family-keywords-002.html - /css/css-fonts/generic-family-keywords-003.html * These two tests only PASS in Layout 2020: - /css/CSS2/positioning/inline-static-position-001.html - /css/cssom-view/getBoundingClientRect-empty-inline.html These two tests have subtests that PASS intermittenttly: - /fetch/metadata/generated/css-font-face.sub.tentative.html - /css/css-fonts/generic-family-keywords-001.html These tests are new TIMEOUTS that used to FAIL because `documents.fonts.ready` was undefined: - /resource-timing/TAO-match.html - /resource-timing/content-type.html - /resource-timing/nextHopProtocol-is-tao-protected.https.html The failure in `/resize-observer/change-layout-in-error.html` could be due to an issue in the ResizeObserver implementation that is now exposed with this change, but this needs more investigation. Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Remove more IPC messages between script and layout (#32377)Martin Robinson2024-05-271-18/+7
| | | | | | Instead of bouncing messages from the compositor to script and then to layout, just have script call methods on Layout. Additionally, we do not need to send any followup messages to script for these messages. Instead just execute code after calling the method on Layout.
* fonts: Clean up messaging during web fonts loads (#32332)Martin Robinson2024-05-221-5/+0
| | | | | | | | | | | | Instead of sending a message to the script thread via IPC when a web font loads and then sending another, just give the `FontContext` a callback that send a single message to the script thread. This moves all the cache invalidation internally into `FontContext` as well. Additionally, the unused LayoutControlMessage::ExitNow enum variant is removed. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* compositor: Move WebRender-ish messages and types to `webrender_traits` (#32315)Mukilan Thiyagarajan2024-05-201-246/+13
| | | | | | | | | | | | | | | | | | | | * Move WebRender related types to `webrender_traits` This refactor moves several WebRender related types from `compositing_traits`, `script_traits` and `net_traits` crates to the `webrender_traits` crate. This change also moves the `Image` type and associated function out of `net_traits` and into the `pixels` crate. Co-authored-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> * Move `script_traits::WebrenderIpcSender` to `webrender_traits::WebRenderScriptApi` --------- Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Move non-gfx things out of `gfx_traits` and create a `base` crate (#32296)Martin Robinson2024-05-171-6/+7
| | | | | | | | | | | | | | | | | | | | | | | For a long time, `gfx_traits` has held a lot of things unrelated to graphics and also unrelated to the `gfx` crate (which is mostly about fonts). This is a cleanup which does a few things: 1. Move non `gfx` crate things out of `gfx_traits`. This is important in order to prevent dependency cycles with a different integration between layout, script, and fonts. 2. Rename the `msg` crate to `base`. It didn't really contain anything to do with messages and instead mostly holds ids, which are used across many different crates in Servo. This new crate will hold the *rare* data types that are widely used. Details: - All BackgroundHangMonitor-related things from base to a new `background_hang_monitor_api` crate. - Moved `TraversalDirection` to `script_traits` - Moved `Epoch`-related things from `gfx_traits` to `base`. - Moved `PrintTree` to base. This should be widely useful in Servo. - Moved `WebrenderApi` from `base` to `webrender_traits` and renamed it to `WebRenderFontApi`.
* script: Start rework to better match the specification HTML event loop (#31505)Gregory Terzian2024-05-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix the HTML event-loop: add a update the rendering task add rendering task source sketch structure to update the rendering resize steps composition events fix warnings in rendering task source refactor handling of composition events: put window and doc for pipeline on top set script as user interacting in update the rendering task fmt add todos for other steps, put all compositor handling logic in one place update the rendering: evaluate media queries and report changes update the rendering: update animations and send events update the rendering: run animation frames update the rendering: order docs put rendering related info on documents map tidy update the rendering: add issue numbers to todos update the rendering: reflow as last step update the rendering: add todo for top layer removals note rendering opportunity when ticking animations for testing fix double borrow crash in css/basic-transition fix faster reversing of transitions test undo ordering of docs bypass not fully-active pipeline task throttling for rendering tasks ensure tasks are dequed from task queue prioritize update the rendering task remove servo media stuff from set activity tidy debug update the rendering: perform microtask checkpoint after task tidy-up only run evaluate media queries if resized re-add evaluation of media queries for each rendering task, re-prioritize rendering tasks, re-add microtask checkpoint for all sequential messages re-structure resize steps, and their interaction with evaluating media queries and reacting to environment changes update the rendering: remove reflow call at the end update webmessaging expectations update to FAIL /html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/load-pageshow-events-iframe-contentWindow.html update to FAIL load-pageshow-events-window-open.html add issue number for ordering of docs nits move batching of mouse move event to document info nits add doc for mouse move event index reset mouse move event index when taking pending compositor events fix replacing mouse move event nits * move update the rendering related data to document * move re-taking of tasks to try_recv * address nits * change task queue try_recv into take_tasks_and_recv, with nits * refactor process_pending_compositor_events * when updating the rendering, return early if script cannot continue running * use an instant for the last render opportunity time * nits * remove handle_tick_all_animations * use a vec for pending resize and compositor events * fix spec links * Fix a few other nits before landing --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* webgpu: Refactor webgpu crate (#32255)Samson2024-05-081-1/+1
| | | | | | | * wgpu(_core) -> wgc * Refactor webgpu crate split lib.rs into multiple modules
* Rework “visible” to “throttled” in constellation + script + ↵Delan Azabani2024-03-221-7/+6
| | | | compositor (#31816)
* clippy: fix `result_unit_err` warnings (#31791)eri2024-03-211-3/+3
| | | | | | | | | | | | | | | | | * clippy: fix `result_unit_err` warnings * feat: fix result warnings in script * doc: document `generate_key` return type Co-authored-by: Martin Robinson <mrobinson@igalia.com> * feat: add back result to RangeRequestBounds::get_final Co-authored-by: Martin Robinson <mrobinson@igalia.com> --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* dependencies: Upgrade to WebRender 0.64 (#31486)Martin Robinson2024-03-141-11/+23
| | | | | | | | | This brings the version of WebRender used in Servo up-to-date with Gecko upstream. The big change here is that HiDPI is no longer handled via WebRender. Instead this happens via a scale applied to the root layer in the compositor. In addition to this change, various changes are made to Servo to adapt to the new WebRender API. Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* clippy: Fix warnings in `components/shared` (#31627)eri2024-03-121-8/+8
| | | | | | | * clippy: fix warnings in `components/shared` * fix: formatting derive * fix: rename new to default
* Fix rustdoc errors in `components/shared` (#31582)Aarya Khandelwal2024-03-081-1/+1
| | | | | | | * Fixed error in documentation in components>shared>embedder>lib.rs * fixed documentation warning in compoenents>shared>net>request.rs * Fixed the documentation (URL issue) in components>shared>script>lib.rs
* script: Do not run layout in a thread (#31346)Martin Robinson2024-02-231-29/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * script: Do not run layout in a thread Instead of spawning a thread for layout that almost always runs synchronously with script, simply run layout in the script thread. This is a resurrection of #28708, taking just the bits that remove the layout thread. It's a complex change and thus is just a first step toward cleaning up the interface between script and layout. Messages are still passed from script to layout via a `process()` method and script proxies some messages to layout from other threads as well. Big changes: 1. Layout is created in the script thread on Document load, thus every live document is guaranteed to have a layout. This isn't completely hidden in the interface, but we can safely `unwrap()` on a Document's layout. 2. Layout configuration is abstracted away into a LayoutConfig struct and the LayoutFactory is a struct passed around by the Constellation. This is to avoid having to monomorphize the entire script thread for each layout. 3. Instead of having the Constellation block on the layout thread to figure out the current epoch and whether there are pending web fonts loading, updates are sent synchronously to the Constellation when rendering to a screenshot. This practically only used by the WPT. A couple tests start to fail, which is probably inevitable since removing the layout thread has introduced timing changes in "exit after load" and screenshot behavior. Co-authored-by: Josh Matthews <josh@joshmatthews.net> * Update test expectations * Fix some issues found during review * Clarify some comments * Address review comments --------- Co-authored-by: Josh Matthews <josh@joshmatthews.net>
* Implement non-XR Gamepad discovery and input (#31200)Daniel Adams2024-02-171-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Create embedder event to send to constellation * Handle gamepad message in constellation, send to script thread * Handle GamepadEvent in script thread and dispatch event to document * Add missing Clones, fix event * Add gamepad task source * Adjust GamepadIndex type, remove unused imports * Add internal getter for gamepads list * Update gamepad new methods * Handle gamepad connect and disconnect events * Proto will be none, no need for HandleObject * Initialize buttons and axes to standard mapping * Adjust update type index types * Update GamepadButton update function * Adjust Gamepad mapping comments to match spec, add update logic * Amend comment * Update button and axis inputs on Updated event * Add GilRs as gamepad backend in servoshell * Add spec links, queue gamepad updates on task source * ./mach fmt * Fix comment length * Split out button init, update spec comments * Move gamepad event handling from document to global * Map and normalize axes/button values * Use std::time for gamepad timestamp * Adjust gamepad handling in event loop * Move button press/touch check into map+normalize function - Small change but is more in line with spec * ./mach fmt * Update comment spec links and warning messages * Doc comments -> regular comments * Add window event handlers for gamepad connect/disconnect * Adjust gamepad disconnect behavior * Add missing TODO's, adjust gamepad/gamepadbutton list methods and formatting * Update button handling from gilrs, add comments * Enable gamepad pref during WPT tests and update expectations * Update WPT expectations in meta-legacy-layout
* rustdoc: Fix many rustdoc errors (#31147)Martin Robinson2024-01-221-4/+4
| | | | This fixes many rustdoc errors that occur due to raw URLs in rustdoc comments as well as unescaped Rust code that should be in backticks.