Roll src/third_party/skia b9ed884:8566539
[chromium-blink-merge.git] / ppapi / cpp / mouse_lock.h
blobed5b07aa832b3221825fc72ee94eec15a2fc241d
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 PPAPI_CPP_MOUSE_LOCK_H_
6 #define PPAPI_CPP_MOUSE_LOCK_H_
8 #include "ppapi/c/pp_stdint.h"
9 #include "ppapi/cpp/instance_handle.h"
11 /// @file
12 /// This file defines the API for locking the target of mouse events to a
13 /// specific module instance.
15 namespace pp {
17 class CompletionCallback;
18 class Instance;
20 /// This class allows you to associate the <code>PPP_MouseLock</code> and
21 /// <code>PPB_MouseLock</code> C-based interfaces with an object. It associates
22 /// itself with the given instance, and registers as the global handler for
23 /// handling the <code>PPP_MouseLock</code> interface that the browser calls.
24 ///
25 /// You would typically use this class by inheritance on your instance or by
26 /// composition.
27 ///
28 /// <strong>Example (inheritance):</strong>
29 /// @code
30 /// class MyInstance : public pp::Instance, public pp::MouseLock {
31 /// class MyInstance() : pp::MouseLock(this) {
32 /// }
33 /// ...
34 /// };
35 /// @endcode
36 ///
37 /// <strong>Example (composition):</strong>
38 /// @code
39 /// class MyMouseLock : public pp::MouseLock {
40 /// ...
41 /// };
42 ///
43 /// class MyInstance : public pp::Instance {
44 /// MyInstance() : mouse_lock_(this) {
45 /// }
46 ///
47 /// MyMouseLock mouse_lock_;
48 /// };
49 /// @endcode
50 class MouseLock {
51 public:
52 /// A constructor for creating a <code>MouseLock</code>.
53 ///
54 /// @param[in] instance The instance with which this resource will be
55 /// associated.
56 explicit MouseLock(Instance* instance);
58 /// Destructor.
59 virtual ~MouseLock();
61 /// PPP_MouseLock functions exposed as virtual functions for you to override.
62 virtual void MouseLockLost() = 0;
64 /// LockMouse() requests the mouse to be locked.
65 ///
66 /// While the mouse is locked, the cursor is implicitly hidden from the user.
67 /// Any movement of the mouse will generate a
68 /// <code>PP_INPUTEVENT_TYPE_MOUSEMOVE</code> event. The
69 /// <code>GetPosition()</code> function in <code>InputEvent()</code>
70 /// reports the last known mouse position just as mouse lock was
71 /// entered. The <code>GetMovement()</code> function provides relative
72 /// movement information indicating what the change in position of the mouse
73 /// would be had it not been locked.
74 ///
75 /// The browser may revoke the mouse lock for reasons including (but not
76 /// limited to) the user pressing the ESC key, the user activating another
77 /// program using a reserved keystroke (e.g. ALT+TAB), or some other system
78 /// event.
79 ///
80 /// @param[in] cc A <code>CompletionCallback</code> to be called upon
81 /// completion.
82 ///
83 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
84 int32_t LockMouse(const CompletionCallback& cc);
86 /// UnlockMouse causes the mouse to be unlocked, allowing it to track user
87 /// movement again. This is an asynchronous operation. The module instance
88 /// will be notified using the <code>PPP_MouseLock</code> interface when it
89 /// has lost the mouse lock.
90 void UnlockMouse();
92 private:
93 InstanceHandle associated_instance_;
96 } // namespace pp
98 #endif // PPAPI_CPP_MOUSE_LOCK_H_