| Index: remoting/client/plugin/normalizing_input_filter_cros.cc
|
| diff --git a/remoting/client/plugin/normalizing_input_filter_cros.cc b/remoting/client/plugin/normalizing_input_filter_cros.cc
|
| index 81cec8d78131ca377e17bbc6a35989ffef6b8804..5ad77eee408007318ab88f937d6e25df52d98f92 100644
|
| --- a/remoting/client/plugin/normalizing_input_filter_cros.cc
|
| +++ b/remoting/client/plugin/normalizing_input_filter_cros.cc
|
| @@ -2,26 +2,9 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -// NormalizingInputFilterCros addresses the problems generated by key rewritings
|
| -// such as Down->PageDown, 1->F1, etc, when keys are pressed in combination with
|
| -// the OSKey (aka Search). Rewriting OSKey+Down, for example, causes us to
|
| -// receive the following:
|
| -//
|
| -// keydown OSKey
|
| -// keydown PageDown
|
| -// keyup PageDown
|
| -// keyup OSKey
|
| -//
|
| -// The host system will therefore behave as if OSKey+PageDown were pressed,
|
| -// rather than PageDown alone.
|
| -//
|
| -// This file must be kept up-to-date with changes to
|
| -// chrome/browser/ui/ash/event_rewriter.cc
|
| -
|
| -#include "remoting/client/plugin/normalizing_input_filter.h"
|
| +#include "remoting/client/plugin/normalizing_input_filter_cros.h"
|
|
|
| #include "base/logging.h"
|
| -#include "remoting/proto/event.pb.h"
|
|
|
| namespace remoting {
|
|
|
| @@ -53,6 +36,8 @@ static bool IsRewrittenKey(unsigned int code) {
|
| return IsRewrittenExtendedKey(code) || IsRewrittenFunctionKey(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.
|
| @@ -86,121 +71,102 @@ static bool IsRewrittenKey(unsigned int code) {
|
| // 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.
|
| +//
|
| +// This file must be kept up-to-date with changes to
|
| +// chrome/browser/ui/ash/event_rewriter.cc
|
|
|
| -class NormalizingInputFilterCros : public protocol::InputFilter {
|
| - public:
|
| - explicit NormalizingInputFilterCros(protocol::InputStub* input_stub)
|
| - : protocol::InputFilter(input_stub),
|
| - deferred_key_is_rewriting_(false),
|
| - modifying_key_(0) {
|
| - }
|
| - virtual ~NormalizingInputFilterCros() {}
|
| +NormalizingInputFilterCros::NormalizingInputFilterCros(
|
| + protocol::InputStub* input_stub)
|
| + : protocol::InputFilter(input_stub),
|
| + deferred_key_is_rewriting_(false),
|
| + modifying_key_(0) {
|
| +}
|
|
|
| - // InputFilter overrides.
|
| - virtual void InjectKeyEvent(const protocol::KeyEvent& event) OVERRIDE {
|
| - DCHECK(event.has_usb_keycode());
|
| - DCHECK(event.has_pressed());
|
| +NormalizingInputFilterCros::~NormalizingInputFilterCros() {}
|
|
|
| - if (event.pressed())
|
| - ProcessKeyDown(event);
|
| - else
|
| - ProcessKeyUp(event);
|
| - }
|
| +void NormalizingInputFilterCros::InjectKeyEvent(
|
| + const protocol::KeyEvent& event) {
|
| + DCHECK(event.has_usb_keycode());
|
| + DCHECK(event.has_pressed());
|
|
|
| - virtual void InjectMouseEvent(const protocol::MouseEvent& event) OVERRIDE {
|
| - if (deferred_keydown_event_.has_usb_keycode())
|
| - SwitchRewritingKeyToModifying();
|
| - InputFilter::InjectMouseEvent(event);
|
| + if (event.pressed()) {
|
| + ProcessKeyDown(event);
|
| + } else {
|
| + ProcessKeyUp(event);
|
| }
|
| +}
|
|
|
| - private:
|
| - void ProcessKeyDown(const protocol::KeyEvent& event) {
|
| - // If |event| is |deferred_keydown_event_| auto-repeat then assume
|
| - // that the user is holding the key down rather than using it to Rewrite.
|
| - if (deferred_keydown_event_.has_usb_keycode() &&
|
| - deferred_keydown_event_.usb_keycode() == event.usb_keycode()) {
|
| - SwitchRewritingKeyToModifying();
|
| - }
|
| -
|
| - // If |event| is a |modifying_key_| repeat then let it pass through.
|
| - if (modifying_key_ == event.usb_keycode()) {
|
| - InputFilter::InjectKeyEvent(event);
|
| - return;
|
| - }
|
| -
|
| - // If |event| is for an OSKey and we don't know whether it's a Normal,
|
| - // Rewriting or Modifying use, then hold the keydown event.
|
| - if (IsOsKey(event.usb_keycode())) {
|
| - deferred_keydown_event_ = event;
|
| - deferred_key_is_rewriting_ = false;
|
| - return;
|
| - }
|
| +void NormalizingInputFilterCros::InjectMouseEvent(
|
| + const protocol::MouseEvent& event) {
|
| + if (deferred_keydown_event_.has_usb_keycode())
|
| + SwitchRewritingKeyToModifying();
|
| + InputFilter::InjectMouseEvent(event);
|
| +}
|
|
|
| - // If |event| is for a Rewritten key then set a flag to prevent any deferred
|
| - // OSKey keydown from being sent when keyup is received for it. Otherwise,
|
| - // inject the deferred OSKey keydown, if any, and switch that key into
|
| - // Modifying mode.
|
| - if (IsRewrittenKey(event.usb_keycode())) {
|
| - // Note that there may not be a deferred OSKey event if there is a full
|
| - // PC keyboard connected, which can generate e.g. PageDown without
|
| - // rewriting.
|
| - deferred_key_is_rewriting_ = true;
|
| - } else {
|
| - if (deferred_keydown_event_.has_usb_keycode())
|
| - SwitchRewritingKeyToModifying();
|
| - }
|
| +void NormalizingInputFilterCros::ProcessKeyDown(
|
| + const protocol::KeyEvent& event) {
|
| + // If |event| is |deferred_keydown_event_| repeat then assume that the user is
|
| + // holding the key down rather than using it to Rewrite.
|
| + if (deferred_keydown_event_.has_usb_keycode() &&
|
| + deferred_keydown_event_.usb_keycode() == event.usb_keycode()) {
|
| + SwitchRewritingKeyToModifying();
|
| + }
|
|
|
| + // If |event| is a |modifying_key_| repeat then let it pass through.
|
| + if (modifying_key_ == event.usb_keycode()) {
|
| InputFilter::InjectKeyEvent(event);
|
| + return;
|
| }
|
|
|
| - void ProcessKeyUp(const protocol::KeyEvent& event) {
|
| - if (deferred_keydown_event_.has_usb_keycode() &&
|
| - deferred_keydown_event_.usb_keycode() == event.usb_keycode()) {
|
| - if (deferred_key_is_rewriting_) {
|
| - // If we never sent the keydown then don't send a keyup.
|
| - deferred_keydown_event_ = protocol::KeyEvent();
|
| - return;
|
| - }
|
| -
|
| - // If the OSKey hasn't Rewritten anything then treat as Modifying.
|
| - SwitchRewritingKeyToModifying();
|
| - }
|
| -
|
| - if (modifying_key_ == event.usb_keycode())
|
| - modifying_key_ = 0;
|
| -
|
| - InputFilter::InjectKeyEvent(event);
|
| + // If |event| is for an OSKey and we don't know whether it's a Normal,
|
| + // Rewriting or Modifying use, then hold the keydown event.
|
| + if (IsOsKey(event.usb_keycode())) {
|
| + deferred_keydown_event_ = event;
|
| + deferred_key_is_rewriting_ = false;
|
| + return;
|
| }
|
|
|
| - void SwitchRewritingKeyToModifying() {
|
| - DCHECK(deferred_keydown_event_.has_usb_keycode());
|
| - modifying_key_ = deferred_keydown_event_.usb_keycode();
|
| - InputFilter::InjectKeyEvent(deferred_keydown_event_);
|
| - deferred_keydown_event_ = protocol::KeyEvent();
|
| + // If |event| is for a Rewritten key then set a flag to prevent any deferred
|
| + // OSKey keydown from being sent when keyup is received for it. Otherwise,
|
| + // inject the deferred OSKey keydown, if any, and switch that key into
|
| + // Modifying mode.
|
| + if (IsRewrittenKey(event.usb_keycode())) {
|
| + // Note that there may not be a deferred OSKey event if there is a full
|
| + // PC keyboard connected, which can generate e.g. PageDown without
|
| + // rewriting.
|
| + deferred_key_is_rewriting_ = true;
|
| + } else {
|
| + if (deferred_keydown_event_.has_usb_keycode())
|
| + SwitchRewritingKeyToModifying();
|
| }
|
|
|
| - // Holds the keydown event for the most recent OSKey to have been pressed,
|
| - // while it is Rewriting, or we are not yet sure whether it is Normal,
|
| - // Rewriting or Modifying. The event is sent on if we switch to Modifying, or
|
| - // discarded if the OSKey is released while in Rewriting mode.
|
| - protocol::KeyEvent deferred_keydown_event_;
|
| + InputFilter::InjectKeyEvent(event);
|
| +}
|
|
|
| - // True while the |rewrite_keydown_event_| key is Rewriting, i.e. was followed
|
| - // by one or more Rewritten key events, and not by any Modified events.
|
| - bool deferred_key_is_rewriting_;
|
| +void NormalizingInputFilterCros::ProcessKeyUp(const protocol::KeyEvent& event) {
|
| + if (deferred_keydown_event_.has_usb_keycode() &&
|
| + deferred_keydown_event_.usb_keycode() == event.usb_keycode()) {
|
| + if (deferred_key_is_rewriting_) {
|
| + // If we never sent the keydown then don't send a keyup.
|
| + deferred_keydown_event_ = protocol::KeyEvent();
|
| + return;
|
| + }
|
|
|
| - // Stores the code of the OSKey while it is pressed for use as a Modifier.
|
| - uint32 modifying_key_;
|
| + // If the OSKey hasn't Rewritten anything then treat as Modifying.
|
| + SwitchRewritingKeyToModifying();
|
| + }
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(NormalizingInputFilterCros);
|
| -};
|
| + if (modifying_key_ == event.usb_keycode())
|
| + modifying_key_ = 0;
|
|
|
| -} // namespace
|
| + InputFilter::InjectKeyEvent(event);
|
| +}
|
|
|
| -scoped_ptr<protocol::InputFilter> CreateNormalizingInputFilter(
|
| - protocol::InputStub* input_stub) {
|
| - return scoped_ptr<protocol::InputFilter>(
|
| - new NormalizingInputFilterCros(input_stub));
|
| +void NormalizingInputFilterCros::SwitchRewritingKeyToModifying() {
|
| + DCHECK(deferred_keydown_event_.has_usb_keycode());
|
| + modifying_key_ = deferred_keydown_event_.usb_keycode();
|
| + InputFilter::InjectKeyEvent(deferred_keydown_event_);
|
| + deferred_keydown_event_ = protocol::KeyEvent();
|
| }
|
|
|
| } // namespace remoting
|
|
|