Skip to content

Commit

Permalink
Use wheelTick in forms/resources/common-wheel-event.js
Browse files Browse the repository at this point in the history
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.

Bug: 1047176
Change-Id: I7416727dfcfbe2d88a283907ee132c838952747e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2171955
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: David Bokan <bokan@chromium.org>
Commit-Queue: Lan Wei <lanwei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782599}
  • Loading branch information
LanWei22 authored and Commit Bot committed Jun 25, 2020
1 parent 37bccc2 commit 5cd3140
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 54 deletions.
Expand Up @@ -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);
Expand Down
Expand Up @@ -141,7 +141,18 @@ + (id)eventWithMagnification:(float)magnification
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
Expand Down Expand Up @@ -182,4 +193,13 @@ + (id)eventWithMagnification:(float)magnification
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
4 changes: 4 additions & 0 deletions content/browser/renderer_host/render_widget_host_view_mac.h
Expand Up @@ -469,6 +469,10 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
// |cocoa_view_|.
void SetParentAccessibilityElement(id parent_accessibility_element);

RenderWidgetHostViewMac* PopupChildHostView() {
return popup_child_host_view_;
}

MouseWheelPhaseHandler* GetMouseWheelPhaseHandler() override;

protected:
Expand Down
Expand Up @@ -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"
Expand Down
Expand Up @@ -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>
@@ -1,12 +1,14 @@
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);
}

var input;
function testWheelEvent(parameters)
async function testWheelEvent(parameters)
{
var inputType = parameters['inputType'];
var initialValue = parameters['initialValue'];
Expand All @@ -20,37 +22,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);
Expand Down
Expand Up @@ -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>
Expand Down Expand Up @@ -129,15 +130,15 @@
waitUntilClosing(test2AfterClosing);
}

function scrollUp() {
async function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, 100);
await dispatchWheelEvent(suggestionList, 0, -100);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest);
}

function scrollDown() {
async function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, -100);
await dispatchWheelEvent(suggestionList, 0, 100);
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}

Expand Down
Expand Up @@ -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>
Expand Down Expand Up @@ -82,15 +83,15 @@
waitUntilClosing(test2AfterClosing);
}

function scrollUp() {
async function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, 100);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest)
await dispatchWheelEvent(suggestionList, 0, -100);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest);
}

function scrollDown() {
async function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, -100);
await dispatchWheelEvent(suggestionList, 0, 100);
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}

Expand Down
Expand Up @@ -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>
Expand Down Expand Up @@ -109,15 +110,15 @@
waitUntilClosing(test2AfterClosing);
}

function scrollUp() {
async function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, 100);
await dispatchWheelEvent(suggestionList, 0, -100);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest)
}

function scrollDown() {
async function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, -100);
await dispatchWheelEvent(suggestionList, 0, 100);
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}

Expand Down
Expand Up @@ -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.
Expand Down
Expand Up @@ -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>
Expand Down Expand Up @@ -47,9 +48,6 @@
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');
Expand Down Expand Up @@ -85,15 +83,15 @@
waitUntilClosing(test2AfterClosing);
}

function scrollUp() {
async function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, 100);
await dispatchWheelEvent(suggestionList, 0, -100);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest)
}

function scrollDown() {
async function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, -100);
await dispatchWheelEvent(suggestionList, 0, 100);
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}

Expand Down
@@ -1,4 +1,3 @@
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.
Expand Down
Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -128,15 +129,15 @@
waitUntilClosing(test2AfterClosing);
}

function scrollUp() {
async function scrollUp() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, 100);
await dispatchWheelEvent(suggestionList, 0, -100);
shouldBecomeEqual('scrollTopBeforeWheelEvent > suggestionList.scrollTop', 'true', finishTest)
}

function scrollDown() {
async function scrollDown() {
scrollTopBeforeWheelEvent = suggestionList.scrollTop;
dispatchWheelEvent(suggestionList, 0, -100);
await dispatchWheelEvent(suggestionList, 0, 100);
shouldBecomeEqual('scrollTopBeforeWheelEvent < suggestionList.scrollTop', 'true', scrollUp);
}

Expand Down
Expand Up @@ -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>
Expand All @@ -13,16 +14,16 @@
<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.
Expand Down

0 comments on commit 5cd3140

Please sign in to comment.