mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Auto merge of #22173 - pyfisch:webdriver-keys, r=paulrouget
Use keyboard-types::webdriver::send_keys This improves the quality of KeyboardEvents sent by WebDriver. Now key, code, location and modifiers are set according to spec. CompositionEvents are discarded as servo does not handle them at all. CompositionEvent support can be added later. Is there a good way to automatically test this? <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22173) <!-- Reviewable:end -->
This commit is contained in:
commit
b1a2b6b5bf
12 changed files with 30 additions and 130 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
@ -512,7 +512,7 @@ dependencies = [
|
|||
"gleam 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"image 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipc-channel 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.2-servo (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
|
@ -549,7 +549,7 @@ dependencies = [
|
|||
"gfx_traits 0.0.1",
|
||||
"http 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipc-channel 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.2-servo (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"layout_traits 0.0.1",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"metrics 0.0.1",
|
||||
|
@ -943,7 +943,7 @@ name = "embedder_traits"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"ipc-channel 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.2-servo (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
|
@ -1898,11 +1898,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "keyboard-types"
|
||||
version = "0.4.2-servo"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2211,7 +2212,7 @@ dependencies = [
|
|||
"hashglobe 0.1.0",
|
||||
"hyper 0.12.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper_serde 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.2-servo (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mozjs 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"selectors 0.20.0",
|
||||
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3201,7 +3202,7 @@ dependencies = [
|
|||
"ipc-channel 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jstraceable_derive 0.0.1",
|
||||
"keyboard-types 0.4.2-servo (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -3305,7 +3306,7 @@ name = "script_tests"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"euclid 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.2-servo (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"script 0.0.1",
|
||||
"servo_url 0.0.1",
|
||||
]
|
||||
|
@ -3325,7 +3326,7 @@ dependencies = [
|
|||
"hyper 0.12.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper_serde 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipc-channel 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.2-servo (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"malloc_size_of 0.0.1",
|
||||
"malloc_size_of_derive 0.0.1",
|
||||
|
@ -3409,7 +3410,7 @@ dependencies = [
|
|||
"gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gleam 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glutin 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.2-servo (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libservo 0.0.1",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -4458,7 +4459,7 @@ dependencies = [
|
|||
"hyper 0.12.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"image 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipc-channel 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.2-servo (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"keyboard-types 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
"net_traits 0.0.1",
|
||||
|
@ -4903,7 +4904,7 @@ dependencies = [
|
|||
"checksum jni-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
|
||||
"checksum jpeg-decoder 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "0dfe27a6c0dabd772d0f9b9f8701c4ca12c4d1eebcadf2be1f6f70396f6a1434"
|
||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum keyboard-types 0.4.2-servo (registry+https://github.com/rust-lang/crates.io-index)" = "75082c134a78e0fc2232d2f30bf3dfdea1cd28591846b85a73b4b46cd776b482"
|
||||
"checksum keyboard-types 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "823bf0e5ec01b80424a318e79a0d1375725281acf311c47543ab3413f704dc25"
|
||||
"checksum khronos_api 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9ef23fcc4059260c5936f638c9805ebfc87cb172fa6661d130cba7f97d58f55"
|
||||
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
|
||||
"checksum lazycell 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d33a48d0365c96081958cc663eef834975cb1e8d8bea3378513fc72bdbf11e50"
|
||||
|
|
|
@ -22,7 +22,7 @@ gleam = {version = "0.6", optional = true}
|
|||
image = "0.19"
|
||||
ipc-channel = "0.11"
|
||||
libc = "0.2"
|
||||
keyboard-types = {version = "0.4.2-servo", features = ["serde"]}
|
||||
keyboard-types = "0.4.3"
|
||||
log = "0.4"
|
||||
msg = {path = "../msg"}
|
||||
net_traits = {path = "../net_traits"}
|
||||
|
|
|
@ -26,7 +26,7 @@ gfx_traits = {path = "../gfx_traits"}
|
|||
http = "0.1"
|
||||
ipc-channel = "0.11"
|
||||
layout_traits = {path = "../layout_traits"}
|
||||
keyboard-types = {version = "0.4.2-servo", features = ["serde"]}
|
||||
keyboard-types = "0.4.3"
|
||||
log = "0.4"
|
||||
metrics = {path = "../metrics"}
|
||||
msg = {path = "../msg"}
|
||||
|
|
|
@ -12,7 +12,7 @@ path = "lib.rs"
|
|||
|
||||
[dependencies]
|
||||
ipc-channel = "0.11"
|
||||
keyboard-types = {version = "0.4.2-servo", features = ["serde"]}
|
||||
keyboard-types = "0.4.3"
|
||||
lazy_static = "1"
|
||||
log = "0.4"
|
||||
msg = {path = "../msg"}
|
||||
|
|
|
@ -31,7 +31,7 @@ euclid = "0.19"
|
|||
hashglobe = { path = "../hashglobe" }
|
||||
hyper = { version = "0.12", optional = true }
|
||||
hyper_serde = { version = "0.9", optional = true }
|
||||
keyboard-types = {version = "0.4.2-servo", features = ["serde"], optional = true}
|
||||
keyboard-types = {version = "0.4.3", optional = true}
|
||||
mozjs = { version = "0.9.3", optional = true }
|
||||
selectors = { path = "../selectors" }
|
||||
serde = { version = "1.0.27", optional = true }
|
||||
|
|
|
@ -65,7 +65,7 @@ ipc-channel = "0.11"
|
|||
itertools = "0.7.6"
|
||||
js = {package = "mozjs", version = "0.9.3"}
|
||||
jstraceable_derive = {path = "../jstraceable_derive"}
|
||||
keyboard-types = {version = "0.4.2-servo", features = ["serde"]}
|
||||
keyboard-types = "0.4.3"
|
||||
lazy_static = "1"
|
||||
libc = "0.2"
|
||||
log = "0.4"
|
||||
|
|
|
@ -22,7 +22,7 @@ http = "0.1"
|
|||
hyper = "0.12"
|
||||
hyper_serde = "0.9"
|
||||
ipc-channel = "0.11"
|
||||
keyboard-types = {version = "0.4.2-servo", features = ["serde"]}
|
||||
keyboard-types = "0.4.3"
|
||||
libc = "0.2"
|
||||
malloc_size_of = { path = "../malloc_size_of" }
|
||||
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
|
||||
|
|
|
@ -17,7 +17,7 @@ euclid = "0.19"
|
|||
hyper = "0.12"
|
||||
image = "0.19"
|
||||
ipc-channel = "0.11"
|
||||
keyboard-types = {version = "0.4.2-servo", features = ["serde"]}
|
||||
keyboard-types = "0.4.3"
|
||||
log = "0.4"
|
||||
msg = {path = "../msg"}
|
||||
net_traits = {path = "../net_traits"}
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use keyboard_types::{Key, KeyboardEvent};
|
||||
|
||||
// spec: https://w3c.github.io/webdriver/#keyboard-actions
|
||||
// normalised (sic) as in british spelling
|
||||
fn get_normalised_key_value(key: char) -> Key {
|
||||
match key {
|
||||
'\u{E000}' => Key::Unidentified,
|
||||
'\u{E001}' => Key::Cancel,
|
||||
'\u{E002}' => Key::Help,
|
||||
'\u{E003}' => Key::Backspace,
|
||||
'\u{E004}' => Key::Tab,
|
||||
'\u{E005}' => Key::Clear,
|
||||
// FIXME(pyfisch): spec says "Return"
|
||||
'\u{E006}' => Key::Enter,
|
||||
'\u{E007}' => Key::Enter,
|
||||
'\u{E008}' => Key::Shift,
|
||||
'\u{E009}' => Key::Control,
|
||||
'\u{E00A}' => Key::Alt,
|
||||
'\u{E00B}' => Key::Pause,
|
||||
'\u{E00C}' => Key::Escape,
|
||||
'\u{E00D}' => Key::Character(" ".to_string()),
|
||||
'\u{E00E}' => Key::PageUp,
|
||||
'\u{E00F}' => Key::PageDown,
|
||||
'\u{E010}' => Key::End,
|
||||
'\u{E011}' => Key::Home,
|
||||
'\u{E012}' => Key::ArrowLeft,
|
||||
'\u{E013}' => Key::ArrowUp,
|
||||
'\u{E014}' => Key::ArrowRight,
|
||||
'\u{E015}' => Key::ArrowDown,
|
||||
'\u{E016}' => Key::Insert,
|
||||
'\u{E017}' => Key::Delete,
|
||||
'\u{E018}' => Key::Character(";".to_string()),
|
||||
'\u{E019}' => Key::Character("=".to_string()),
|
||||
'\u{E01A}' => Key::Character("0".to_string()),
|
||||
'\u{E01B}' => Key::Character("1".to_string()),
|
||||
'\u{E01C}' => Key::Character("2".to_string()),
|
||||
'\u{E01D}' => Key::Character("3".to_string()),
|
||||
'\u{E01E}' => Key::Character("4".to_string()),
|
||||
'\u{E01F}' => Key::Character("5".to_string()),
|
||||
'\u{E020}' => Key::Character("6".to_string()),
|
||||
'\u{E021}' => Key::Character("7".to_string()),
|
||||
'\u{E022}' => Key::Character("8".to_string()),
|
||||
'\u{E023}' => Key::Character("9".to_string()),
|
||||
'\u{E024}' => Key::Character("*".to_string()),
|
||||
'\u{E025}' => Key::Character("+".to_string()),
|
||||
'\u{E026}' => Key::Character(",".to_string()),
|
||||
'\u{E027}' => Key::Character("-".to_string()),
|
||||
'\u{E028}' => Key::Character(".".to_string()),
|
||||
'\u{E029}' => Key::Character("/".to_string()),
|
||||
'\u{E031}' => Key::F1,
|
||||
'\u{E032}' => Key::F2,
|
||||
'\u{E033}' => Key::F3,
|
||||
'\u{E034}' => Key::F4,
|
||||
'\u{E035}' => Key::F5,
|
||||
'\u{E036}' => Key::F6,
|
||||
'\u{E037}' => Key::F7,
|
||||
'\u{E038}' => Key::F8,
|
||||
'\u{E039}' => Key::F9,
|
||||
'\u{E03A}' => Key::F10,
|
||||
'\u{E03B}' => Key::F11,
|
||||
'\u{E03C}' => Key::F12,
|
||||
'\u{E03D}' => Key::Meta,
|
||||
'\u{E040}' => Key::ZenkakuHankaku,
|
||||
'\u{E050}' => Key::Shift,
|
||||
'\u{E051}' => Key::Control,
|
||||
'\u{E052}' => Key::Alt,
|
||||
'\u{E053}' => Key::Meta,
|
||||
'\u{E054}' => Key::PageUp,
|
||||
'\u{E055}' => Key::PageDown,
|
||||
'\u{E056}' => Key::End,
|
||||
'\u{E057}' => Key::Home,
|
||||
'\u{E058}' => Key::ArrowLeft,
|
||||
'\u{E059}' => Key::ArrowUp,
|
||||
'\u{E05A}' => Key::ArrowRight,
|
||||
'\u{E05B}' => Key::ArrowDown,
|
||||
'\u{E05C}' => Key::Insert,
|
||||
'\u{E05D}' => Key::Delete,
|
||||
_ => Key::Character(key.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn keycodes_to_keys(key_codes: &str) -> Vec<KeyboardEvent> {
|
||||
let mut rv = vec![];
|
||||
|
||||
for char_code in key_codes.chars() {
|
||||
// TODO(pyfisch): compute code, location, modifiers according to spec
|
||||
let key = get_normalised_key_value(char_code);
|
||||
let mut event = KeyboardEvent {
|
||||
state: ::keyboard_types::KeyState::Down,
|
||||
key,
|
||||
code: ::keyboard_types::Code::Unidentified,
|
||||
location: ::keyboard_types::Location::Standard,
|
||||
modifiers: ::keyboard_types::Modifiers::empty(),
|
||||
repeat: false,
|
||||
is_composing: false,
|
||||
};
|
||||
rv.push(event.clone());
|
||||
event.state = ::keyboard_types::KeyState::Up;
|
||||
rv.push(event);
|
||||
}
|
||||
rv
|
||||
}
|
|
@ -11,14 +11,12 @@ extern crate log;
|
|||
#[macro_use]
|
||||
extern crate serde;
|
||||
|
||||
mod keys;
|
||||
|
||||
use base64;
|
||||
use crate::keys::keycodes_to_keys;
|
||||
use euclid::TypedSize2D;
|
||||
use hyper::Method;
|
||||
use image::{DynamicImage, ImageFormat, RgbImage};
|
||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||
use keyboard_types::webdriver::{send_keys, Event as KeyEvent};
|
||||
use msg::constellation_msg::{BrowsingContextId, TopLevelBrowsingContextId, TraversalDirection};
|
||||
use net_traits::image::base::PixelFormat;
|
||||
use regex::Captures;
|
||||
|
@ -1038,7 +1036,14 @@ impl Handler {
|
|||
))
|
||||
})?;
|
||||
|
||||
let keys = keycodes_to_keys(&keys.text);
|
||||
// FIXME: Don't discard composition events.
|
||||
let keys = send_keys(&keys.text)
|
||||
.drain(..)
|
||||
.filter_map(|event| match event {
|
||||
KeyEvent::Keyboard(v) => Some(v),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
|
||||
// TODO: there's a race condition caused by the focus command and the
|
||||
// send keys command being two separate messages,
|
||||
|
|
|
@ -45,7 +45,7 @@ crossbeam-channel = "0.2"
|
|||
euclid = "0.19"
|
||||
gleam = "0.6"
|
||||
glutin = "0.18"
|
||||
keyboard-types = {version = "0.4.2-servo", features = ["serde"]}
|
||||
keyboard-types = "0.4.3"
|
||||
lazy_static = "1"
|
||||
libservo = {path = "../../components/servo"}
|
||||
log = "0.4"
|
||||
|
|
|
@ -11,6 +11,6 @@ path = "lib.rs"
|
|||
|
||||
[dependencies]
|
||||
euclid = "0.19"
|
||||
keyboard-types = "0.4.2-servo"
|
||||
keyboard-types = "0.4.3"
|
||||
script = {path = "../../../components/script"}
|
||||
servo_url = {path = "../../../components/url"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue