Handle account removal correctly on all platforms.
[chromium-blink-merge.git] / remoting / client / plugin / pepper_input_handler.h
blob9ec04755282bec688d39598f7978e2c62f0e9478
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_
6 #define REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ppapi/cpp/mouse_lock.h"
11 #include "ppapi/cpp/point.h"
12 #include "ppapi/utility/completion_callback_factory.h"
13 #include "remoting/protocol/input_stub.h"
15 namespace pp {
16 class ImageData;
17 class InputEvent;
18 class Instance;
19 } // namespace pp
21 namespace remoting {
23 namespace protocol {
24 class InputStub;
25 } // namespace protocol
27 class PepperInputHandler : public pp::MouseLock {
28 public:
29 // |instance| must outlive |this|.
30 explicit PepperInputHandler(pp::Instance* instance);
31 virtual ~PepperInputHandler();
33 void set_input_stub(protocol::InputStub* input_stub) {
34 input_stub_ = input_stub;
37 bool HandleInputEvent(const pp::InputEvent& event);
39 // Enables locking the mouse when the host sets a completely transparent mouse
40 // cursor.
41 void AllowMouseLock();
43 // Called when the plugin receives or loses focus.
44 void DidChangeFocus(bool has_focus);
46 // Sets the mouse cursor image. Passing NULL image will lock the mouse if
47 // mouse lock is enabled.
48 void SetMouseCursor(scoped_ptr<pp::ImageData> image,
49 const pp::Point& hotspot);
51 // Enable or disable sending mouse input when the plugin does not have input
52 // focus.
53 void set_send_mouse_input_when_unfocused(bool send) {
54 send_mouse_input_when_unfocused_ = send;
57 private:
58 enum MouseLockState {
59 MouseLockDisallowed,
60 MouseLockOff,
61 MouseLockRequestPending,
62 MouseLockOn,
63 MouseLockCancelling
66 // pp::MouseLock interface.
67 virtual void MouseLockLost() OVERRIDE;
69 // Requests the browser to lock the mouse and hides the cursor.
70 void RequestMouseLock();
72 // Requests the browser to cancel mouse lock and restores the cursor once
73 // the lock is gone.
74 void CancelMouseLock();
76 // Applies |cursor_image_| as the custom pointer or uses the standard arrow
77 // pointer if |cursor_image_| is not available.
78 void UpdateMouseCursor();
80 // Handles completion of the mouse lock request issued by RequestMouseLock().
81 void OnMouseLocked(int error);
83 pp::Instance* instance_;
84 protocol::InputStub* input_stub_;
86 pp::CompletionCallbackFactory<PepperInputHandler> callback_factory_;
88 // Custom cursor image sent by the host. |cursor_image_| is set to NULL when
89 // the cursor image is completely transparent. This can be interpreted as
90 // a mouse lock request if enabled by the webapp.
91 scoped_ptr<pp::ImageData> cursor_image_;
93 // Hot spot for |cursor_image_|.
94 pp::Point cursor_hotspot_;
96 // True if the plugin has focus.
97 bool has_focus_;
99 // True if the plugin should respond to mouse input even if it does not have
100 // keyboard focus.
101 bool send_mouse_input_when_unfocused_;
103 MouseLockState mouse_lock_state_;
105 // Accumulated sub-pixel and sub-tick deltas from wheel events.
106 float wheel_delta_x_;
107 float wheel_delta_y_;
108 float wheel_ticks_x_;
109 float wheel_ticks_y_;
111 DISALLOW_COPY_AND_ASSIGN(PepperInputHandler);
114 } // namespace remoting
116 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_