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 PepperInputHandler(pp::Instance* instance, protocol::InputStub* input_stub);
31 virtual ~PepperInputHandler();
33 bool HandleInputEvent(const pp::InputEvent& event);
35 // Enables locking the mouse when the host sets a completely transparent mouse
37 void AllowMouseLock();
39 // Called when the plugin receives or loses focus.
40 void DidChangeFocus(bool has_focus);
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);
51 MouseLockRequestPending,
56 // pp::MouseLock interface.
57 virtual void MouseLockLost() OVERRIDE;
59 // Requests the browser to lock the mouse and hides the cursor.
60 void RequestMouseLock();
62 // Requests the browser to cancel mouse lock and restores the cursor once
64 void CancelMouseLock();
66 // Applies |cursor_image_| as the custom pointer or uses the standard arrow
67 // pointer if |cursor_image_| is not available.
68 void UpdateMouseCursor();
70 // Handles completion of the mouse lock request issued by RequestMouseLock().
71 void OnMouseLocked(int error);
73 pp::Instance* instance_;
74 protocol::InputStub* input_stub_;
76 pp::CompletionCallbackFactory<PepperInputHandler> callback_factory_;
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_;
83 // Hot spot for |cursor_image_|.
84 pp::Point cursor_hotspot_;
86 // True if the plugin has focus.
89 MouseLockState mouse_lock_state_;
91 // Accumulated sub-pixel and sub-tick deltas from wheel events.
97 DISALLOW_COPY_AND_ASSIGN(PepperInputHandler);
100 } // namespace remoting
102 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_