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

Side by Side Diff: content/browser/frame_host/render_widget_host_view_guest.cc

Issue 1934703002: Fix keyboard focus for OOPIF-<webview>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed WebViewTests/WebViewTest.SelectShowHide/1 browser_test Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/frame_host/render_widget_host_view_guest.h" 5 #include "content/browser/frame_host/render_widget_host_view_guest.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 #if defined(USE_AURA) 160 #if defined(USE_AURA)
161 void RenderWidgetHostViewGuest::ProcessAckedTouchEvent( 161 void RenderWidgetHostViewGuest::ProcessAckedTouchEvent(
162 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) { 162 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) {
163 // TODO(tdresser): Since all ProcessAckedTouchEvent() uses is the event id, 163 // TODO(tdresser): Since all ProcessAckedTouchEvent() uses is the event id,
164 // don't pass the full event object here. https://crbug.com/550581. 164 // don't pass the full event object here. https://crbug.com/550581.
165 GetOwnerRenderWidgetHostView()->ProcessAckedTouchEvent(touch, ack_result); 165 GetOwnerRenderWidgetHostView()->ProcessAckedTouchEvent(touch, ack_result);
166 } 166 }
167 #endif 167 #endif
168 168
169 void RenderWidgetHostViewGuest::ProcessMouseEvent(
170 const blink::WebMouseEvent& event,
171 const ui::LatencyInfo& latency) {
172 if (event.type == blink::WebInputEvent::MouseDown) {
173 DCHECK(guest_->GetOwnerRenderWidgetHostView());
174 RenderWidgetHostImpl* embedder = static_cast<RenderWidgetHostImpl*>(
alexmos 2016/07/26 21:08:30 Is this cast necessary? Calling GetView()->HasFoc
avallee 2016/07/27 01:30:18 Done.
175 guest_->GetOwnerRenderWidgetHostView()->GetRenderWidgetHost());
176 if (!embedder->GetView()->HasFocus())
177 embedder->GetView()->Focus();
178
179 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code.
180 // http://crbug.com/533069
181 MaybeSendSyntheticTapGesture(
182 blink::WebFloatPoint(event.x, event.y),
183 blink::WebFloatPoint(event.globalX, event.globalY));
184 }
185 host_->ForwardMouseEventWithLatencyInfo(event, latency);
186 }
187
169 void RenderWidgetHostViewGuest::ProcessTouchEvent( 188 void RenderWidgetHostViewGuest::ProcessTouchEvent(
170 const blink::WebTouchEvent& event, 189 const blink::WebTouchEvent& event,
171 const ui::LatencyInfo& latency) { 190 const ui::LatencyInfo& latency) {
172 if (event.type == blink::WebInputEvent::TouchStart) { 191 if (event.type == blink::WebInputEvent::TouchStart) {
173 DCHECK(guest_->GetOwnerRenderWidgetHostView()); 192 DCHECK(guest_->GetOwnerRenderWidgetHostView());
174 RenderWidgetHostImpl* embedder = static_cast<RenderWidgetHostImpl*>( 193 RenderWidgetHostImpl* embedder = static_cast<RenderWidgetHostImpl*>(
175 guest_->GetOwnerRenderWidgetHostView()->GetRenderWidgetHost()); 194 guest_->GetOwnerRenderWidgetHostView()->GetRenderWidgetHost());
176 if (!embedder->GetView()->HasFocus()) 195 if (!embedder->GetView()->HasFocus())
177 embedder->GetView()->Focus(); 196 embedder->GetView()->Focus();
178 197
179 // Since we now route GestureEvents directly to the guest renderer, we need
180 // a way to make sure that the BrowserPlugin in the embedder gets focused so
181 // that keyboard input (which still travels via BrowserPlugin) is routed to
182 // the plugin and thus onwards to the guest.
wjmaclean 2016/07/25 19:54:31 Is it worth keeping some part of this comment arou
avallee 2016/07/26 20:11:51 Done.
183 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code. 198 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code.
184 // http://crbug.com/533069 199 // http://crbug.com/533069
185 if (!HasFocus()) { 200 MaybeSendSyntheticTapGesture(event.touches[0].position,
186 // We need to a account for the position of the guest view within the 201 event.touches[0].screenPosition);
187 // embedder, as well as the fact that the embedder's host will add its
188 // offset in screen coordinates before sending the event (with the latter
189 // component just serving to confuse the renderer, hence why it should be
190 // removed).
191 gfx::Vector2d offset = GetViewBounds().origin() -
192 GetOwnerRenderWidgetHostView()->GetBoundsInRootWindow().origin();
193 blink::WebGestureEvent gesture_tap_event;
194 gesture_tap_event.sourceDevice = blink::WebGestureDeviceTouchscreen;
195 gesture_tap_event.type = blink::WebGestureEvent::GestureTapDown;
196 gesture_tap_event.x = event.touches[0].position.x + offset.x();
197 gesture_tap_event.y = event.touches[0].position.y + offset.y();
198 gesture_tap_event.globalX = event.touches[0].screenPosition.x;
199 gesture_tap_event.globalY = event.touches[0].screenPosition.y;
200 GetOwnerRenderWidgetHostView()->ProcessGestureEvent(gesture_tap_event,
201 ui::LatencyInfo());
202 gesture_tap_event.type = blink::WebGestureEvent::GestureTapCancel;
203 GetOwnerRenderWidgetHostView()->ProcessGestureEvent(gesture_tap_event,
204 ui::LatencyInfo());
205 }
206 } 202 }
207 203
208 host_->ForwardTouchEventWithLatencyInfo(event, latency); 204 host_->ForwardTouchEventWithLatencyInfo(event, latency);
209 } 205 }
210 206
211 gfx::Rect RenderWidgetHostViewGuest::GetViewBounds() const { 207 gfx::Rect RenderWidgetHostViewGuest::GetViewBounds() const {
212 if (!guest_) 208 if (!guest_)
213 return gfx::Rect(); 209 return gfx::Rect();
214 210
215 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView(); 211 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView();
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 void RenderWidgetHostViewGuest::UnlockCompositingSurface() { 520 void RenderWidgetHostViewGuest::UnlockCompositingSurface() {
525 NOTIMPLEMENTED(); 521 NOTIMPLEMENTED();
526 } 522 }
527 523
528 RenderWidgetHostViewBase* 524 RenderWidgetHostViewBase*
529 RenderWidgetHostViewGuest::GetOwnerRenderWidgetHostView() const { 525 RenderWidgetHostViewGuest::GetOwnerRenderWidgetHostView() const {
530 return static_cast<RenderWidgetHostViewBase*>( 526 return static_cast<RenderWidgetHostViewBase*>(
531 guest_->GetOwnerRenderWidgetHostView()); 527 guest_->GetOwnerRenderWidgetHostView());
532 } 528 }
533 529
530 // TODO(wjmaclean): When we remove BrowserPlugin, delete this code.
531 // http://crbug.com/533069
532 void RenderWidgetHostViewGuest::MaybeSendSyntheticTapGesture(
533 const blink::WebFloatPoint& position,
534 const blink::WebFloatPoint& screenPosition) const {
535 if (!HasFocus()) {
536 // We need to a account for the position of the guest view within the
537 // embedder, as well as the fact that the embedder's host will add its
538 // offset in screen coordinates before sending the event (with the latter
539 // component just serving to confuse the renderer, hence why it should be
540 // removed).
541 gfx::Vector2d offset =
542 GetViewBounds().origin() -
543 GetOwnerRenderWidgetHostView()->GetBoundsInRootWindow().origin();
544 blink::WebGestureEvent gesture_tap_event;
545 gesture_tap_event.sourceDevice = blink::WebGestureDeviceTouchscreen;
546 gesture_tap_event.type = blink::WebGestureEvent::GestureTapDown;
547 gesture_tap_event.x = position.x + offset.x();
548 gesture_tap_event.y = position.y + offset.y();
549 gesture_tap_event.globalX = screenPosition.x;
550 gesture_tap_event.globalY = screenPosition.y;
551 GetOwnerRenderWidgetHostView()->ProcessGestureEvent(gesture_tap_event,
552 ui::LatencyInfo());
553 gesture_tap_event.type = blink::WebGestureEvent::GestureTapCancel;
554 GetOwnerRenderWidgetHostView()->ProcessGestureEvent(gesture_tap_event,
555 ui::LatencyInfo());
556 }
557 }
558
534 void RenderWidgetHostViewGuest::WheelEventAck( 559 void RenderWidgetHostViewGuest::WheelEventAck(
535 const blink::WebMouseWheelEvent& event, 560 const blink::WebMouseWheelEvent& event,
536 InputEventAckState ack_result) { 561 InputEventAckState ack_result) {
537 if (ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED || 562 if (ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED ||
538 ack_result == INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS) { 563 ack_result == INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS) {
539 guest_->ResendEventToEmbedder(event); 564 guest_->ResendEventToEmbedder(event);
540 } 565 }
541 } 566 }
542 567
543 void RenderWidgetHostViewGuest::GestureEventAck( 568 void RenderWidgetHostViewGuest::GestureEventAck(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 gesture_event.data.scrollUpdate.inertialPhase == 663 gesture_event.data.scrollUpdate.inertialPhase ==
639 blink::WebGestureEvent::MomentumPhase) { 664 blink::WebGestureEvent::MomentumPhase) {
640 return; 665 return;
641 } 666 }
642 host_->ForwardGestureEvent(gesture_event); 667 host_->ForwardGestureEvent(gesture_event);
643 return; 668 return;
644 } 669 }
645 } 670 }
646 671
647 } // namespace content 672 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698