Commit 89c9ea26 authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

Reland "Use wheelTick in forms/resources/common-wheel-event.js"

After we finish the scroll unification, the scrolls happens mainly on
the compositor thread, and the scroll code in the main thread will be
removed. eventSender sends the scroll events to main thread, so it
would not work after the scroll unification. This CL we should replace
eventSender.mouseScrollBy with wheelTick which uses
gpuBenchmarking.smoothScrollByXY in
forms/resources/common-wheel-event.js.

TBR=ellyjones@chromium.org,avi@chromium.org,sky@chromium.org,bokan@chromium.org,lanwei@chromium.org

Bug: 1047176
Change-Id: Ib45dce450fe395d53a443612033305bccef6b19d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2268227Reviewed-by: default avatarLan Wei <lanwei@chromium.org>
Commit-Queue: Lan Wei <lanwei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#783007}
parent 608bb8f3
......@@ -42,6 +42,8 @@ class SyntheticGestureTargetMac : public SyntheticGestureTargetBase {
private:
RenderWidgetHostViewMac* GetView() const;
bool PointIsWithinContents(RenderWidgetHostView* view,
const gfx::PointF& point);
RenderWidgetHostViewCocoa* cocoa_view_;
DISALLOW_COPY_AND_ASSIGN(SyntheticGestureTargetMac);
......
......@@ -141,7 +141,18 @@ void SyntheticGestureTargetMac::DispatchWebMouseWheelEventToPlatform(
web_wheel.delta_x / ui::kScrollbarPixelsPerCocoaTick;
wheel_event.wheel_ticks_y =
web_wheel.delta_y / ui::kScrollbarPixelsPerCocoaTick;
GetView()->RouteOrProcessWheelEvent(wheel_event);
// Manually route the WebMouseWheelEvent to any open popup window if the
// mouse is currently over the pop window, because window-level event routing
// on Mac happens at the OS API level which we cannot easily inject the
// events into.
if (GetView()->PopupChildHostView() &&
PointIsWithinContents(GetView()->PopupChildHostView(),
web_wheel.PositionInWidget())) {
GetView()->PopupChildHostView()->RouteOrProcessWheelEvent(wheel_event);
} else {
GetView()->RouteOrProcessWheelEvent(wheel_event);
}
if (web_wheel.phase == blink::WebMouseWheelEvent::kPhaseEnded) {
// Send the pending wheel end event immediately. Otherwise, the
// MouseWheelPhaseHandler will defer the end event in case of momentum
......@@ -182,4 +193,13 @@ RenderWidgetHostViewMac* SyntheticGestureTargetMac::GetView() const {
return view;
}
bool SyntheticGestureTargetMac::PointIsWithinContents(
RenderWidgetHostView* view,
const gfx::PointF& point) {
gfx::Rect bounds = view->GetViewBounds();
gfx::Rect bounds_in_window =
bounds - bounds.OffsetFromOrigin(); // Translate the bounds to (0,0).
return bounds_in_window.Contains(point.x(), point.y());
}
} // namespace content
......@@ -473,6 +473,10 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
// |cocoa_view_|.
void SetParentAccessibilityElement(id parent_accessibility_element);
RenderWidgetHostViewMac* PopupChildHostView() {
return popup_child_host_view_;
}
MouseWheelPhaseHandler* GetMouseWheelPhaseHandler() override;
protected:
......
......@@ -4,11 +4,11 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
Initial value is 0. We'll wheel up by 1:
PASS input.value is "1"
Wheel up by 100:
Wheel up by 3:
PASS input.value is "2"
Wheel down by 1:
PASS input.value is "1"
Wheel down by 256:
Wheel down by 3:
PASS input.value is "0"
Disabled input element:
PASS input.value is "0"
......
......@@ -2,15 +2,21 @@
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../../../resources/gesture-util.js"></script>
<script src="../resources/common-wheel-event.js"></script>
</head>
<body>
<body onload="runTest();">
<script>
testWheelEvent({
'inputType' : 'number',
'initialValue' : '0',
'stepUpValue1' : '1',
'stepUpValue2' : '2' });
async function runTest() {
await testWheelEvent({
'inputType' : 'number',
'initialValue' : '0',
'stepUpValue1' : '1',
'stepUpValue2' : '2' });
finishJSTest();
}
</script>
</body>
</html>
function dispatchWheelEvent(element, deltaX, deltaY)
jsTestIsAsync = true;
// Positive deltaX or deltaY means scroll right or down.
async function dispatchWheelEvent(element, deltaX, deltaY)
{
var rect = element.getClientRects()[0]
eventSender.mouseMoveTo(rect.left, rect.top);
eventSender.mouseScrollBy(deltaX, deltaY);
element_center = elementCenter(element);
await wheelTick(deltaX, deltaY, element_center);
await waitForCompositorCommit();
}
var input;
function testWheelEvent(parameters)
async function testWheelEvent(parameters)
{
var inputType = parameters['inputType'];
var initialValue = parameters['initialValue'];
......@@ -20,37 +23,40 @@ function testWheelEvent(parameters)
input.focus();
debug('Initial value is ' + initialValue + '. We\'ll wheel up by 1:');
dispatchWheelEvent(input, 0, 1);
await dispatchWheelEvent(input, 0, -1);
shouldBeEqualToString('input.value', stepUpValue1);
debug('Wheel up by 100:');
dispatchWheelEvent(input, 0, 100);
// We change the selected value in ScrollBegin and the three wheel ticks
// are treated as a single stream with one ScrollBegin, so we increase or
// decrease by one value even though there is more than one wheel tick.
debug('Wheel up by 3:');
await dispatchWheelEvent(input, 0, -3);
shouldBeEqualToString('input.value', stepUpValue2);
debug('Wheel down by 1:');
dispatchWheelEvent(input, 0, -1);
await dispatchWheelEvent(input, 0, 1);
shouldBeEqualToString('input.value', stepUpValue1);
debug('Wheel down by 256:');
dispatchWheelEvent(input, 0, -256);
debug('Wheel down by 3:');
await dispatchWheelEvent(input, 0, 3);
shouldBeEqualToString('input.value', initialValue);
debug('Disabled input element:');
input.disabled = true;
dispatchWheelEvent(input, 0, 1);
await dispatchWheelEvent(input, 0, -1);
shouldBeEqualToString('input.value', initialValue);
input.removeAttribute('disabled');
debug('Read-only input element:');
input.readOnly = true;
dispatchWheelEvent(input, 0, 1);
await dispatchWheelEvent(input, 0, -1);
shouldBeEqualToString('input.value', initialValue);
input.readOnly = false;
debug('No focus:');
document.getElementById('another').focus();
dispatchWheelEvent(input, 0, 1);
await dispatchWheelEvent(input, 0, -1);
shouldBeEqualToString('input.value', initialValue);
parent.parentNode.removeChild(parent);
......
......@@ -2,6 +2,7 @@
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../../../resources/gesture-util.js"></script>
<script src="../../forms/resources/common.js"></script>
<script src="../../forms/resources/common-wheel-event.js"></script>
<script src="../../forms/resources/picker-common.js"></script>
......@@ -129,15 +130,15 @@ function test2() {
waitUntilClosing(test2AfterClosing);
}
function scrollUp() {
async function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, 100);
await dispatchWheelEvent(suggestionList, 0, -3);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest);
}
function scrollDown() {
async function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, -100);
await dispatchWheelEvent(suggestionList, 0, 3);
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}
......
......@@ -2,6 +2,7 @@
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../../../resources/gesture-util.js"></script>
<script src="../../forms/resources/common.js"></script>
<script src="../../forms/resources/common-wheel-event.js"></script>
<script src="../../forms/resources/picker-common.js"></script>
......@@ -82,15 +83,15 @@ function test2() {
waitUntilClosing(test2AfterClosing);
}
function scrollUp() {
async function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, 100);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest)
await dispatchWheelEvent(suggestionList, 0, -3);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest);
}
function scrollDown() {
async function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, -100);
await dispatchWheelEvent(suggestionList, 0, 3);
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}
......
......@@ -2,6 +2,7 @@
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../../../resources/gesture-util.js"></script>
<script src="../../forms/resources/common.js"></script>
<script src="../../forms/resources/common-wheel-event.js"></script>
<script src="../../forms/resources/picker-common.js"></script>
......@@ -109,15 +110,15 @@ function test2() {
waitUntilClosing(test2AfterClosing);
}
function scrollUp() {
async function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, 100);
await dispatchWheelEvent(suggestionList, 0, -3);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest)
}
function scrollDown() {
async function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, -100);
await dispatchWheelEvent(suggestionList, 0, 3);
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}
......
......@@ -2,8 +2,6 @@ Check that page popup doesn't exist at first.
PASS $("mock-page-popup") is null
Check that page popup exists.
PASS popupWindow.pagePopupController.toString() is "[object PagePopupController]"
Check that page popup exists.
PASS popupWindow.pagePopupController.toString() is "[object PagePopupController]"
Check that hovering over an entry highlights it.
PASS highlightedEntry() is "01:02"
Check that moving the mouse outside the popup de-highlights entries.
......
......@@ -2,6 +2,7 @@
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../../../resources/gesture-util.js"></script>
<script src="../../forms/resources/common.js"></script>
<script src="../../forms/resources/common-wheel-event.js"></script>
<script src="../../forms/resources/picker-common.js"></script>
......@@ -47,9 +48,6 @@ function test1() {
debug('Check that page popup exists.');
shouldBeEqualToString('popupWindow.pagePopupController.toString()', '[object PagePopupController]');
debug('Check that page popup exists.');
shouldBeEqualToString('popupWindow.pagePopupController.toString()', '[object PagePopupController]');
debug('Check that hovering over an entry highlights it.');
hoverOverElement(popupWindow.document.querySelector(".suggestion-list-entry:nth-child(2)"));
shouldBeEqualToString('highlightedEntry()', '01:02');
......@@ -85,15 +83,15 @@ function test2() {
waitUntilClosing(test2AfterClosing);
}
function scrollUp() {
async function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, 100);
await dispatchWheelEvent(suggestionList, 0, -3);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest)
}
function scrollDown() {
async function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, -100);
await dispatchWheelEvent(suggestionList, 0, 3);
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}
......
CONSOLE WARNING: line 13: The specified value "2012-12-24" does not conform to the required format. The format is "yyyy-Www" where yyyy is year in four or more digits, and ww is 01-53.
Check that page popup doesn't exist at first.
PASS $("mock-page-popup") is null
Check that page popup exists.
......
......@@ -2,6 +2,7 @@
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../../../resources/gesture-util.js"></script>
<script src="../../forms/resources/common.js"></script>
<script src="../../forms/resources/common-wheel-event.js"></script>
<script src="../../forms/resources/picker-common.js"></script>
......@@ -10,7 +11,7 @@
<body style="background-color: #bbbbbb;">
<p id="description"></p>
<div id="console"></div>
<input type=week id=week value="2012-12-24" list=suggestions>
<input type=week id=week value="2012-W52" list=suggestions>
<datalist id=suggestions>
<option label="This Week">2012-W01</option>
<option>2012-W02</option>
......@@ -128,15 +129,15 @@ function test2() {
waitUntilClosing(test2AfterClosing);
}
function scrollUp() {
async function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, 100);
await dispatchWheelEvent(suggestionList, 0, -3);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest)
}
function scrollDown() {
async function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, -100);
await dispatchWheelEvent(suggestionList, 0, 3);
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}
......
......@@ -3,6 +3,7 @@
if (window.internals)
internals.settings.setLangAttributeAwareFormControlUIEnabled(true);
</script>
<script src="../../../resources/gesture-util.js"></script>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../../fast/forms/resources/common.js"></script>
......@@ -13,16 +14,16 @@ if (window.internals)
<script>
let t = async_test('Test scrolling in time picker.');
function test1() {
async function test1() {
let hourColumn = popupWindow.global.picker.timeColumns.firstChild;
const scrollHourTopBeforeWheelEvent = hourColumn.scrollTop;
// scroll up by 2 ticks ~ 2 cells
dispatchWheelEvent(hourColumn, 0, 2);
await dispatchWheelEvent(hourColumn, 0, -2);
let minuteColumn = hourColumn.nextSibling;
const scrollMinuteTopBeforeWheelEvent = minuteColumn.scrollTop;
// scroll up by 3 ticks ~ 3 cells
dispatchWheelEvent(minuteColumn, 0, 3);
await dispatchWheelEvent(minuteColumn, 0, -3);
t.step_timeout(function() {
// verify that both columns have been scrolled up.
......
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