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

Unified Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 2451143003: <webview>: Correctly shift focus between WebContents. (Closed)
Patch Set: Address wjmaclean comment: ternary op. Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_impl.cc
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc
index 0ce169540b3cae2c0e67d865f585d0d48d8763a3..24fdb73baac47aafaf8162e021d33d85483c8ec6 100644
--- a/content/browser/renderer_host/render_widget_host_impl.cc
+++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -692,6 +692,26 @@ void RenderWidgetHostImpl::GotFocus() {
}
void RenderWidgetHostImpl::Focus() {
+ RenderWidgetHostImpl* focused_widget =
+ delegate_ ? delegate_->GetFocusedRenderWidgetHost(this) : nullptr;
alexmos 2016/10/28 06:36:39 I think in the case where GetFocusedRenderWidgetHo
avallee 2016/10/28 19:19:56 The main place where Focus() is called is from the
alexmos 2016/10/31 18:57:57 It might not always be safe: a malicious embedder
avallee 2016/11/16 05:38:09 Would crashing the renderer lead a focus change? C
alexmos 2016/11/16 23:29:02 I'm not sure -- that's why I was curious if you co
+
+ if (focused_widget)
+ focused_widget->FocusDirect();
alexmos 2016/10/28 06:36:39 I'm trying to understand the implication of this c
avallee 2016/10/28 19:19:56 I believe that GetFocusedWebContents()->GetMainFra
alexmos 2016/10/31 18:57:57 Yes, that looks better. However, are we sure that
alexmos 2016/11/09 02:47:54 Still curious about this. Might be worth trying p
avallee 2016/11/16 05:38:09 This DCHECK would fail if a webview is focused. On
alexmos 2016/11/16 23:29:02 Sorry, the DCHECK I had in mind was assuming a sin
+ else
+ FocusDirect();
+}
+
+void RenderWidgetHostImpl::Blur() {
+ RenderWidgetHostImpl* focused_widget =
+ delegate_ ? delegate_->GetFocusedRenderWidgetHost(this) : nullptr;
+
+ if (focused_widget)
+ focused_widget->BlurDirect();
+ else
+ BlurDirect();
+}
+
+void RenderWidgetHostImpl::FocusDirect() {
alexmos 2016/10/28 06:36:39 I find these names a bit hard to interpret. Since
avallee 2016/10/28 19:19:56 Done.
is_focused_ = true;
Send(new InputMsg_SetFocus(routing_id_, true));
@@ -702,7 +722,7 @@ void RenderWidgetHostImpl::Focus() {
delegate_->ReplicatePageFocus(true);
}
-void RenderWidgetHostImpl::Blur() {
+void RenderWidgetHostImpl::BlurDirect() {
is_focused_ = false;
// If there is a pending mouse lock request, we don't want to reject it at
@@ -1886,11 +1906,17 @@ InputEventAckState RenderWidgetHostImpl::FilterInputEvent(
if (!process_->HasConnection())
return INPUT_EVENT_ACK_STATE_UNKNOWN;
- if (delegate_ && (event.type == WebInputEvent::MouseDown ||
- event.type == WebInputEvent::GestureScrollBegin ||
- event.type == WebInputEvent::TouchStart ||
- event.type == WebInputEvent::RawKeyDown)) {
- delegate_->OnUserInteraction(this, event.type);
+ if (delegate_) {
+ if (event.type == WebInputEvent::MouseDown ||
+ event.type == WebInputEvent::TouchStart) {
+ delegate_->EnsureOwningContentsIsFocused(this);
+ }
+ if (event.type == WebInputEvent::MouseDown ||
+ event.type == WebInputEvent::GestureScrollBegin ||
+ event.type == WebInputEvent::TouchStart ||
+ event.type == WebInputEvent::RawKeyDown) {
+ delegate_->OnUserInteraction(this, event.type);
+ }
}
return view_ ? view_->FilterInputEvent(event)

Powered by Google App Engine
This is Rietveld 408576698