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

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

Issue 8970016: refactoring mouse lock to support pepper and WebKit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated webkit API names. Created 8 years, 11 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
yzshen1 2012/01/16 07:50:35 2012. :)
scheib 2012/01/17 22:05:36 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/renderer/mouse_lock_dispatcher.h"
6
7 #include "content/common/view_messages.h"
8 #include "content/renderer/render_view_impl.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
yzshen1 2012/01/16 07:50:35 Alphabetically, please.
scheib 2012/01/17 22:05:36 Done.
11
12 MouseLockDispatcher::MouseLockDispatcher(RenderViewImpl* render_view_impl)
13 : content::RenderViewObserver(render_view_impl),
14 render_view_impl_(render_view_impl),
15 mouse_locked_(false),
16 pending_lock_request_(false),
17 pending_unlock_request_(false),
18 mouse_lock_webwidget_owner_(NULL),
19 mouse_lock_pinstance_owner_(NULL) {
20 }
21
22 MouseLockDispatcher::~MouseLockDispatcher() {
23 }
24
25 bool MouseLockDispatcher::LockMouse(WebKit::WebWidget* webwidget,
26 webkit::ppapi::PluginInstance* pinstance) {
yzshen1 2012/01/16 07:50:35 Wrong indent.
scheib 2012/01/17 22:05:36 Done.
27 DCHECK(!(webwidget && pinstance)); // Only one mouse lock target at a time.
28
29 if (MouseLockedOrPendingAction())
30 return false;
31
32 pending_lock_request_ = true;
33 DCHECK(!mouse_lock_webwidget_owner_ && !mouse_lock_pinstance_owner_);
34 mouse_lock_webwidget_owner_ = webwidget;
35 mouse_lock_pinstance_owner_ = pinstance;
36
37 Send(new ViewHostMsg_LockMouse(routing_id()));
38 return true;
39 }
40
41 void MouseLockDispatcher::UnlockMouse(WebKit::WebWidget* webwidget,
42 webkit::ppapi::PluginInstance* pinstance) {
yzshen1 2012/01/16 07:50:35 Wrong indent.
scheib 2012/01/17 22:05:36 Done.
43 if (!MouseLockedOrPendingAction() || pending_unlock_request_)
44 return;
45
46 // Ignore unless the unlock request is for the current lock holder.
47 if (webwidget == mouse_lock_webwidget_owner_ ||
48 pinstance == mouse_lock_pinstance_owner_) {
49 pending_unlock_request_ = true;
50 Send(new ViewHostMsg_UnlockMouse(routing_id()));
51 }
52 }
53
54 bool MouseLockDispatcher::IsPointerLockedTo(WebKit::WebWidget* webwidget) {
55 return mouse_locked_ && mouse_lock_webwidget_owner_ == webwidget;
56 }
57
58 bool MouseLockDispatcher::IsMouseLockedTo(
59 webkit::ppapi::PluginInstance* pinstance) {
60 return mouse_locked_ && mouse_lock_pinstance_owner_ == pinstance;
61 }
62
63 bool MouseLockDispatcher::WillHandleMouseEvent(
64 const WebKit::WebMouseEvent& event) {
65 if (mouse_locked_ && mouse_lock_pinstance_owner_) {
66 DCHECK(!mouse_lock_webwidget_owner_);
67 if (mouse_lock_pinstance_owner_)
yzshen1 2012/01/16 07:50:35 you don't need this check, right?
scheib 2012/01/17 22:05:36 Done.
68 mouse_lock_pinstance_owner_->HandleMouseLockedInputEvent(event);
69
70 // mouse_lock_webwidget_owner_ handles mouse lock in handleInputEvent().
71
72 // If the mouse is locked, only the current owner of the mouse lock can
73 // process mouse events.
74 return true;
75 }
76 return false;
77 }
yzshen1 2012/01/16 07:50:35 Empty line after it, please.
scheib 2012/01/17 22:05:36 Done.
78 bool MouseLockDispatcher::OnMessageReceived(const IPC::Message& message) {
79 bool handled = true;
80 IPC_BEGIN_MESSAGE_MAP(MouseLockDispatcher, message)
81 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK)
82 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost)
83 IPC_MESSAGE_UNHANDLED(handled = false)
84 IPC_END_MESSAGE_MAP()
85 return handled;
86 }
87
88 void MouseLockDispatcher::OnLockMouseACK(bool succeeded) {
89 // Mouse Lock removes the system cursor and provides all mouse motion as
90 // .movementX/Y values on events all sent to a fixed target. This requires
91 // content to specifically request the mode to be entered.
92 // Mouse Capture is implicitly given for the duration of a drag event, and
93 // sends all mouse events to the initial target of the drag.
94 // If Lock is entered it supercedes any in progress Capture.
95 if (succeeded && render_view_impl_->webwidget())
96 render_view_impl_->webwidget()->mouseCaptureLost();
97
98 DCHECK(!mouse_locked_ && pending_lock_request_);
99
100 mouse_locked_ = succeeded;
101 pending_lock_request_ = false;
102 if (pending_unlock_request_ && !succeeded) {
103 // We have sent an unlock request after the lock request. However, since
104 // the lock request has failed, the unlock request will be ignored by the
105 // browser side and there won't be any response to it.
106 pending_unlock_request_ = false;
107 }
108
109 if (mouse_lock_webwidget_owner_ || mouse_lock_pinstance_owner_) {
110 WebKit::WebWidget* last_webwidget_owner = mouse_lock_webwidget_owner_;
yzshen1 2012/01/16 07:50:35 [Just want to double check.] Is it possible that m
scheib 2012/01/17 22:05:36 It is not possible, the render view impl will call
111 webkit::ppapi::PluginInstance* last_pinstance_owner =
112 mouse_lock_pinstance_owner_;
113
114 if (!succeeded) {
115 // Reset mouse lock owner to NULL before calling OnLockMouseACK(), so
116 // that if OnLockMouseACK() results in calls to any mouse lock method
117 // (e.g., LockMouse()), the method will see consistent internal state.
118 mouse_lock_webwidget_owner_ = NULL;
119 mouse_lock_pinstance_owner_ = NULL;
120 }
121
122 DCHECK(!mouse_lock_webwidget_owner_ || !mouse_lock_pinstance_owner_);
123 if (last_webwidget_owner) {
124 if (succeeded)
125 last_webwidget_owner->didCompletePointerLock();
126 else
127 last_webwidget_owner->didNotCompletePointerLock();
128 }
129 if (last_pinstance_owner)
130 last_pinstance_owner->OnLockMouseACK(succeeded);
131 }
132 }
133
134 void MouseLockDispatcher::OnMouseLockLost() {
135 DCHECK(mouse_locked_ && !pending_lock_request_);
136
137 mouse_locked_ = false;
138 pending_unlock_request_ = false;
139 if (mouse_lock_webwidget_owner_ || mouse_lock_pinstance_owner_) {
140 WebKit::WebWidget* last_webwidget_owner = mouse_lock_webwidget_owner_;
141 webkit::ppapi::PluginInstance* last_pinstance_owner =
142 mouse_lock_pinstance_owner_;
143
144 // Reset mouse lock owner to NULL before calling OnLockMouseACK(), so
yzshen1 2012/01/16 07:50:35 OnLockMouseACK -> OnMouseLockLost. (And the same f
scheib 2012/01/17 22:05:36 Done.
145 // that if OnLockMouseACK() results in calls to any mouse lock method
146 // (e.g., LockMouse()), the method will see consistent internal state.
147 mouse_lock_webwidget_owner_ = NULL;
148 mouse_lock_pinstance_owner_ = NULL;
149
150 DCHECK(!mouse_lock_webwidget_owner_ || !mouse_lock_pinstance_owner_);
151 if (last_webwidget_owner)
152 last_webwidget_owner->didLosePointerLock();
153 if (last_pinstance_owner)
154 last_pinstance_owner->OnMouseLockLost();
155 }
156 }
157
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698