| 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/WebInputEvent.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" |
| 11 | 12 |
| 12 MouseLockDispatcher::MouseLockDispatcher(RenderViewImpl* render_view_impl) | 13 MouseLockDispatcher::MouseLockDispatcher(RenderViewImpl* render_view_impl) |
| 13 : content::RenderViewObserver(render_view_impl), | 14 : content::RenderViewObserver(render_view_impl), |
| 14 render_view_impl_(render_view_impl), | 15 render_view_impl_(render_view_impl), |
| 15 mouse_locked_(false), | 16 mouse_locked_(false), |
| 16 pending_lock_request_(false), | 17 pending_lock_request_(false), |
| 17 pending_unlock_request_(false), | 18 pending_unlock_request_(false), |
| 18 target_(NULL) { | 19 target_(NULL) { |
| 19 } | 20 } |
| 20 | 21 |
| 21 MouseLockDispatcher::~MouseLockDispatcher() { | 22 MouseLockDispatcher::~MouseLockDispatcher() { |
| 22 } | 23 } |
| 23 | 24 |
| 24 bool MouseLockDispatcher::LockMouse(LockTarget* target) { | 25 bool MouseLockDispatcher::LockMouse(LockTarget* target) { |
| 25 if (MouseLockedOrPendingAction()) | 26 if (MouseLockedOrPendingAction()) |
| 26 return false; | 27 return false; |
| 27 | 28 |
| 28 pending_lock_request_ = true; | 29 pending_lock_request_ = true; |
| 29 target_ = target; | 30 target_ = target; |
| 30 | 31 |
| 31 Send(new ViewHostMsg_LockMouse(routing_id())); | 32 bool user_gesture = |
| 33 render_view_impl_->webview() && |
| 34 render_view_impl_->webview()->mainFrame() && |
| 35 render_view_impl_->webview()->mainFrame()->isProcessingUserGesture(); |
| 36 |
| 37 Send(new ViewHostMsg_LockMouse(routing_id(), user_gesture)); |
| 32 return true; | 38 return true; |
| 33 } | 39 } |
| 34 | 40 |
| 35 void MouseLockDispatcher::UnlockMouse(LockTarget* target) { | 41 void MouseLockDispatcher::UnlockMouse(LockTarget* target) { |
| 36 if (target && target == target_ && !pending_unlock_request_) { | 42 if (target && target == target_ && !pending_unlock_request_) { |
| 37 pending_unlock_request_ = true; | 43 pending_unlock_request_ = true; |
| 38 Send(new ViewHostMsg_UnlockMouse(routing_id())); | 44 Send(new ViewHostMsg_UnlockMouse(routing_id())); |
| 39 } | 45 } |
| 40 } | 46 } |
| 41 | 47 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 LockTarget* last_target = target_; | 114 LockTarget* last_target = target_; |
| 109 target_ = NULL; | 115 target_ = NULL; |
| 110 | 116 |
| 111 // Callbacks made after all state modification to prevent reentrant errors | 117 // Callbacks made after all state modification to prevent reentrant errors |
| 112 // such as OnMouseLockLost() synchronously calling LockMouse(). | 118 // such as OnMouseLockLost() synchronously calling LockMouse(). |
| 113 | 119 |
| 114 if (last_target) | 120 if (last_target) |
| 115 last_target->OnMouseLockLost(); | 121 last_target->OnMouseLockLost(); |
| 116 } | 122 } |
| 117 | 123 |
| OLD | NEW |