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"
25 } // namespace protocol
27 class PepperInputHandler : public pp::MouseLock {
29 // |instance| must outlive |this|.
30 explicit PepperInputHandler(pp::Instance* instance);
31 ~PepperInputHandler() override;
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
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 cause the cursor to
48 // Passing NULL |image| will also cause mouse-lock to be entered, if allowed.
49 void SetMouseCursor(scoped_ptr<pp::ImageData> image,
50 const pp::Point& hotspot);
52 // Hides the mousr cursor without triggering mouse-lock.
53 void HideMouseCursor();
55 // Enable or disable sending mouse input when the plugin does not have input
57 void set_send_mouse_input_when_unfocused(bool send) {
58 send_mouse_input_when_unfocused_ = send;
65 MouseLockRequestPending,
70 // pp::MouseLock interface.
71 void MouseLockLost() override;
73 // Requests the browser to lock the mouse and hides the cursor.
74 void RequestMouseLock();
76 // Requests the browser to cancel mouse lock and restores the cursor once
78 void CancelMouseLock();
80 // Applies |cursor_image_| as the custom pointer or uses the standard arrow
81 // pointer if |cursor_image_| is not available.
82 void UpdateMouseCursor();
84 // Handles completion of the mouse lock request issued by RequestMouseLock().
85 void OnMouseLocked(int error);
87 pp::Instance* instance_;
88 protocol::InputStub* input_stub_;
90 pp::CompletionCallbackFactory<PepperInputHandler> callback_factory_;
92 // Custom cursor image sent by the host. |cursor_image_| is set to NULL when
93 // the cursor image is completely transparent. This can be interpreted as
94 // a mouse lock request if enabled by the webapp.
95 scoped_ptr<pp::ImageData> cursor_image_;
97 // Hot spot for |cursor_image_|.
98 pp::Point cursor_hotspot_;
100 // True if the plugin has focus.
103 // True if the plugin should respond to mouse input even if it does not have
105 bool send_mouse_input_when_unfocused_;
107 MouseLockState mouse_lock_state_;
109 // Accumulated sub-pixel and sub-tick deltas from wheel events.
110 float wheel_delta_x_;
111 float wheel_delta_y_;
112 float wheel_ticks_x_;
113 float wheel_ticks_y_;
115 DISALLOW_COPY_AND_ASSIGN(PepperInputHandler);
118 } // namespace remoting
120 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_