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

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

Issue 1980133002: Implement pointer lock API for out-of-process iframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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
OLDNEW
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
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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 328 }
306 scoped_refptr<RenderWidget> widget( 329 scoped_refptr<RenderWidget> widget(
307 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info, 330 new RenderWidget(compositor_deps, blink::WebPopupTypeNone, screen_info,
308 false, hidden, false)); 331 false, hidden, false));
309 widget->SetRoutingID(routing_id); 332 widget->SetRoutingID(routing_id);
310 widget->for_oopif_ = true; 333 widget->for_oopif_ = true;
311 // DoInit increments the reference count on |widget|, keeping it alive after 334 // DoInit increments the reference count on |widget|, keeping it alive after
312 // this function returns. 335 // this function returns.
313 if (widget->DoInit(MSG_ROUTING_NONE, 336 if (widget->DoInit(MSG_ROUTING_NONE,
314 RenderWidget::CreateWebFrameWidget(widget.get(), frame), 337 RenderWidget::CreateWebFrameWidget(widget.get(), frame),
315 nullptr)) { 338 nullptr, true)) {
316 return widget.get(); 339 return widget.get();
317 } 340 }
318 return nullptr; 341 return nullptr;
319 } 342 }
320 343
321 // static 344 // static
322 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( 345 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget(
323 RenderWidget* render_widget, 346 RenderWidget* render_widget,
324 blink::WebLocalFrame* frame) { 347 blink::WebLocalFrame* frame) {
325 if (!frame->parent()) { 348 if (!frame->parent()) {
(...skipping 23 matching lines...) Expand all
349 372
350 void RenderWidget::SetRoutingID(int32_t routing_id) { 373 void RenderWidget::SetRoutingID(int32_t routing_id) {
351 routing_id_ = routing_id; 374 routing_id_ = routing_id;
352 input_handler_.reset(new RenderWidgetInputHandler( 375 input_handler_.reset(new RenderWidgetInputHandler(
353 GetRenderWidgetInputHandlerDelegate(this), this)); 376 GetRenderWidgetInputHandlerDelegate(this), this));
354 } 377 }
355 378
356 bool RenderWidget::Init(int32_t opener_id) { 379 bool RenderWidget::Init(int32_t opener_id) {
357 bool success = DoInit( 380 bool success = DoInit(
358 opener_id, RenderWidget::CreateWebWidget(this), 381 opener_id, RenderWidget::CreateWebWidget(this),
359 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_)); 382 new ViewHostMsg_CreateWidget(opener_id, popup_type_, &routing_id_), true);
360 if (success) { 383 if (success) {
361 SetRoutingID(routing_id_); 384 SetRoutingID(routing_id_);
362 return true; 385 return true;
363 } 386 }
364 return false; 387 return false;
365 } 388 }
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,
393 bool should_add_route) {
dcheng 2016/06/04 05:28:56 Can we just make RenderView::Initialize() not add
lfg 2016/06/06 20:09:43 Done.
370 DCHECK(!webwidget_); 394 DCHECK(!webwidget_);
371 395
372 if (opener_id != MSG_ROUTING_NONE) 396 if (opener_id != MSG_ROUTING_NONE)
373 opener_id_ = opener_id; 397 opener_id_ = opener_id;
374 398
375 webwidget_ = web_widget; 399 webwidget_ = web_widget;
400 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
401 mouse_lock_dispatcher_ =
402 base::WrapUnique(new RenderWidgetMouseLockDispatcher(this));
dcheng 2016/06/04 05:28:56 Nit: base::MakeUnique, or be consistent with line
lfg 2016/06/06 20:09:43 Done.
376 403
377 bool result = true; 404 bool result = true;
378 if (create_widget_message) 405 if (create_widget_message)
379 result = RenderThread::Get()->Send(create_widget_message); 406 result = RenderThread::Get()->Send(create_widget_message);
380 407
408 if (!should_add_route)
409 return true;
410
381 if (result) { 411 if (result) {
382 RenderThread::Get()->AddRoute(routing_id_, this); 412 RenderThread::Get()->AddRoute(routing_id_, this);
383 // Take a reference on behalf of the RenderThread. This will be balanced 413 // Take a reference on behalf of the RenderThread. This will be balanced
384 // when we receive ViewMsg_Close. 414 // when we receive ViewMsg_Close.
385 AddRef(); 415 AddRef();
386 if (RenderThreadImpl::current()) { 416 if (RenderThreadImpl::current()) {
387 RenderThreadImpl::current()->WidgetCreated(); 417 RenderThreadImpl::current()->WidgetCreated();
388 if (is_hidden_) 418 if (is_hidden_)
389 RenderThreadImpl::current()->WidgetHidden(); 419 RenderThreadImpl::current()->WidgetHidden();
390 } 420 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 emulator->scale(), emulator->offset()); 472 emulator->scale(), emulator->offset());
443 } 473 }
444 #endif 474 #endif
445 475
446 void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) { 476 void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
447 if (screen_metrics_emulator_) 477 if (screen_metrics_emulator_)
448 screen_metrics_emulator_->OnShowContextMenu(params); 478 screen_metrics_emulator_->OnShowContextMenu(params);
449 } 479 }
450 480
451 bool RenderWidget::OnMessageReceived(const IPC::Message& message) { 481 bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
482 if (mouse_lock_dispatcher_ &&
483 mouse_lock_dispatcher_->OnMessageReceived(message))
484 return true;
485
452 bool handled = true; 486 bool handled = true;
453 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) 487 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
454 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent) 488 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
455 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange, 489 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
456 OnCursorVisibilityChange) 490 OnCursorVisibilityChange)
457 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition) 491 IPC_MESSAGE_HANDLER(InputMsg_ImeSetComposition, OnImeSetComposition)
458 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition) 492 IPC_MESSAGE_HANDLER(InputMsg_ImeConfirmComposition, OnImeConfirmComposition)
459 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost) 493 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
460 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus) 494 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
461 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted, 495 IPC_MESSAGE_HANDLER(InputMsg_SyntheticGestureCompleted,
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE); 2123 MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE);
2090 } 2124 }
2091 2125
2092 float RenderWidget::GetOriginalDeviceScaleFactor() const { 2126 float RenderWidget::GetOriginalDeviceScaleFactor() const {
2093 return 2127 return
2094 screen_metrics_emulator_ ? 2128 screen_metrics_emulator_ ?
2095 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : 2129 screen_metrics_emulator_->original_screen_info().deviceScaleFactor :
2096 device_scale_factor_; 2130 device_scale_factor_;
2097 } 2131 }
2098 2132
2133 bool RenderWidget::requestPointerLock() {
2134 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2135 }
2136
2137 void RenderWidget::requestPointerUnlock() {
2138 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2139 }
2140
2141 bool RenderWidget::isPointerLocked() {
2142 return mouse_lock_dispatcher_->IsMouseLockedTo(
2143 webwidget_mouse_lock_target_.get());
2144 }
2145
2099 } // namespace content 2146 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698