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

Side by Side Diff: content/browser/renderer_host/render_widget_host.cc

Issue 7863003: Mouse lock implementation, including the renderer side and the Windows version of the browser side. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove two tab chars. Created 9 years, 3 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/browser/renderer_host/render_widget_host.h" 5 #include "content/browser/renderer_host/render_widget_host.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur) 176 IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur)
177 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor) 177 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor)
178 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeUpdateTextInputState, 178 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeUpdateTextInputState,
179 OnMsgImeUpdateTextInputState) 179 OnMsgImeUpdateTextInputState)
180 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeCompositionRangeChanged, 180 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeCompositionRangeChanged,
181 OnMsgImeCompositionRangeChanged) 181 OnMsgImeCompositionRangeChanged)
182 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeCancelComposition, 182 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeCancelComposition,
183 OnMsgImeCancelComposition) 183 OnMsgImeCancelComposition)
184 IPC_MESSAGE_HANDLER(ViewHostMsg_DidActivateAcceleratedCompositing, 184 IPC_MESSAGE_HANDLER(ViewHostMsg_DidActivateAcceleratedCompositing,
185 OnMsgDidActivateAcceleratedCompositing) 185 OnMsgDidActivateAcceleratedCompositing)
186 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnMsgLockMouse)
187 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnMsgUnlockMouse)
186 #if defined(OS_POSIX) 188 #if defined(OS_POSIX)
187 IPC_MESSAGE_HANDLER(ViewHostMsg_GetScreenInfo, OnMsgGetScreenInfo) 189 IPC_MESSAGE_HANDLER(ViewHostMsg_GetScreenInfo, OnMsgGetScreenInfo)
188 IPC_MESSAGE_HANDLER(ViewHostMsg_GetWindowRect, OnMsgGetWindowRect) 190 IPC_MESSAGE_HANDLER(ViewHostMsg_GetWindowRect, OnMsgGetWindowRect)
189 IPC_MESSAGE_HANDLER(ViewHostMsg_GetRootWindowRect, OnMsgGetRootWindowRect) 191 IPC_MESSAGE_HANDLER(ViewHostMsg_GetRootWindowRect, OnMsgGetRootWindowRect)
190 #endif 192 #endif
191 #if defined(OS_MACOSX) 193 #if defined(OS_MACOSX)
192 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, 194 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged,
193 OnMsgPluginFocusChanged) 195 OnMsgPluginFocusChanged)
194 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, 196 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme,
195 OnMsgStartPluginIme) 197 OnMsgStartPluginIme)
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 360
359 void RenderWidgetHost::GotFocus() { 361 void RenderWidgetHost::GotFocus() {
360 Focus(); 362 Focus();
361 } 363 }
362 364
363 void RenderWidgetHost::Focus() { 365 void RenderWidgetHost::Focus() {
364 Send(new ViewMsg_SetFocus(routing_id_, true)); 366 Send(new ViewMsg_SetFocus(routing_id_, true));
365 } 367 }
366 368
367 void RenderWidgetHost::Blur() { 369 void RenderWidgetHost::Blur() {
370 if (IsMouseLocked())
371 view_->UnlockMouse();
372
368 Send(new ViewMsg_SetFocus(routing_id_, false)); 373 Send(new ViewMsg_SetFocus(routing_id_, false));
369 } 374 }
370 375
371 void RenderWidgetHost::LostCapture() { 376 void RenderWidgetHost::LostCapture() {
372 Send(new ViewMsg_MouseCaptureLost(routing_id_)); 377 Send(new ViewMsg_MouseCaptureLost(routing_id_));
373 } 378 }
374 379
380 void RenderWidgetHost::LostMouseLock() {
381 Send(new ViewMsg_MouseLockLost(routing_id_));
382 }
383
375 void RenderWidgetHost::ViewDestroyed() { 384 void RenderWidgetHost::ViewDestroyed() {
385 if (IsMouseLocked())
386 view_->UnlockMouse();
387
376 // TODO(evanm): tracking this may no longer be necessary; 388 // TODO(evanm): tracking this may no longer be necessary;
377 // eliminate this function if so. 389 // eliminate this function if so.
378 SetView(NULL); 390 SetView(NULL);
379 } 391 }
380 392
381 void RenderWidgetHost::SetIsLoading(bool is_loading) { 393 void RenderWidgetHost::SetIsLoading(bool is_loading) {
382 is_loading_ = is_loading; 394 is_loading_ = is_loading;
383 if (!view_) 395 if (!view_)
384 return; 396 return;
385 view_->SetIsLoading(is_loading); 397 view_->SetIsLoading(is_loading);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 TRACE_EVENT0("renderer_host", "RenderWidgetHost::ForwardMouseEvent"); 516 TRACE_EVENT0("renderer_host", "RenderWidgetHost::ForwardMouseEvent");
505 if (ignore_input_events_ || process_->ignore_input_events()) 517 if (ignore_input_events_ || process_->ignore_input_events())
506 return; 518 return;
507 519
508 // Avoid spamming the renderer with mouse move events. It is important 520 // Avoid spamming the renderer with mouse move events. It is important
509 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our 521 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our
510 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way 522 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way
511 // more WM_MOUSEMOVE events than we wish to send to the renderer. 523 // more WM_MOUSEMOVE events than we wish to send to the renderer.
512 if (mouse_event.type == WebInputEvent::MouseMove) { 524 if (mouse_event.type == WebInputEvent::MouseMove) {
513 if (mouse_move_pending_) { 525 if (mouse_move_pending_) {
514 next_mouse_move_.reset(new WebMouseEvent(mouse_event)); 526 if (!next_mouse_move_.get()) {
527 next_mouse_move_.reset(new WebMouseEvent(mouse_event));
528 } else {
529 // Accumulate movement deltas.
530 int x = next_mouse_move_->movementX;
531 int y = next_mouse_move_->movementY;
532 *next_mouse_move_ = mouse_event;
533 next_mouse_move_->movementX += x;
534 next_mouse_move_->movementY += y;
535 }
515 return; 536 return;
516 } 537 }
517 mouse_move_pending_ = true; 538 mouse_move_pending_ = true;
518 } else if (mouse_event.type == WebInputEvent::MouseDown) { 539 } else if (mouse_event.type == WebInputEvent::MouseDown) {
519 OnUserGesture(); 540 OnUserGesture();
520 } 541 }
521 542
522 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent), false); 543 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent), false);
523 } 544 }
524 545
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 780
760 void RenderWidgetHost::ImeConfirmComposition() { 781 void RenderWidgetHost::ImeConfirmComposition() {
761 Send(new ViewMsg_ImeConfirmComposition(routing_id(), string16())); 782 Send(new ViewMsg_ImeConfirmComposition(routing_id(), string16()));
762 } 783 }
763 784
764 void RenderWidgetHost::ImeCancelComposition() { 785 void RenderWidgetHost::ImeCancelComposition() {
765 Send(new ViewMsg_ImeSetComposition(routing_id(), string16(), 786 Send(new ViewMsg_ImeSetComposition(routing_id(), string16(),
766 std::vector<WebKit::WebCompositionUnderline>(), 0, 0)); 787 std::vector<WebKit::WebCompositionUnderline>(), 0, 0));
767 } 788 }
768 789
790 bool RenderWidgetHost::IsMouseLocked() const {
791 return view_ ? view_->mouse_locked() : false;
792 }
793
769 void RenderWidgetHost::Destroy() { 794 void RenderWidgetHost::Destroy() {
770 NotificationService::current()->Notify( 795 NotificationService::current()->Notify(
771 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, 796 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
772 Source<RenderWidgetHost>(this), 797 Source<RenderWidgetHost>(this),
773 NotificationService::NoDetails()); 798 NotificationService::NoDetails());
774 799
775 // Tell the view to die. 800 // Tell the view to die.
776 // Note that in the process of the view shutting down, it can call a ton 801 // Note that in the process of the view shutting down, it can call a ton
777 // of other messages on us. So if you do any other deinitialization here, 802 // of other messages on us. So if you do any other deinitialization here,
778 // do it after this call to view_->Destroy(). 803 // do it after this call to view_->Destroy().
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 view_->GpuRenderingStateDidChange(); 1129 view_->GpuRenderingStateDidChange();
1105 #elif defined(OS_WIN) 1130 #elif defined(OS_WIN)
1106 if (view_) 1131 if (view_)
1107 view_->ShowCompositorHostWindow(is_accelerated_compositing_active_); 1132 view_->ShowCompositorHostWindow(is_accelerated_compositing_active_);
1108 #elif defined(TOOLKIT_USES_GTK) 1133 #elif defined(TOOLKIT_USES_GTK)
1109 if (view_) 1134 if (view_)
1110 view_->AcceleratedCompositingActivated(activated); 1135 view_->AcceleratedCompositingActivated(activated);
1111 #endif 1136 #endif
1112 } 1137 }
1113 1138
1139 void RenderWidgetHost::OnMsgLockMouse() {
1140 // TODO(yzshen): Only allow to lock the mouse when in fullscreen mode, and
1141 // make sure that the mouse is unlocked when leaving fullscreen mode.
1142 if (!view_ || !view_->HasFocus() || !view_->LockMouse()) {
1143 Send(new ViewMsg_LockMouse_ACK(routing_id_, false));
1144 } else {
1145 Send(new ViewMsg_LockMouse_ACK(routing_id_, true));
1146 }
1147 }
1148
1149 void RenderWidgetHost::OnMsgUnlockMouse() {
1150 if (IsMouseLocked())
1151 view_->UnlockMouse();
1152 }
1153
1114 #if defined(OS_POSIX) 1154 #if defined(OS_POSIX)
1115 void RenderWidgetHost::OnMsgGetScreenInfo(gfx::NativeViewId window_id, 1155 void RenderWidgetHost::OnMsgGetScreenInfo(gfx::NativeViewId window_id,
1116 WebKit::WebScreenInfo* results) { 1156 WebKit::WebScreenInfo* results) {
1117 if (view_) 1157 if (view_)
1118 view_->GetScreenInfo(results); 1158 view_->GetScreenInfo(results);
1119 else 1159 else
1120 RenderWidgetHostView::GetDefaultScreenInfo(results); 1160 RenderWidgetHostView::GetDefaultScreenInfo(results);
1121 } 1161 }
1122 1162
1123 void RenderWidgetHost::OnMsgGetWindowRect(gfx::NativeViewId window_id, 1163 void RenderWidgetHost::OnMsgGetWindowRect(gfx::NativeViewId window_id,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 view_->CreatePluginContainer(deferred_plugin_handles_[i]); 1285 view_->CreatePluginContainer(deferred_plugin_handles_[i]);
1246 #endif 1286 #endif
1247 } 1287 }
1248 1288
1249 deferred_plugin_handles_.clear(); 1289 deferred_plugin_handles_.clear();
1250 } 1290 }
1251 1291
1252 void RenderWidgetHost::StartUserGesture() { 1292 void RenderWidgetHost::StartUserGesture() {
1253 OnUserGesture(); 1293 OnUserGesture();
1254 } 1294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698