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"
12 /// This file defines the API for locking the target of mouse events to a
13 /// specific module instance.
17 class CompletionCallback
;
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.
25 /// You would typically use this class by inheritance on your instance or by
28 /// <strong>Example (inheritance):</strong>
30 /// class MyInstance : public pp::Instance, public pp::MouseLock {
31 /// class MyInstance() : pp::MouseLock(this) {
37 /// <strong>Example (composition):</strong>
39 /// class MyMouseLock : public pp::MouseLock {
43 /// class MyInstance : public pp::Instance {
44 /// MyInstance() : mouse_lock_(this) {
47 /// MyMouseLock mouse_lock_;
52 /// A constructor for creating a <code>MouseLock</code>.
54 /// @param[in] instance The instance with which this resource will be
56 explicit MouseLock(Instance
* instance
);
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.
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.
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
80 /// @param[in] cc A <code>CompletionCallback</code> to be called upon
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.
93 InstanceHandle associated_instance_
;
98 #endif // PPAPI_CPP_MOUSE_LOCK_H_