Commit bad70cb2 authored by Sadrul Habib Chowdhury's avatar Sadrul Habib Chowdhury Committed by Commit Bot

[synthesized scroll] Fix wheel-event precision on android.

Update API to set fractional wheel deltas on android, and remove the
code that explicitly used to remove precision.

BUG=1085890

Change-Id: Ifd18df07637b2fa28288de62bf538f65f7a4d0a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2213406
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771639}
parent 5096aba5
......@@ -38,8 +38,8 @@ SyntheticGestureTargetAndroid::SyntheticGestureTargetAndroid(
SyntheticGestureTargetAndroid::~SyntheticGestureTargetAndroid() = default;
void SyntheticGestureTargetAndroid::TouchSetPointer(int index,
int x,
int y,
float x,
float y,
int id) {
TRACE_EVENT0("input", "SyntheticGestureTargetAndroid::TouchSetPointer");
JNIEnv* env = base::android::AttachCurrentThread();
......@@ -48,10 +48,10 @@ void SyntheticGestureTargetAndroid::TouchSetPointer(int index,
env, java_ref_, index, x * scale_factor, y * scale_factor, id);
}
void SyntheticGestureTargetAndroid::TouchSetScrollDeltas(int x,
int y,
int dx,
int dy) {
void SyntheticGestureTargetAndroid::TouchSetScrollDeltas(float x,
float y,
float dx,
float dy) {
TRACE_EVENT0("input", "SyntheticGestureTargetAndroid::TouchSetScrollDeltas");
JNIEnv* env = base::android::AttachCurrentThread();
......
......@@ -47,8 +47,8 @@ class SyntheticGestureTargetAndroid : public SyntheticGestureTargetBase {
float GetMinScalingSpanInDips() const override;
private:
void TouchSetPointer(int index, int x, int y, int id);
void TouchSetScrollDeltas(int x, int y, int dx, int dy);
void TouchSetPointer(int index, float x, float y, int id);
void TouchSetScrollDeltas(float x, float y, float dx, float dy);
void TouchInject(MotionEventAction action,
int pointer_count,
base::TimeTicks time);
......
......@@ -157,15 +157,9 @@ IN_PROC_BROWSER_TEST_F(SyntheticInputTest, SmoothScrollWheel) {
"document.scrollingElement.scrollTop"));
}
// Wheel events lose precision on android (crbug.com/934649)
#if defined(OS_ANDROID)
#define MAYBE_SlowSmoothScrollWheel DISABLED_SlowSmoothScrollWheel
#else
#define MAYBE_SlowSmoothScrollWheel SlowSmoothScrollWheel
#endif
// This test ensures that slow synthetic wheel scrolling does not lose precision
// over time.
IN_PROC_BROWSER_TEST_F(SyntheticInputTest, MAYBE_SlowSmoothScrollWheel) {
IN_PROC_BROWSER_TEST_F(SyntheticInputTest, SlowSmoothScrollWheel) {
LoadURL(R"HTML(
data:text/html;charset=utf-8,
<!DOCTYPE html>
......@@ -199,14 +193,18 @@ IN_PROC_BROWSER_TEST_F(SyntheticInputTest, MAYBE_SlowSmoothScrollWheel) {
runner_ = std::make_unique<base::RunLoop>();
RenderFrameSubmissionObserver scroll_offset_wait(shell()->web_contents());
auto* web_contents = shell()->web_contents();
RenderFrameSubmissionObserver scroll_offset_wait(web_contents);
std::unique_ptr<SyntheticSmoothScrollGesture> gesture(
new SyntheticSmoothScrollGesture(params));
GetRenderWidgetHost()->QueueSyntheticGesture(
std::move(gesture),
base::BindOnce(&SyntheticInputTest::OnSyntheticGestureCompleted,
base::Unretained(this)));
scroll_offset_wait.WaitForScrollOffset(gfx::Vector2dF(0.f, 1024.f));
float device_scale_factor =
web_contents->GetRenderWidgetHostView()->GetDeviceScaleFactor();
scroll_offset_wait.WaitForScrollOffset(
gfx::Vector2dF(0.f, 1024.f * device_scale_factor));
EXPECT_EQ(1024, EvalJs(shell()->web_contents(),
"document.scrollingElement.scrollTop"));
......
......@@ -172,23 +172,6 @@ void SyntheticSmoothMoveGesture::ForwardMouseWheelInputEvents(
base::TimeTicks event_timestamp = ClampTimestamp(timestamp);
gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp) -
current_move_segment_total_delta_;
// Android MotionEvents that carry mouse wheel ticks and the tick
// granularity. Since it's not easy to change this granularity, it means
// we can only scroll in terms of number of these ticks. Note also: if
// the delta is smaller than one tick size we wont send an event or
// accumulate it in current_move_segment_total_delta_ so that we don't
// consider that delta applied. If we did, slow scrolls would be entirely
// lost since we'd send 0 ticks in each event but assume delta was
// applied.
int pixels_per_wheel_tick = target->GetMouseWheelMinimumGranularity();
if (pixels_per_wheel_tick) {
int wheel_ticks_x = static_cast<int>(delta.x() / pixels_per_wheel_tick);
int wheel_ticks_y = static_cast<int>(delta.y() / pixels_per_wheel_tick);
delta = gfx::Vector2dF(wheel_ticks_x * pixels_per_wheel_tick,
wheel_ticks_y * pixels_per_wheel_tick);
}
if (delta.x() || delta.y()) {
blink::WebMouseWheelEvent::Phase phase =
needs_scroll_begin_ ? blink::WebMouseWheelEvent::kPhaseBegan
......
......@@ -44,7 +44,7 @@ public class MotionEventSynthesizerImpl implements MotionEventSynthesizer {
* @param toolType ToolType property of the point.
*/
@Override
public void setPointer(int index, int x, int y, int id, int toolType) {
public void setPointer(int index, float x, float y, int id, int toolType) {
assert (0 <= index && index < MAX_NUM_POINTERS);
PointerCoords coords = new PointerCoords();
......@@ -67,7 +67,7 @@ public class MotionEventSynthesizerImpl implements MotionEventSynthesizer {
* @param x Y coordinate of the point.
* @param id Id property of the point.
*/
public void setPointer(int index, int x, int y, int id) {
public void setPointer(int index, float x, float y, int id) {
setPointer(index, x, y, id, MotionEvent.TOOL_TYPE_UNKNOWN);
}
......@@ -79,7 +79,7 @@ public class MotionEventSynthesizerImpl implements MotionEventSynthesizer {
* @param dx Delta along the X coordinate.
* @param dy Delta along the Y coordinate.
*/
public void setScrollDeltas(int x, int y, int dx, int dy) {
public void setScrollDeltas(float x, float y, float dx, float dy) {
setPointer(0, x, y, 0);
mPointerCoords[0].setAxisValue(MotionEvent.AXIS_HSCROLL, dx);
mPointerCoords[0].setAxisValue(MotionEvent.AXIS_VSCROLL, dy);
......
......@@ -31,12 +31,12 @@ public class SyntheticGestureTarget {
}
@CalledByNative
private void setPointer(int index, int x, int y, int id) {
private void setPointer(int index, float x, float y, int id) {
mMotionEventSynthesizer.setPointer(index, x, y, id);
}
@CalledByNative
private void setScrollDeltas(int x, int y, int dx, int dy) {
private void setScrollDeltas(float x, float y, float dx, float dy) {
mMotionEventSynthesizer.setScrollDeltas(x, y, dx, dy);
}
}
......@@ -25,7 +25,7 @@ public interface MotionEventSynthesizer {
* @param id Id property of the point.
* @param toolType ToolType property of the point.
*/
void setPointer(int index, int x, int y, int id, int toolType);
void setPointer(int index, float x, float y, int id, int toolType);
/**
* Injects a synthetic action with the preset points and delta.
......
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