// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "remoting/client/input/normalizing_input_filter_cros.h" #include "base/check.h" #include "ui/events/keycodes/dom/dom_code.h" namespace remoting { namespace { // Returns true for OSKey codes. static bool IsOsKey(uint32_t code) { … } // Returns true for codes generated by EventRewriter::RewriteFunctionKeys(). static bool IsRewrittenFunctionKey(uint32_t code) { … } // Returns true for codes generated by EventRewriter::RewriteExtendedKeys(). static bool IsRewrittenExtendedKey(uint32_t code) { … } // Returns true for codes generated by EventRewriter::Rewrite(). static bool IsRewrittenKey(uint32_t code) { … } } // namespace // The input filter tries to avoid sending keydown/keyup events for OSKey // (aka Search, WinKey, Cmd, Super) when it is used to rewrite other key events. // Rewriting via other combinations is not currently handled. // // OSKey events can be categorised as one of three kinds: // - Modifying - Holding the key down while executing other input modifies the // effect of that input, e.g. OSKey+L causes the workstation to lock, e.g. // OSKey + mouse-move performs an extended selection. // - Rewriting (ChromeOS only) - Holding the key down while pressing certain // keys causes them to be treated as different keys, e.g. OSKey causes the // Down key to behave as PageDown. // - Normal - Press & release of the key trigger an action, e.g. showing the // Start menu. // // The input filter has four states: // 1. No OSKey has been pressed. // - When an OSKey keydown is received, the event is deferred, and we move to // State #2. // 2. An OSKey is pressed, but may be Normal, Rewriting or Modifying. // - If the OSKey keyup is received, the key is Normal, both events are sent // and we return to State #1. // - If a Rewritten event is received we move to State #3. // - If a Modified event is received the OSKey keydown is sent and we enter // State #4. // 3. An OSKey is pressed, and is being used to Rewrite other key events. // - If the OSKey keyup is received then it is suppressed, and we move to // State #1. // - If a Modified event is received the OSKey keydown is sent and we enter // State #4. // - If a Rewritten event is received then we stay in State #3. // 4. An OSKey is pressed, and is Modifying. // - If the OSKey keyup is received then we send it and we move to State #1. // - All other key event pass through the filter unchanged. // // ChromeOS also maps Alt+LeftClick to RightClick (even for an external mouse). // As with the OSKey remapping described above, this is fed into this filter // as Alt followed by RightClick. However, because there are other ways to // generate RightClick (two-finger tap, for example), rather than suppressing // the Alt key as we do for the OSKey (which would allow Alt+LeftClick to be // interpreted as interpreted as RightClick as per the ChromeOS idiom), the // filter maps RightClick to LeftClick while LeftAlt is held, which allows // Alt+LeftClick to be injected. The equivalent mapping using RightAlt is // unchanged, allowing Alt+RightClick also to be injected, as long as the // target application doesn't distinguish between left and right Alt keys. // // This file must be kept up to date with changes to // ui/events/ash/event_rewriter_ash.cc NormalizingInputFilterCros::NormalizingInputFilterCros( protocol::InputStub* input_stub) : … { … } NormalizingInputFilterCros::~NormalizingInputFilterCros() = default; void NormalizingInputFilterCros::InjectKeyEvent( const protocol::KeyEvent& event_arg) { … } void NormalizingInputFilterCros::InjectMouseEvent( const protocol::MouseEvent& event) { … } void NormalizingInputFilterCros::ProcessKeyDown( const protocol::KeyEvent& event) { … } void NormalizingInputFilterCros::ProcessKeyUp(const protocol::KeyEvent& event) { … } void NormalizingInputFilterCros::SwitchRewritingKeyToModifying() { … } void NormalizingInputFilterCros::UndoAltKeyMapping(protocol::KeyEvent* event) { … } } // namespace remoting