Small key utils refactor

This commit is contained in:
Dzmitry Malyshau 2018-04-18 22:45:08 -04:00
parent 7fa295d8e6
commit 7af725bff0
3 changed files with 101 additions and 98 deletions

View file

@ -22,6 +22,7 @@ matrix:
- curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain none -y - curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain none -y
- source ~/.profile - source ~/.profile
script: script:
# see https://github.com/servo/servo/issues/20664
#- ./mach cargo check -p compositing --no-default-features #- ./mach cargo check -p compositing --no-default-features
- ./mach build -d --verbose - ./mach build -d --verbose
- ./mach test-unit - ./mach test-unit

View file

@ -60,6 +60,7 @@ install:
build_script: build_script:
- mach clean-nightlies --keep 2 --force - mach clean-nightlies --keep 2 --force
# see https://github.com/servo/servo/issues/20664
#- mach cargo check -p compositing --no-default-features #- mach cargo check -p compositing --no-default-features
- mach build -d -v - mach build -d -v
- mach test-unit - mach test-unit

View file

@ -132,114 +132,115 @@ pub fn char_to_script_key(c: char) -> Option<constellation_msg::Key> {
} }
pub fn winit_key_to_script_key(key: VirtualKeyCode) -> Result<constellation_msg::Key, ()> { pub fn winit_key_to_script_key(key: VirtualKeyCode) -> Result<constellation_msg::Key, ()> {
use winit::VirtualKeyCode::*;
// TODO(negge): add more key mappings // TODO(negge): add more key mappings
match key { Ok(match key {
VirtualKeyCode::A => Ok(Key::A), A => Key::A,
VirtualKeyCode::B => Ok(Key::B), B => Key::B,
VirtualKeyCode::C => Ok(Key::C), C => Key::C,
VirtualKeyCode::D => Ok(Key::D), D => Key::D,
VirtualKeyCode::E => Ok(Key::E), E => Key::E,
VirtualKeyCode::F => Ok(Key::F), F => Key::F,
VirtualKeyCode::G => Ok(Key::G), G => Key::G,
VirtualKeyCode::H => Ok(Key::H), H => Key::H,
VirtualKeyCode::I => Ok(Key::I), I => Key::I,
VirtualKeyCode::J => Ok(Key::J), J => Key::J,
VirtualKeyCode::K => Ok(Key::K), K => Key::K,
VirtualKeyCode::L => Ok(Key::L), L => Key::L,
VirtualKeyCode::M => Ok(Key::M), M => Key::M,
VirtualKeyCode::N => Ok(Key::N), N => Key::N,
VirtualKeyCode::O => Ok(Key::O), O => Key::O,
VirtualKeyCode::P => Ok(Key::P), P => Key::P,
VirtualKeyCode::Q => Ok(Key::Q), Q => Key::Q,
VirtualKeyCode::R => Ok(Key::R), R => Key::R,
VirtualKeyCode::S => Ok(Key::S), S => Key::S,
VirtualKeyCode::T => Ok(Key::T), T => Key::T,
VirtualKeyCode::U => Ok(Key::U), U => Key::U,
VirtualKeyCode::V => Ok(Key::V), V => Key::V,
VirtualKeyCode::W => Ok(Key::W), W => Key::W,
VirtualKeyCode::X => Ok(Key::X), X => Key::X,
VirtualKeyCode::Y => Ok(Key::Y), Y => Key::Y,
VirtualKeyCode::Z => Ok(Key::Z), Z => Key::Z,
VirtualKeyCode::Numpad0 => Ok(Key::Kp0), Numpad0 => Key::Kp0,
VirtualKeyCode::Numpad1 => Ok(Key::Kp1), Numpad1 => Key::Kp1,
VirtualKeyCode::Numpad2 => Ok(Key::Kp2), Numpad2 => Key::Kp2,
VirtualKeyCode::Numpad3 => Ok(Key::Kp3), Numpad3 => Key::Kp3,
VirtualKeyCode::Numpad4 => Ok(Key::Kp4), Numpad4 => Key::Kp4,
VirtualKeyCode::Numpad5 => Ok(Key::Kp5), Numpad5 => Key::Kp5,
VirtualKeyCode::Numpad6 => Ok(Key::Kp6), Numpad6 => Key::Kp6,
VirtualKeyCode::Numpad7 => Ok(Key::Kp7), Numpad7 => Key::Kp7,
VirtualKeyCode::Numpad8 => Ok(Key::Kp8), Numpad8 => Key::Kp8,
VirtualKeyCode::Numpad9 => Ok(Key::Kp9), Numpad9 => Key::Kp9,
VirtualKeyCode::Key0 => Ok(Key::Num0), Key0 => Key::Num0,
VirtualKeyCode::Key1 => Ok(Key::Num1), Key1 => Key::Num1,
VirtualKeyCode::Key2 => Ok(Key::Num2), Key2 => Key::Num2,
VirtualKeyCode::Key3 => Ok(Key::Num3), Key3 => Key::Num3,
VirtualKeyCode::Key4 => Ok(Key::Num4), Key4 => Key::Num4,
VirtualKeyCode::Key5 => Ok(Key::Num5), Key5 => Key::Num5,
VirtualKeyCode::Key6 => Ok(Key::Num6), Key6 => Key::Num6,
VirtualKeyCode::Key7 => Ok(Key::Num7), Key7 => Key::Num7,
VirtualKeyCode::Key8 => Ok(Key::Num8), Key8 => Key::Num8,
VirtualKeyCode::Key9 => Ok(Key::Num9), Key9 => Key::Num9,
VirtualKeyCode::Return => Ok(Key::Enter), Return => Key::Enter,
VirtualKeyCode::Space => Ok(Key::Space), Space => Key::Space,
VirtualKeyCode::Escape => Ok(Key::Escape), Escape => Key::Escape,
VirtualKeyCode::Equals => Ok(Key::Equal), Equals => Key::Equal,
VirtualKeyCode::Minus => Ok(Key::Minus), Minus => Key::Minus,
VirtualKeyCode::Back => Ok(Key::Backspace), Back => Key::Backspace,
VirtualKeyCode::PageDown => Ok(Key::PageDown), PageDown => Key::PageDown,
VirtualKeyCode::PageUp => Ok(Key::PageUp), PageUp => Key::PageUp,
VirtualKeyCode::Insert => Ok(Key::Insert), Insert => Key::Insert,
VirtualKeyCode::Home => Ok(Key::Home), Home => Key::Home,
VirtualKeyCode::Delete => Ok(Key::Delete), Delete => Key::Delete,
VirtualKeyCode::End => Ok(Key::End), End => Key::End,
VirtualKeyCode::Left => Ok(Key::Left), Left => Key::Left,
VirtualKeyCode::Up => Ok(Key::Up), Up => Key::Up,
VirtualKeyCode::Right => Ok(Key::Right), Right => Key::Right,
VirtualKeyCode::Down => Ok(Key::Down), Down => Key::Down,
VirtualKeyCode::LShift => Ok(Key::LeftShift), LShift => Key::LeftShift,
VirtualKeyCode::LControl => Ok(Key::LeftControl), LControl => Key::LeftControl,
VirtualKeyCode::LAlt => Ok(Key::LeftAlt), LAlt => Key::LeftAlt,
VirtualKeyCode::LWin => Ok(Key::LeftSuper), LWin => Key::LeftSuper,
VirtualKeyCode::RShift => Ok(Key::RightShift), RShift => Key::RightShift,
VirtualKeyCode::RControl => Ok(Key::RightControl), RControl => Key::RightControl,
VirtualKeyCode::RAlt => Ok(Key::RightAlt), RAlt => Key::RightAlt,
VirtualKeyCode::RWin => Ok(Key::RightSuper), RWin => Key::RightSuper,
VirtualKeyCode::Apostrophe => Ok(Key::Apostrophe), Apostrophe => Key::Apostrophe,
VirtualKeyCode::Backslash => Ok(Key::Backslash), Backslash => Key::Backslash,
VirtualKeyCode::Comma => Ok(Key::Comma), Comma => Key::Comma,
VirtualKeyCode::Grave => Ok(Key::GraveAccent), Grave => Key::GraveAccent,
VirtualKeyCode::LBracket => Ok(Key::LeftBracket), LBracket => Key::LeftBracket,
VirtualKeyCode::Period => Ok(Key::Period), Period => Key::Period,
VirtualKeyCode::RBracket => Ok(Key::RightBracket), RBracket => Key::RightBracket,
VirtualKeyCode::Semicolon => Ok(Key::Semicolon), Semicolon => Key::Semicolon,
VirtualKeyCode::Slash => Ok(Key::Slash), Slash => Key::Slash,
VirtualKeyCode::Tab => Ok(Key::Tab), Tab => Key::Tab,
VirtualKeyCode::Subtract => Ok(Key::Minus), Subtract => Key::Minus,
VirtualKeyCode::F1 => Ok(Key::F1), F1 => Key::F1,
VirtualKeyCode::F2 => Ok(Key::F2), F2 => Key::F2,
VirtualKeyCode::F3 => Ok(Key::F3), F3 => Key::F3,
VirtualKeyCode::F4 => Ok(Key::F4), F4 => Key::F4,
VirtualKeyCode::F5 => Ok(Key::F5), F5 => Key::F5,
VirtualKeyCode::F6 => Ok(Key::F6), F6 => Key::F6,
VirtualKeyCode::F7 => Ok(Key::F7), F7 => Key::F7,
VirtualKeyCode::F8 => Ok(Key::F8), F8 => Key::F8,
VirtualKeyCode::F9 => Ok(Key::F9), F9 => Key::F9,
VirtualKeyCode::F10 => Ok(Key::F10), F10 => Key::F10,
VirtualKeyCode::F11 => Ok(Key::F11), F11 => Key::F11,
VirtualKeyCode::F12 => Ok(Key::F12), F12 => Key::F12,
VirtualKeyCode::NavigateBackward => Ok(Key::NavigateBackward), NavigateBackward => Key::NavigateBackward,
VirtualKeyCode::NavigateForward => Ok(Key::NavigateForward), NavigateForward => Key::NavigateForward,
_ => Err(()), _ => return Err(()),
} })
} }
pub fn winit_mods_to_script_mods(modifiers: WinitKeyModifiers) -> constellation_msg::KeyModifiers { pub fn winit_mods_to_script_mods(modifiers: WinitKeyModifiers) -> constellation_msg::KeyModifiers {