Commit be51aadb authored by Kevin McNee's avatar Kevin McNee Committed by Commit Bot

Consistent touchpad pinch behaviour for app windows and webviews

Currently, app windows (possibly containing webviews):
1) suppress all pinch events which also suppresses the
   synthetic wheel event, but not touchscreen touch events, and
2) allow "smart zoom" on Mac which can change the page scale even
   though other means of changing the page scale are suppressed.

As a result of (1), if we have, say, google maps in a webview, a
user can pinch zoom with a touchscreen, but not with a touchpad.

We now suppress gesture events to app windows based on whether they
cause a scale change. So now touchscreen and touchpad pinching are
consistent since the page has access to the events so that it may
implement custom pinch zoom behaviour, but unhandled events still
do not result in a scale change for the app window. Also, smart
zoom is suppressed to be consistent with other touchpad pinching.

Bug: 725970, 874132
Change-Id: I03dd2048002d69dc7c8a822fc727140c67d64706
Reviewed-on: https://chromium-review.googlesource.com/1174933Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Reviewed-by: default avatarJames MacLean <wjmaclean@chromium.org>
Reviewed-by: default avatarEhsan Karamad <ekaramad@chromium.org>
Commit-Queue: Kevin McNee <mcnee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585489}
parent ec5aed42
...@@ -4430,3 +4430,26 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, AutoResizeMessages) { ...@@ -4430,3 +4430,26 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, AutoResizeMessages) {
embedder->GetRenderWidgetHostView()->GetRenderWidgetHost()->GetProcess(), embedder->GetRenderWidgetHostView()->GetRenderWidgetHost()->GetProcess(),
guest->GetRenderWidgetHostView()->GetRenderWidgetHost())); guest->GetRenderWidgetHostView()->GetRenderWidgetHost()));
} }
// Test that a guest sees the synthetic wheel events of a touchpad pinch.
IN_PROC_BROWSER_TEST_F(WebViewTest, TouchpadPinchSyntheticWheelEvents) {
ASSERT_TRUE(StartEmbeddedTestServer());
LoadAppWithGuest("web_view/touchpad_pinch");
content::WebContents* guest_contents = GetGuestWebContents();
// Ensure the compositor thread is aware of the wheel listener.
content::MainThreadFrameObserver synchronize_threads(
guest_contents->GetRenderWidgetHostView()->GetRenderWidgetHost());
synchronize_threads.Wait();
ExtensionTestMessageListener synthetic_wheel_listener("Seen wheel event",
false);
const gfx::Rect contents_rect = guest_contents->GetContainerBounds();
const gfx::Point pinch_position(contents_rect.width() / 2,
contents_rect.height() / 2);
content::SimulateGesturePinchSequence(guest_contents, pinch_position, 1.23,
blink::kWebGestureDeviceTouchpad);
ASSERT_TRUE(synthetic_wheel_listener.WaitUntilSatisfied());
}
...@@ -1400,4 +1400,32 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, NewWindowAboutBlank) { ...@@ -1400,4 +1400,32 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, NewWindowAboutBlank) {
ASSERT_TRUE(RunPlatformAppTest("platform_apps/new_window_about_blank")); ASSERT_TRUE(RunPlatformAppTest("platform_apps/new_window_about_blank"));
} }
// Test that an app window sees the synthetic wheel events of a touchpad pinch.
// While the app window itself does not scale in response to a pinch, we
// still offer the synthetic wheels for pages that want to implement custom
// pinch zoom behaviour.
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
TouchpadPinchSyntheticWheelEvents) {
LoadAndLaunchPlatformApp("touchpad_pinch", "Launched");
WebContents* web_contents = GetFirstAppWindowWebContents();
ASSERT_TRUE(web_contents);
// Ensure the compositor thread is aware of the wheel listener.
content::MainThreadFrameObserver synchronize_threads(
web_contents->GetRenderWidgetHostView()->GetRenderWidgetHost());
synchronize_threads.Wait();
ExtensionTestMessageListener synthetic_wheel_listener("Seen wheel event",
false);
const gfx::Rect contents_rect = web_contents->GetContainerBounds();
const gfx::Point pinch_position(contents_rect.width() / 2,
contents_rect.height() / 2);
content::SimulateGesturePinchSequence(web_contents, pinch_position, 1.23,
blink::kWebGestureDeviceTouchpad);
ASSERT_TRUE(synthetic_wheel_listener.WaitUntilSatisfied());
}
} // namespace extensions } // namespace extensions
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('window.html');
});
{
"name": "Touchpad pinch synthetic wheel event",
"version": "1",
"manifest_version": 2,
"app": {
"background": {
"scripts": ["background.js"]
}
}
}
<!--
* Copyright (c) 2018 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<html>
<head>
<style>
html,body {
height: 100%;
}
</style>
</head>
<body>
<p>Hello.</p>
<script src="window.js"></script>
</body>
</html>
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
window.onload = () => {
document.body.addEventListener('wheel', (e) => {
chrome.test.sendMessage('Seen wheel event');
});
chrome.test.sendMessage('Launched');
};
<!--
* Copyright (c) 2018 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<html>
<body>
<script src="embedder.js"></script>
</body>
</html>
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
window.onload = () => {
chrome.test.getConfig(function(config) {
var guestURL = 'http://localhost:' + config.testServer.port +
'/extensions/platform_apps/web_view/touchpad_pinch/guest.html';
var webview = document.createElement('webview');
webview.src = guestURL;
webview.addEventListener('loadstop', () => {
webview.contentWindow.postMessage({}, '*');
});
document.body.appendChild(webview);
});
};
window.addEventListener('message', (e) => {
chrome.test.sendMessage(e.data);
});
<!--
* Copyright (c) 2018 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<html>
<head>
<style>
html,body {
height: 100%;
}
</style>
</head>
<body>
<p>Hello.</p>
<script src="guest.js"></script>
</body>
</html>
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var parentWindow = null;
window.onload = () => {
document.body.addEventListener('wheel', (e) => {
parentWindow.postMessage('Seen wheel event', '*');
});
};
window.addEventListener('message', (e) => {
parentWindow = e.source;
parentWindow.postMessage('WebViewTest.LAUNCHED', '*');
});
{
"name": "<webview> Touchpad pinch synthetic wheel event",
"version": "1",
"manifest_version": 2,
"permissions": [
"webview"
],
"app": {
"background": {
"scripts": ["test.js"]
}
}
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('embedder.html');
});
...@@ -683,7 +683,11 @@ bool GuestViewBase::ShouldFocusPageAfterCrash() { ...@@ -683,7 +683,11 @@ bool GuestViewBase::ShouldFocusPageAfterCrash() {
bool GuestViewBase::PreHandleGestureEvent(WebContents* source, bool GuestViewBase::PreHandleGestureEvent(WebContents* source,
const blink::WebGestureEvent& event) { const blink::WebGestureEvent& event) {
return blink::WebInputEvent::IsPinchGestureEventType(event.GetType()); // Pinch events which cause a scale change should not be routed to a guest.
// We still allow synthetic wheel events for touchpad pinch to go to the page.
DCHECK(!blink::WebInputEvent::IsPinchGestureEventType(event.GetType()) ||
event.NeedsWheelEvent());
return false;
} }
void GuestViewBase::UpdatePreferredSize(WebContents* target_web_contents, void GuestViewBase::UpdatePreferredSize(WebContents* target_web_contents,
......
...@@ -32,8 +32,18 @@ AppWebContentsHelper::AppWebContentsHelper( ...@@ -32,8 +32,18 @@ AppWebContentsHelper::AppWebContentsHelper(
// static // static
bool AppWebContentsHelper::ShouldSuppressGestureEvent( bool AppWebContentsHelper::ShouldSuppressGestureEvent(
const blink::WebGestureEvent& event) { const blink::WebGestureEvent& event) {
// Disable "smart zoom" (double-tap with two fingers on Mac trackpad).
if (event.GetType() == blink::WebInputEvent::kGestureDoubleTap)
return true;
// Disable pinch zooming in app windows. // Disable pinch zooming in app windows.
return blink::WebInputEvent::IsPinchGestureEventType(event.GetType()); if (blink::WebInputEvent::IsPinchGestureEventType(event.GetType())) {
// Only suppress pinch events that cause a scale change. We still
// allow synthetic wheel events for touchpad pinch to go to the page.
return !event.NeedsWheelEvent();
}
return false;
} }
content::WebContents* AppWebContentsHelper::OpenURLFromTab( content::WebContents* AppWebContentsHelper::OpenURLFromTab(
......
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