| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 // TODO(yzshen): Is it necessary to consider the case that this class calls |
| 386 // Destory on RenderWidgetHostView, and then we won't get a notification of |
| 387 // ViewDestroyed? At that point, does it make sense to send message to the |
| 388 // renderer side? |
| 389 if (IsMouseLocked()) |
| 390 view_->UnlockMouse(); |
| 391 |
| 376 // TODO(evanm): tracking this may no longer be necessary; | 392 // TODO(evanm): tracking this may no longer be necessary; |
| 377 // eliminate this function if so. | 393 // eliminate this function if so. |
| 378 SetView(NULL); | 394 SetView(NULL); |
| 379 } | 395 } |
| 380 | 396 |
| 381 void RenderWidgetHost::SetIsLoading(bool is_loading) { | 397 void RenderWidgetHost::SetIsLoading(bool is_loading) { |
| 382 is_loading_ = is_loading; | 398 is_loading_ = is_loading; |
| 383 if (!view_) | 399 if (!view_) |
| 384 return; | 400 return; |
| 385 view_->SetIsLoading(is_loading); | 401 view_->SetIsLoading(is_loading); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 TRACE_EVENT0("renderer_host", "RenderWidgetHost::ForwardMouseEvent"); | 520 TRACE_EVENT0("renderer_host", "RenderWidgetHost::ForwardMouseEvent"); |
| 505 if (ignore_input_events_ || process_->ignore_input_events()) | 521 if (ignore_input_events_ || process_->ignore_input_events()) |
| 506 return; | 522 return; |
| 507 | 523 |
| 508 // Avoid spamming the renderer with mouse move events. It is important | 524 // Avoid spamming the renderer with mouse move events. It is important |
| 509 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our | 525 // 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 | 526 // 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. | 527 // more WM_MOUSEMOVE events than we wish to send to the renderer. |
| 512 if (mouse_event.type == WebInputEvent::MouseMove) { | 528 if (mouse_event.type == WebInputEvent::MouseMove) { |
| 513 if (mouse_move_pending_) { | 529 if (mouse_move_pending_) { |
| 514 next_mouse_move_.reset(new WebMouseEvent(mouse_event)); | 530 if (!next_mouse_move_.get()) { |
| 531 next_mouse_move_.reset(new WebMouseEvent(mouse_event)); |
| 532 } else { |
| 533 // Accumulate movement deltas. |
| 534 int x = next_mouse_move_->movementX; |
| 535 int y = next_mouse_move_->movementY; |
| 536 *next_mouse_move_ = mouse_event; |
| 537 next_mouse_move_->movementX += x; |
| 538 next_mouse_move_->movementY += y; |
| 539 } |
| 515 return; | 540 return; |
| 516 } | 541 } |
| 517 mouse_move_pending_ = true; | 542 mouse_move_pending_ = true; |
| 518 } else if (mouse_event.type == WebInputEvent::MouseDown) { | 543 } else if (mouse_event.type == WebInputEvent::MouseDown) { |
| 519 OnUserGesture(); | 544 OnUserGesture(); |
| 520 } | 545 } |
| 521 | 546 |
| 522 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent), false); | 547 ForwardInputEvent(mouse_event, sizeof(WebMouseEvent), false); |
| 523 } | 548 } |
| 524 | 549 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 | 784 |
| 760 void RenderWidgetHost::ImeConfirmComposition() { | 785 void RenderWidgetHost::ImeConfirmComposition() { |
| 761 Send(new ViewMsg_ImeConfirmComposition(routing_id(), string16())); | 786 Send(new ViewMsg_ImeConfirmComposition(routing_id(), string16())); |
| 762 } | 787 } |
| 763 | 788 |
| 764 void RenderWidgetHost::ImeCancelComposition() { | 789 void RenderWidgetHost::ImeCancelComposition() { |
| 765 Send(new ViewMsg_ImeSetComposition(routing_id(), string16(), | 790 Send(new ViewMsg_ImeSetComposition(routing_id(), string16(), |
| 766 std::vector<WebKit::WebCompositionUnderline>(), 0, 0)); | 791 std::vector<WebKit::WebCompositionUnderline>(), 0, 0)); |
| 767 } | 792 } |
| 768 | 793 |
| 794 bool RenderWidgetHost::IsMouseLocked() const { |
| 795 return view_ ? view_->mouse_locked() : false; |
| 796 } |
| 797 |
| 769 void RenderWidgetHost::Destroy() { | 798 void RenderWidgetHost::Destroy() { |
| 770 NotificationService::current()->Notify( | 799 NotificationService::current()->Notify( |
| 771 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 800 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 772 Source<RenderWidgetHost>(this), | 801 Source<RenderWidgetHost>(this), |
| 773 NotificationService::NoDetails()); | 802 NotificationService::NoDetails()); |
| 774 | 803 |
| 775 // Tell the view to die. | 804 // Tell the view to die. |
| 776 // Note that in the process of the view shutting down, it can call a ton | 805 // 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, | 806 // of other messages on us. So if you do any other deinitialization here, |
| 778 // do it after this call to view_->Destroy(). | 807 // do it after this call to view_->Destroy(). |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 view_->GpuRenderingStateDidChange(); | 1133 view_->GpuRenderingStateDidChange(); |
| 1105 #elif defined(OS_WIN) | 1134 #elif defined(OS_WIN) |
| 1106 if (view_) | 1135 if (view_) |
| 1107 view_->ShowCompositorHostWindow(is_accelerated_compositing_active_); | 1136 view_->ShowCompositorHostWindow(is_accelerated_compositing_active_); |
| 1108 #elif defined(TOOLKIT_USES_GTK) | 1137 #elif defined(TOOLKIT_USES_GTK) |
| 1109 if (view_) | 1138 if (view_) |
| 1110 view_->AcceleratedCompositingActivated(activated); | 1139 view_->AcceleratedCompositingActivated(activated); |
| 1111 #endif | 1140 #endif |
| 1112 } | 1141 } |
| 1113 | 1142 |
| 1143 void RenderWidgetHost::OnMsgLockMouse() { |
| 1144 // TODO(yzshen): Only allow to lock the mouse when in fullscreen mode, and |
| 1145 // make sure that the mouse is unlocked when leaving fullscreen mode. |
| 1146 if (!view_ || !view_->HasFocus() || !view_->LockMouse()) { |
| 1147 Send(new ViewMsg_LockMouse_ACK(routing_id_, false)); |
| 1148 } else { |
| 1149 Send(new ViewMsg_LockMouse_ACK(routing_id_, true)); |
| 1150 } |
| 1151 } |
| 1152 |
| 1153 void RenderWidgetHost::OnMsgUnlockMouse() { |
| 1154 if (IsMouseLocked()) |
| 1155 view_->UnlockMouse(); |
| 1156 } |
| 1157 |
| 1114 #if defined(OS_POSIX) | 1158 #if defined(OS_POSIX) |
| 1115 void RenderWidgetHost::OnMsgGetScreenInfo(gfx::NativeViewId window_id, | 1159 void RenderWidgetHost::OnMsgGetScreenInfo(gfx::NativeViewId window_id, |
| 1116 WebKit::WebScreenInfo* results) { | 1160 WebKit::WebScreenInfo* results) { |
| 1117 if (view_) | 1161 if (view_) |
| 1118 view_->GetScreenInfo(results); | 1162 view_->GetScreenInfo(results); |
| 1119 else | 1163 else |
| 1120 RenderWidgetHostView::GetDefaultScreenInfo(results); | 1164 RenderWidgetHostView::GetDefaultScreenInfo(results); |
| 1121 } | 1165 } |
| 1122 | 1166 |
| 1123 void RenderWidgetHost::OnMsgGetWindowRect(gfx::NativeViewId window_id, | 1167 void RenderWidgetHost::OnMsgGetWindowRect(gfx::NativeViewId window_id, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 view_->CreatePluginContainer(deferred_plugin_handles_[i]); | 1289 view_->CreatePluginContainer(deferred_plugin_handles_[i]); |
| 1246 #endif | 1290 #endif |
| 1247 } | 1291 } |
| 1248 | 1292 |
| 1249 deferred_plugin_handles_.clear(); | 1293 deferred_plugin_handles_.clear(); |
| 1250 } | 1294 } |
| 1251 | 1295 |
| 1252 void RenderWidgetHost::StartUserGesture() { | 1296 void RenderWidgetHost::StartUserGesture() { |
| 1253 OnUserGesture(); | 1297 OnUserGesture(); |
| 1254 } | 1298 } |
| OLD | NEW |