Commit 86fdbaa9 authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

Take vertical and horizontal delta values in WheelTick function

After we merged the new GpuBenchmarking::SmoothScrollByXY, which has two
delta values, for vertical and horizontal scroll deltas, we should this
new function for all the scroll functions in resources/gesture-util.js.
So here we change wheelTick function to take deltaX and deltaY instead
of one delta and direction values, so now scroll deltaX and deltaY can
be different values.

Bug: 1047176
Change-Id: If692c7b807e9d2d5a00fefe09ce4b00a9be0c4f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2161651
Commit-Queue: Lan Wei <lanwei@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762084}
parent bb1779d6
...@@ -26,7 +26,7 @@ promise_test(async () => { ...@@ -26,7 +26,7 @@ promise_test(async () => {
shadowRoot.appendChild(shadowDiv); shadowRoot.appendChild(shadowDiv);
var center = elementCenter(shadowDiv); var center = elementCenter(shadowDiv);
await wheelTick(1, center, 'up'); await wheelTick(0, -1, center);
assert_true(receivedMouseWheel); assert_true(receivedMouseWheel);
}, "Verify a mousewheel event is fired when wheeling over shadow div element."); }, "Verify a mousewheel event is fired when wheeling over shadow div element.");
......
...@@ -26,7 +26,7 @@ promise_test(async () => { ...@@ -26,7 +26,7 @@ promise_test(async () => {
shadowRoot.appendChild(shadowDiv); shadowRoot.appendChild(shadowDiv);
var center = elementCenter(shadowDiv); var center = elementCenter(shadowDiv);
await wheelTick(1, center, 'up'); await wheelTick(0, -1, center);
assert_true(receivedMouseWheel); assert_true(receivedMouseWheel);
}, "Verify a mousewheel event is fired when wheeling over shadow div element."); }, "Verify a mousewheel event is fired when wheeling over shadow div element.");
......
...@@ -20,7 +20,7 @@ function iframeMouseWheel() ...@@ -20,7 +20,7 @@ function iframeMouseWheel()
promise_test(async () => { promise_test(async () => {
var frame = document.getElementById("frame"); var frame = document.getElementById("frame");
var center = elementCenter(frame); var center = elementCenter(frame);
await wheelTick(1, center, 'up', 4000); await wheelTick(0, -1, center, 4000);
assert_false(receivedMouseWheel, "Received wheel event in parent"); assert_false(receivedMouseWheel, "Received wheel event in parent");
assert_true(iframeReceivedMouseWheel, "Received wheel event in iframe"); assert_true(iframeReceivedMouseWheel, "Received wheel event in iframe");
}, "Mousewheel in iframe doesn't dispatch to parent."); }, "Mousewheel in iframe doesn't dispatch to parent.");
......
...@@ -32,7 +32,7 @@ promise_test(async () => { ...@@ -32,7 +32,7 @@ promise_test(async () => {
div.addEventListener('wheel', wheelHandler); div.addEventListener('wheel', wheelHandler);
div.addEventListener('mousewheel', mouseWheelHandler); div.addEventListener('mousewheel', mouseWheelHandler);
var center = elementCenter(div); var center = elementCenter(div);
await wheelTick(20, center, 'upleft', 4000); await wheelTick(-20, -20, center, 4000);
assert_equals(testEvent.__proto__, WheelEvent.prototype, "Standard wheel event was fired."); assert_equals(testEvent.__proto__, WheelEvent.prototype, "Standard wheel event was fired.");
assert_false(receivedMouseWheel, "mousewheel event should not have fired."); assert_false(receivedMouseWheel, "mousewheel event should not have fired.");
......
...@@ -15,7 +15,7 @@ input::-webkit-textfield-decoration-container { ...@@ -15,7 +15,7 @@ input::-webkit-textfield-decoration-container {
promise_test(async () => { promise_test(async () => {
var input = document.createElement('input'); var input = document.createElement('input');
var center = elementCenter(input); var center = elementCenter(input);
await wheelTick(10, center, 'up'); await wheelTick(0, -10, center);
}, "No crash when move the mouse over the input element and do a mouse wheel scroll."); }, "No crash when move the mouse over the input element and do a mouse wheel scroll.");
</script> </script>
...@@ -18,7 +18,7 @@ function reset() { ...@@ -18,7 +18,7 @@ function reset() {
var position = {x: 20, y: 20}; var position = {x: 20, y: 20};
promise_test(async () => { promise_test(async () => {
await wheelTick(1, position, 'down'); await wheelTick(0, 1, position);
await waitFor( () => { await waitFor( () => {
return document.scrollingElement.scrollTop == pixelsPerTick() && return document.scrollingElement.scrollTop == pixelsPerTick() &&
document.scrollingElement.scrollLeft == 0; document.scrollingElement.scrollLeft == 0;
...@@ -27,7 +27,7 @@ promise_test(async () => { ...@@ -27,7 +27,7 @@ promise_test(async () => {
promise_test(async () => { promise_test(async () => {
reset(); reset();
await wheelTick(1, position, 'right'); await wheelTick(1, 0, position);
await waitFor( () => { await waitFor( () => {
return document.scrollingElement.scrollTop == 0 && return document.scrollingElement.scrollTop == 0 &&
document.scrollingElement.scrollLeft == pixelsPerTick(); document.scrollingElement.scrollLeft == pixelsPerTick();
...@@ -36,7 +36,7 @@ promise_test(async () => { ...@@ -36,7 +36,7 @@ promise_test(async () => {
promise_test(async () => { promise_test(async () => {
reset(); reset();
await wheelTick(2, position, 'down'); await wheelTick(0, 2, position);
await waitFor( () => { await waitFor( () => {
return document.scrollingElement.scrollTop == 2 * pixelsPerTick() && return document.scrollingElement.scrollTop == 2 * pixelsPerTick() &&
document.scrollingElement.scrollLeft == 0; document.scrollingElement.scrollLeft == 0;
...@@ -45,7 +45,7 @@ promise_test(async () => { ...@@ -45,7 +45,7 @@ promise_test(async () => {
promise_test(async () => { promise_test(async () => {
reset(); reset();
await wheelTick(2, position, 'right'); await wheelTick(2, 0, position);
await waitFor( () => { await waitFor( () => {
return document.scrollingElement.scrollTop == 0 && return document.scrollingElement.scrollTop == 0 &&
document.scrollingElement.scrollLeft == 2 * pixelsPerTick(); document.scrollingElement.scrollLeft == 2 * pixelsPerTick();
......
...@@ -166,7 +166,9 @@ const GestureSourceType = (function() { ...@@ -166,7 +166,9 @@ const GestureSourceType = (function() {
// https://crbug.com/893608 // https://crbug.com/893608
const SPEED_INSTANT = 400000; const SPEED_INSTANT = 400000;
function smoothScroll(pixels_to_scroll, start_x, start_y, gesture_source_type, direction, speed_in_pixels_s, precise_scrolling_deltas, scroll_by_page, cursor_visible, scroll_by_percentage) { function smoothScroll(pixels_to_scroll, start_x, start_y, gesture_source_type,
direction, speed_in_pixels_s, precise_scrolling_deltas,
scroll_by_page, cursor_visible, scroll_by_percentage) {
let pixels_to_scroll_x = 0; let pixels_to_scroll_x = 0;
let pixels_to_scroll_y = 0; let pixels_to_scroll_y = 0;
if (direction == "down") { if (direction == "down") {
...@@ -190,10 +192,16 @@ function smoothScroll(pixels_to_scroll, start_x, start_y, gesture_source_type, d ...@@ -190,10 +192,16 @@ function smoothScroll(pixels_to_scroll, start_x, start_y, gesture_source_type, d
pixels_to_scroll_x = pixels_to_scroll; pixels_to_scroll_x = pixels_to_scroll;
pixels_to_scroll_y = pixels_to_scroll; pixels_to_scroll_y = pixels_to_scroll;
} }
return smoothScrollWithXY(pixels_to_scroll_x, pixels_to_scroll_y, start_x, start_y, gesture_source_type, speed_in_pixels_s, precise_scrolling_deltas, scroll_by_page, cursor_visible, scroll_by_percentage); return smoothScrollWithXY(pixels_to_scroll_x, pixels_to_scroll_y, start_x,
start_y, gesture_source_type, speed_in_pixels_s,
precise_scrolling_deltas, scroll_by_page,
cursor_visible, scroll_by_percentage);
} }
function smoothScrollWithXY(pixels_to_scroll_x, pixels_to_scroll_y, start_x, start_y, gesture_source_type, speed_in_pixels_s, precise_scrolling_deltas, scroll_by_page, cursor_visible, scroll_by_percentage) { function smoothScrollWithXY(pixels_to_scroll_x, pixels_to_scroll_y, start_x,
start_y, gesture_source_type, speed_in_pixels_s,
precise_scrolling_deltas, scroll_by_page,
cursor_visible, scroll_by_percentage) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (window.chrome && chrome.gpuBenchmarking) { if (window.chrome && chrome.gpuBenchmarking) {
chrome.gpuBenchmarking.smoothScrollByXY(pixels_to_scroll_x, chrome.gpuBenchmarking.smoothScrollByXY(pixels_to_scroll_x,
...@@ -213,12 +221,14 @@ function smoothScrollWithXY(pixels_to_scroll_x, pixels_to_scroll_y, start_x, sta ...@@ -213,12 +221,14 @@ function smoothScrollWithXY(pixels_to_scroll_x, pixels_to_scroll_y, start_x, sta
}); });
} }
function wheelTick(scroll_tick, center, direction, speed_in_pixels_s) { function wheelTick(scroll_tick_x, scroll_tick_y, center, speed_in_pixels_s) {
if (typeof(speed_in_pixels_s) == "undefined") if (typeof(speed_in_pixels_s) == "undefined")
speed_in_pixels_s = SPEED_INSTANT; speed_in_pixels_s = SPEED_INSTANT;
// Do not allow precise scrolling deltas for tick wheel scroll. // Do not allow precise scrolling deltas for tick wheel scroll.
return smoothScroll(scroll_tick * pixelsPerTick(), center.x, center.y, GestureSourceType.MOUSE_INPUT, return smoothScrollWithXY(scroll_tick_x * pixelsPerTick(),
direction, speed_in_pixels_s, false /* precise_scrolling_deltas */); scroll_tick_y * pixelsPerTick(),
center.x, center.y, GestureSourceType.MOUSE_INPUT,
speed_in_pixels_s, false /* precise_scrolling_deltas */);
} }
const LEGACY_MOUSE_WHEEL_TICK_MULTIPLIER = 120; const LEGACY_MOUSE_WHEEL_TICK_MULTIPLIER = 120;
......
...@@ -15,7 +15,7 @@ async function runTest() { ...@@ -15,7 +15,7 @@ async function runTest() {
var doc = window.frames[0].document; var doc = window.frames[0].document;
var fillDiv = doc.getElementById("fillDIV"); var fillDiv = doc.getElementById("fillDIV");
var center = elementCenter(fillDiv); var center = elementCenter(fillDiv);
await wheelTick(1, center, 'down'); await wheelTick(0, 1, center);
await conditionHolds( () => { await conditionHolds( () => {
return window.frames[0].scrollY == 0; return window.frames[0].scrollY == 0;
}); });
......
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