diff options
author | jamiewalch <jamiewalch@chromium.org> | 2015-10-13 11:50:42 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-13 18:51:49 +0000 |
commit | c887dd916e1d12804ee8fde58e4e3089b2aba86c (patch) | |
tree | e8b71c1aeb0974b12b788fb20e8ecdd509c2911f /remoting/client/normalizing_input_filter_cros.cc | |
parent | 19bdd83da5479408eb07449893b8e52c6a3ade51 (diff) | |
download | chromium_src-c887dd916e1d12804ee8fde58e4e3089b2aba86c.zip chromium_src-c887dd916e1d12804ee8fde58e4e3089b2aba86c.tar.gz chromium_src-c887dd916e1d12804ee8fde58e4e3089b2aba86c.tar.bz2 |
Undo ChromeOS Alt-key mapping for keys that have an identical Search key mapping.
Without this mapping, keys are either injected as Alt+<remapped key> or (in the case
of Backspace) are not injected at all. Since an alternative remapping exists using
the search key, and keyboard shortcuts such as Alt+Up are useful in some contexts,
we undo the mapping. Note that this will make it impossible to type, for example,
Alt+PgUp, even if an external keyboard is plugged in.
BUG=435411
Review URL: https://codereview.chromium.org/1393763005
Cr-Commit-Position: refs/heads/master@{#353809}
Diffstat (limited to 'remoting/client/normalizing_input_filter_cros.cc')
-rw-r--r-- | remoting/client/normalizing_input_filter_cros.cc | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/remoting/client/normalizing_input_filter_cros.cc b/remoting/client/normalizing_input_filter_cros.cc index 0b97652..8cb2229 100644 --- a/remoting/client/normalizing_input_filter_cros.cc +++ b/remoting/client/normalizing_input_filter_cros.cc @@ -17,11 +17,6 @@ static bool IsOsKey(uint32_t code) { code == static_cast<uint32_t>(ui::DomCode::OS_RIGHT); } -// Returns true for the left-hand Alt key. -static bool IsLeftAltKey(uint32_t code) { - return code == static_cast<uint32_t>(ui::DomCode::ALT_LEFT); -} - // Returns true for codes generated by EventRewriter::RewriteFunctionKeys(). static bool IsRewrittenFunctionKey(uint32_t code) { return code >= static_cast<uint32_t>(ui::DomCode::F1) && @@ -96,6 +91,7 @@ NormalizingInputFilterCros::NormalizingInputFilterCros( deferred_key_is_rewriting_(false), modifying_key_(0), left_alt_is_pressed_(false), + right_alt_is_pressed_(false), previous_mouse_x_(-1), previous_mouse_y_(-1) { } @@ -177,10 +173,17 @@ void NormalizingInputFilterCros::ProcessKeyDown( SwitchRewritingKeyToModifying(); } - if (IsLeftAltKey(event.usb_keycode())) + ui::DomCode dom_code = static_cast<ui::DomCode>(event.usb_keycode()); + if (dom_code == ui::DomCode::ALT_LEFT) { left_alt_is_pressed_ = true; + } else if (dom_code == ui::DomCode::ALT_RIGHT) { + right_alt_is_pressed_ = true; + } - InputFilter::InjectKeyEvent(event); + protocol::KeyEvent updated_event = event; + UndoAltKeyMapping(&updated_event); + + InputFilter::InjectKeyEvent(updated_event); } void NormalizingInputFilterCros::ProcessKeyUp(const protocol::KeyEvent& event) { @@ -199,10 +202,17 @@ void NormalizingInputFilterCros::ProcessKeyUp(const protocol::KeyEvent& event) { if (modifying_key_ == event.usb_keycode()) modifying_key_ = 0; - if (IsLeftAltKey(event.usb_keycode())) + ui::DomCode dom_code = static_cast<ui::DomCode>(event.usb_keycode()); + if (dom_code == ui::DomCode::ALT_LEFT) { left_alt_is_pressed_ = false; + } else if (dom_code == ui::DomCode::ALT_RIGHT) { + right_alt_is_pressed_ = false; + } + + protocol::KeyEvent updated_event = event; + UndoAltKeyMapping(&updated_event); - InputFilter::InjectKeyEvent(event); + InputFilter::InjectKeyEvent(updated_event); } void NormalizingInputFilterCros::SwitchRewritingKeyToModifying() { @@ -212,4 +222,24 @@ void NormalizingInputFilterCros::SwitchRewritingKeyToModifying() { deferred_keydown_event_ = protocol::KeyEvent(); } +void NormalizingInputFilterCros::UndoAltKeyMapping(protocol::KeyEvent* event) { + if (!left_alt_is_pressed_ && !right_alt_is_pressed_) { + return; + } + + // If the keycode is one for which the Alt and Search keyboard shortcuts are + // the same, map it back to the original key. + switch (event->usb_keycode()) { + case static_cast<uint32_t>(ui::DomCode::PAGE_DOWN): + event->set_usb_keycode(static_cast<uint32_t>(ui::DomCode::ARROW_DOWN)); + break; + case static_cast<uint32_t>(ui::DomCode::PAGE_UP): + event->set_usb_keycode(static_cast<uint32_t>(ui::DomCode::ARROW_UP)); + break; + case static_cast<uint32_t>(ui::DomCode::DEL): + event->set_usb_keycode(static_cast<uint32_t>(ui::DomCode::BACKSPACE)); + break; + } +} + } // namespace remoting |