Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "content/public/renderer/render_view_observer.h" | |
| 11 | |
| 12 class RenderViewImpl; | |
| 13 | |
| 14 namespace WebKit { | |
| 15 class WebMouseEvent; | |
| 16 class WebWidget; | |
| 17 } // namespace WebKit | |
| 18 | |
| 19 namespace webkit{ | |
| 20 namespace ppapi { | |
| 21 class PluginInstance; | |
| 22 } // namespace ppapi | |
| 23 } // namespace webkit | |
| 24 | |
| 25 // MouseLockDispatcher is owned by RenderViewImpl. | |
| 26 class MouseLockDispatcher : public content::RenderViewObserver { | |
| 27 public: | |
| 28 explicit MouseLockDispatcher(RenderViewImpl* render_view_impl); | |
| 29 virtual ~MouseLockDispatcher(); | |
| 30 | |
| 31 class LockTarget { | |
|
yzshen1
2012/01/24 18:56:08
Please define a virtual destructor.
scheib
2012/01/25 00:27:11
Done.
| |
| 32 public: | |
| 33 // A mouse lock request was pending and this reports success or failure. | |
| 34 virtual void OnLockMouseACK(bool succeeded) = 0; | |
| 35 // A mouse lock was in place, but has been lost. | |
| 36 virtual void OnMouseLockLost() = 0; | |
| 37 // A mouse lock is enabled and mouse events are being delievered. | |
| 38 virtual bool HandleMouseLockedInputEvent( | |
| 39 const WebKit::WebMouseEvent& event) = 0; | |
| 40 }; | |
| 41 | |
| 42 static LockTarget* CreateLockTarget(webkit::ppapi::PluginInstance* plugin); | |
|
yzshen1
2012/01/24 18:56:08
Please comment about the ownership of the returned
scheib
2012/01/25 00:27:11
Done.
| |
| 43 static LockTarget* CreateLockTarget(WebKit::WebWidget* webwidget); | |
| 44 | |
| 45 // Lock the mouse to the |target|. If true is returned, an asynchronous | |
|
yzshen1
2012/01/24 18:56:08
Lock -> Locks. (And some other places.)
scheib
2012/01/25 00:27:11
Done. er.. but I'm not sure if we have a preferred
yzshen1
2012/01/25 18:10:01
According to our code style, the second one is pre
| |
| 46 // response to target->OnLockMouseACK() will follow. | |
| 47 bool LockMouse(LockTarget* target); | |
| 48 // Request to unlock the mouse. An asynchronous | |
|
yzshen1
2012/01/24 18:56:08
Fit as many words in one line as possible. (And so
scheib
2012/01/25 00:27:11
Done.
| |
| 49 // response to target->OnMouseLockLost() will follow. | |
| 50 void UnlockMouse(LockTarget* target); | |
| 51 // Request to unlock and clear references to the target, the pointer is no | |
| 52 // longer valid. The pointer will not be accessed again.. | |
|
yzshen1
2012/01/24 18:56:08
.. -> .
scheib
2012/01/25 00:27:11
Done.
| |
| 53 void UnlockMouseAndClearTarget(LockTarget* target); | |
| 54 bool IsMouseLockedTo(LockTarget* target); | |
| 55 | |
| 56 // Allow lock target to consumed a mouse event, if it does returns true. | |
|
yzshen1
2012/01/24 18:56:08
returns -> return.
scheib
2012/01/25 00:27:11
Done.
| |
| 57 bool WillHandleMouseEvent(const WebKit::WebMouseEvent& event); | |
| 58 | |
| 59 private: | |
| 60 // RenderView::Observer implementation. | |
| 61 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 62 | |
| 63 // IPC handlers. | |
| 64 void OnLockMouseACK(bool succeeded); | |
| 65 void OnMouseLockLost(); | |
| 66 | |
| 67 bool MouseLockedOrPendingAction() const { | |
| 68 return mouse_locked_ || pending_lock_request_ || pending_unlock_request_; | |
| 69 } | |
| 70 | |
| 71 RenderViewImpl* render_view_impl_; | |
| 72 | |
| 73 bool mouse_locked_; | |
| 74 // If both |pending_lock_request_| and |pending_unlock_request_| are true, | |
| 75 // it means a lock request was sent before an unlock request and we haven't | |
| 76 // received responses for them. | |
| 77 // The logic in LockMouse() makes sure that a lock request won't be sent when | |
| 78 // there is a pending unlock request. | |
| 79 bool pending_lock_request_; | |
| 80 bool pending_unlock_request_; | |
| 81 | |
| 82 // |target_| is the pending or current owner of mouse lock. We retain a | |
| 83 // non owning reference here that must be cleared by | |
| 84 // |UnlockMouseAndClearTarget| when it is destroyed. | |
| 85 LockTarget* target_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(MouseLockDispatcher); | |
| 88 }; | |
| 89 | |
| 90 #endif // CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_ | |
| OLD | NEW |