Webdriver: Keyboard Action use webview::notify_input_event instead of directly sent to constellation (#37908)

Previously, we KeyboardAction will be forwarded to constellation by the
embedder. Now we use `webview.notify_input_event`, which will send
`WebDriverCommandMsg::ForwardInputEvent` for KeyboardAction

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

---------

Signed-off-by: PotatoCP <kenzieradityatirtarahardja18@gmail.com>
This commit is contained in:
Kenzie Raditya Tirtarahardja 2025-07-08 14:54:57 +08:00 committed by GitHub
parent 11bb83d422
commit 1773ea44f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 17 additions and 61 deletions

View file

@ -4625,31 +4625,8 @@ where
}
}
},
WebDriverCommandMsg::KeyboardAction(browsing_context_id, key_event, msg_id) => {
let pipeline_id = match self.browsing_contexts.get(&browsing_context_id) {
Some(browsing_context) => browsing_context.pipeline_id,
None => {
return warn!("{}: KeyboardAction after closure", browsing_context_id);
},
};
let event_loop = match self.pipelines.get(&pipeline_id) {
Some(pipeline) => pipeline.event_loop.clone(),
None => return warn!("{}: KeyboardAction after closure", pipeline_id),
};
let event = InputEvent::Keyboard(KeyboardEvent::new(key_event.clone()))
.with_webdriver_message_id(msg_id);
let control_msg = ScriptThreadMessage::SendInputEvent(
pipeline_id,
ConstellationInputEvent {
pressed_mouse_buttons: self.pressed_mouse_buttons,
active_keyboard_modifiers: key_event.modifiers,
hit_test_result: None,
event,
},
);
if let Err(e) = event_loop.send(control_msg) {
self.handle_send_error(pipeline_id, e)
}
WebDriverCommandMsg::KeyboardAction(..) => {
unreachable!("This command should be send directly to the embedder.");
},
WebDriverCommandMsg::MouseButtonAction(..) => {
unreachable!("This command should be send directly to the embedder.");

View file

@ -52,7 +52,7 @@ pub enum WebDriverCommandMsg {
SendKeys(BrowsingContextId, Vec<WebDriverInputEvent>),
/// Act as if keys were pressed or release in the browsing context with the given ID.
KeyboardAction(
BrowsingContextId,
WebViewId,
KeyboardEvent,
// Should never be None.
Option<WebDriverMessageId>,

View file

@ -311,11 +311,8 @@ impl Handler {
// Step 12
self.increment_num_pending_actions();
let msg_id = self.current_action_id.get();
let cmd_msg = WebDriverCommandMsg::KeyboardAction(
self.session().unwrap().browsing_context_id,
keyboard_event,
msg_id,
);
let cmd_msg =
WebDriverCommandMsg::KeyboardAction(session.webview_id, keyboard_event, msg_id);
let _ = self.send_message_to_embedder(cmd_msg);
}
@ -350,11 +347,8 @@ impl Handler {
// Step 12
self.increment_num_pending_actions();
let msg_id = self.current_action_id.get();
let cmd_msg = WebDriverCommandMsg::KeyboardAction(
self.session().unwrap().browsing_context_id,
keyboard_event,
msg_id,
);
let cmd_msg =
WebDriverCommandMsg::KeyboardAction(session.webview_id, keyboard_event, msg_id);
let _ = self.send_message_to_embedder(cmd_msg);
}
}

View file

@ -24,8 +24,8 @@ use servo::servo_url::ServoUrl;
use servo::user_content_manager::{UserContentManager, UserScript};
use servo::webrender_api::ScrollLocation;
use servo::{
EventLoopWaker, InputEvent, MouseButtonEvent, MouseMoveEvent, WebDriverCommandMsg, WheelDelta,
WheelEvent, WheelMode,
EventLoopWaker, InputEvent, KeyboardEvent, MouseButtonEvent, MouseMoveEvent,
WebDriverCommandMsg, WheelDelta, WheelEvent, WheelMode,
};
use url::Url;
use winit::application::ApplicationHandler;
@ -458,8 +458,14 @@ impl App {
WebDriverCommandMsg::SendKeys(..) => {
running_state.forward_webdriver_command(msg);
},
WebDriverCommandMsg::KeyboardAction(..) => {
running_state.forward_webdriver_command(msg);
WebDriverCommandMsg::KeyboardAction(webview_id, key_event, msg_id) => {
// TODO: We should do processing like in `headed_window:handle_keyboard_input`.
if let Some(webview) = running_state.webview_by_id(webview_id) {
webview.notify_input_event(
InputEvent::Keyboard(KeyboardEvent::new(key_event))
.with_webdriver_message_id(msg_id),
);
}
},
WebDriverCommandMsg::MouseButtonAction(
webview_id,

View file

@ -1,21 +0,0 @@
[pointer_modifier_click.py]
[test_modifier_click[\\ue00a-altKey\]]
expected: FAIL
[test_modifier_click[\\ue052-altKey\]]
expected: FAIL
[test_modifier_click[\\ue03d-metaKey\]]
expected: FAIL
[test_modifier_click[\\ue053-metaKey\]]
expected: FAIL
[test_modifier_click[\\ue008-shiftKey\]]
expected: FAIL
[test_modifier_click[\\ue050-shiftKey\]]
expected: FAIL
[test_many_modifiers_click]
expected: FAIL