1 // Copyright 2014 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_MOUSE_LOCKER_H_
6 #define REMOTING_CLIENT_PLUGIN_PEPPER_MOUSE_LOCKER_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ppapi/cpp/mouse_lock.h"
11 #include "ppapi/utility/completion_callback_factory.h"
12 #include "remoting/protocol/cursor_shape_stub.h"
20 class PepperInputHandler
;
22 class PepperMouseLocker
: public pp::MouseLock
,
23 public protocol::CursorShapeStub
{
25 // |instance| and |cursor_stub| must outlive |this|.
27 pp::Instance
* instance
,
28 const base::Callback
<void(bool)>& enable_mouse_deltas
,
29 protocol::CursorShapeStub
* cursor_stub
);
30 ~PepperMouseLocker() override
;
32 // Must be called when the plugin receives or loses focus.
33 void DidChangeFocus(bool has_focus
);
35 // protocol::CursorShapeStub interface.
36 void SetCursorShape(const protocol::CursorShapeInfo
& cursor_shape
) override
;
41 MouseLockRequestPending
,
46 // pp::MouseLock interface.
47 void MouseLockLost() override
;
49 // Handles completion of the mouse lock request issued by RequestMouseLock().
50 void OnMouseLocked(int error
);
52 // Sets the mouse-lock state to "off" and restores the normal mouse cursor.
53 void OnMouseLockOff();
55 // Requests the browser to lock the mouse and hides the cursor.
56 void RequestMouseLock();
58 // Requests the browser to cancel mouse lock and restores the cursor once
60 void CancelMouseLock();
62 // Callback used to enable/disable delta motion fields in mouse events.
63 base::Callback
<void(bool)> enable_mouse_deltas_
;
65 // Stub used to set the cursor that will actually be displayed.
66 protocol::CursorShapeStub
* cursor_stub_
;
68 // Copy of the most-recently-set cursor, to set when mouse-lock is cancelled.
69 scoped_ptr
<protocol::CursorShapeInfo
> cursor_shape_
;
71 // Used to create PPAPI callbacks that will be abandoned when |this| is
73 pp::CompletionCallbackFactory
<PepperMouseLocker
> callback_factory_
;
75 // True if the plugin has focus.
78 // Holds the current mouse lock state.
79 MouseLockState mouse_lock_state_
;
81 DISALLOW_COPY_AND_ASSIGN(PepperMouseLocker
);
84 } // namespace remoting
86 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_MOUSE_LOCKER_H_