Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/SyntheticTouchEvent.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/SyntheticTouchEvent.java b/content/public/android/java/src/org/chromium/content/browser/SyntheticTouchEvent.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..58def99b4a88e2704fd1dabe474812aea40a0b1e |
| --- /dev/null |
| +++ b/content/public/android/java/src/org/chromium/content/browser/SyntheticTouchEvent.java |
| @@ -0,0 +1,130 @@ |
| +// Copyright 2013 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; |
| + |
| +import android.os.SystemClock; |
| +import android.view.MotionEvent; |
| +import android.view.MotionEvent.PointerProperties; |
| +import android.view.MotionEvent.PointerCoords; |
| + |
| +import org.chromium.base.CalledByNative; |
| +import org.chromium.base.JNINamespace; |
| + |
| +/** |
| + * Provides a Java-side implementation for injecting synthetic touch events. |
| + */ |
| +@JNINamespace("content") |
| +public class SyntheticTouchEvent { |
| + private static final int MAX_NUM_POINTERS = 16; |
| + |
| + private static final int ACTION_START = 0; |
| + private static final int ACTION_MOVE = 1; |
| + private static final int ACTION_CANCEL = 2; |
| + private static final int ACTION_END = 3; |
| + |
| + private final ContentViewCore mContentViewCore; |
| + private final PointerProperties[] mPointerProperties; |
| + private final PointerCoords[] mPointerCoords; |
| + private int mPointerCount; |
| + private long mDownTime; |
| + private long mTime; |
| + |
| + SyntheticTouchEvent(ContentViewCore contentViewCore) { |
| + mContentViewCore = contentViewCore; |
| + mPointerProperties = new PointerProperties[MAX_NUM_POINTERS]; |
| + mPointerCoords = new PointerCoords[MAX_NUM_POINTERS]; |
| + reset(); |
| + } |
| + |
| + @CalledByNative |
| + void reset() { |
| + mPointerCount = 0; |
| + mDownTime = mTime = SystemClock.uptimeMillis(); |
| + } |
| + |
| + @CalledByNative |
| + static long getCurrentTime() { |
| + return SystemClock.uptimeMillis(); |
| + } |
| + |
| + @CalledByNative |
| + void setDownTime(long downTime) { |
| + mDownTime = downTime; |
| + } |
| + |
| + @CalledByNative |
| + void addPointer(int x, int y, int id) { |
| + PointerCoords coords = new PointerCoords(); |
| + coords.x = x; |
| + coords.y = y; |
|
Dominik Grewe
2013/10/10 14:01:45
In GenericTouchGesture.java we're also setting coo
kouhei (in TOK)
2013/10/15 02:10:02
Done.
|
| + mPointerCoords[mPointerCount] = coords; |
| + |
| + PointerProperties properties = new PointerProperties(); |
| + properties.id = id; |
| + mPointerProperties[mPointerCount] = properties; |
| + |
| + ++ mPointerCount; |
| + } |
| + |
| + @CalledByNative |
| + void inject(int action) { |
| + switch (action) { |
| + case ACTION_START: { |
| + MotionEvent event = MotionEvent.obtain( |
| + mDownTime, mTime, MotionEvent.ACTION_DOWN, 1, |
| + mPointerProperties, mPointerCoords, |
| + 0, 0, 1, 1, 0, 0, 0, 0); |
| + mContentViewCore.onTouchEvent(event); |
| + event.recycle(); |
| + |
| + if (mPointerCount > 1) { |
| + event = MotionEvent.obtain( |
| + mDownTime, mTime, MotionEvent.ACTION_POINTER_DOWN, |
| + mPointerCount, mPointerProperties, mPointerCoords, |
| + 0, 0, 1, 1, 0, 0, 0, 0); |
| + mContentViewCore.onTouchEvent(event); |
| + event.recycle(); |
| + } |
| + break; |
| + } |
| + case ACTION_MOVE: { |
| + MotionEvent event = MotionEvent.obtain(mDownTime, mTime, |
| + MotionEvent.ACTION_MOVE, |
| + mPointerCount, mPointerProperties, mPointerCoords, |
| + 0, 0, 1, 1, 0, 0, 0, 0); |
| + mContentViewCore.onTouchEvent(event); |
| + event.recycle(); |
| + break; |
| + } |
| + case ACTION_CANCEL: { |
| + MotionEvent event = MotionEvent.obtain( |
| + mDownTime, mTime, MotionEvent.ACTION_CANCEL, 1, |
| + mPointerProperties, mPointerCoords, |
| + 0, 0, 1, 1, 0, 0, 0, 0); |
| + mContentViewCore.onTouchEvent(event); |
| + event.recycle(); |
| + break; |
| + } |
| + case ACTION_END: { |
| + if (mPointerCount > 1) { |
| + MotionEvent event = MotionEvent.obtain( |
| + mDownTime, mTime, MotionEvent.ACTION_POINTER_UP, |
| + mPointerCount, mPointerProperties, mPointerCoords, |
| + 0, 0, 1, 1, 0, 0, 0, 0); |
| + mContentViewCore.onTouchEvent(event); |
| + event.recycle(); |
| + } |
| + |
| + MotionEvent event = MotionEvent.obtain( |
| + mDownTime, mTime, MotionEvent.ACTION_UP, 1, |
| + mPointerProperties, mPointerCoords, |
| + 0, 0, 1, 1, 0, 0, 0, 0); |
| + mContentViewCore.onTouchEvent(event); |
| + event.recycle(); |
| + break; |
| + } |
| + } |
| + } |
| +} |