summaryrefslogtreecommitdiffstats
path: root/remoting/client/plugin/pepper_input_handler.h
blob: 1d07c9fe3ee1c957998f9570fb81c82bd5c1b4e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2012 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.

#ifndef REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_
#define REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"

namespace pp {
class InputEvent;
}  // namespace pp

namespace remoting {

namespace protocol {
class InputStub;
class InputEventTracker;
} // namespace protocol

class PepperInputHandler {
 public:
  // Create a PepperInputHandler using the specified InputEventTracker to
  // handle auto-release. The InputEventTracker instance must remain valid
  // for the lifetime of the PepperInputHandler.
  explicit PepperInputHandler(protocol::InputEventTracker* input_tracker);

  // Enable or disable sending mouse input when the plugin does not have input
  // focus.
  void set_send_mouse_input_when_unfocused(bool send) {
    send_mouse_input_when_unfocused_ = send;
  }

  void set_send_mouse_move_deltas(bool enable) {
    send_mouse_move_deltas_ = enable;
  }

  // Enable or disable detection of stuck modifier keys.
  void set_detect_stuck_modifiers(bool detect) {
    detect_stuck_modifiers_ = detect;
  }

  // Processes PPAPI events and dispatches them to |input_tracker_|.
  bool HandleInputEvent(const pp::InputEvent& event);

  // Must be called when the plugin receives or loses focus.
  void DidChangeFocus(bool has_focus);

 private:
  // Check for any missed "keyup" events for modifiers. These can sometimes be
  // missed due to OS-level keyboard shortcuts such as "lock screen" that cause
  // focus to switch to another application. If any modifier keys are held that
  // are not indicated as active on |event|, release all keys.
  void ReleaseAllIfModifiersStuck(const pp::InputEvent& event);

  // Tracks input events to manage auto-release in ReleaseAllIfModifiersStuck
  // and receives input events generated from PPAPI input.
  protocol::InputEventTracker* input_tracker_;

  // True if the plugin has focus.
  bool has_focus_;

  // True if the plugin should respond to mouse input even if it does not have
  // keyboard focus.
  bool send_mouse_input_when_unfocused_;

  // True if the plugin should include mouse move deltas, in addition to
  // absolute position information, in mouse events.
  bool send_mouse_move_deltas_;

  // Accumulated sub-pixel and sub-tick deltas from wheel events.
  float wheel_delta_x_;
  float wheel_delta_y_;
  float wheel_ticks_x_;
  float wheel_ticks_y_;

  // Whether or not to check for stuck modifier keys on keyboard input events.
  bool detect_stuck_modifiers_;

  DISALLOW_COPY_AND_ASSIGN(PepperInputHandler);
};

}  // namespace remoting

#endif  // REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_