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 CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_
6 #define CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_
8 #include "base/basictypes.h"
9 #include "content/common/content_export.h"
17 class CONTENT_EXPORT MouseLockDispatcher
{
19 MouseLockDispatcher();
20 virtual ~MouseLockDispatcher();
24 virtual ~LockTarget() {}
25 // A mouse lock request was pending and this reports success or failure.
26 virtual void OnLockMouseACK(bool succeeded
) = 0;
27 // A mouse lock was in place, but has been lost.
28 virtual void OnMouseLockLost() = 0;
29 // A mouse lock is enabled and mouse events are being delievered.
30 virtual bool HandleMouseLockedInputEvent(
31 const blink::WebMouseEvent
& event
) = 0;
34 // Locks the mouse to the |target|. If true is returned, an asynchronous
35 // response to target->OnLockMouseACK() will follow.
36 bool LockMouse(LockTarget
* target
);
37 // Request to unlock the mouse. An asynchronous response to
38 // target->OnMouseLockLost() will follow.
39 void UnlockMouse(LockTarget
* target
);
40 // Clears out the reference to the |target| because it has or is being
41 // destroyed. Unlocks if locked. The pointer will not be accessed.
42 void OnLockTargetDestroyed(LockTarget
* target
);
43 bool IsMouseLockedTo(LockTarget
* target
);
45 // Allow lock target to consumed a mouse event, if it does return true.
46 bool WillHandleMouseEvent(const blink::WebMouseEvent
& event
);
48 // Subclasses or users have to call these methods to report mouse lock events
50 void OnLockMouseACK(bool succeeded
);
51 void OnMouseLockLost();
54 // Subclasses must implement these methods to send mouse lock requests to the
56 virtual void SendLockMouseRequest(bool unlocked_by_target
) = 0;
57 virtual void SendUnlockMouseRequest() = 0;
60 bool MouseLockedOrPendingAction() const {
61 return mouse_locked_
|| pending_lock_request_
|| pending_unlock_request_
;
65 // If both |pending_lock_request_| and |pending_unlock_request_| are true,
66 // it means a lock request was sent before an unlock request and we haven't
67 // received responses for them. The logic in LockMouse() makes sure that a
68 // lock request won't be sent when there is a pending unlock request.
69 bool pending_lock_request_
;
70 bool pending_unlock_request_
;
72 // Used when locking to indicate when a target application has voluntarily
73 // unlocked and desires to relock the mouse. If the mouse is unlocked due
74 // to ESC being pressed by the user, this will be false
75 bool unlocked_by_target_
;
77 // |target_| is the pending or current owner of mouse lock. We retain a non
78 // owning reference here that must be cleared by |OnLockTargetDestroyed|
79 // when it is destroyed.
82 DISALLOW_COPY_AND_ASSIGN(MouseLockDispatcher
);
85 } // namespace content
87 #endif // CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_