| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_ | 5 #ifndef CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_ |
| 6 #define CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_ | 6 #define CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "content/public/renderer/render_view_observer.h" | 10 #include "content/common/content_export.h" |
| 11 | |
| 12 class RenderViewImpl; | |
| 13 | 11 |
| 14 namespace WebKit { | 12 namespace WebKit { |
| 15 class WebMouseEvent; | 13 class WebMouseEvent; |
| 16 class WebWidget; | |
| 17 } // namespace WebKit | 14 } // namespace WebKit |
| 18 | 15 |
| 19 namespace webkit{ | 16 class CONTENT_EXPORT MouseLockDispatcher { |
| 20 namespace ppapi { | |
| 21 class PluginInstance; | |
| 22 } // namespace ppapi | |
| 23 } // namespace webkit | |
| 24 | |
| 25 // MouseLockDispatcher is owned by RenderViewImpl. | |
| 26 class CONTENT_EXPORT MouseLockDispatcher : public content::RenderViewObserver { | |
| 27 public: | 17 public: |
| 28 explicit MouseLockDispatcher(RenderViewImpl* render_view_impl); | 18 MouseLockDispatcher(); |
| 29 virtual ~MouseLockDispatcher(); | 19 virtual ~MouseLockDispatcher(); |
| 30 | 20 |
| 31 class LockTarget { | 21 class LockTarget { |
| 32 public: | 22 public: |
| 33 virtual ~LockTarget() {} | 23 virtual ~LockTarget() {} |
| 34 // A mouse lock request was pending and this reports success or failure. | 24 // A mouse lock request was pending and this reports success or failure. |
| 35 virtual void OnLockMouseACK(bool succeeded) = 0; | 25 virtual void OnLockMouseACK(bool succeeded) = 0; |
| 36 // A mouse lock was in place, but has been lost. | 26 // A mouse lock was in place, but has been lost. |
| 37 virtual void OnMouseLockLost() = 0; | 27 virtual void OnMouseLockLost() = 0; |
| 38 // A mouse lock is enabled and mouse events are being delievered. | 28 // A mouse lock is enabled and mouse events are being delievered. |
| 39 virtual bool HandleMouseLockedInputEvent( | 29 virtual bool HandleMouseLockedInputEvent( |
| 40 const WebKit::WebMouseEvent& event) = 0; | 30 const WebKit::WebMouseEvent& event) = 0; |
| 41 }; | 31 }; |
| 42 | 32 |
| 43 // Locks the mouse to the |target|. If true is returned, an asynchronous | 33 // Locks the mouse to the |target|. If true is returned, an asynchronous |
| 44 // response to target->OnLockMouseACK() will follow. | 34 // response to target->OnLockMouseACK() will follow. |
| 45 bool LockMouse(LockTarget* target); | 35 bool LockMouse(LockTarget* target); |
| 46 // Request to unlock the mouse. An asynchronous response to | 36 // Request to unlock the mouse. An asynchronous response to |
| 47 // target->OnMouseLockLost() will follow. | 37 // target->OnMouseLockLost() will follow. |
| 48 void UnlockMouse(LockTarget* target); | 38 void UnlockMouse(LockTarget* target); |
| 49 // Clears out the reference to the |target| because it has or is being | 39 // Clears out the reference to the |target| because it has or is being |
| 50 // destroyed. Unlocks if locked. The pointer will not be accessed. | 40 // destroyed. Unlocks if locked. The pointer will not be accessed. |
| 51 void OnLockTargetDestroyed(LockTarget* target); | 41 void OnLockTargetDestroyed(LockTarget* target); |
| 52 bool IsMouseLockedTo(LockTarget* target); | 42 bool IsMouseLockedTo(LockTarget* target); |
| 53 | 43 |
| 54 // Allow lock target to consumed a mouse event, if it does return true. | 44 // Allow lock target to consumed a mouse event, if it does return true. |
| 55 bool WillHandleMouseEvent(const WebKit::WebMouseEvent& event); | 45 bool WillHandleMouseEvent(const WebKit::WebMouseEvent& event); |
| 56 | 46 |
| 57 private: | 47 // Subclasses or users have to call these methods to report mouse lock events |
| 58 // RenderView::Observer implementation. | 48 // from the browser. |
| 59 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 60 | |
| 61 // IPC handlers. | |
| 62 void OnLockMouseACK(bool succeeded); | 49 void OnLockMouseACK(bool succeeded); |
| 63 void OnMouseLockLost(); | 50 void OnMouseLockLost(); |
| 64 | 51 |
| 52 protected: |
| 53 // Subclasses must implement these methods to send mouse lock requests to the |
| 54 // browser. |
| 55 virtual void SendLockMouseRequest(bool unlocked_by_target) = 0; |
| 56 virtual void SendUnlockMouseRequest() = 0; |
| 57 |
| 58 private: |
| 65 bool MouseLockedOrPendingAction() const { | 59 bool MouseLockedOrPendingAction() const { |
| 66 return mouse_locked_ || pending_lock_request_ || pending_unlock_request_; | 60 return mouse_locked_ || pending_lock_request_ || pending_unlock_request_; |
| 67 } | 61 } |
| 68 | 62 |
| 69 RenderViewImpl* render_view_impl_; | |
| 70 | |
| 71 bool mouse_locked_; | 63 bool mouse_locked_; |
| 72 // If both |pending_lock_request_| and |pending_unlock_request_| are true, | 64 // If both |pending_lock_request_| and |pending_unlock_request_| are true, |
| 73 // it means a lock request was sent before an unlock request and we haven't | 65 // it means a lock request was sent before an unlock request and we haven't |
| 74 // received responses for them. The logic in LockMouse() makes sure that a | 66 // received responses for them. The logic in LockMouse() makes sure that a |
| 75 // lock request won't be sent when there is a pending unlock request. | 67 // lock request won't be sent when there is a pending unlock request. |
| 76 bool pending_lock_request_; | 68 bool pending_lock_request_; |
| 77 bool pending_unlock_request_; | 69 bool pending_unlock_request_; |
| 78 | 70 |
| 79 // Used when locking to indicate when a target application has voluntarily | 71 // Used when locking to indicate when a target application has voluntarily |
| 80 // unlocked and desires to relock the mouse. If the mouse is unlocked due | 72 // unlocked and desires to relock the mouse. If the mouse is unlocked due |
| 81 // to ESC being pressed by the user, this will be false | 73 // to ESC being pressed by the user, this will be false |
| 82 bool unlocked_by_target_; | 74 bool unlocked_by_target_; |
| 83 | 75 |
| 84 // |target_| is the pending or current owner of mouse lock. We retain a non | 76 // |target_| is the pending or current owner of mouse lock. We retain a non |
| 85 // owning reference here that must be cleared by |OnLockTargetDestroyed| | 77 // owning reference here that must be cleared by |OnLockTargetDestroyed| |
| 86 // when it is destroyed. | 78 // when it is destroyed. |
| 87 LockTarget* target_; | 79 LockTarget* target_; |
| 88 | 80 |
| 89 DISALLOW_COPY_AND_ASSIGN(MouseLockDispatcher); | 81 DISALLOW_COPY_AND_ASSIGN(MouseLockDispatcher); |
| 90 }; | 82 }; |
| 91 | 83 |
| 92 #endif // CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_ | 84 #endif // CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_ |
| OLD | NEW |