Refactor android test results logging.
[chromium-blink-merge.git] / ppapi / cpp / mouse_lock.h
blobf52fe10b060b020efc4adbb911b6681784c1e72c
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 /// </code>
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 /// </code>
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. The browser will permit
65 /// mouse lock only while the tab is in fullscreen mode.
66 ///
67 /// While the mouse is locked, the cursor is implicitly hidden from the user.
68 /// Any movement of the mouse will generate a
69 /// <code>PP_INPUTEVENT_TYPE_MOUSEMOVE</code> event. The
70 /// <code>GetPosition()</code> function in <code>InputEvent()</code>
71 /// reports the last known mouse position just as mouse lock was
72 /// entered. The <code>GetMovement()</code> function provides relative
73 /// movement information indicating what the change in position of the mouse
74 /// would be had it not been locked.
75 ///
76 /// The browser may revoke the mouse lock for reasons including (but not
77 /// limited to) the user pressing the ESC key, the user activating another
78 /// program using a reserved keystroke (e.g. ALT+TAB), or some other system
79 /// event.
80 ///
81 /// @param[in] cc A <code>CompletionCallback</code> to be called upon
82 /// completion.
83 ///
84 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
85 int32_t LockMouse(const CompletionCallback& cc);
87 /// UnlockMouse causes the mouse to be unlocked, allowing it to track user
88 /// movement again. This is an asynchronous operation. The module instance
89 /// will be notified using the <code>PPP_MouseLock</code> interface when it
90 /// has lost the mouse lock.
91 void UnlockMouse();
93 private:
94 InstanceHandle associated_instance_;
97 } // namespace pp
99 #endif // PPAPI_CPP_MOUSE_LOCK_H_