OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_ | 5 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_ |
6 #define REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_ | 6 #define REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_ |
7 | 7 |
8 #include "base/compiler_specific.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" |
9 #include "remoting/protocol/input_stub.h" | 13 #include "remoting/protocol/input_stub.h" |
10 | 14 |
11 namespace pp { | 15 namespace pp { |
| 16 class ImageData; |
12 class InputEvent; | 17 class InputEvent; |
| 18 class Instance; |
13 } // namespace pp | 19 } // namespace pp |
14 | 20 |
15 namespace remoting { | 21 namespace remoting { |
16 | 22 |
17 namespace protocol { | 23 namespace protocol { |
18 class InputStub; | 24 class InputStub; |
19 } // namespace protocol | 25 } // namespace protocol |
20 | 26 |
21 class PepperInputHandler { | 27 class PepperInputHandler : public pp::MouseLock { |
22 public: | 28 public: |
23 explicit PepperInputHandler(protocol::InputStub* input_stub); | 29 // |instance| must outlive |this|. |
| 30 PepperInputHandler(pp::Instance* instance, protocol::InputStub* input_stub); |
24 virtual ~PepperInputHandler(); | 31 virtual ~PepperInputHandler(); |
25 | 32 |
26 bool HandleInputEvent(const pp::InputEvent& event); | 33 bool HandleInputEvent(const pp::InputEvent& event); |
27 | 34 |
| 35 // Enables locking the mouse when the host sets a completely transparent mouse |
| 36 // cursor. |
| 37 void AllowMouseLock(); |
| 38 |
| 39 // Called when the plugin receives or loses focus. |
| 40 void DidChangeFocus(bool has_focus); |
| 41 |
| 42 // Sets the mouse cursor image. Passing NULL image will lock the mouse if |
| 43 // mouse lock is enabled. |
| 44 void SetMouseCursor(scoped_ptr<pp::ImageData> image, |
| 45 const pp::Point& hotspot); |
| 46 |
28 private: | 47 private: |
| 48 enum MouseLockState { |
| 49 MouseLockDisallowed, |
| 50 MouseLockOff, |
| 51 MouseLockRequestPending, |
| 52 MouseLockOn, |
| 53 MouseLockCancelling |
| 54 }; |
| 55 |
| 56 // pp::MouseLock interface. |
| 57 virtual void MouseLockLost() OVERRIDE; |
| 58 |
| 59 // Requests the browser to lock the mouse and hides the cursor. |
| 60 void RequestMouseLock(); |
| 61 |
| 62 // Requests the browser to cancel mouse lock and restores the cursor once |
| 63 // the lock is gone. |
| 64 void CancelMouseLock(); |
| 65 |
| 66 // Applies |cursor_image_| as the custom pointer or uses the standard arrow |
| 67 // pointer if |cursor_image_| is not available. |
| 68 void UpdateMouseCursor(); |
| 69 |
| 70 // Handles completion of the mouse lock request issued by RequestMouseLock(). |
| 71 void OnMouseLocked(int error); |
| 72 |
| 73 pp::Instance* instance_; |
29 protocol::InputStub* input_stub_; | 74 protocol::InputStub* input_stub_; |
30 | 75 |
| 76 pp::CompletionCallbackFactory<PepperInputHandler> callback_factory_; |
| 77 |
| 78 // Custom cursor image sent by the host. |cursor_image_| is set to NULL when |
| 79 // the cursor image is completely transparent. This can be interpreted as |
| 80 // a mouse lock request if enabled by the webapp. |
| 81 scoped_ptr<pp::ImageData> cursor_image_; |
| 82 |
| 83 // Hot spot for |cursor_image_|. |
| 84 pp::Point cursor_hotspot_; |
| 85 |
| 86 // True if the plugin has focus. |
| 87 bool has_focus_; |
| 88 |
| 89 MouseLockState mouse_lock_state_; |
| 90 |
31 // Accumulated sub-pixel and sub-tick deltas from wheel events. | 91 // Accumulated sub-pixel and sub-tick deltas from wheel events. |
32 float wheel_delta_x_; | 92 float wheel_delta_x_; |
33 float wheel_delta_y_; | 93 float wheel_delta_y_; |
34 float wheel_ticks_x_; | 94 float wheel_ticks_x_; |
35 float wheel_ticks_y_; | 95 float wheel_ticks_y_; |
36 | 96 |
37 DISALLOW_COPY_AND_ASSIGN(PepperInputHandler); | 97 DISALLOW_COPY_AND_ASSIGN(PepperInputHandler); |
38 }; | 98 }; |
39 | 99 |
40 } // namespace remoting | 100 } // namespace remoting |
41 | 101 |
42 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_ | 102 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_ |
OLD | NEW |