Chromium Code Reviews| 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 7887b5d71d80ac4d0c7ac9940e1dfdbf148c974b..c16f315a77d39602353e247720c3dde0f63c35a5 100644 |
| --- a/content/browser/renderer_host/render_widget_host_impl.cc |
| +++ b/content/browser/renderer_host/render_widget_host_impl.cc |
| @@ -737,34 +737,39 @@ void RenderWidgetHostImpl::GotFocus() { |
| } |
| void RenderWidgetHostImpl::Focus() { |
| - is_focused_ = true; |
| + RenderWidgetHostImpl* focused_widget = |
| + delegate_ ? delegate_->GetRenderWidgetHostWithPageFocus() : nullptr; |
| - Send(new InputMsg_SetFocus(routing_id_, true)); |
| - |
| - // Also send page-level focus state to other SiteInstances involved in |
| - // rendering the current FrameTree. |
| - if (RenderViewHost::From(this) && delegate_) |
| - delegate_->ReplicatePageFocus(true); |
| + (focused_widget ? focused_widget : this)->SetPageFocus(true); |
|
Charlie Reis
2016/11/16 20:28:23
Style nit: Let's avoid using ternary operators ins
avallee
2016/11/16 21:18:10
wjmaclean asked for this on https://codereview.chr
wjmaclean
2016/11/16 21:57:09
It would make sense, in this case, to do
RenderWi
Charlie Reis
2016/11/16 22:00:57
Only if GetRenderWidgetHostWithPageFocus() can nev
|
| } |
| void RenderWidgetHostImpl::Blur() { |
| - is_focused_ = false; |
| + RenderWidgetHostImpl* focused_widget = |
| + delegate_ ? delegate_->GetRenderWidgetHostWithPageFocus() : nullptr; |
| - // If there is a pending mouse lock request, we don't want to reject it at |
| - // this point. The user can switch focus back to this view and approve the |
| - // request later. |
| - if (IsMouseLocked()) |
| - view_->UnlockMouse(); |
| + (focused_widget ? focused_widget : this)->SetPageFocus(false); |
| +} |
| - if (touch_emulator_) |
| - touch_emulator_->CancelTouch(); |
| +void RenderWidgetHostImpl::SetPageFocus(bool focused) { |
| + is_focused_ = focused; |
| - Send(new InputMsg_SetFocus(routing_id_, false)); |
| + if (!focused) { |
| + // If there is a pending mouse lock request, we don't want to reject it at |
| + // this point. The user can switch focus back to this view and approve the |
| + // request later. |
| + if (IsMouseLocked()) |
| + view_->UnlockMouse(); |
| + |
| + if (touch_emulator_) |
| + touch_emulator_->CancelTouch(); |
| + } |
| + |
| + Send(new InputMsg_SetFocus(routing_id_, focused)); |
| // Also send page-level focus state to other SiteInstances involved in |
| // rendering the current FrameTree. |
| if (RenderViewHost::From(this) && delegate_) |
| - delegate_->ReplicatePageFocus(false); |
| + delegate_->ReplicatePageFocus(focused); |
| } |
| void RenderWidgetHostImpl::LostCapture() { |
| @@ -2073,11 +2078,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) |