Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.ui.base; | 5 package org.chromium.ui.base; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.os.Build; | 8 import android.os.Build; |
| 9 import android.view.MotionEvent; | 9 import android.view.MotionEvent; |
| 10 import android.view.View; | |
| 10 | 11 |
| 11 import org.chromium.base.TraceEvent; | 12 import org.chromium.base.TraceEvent; |
| 12 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; |
| 13 import org.chromium.base.annotations.JNINamespace; | 14 import org.chromium.base.annotations.JNINamespace; |
| 15 import org.chromium.ui.input.JoystickScrollProvider; | |
| 14 | 16 |
| 15 /** | 17 /** |
| 16 * Class used to forward view, input events down to native. | 18 * Class used to forward view, input events down to native. |
| 17 */ | 19 */ |
| 18 @JNINamespace("ui") | 20 @JNINamespace("ui") |
| 19 public class EventForwarder { | 21 public class EventForwarder { |
| 20 private long mNativeEventForwarder; | 22 private long mNativeEventForwarder; |
| 21 | 23 |
| 22 // Offsets for the events that passes through. | 24 // Offsets for the events that passes through. |
| 23 private float mCurrentTouchOffsetX; | 25 private float mCurrentTouchOffsetX; |
| 24 private float mCurrentTouchOffsetY; | 26 private float mCurrentTouchOffsetY; |
| 25 | 27 |
| 28 // Provides smooth gamepad joystick-driven scrolling. | |
| 29 private JoystickScrollProvider mJoystickScrollProvider; | |
| 30 | |
| 26 @CalledByNative | 31 @CalledByNative |
| 27 private static EventForwarder create(long nativeEventForwarder) { | 32 private static EventForwarder create(long nativeEventForwarder) { |
| 28 return new EventForwarder(nativeEventForwarder); | 33 return new EventForwarder(nativeEventForwarder); |
| 29 } | 34 } |
| 30 | 35 |
| 31 private EventForwarder(long nativeEventForwarder) { | 36 private EventForwarder(long nativeEventForwarder) { |
| 32 mNativeEventForwarder = nativeEventForwarder; | 37 mNativeEventForwarder = nativeEventForwarder; |
| 33 } | 38 } |
| 34 | 39 |
| 35 @CalledByNative | 40 @CalledByNative |
| 36 private void destroy() { | 41 private void destroy() { |
| 37 mNativeEventForwarder = 0; | 42 mNativeEventForwarder = 0; |
| 43 mJoystickScrollProvider = null; | |
| 38 } | 44 } |
| 39 | 45 |
| 40 /** | 46 /** |
| 41 * @see View#onTouchEvent(MotionEvent) | 47 * @see View#onTouchEvent(MotionEvent) |
| 42 */ | 48 */ |
| 43 public boolean onTouchEvent(MotionEvent event) { | 49 public boolean onTouchEvent(MotionEvent event) { |
| 44 // TODO(mustaq): Should we include MotionEvent.TOOL_TYPE_STYLUS here? | 50 // TODO(mustaq): Should we include MotionEvent.TOOL_TYPE_STYLUS here? |
| 45 // crbug.com/592082 | 51 // crbug.com/592082 |
| 46 if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) { | 52 if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) { |
| 47 // Mouse button info is incomplete on L and below | 53 // Mouse button info is incomplete on L and below |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 | 180 |
| 175 @TargetApi(Build.VERSION_CODES.M) | 181 @TargetApi(Build.VERSION_CODES.M) |
| 176 public void sendMouseEvent(long timeMs, int action, float x, float y, int po interId, | 182 public void sendMouseEvent(long timeMs, int action, float x, float y, int po interId, |
| 177 float pressure, float orientation, float tilt, int actionButton, int buttonState, | 183 float pressure, float orientation, float tilt, int actionButton, int buttonState, |
| 178 int metaState, int toolType) { | 184 int metaState, int toolType) { |
| 179 assert mNativeEventForwarder != 0; | 185 assert mNativeEventForwarder != 0; |
| 180 nativeOnMouseEvent(mNativeEventForwarder, timeMs, action, x, y, pointerI d, pressure, | 186 nativeOnMouseEvent(mNativeEventForwarder, timeMs, action, x, y, pointerI d, pressure, |
| 181 orientation, tilt, actionButton, buttonState, metaState, toolTyp e); | 187 orientation, tilt, actionButton, buttonState, metaState, toolTyp e); |
| 182 } | 188 } |
| 183 | 189 |
| 190 /** | |
| 191 * Handles motion event of type {@code SOURCE_CLASS_POINTER}. | |
| 192 * | |
| 193 * @param event {@link MotionEvent} instance. | |
| 194 * @param event scrollFactor scale factor used to convert wheel tick to pixe l. | |
| 195 */ | |
| 196 public boolean onPointerDeviceEvent(MotionEvent event, float scrollFactor) { | |
| 197 switch (event.getActionMasked()) { | |
| 198 case MotionEvent.ACTION_SCROLL: | |
| 199 assert mNativeEventForwarder != 0; | |
| 200 | |
| 201 nativeOnMouseWheelEvent(mNativeEventForwarder, event.getEventTim e(), event.getX(), | |
| 202 event.getY(), event.getAxisValue(MotionEvent.AXIS_HSCROL L), | |
| 203 event.getAxisValue(MotionEvent.AXIS_VSCROLL), scrollFact or); | |
| 204 return true; | |
| 205 case MotionEvent.ACTION_BUTTON_PRESS: | |
| 206 case MotionEvent.ACTION_BUTTON_RELEASE: | |
| 207 // TODO(mustaq): Should we include MotionEvent.TOOL_TYPE_STYLUS here? | |
| 208 // crbug.com/592082 | |
| 209 if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) return onMouseEvent(event); | |
| 210 } | |
| 211 | |
| 212 return false; | |
| 213 } | |
| 214 | |
| 215 public JoystickScrollProvider createJoystickScrollProvider( | |
|
boliu
2017/03/27 17:44:44
Having JoystickScrollProvider and whatnot in ui ma
Jinsuk Kim
2017/03/27 22:42:06
The motivation is to migrate these input events fl
boliu
2017/03/27 22:54:22
afaict, the dependency (from higher to lower) is c
Jinsuk Kim
2017/03/27 22:59:51
.. wish it had been discussed in the crbug.com/703
Jinsuk Kim
2017/03/27 23:04:24
May I was not clear. I meant that EventForwarder p
boliu
2017/03/27 23:19:17
You can just make onMouseWheelEvent public here th
Jinsuk Kim
2017/03/28 02:40:33
Done. Moved Joystick.+Provider classes back to con
| |
| 216 View containerView, WindowAndroid windowAndroid) { | |
| 217 if (mJoystickScrollProvider != null) return mJoystickScrollProvider; | |
| 218 mJoystickScrollProvider = new JoystickScrollProvider( | |
| 219 containerView, windowAndroid, new JoystickScrollProvider.ScrollE mulator() { | |
| 220 // Joystick scroll is translated to mouse wheel event. | |
| 221 @Override | |
| 222 public void scroll(long timeMillis, float dx, float dy) { | |
| 223 assert mNativeEventForwarder != 0; | |
| 224 nativeOnMouseWheelEvent( | |
| 225 mNativeEventForwarder, timeMillis, 0, 0, -dx, -d y, 1.0f); | |
| 226 } | |
| 227 }); | |
| 228 return mJoystickScrollProvider; | |
| 229 } | |
| 230 | |
| 184 // All touch events (including flings, scrolls etc) accept coordinates in ph ysical pixels. | 231 // All touch events (including flings, scrolls etc) accept coordinates in ph ysical pixels. |
| 185 private native boolean nativeOnTouchEvent(long nativeEventForwarder, MotionE vent event, | 232 private native boolean nativeOnTouchEvent(long nativeEventForwarder, MotionE vent event, |
| 186 long timeMs, int action, int pointerCount, int historySize, int acti onIndex, float x0, | 233 long timeMs, int action, int pointerCount, int historySize, int acti onIndex, float x0, |
| 187 float y0, float x1, float y1, int pointerId0, int pointerId1, float touchMajor0, | 234 float y0, float x1, float y1, int pointerId0, int pointerId1, float touchMajor0, |
| 188 float touchMajor1, float touchMinor0, float touchMinor1, float orien tation0, | 235 float touchMajor1, float touchMinor0, float touchMinor1, float orien tation0, |
| 189 float orientation1, float tilt0, float tilt1, float rawX, float rawY , | 236 float orientation1, float tilt0, float tilt1, float rawX, float rawY , |
| 190 int androidToolType0, int androidToolType1, int androidButtonState, | 237 int androidToolType0, int androidToolType1, int androidButtonState, |
| 191 int androidMetaState, boolean isTouchHandleEvent); | 238 int androidMetaState, boolean isTouchHandleEvent); |
| 192 private native void nativeOnMouseEvent(long nativeEventForwarder, long timeM s, int action, | 239 private native void nativeOnMouseEvent(long nativeEventForwarder, long timeM s, int action, |
| 193 float x, float y, int pointerId, float pressure, float orientation, float tilt, | 240 float x, float y, int pointerId, float pressure, float orientation, float tilt, |
| 194 int changedButton, int buttonState, int metaState, int toolType); | 241 int changedButton, int buttonState, int metaState, int toolType); |
| 242 private native void nativeOnMouseWheelEvent(long nativeEventForwarder, long timeMs, float x, | |
| 243 float y, float ticksX, float ticksY, float pixelsPerTick); | |
| 195 } | 244 } |
| OLD | NEW |