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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 using blink::WebWidget; | 132 using blink::WebWidget; |
133 | 133 |
134 #define STATIC_ASSERT_ENUM(a, b) \ | 134 #define STATIC_ASSERT_ENUM(a, b) \ |
135 static_assert(static_cast<int>(a) == static_cast<int>(b), \ | 135 static_assert(static_cast<int>(a) == static_cast<int>(b), \ |
136 "mismatching enums: " #a) | 136 "mismatching enums: " #a) |
137 | 137 |
138 namespace { | 138 namespace { |
139 | 139 |
140 typedef std::map<std::string, ui::TextInputMode> TextInputModeMap; | 140 typedef std::map<std::string, ui::TextInputMode> TextInputModeMap; |
141 | 141 |
| 142 class WebWidgetLockTarget : public content::MouseLockDispatcher::LockTarget { |
| 143 public: |
| 144 explicit WebWidgetLockTarget(blink::WebWidget* webwidget) |
| 145 : webwidget_(webwidget) {} |
| 146 |
| 147 void OnLockMouseACK(bool succeeded) override { |
| 148 if (succeeded) |
| 149 webwidget_->didAcquirePointerLock(); |
| 150 else |
| 151 webwidget_->didNotAcquirePointerLock(); |
| 152 } |
| 153 |
| 154 void OnMouseLockLost() override { webwidget_->didLosePointerLock(); } |
| 155 |
| 156 bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) override { |
| 157 // The WebWidget handles mouse lock in Blink's handleInputEvent(). |
| 158 return false; |
| 159 } |
| 160 |
| 161 private: |
| 162 blink::WebWidget* webwidget_; |
| 163 }; |
| 164 |
142 class TextInputModeMapSingleton { | 165 class TextInputModeMapSingleton { |
143 public: | 166 public: |
144 static TextInputModeMapSingleton* GetInstance() { | 167 static TextInputModeMapSingleton* GetInstance() { |
145 return base::Singleton<TextInputModeMapSingleton>::get(); | 168 return base::Singleton<TextInputModeMapSingleton>::get(); |
146 } | 169 } |
147 TextInputModeMapSingleton() { | 170 TextInputModeMapSingleton() { |
148 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM; | 171 map_["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM; |
149 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN; | 172 map_["latin"] = ui::TEXT_INPUT_MODE_LATIN; |
150 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME; | 173 map_["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME; |
151 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE; | 174 map_["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 389 |
367 bool RenderWidget::DoInit(int32_t opener_id, | 390 bool RenderWidget::DoInit(int32_t opener_id, |
368 WebWidget* web_widget, | 391 WebWidget* web_widget, |
369 IPC::SyncMessage* create_widget_message) { | 392 IPC::SyncMessage* create_widget_message) { |
370 DCHECK(!webwidget_); | 393 DCHECK(!webwidget_); |
371 | 394 |
372 if (opener_id != MSG_ROUTING_NONE) | 395 if (opener_id != MSG_ROUTING_NONE) |
373 opener_id_ = opener_id; | 396 opener_id_ = opener_id; |
374 | 397 |
375 webwidget_ = web_widget; | 398 webwidget_ = web_widget; |
| 399 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_)); |
| 400 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this)); |
376 | 401 |
377 bool result = true; | 402 bool result = true; |
378 if (create_widget_message) | 403 if (create_widget_message) |
379 result = RenderThread::Get()->Send(create_widget_message); | 404 result = RenderThread::Get()->Send(create_widget_message); |
380 | 405 |
381 if (result) { | 406 if (result) { |
382 RenderThread::Get()->AddRoute(routing_id_, this); | 407 RenderThread::Get()->AddRoute(routing_id_, this); |
383 // Take a reference on behalf of the RenderThread. This will be balanced | 408 // Take a reference on behalf of the RenderThread. This will be balanced |
384 // when we receive ViewMsg_Close. | 409 // when we receive ViewMsg_Close. |
385 AddRef(); | 410 AddRef(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 emulator->scale(), emulator->offset()); | 467 emulator->scale(), emulator->offset()); |
443 } | 468 } |
444 #endif | 469 #endif |
445 | 470 |
446 void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) { | 471 void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) { |
447 if (screen_metrics_emulator_) | 472 if (screen_metrics_emulator_) |
448 screen_metrics_emulator_->OnShowContextMenu(params); | 473 screen_metrics_emulator_->OnShowContextMenu(params); |
449 } | 474 } |
450 | 475 |
451 bool RenderWidget::OnMessageReceived(const IPC::Message& message) { | 476 bool RenderWidget::OnMessageReceived(const IPC::Message& message) { |
| 477 if (mouse_lock_dispatcher_ && |
| 478 mouse_lock_dispatcher_->OnMessageReceived(message)) |
| 479 return true; |
| 480 |
452 bool handled = true; | 481 bool handled = true; |
453 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) | 482 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) |
454 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent) | 483 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent) |
455 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange, | 484 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange, |
456 OnCursorVisibilityChange) | 485 OnCursorVisibilityChange) |
457 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition) | 486 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition) |
458 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition) | 487 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition) |
459 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost) | 488 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost) |
460 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus) | 489 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus) |
461 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted, | 490 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted, |
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2089 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); | 2118 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); |
2090 } | 2119 } |
2091 | 2120 |
2092 float RenderWidget::GetOriginalDeviceScaleFactor() const { | 2121 float RenderWidget::GetOriginalDeviceScaleFactor() const { |
2093 return | 2122 return |
2094 screen_metrics_emulator_ ? | 2123 screen_metrics_emulator_ ? |
2095 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : | 2124 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : |
2096 device_scale_factor_; | 2125 device_scale_factor_; |
2097 } | 2126 } |
2098 | 2127 |
| 2128 bool RenderWidget::requestPointerLock() { |
| 2129 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| 2130 } |
| 2131 |
| 2132 void RenderWidget::requestPointerUnlock() { |
| 2133 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get()); |
| 2134 } |
| 2135 |
| 2136 bool RenderWidget::isPointerLocked() { |
| 2137 return mouse_lock_dispatcher_->IsMouseLockedTo( |
| 2138 webwidget_mouse_lock_target_.get()); |
| 2139 } |
| 2140 |
2099 } // namespace content | 2141 } // namespace content |
OLD | NEW |