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

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 2451143003: <webview>: Correctly shift focus between WebContents. (Closed)
Patch Set: Add fix for MacOS hang. 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 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/browser/renderer_host/render_widget_host_impl.h" 5 #include "content/browser/renderer_host/render_widget_host_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <set> 9 #include <set>
10 #include <tuple> 10 #include <tuple>
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 730
731 void RenderWidgetHostImpl::GotFocus() { 731 void RenderWidgetHostImpl::GotFocus() {
732 Focus(); 732 Focus();
733 if (owner_delegate_) 733 if (owner_delegate_)
734 owner_delegate_->RenderWidgetGotFocus(); 734 owner_delegate_->RenderWidgetGotFocus();
735 if (delegate_) 735 if (delegate_)
736 delegate_->RenderWidgetGotFocus(this); 736 delegate_->RenderWidgetGotFocus(this);
737 } 737 }
738 738
739 void RenderWidgetHostImpl::Focus() { 739 void RenderWidgetHostImpl::Focus() {
740 is_focused_ = true; 740 RenderWidgetHostImpl* focused_widget =
741 delegate_ ? delegate_->GetRenderWidgetHostWithPageFocus() : nullptr;
741 742
742 Send(new InputMsg_SetFocus(routing_id_, true)); 743 (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
744 }
745
746 void RenderWidgetHostImpl::Blur() {
747 RenderWidgetHostImpl* focused_widget =
748 delegate_ ? delegate_->GetRenderWidgetHostWithPageFocus() : nullptr;
749
750 (focused_widget ? focused_widget : this)->SetPageFocus(false);
751 }
752
753 void RenderWidgetHostImpl::SetPageFocus(bool focused) {
754 is_focused_ = focused;
755
756 if (!focused) {
757 // If there is a pending mouse lock request, we don't want to reject it at
758 // this point. The user can switch focus back to this view and approve the
759 // request later.
760 if (IsMouseLocked())
761 view_->UnlockMouse();
762
763 if (touch_emulator_)
764 touch_emulator_->CancelTouch();
765 }
766
767 Send(new InputMsg_SetFocus(routing_id_, focused));
743 768
744 // Also send page-level focus state to other SiteInstances involved in 769 // Also send page-level focus state to other SiteInstances involved in
745 // rendering the current FrameTree. 770 // rendering the current FrameTree.
746 if (RenderViewHost::From(this) && delegate_) 771 if (RenderViewHost::From(this) && delegate_)
747 delegate_->ReplicatePageFocus(true); 772 delegate_->ReplicatePageFocus(focused);
748 }
749
750 void RenderWidgetHostImpl::Blur() {
751 is_focused_ = false;
752
753 // If there is a pending mouse lock request, we don't want to reject it at
754 // this point. The user can switch focus back to this view and approve the
755 // request later.
756 if (IsMouseLocked())
757 view_->UnlockMouse();
758
759 if (touch_emulator_)
760 touch_emulator_->CancelTouch();
761
762 Send(new InputMsg_SetFocus(routing_id_, false));
763
764 // Also send page-level focus state to other SiteInstances involved in
765 // rendering the current FrameTree.
766 if (RenderViewHost::From(this) && delegate_)
767 delegate_->ReplicatePageFocus(false);
768 } 773 }
769 774
770 void RenderWidgetHostImpl::LostCapture() { 775 void RenderWidgetHostImpl::LostCapture() {
771 if (touch_emulator_) 776 if (touch_emulator_)
772 touch_emulator_->CancelTouch(); 777 touch_emulator_->CancelTouch();
773 778
774 Send(new InputMsg_MouseCaptureLost(routing_id_)); 779 Send(new InputMsg_MouseCaptureLost(routing_id_));
775 780
776 if (delegate_) 781 if (delegate_)
777 delegate_->LostCapture(this); 782 delegate_->LostCapture(this);
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2066 const blink::WebInputEvent& event, const ui::LatencyInfo& latency_info) { 2071 const blink::WebInputEvent& event, const ui::LatencyInfo& latency_info) {
2067 // Don't ignore touch cancel events, since they may be sent while input 2072 // Don't ignore touch cancel events, since they may be sent while input
2068 // events are being ignored in order to keep the renderer from getting 2073 // events are being ignored in order to keep the renderer from getting
2069 // confused about how many touches are active. 2074 // confused about how many touches are active.
2070 if (ShouldDropInputEvents() && event.type != WebInputEvent::TouchCancel) 2075 if (ShouldDropInputEvents() && event.type != WebInputEvent::TouchCancel)
2071 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; 2076 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
2072 2077
2073 if (!process_->HasConnection()) 2078 if (!process_->HasConnection())
2074 return INPUT_EVENT_ACK_STATE_UNKNOWN; 2079 return INPUT_EVENT_ACK_STATE_UNKNOWN;
2075 2080
2076 if (delegate_ && (event.type == WebInputEvent::MouseDown || 2081 if (delegate_) {
2077 event.type == WebInputEvent::GestureScrollBegin || 2082 if (event.type == WebInputEvent::MouseDown ||
2078 event.type == WebInputEvent::TouchStart || 2083 event.type == WebInputEvent::TouchStart) {
2079 event.type == WebInputEvent::RawKeyDown)) { 2084 delegate_->EnsureOwningContentsIsFocused(this);
2080 delegate_->OnUserInteraction(this, event.type); 2085 }
2086 if (event.type == WebInputEvent::MouseDown ||
2087 event.type == WebInputEvent::GestureScrollBegin ||
2088 event.type == WebInputEvent::TouchStart ||
2089 event.type == WebInputEvent::RawKeyDown) {
2090 delegate_->OnUserInteraction(this, event.type);
2091 }
2081 } 2092 }
2082 2093
2083 return view_ ? view_->FilterInputEvent(event) 2094 return view_ ? view_->FilterInputEvent(event)
2084 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED; 2095 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
2085 } 2096 }
2086 2097
2087 void RenderWidgetHostImpl::IncrementInFlightEventCount( 2098 void RenderWidgetHostImpl::IncrementInFlightEventCount(
2088 blink::WebInputEvent::Type event_type) { 2099 blink::WebInputEvent::Type event_type) {
2089 increment_in_flight_event_count(); 2100 increment_in_flight_event_count();
2090 if (!is_hidden_) { 2101 if (!is_hidden_) {
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
2489 // Note: We are using the origin URL provided by the sender here. It may be 2500 // Note: We are using the origin URL provided by the sender here. It may be
2490 // different from the receiver's. 2501 // different from the receiver's.
2491 file_system_file.url = 2502 file_system_file.url =
2492 GURL(storage::GetIsolatedFileSystemRootURIString( 2503 GURL(storage::GetIsolatedFileSystemRootURIString(
2493 file_system_url.origin(), filesystem_id, std::string()) 2504 file_system_url.origin(), filesystem_id, std::string())
2494 .append(register_name)); 2505 .append(register_name));
2495 } 2506 }
2496 } 2507 }
2497 2508
2498 } // namespace content 2509 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698