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

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

Issue 2451143003: <webview>: Correctly shift focus between WebContents. (Closed)
Patch Set: forgot rebase Created 4 years, 1 month 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 11172c31d3b9c4f0fc6bcffb7a69d687a4238cc9..93770c167dff45e3774fdd4478e3c8c16b1e07b6 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -1871,6 +1871,10 @@ RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
}
+RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() {
+ return GetFocusedWebContents()->GetMainFrame()->GetRenderWidgetHost();
+}
+
void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
// This method is being called to enter renderer-initiated fullscreen mode.
// Make sure any existing fullscreen widget is shut down first.
@@ -4618,6 +4622,20 @@ void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
}
}
+void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() {
+ // Only change focus if we are not currently focused.
+ WebContentsImpl* old_contents = GetFocusedWebContents();
+ if (old_contents == this)
+ return;
+
+ // Send a page level blur to the old contents so that it displays inactive UI
+ // and focus this contents to activate it.
+ if (old_contents)
+ old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
+ GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
+ GetOutermostWebContents()->node_->SetFocusedWebContents(this);
+}
+
void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
SiteInstance* source) {
if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) {
@@ -4625,22 +4643,9 @@ void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
return;
}
- // 1. Find old focused frame and unfocus it.
- // 2. Focus the new frame in the current FrameTree.
- // 3. Set current WebContents as focused.
- WebContentsImpl* old_focused_contents = GetFocusedWebContents();
- if (old_focused_contents != this) {
- // Focus is moving between frame trees, unfocus the frame in the old tree.
- old_focused_contents->frame_tree_.SetFocusedFrame(nullptr, source);
- GetOutermostWebContents()->node_->SetFocusedWebContents(this);
- }
+ SetAsFocusedWebContentsIfNecessary();
frame_tree_.SetFocusedFrame(node, source);
-
- // TODO(avallee): Remove this once page focus is fixed.
- RenderWidgetHostImpl* rwh = node->current_frame_host()->GetRenderWidgetHost();
- if (rwh && old_focused_contents != this)
- rwh->Focus();
}
bool WebContentsImpl::AddMessageToConsole(int32_t level,
@@ -4670,6 +4675,20 @@ void WebContentsImpl::OnUserInteraction(
rdh->OnUserGesture();
}
+void WebContentsImpl::EnsureOwningContentsIsFocused(
+ RenderWidgetHostImpl* render_widget_host) {
+ if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
+ return;
+
+ RenderWidgetHostImpl* focused_widget =
+ GetFocusedRenderWidgetHost(render_widget_host);
+
+ if (focused_widget != render_widget_host &&
+ focused_widget->delegate() != render_widget_host->delegate()) {
+ SetAsFocusedWebContentsIfNecessary();
+ }
+}
+
void WebContentsImpl::OnIgnoredUIEvent() {
// Notify observers.
for (auto& observer : observers_)
« content/browser/frame_host/frame_tree.cc ('K') | « content/browser/web_contents/web_contents_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698