[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 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. | ||||
4 | |||||
5 | #ifndef CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_ | ||||
6 | #define CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_ | ||||
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 7 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 8 | #include "base/macros.h" |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 9 | #include "content/common/content_export.h" |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 10 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 11 | namespace blink { |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 12 | class WebMouseEvent; |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 13 | } // namespace blink |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 14 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 15 | namespace content { |
16 | |||||
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 17 | class CONTENT_EXPORT MouseLockDispatcher { |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 18 | public: |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 19 | MouseLockDispatcher(); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 20 | 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] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 31 | const blink::WebMouseEvent& event) = 0; |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 32 | }; |
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] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 46 | bool WillHandleMouseEvent(const blink::WebMouseEvent& event); |
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 47 | |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 48 | // Subclasses or users have to call these methods to report mouse lock events |
49 | // from the browser. | ||||
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 50 | void OnLockMouseACK(bool succeeded); |
51 | void OnMouseLockLost(); | ||||
52 | |||||
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 53 | 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] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 60 | bool MouseLockedOrPendingAction() const { |
61 | return mouse_locked_ || pending_lock_request_ || pending_unlock_request_; | ||||
62 | } | ||||
63 | |||||
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 64 | 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] | a9c81f0 | 2012-06-01 00:15:44 | [diff] [blame] | 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_; | ||||
76 | |||||
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 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. | ||||
80 | LockTarget* target_; | ||||
81 | |||||
82 | DISALLOW_COPY_AND_ASSIGN(MouseLockDispatcher); | ||||
83 | }; | ||||
84 | |||||
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 85 | } // namespace content |
86 | |||||
[email protected] | 217690d | 2012-01-27 07:33:11 | [diff] [blame] | 87 | #endif // CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_ |