Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Unified Diff: ui/android/java/src/org/chromium/ui/input/JoystickScrollProvider.java

Issue 2770613002: Forward GenericMotionEvent to EventForwarder (Closed)
Patch Set: fix tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/android/java/src/org/chromium/ui/input/JoystickScrollProvider.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/JoystickScrollProvider.java b/ui/android/java/src/org/chromium/ui/input/JoystickScrollProvider.java
similarity index 78%
rename from content/public/android/java/src/org/chromium/content/browser/input/JoystickScrollProvider.java
rename to ui/android/java/src/org/chromium/ui/input/JoystickScrollProvider.java
index 8c57b5f8f8531fb34f99ba8a4890ca492b78903d..8f8fbc2288a4501fa4d63566fb22e16b2bdd2307 100644
--- a/content/public/android/java/src/org/chromium/content/browser/input/JoystickScrollProvider.java
+++ b/ui/android/java/src/org/chromium/ui/input/JoystickScrollProvider.java
@@ -1,8 +1,8 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-package org.chromium.content.browser.input;
+package org.chromium.ui.input;
import android.content.Context;
import android.util.TypedValue;
@@ -12,9 +12,6 @@ import android.view.View;
import android.view.animation.AnimationUtils;
import org.chromium.base.Log;
-import org.chromium.base.annotations.CalledByNative;
-import org.chromium.base.annotations.JNINamespace;
-import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.display.DisplayAndroid;
import org.chromium.ui.display.DisplayAndroid.DisplayAndroidObserver;
@@ -22,7 +19,6 @@ import org.chromium.ui.display.DisplayAndroid.DisplayAndroidObserver;
/**
* This class implements auto scrolling and panning for gamepad left joystick motion event.
*/
-@JNINamespace("content")
public class JoystickScrollProvider {
private static final String TAG = "JoystickScroll";
@@ -43,11 +39,26 @@ public class JoystickScrollProvider {
}
}
- private WindowAndroid mWindowAndroid;
- private View mContainerView;
- private long mNativeJoystickScrollProvider;
- private JoystickScrollDisplayObserver mDisplayObserver;
+ /**
+ * Actual joystick event should be translated to other input event since Blink does not
+ * support it. This interface is used to provide the way to emulate it.
+ */
+ public interface ScrollEmulator {
+ /**
+ * Called when a scroll event got issued.
+ * @param timeMillis current animation time.
+ * @param dx amount of scroll along x axis.
+ * @param dy amount of scroll along y axis.
+ */
+ void scroll(long timeMillis, float dx, float dy);
+ }
+
+ private final View mContainerView;
+ // Interface used to send an event to Blink to emulate joystick scroll.
+ private final ScrollEmulator mScrollEmulator;
+ private final JoystickScrollDisplayObserver mDisplayObserver;
+ private WindowAndroid mWindowAndroid;
private float mScrollVelocityX;
private float mScrollVelocityY;
private float mScrollFactor;
@@ -63,20 +74,14 @@ public class JoystickScrollProvider {
* Constructs a new JoystickScrollProvider.
*/
public JoystickScrollProvider(
- WebContents webContents, View containerView, WindowAndroid windowAndroid) {
- mNativeJoystickScrollProvider = nativeInit(webContents);
+ View containerView, WindowAndroid windowAndroid, ScrollEmulator scrollEmulator) {
mContainerView = containerView;
mWindowAndroid = windowAndroid;
+ mScrollEmulator = scrollEmulator;
mEnabled = true;
mDisplayObserver = new JoystickScrollDisplayObserver();
}
- @CalledByNative
- private void onNativeObjectDestroyed(long nativePointer) {
- assert nativePointer == mNativeJoystickScrollProvider;
- mNativeJoystickScrollProvider = 0;
- }
-
/**
* This function enables or disables scrolling through joystick.
* @param enabled Decides whether joystick scrolling should be
@@ -118,12 +123,14 @@ public class JoystickScrollProvider {
Context context = mWindowAndroid == null ? null : mWindowAndroid.getContext().get();
TypedValue outValue = new TypedValue();
- if (context != null && context.getTheme().resolveAttribute(
- android.R.attr.listPreferredItemHeight, outValue, true)) {
+ if (context != null
+ && context.getTheme().resolveAttribute(
+ android.R.attr.listPreferredItemHeight, outValue, true)) {
mScrollFactor = outValue.getDimension(context.getResources().getDisplayMetrics());
} else {
if (context != null) {
- Log.d(TAG, "Theme attribute listPreferredItemHeight not defined"
+ Log.d(TAG,
+ "Theme attribute listPreferredItemHeight not defined"
+ " switching to fallback scroll factor");
}
mScrollFactor = SCROLL_FACTOR_FALLBACK * mDipScale;
@@ -134,6 +141,7 @@ public class JoystickScrollProvider {
* This function processes motion event and computes new
* scroll offest in pixels which is propertional to left joystick
* axes movement.
+ *
* It also starts runnable to scroll content view core equal to
* scroll offset pixels.
*
@@ -143,8 +151,9 @@ public class JoystickScrollProvider {
public boolean onMotion(MotionEvent event) {
if (!mEnabled) return false;
if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0) return false;
- Log.d(TAG, "Joystick left stick axis: " + event.getAxisValue(MotionEvent.AXIS_X) + ","
- + event.getAxisValue(MotionEvent.AXIS_Y));
+ Log.d(TAG,
+ "Joystick left stick axis: " + event.getAxisValue(MotionEvent.AXIS_X) + ","
+ + event.getAxisValue(MotionEvent.AXIS_Y));
assert mScrollFactor != 0;
@@ -181,10 +190,7 @@ public class JoystickScrollProvider {
final float dx = (mScrollVelocityX * dt / 1000.f);
final float dy = (mScrollVelocityY * dt / 1000.f);
- if (mNativeJoystickScrollProvider != 0) {
- nativeScrollBy(
- mNativeJoystickScrollProvider, timeMillis, dx / mDipScale, dy / mDipScale);
- }
+ if (mScrollEmulator != null) mScrollEmulator.scroll(timeMillis, dx, dy);
mLastAnimateTimeMillis = timeMillis;
mContainerView.postOnAnimation(mScrollRunnable);
@@ -197,7 +203,7 @@ public class JoystickScrollProvider {
/**
* Removes noise from joystick motion events.
*/
- private float getFilteredAxisValue(MotionEvent event, int axis) {
+ private static float getFilteredAxisValue(MotionEvent event, int axis) {
float axisValWithNoise = event.getAxisValue(axis);
if (axisValWithNoise > JOYSTICK_SCROLL_DEADZONE
|| axisValWithNoise < -JOYSTICK_SCROLL_DEADZONE) {
@@ -205,8 +211,4 @@ public class JoystickScrollProvider {
}
return 0f;
}
-
- private native long nativeInit(WebContents webContents);
- private native void nativeScrollBy(
- long nativeJoystickScrollProvider, long timeMs, float dxDip, float dyDip);
}

Powered by Google App Engine
This is Rietveld 408576698