Define JoystickHandler for Android
JoystickHandler in content/ is WebContentsUserData-backed
class that handles generic motion events by converting them
to fling event. This sets ContentViewCore free from having to
manage joystick-related states and keep several view event flows
together inside.
Fling events that joystick input is converted to are now
routed to EventForwarder and going down ViewAndroid tree.
Updated the flow to handle more gesture events relevant to
fling scroll.
Bug: 811168
Change-Id: I6904e92e708fdea33dba8fc0df2ace48134331fa
Reviewed-on: https://chromium-review.googlesource.com/915747
Commit-Queue: Jinsuk Kim <[email protected]>
Reviewed-by: Timothy Dresser <[email protected]>
Reviewed-by: Dave Tapuska <[email protected]>
Reviewed-by: Tommy Nyquist <[email protected]>
Reviewed-by: Bo <[email protected]>
Cr-Commit-Position: refs/heads/master@{#538650}
diff --git a/ui/android/event_forwarder.cc b/ui/android/event_forwarder.cc
index dd63f7b..7be0652c 100644
--- a/ui/android/event_forwarder.cc
+++ b/ui/android/event_forwarder.cc
@@ -12,6 +12,7 @@
#include "ui/base/ui_base_switches_util.h"
#include "ui/events/android/drag_event_android.h"
#include "ui/events/android/gesture_event_android.h"
+#include "ui/events/android/gesture_event_type.h"
#include "ui/events/android/motion_event_android.h"
#include "ui/events/base_event_utils.h"
@@ -175,16 +176,42 @@
const JavaParamRef<jobject>& jobj,
jint type,
jlong time_ms,
- jfloat delta) {
+ jfloat scale) {
float dip_scale = view_->GetDipScale();
auto size = view_->GetSize();
float x = size.width() / 2;
float y = size.height() / 2;
gfx::PointF root_location =
ScalePoint(view_->GetLocationOnScreen(x, y), 1.f / dip_scale);
- return view_->OnGestureEvent(
- GestureEventAndroid(type, gfx::PointF(x / dip_scale, y / dip_scale),
- root_location, time_ms, delta));
+ return view_->OnGestureEvent(GestureEventAndroid(
+ type, gfx::PointF(x / dip_scale, y / dip_scale), root_location, time_ms,
+ scale, 0, 0, 0, 0, false, false));
+}
+
+void EventForwarder::OnStartFling(JNIEnv* env,
+ const JavaParamRef<jobject>& jobj,
+ jlong time_ms,
+ jfloat velocity_x,
+ jfloat velocity_y,
+ jboolean synthetic_scroll) {
+ OnCancelFling(env, jobj, time_ms);
+ if (velocity_x == 0 && velocity_y == 0)
+ return;
+ // Use velocity as delta in scroll event.
+ view_->OnGestureEvent(GestureEventAndroid(
+ GESTURE_EVENT_TYPE_SCROLL_START, gfx::PointF(), gfx::PointF(), time_ms, 0,
+ velocity_x, velocity_y, 0, 0, true, synthetic_scroll));
+ view_->OnGestureEvent(GestureEventAndroid(
+ GESTURE_EVENT_TYPE_FLING_START, gfx::PointF(), gfx::PointF(), time_ms, 0,
+ 0, 0, velocity_x, velocity_y, true, synthetic_scroll));
+}
+
+void EventForwarder::OnCancelFling(JNIEnv* env,
+ const JavaParamRef<jobject>& jobj,
+ jlong time_ms) {
+ view_->OnGestureEvent(
+ GestureEventAndroid(GESTURE_EVENT_TYPE_FLING_CANCEL, gfx::PointF(),
+ gfx::PointF(), time_ms, 0, 0, 0, 0, 0, false, false));
}
} // namespace ui