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

Unified Diff: content/browser/web_contents/web_contents_impl.cc

Issue 2591783003: Implement pointer lock across outer/inner WebContents. (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/web_contents/web_contents_impl.cc
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index c8b38722cbd096c893ec16e258aae8768681b16b..03fa5d5aee10f1f32d234d9d48007c7289849200 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -1916,12 +1916,16 @@ void WebContentsImpl::RequestToLockMouse(
bool user_gesture,
bool last_unlocked_by_target,
bool privileged) {
- if (mouse_lock_widget_) {
- render_widget_host->GotResponseToLockMouseRequest(false);
- return;
+ for (WebContentsImpl* current = this; current;
+ current = current->GetOuterWebContents()) {
+ if (current->mouse_lock_widget_) {
ncarter (slow) 2016/12/22 00:01:07 I'm wondering if we should contemplate having some
lfg 2016/12/22 19:23:55 I thought about that a bit, but for a single point
+ render_widget_host->GotResponseToLockMouseRequest(false);
+ return;
+ }
}
if (privileged) {
+ DCHECK(!GetOuterWebContents());
mouse_lock_widget_ = render_widget_host;
render_widget_host->GotResponseToLockMouseRequest(true);
return;
@@ -1937,7 +1941,11 @@ void WebContentsImpl::RequestToLockMouse(
}
if (widget_in_frame_tree && delegate_) {
- mouse_lock_widget_ = render_widget_host;
+ for (WebContentsImpl* current = this; current;
+ current = current->GetOuterWebContents()) {
+ current->mouse_lock_widget_ = render_widget_host;
+ }
+
delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
} else {
render_widget_host->GotResponseToLockMouseRequest(false);
@@ -1946,8 +1954,15 @@ void WebContentsImpl::RequestToLockMouse(
void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
CHECK(mouse_lock_widget_);
+
+ if (mouse_lock_widget_->delegate()->GetAsWebContents() != this)
+ return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host);
+
mouse_lock_widget_->SendMouseLockLost();
- mouse_lock_widget_ = nullptr;
+ for (WebContentsImpl* current = this; current;
+ current = current->GetOuterWebContents()) {
+ current->mouse_lock_widget_ = nullptr;
+ }
if (delegate_)
delegate_->LostMouseLock();
@@ -3063,14 +3078,26 @@ gfx::Size WebContentsImpl::GetPreferredSize() const {
}
bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
- if (GetBrowserPluginGuest())
+ if (!GuestMode::IsCrossProcessFrameGuest(GetWebContents()) &&
+ GetBrowserPluginGuest())
return GetBrowserPluginGuest()->LockMouse(allowed);
- if (mouse_lock_widget_ &&
- mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
- return true;
+ if (mouse_lock_widget_) {
+ if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) {
ncarter (slow) 2016/12/22 00:01:07 When does this case happen? From what I can tell,
lfg 2016/12/22 19:23:55 GotResponseToLockMouseRequest is a poor name for t
+ return mouse_lock_widget_->delegate()
+ ->GetAsWebContents()
+ ->GotResponseToLockMouseRequest(allowed);
+ }
+
+ if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed))
+ return true;
+ }
+
+ for (WebContentsImpl* current = this; current;
+ current = current->GetOuterWebContents()) {
+ current->mouse_lock_widget_ = nullptr;
+ }
- mouse_lock_widget_ = nullptr;
return false;
}

Powered by Google App Engine
This is Rietveld 408576698