blob: ed5b07aa832b3221825fc72ee94eec15a2fc241d [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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 PPAPI_CPP_MOUSE_LOCK_H_
6#define PPAPI_CPP_MOUSE_LOCK_H_
7
8#include "ppapi/c/pp_stdint.h"
9#include "ppapi/cpp/instance_handle.h"
10
11/// @file
12/// This file defines the API for locking the target of mouse events to a
13/// specific module instance.
14
15namespace pp {
16
17class CompletionCallback;
18class Instance;
19
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>
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010029/// @code
Torne (Richard Coles)58218062012-11-14 11:43:16 +000030/// class MyInstance : public pp::Instance, public pp::MouseLock {
31/// class MyInstance() : pp::MouseLock(this) {
32/// }
33/// ...
34/// };
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010035/// @endcode
Torne (Richard Coles)58218062012-11-14 11:43:16 +000036///
37/// <strong>Example (composition):</strong>
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010038/// @code
Torne (Richard Coles)58218062012-11-14 11:43:16 +000039/// 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/// };
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010049/// @endcode
Torne (Richard Coles)58218062012-11-14 11:43:16 +000050class 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);
57
58 /// Destructor.
59 virtual ~MouseLock();
60
61 /// PPP_MouseLock functions exposed as virtual functions for you to override.
62 virtual void MouseLockLost() = 0;
63
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000064 /// LockMouse() requests the mouse to be locked.
Torne (Richard Coles)58218062012-11-14 11:43:16 +000065 ///
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);
85
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();
91
92 private:
93 InstanceHandle associated_instance_;
94};
95
96} // namespace pp
97
98#endif // PPAPI_CPP_MOUSE_LOCK_H_