Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: content/renderer/mouse_lock_dispatcher.cc

Issue 10458008: Support mouse lock in Flash fullscreen mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/logging.h"
8 #include "content/renderer/render_view_impl.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
12 9
13 MouseLockDispatcher::MouseLockDispatcher(RenderViewImpl* render_view_impl) 10 MouseLockDispatcher::MouseLockDispatcher() : mouse_locked_(false),
14 : content::RenderViewObserver(render_view_impl), 11 pending_lock_request_(false),
15 render_view_impl_(render_view_impl), 12 pending_unlock_request_(false),
16 mouse_locked_(false), 13 unlocked_by_target_(false),
17 pending_lock_request_(false), 14 target_(NULL) {
18 pending_unlock_request_(false),
19 unlocked_by_target_(false),
20 target_(NULL) {
21 } 15 }
22 16
23 MouseLockDispatcher::~MouseLockDispatcher() { 17 MouseLockDispatcher::~MouseLockDispatcher() {
24 } 18 }
25 19
26 bool MouseLockDispatcher::LockMouse(LockTarget* target) { 20 bool MouseLockDispatcher::LockMouse(LockTarget* target) {
27 if (MouseLockedOrPendingAction()) 21 if (MouseLockedOrPendingAction())
28 return false; 22 return false;
29 23
30 pending_lock_request_ = true; 24 pending_lock_request_ = true;
31 target_ = target; 25 target_ = target;
32 26
33 bool user_gesture = 27 SendLockMouseRequest(unlocked_by_target_);
34 render_view_impl_->webview() &&
35 render_view_impl_->webview()->mainFrame() &&
36 render_view_impl_->webview()->mainFrame()->isProcessingUserGesture();
37 Send(new ViewHostMsg_LockMouse(routing_id(),
38 user_gesture,
39 unlocked_by_target_));
40 unlocked_by_target_ = false; 28 unlocked_by_target_ = false;
41 return true; 29 return true;
42 } 30 }
43 31
44 void MouseLockDispatcher::UnlockMouse(LockTarget* target) { 32 void MouseLockDispatcher::UnlockMouse(LockTarget* target) {
45 if (target && target == target_ && !pending_unlock_request_) { 33 if (target && target == target_ && !pending_unlock_request_) {
46 pending_unlock_request_ = true; 34 pending_unlock_request_ = true;
47 unlocked_by_target_ = true; 35 unlocked_by_target_ = true;
48 Send(new ViewHostMsg_UnlockMouse(routing_id())); 36 SendUnlockMouseRequest();
49 } 37 }
50 } 38 }
51 39
52 void MouseLockDispatcher::OnLockTargetDestroyed(LockTarget* target) { 40 void MouseLockDispatcher::OnLockTargetDestroyed(LockTarget* target) {
53 if (target == target_) { 41 if (target == target_) {
54 UnlockMouse(target); 42 UnlockMouse(target);
55 target_ = NULL; 43 target_ = NULL;
56 } 44 }
57 } 45 }
58 46
59 bool MouseLockDispatcher::IsMouseLockedTo(LockTarget* target) { 47 bool MouseLockDispatcher::IsMouseLockedTo(LockTarget* target) {
60 return mouse_locked_ && target_ == target; 48 return mouse_locked_ && target_ == target;
61 } 49 }
62 50
63 bool MouseLockDispatcher::WillHandleMouseEvent( 51 bool MouseLockDispatcher::WillHandleMouseEvent(
64 const WebKit::WebMouseEvent& event) { 52 const WebKit::WebMouseEvent& event) {
65 if (mouse_locked_ && target_) 53 if (mouse_locked_ && target_)
66 return target_->HandleMouseLockedInputEvent(event); 54 return target_->HandleMouseLockedInputEvent(event);
67 return false; 55 return false;
68 } 56 }
69 57
70 bool MouseLockDispatcher::OnMessageReceived(const IPC::Message& message) {
71 bool handled = true;
72 IPC_BEGIN_MESSAGE_MAP(MouseLockDispatcher, message)
73 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK)
74 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost)
75 IPC_MESSAGE_UNHANDLED(handled = false)
76 IPC_END_MESSAGE_MAP()
77 return handled;
78 }
79
80 void MouseLockDispatcher::OnLockMouseACK(bool succeeded) { 58 void MouseLockDispatcher::OnLockMouseACK(bool succeeded) {
81 DCHECK(!mouse_locked_ && pending_lock_request_); 59 DCHECK(!mouse_locked_ && pending_lock_request_);
82 60
83 mouse_locked_ = succeeded; 61 mouse_locked_ = succeeded;
84 pending_lock_request_ = false; 62 pending_lock_request_ = false;
85 if (pending_unlock_request_ && !succeeded) { 63 if (pending_unlock_request_ && !succeeded) {
86 // We have sent an unlock request after the lock request. However, since 64 // We have sent an unlock request after the lock request. However, since
87 // the lock request has failed, the unlock request will be ignored by the 65 // the lock request has failed, the unlock request will be ignored by the
88 // browser side and there won't be any response to it. 66 // browser side and there won't be any response to it.
89 pending_unlock_request_ = false; 67 pending_unlock_request_ = false;
90 } 68 }
91 69
92 LockTarget* last_target = target_; 70 LockTarget* last_target = target_;
93 if (!succeeded) 71 if (!succeeded)
94 target_ = NULL; 72 target_ = NULL;
95 73
96 // Callbacks made after all state modification to prevent reentrant errors 74 // Callbacks made after all state modification to prevent reentrant errors
97 // such as OnLockMouseACK() synchronously calling LockMouse(). 75 // such as OnLockMouseACK() synchronously calling LockMouse().
98 76
99 if (last_target) 77 if (last_target)
100 last_target->OnLockMouseACK(succeeded); 78 last_target->OnLockMouseACK(succeeded);
101
102 // Mouse Lock removes the system cursor and provides all mouse motion as
103 // .movementX/Y values on events all sent to a fixed target. This requires
104 // content to specifically request the mode to be entered.
105 // Mouse Capture is implicitly given for the duration of a drag event, and
106 // sends all mouse events to the initial target of the drag.
107 // If Lock is entered it supercedes any in progress Capture.
108 if (succeeded && render_view_impl_->webwidget())
109 render_view_impl_->webwidget()->mouseCaptureLost();
110 } 79 }
111 80
112 void MouseLockDispatcher::OnMouseLockLost() { 81 void MouseLockDispatcher::OnMouseLockLost() {
113 DCHECK(mouse_locked_ && !pending_lock_request_); 82 DCHECK(mouse_locked_ && !pending_lock_request_);
114 83
115 mouse_locked_ = false; 84 mouse_locked_ = false;
116 pending_unlock_request_ = false; 85 pending_unlock_request_ = false;
117 86
118 LockTarget* last_target = target_; 87 LockTarget* last_target = target_;
119 target_ = NULL; 88 target_ = NULL;
120 89
121 // Callbacks made after all state modification to prevent reentrant errors 90 // Callbacks made after all state modification to prevent reentrant errors
122 // such as OnMouseLockLost() synchronously calling LockMouse(). 91 // such as OnMouseLockLost() synchronously calling LockMouse().
123 92
124 if (last_target) 93 if (last_target)
125 last_target->OnMouseLockLost(); 94 last_target->OnMouseLockLost();
126 } 95 }
OLDNEW
« no previous file with comments | « content/renderer/mouse_lock_dispatcher.h ('k') | content/renderer/pepper/pepper_plugin_delegate_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698