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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/TouchEventSynthesizer.java

Issue 26664002: SyntheticGestureTarget implementation for injecting synthetic input events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add virtual to dtor Created 7 years, 1 month 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
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/TouchEventSynthesizer.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/TouchEventSynthesizer.java b/content/public/android/java/src/org/chromium/content/browser/TouchEventSynthesizer.java
new file mode 100644
index 0000000000000000000000000000000000000000..9c67587e96559ed752b9e836621d4023d0764963
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/TouchEventSynthesizer.java
@@ -0,0 +1,118 @@
+// 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 TouchEventSynthesizer {
+ 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 long mDownTime;
+
+ TouchEventSynthesizer(ContentViewCore contentViewCore) {
+ mContentViewCore = contentViewCore;
+ mPointerProperties = new PointerProperties[MAX_NUM_POINTERS];
+ mPointerCoords = new PointerCoords[MAX_NUM_POINTERS];
+ }
+
+ @CalledByNative
+ void setPointer(int index, int x, int y, int id) {
+ assert (0 <= index && index < MAX_NUM_POINTERS);
+
+ // Convert coordinates from density independent pixels to density dependent pixels.
+ float scaleFactor = mContentViewCore.getRenderCoordinates().getDeviceScaleFactor();
+
+ PointerCoords coords = new PointerCoords();
+ coords.x = scaleFactor * x;
+ coords.y = scaleFactor * y;
+ coords.pressure = 1.0f;
+ mPointerCoords[index] = coords;
+
+ PointerProperties properties = new PointerProperties();
+ properties.id = id;
+ mPointerProperties[index] = properties;
+ }
+
+ @CalledByNative
+ void inject(int action, int pointerCount) {
+ long time = SystemClock.uptimeMillis();
+
+ switch (action) {
+ case ACTION_START: {
+ mDownTime = time;
+ MotionEvent event = MotionEvent.obtain(
+ mDownTime, time, MotionEvent.ACTION_DOWN, 1,
+ mPointerProperties, mPointerCoords,
+ 0, 0, 1, 1, 0, 0, 0, 0);
+ mContentViewCore.onTouchEvent(event);
+ event.recycle();
+
+ if (pointerCount > 1) {
+ event = MotionEvent.obtain(
+ mDownTime, time, MotionEvent.ACTION_POINTER_DOWN,
+ pointerCount, mPointerProperties, mPointerCoords,
+ 0, 0, 1, 1, 0, 0, 0, 0);
+ mContentViewCore.onTouchEvent(event);
+ event.recycle();
+ }
+ break;
+ }
+ case ACTION_MOVE: {
+ MotionEvent event = MotionEvent.obtain(mDownTime, time,
+ MotionEvent.ACTION_MOVE,
+ pointerCount, mPointerProperties, mPointerCoords,
+ 0, 0, 1, 1, 0, 0, 0, 0);
+ mContentViewCore.onTouchEvent(event);
+ event.recycle();
+ break;
+ }
+ case ACTION_CANCEL: {
+ MotionEvent event = MotionEvent.obtain(
+ mDownTime, time, MotionEvent.ACTION_CANCEL, 1,
+ mPointerProperties, mPointerCoords,
+ 0, 0, 1, 1, 0, 0, 0, 0);
+ mContentViewCore.onTouchEvent(event);
+ event.recycle();
+ break;
+ }
+ case ACTION_END: {
+ if (pointerCount > 1) {
+ MotionEvent event = MotionEvent.obtain(
+ mDownTime, time, MotionEvent.ACTION_POINTER_UP,
+ pointerCount, mPointerProperties, mPointerCoords,
+ 0, 0, 1, 1, 0, 0, 0, 0);
+ mContentViewCore.onTouchEvent(event);
+ event.recycle();
+ }
+
+ MotionEvent event = MotionEvent.obtain(
+ mDownTime, time, MotionEvent.ACTION_UP, 1,
+ mPointerProperties, mPointerCoords,
+ 0, 0, 1, 1, 0, 0, 0, 0);
+ mContentViewCore.onTouchEvent(event);
+ event.recycle();
+ break;
+ }
+ }
+ }
+}
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698