Put the Gamepad API and its supporting infrastructure behind a `gamepad`
feature flag. This allows embedders to opt-out of gamepad support at
compile time to save on binary size and reduce dependencies.
Testing:
1. `./mach build -d` (Gamepad enabled by default)
2. `cargo build -p servoshell --no-default-features --features
"libservo/clipboard,js_jit,max_log_level,webgpu"` (Gamepad Disabled)
3. `cargo build -p servoshell --features "gamepad,webxr,..."` (Gamepad &
WebXR Enabled)
Fixes: #40897
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
dblclick on text inputs was being dispatched to an internal element used
for the input, not to the <input> itself. As a result, page scripts
listening for dblclick on the input never received the event.
Testing: tested manually.
Fixes: #41303
---------
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
For a long time, the "Compositor" hasn't done any compositing. This is
handled by WebRender. In addition the "Compositor" does many other
tasks. This change renames `IOCompositor` to `Paint`.
`Paint` is Servo's paint subsystem and contains multiple `Painter`s.
This change does not rename the crate; that will be done in a
followup change.
Testing: This just renames types and updates comments, so no new tests
are necessary.
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This new data structure allows passing more information when popping up
context menus. It's possible in the future that it will be adapted into
a more generic "hit test result" type API ala WebKit, but for now, this
is probably
enough.
Testing: This change includes new API test assertions.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
The two are semantically equivalent, but `find_map` is more concise.
Testing: Covered by existing tests
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Add context menu options for images, links, and editable text areas. In
addition add the ability to show menu options that are disabled. This
also improves the visual style of the context menu in egui as part of
supporting disabled options.
Testing: This has been manually tested, but we could we should be able
to
easily add unit tests when enriching the API with information about the
active element under context menus.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
Removes some unneeded lints, especially `#[allow(unsafe_code)]`.
Testing: Refactor
Part of: #40383
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
This PR integrates showing context menus into the
`WebViewDelegate::show_embedder_control` API. In addition,
`ContextMenuItem` and `ContextMenuAction` data types are exposed which
abstract away the different components of the context menu. Later
changes will implement this API for servoshell as well as add
element-specific actions such as "Select All" and "Copy Image URL".
Testing: This change adds a WebView API test.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
When scrolling the root viewport of a WebView (the top level frame),
ask the renderer to process that event. This allows keyboard scrolling
to pan the pinch zoom viewport. This is important for moving around a
pinch zoomed WebView via the keyboard.
Testing: The changes this makes to panning are hard to test, since we
have no way of retrieving the pinch zoom viewport values from Servo,
but the normal scrolling is tested by a servodriver test which is still
passing with these changes.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
This replaces the implementation of is_empty and len with more efficient
representation without conversion
and allocation based on the underlying bytes.
For this we use a new view, EncodedBytesView.
Additionally, we implement a new macro `match_domstring_ascii!` which
allows simple match clauses
matching ascii strings with DOMStrings without conversion/allocation.
The macro will panic in debug builds if the strings are non-ascii but
will not match all DOMStrings correctly.
We replaced the usage of `DOMString::str()` in many places with this
macro.
Testing: len and is_empty were already covered by tests.
match_domstring_ascii! has more unit tests added with this PR.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
The renderer needs needs to know when touch events processing has
finished in the DOM in order to properly handle them. This was
previously done using the `CompositorMsg::TouchEventProcessed` message.
This message is now redudant with the general-purpose
`EmbedderMsg::InputEventHandled` message.
This change removes the former message and instead, has the
`TouchHandler` keep a `HashMap` of pending touch events which is uses to
finish their processing when they come back from script. The goal here
is reduce the number of messages sent and to keep the complexity of
touch handling more centered in the `TouchHandler`.
Testing: This should not change observable behavior, so is covered by
existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This makes the management of flags conceptually simpler and reduces the
number of instance variables in the `Event` data structure.
Testing: This should not change behavior so should be covered by
existing tests.
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Servo currently has three ways of notifying the embedder that input
events have been processed.
1. `WebViewDelegate::notify_keyboard_event`: This is used to implement
overridable keybindings in servoshell. It notifies the embedder when
a keyboard event has been processed, but not "handled" by the engine.
2. WebDriver's command message senders and receivers, this is used to
let WebDriver wait until events have been handled to continue with
script execution.
3. Touch event processing notifications: This is used to serialize touch
event processing.
This change unifies the first two things with a new
`WebViewDelegate::notify_input_event_handled` API. This API informs the
embedder (via a generated id) that an input event has finished
processing and what the result of the processing was.
This allows embedders to do other things with events once they have been
processed. For example, embedders might want to chain unconsumed events
up to parent widgets or to add support for overridable keybindings.
As part of this the `canceled` flag in script's `Event` data structure
is turned into a `bitflags` mirror of the new API type to describe the
result of event handling.
Testing: This shouldn't change observable behavior and is thus covered
by existing tests.
The new API is consumed by servoshell, which uses it for tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This implements LazyDOMString (from now on DOMString) as outlined in
https://github.com/servo/servo/issues/39479.
Constructing from a *mut JSString we keep the in a
RootedTraceableBox<Heap<*mut JSString>> and transform
the string into a rust string if necessary via the `make_rust_string`
method.
Methods used in script are implemented on this string. Currently we
transform the string at all times.
But in the future more efficient implementations are possible.
We implement the safety critical sections in a separate module
DOMStringInner which allows simple constructors, `make_rust_string` and
the `bytes` method.
This method returns the new type `EncodedBytes` which contains the
reference to the underlying string in either format.
Testing: WPT tests still seem to work, so this should test this
functionality.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
The embedder should never be responsible for triggering click events, so
this change removes that possibility from the API. In addition,
triggering of click events is simplified by moving the logic to the
`DocumentEventHandler`. This has the benefit of making behavior
consistent between in-process and out-of-process `<iframe>`s. Now click
events are never triggered when the button up and down cross frame
boundaries.
Testing: This should be covered by existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
When an `<iframe>` cannot scroll because the size of the frame is
greater than or
equal to the size of page contents, chain up the keyboard scroll
operation to the parent frame.
Testing: A new Servo-only WPT tests is added, though needs to be
manually
run with `--product servodriver`.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Delan Azabani <dazabani@igalia.com>
Instead of having every single embedder implement keyboard scrolling,
handle it in script in the default key event handler. This allows
properly targeting the scroll events to their scroll containers as well
as appropriately sizing "page up" and "page down" scroll deltas.
This change means that when you use the keyboard to scroll, the focused
or most recently clicked `<iframe>` or overflow scroll container is
scrolled, rather than the main frame.
In addition, when a particular scroll frame is larger than its content
in the axis of the scroll, the scrolling operation is chained to
the parent (as in other browsers). One exception is for `<iframe>`s,
which will be implemented in a followup change.
Testing: automated tests runnable locally with `mach test-wpt --product
servodriver`
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This PR **removes** `ScriptToConstellationMessage::ForwardToEmbedder`,
and replaces it with an explicit `ScriptToEmbedderChannel`. This new
channel is based on `GenericCallback` and in single-process mode will
directly send the message the to the embedder and wake it. In
multi-process mode, the message is routed via the ROUTER, since waking
is only possible from the same process currently. This means in
multi-process mode there are likely no direct perf benefits, since we
still need to hop the message over the ROUTER (instead of over the
constellation).
In single-process mode we can directly send the message to the embedder,
which should provide a noticable latency improvement in all cases where
script is blocked waiting on the embedder to reply.
This does not change the way the embedder receives messages - the
receiving end is unchanged.
## How was sending messages to the embedder working before?
1. Script wraps it's message to the embedder in
`ScriptToConstellationMessage::ForwardToEmbedder` and sends it to
constellation.
2. The [constellation event loop] receives the message in
[handle_request]
3. If deserialization fails, [an error is logged and the message is
ignored]
4. Since our message came from script, it is handle in
[handle_request_from_script]
5. The message is logged with trace log level
6. If the pipeline is closed, [a warning is logged and the message
ignored]
7. The wrapped `EmbedderMsg` [is forwarded to the embedder]. Sending the
message also invokes `wake()` on the embedder eventloop waker.
[constellation event loop]:
2e1b2e7260/components/constellation/constellation.rs (L755)
[handle request]:
2e1b2e7260/components/constellation/constellation.rs (L1182)
[an error is logged and the message is ignored]:
2e1b2e7260/components/constellation/constellation.rs (L1252)
[handle_request_from_script]:
https://github.com/servo/servo/blob/main/components/constellation/constellation.rs#L1590
[a warning is logged and the message ignored]:
2e1b2e7260/components/constellation/constellation.rs (L1599)
[is forwarded to the embedder]:
2e1b2e7260/components/constellation/constellation.rs (L1701)
Testing: Communication between Script and Embedder is extensive, so this
should be covered by existing tests.
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This change ports all `EmbedderMsg` reply channels that don't use the
`ROUTER` to GenericChannel.
The remaining reply channels that use the router are blocked until
#38973 is merged.
This is a breaking change in the API between libservo and embedders.
Future work: A lot of the reply channels in this PR look like they
conceptually should be oneshot ipc channels. It might make sense to
provide a `OneshotGenericChannel` abstraction that encodes this.
Testing: No functional changes - covered by existing tests. None of the
channels changed here uses the Router
Part of #38912
---------
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
Moves interfaces defined by the gamepad spec to the
`script/dom/gamepad/` module from `script/dom/`.
Testing: Just a refactor shouldn't need any testing
Fixes: N/A
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
This changes makes a variety of changes to ensure that the cursor is set
back to the default cursor when it leaves the `WebView`:
1. Display list updates can come after a mouse leaves the `WebView`, so
when refreshing the cursor after the update, base the updated cursor
on the last hovered location in the `DocumentEventHandler`, rather
than the compositor. This allows us to catch when the last hovered
position is `None` (ie the cursor has left the `WebView`).
2. When handling `MouseLeftViewport` events for the cursor leaving the
entire WebView, properly set the
MouseLeftViewport::focus_moving_to_another_iframe` on the input event
passed to the script thread.
3. When moving out of the `WebView` entirely, explicitly ask the
embedder to set the cursor back to the default.
Testing: This change adds a unit test verifying this behavior.
Fixes: #38710.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This shows up sometimes in code reviews, so it makes sense that tidy
enforces it. `rustfmt` supports this via comment normalization, but it
does many other things and is still an unstable feature (with bugs).
Testing: There are new tidy tests for this change.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
According to spec of
[hit-test](https://w3c.github.io/uievents/#hit-test) for native mouse
event, mousedown/mouseup should also be excluded when interacting with
disabled element, even tho it may be the frontmost of
[elementFromPoint](https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint).
Testing: Now it matches the behaviour of other browsers in #38670 for
disabled element. Also testdriver test:
`tests\wpt\tests\html\semantics\disabled-elements\disabled-event-dispatch.tentative.html`
has 4 more passing tests.
Fixes: Part of #38670.
Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
#38584 moves input event handling to new `DocumentEventHandler`, but
probably reintroduced some removed code when resolving conflict with
#38589.
Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This moves the majority of the input event handler code to the
`DocumentEventHandler` helper structure. It better encapsulates event
handling, hiding most of the details from both `ScriptThread` and
`Document`. The benefit here is that the majority of the functions can
become private and `Document` is over 1000 lines shorter.
Testing: This should not change any behavior so is covered by existing
WPT tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Properly send `mouseleave` events when the cursor moves between
`<iframe>`s. This allows a better handling of cursor changes and status
text updates. Specifically, we do not need to continuously update the
cursor and the value can be cached in the `Document`. In addition,
status updates can now be sent properly when moving focus between
`<iframe>`s.
Note that style updates for `:hover` values are still broken, but less
so than before. Now the hover state on the `Node` is updated, but for
some
reason the restyle isn't taking place properly. This maintains the
status quo as far as behavior goes when hover moves between `<iframe>`s.
This change also adds a helper data structure to `Document` which will
eventually be responsible for event handling.
Testing: Cursor and status change are currently very hard to test as
the API test harness makes this difficult at the moment.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>