blob: 546088ea96253d2ca2a4ee097ec65e7ad73a90bc [file] [log] [blame]
[email protected]217690d2012-01-27 07:33:111// 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 CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_
6#define CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_
[email protected]217690d2012-01-27 07:33:117
avi1023d012015-12-25 02:39:148#include "base/macros.h"
[email protected]89054502012-06-03 10:29:249#include "content/common/content_export.h"
[email protected]217690d2012-01-27 07:33:1110
[email protected]180ef242013-11-07 06:50:4611namespace blink {
[email protected]217690d2012-01-27 07:33:1112class WebMouseEvent;
[email protected]180ef242013-11-07 06:50:4613} // namespace blink
[email protected]217690d2012-01-27 07:33:1114
[email protected]e9ff79c2012-10-19 21:31:2615namespace content {
16
[email protected]89054502012-06-03 10:29:2417class CONTENT_EXPORT MouseLockDispatcher {
[email protected]217690d2012-01-27 07:33:1118 public:
[email protected]89054502012-06-03 10:29:2419 MouseLockDispatcher();
[email protected]217690d2012-01-27 07:33:1120 virtual ~MouseLockDispatcher();
21
22 class LockTarget {
23 public:
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(
[email protected]180ef242013-11-07 06:50:4631 const blink::WebMouseEvent& event) = 0;
[email protected]217690d2012-01-27 07:33:1132 };
33
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);
44
45 // Allow lock target to consumed a mouse event, if it does return true.
[email protected]180ef242013-11-07 06:50:4646 bool WillHandleMouseEvent(const blink::WebMouseEvent& event);
[email protected]217690d2012-01-27 07:33:1147
[email protected]89054502012-06-03 10:29:2448 // Subclasses or users have to call these methods to report mouse lock events
49 // from the browser.
[email protected]217690d2012-01-27 07:33:1150 void OnLockMouseACK(bool succeeded);
51 void OnMouseLockLost();
52
[email protected]89054502012-06-03 10:29:2453 protected:
54 // Subclasses must implement these methods to send mouse lock requests to the
55 // browser.
56 virtual void SendLockMouseRequest(bool unlocked_by_target) = 0;
57 virtual void SendUnlockMouseRequest() = 0;
58
59 private:
[email protected]217690d2012-01-27 07:33:1160 bool MouseLockedOrPendingAction() const {
61 return mouse_locked_ || pending_lock_request_ || pending_unlock_request_;
62 }
63
[email protected]217690d2012-01-27 07:33:1164 bool mouse_locked_;
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_;
71
[email protected]a9c81f02012-06-01 00:15:4472 // 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_;
76
[email protected]217690d2012-01-27 07:33:1177 // |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.
80 LockTarget* target_;
81
82 DISALLOW_COPY_AND_ASSIGN(MouseLockDispatcher);
83};
84
[email protected]e9ff79c2012-10-19 21:31:2685} // namespace content
86
[email protected]217690d2012-01-27 07:33:1187#endif // CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_