Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / remoting / client / plugin / pepper_input_handler.h
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.
4
5 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_
6 #define REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_
7
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"
14
15 namespace pp {
16 class ImageData;
17 class InputEvent;
18 class Instance;
19 }  // namespace pp
20
21 namespace remoting {
22
23 namespace protocol {
24 class InputStub;
25 } // namespace protocol
26
27 class PepperInputHandler : public pp::MouseLock {
28  public:
29   // |instance| must outlive |this|.
30   explicit PepperInputHandler(pp::Instance* instance);
31   ~PepperInputHandler() override;
32
33   void set_input_stub(protocol::InputStub* input_stub) {
34     input_stub_ = input_stub;
35   }
36
37   bool HandleInputEvent(const pp::InputEvent& event);
38
39   // Enables locking the mouse when the host sets a completely transparent mouse
40   // cursor.
41   void AllowMouseLock();
42
43   // Called when the plugin receives or loses focus.
44   void DidChangeFocus(bool has_focus);
45
46   // Sets the mouse cursor image. Passing NULL |image| will cause the cursor to
47   // be hidden.
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);
51
52   // Hides the mousr cursor without triggering mouse-lock.
53   void HideMouseCursor();
54
55   // Enable or disable sending mouse input when the plugin does not have input
56   // focus.
57   void set_send_mouse_input_when_unfocused(bool send) {
58     send_mouse_input_when_unfocused_ = send;
59   }
60
61  private:
62   enum MouseLockState {
63     MouseLockDisallowed,
64     MouseLockOff,
65     MouseLockRequestPending,
66     MouseLockOn,
67     MouseLockCancelling
68   };
69
70   // pp::MouseLock interface.
71   void MouseLockLost() override;
72
73   // Requests the browser to lock the mouse and hides the cursor.
74   void RequestMouseLock();
75
76   // Requests the browser to cancel mouse lock and restores the cursor once
77   // the lock is gone.
78   void CancelMouseLock();
79
80   // Applies |cursor_image_| as the custom pointer or uses the standard arrow
81   // pointer if |cursor_image_| is not available.
82   void UpdateMouseCursor();
83
84   // Handles completion of the mouse lock request issued by RequestMouseLock().
85   void OnMouseLocked(int error);
86
87   pp::Instance* instance_;
88   protocol::InputStub* input_stub_;
89
90   pp::CompletionCallbackFactory<PepperInputHandler> callback_factory_;
91
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_;
96
97   // Hot spot for |cursor_image_|.
98   pp::Point cursor_hotspot_;
99
100   // True if the plugin has focus.
101   bool has_focus_;
102
103   // True if the plugin should respond to mouse input even if it does not have
104   // keyboard focus.
105   bool send_mouse_input_when_unfocused_;
106
107   MouseLockState mouse_lock_state_;
108
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_;
114
115   DISALLOW_COPY_AND_ASSIGN(PepperInputHandler);
116 };
117
118 }  // namespace remoting
119
120 #endif  // REMOTING_CLIENT_PLUGIN_PEPPER_INPUT_HANDLER_H_