Chromium Code Reviews| 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/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 using blink::WebWidget; | 133 using blink::WebWidget; |
| 134 | 134 |
| 135 #define STATIC_ASSERT_ENUM(a, b) \ | 135 #define STATIC_ASSERT_ENUM(a, b) \ |
| 136 static_assert(static_cast<int>(a) == static_cast<int>(b), \ | 136 static_assert(static_cast<int>(a) == static_cast<int>(b), \ |
| 137 "mismatching enums: " #a) | 137 "mismatching enums: " #a) |
| 138 | 138 |
| 139 namespace { | 139 namespace { |
| 140 | 140 |
| 141 typedef std::map<std::string, ui::TextInputMode> TextInputModeMap; | 141 typedef std::map<std::string, ui::TextInputMode> TextInputModeMap; |
| 142 | 142 |
| 143 class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget { | |
| 144 public: | |
| 145 explicit WebWidgetLockTarget(blink::WebWidget* webwidget) | |
| 146 : webwidget_(webwidget) {} | |
| 147 | |
| 148 void OnLockMouseACK(bool succeeded) override { | |
| 149 if (succeeded) | |
| 150 webwidget_->didAcquirePointerLock(); | |
| 151 else | |
| 152 webwidget_->didNotAcquirePointerLock(); | |
| 153 } | |
| 154 | |
| 155 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); } | |
| 156 | |
| 157 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override { | |
| 158 // The WebWidget handles mouse lock in WebKit's handleInputEvent(). | |
|
nasko
2016/05/25 21:12:01
nit: s/WebKit/Blink/
lfg
2016/05/31 21:13:20
Done.
| |
| 159 return false; | |
| 160 } | |
| 161 | |
| 162 private: | |
| 163 blink::WebWidget* webwidget_; | |
| 164 }; | |
| 165 | |
| 143 class TextInputModeMapSingleton { | 166 class TextInputModeMapSingleton { |
| 144 public: | 167 public: |
| 145 static TextInputModeMapSingleton* GetInstance() { | 168 static TextInputModeMapSingleton* GetInstance() { |
| 146 return base::Singleton<TextInputModeMapSingleton>::get(); | 169 return base::Singleton<TextInputModeMapSingleton>::get(); |
| 147 } | 170 } |
| 148 TextInputModeMapSingleton() { | 171 TextInputModeMapSingleton() { |
| 149 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM; | 172 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM; |
| 150 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN; | 173 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN; |
| 151 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME; | 174 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME; |
| 152 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE; | 175 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 screen_info_(screen_info), | 263 screen_info_(screen_info), |
| 241 device_scale_factor_(screen_info_.deviceScaleFactor), | 264 device_scale_factor_(screen_info_.deviceScaleFactor), |
| 242 next_output_surface_id_(0), | 265 next_output_surface_id_(0), |
| 243 #if defined(OS_ANDROID) | 266 #if defined(OS_ANDROID) |
| 244 text_field_is_dirty_(false), | 267 text_field_is_dirty_(false), |
| 245 #endif | 268 #endif |
| 246 popup_origin_scale_for_emulation_(0.f), | 269 popup_origin_scale_for_emulation_(0.f), |
| 247 frame_swap_message_queue_(new FrameSwapMessageQueue()), | 270 frame_swap_message_queue_(new FrameSwapMessageQueue()), |
| 248 resizing_mode_selector_(new ResizingModeSelector()), | 271 resizing_mode_selector_(new ResizingModeSelector()), |
| 249 has_host_context_menu_location_(false), | 272 has_host_context_menu_location_(false), |
| 273 mouse_lock_dispatcher_(nullptr), | |
|
nasko
2016/05/25 21:12:01
unique_ptr doesn't need explicit initialization to
lfg
2016/05/31 21:13:20
Right, it used to be a raw pointer, I've changed i
| |
| 250 has_focus_(false) { | 274 has_focus_(false) { |
| 251 if (!swapped_out) | 275 if (!swapped_out) |
| 252 RenderProcess::current()->AddRefProcess(); | 276 RenderProcess::current()->AddRefProcess(); |
| 253 DCHECK(RenderThread::Get()); | 277 DCHECK(RenderThread::Get()); |
| 254 device_color_profile_.push_back('0'); | 278 device_color_profile_.push_back('0'); |
| 255 #if defined(OS_ANDROID) | 279 #if defined(OS_ANDROID) |
| 256 text_input_info_history_.push_back(blink::WebTextInputInfo()); | 280 text_input_info_history_.push_back(blink::WebTextInputInfo()); |
| 257 #endif | 281 #endif |
| 258 | 282 |
| 259 // In tests there may not be a RenderThreadImpl. | 283 // In tests there may not be a RenderThreadImpl. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 } | 330 } |
| 307 scoped_refptr<RenderWidget> widget( | 331 scoped_refptr<RenderWidget> widget( |
| 308 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info, | 332 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info, |
| 309 false, hidden, false)); | 333 false, hidden, false)); |
| 310 widget->SetRoutingID(routing_id); | 334 widget->SetRoutingID(routing_id); |
| 311 widget->for_oopif_ = true; | 335 widget->for_oopif_ = true; |
| 312 // DoInit increments the reference count on |widget|, keeping it alive after | 336 // DoInit increments the reference count on |widget|, keeping it alive after |
| 313 // this function returns. | 337 // this function returns. |
| 314 if (widget->DoInit(MSG_ROUTING_NONE, | 338 if (widget->DoInit(MSG_ROUTING_NONE, |
| 315 RenderWidget::CreateWebFrameWidget(widget.get(), frame), | 339 RenderWidget::CreateWebFrameWidget(widget.get(), frame), |
| 316 nullptr)) { | 340 nullptr, true)) { |
| 317 return widget.get(); | 341 return widget.get(); |
| 318 } | 342 } |
| 319 return nullptr; | 343 return nullptr; |
| 320 } | 344 } |
| 321 | 345 |
| 322 // static | 346 // static |
| 323 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( | 347 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( |
| 324 RenderWidget* render_widget, | 348 RenderWidget* render_widget, |
| 325 blink::WebLocalFrame* frame) { | 349 blink::WebLocalFrame* frame) { |
| 326 if (!frame->parent()) { | 350 if (!frame->parent()) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 350 | 374 |
| 351 void RenderWidget::SetRoutingID(int32_t routing_id) { | 375 void RenderWidget::SetRoutingID(int32_t routing_id) { |
| 352 routing_id_ = routing_id; | 376 routing_id_ = routing_id; |
| 353 input_handler_.reset(new RenderWidgetInputHandler( | 377 input_handler_.reset(new RenderWidgetInputHandler( |
| 354 GetRenderWidgetInputHandlerDelegate(this), this)); | 378 GetRenderWidgetInputHandlerDelegate(this), this)); |
| 355 } | 379 } |
| 356 | 380 |
| 357 bool RenderWidget::Init(int32_t opener_id) { | 381 bool RenderWidget::Init(int32_t opener_id) { |
| 358 bool success = DoInit( | 382 bool success = DoInit( |
| 359 opener_id, RenderWidget::CreateWebWidget(this), | 383 opener_id, RenderWidget::CreateWebWidget(this), |
| 360 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_)); | 384 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_), true); |
| 361 if (success) { | 385 if (success) { |
| 362 SetRoutingID(routing_id_); | 386 SetRoutingID(routing_id_); |
| 363 return true; | 387 return true; |
| 364 } | 388 } |
| 365 return false; | 389 return false; |
| 366 } | 390 } |
| 367 | 391 |
| 368 bool RenderWidget::DoInit(int32_t opener_id, | 392 bool RenderWidget::DoInit(int32_t opener_id, |
| 369 WebWidget* web_widget, | 393 WebWidget* web_widget, |
| 370 IPC::SyncMessage* create_widget_message) { | 394 IPC::SyncMessage* create_widget_message, |
| 395 bool should_add_route) { | |
| 371 DCHECK(!webwidget_); | 396 DCHECK(!webwidget_); |
| 372 | 397 |
| 373 if (opener_id != MSG_ROUTING_NONE) | 398 if (opener_id != MSG_ROUTING_NONE) |
| 374 opener_id_ = opener_id; | 399 opener_id_ = opener_id; |
| 375 | 400 |
| 376 webwidget_ = web_widget; | 401 webwidget_ = web_widget; |
| 402 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); | |
| 403 mouse_lock_dispatcher_ = | |
| 404 base::WrapUnique(new RenderWidgetMouseLockDispatcher(this)); | |
| 377 | 405 |
| 378 bool result = true; | 406 bool result = true; |
| 379 if (create_widget_message) | 407 if (create_widget_message) |
| 380 result = RenderThread::Get()->Send(create_widget_message); | 408 result = RenderThread::Get()->Send(create_widget_message); |
| 381 | 409 |
| 410 if (!should_add_route) | |
| 411 return true; | |
| 412 | |
| 382 if (result) { | 413 if (result) { |
| 383 RenderThread::Get()->AddRoute(routing_id_, this); | 414 RenderThread::Get()->AddRoute(routing_id_, this); |
| 384 // Take a reference on behalf of the RenderThread. This will be balanced | 415 // Take a reference on behalf of the RenderThread. This will be balanced |
| 385 // when we receive ViewMsg_Close. | 416 // when we receive ViewMsg_Close. |
| 386 AddRef(); | 417 AddRef(); |
| 387 if (RenderThreadImpl::current()) { | 418 if (RenderThreadImpl::current()) { |
| 388 RenderThreadImpl::current()->WidgetCreated(); | 419 RenderThreadImpl::current()->WidgetCreated(); |
| 389 if (is_hidden_) | 420 if (is_hidden_) |
| 390 RenderThreadImpl::current()->WidgetHidden(); | 421 RenderThreadImpl::current()->WidgetHidden(); |
| 391 } | 422 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 emulator->scale(), emulator->offset()); | 474 emulator->scale(), emulator->offset()); |
| 444 } | 475 } |
| 445 #endif | 476 #endif |
| 446 | 477 |
| 447 void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) { | 478 void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) { |
| 448 if (screen_metrics_emulator_) | 479 if (screen_metrics_emulator_) |
| 449 screen_metrics_emulator_->OnShowContextMenu(params); | 480 screen_metrics_emulator_->OnShowContextMenu(params); |
| 450 } | 481 } |
| 451 | 482 |
| 452 bool RenderWidget::OnMessageReceived(const IPC::Message& message) { | 483 bool RenderWidget::OnMessageReceived(const IPC::Message& message) { |
| 484 if (mouse_lock_dispatcher_ && | |
| 485 mouse_lock_dispatcher_->OnMessageReceived(message)) | |
| 486 return true; | |
| 487 | |
| 453 bool handled = true; | 488 bool handled = true; |
| 454 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) | 489 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) |
| 455 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent) | 490 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent) |
| 456 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange, | 491 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange, |
| 457 OnCursorVisibilityChange) | 492 OnCursorVisibilityChange) |
| 458 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition) | 493 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition) |
| 459 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition) | 494 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition) |
| 460 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost) | 495 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost) |
| 461 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus) | 496 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus) |
| 462 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted, | 497 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted, |
| (...skipping 1628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2091 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); | 2126 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); |
| 2092 } | 2127 } |
| 2093 | 2128 |
| 2094 float RenderWidget::GetOriginalDeviceScaleFactor() const { | 2129 float RenderWidget::GetOriginalDeviceScaleFactor() const { |
| 2095 return | 2130 return |
| 2096 screen_metrics_emulator_ ? | 2131 screen_metrics_emulator_ ? |
| 2097 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : | 2132 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : |
| 2098 device_scale_factor_; | 2133 device_scale_factor_; |
| 2099 } | 2134 } |
| 2100 | 2135 |
| 2136 bool RenderWidget::requestPointerLock() { | |
| 2137 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); | |
| 2138 } | |
| 2139 | |
| 2140 void RenderWidget::requestPointerUnlock() { | |
| 2141 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); | |
| 2142 } | |
| 2143 | |
| 2144 bool RenderWidget::isPointerLocked() { | |
| 2145 return mouse_lock_dispatcher_->IsMouseLockedTo( | |
| 2146 webwidget_mouse_lock_target_.get()); | |
| 2147 } | |
| 2148 | |
| 2101 } // namespace content | 2149 } // namespace content |
| OLD | NEW |