Commit 347f2466 authored by wjmaclean's avatar wjmaclean Committed by Commit bot

Send synthetic GestureTapDown to focus BrowserPlugin

Since we now route Gesture events directly to the guest renderer, there
is no longer any event to focus the BrowserPlugin in the embedder
renderer, meaning that even though touch/gesture events work properly,
the guest may not receive keyboard input.

This CL provides a temporary fix by sending a synthetic GestureTapDown
to the embedder on TouchStarti, in parallel with sending the TouchStart
directly to the guest. The synthetic event focuses the BrowserPlugin.

This CL also fixes two tests that were still sending Gestures to the
embedder.

When BrowserPlugin is removed, this code will disappear along with
RenderWidgetHostViewGuest.

BUG=619906
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2101663002
Cr-Commit-Position: refs/heads/master@{#403308}
parent a796d935
......@@ -3405,16 +3405,13 @@ IN_PROC_BROWSER_TEST_P(WebViewGuestScrollTouchTest,
// Perform a scroll gesture of the same magnitude, but in the opposite
// direction and centered over the GuestView this time.
guest_rect = guest_contents->GetContainerBounds();
embedder_rect = embedder_contents->GetContainerBounds();
guest_rect.set_x(guest_rect.x() - embedder_rect.x());
guest_rect.set_y(guest_rect.y() - embedder_rect.y());
{
gfx::Point guest_scroll_location(guest_rect.x() + guest_rect.width() / 2,
guest_rect.y());
gfx::Point guest_scroll_location(guest_rect.width() / 2,
guest_rect.height() / 2);
ScrollWaiter waiter(embedder_host_view);
content::SimulateGestureScrollSequence(embedder_contents,
content::SimulateGestureScrollSequence(guest_contents,
guest_scroll_location,
gfx::Vector2dF(0, gesture_distance));
......@@ -3462,8 +3459,7 @@ IN_PROC_BROWSER_TEST_P(WebViewScrollGuestContentTest, ScrollGuestContent) {
EXPECT_EQ(gfx::Vector2dF(), guest_host_view->GetLastScrollOffset());
EXPECT_EQ(gfx::Vector2dF(), embedder_host_view->GetLastScrollOffset());
gfx::Point guest_scroll_location(guest_rect.x() + guest_rect.width() / 2,
guest_rect.y());
gfx::Point guest_scroll_location(guest_rect.width() / 2, 0);
float gesture_distance = 15.f;
{
......@@ -3472,7 +3468,7 @@ IN_PROC_BROWSER_TEST_P(WebViewScrollGuestContentTest, ScrollGuestContent) {
ScrollWaiter waiter(guest_host_view);
content::SimulateGestureScrollSequence(
embedder_contents, guest_scroll_location,
guest_contents, guest_scroll_location,
gfx::Vector2dF(0, -gesture_distance));
waiter.WaitForScrollChange(expected_offset);
......@@ -3486,7 +3482,7 @@ IN_PROC_BROWSER_TEST_P(WebViewScrollGuestContentTest, ScrollGuestContent) {
ScrollWaiter waiter(guest_host_view);
content::SimulateGestureFlingSequence(
embedder_contents, guest_scroll_location,
guest_contents, guest_scroll_location,
gfx::Vector2dF(0, fling_velocity));
waiter.WaitForScrollChange(gfx::Vector2dF());
......
......@@ -175,6 +175,34 @@ void RenderWidgetHostViewGuest::ProcessTouchEvent(
guest_->GetOwnerRenderWidgetHostView()->GetRenderWidgetHost());
if (!embedder->GetView()->HasFocus())
embedder->GetView()->Focus();
// Since we now route GestureEvents directly to the guest renderer, we need
// a way to make sure that the BrowserPlugin in the embedder gets focused so
// that keyboard input (which still travels via BrowserPlugin) is routed to
// the plugin and thus onwards to the guest.
// TODO(wjmaclean): When we remove BrowserPlugin, delete this code.
// http://crbug.com/533069
if (!HasFocus()) {
// We need to a account for the position of the guest view within the
// embedder, as well as the fact that the embedder's host will add its
// offset in screen coordinates before sending the event (with the latter
// component just serving to confuse the renderer, hence why it should be
// removed).
gfx::Vector2d offset = GetViewBounds().origin() -
GetOwnerRenderWidgetHostView()->GetBoundsInRootWindow().origin();
blink::WebGestureEvent gesture_tap_event;
gesture_tap_event.sourceDevice = blink::WebGestureDeviceTouchscreen;
gesture_tap_event.type = blink::WebGestureEvent::GestureTapDown;
gesture_tap_event.x = event.touches[0].position.x + offset.x();
gesture_tap_event.y = event.touches[0].position.y + offset.y();
gesture_tap_event.globalX = event.touches[0].screenPosition.x;
gesture_tap_event.globalY = event.touches[0].screenPosition.y;
GetOwnerRenderWidgetHostView()->ProcessGestureEvent(gesture_tap_event,
ui::LatencyInfo());
gesture_tap_event.type = blink::WebGestureEvent::GestureTapCancel;
GetOwnerRenderWidgetHostView()->ProcessGestureEvent(gesture_tap_event,
ui::LatencyInfo());
}
}
host_->ForwardTouchEventWithLatencyInfo(event, latency);
......
......@@ -429,8 +429,14 @@ blink::WebInputEventResult BrowserPlugin::handleInputEvent(
if (blink::WebInputEvent::isGestureEventType(event.type)) {
auto gesture_event = static_cast<const blink::WebGestureEvent&>(event);
if (gesture_event.resendingPluginId == browser_plugin_instance_id_)
return blink::WebInputEventResult::NotHandled;
DCHECK(blink::WebInputEvent::GestureTapDown == event.type ||
gesture_event.resendingPluginId == browser_plugin_instance_id_);
// We shouldn't be forwarding GestureEvents to the Guest anymore. Indicate
// we handled this only if it's a non-resent event.
return gesture_event.resendingPluginId == browser_plugin_instance_id_
? blink::WebInputEventResult::NotHandled
: blink::WebInputEventResult::HandledApplication;
}
if (event.type == blink::WebInputEvent::ContextMenu)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment