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

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

Issue 2451143003: <webview>: Correctly shift focus between WebContents. (Closed)
Patch Set: Address comments from alexmos and lfg. 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 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 685
686 void RenderWidgetHostImpl::GotFocus() { 686 void RenderWidgetHostImpl::GotFocus() {
687 Focus(); 687 Focus();
688 if (owner_delegate_) 688 if (owner_delegate_)
689 owner_delegate_->RenderWidgetGotFocus(); 689 owner_delegate_->RenderWidgetGotFocus();
690 if (delegate_) 690 if (delegate_)
691 delegate_->RenderWidgetGotFocus(this); 691 delegate_->RenderWidgetGotFocus(this);
692 } 692 }
693 693
694 void RenderWidgetHostImpl::Focus() { 694 void RenderWidgetHostImpl::Focus() {
695 is_focused_ = true; 695 RenderWidgetHostImpl* focused_widget =
696 delegate_ ? delegate_->GetRenderWidgetHostWithPageFocus() : nullptr;
696 697
697 Send(new InputMsg_SetFocus(routing_id_, true)); 698 (focused_widget ? focused_widget : this)->SetPageFocus(true);
699 }
700
701 void RenderWidgetHostImpl::Blur() {
702 RenderWidgetHostImpl* focused_widget =
703 delegate_ ? delegate_->GetRenderWidgetHostWithPageFocus() : nullptr;
704
705 (focused_widget ? focused_widget : this)->SetPageFocus(false);
706 }
707
708 void RenderWidgetHostImpl::SetPageFocus(bool focused) {
709 is_focused_ = focused;
710
711 if (!focused) {
712 // If there is a pending mouse lock request, we don't want to reject it at
713 // this point. The user can switch focus back to this view and approve the
714 // request later.
715 if (IsMouseLocked())
716 view_->UnlockMouse();
717
718 if (touch_emulator_)
719 touch_emulator_->CancelTouch();
720 }
721
722 Send(new InputMsg_SetFocus(routing_id_, focused));
698 723
699 // Also send page-level focus state to other SiteInstances involved in 724 // Also send page-level focus state to other SiteInstances involved in
700 // rendering the current FrameTree. 725 // rendering the current FrameTree.
701 if (RenderViewHost::From(this) && delegate_) 726 if (RenderViewHost::From(this) && delegate_)
702 delegate_->ReplicatePageFocus(true); 727 delegate_->ReplicatePageFocus(focused);
703 }
704
705 void RenderWidgetHostImpl::Blur() {
706 is_focused_ = false;
707
708 // If there is a pending mouse lock request, we don't want to reject it at
709 // this point. The user can switch focus back to this view and approve the
710 // request later.
711 if (IsMouseLocked())
712 view_->UnlockMouse();
713
714 if (touch_emulator_)
715 touch_emulator_->CancelTouch();
716
717 Send(new InputMsg_SetFocus(routing_id_, false));
718
719 // Also send page-level focus state to other SiteInstances involved in
720 // rendering the current FrameTree.
721 if (RenderViewHost::From(this) && delegate_)
722 delegate_->ReplicatePageFocus(false);
723 } 728 }
724 729
725 void RenderWidgetHostImpl::LostCapture() { 730 void RenderWidgetHostImpl::LostCapture() {
726 if (touch_emulator_) 731 if (touch_emulator_)
727 touch_emulator_->CancelTouch(); 732 touch_emulator_->CancelTouch();
728 733
729 Send(new InputMsg_MouseCaptureLost(routing_id_)); 734 Send(new InputMsg_MouseCaptureLost(routing_id_));
730 735
731 if (delegate_) 736 if (delegate_)
732 delegate_->LostCapture(this); 737 delegate_->LostCapture(this);
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 const blink::WebInputEvent& event, const ui::LatencyInfo& latency_info) { 1884 const blink::WebInputEvent& event, const ui::LatencyInfo& latency_info) {
1880 // Don't ignore touch cancel events, since they may be sent while input 1885 // Don't ignore touch cancel events, since they may be sent while input
1881 // events are being ignored in order to keep the renderer from getting 1886 // events are being ignored in order to keep the renderer from getting
1882 // confused about how many touches are active. 1887 // confused about how many touches are active.
1883 if (ShouldDropInputEvents() && event.type != WebInputEvent::TouchCancel) 1888 if (ShouldDropInputEvents() && event.type != WebInputEvent::TouchCancel)
1884 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; 1889 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1885 1890
1886 if (!process_->HasConnection()) 1891 if (!process_->HasConnection())
1887 return INPUT_EVENT_ACK_STATE_UNKNOWN; 1892 return INPUT_EVENT_ACK_STATE_UNKNOWN;
1888 1893
1889 if (delegate_ && (event.type == WebInputEvent::MouseDown || 1894 if (delegate_) {
1890 event.type == WebInputEvent::GestureScrollBegin || 1895 if (event.type == WebInputEvent::MouseDown ||
1891 event.type == WebInputEvent::TouchStart || 1896 event.type == WebInputEvent::TouchStart) {
1892 event.type == WebInputEvent::RawKeyDown)) { 1897 delegate_->EnsureOwningContentsIsFocused(this);
1893 delegate_->OnUserInteraction(this, event.type); 1898 }
1899 if (event.type == WebInputEvent::MouseDown ||
1900 event.type == WebInputEvent::GestureScrollBegin ||
1901 event.type == WebInputEvent::TouchStart ||
1902 event.type == WebInputEvent::RawKeyDown) {
1903 delegate_->OnUserInteraction(this, event.type);
1904 }
1894 } 1905 }
1895 1906
1896 return view_ ? view_->FilterInputEvent(event) 1907 return view_ ? view_->FilterInputEvent(event)
1897 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED; 1908 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1898 } 1909 }
1899 1910
1900 void RenderWidgetHostImpl::IncrementInFlightEventCount( 1911 void RenderWidgetHostImpl::IncrementInFlightEventCount(
1901 blink::WebInputEvent::Type event_type) { 1912 blink::WebInputEvent::Type event_type) {
1902 increment_in_flight_event_count(); 1913 increment_in_flight_event_count();
1903 if (!is_hidden_) { 1914 if (!is_hidden_) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; 2233 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL;
2223 } 2234 }
2224 2235
2225 BrowserAccessibilityManager* 2236 BrowserAccessibilityManager*
2226 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { 2237 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() {
2227 return delegate_ ? 2238 return delegate_ ?
2228 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; 2239 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL;
2229 } 2240 }
2230 2241
2231 } // namespace content 2242 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698