mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Auto merge of #10122 - Manishearth:nav-keys, r=asajeffrey
Support navigation keys Rather useful. If most people have these keys on their keyboard, I'd prefer to remove the backspace navigation handler. I've never used it on purpose, but it gets hit often by accident when an input widget isn't focused (either due to a misclick or debug build lag). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10122) <!-- Reviewable:end -->
This commit is contained in:
commit
771623054f
3 changed files with 21 additions and 3 deletions
|
@ -186,6 +186,9 @@ pub enum Key {
|
||||||
RightAlt,
|
RightAlt,
|
||||||
RightSuper,
|
RightSuper,
|
||||||
Menu,
|
Menu,
|
||||||
|
|
||||||
|
NavigateBackward,
|
||||||
|
NavigateForward,
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
|
|
@ -148,7 +148,7 @@ impl KeyboardEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3Events-key.html
|
// https://w3c.github.io/uievents-key/#key-value-tables
|
||||||
pub fn key_value(key: Key, mods: KeyModifiers) -> &'static str {
|
pub fn key_value(key: Key, mods: KeyModifiers) -> &'static str {
|
||||||
let shift = mods.contains(constellation_msg::SHIFT);
|
let shift = mods.contains(constellation_msg::SHIFT);
|
||||||
match key {
|
match key {
|
||||||
|
@ -319,6 +319,8 @@ pub fn key_value(key: Key, mods: KeyModifiers) -> &'static str {
|
||||||
Key::RightAlt => "Alt",
|
Key::RightAlt => "Alt",
|
||||||
Key::RightSuper => "Super",
|
Key::RightSuper => "Super",
|
||||||
Key::Menu => "ContextMenu",
|
Key::Menu => "ContextMenu",
|
||||||
|
Key::NavigateForward => "BrowserForward",
|
||||||
|
Key::NavigateBackward => "BrowserBack",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,11 +491,13 @@ fn key_from_string(key_string: &str, location: u32) -> Option<Key> {
|
||||||
"Alt" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightAlt),
|
"Alt" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightAlt),
|
||||||
"Super" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightSuper),
|
"Super" if location == KeyboardEventConstants::DOM_KEY_LOCATION_RIGHT => Some(Key::RightSuper),
|
||||||
"ContextMenu" => Some(Key::Menu),
|
"ContextMenu" => Some(Key::Menu),
|
||||||
|
"BrowserForward" => Some(Key::NavigateForward),
|
||||||
|
"BrowserBack" => Some(Key::NavigateBackward),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3Events-code.html
|
// https://w3c.github.io/uievents-code/#code-value-tables
|
||||||
fn code_value(key: Key) -> &'static str {
|
fn code_value(key: Key) -> &'static str {
|
||||||
match key {
|
match key {
|
||||||
Key::Space => "Space",
|
Key::Space => "Space",
|
||||||
|
@ -613,7 +617,10 @@ fn code_value(key: Key) -> &'static str {
|
||||||
Key::LeftControl | Key::RightControl => "Control",
|
Key::LeftControl | Key::RightControl => "Control",
|
||||||
Key::LeftAlt | Key::RightAlt => "Alt",
|
Key::LeftAlt | Key::RightAlt => "Alt",
|
||||||
Key::LeftSuper | Key::RightSuper => "Super",
|
Key::LeftSuper | Key::RightSuper => "Super",
|
||||||
Key::Menu => "Menu",
|
Key::Menu => "ContextMenu",
|
||||||
|
|
||||||
|
Key::NavigateForward => "BrowserForward",
|
||||||
|
Key::NavigateBackward => "BrowserBackward",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -498,6 +498,8 @@ impl Window {
|
||||||
VirtualKeyCode::Tab => Ok(Key::Tab),
|
VirtualKeyCode::Tab => Ok(Key::Tab),
|
||||||
VirtualKeyCode::Subtract => Ok(Key::Minus),
|
VirtualKeyCode::Subtract => Ok(Key::Minus),
|
||||||
|
|
||||||
|
VirtualKeyCode::NavigateBackward => Ok(Key::NavigateBackward),
|
||||||
|
VirtualKeyCode::NavigateForward => Ok(Key::NavigateForward),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -731,6 +733,12 @@ impl WindowMethods for Window {
|
||||||
(NONE, Key::Backspace) => {
|
(NONE, Key::Backspace) => {
|
||||||
self.event_queue.borrow_mut().push(WindowEvent::Navigation(WindowNavigateMsg::Back));
|
self.event_queue.borrow_mut().push(WindowEvent::Navigation(WindowNavigateMsg::Back));
|
||||||
}
|
}
|
||||||
|
(SHIFT, Key::NavigateForward) => {
|
||||||
|
self.event_queue.borrow_mut().push(WindowEvent::Navigation(WindowNavigateMsg::Forward));
|
||||||
|
}
|
||||||
|
(NONE, Key::NavigateBackward) => {
|
||||||
|
self.event_queue.borrow_mut().push(WindowEvent::Navigation(WindowNavigateMsg::Back));
|
||||||
|
}
|
||||||
|
|
||||||
(NONE, Key::Escape) => {
|
(NONE, Key::Escape) => {
|
||||||
self.event_queue.borrow_mut().push(WindowEvent::Quit);
|
self.event_queue.borrow_mut().push(WindowEvent::Quit);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue