| 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 #include "content/renderer/mouse_lock_dispatcher.h" | 5 #include "content/renderer/mouse_lock_dispatcher.h" |
| 6 | 6 |
| 7 #include "content/common/view_messages.h" | 7 #include "content/common/view_messages.h" |
| 8 #include "content/renderer/render_view_impl.h" | 8 #include "content/renderer/render_view_impl.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" |
| 12 | 12 |
| 13 MouseLockDispatcher::MouseLockDispatcher(RenderViewImpl* render_view_impl) | 13 MouseLockDispatcher::MouseLockDispatcher(RenderViewImpl* render_view_impl) |
| 14 : content::RenderViewObserver(render_view_impl), | 14 : content::RenderViewObserver(render_view_impl), |
| 15 render_view_impl_(render_view_impl), | 15 render_view_impl_(render_view_impl), |
| 16 mouse_locked_(false), | 16 mouse_locked_(false), |
| 17 pending_lock_request_(false), | 17 pending_lock_request_(false), |
| 18 pending_unlock_request_(false), | 18 pending_unlock_request_(false), |
| 19 unlock_source_(content::NOT_TARGET), |
| 19 target_(NULL) { | 20 target_(NULL) { |
| 20 } | 21 } |
| 21 | 22 |
| 22 MouseLockDispatcher::~MouseLockDispatcher() { | 23 MouseLockDispatcher::~MouseLockDispatcher() { |
| 23 } | 24 } |
| 24 | 25 |
| 25 bool MouseLockDispatcher::LockMouse(LockTarget* target) { | 26 bool MouseLockDispatcher::LockMouse(LockTarget* target) { |
| 26 if (MouseLockedOrPendingAction()) | 27 if (MouseLockedOrPendingAction()) |
| 27 return false; | 28 return false; |
| 28 | 29 |
| 29 pending_lock_request_ = true; | 30 pending_lock_request_ = true; |
| 30 target_ = target; | 31 target_ = target; |
| 31 | 32 |
| 32 bool user_gesture = | 33 bool user_gesture = |
| 33 render_view_impl_->webview() && | 34 render_view_impl_->webview() && |
| 34 render_view_impl_->webview()->mainFrame() && | 35 render_view_impl_->webview()->mainFrame() && |
| 35 render_view_impl_->webview()->mainFrame()->isProcessingUserGesture(); | 36 render_view_impl_->webview()->mainFrame()->isProcessingUserGesture(); |
| 36 | 37 |
| 37 Send(new ViewHostMsg_LockMouse(routing_id(), user_gesture)); | 38 Send( |
| 39 new ViewHostMsg_LockMouse(routing_id(), |
| 40 user_gesture ? content::USER_GESTURE : content::NOT_USER_GESTURE, |
| 41 unlock_source_)); |
| 42 // reset the source |
| 43 unlock_source_ = content::NOT_TARGET; |
| 38 return true; | 44 return true; |
| 39 } | 45 } |
| 40 | 46 |
| 41 void MouseLockDispatcher::UnlockMouse(LockTarget* target) { | 47 void MouseLockDispatcher::UnlockMouse(LockTarget* target) { |
| 42 if (target && target == target_ && !pending_unlock_request_) { | 48 if (target && target == target_ && !pending_unlock_request_) { |
| 43 pending_unlock_request_ = true; | 49 pending_unlock_request_ = true; |
| 50 unlock_source_ = content::TARGET; |
| 44 Send(new ViewHostMsg_UnlockMouse(routing_id())); | 51 Send(new ViewHostMsg_UnlockMouse(routing_id())); |
| 45 } | 52 } |
| 46 } | 53 } |
| 47 | 54 |
| 48 void MouseLockDispatcher::OnLockTargetDestroyed(LockTarget* target) { | 55 void MouseLockDispatcher::OnLockTargetDestroyed(LockTarget* target) { |
| 49 if (target == target_) { | 56 if (target == target_) { |
| 50 UnlockMouse(target); | 57 UnlockMouse(target); |
| 51 target_ = NULL; | 58 target_ = NULL; |
| 52 } | 59 } |
| 53 } | 60 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 120 |
| 114 LockTarget* last_target = target_; | 121 LockTarget* last_target = target_; |
| 115 target_ = NULL; | 122 target_ = NULL; |
| 116 | 123 |
| 117 // Callbacks made after all state modification to prevent reentrant errors | 124 // Callbacks made after all state modification to prevent reentrant errors |
| 118 // such as OnMouseLockLost() synchronously calling LockMouse(). | 125 // such as OnMouseLockLost() synchronously calling LockMouse(). |
| 119 | 126 |
| 120 if (last_target) | 127 if (last_target) |
| 121 last_target->OnMouseLockLost(); | 128 last_target->OnMouseLockLost(); |
| 122 } | 129 } |
| 123 | |
| OLD | NEW |