mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Change the dispatch in TextInput::handle_keydown_aux match on enum values instead of strings.
This commit is contained in:
parent
29f8306089
commit
0587717944
2 changed files with 203 additions and 193 deletions
|
@ -109,16 +109,11 @@ impl KeyboardEvent {
|
|||
pub fn Constructor(global: GlobalRef,
|
||||
type_: DOMString,
|
||||
init: &KeyboardEventBinding::KeyboardEventInit) -> Fallible<Temporary<KeyboardEvent>> {
|
||||
let key = if let Some((key, _)) = key_from_string(init.key.as_slice()) {
|
||||
Some(key)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let event = KeyboardEvent::new(global.as_window(), type_,
|
||||
init.parent.parent.parent.bubbles,
|
||||
init.parent.parent.parent.cancelable,
|
||||
init.parent.parent.view.r(),
|
||||
init.parent.parent.detail, key,
|
||||
init.parent.parent.detail, key_from_string(&init.key, init.location),
|
||||
init.key.clone(), init.code.clone(), init.location,
|
||||
init.repeat, init.isComposing, init.parent.ctrlKey,
|
||||
init.parent.altKey, init.parent.shiftKey, init.parent.metaKey,
|
||||
|
@ -341,175 +336,173 @@ pub fn key_value(key: Key, mods: KeyModifiers) -> &'static str {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn key_from_string(key_string: &str) -> Option<(Key, KeyModifiers)> {
|
||||
fn key_from_string(key_string: &str, location: u32) -> Option<Key> {
|
||||
match key_string {
|
||||
" " => Some((Key::Space, KeyModifiers::empty())),
|
||||
"\"" => Some((Key::Apostrophe, SHIFT)),
|
||||
"'" => Some((Key::Apostrophe, KeyModifiers::empty())),
|
||||
"<" => Some((Key::Comma, SHIFT)),
|
||||
"," => Some((Key::Comma, KeyModifiers::empty())),
|
||||
"_" => Some((Key::Minus, SHIFT)),
|
||||
"-" => Some((Key::Minus, KeyModifiers::empty())),
|
||||
">" => Some((Key::Period, SHIFT)),
|
||||
"." => Some((Key::Period, KeyModifiers::empty())),
|
||||
"?" => Some((Key::Slash, SHIFT)),
|
||||
"/" => Some((Key::Slash, KeyModifiers::empty())),
|
||||
"~" => Some((Key::GraveAccent, SHIFT)),
|
||||
"`" => Some((Key::GraveAccent, KeyModifiers::empty())),
|
||||
")" => Some((Key::Num0, SHIFT)),
|
||||
"0" => Some((Key::Num0, KeyModifiers::empty())),
|
||||
"!" => Some((Key::Num1, SHIFT)),
|
||||
"1" => Some((Key::Num1, KeyModifiers::empty())),
|
||||
"@" => Some((Key::Num2, SHIFT)),
|
||||
"2" => Some((Key::Num2, KeyModifiers::empty())),
|
||||
"#" => Some((Key::Num3, SHIFT)),
|
||||
"3" => Some((Key::Num3, KeyModifiers::empty())),
|
||||
"$" => Some((Key::Num4, SHIFT)),
|
||||
"4" => Some((Key::Num4, KeyModifiers::empty())),
|
||||
"%" => Some((Key::Num5, SHIFT)),
|
||||
"5" => Some((Key::Num5, KeyModifiers::empty())),
|
||||
"^" => Some((Key::Num6, SHIFT)),
|
||||
"6" => Some((Key::Num6, KeyModifiers::empty())),
|
||||
"&" => Some((Key::Num7, SHIFT)),
|
||||
"7" => Some((Key::Num7, KeyModifiers::empty())),
|
||||
"*" => Some((Key::Num8, SHIFT)),
|
||||
"8" => Some((Key::Num8, KeyModifiers::empty())),
|
||||
"(" => Some((Key::Num9, SHIFT)),
|
||||
"9" => Some((Key::Num9, KeyModifiers::empty())),
|
||||
":" => Some((Key::Semicolon, SHIFT)),
|
||||
";" => Some((Key::Semicolon, KeyModifiers::empty())),
|
||||
"+" => Some((Key::Equal, SHIFT)),
|
||||
"=" => Some((Key::Equal, KeyModifiers::empty())),
|
||||
"A" => Some((Key::A, SHIFT)),
|
||||
"a" => Some((Key::A, KeyModifiers::empty())),
|
||||
"B" => Some((Key::B, SHIFT)),
|
||||
"b" => Some((Key::B, KeyModifiers::empty())),
|
||||
"C" => Some((Key::C, SHIFT)),
|
||||
"c" => Some((Key::C, KeyModifiers::empty())),
|
||||
"D" => Some((Key::D, SHIFT)),
|
||||
"d" => Some((Key::D, KeyModifiers::empty())),
|
||||
"E" => Some((Key::E, SHIFT)),
|
||||
"e" => Some((Key::E, KeyModifiers::empty())),
|
||||
"F" => Some((Key::F, SHIFT)),
|
||||
"f" => Some((Key::F, KeyModifiers::empty())),
|
||||
"G" => Some((Key::G, SHIFT)),
|
||||
"g" => Some((Key::G, KeyModifiers::empty())),
|
||||
"H" => Some((Key::H, SHIFT)),
|
||||
"h" => Some((Key::H, KeyModifiers::empty())),
|
||||
"I" => Some((Key::I, SHIFT)),
|
||||
"i" => Some((Key::I, KeyModifiers::empty())),
|
||||
"J" => Some((Key::J, SHIFT)),
|
||||
"j" => Some((Key::J, KeyModifiers::empty())),
|
||||
"K" => Some((Key::K, SHIFT)),
|
||||
"k" => Some((Key::K, KeyModifiers::empty())),
|
||||
"L" => Some((Key::L, SHIFT)),
|
||||
"l" => Some((Key::L, KeyModifiers::empty())),
|
||||
"M" => Some((Key::M, SHIFT)),
|
||||
"m" => Some((Key::M, KeyModifiers::empty())),
|
||||
"N" => Some((Key::N, SHIFT)),
|
||||
"n" => Some((Key::N, KeyModifiers::empty())),
|
||||
"O" => Some((Key::O, SHIFT)),
|
||||
"o" => Some((Key::O, KeyModifiers::empty())),
|
||||
"P" => Some((Key::P, SHIFT)),
|
||||
"p" => Some((Key::P, KeyModifiers::empty())),
|
||||
"Q" => Some((Key::Q, SHIFT)),
|
||||
"q" => Some((Key::Q, KeyModifiers::empty())),
|
||||
"R" => Some((Key::R, SHIFT)),
|
||||
"r" => Some((Key::R, KeyModifiers::empty())),
|
||||
"S" => Some((Key::S, SHIFT)),
|
||||
"s" => Some((Key::S, KeyModifiers::empty())),
|
||||
"T" => Some((Key::T, SHIFT)),
|
||||
"t" => Some((Key::T, KeyModifiers::empty())),
|
||||
"U" => Some((Key::U, SHIFT)),
|
||||
"u" => Some((Key::U, KeyModifiers::empty())),
|
||||
"V" => Some((Key::V, SHIFT)),
|
||||
"v" => Some((Key::V, KeyModifiers::empty())),
|
||||
"W" => Some((Key::W, SHIFT)),
|
||||
"w" => Some((Key::W, KeyModifiers::empty())),
|
||||
"X" => Some((Key::X, SHIFT)),
|
||||
"x" => Some((Key::X, KeyModifiers::empty())),
|
||||
"Y" => Some((Key::Y, SHIFT)),
|
||||
"y" => Some((Key::Y, KeyModifiers::empty())),
|
||||
"Z" => Some((Key::Z, SHIFT)),
|
||||
"z" => Some((Key::Z, KeyModifiers::empty())),
|
||||
"{" => Some((Key::LeftBracket, SHIFT)),
|
||||
"[" => Some((Key::LeftBracket, KeyModifiers::empty())),
|
||||
"|" => Some((Key::Backslash, SHIFT)),
|
||||
"\\" => Some((Key::Backslash, KeyModifiers::empty())),
|
||||
"}" => Some((Key::RightBracket, SHIFT)),
|
||||
"]" => Some((Key::RightBracket, KeyModifiers::empty())),
|
||||
"Unidentified" => Some((Key::World1, KeyModifiers::empty())),
|
||||
/*"Unidentified" => Some((Key::World2, KeyModifiers::empty())),*/
|
||||
"Escape" => Some((Key::Escape, KeyModifiers::empty())),
|
||||
"Enter" => Some((Key::Enter, KeyModifiers::empty())),
|
||||
"Tab" => Some((Key::Tab, KeyModifiers::empty())),
|
||||
"Backspace" => Some((Key::Backspace, KeyModifiers::empty())),
|
||||
"Insert" => Some((Key::Insert, KeyModifiers::empty())),
|
||||
"Delete" => Some((Key::Delete, KeyModifiers::empty())),
|
||||
"ArrowRight" => Some((Key::Right, KeyModifiers::empty())),
|
||||
"ArrowLeft" => Some((Key::Left, KeyModifiers::empty())),
|
||||
"ArrowDown" => Some((Key::Down, KeyModifiers::empty())),
|
||||
"ArrowUp" => Some((Key::Up, KeyModifiers::empty())),
|
||||
"PageUp" => Some((Key::PageUp, KeyModifiers::empty())),
|
||||
"PageDown" => Some((Key::PageDown, KeyModifiers::empty())),
|
||||
"Home" => Some((Key::Home, KeyModifiers::empty())),
|
||||
"End" => Some((Key::End, KeyModifiers::empty())),
|
||||
"CapsLock" => Some((Key::CapsLock, KeyModifiers::empty())),
|
||||
"ScrollLock" => Some((Key::ScrollLock, KeyModifiers::empty())),
|
||||
"NumLock" => Some((Key::NumLock, KeyModifiers::empty())),
|
||||
"PrintScreen" => Some((Key::PrintScreen, KeyModifiers::empty())),
|
||||
"Pause" => Some((Key::Pause, KeyModifiers::empty())),
|
||||
"F1" => Some((Key::F1, KeyModifiers::empty())),
|
||||
"F2" => Some((Key::F2, KeyModifiers::empty())),
|
||||
"F3" => Some((Key::F3, KeyModifiers::empty())),
|
||||
"F4" => Some((Key::F4, KeyModifiers::empty())),
|
||||
"F5" => Some((Key::F5, KeyModifiers::empty())),
|
||||
"F6" => Some((Key::F6, KeyModifiers::empty())),
|
||||
"F7" => Some((Key::F7, KeyModifiers::empty())),
|
||||
"F8" => Some((Key::F8, KeyModifiers::empty())),
|
||||
"F9" => Some((Key::F9, KeyModifiers::empty())),
|
||||
"F10" => Some((Key::F10, KeyModifiers::empty())),
|
||||
"F11" => Some((Key::F11, KeyModifiers::empty())),
|
||||
"F12" => Some((Key::F12, KeyModifiers::empty())),
|
||||
"F13" => Some((Key::F13, KeyModifiers::empty())),
|
||||
"F14" => Some((Key::F14, KeyModifiers::empty())),
|
||||
"F15" => Some((Key::F15, KeyModifiers::empty())),
|
||||
"F16" => Some((Key::F16, KeyModifiers::empty())),
|
||||
"F17" => Some((Key::F17, KeyModifiers::empty())),
|
||||
"F18" => Some((Key::F18, KeyModifiers::empty())),
|
||||
"F19" => Some((Key::F19, KeyModifiers::empty())),
|
||||
"F20" => Some((Key::F20, KeyModifiers::empty())),
|
||||
"F21" => Some((Key::F21, KeyModifiers::empty())),
|
||||
"F22" => Some((Key::F22, KeyModifiers::empty())),
|
||||
"F23" => Some((Key::F23, KeyModifiers::empty())),
|
||||
"F24" => Some((Key::F24, KeyModifiers::empty())),
|
||||
"F25" => Some((Key::F25, KeyModifiers::empty())),
|
||||
/*"0" => Some((Key::Kp0, KeyModifiers::empty())),
|
||||
"1" => Some((Key::Kp1, KeyModifiers::empty())),
|
||||
"2" => Some((Key::Kp2, KeyModifiers::empty())),
|
||||
"3" => Some((Key::Kp3, KeyModifiers::empty())),
|
||||
"4" => Some((Key::Kp4, KeyModifiers::empty())),
|
||||
"5" => Some((Key::Kp5, KeyModifiers::empty())),
|
||||
"6" => Some((Key::Kp6, KeyModifiers::empty())),
|
||||
"7" => Some((Key::Kp7, KeyModifiers::empty())),
|
||||
"8" => Some((Key::Kp8, KeyModifiers::empty())),
|
||||
"9" => Some((Key::Kp9, KeyModifiers::empty())),
|
||||
"." => Some((Key::KpDecimal, KeyModifiers::empty())),
|
||||
"/" => Some((Key::KpDivide, KeyModifiers::empty())),
|
||||
"*" => Some((Key::KpMultiply, KeyModifiers::empty())),
|
||||
"-" => Some((Key::KpSubtract, KeyModifiers::empty())),
|
||||
"+" => Some((Key::KpAdd, KeyModifiers::empty())),
|
||||
"Enter" => Some((Key::KpEnter, KeyModifiers::empty())),
|
||||
"=" => Some((Key::KpEqual, KeyModifiers::empty())),*/
|
||||
"Shift" => Some((Key::LeftShift, SHIFT)),
|
||||
"Control" => Some((Key::LeftControl, CONTROL)),
|
||||
"Alt" => Some((Key::LeftAlt, ALT)),
|
||||
"Super" => Some((Key::LeftSuper, SUPER)),
|
||||
/*"Shift" => Some((Key::RightShift, SHIFT)),
|
||||
"Control" => Some((Key::RightControl, CONTROL)),
|
||||
"Alt" => Some((Key::RightAlt, ALT)),
|
||||
"Super" => Some((Key::RightSuper, SUPER)),*/
|
||||
"ContextMenu" => Some((Key::Menu, KeyModifiers::empty())),
|
||||
" " => Some(Key::Space),
|
||||
"\"" => Some(Key::Apostrophe),
|
||||
"'" => Some(Key::Apostrophe),
|
||||
"<" => Some(Key::Comma),
|
||||
"," => Some(Key::Comma),
|
||||
"_" => Some(Key::Minus),
|
||||
"-" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Minus),
|
||||
">" => Some(Key::Period),
|
||||
"." if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Period),
|
||||
"?" => Some(Key::Slash),
|
||||
"/" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Slash),
|
||||
"~" => Some(Key::GraveAccent),
|
||||
"`" => Some(Key::GraveAccent),
|
||||
")" => Some(Key::Num0),
|
||||
"0" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num0),
|
||||
"!" => Some(Key::Num1),
|
||||
"1" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num1),
|
||||
"@" => Some(Key::Num2),
|
||||
"2" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num2),
|
||||
"#" => Some(Key::Num3),
|
||||
"3" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num3),
|
||||
"$" => Some(Key::Num4),
|
||||
"4" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num4),
|
||||
"%" => Some(Key::Num5),
|
||||
"5" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num5),
|
||||
"^" => Some(Key::Num6),
|
||||
"6" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num6),
|
||||
"&" => Some(Key::Num7),
|
||||
"7" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num7),
|
||||
"*" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num8),
|
||||
"8" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num8),
|
||||
"(" => Some(Key::Num9),
|
||||
"9" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Num9),
|
||||
":" => Some(Key::Semicolon),
|
||||
";" => Some(Key::Semicolon),
|
||||
"+" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Equal),
|
||||
"=" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Equal),
|
||||
"A" => Some(Key::A),
|
||||
"a" => Some(Key::A),
|
||||
"B" => Some(Key::B),
|
||||
"b" => Some(Key::B),
|
||||
"C" => Some(Key::C),
|
||||
"c" => Some(Key::C),
|
||||
"D" => Some(Key::D),
|
||||
"d" => Some(Key::D),
|
||||
"E" => Some(Key::E),
|
||||
"e" => Some(Key::E),
|
||||
"F" => Some(Key::F),
|
||||
"f" => Some(Key::F),
|
||||
"G" => Some(Key::G),
|
||||
"g" => Some(Key::G),
|
||||
"H" => Some(Key::H),
|
||||
"h" => Some(Key::H),
|
||||
"I" => Some(Key::I),
|
||||
"i" => Some(Key::I),
|
||||
"J" => Some(Key::J),
|
||||
"j" => Some(Key::J),
|
||||
"K" => Some(Key::K),
|
||||
"k" => Some(Key::K),
|
||||
"L" => Some(Key::L),
|
||||
"l" => Some(Key::L),
|
||||
"M" => Some(Key::M),
|
||||
"m" => Some(Key::M),
|
||||
"N" => Some(Key::N),
|
||||
"n" => Some(Key::N),
|
||||
"O" => Some(Key::O),
|
||||
"o" => Some(Key::O),
|
||||
"P" => Some(Key::P),
|
||||
"p" => Some(Key::P),
|
||||
"Q" => Some(Key::Q),
|
||||
"q" => Some(Key::Q),
|
||||
"R" => Some(Key::R),
|
||||
"r" => Some(Key::R),
|
||||
"S" => Some(Key::S),
|
||||
"s" => Some(Key::S),
|
||||
"T" => Some(Key::T),
|
||||
"t" => Some(Key::T),
|
||||
"U" => Some(Key::U),
|
||||
"u" => Some(Key::U),
|
||||
"V" => Some(Key::V),
|
||||
"v" => Some(Key::V),
|
||||
"W" => Some(Key::W),
|
||||
"w" => Some(Key::W),
|
||||
"X" => Some(Key::X),
|
||||
"x" => Some(Key::X),
|
||||
"Y" => Some(Key::Y),
|
||||
"y" => Some(Key::Y),
|
||||
"Z" => Some(Key::Z),
|
||||
"z" => Some(Key::Z),
|
||||
"{" => Some(Key::LeftBracket),
|
||||
"[" => Some(Key::LeftBracket),
|
||||
"|" => Some(Key::Backslash),
|
||||
"\\" => Some(Key::Backslash),
|
||||
"}" => Some(Key::RightBracket),
|
||||
"]" => Some(Key::RightBracket),
|
||||
"Escape" => Some(Key::Escape),
|
||||
"Enter" if location == KeyboardEventConstants::DOM_KEY_LOCATION_STANDARD => Some(Key::Enter),
|
||||
"Tab" => Some(Key::Tab),
|
||||
"Backspace" => Some(Key::Backspace),
|
||||
"Insert" => Some(Key::Insert),
|
||||
"Delete" => Some(Key::Delete),
|
||||
"ArrowRight" => Some(Key::Right),
|
||||
"ArrowLeft" => Some(Key::Left),
|
||||
"ArrowDown" => Some(Key::Down),
|
||||
"ArrowUp" => Some(Key::Up),
|
||||
"PageUp" => Some(Key::PageUp),
|
||||
"PageDown" => Some(Key::PageDown),
|
||||
"Home" => Some(Key::Home),
|
||||
"End" => Some(Key::End),
|
||||
"CapsLock" => Some(Key::CapsLock),
|
||||
"ScrollLock" => Some(Key::ScrollLock),
|
||||
"NumLock" => Some(Key::NumLock),
|
||||
"PrintScreen" => Some(Key::PrintScreen),
|
||||
"Pause" => Some(Key::Pause),
|
||||
"F1" => Some(Key::F1),
|
||||
"F2" => Some(Key::F2),
|
||||
"F3" => Some(Key::F3),
|
||||
"F4" => Some(Key::F4),
|
||||
"F5" => Some(Key::F5),
|
||||
"F6" => Some(Key::F6),
|
||||
"F7" => Some(Key::F7),
|
||||
"F8" => Some(Key::F8),
|
||||
"F9" => Some(Key::F9),
|
||||
"F10" => Some(Key::F10),
|
||||
"F11" => Some(Key::F11),
|
||||
"F12" => Some(Key::F12),
|
||||
"F13" => Some(Key::F13),
|
||||
"F14" => Some(Key::F14),
|
||||
"F15" => Some(Key::F15),
|
||||
"F16" => Some(Key::F16),
|
||||
"F17" => Some(Key::F17),
|
||||
"F18" => Some(Key::F18),
|
||||
"F19" => Some(Key::F19),
|
||||
"F20" => Some(Key::F20),
|
||||
"F21" => Some(Key::F21),
|
||||
"F22" => Some(Key::F22),
|
||||
"F23" => Some(Key::F23),
|
||||
"F24" => Some(Key::F24),
|
||||
"F25" => Some(Key::F25),
|
||||
"0" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp0),
|
||||
"1" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp1),
|
||||
"2" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp2),
|
||||
"3" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp3),
|
||||
"4" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp4),
|
||||
"5" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp5),
|
||||
"6" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp6),
|
||||
"7" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp7),
|
||||
"8" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp8),
|
||||
"9" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::Kp9),
|
||||
"." if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpDecimal),
|
||||
"/" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpDivide),
|
||||
"*" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpMultiply),
|
||||
"-" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpSubtract),
|
||||
"+" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpAdd),
|
||||
"Enter" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpEnter),
|
||||
"=" if location == KeyboardEventConstants::DOM_KEY_LOCATION_NUMPAD => Some(Key::KpEqual),
|
||||
"Shift" if location == KeyboardEventConstants::DOM_KEY_LOCATION_LEFT => Some(Key::LeftShift),
|
||||
"Control" if location == KeyboardEventConstants::DOM_KEY_LOCATION_LEFT => Some(Key::LeftControl),
|
||||
"Alt" if location == KeyboardEventConstants::DOM_KEY_LOCATION_LEFT => Some(Key::LeftAlt),
|
||||
"Super" if location == KeyboardEventConstants::DOM_KEY_LOCATION_LEFT => Some(Key::LeftSuper),
|
||||
"Shift" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightShift),
|
||||
"Control" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightControl),
|
||||
"Alt" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightAlt),
|
||||
"Super" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightSuper),
|
||||
"ContextMenu" => Some(Key::Menu),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,6 +88,24 @@ fn is_control_key(mods: KeyModifiers) -> bool {
|
|||
mods.contains(CONTROL) && !mods.contains(SUPER | ALT)
|
||||
}
|
||||
|
||||
fn is_printable_key(key: Key) -> bool {
|
||||
match key {
|
||||
Key::Space | Key::Apostrophe | Key::Comma | Key::Minus |
|
||||
Key::Period | Key::Slash | Key::GraveAccent | Key::Num0 |
|
||||
Key::Num1 | Key::Num2 | Key::Num3 | Key::Num4 | Key::Num5 |
|
||||
Key::Num6 | Key::Num7 | Key::Num8 | Key::Num9 | Key::Semicolon |
|
||||
Key::Equal | Key::A | Key::B | Key::C | Key::D | Key::E | Key::F |
|
||||
Key::G | Key::H | Key::I | Key::J | Key::K | Key::L | Key::M | Key::N |
|
||||
Key::O | Key::P | Key::Q | Key::R | Key::S | Key::T | Key::U | Key::V |
|
||||
Key::W | Key::X | Key::Y | Key::Z | Key::LeftBracket | Key::Backslash |
|
||||
Key::RightBracket | Key::Kp0 | Key::Kp1 | Key::Kp2 | Key::Kp3 |
|
||||
Key::Kp4 | Key::Kp5 | Key::Kp6 | Key::Kp7 | Key::Kp8 | Key::Kp9 |
|
||||
Key::KpDecimal | Key::KpDivide | Key::KpMultiply | Key::KpSubtract |
|
||||
Key::KpAdd | Key::KpEqual => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ClipboardProvider> TextInput<T> {
|
||||
/// Instantiate a new text input control
|
||||
pub fn new(lines: Lines, initial: DOMString, clipboard_provider: T) -> TextInput<T> {
|
||||
|
@ -291,67 +309,66 @@ impl<T: ClipboardProvider> TextInput<T> {
|
|||
}
|
||||
pub fn handle_keydown_aux(&mut self, key: Key, mods: KeyModifiers) -> KeyReaction {
|
||||
let maybe_select = if mods.contains(SHIFT) { Selection::Selected } else { Selection::NotSelected };
|
||||
match key_value(key, mods) {
|
||||
"a" if is_control_key(mods) => {
|
||||
match key {
|
||||
Key::A if is_control_key(mods) => {
|
||||
self.select_all();
|
||||
KeyReaction::Nothing
|
||||
},
|
||||
"v" if is_control_key(mods) => {
|
||||
Key::V if is_control_key(mods) => {
|
||||
let contents = self.clipboard_provider.get_clipboard_contents();
|
||||
self.insert_string(&contents);
|
||||
KeyReaction::DispatchInput
|
||||
},
|
||||
// printable characters have single-character key values
|
||||
c if c.len() == 1 => {
|
||||
self.insert_char(c.chars().next().unwrap());
|
||||
_ if is_printable_key(key) => {
|
||||
self.insert_string(key_value(key, mods));
|
||||
KeyReaction::DispatchInput
|
||||
}
|
||||
"Space" => {
|
||||
Key::Space => {
|
||||
self.insert_char(' ');
|
||||
KeyReaction::DispatchInput
|
||||
}
|
||||
"Delete" => {
|
||||
Key::Delete => {
|
||||
self.delete_char(DeleteDir::Forward);
|
||||
KeyReaction::DispatchInput
|
||||
}
|
||||
"Backspace" => {
|
||||
Key::Backspace => {
|
||||
self.delete_char(DeleteDir::Backward);
|
||||
KeyReaction::DispatchInput
|
||||
}
|
||||
"ArrowLeft" => {
|
||||
Key::Left => {
|
||||
self.adjust_horizontal(-1, maybe_select);
|
||||
KeyReaction::Nothing
|
||||
}
|
||||
"ArrowRight" => {
|
||||
Key::Right => {
|
||||
self.adjust_horizontal(1, maybe_select);
|
||||
KeyReaction::Nothing
|
||||
}
|
||||
"ArrowUp" => {
|
||||
Key::Up => {
|
||||
self.adjust_vertical(-1, maybe_select);
|
||||
KeyReaction::Nothing
|
||||
}
|
||||
"ArrowDown" => {
|
||||
Key::Down => {
|
||||
self.adjust_vertical(1, maybe_select);
|
||||
KeyReaction::Nothing
|
||||
}
|
||||
"Enter" => self.handle_return(),
|
||||
"Home" => {
|
||||
Key::Enter | Key::KpEnter => self.handle_return(),
|
||||
Key::Home => {
|
||||
self.edit_point.index = 0;
|
||||
KeyReaction::Nothing
|
||||
}
|
||||
"End" => {
|
||||
Key::End => {
|
||||
self.edit_point.index = self.current_line_length();
|
||||
KeyReaction::Nothing
|
||||
}
|
||||
"PageUp" => {
|
||||
Key::PageUp => {
|
||||
self.adjust_vertical(-28, maybe_select);
|
||||
KeyReaction::Nothing
|
||||
}
|
||||
"PageDown" => {
|
||||
Key::PageDown => {
|
||||
self.adjust_vertical(28, maybe_select);
|
||||
KeyReaction::Nothing
|
||||
}
|
||||
"Tab" => KeyReaction::TriggerDefaultAction,
|
||||
Key::Tab => KeyReaction::TriggerDefaultAction,
|
||||
_ => KeyReaction::Nothing,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue