Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: remoting/client/plugin/normalizing_input_filter_cros.cc

Issue 1228333004: Move code that doesn't depend on PPAPI out of remoting/client/plugin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
deleted file mode 100644
index ed5d438d7b54c6f8577c2a33e4fced8178bf17ac..0000000000000000000000000000000000000000
--- a/remoting/client/plugin/normalizing_input_filter_cros.cc
+++ /dev/null
@@ -1,216 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/client/plugin/normalizing_input_filter_cros.h"
-
-#include "base/logging.h"
-#include "remoting/protocol/usb_key_codes.h"
-
-namespace remoting {
-
-namespace {
-
-// Returns true for OSKey codes.
-static bool IsOsKey(unsigned int code) {
- return code == kUsbLeftOs || code == kUsbRightOs;
-}
-
-// Returns true for the left-hand Alt key.
-static bool IsLeftAltKey(unsigned int code) {
- return code == kUsbLeftAlt;
-}
-
-// Returns true for codes generated by EventRewriter::RewriteFunctionKeys().
-static bool IsRewrittenFunctionKey(unsigned int code) {
- const unsigned int kUsbFunctionKeyMin = 0x07003a;
- const unsigned int kUsbFunctionKeyMax = 0x070045;
- return code >= kUsbFunctionKeyMin && code <= kUsbFunctionKeyMax;
-}
-
-// Returns true for codes generated by EventRewriter::RewriteExtendedKeys().
-static bool IsRewrittenExtendedKey(unsigned int code) {
- const unsigned int kUsbExtendedKeyMin = 0x070049;
- const unsigned int kUsbExtendedKeyMax = 0x07004e;
- return code >= kUsbExtendedKeyMin && code <= kUsbExtendedKeyMax;
-}
-
-// Returns true for codes generated by EventRewriter::Rewrite().
-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.
-//
-// 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
-// chrome/browser/chromeos/events/event_rewriter.cc
-
-
-NormalizingInputFilterCros::NormalizingInputFilterCros(
- protocol::InputStub* input_stub)
- : protocol::InputFilter(input_stub),
- deferred_key_is_rewriting_(false),
- modifying_key_(0),
- left_alt_is_pressed_(false),
- previous_mouse_x_(-1),
- previous_mouse_y_(-1) {
-}
-
-NormalizingInputFilterCros::~NormalizingInputFilterCros() {}
-
-void NormalizingInputFilterCros::InjectKeyEvent(
- const protocol::KeyEvent& event) {
- DCHECK(event.has_usb_keycode());
- DCHECK(event.has_pressed());
-
- if (event.pressed()) {
- ProcessKeyDown(event);
- } else {
- ProcessKeyUp(event);
- }
-}
-
-void NormalizingInputFilterCros::InjectMouseEvent(
- const protocol::MouseEvent& event) {
- // If there's a rewriting/modifier decision pending, assume that it's
- // intended to be used as a modifying key for this mouse event and send it.
- if (deferred_keydown_event_.has_usb_keycode()) {
- // TODO(jamiewalch): Until crbug.com/489468 is fixed, a spurious mouse move
- // event is generated in response to certain key combinations, so check that
- // this is actually an "interesting" event.
- if (event.has_button() ||
- event.x() != previous_mouse_x_ ||
- event.y() != previous_mouse_y_) {
- SwitchRewritingKeyToModifying();
- }
- }
- previous_mouse_x_ = event.x();
- previous_mouse_y_ = event.y();
-
- protocol::MouseEvent newEvent = event;
- if (left_alt_is_pressed_ &&
- event.has_button() &&
- event.button() == protocol::MouseEvent::BUTTON_RIGHT) {
- newEvent.set_button(protocol::MouseEvent::BUTTON_LEFT);
- }
- InputFilter::InjectMouseEvent(newEvent);
-}
-
-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;
- }
-
- // 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;
- }
-
- // 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();
- }
-
- if (IsLeftAltKey(event.usb_keycode()))
- left_alt_is_pressed_ = true;
-
- InputFilter::InjectKeyEvent(event);
-}
-
-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;
- }
-
- // If the OSKey hasn't Rewritten anything then treat as Modifying.
- SwitchRewritingKeyToModifying();
- }
-
- if (modifying_key_ == event.usb_keycode())
- modifying_key_ = 0;
-
- if (IsLeftAltKey(event.usb_keycode()))
- left_alt_is_pressed_ = false;
-
- InputFilter::InjectKeyEvent(event);
-}
-
-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

Powered by Google App Engine
This is Rietveld 408576698