Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions components/constellation/constellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ use embedder_traits::user_content_manager::UserContentManager;
use embedder_traits::{
AnimationState, CompositorHitTestResult, Cursor, EmbedderMsg, EmbedderProxy,
FocusSequenceNumber, ImeEvent, InputEvent, JSValue, JavaScriptEvaluationError,
JavaScriptEvaluationId, MediaSessionActionType, MediaSessionEvent, MediaSessionPlaybackState,
MouseButton, MouseButtonAction, MouseButtonEvent, Theme, ViewportDetails, WebDriverCommandMsg,
WebDriverCommandResponse, WebDriverLoadStatus,
JavaScriptEvaluationId, KeyboardEvent, MediaSessionActionType, MediaSessionEvent,
MediaSessionPlaybackState, MouseButton, MouseButtonAction, MouseButtonEvent, Theme,
ViewportDetails, WebDriverCommandMsg, WebDriverCommandResponse, WebDriverLoadStatus,
};
use euclid::Size2D;
use euclid::default::Size2D as UntypedSize2D;
Expand All @@ -140,7 +140,7 @@ use ipc_channel::Error as IpcError;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use keyboard_types::webdriver::Event as WebDriverInputEvent;
use keyboard_types::{Key, KeyState, KeyboardEvent, Modifiers};
use keyboard_types::{Key, KeyState, Modifiers};
use log::{debug, error, info, trace, warn};
use media::WindowGLContext;
use net_traits::pub_domains::reg_host;
Expand Down Expand Up @@ -3022,13 +3022,13 @@ where
}

fn update_active_keybord_modifiers(&mut self, event: &KeyboardEvent) {
self.active_keyboard_modifiers = event.modifiers;
self.active_keyboard_modifiers = event.event.modifiers;

// `KeyboardEvent::modifiers` contains the pre-existing modifiers before this key was
// either pressed or released, but `active_keyboard_modifiers` should track the subsequent
// state. If this event will update that state, we need to ensure that we are tracking what
// the event changes.
let modified_modifier = match event.key {
let modified_modifier = match event.event.key {
Key::Alt => Modifiers::ALT,
Key::AltGraph => Modifiers::ALT_GRAPH,
Key::CapsLock => Modifiers::CAPS_LOCK,
Expand All @@ -3047,7 +3047,7 @@ where
Key::Super => Modifiers::META,
_ => return,
};
match event.state {
match event.event.state {
KeyState::Down => self.active_keyboard_modifiers.insert(modified_modifier),
KeyState::Up => self.active_keyboard_modifiers.remove(modified_modifier),
}
Expand Down Expand Up @@ -4828,7 +4828,7 @@ where
pressed_mouse_buttons: self.pressed_mouse_buttons,
active_keyboard_modifiers: event.modifiers,
hit_test_result: None,
event: InputEvent::Keyboard(event),
event: InputEvent::Keyboard(KeyboardEvent::new(event)),
},
WebDriverInputEvent::Composition(event) => ConstellationInputEvent {
pressed_mouse_buttons: self.pressed_mouse_buttons,
Expand All @@ -4843,7 +4843,14 @@ where
}
}
},
WebDriverCommandMsg::KeyboardAction(browsing_context_id, event) => {
WebDriverCommandMsg::KeyboardAction(
browsing_context_id,
key_event,
msg_id,
response_sender,
) => {
self.webdriver.input_command_response_sender = Some(response_sender);

let pipeline_id = match self.browsing_contexts.get(&browsing_context_id) {
Some(browsing_context) => browsing_context.pipeline_id,
None => {
Expand All @@ -4854,13 +4861,15 @@ where
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: event.modifiers,
active_keyboard_modifiers: key_event.modifiers,
hit_test_result: None,
event: InputEvent::Keyboard(event),
event,
},
);
if let Err(e) = event_loop.send(control_msg) {
Expand Down
42 changes: 21 additions & 21 deletions components/script/dom/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,7 @@ impl Document {
/// The entry point for all key processing for web content
pub(crate) fn dispatch_key_event(
&self,
keyboard_event: ::keyboard_types::KeyboardEvent,
keyboard_event: ::embedder_traits::KeyboardEvent,
can_gc: CanGc,
) {
let focused = self.get_focused_element();
Expand All @@ -2345,19 +2345,19 @@ impl Document {

let keyevent = KeyboardEvent::new(
&self.window,
DOMString::from(keyboard_event.state.to_string()),
DOMString::from(keyboard_event.event.state.to_string()),
true,
true,
Some(&self.window),
0,
keyboard_event.key.clone(),
DOMString::from(keyboard_event.code.to_string()),
keyboard_event.location as u32,
keyboard_event.repeat,
keyboard_event.is_composing,
keyboard_event.modifiers,
keyboard_event.event.key.clone(),
DOMString::from(keyboard_event.event.code.to_string()),
keyboard_event.event.location as u32,
keyboard_event.event.repeat,
keyboard_event.event.is_composing,
keyboard_event.event.modifiers,
0,
keyboard_event.key.legacy_keycode(),
keyboard_event.event.key.legacy_keycode(),
can_gc,
);
let event = keyevent.upcast::<Event>();
Expand All @@ -2368,9 +2368,9 @@ impl Document {
// it MUST prevent the respective beforeinput and input
// (and keypress if supported) events from being generated
// TODO: keypress should be deprecated and superceded by beforeinput
if keyboard_event.state == KeyState::Down &&
is_character_value_key(&(keyboard_event.key)) &&
!keyboard_event.is_composing &&
if keyboard_event.event.state == KeyState::Down &&
is_character_value_key(&(keyboard_event.event.key)) &&
!keyboard_event.event.is_composing &&
cancel_state != EventDefault::Prevented
{
// https://w3c.github.io/uievents/#keypress-event-order
Expand All @@ -2381,13 +2381,13 @@ impl Document {
true,
Some(&self.window),
0,
keyboard_event.key.clone(),
DOMString::from(keyboard_event.code.to_string()),
keyboard_event.location as u32,
keyboard_event.repeat,
keyboard_event.is_composing,
keyboard_event.modifiers,
keyboard_event.key.legacy_charcode(),
keyboard_event.event.key.clone(),
DOMString::from(keyboard_event.event.code.to_string()),
keyboard_event.event.location as u32,
keyboard_event.event.repeat,
keyboard_event.event.is_composing,
keyboard_event.event.modifiers,
keyboard_event.event.key.legacy_charcode(),
0,
can_gc,
);
Expand All @@ -2405,8 +2405,8 @@ impl Document {
// however *when* we do it is up to us.
// Here, we're dispatching it after the key event so the script has a chance to cancel it
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27337
if (keyboard_event.key == Key::Enter || keyboard_event.code == Code::Space) &&
keyboard_event.state == KeyState::Up
if (keyboard_event.event.key == Key::Enter || keyboard_event.event.code == Code::Space) &&
keyboard_event.event.state == KeyState::Up
{
if let Some(elem) = target.downcast::<Element>() {
elem.upcast::<Node>()
Expand Down
4 changes: 3 additions & 1 deletion components/servo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ use gleam::gl::RENDERER;
use ipc_channel::ipc::{self, IpcSender};
use ipc_channel::router::ROUTER;
use javascript_evaluator::JavaScriptEvaluator;
pub use keyboard_types::*;
pub use keyboard_types::{
Code, CompositionEvent, CompositionState, Key, KeyState, Location, Modifiers,
};
use layout::LayoutFactoryImpl;
use log::{Log, Metadata, Record, debug, warn};
use media::{GlApi, NativeDisplay, WindowGLContext};
Expand Down
7 changes: 3 additions & 4 deletions components/servo/webview_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ use base::id::PipelineId;
use constellation_traits::EmbedderToConstellationMessage;
use embedder_traits::{
AllowOrDeny, AuthenticationResponse, ContextMenuResult, Cursor, FilterPattern,
GamepadHapticEffectType, InputMethodType, LoadStatus, MediaSessionEvent, Notification,
PermissionFeature, RgbColor, ScreenGeometry, SelectElementOptionOrOptgroup, SimpleDialog,
WebResourceRequest, WebResourceResponse, WebResourceResponseMsg,
GamepadHapticEffectType, InputMethodType, KeyboardEvent, LoadStatus, MediaSessionEvent,
Notification, PermissionFeature, RgbColor, ScreenGeometry, SelectElementOptionOrOptgroup,
SimpleDialog, WebResourceRequest, WebResourceResponse, WebResourceResponseMsg,
};
use ipc_channel::ipc::IpcSender;
use keyboard_types::KeyboardEvent;
use serde::Serialize;
use url::Url;
use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize};
Expand Down
53 changes: 50 additions & 3 deletions components/shared/embedder/input_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use keyboard_types::{CompositionEvent, KeyboardEvent};
use keyboard_types::{Code, CompositionEvent, Key, KeyState, Location, Modifiers};
use log::error;
use malloc_size_of_derive::MallocSizeOf;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -50,7 +50,7 @@ impl InputEvent {
InputEvent::EditingAction(..) => None,
InputEvent::Gamepad(..) => None,
InputEvent::Ime(..) => None,
InputEvent::Keyboard(..) => None,
InputEvent::Keyboard(event) => event.webdriver_id,
InputEvent::MouseButton(event) => event.webdriver_id,
InputEvent::MouseMove(event) => event.webdriver_id,
InputEvent::Touch(..) => None,
Expand All @@ -63,7 +63,9 @@ impl InputEvent {
InputEvent::EditingAction(..) => {},
InputEvent::Gamepad(..) => {},
InputEvent::Ime(..) => {},
InputEvent::Keyboard(..) => {},
InputEvent::Keyboard(ref mut event) => {
event.webdriver_id = webdriver_id;
},
InputEvent::MouseButton(ref mut event) => {
event.webdriver_id = webdriver_id;
},
Expand All @@ -80,6 +82,51 @@ impl InputEvent {
}
}

/// Recreate KeyboardEvent from keyboard_types to pair it with webdriver_id,
/// which is used for webdriver action synchronization.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct KeyboardEvent {
pub event: ::keyboard_types::KeyboardEvent,
webdriver_id: Option<WebDriverMessageId>,
}

impl KeyboardEvent {
pub fn new(keyboard_event: ::keyboard_types::KeyboardEvent) -> Self {
Self {
event: keyboard_event,
webdriver_id: None,
}
}

pub fn new_without_event(
state: KeyState,
key: Key,
code: Code,
location: Location,
modifiers: Modifiers,
repeat: bool,
is_composing: bool,
) -> Self {
Self::new(::keyboard_types::KeyboardEvent {
state,
key,
code,
location,
modifiers,
repeat,
is_composing,
})
}

pub fn from_state_and_key(state: KeyState, key: Key) -> Self {
Self::new(::keyboard_types::KeyboardEvent {
state,
key,
..::keyboard_types::KeyboardEvent::default()
})
}
}

#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct MouseButtonEvent {
pub action: MouseButtonAction,
Expand Down
1 change: 0 additions & 1 deletion components/shared/embedder/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crossbeam_channel::Sender;
use euclid::{Scale, Size2D};
use http::{HeaderMap, Method, StatusCode};
use ipc_channel::ipc::IpcSender;
pub use keyboard_types::{KeyboardEvent, Modifiers};
use log::warn;
use malloc_size_of::malloc_size_of_is_0;
use malloc_size_of_derive::MallocSizeOf;
Expand Down
8 changes: 7 additions & 1 deletion components/shared/embedder/webdriver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ pub enum WebDriverCommandMsg {
/// Act as if keys were pressed in the browsing context with the given ID.
SendKeys(BrowsingContextId, Vec<WebDriverInputEvent>),
/// Act as if keys were pressed or release in the browsing context with the given ID.
KeyboardAction(BrowsingContextId, KeyboardEvent),
KeyboardAction(
BrowsingContextId,
KeyboardEvent,
// Should never be None.
Option<WebDriverMessageId>,
IpcSender<WebDriverCommandResponse>,
),
/// Act as if the mouse was clicked in the browsing context with the given ID.
MouseButtonAction(
WebViewId,
Expand Down
Loading