summaryrefslogtreecommitdiff
path: root/tests/DumpRenderTree/src/com/android/dumprendertree/WebViewEventSender.java
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-01-13 10:54:56 +0000
committerBen Murdoch <benm@google.com>2010-02-03 16:57:46 +0000
commitecbc65cf8f2ea3bdd311f954e3927b46fca068ff (patch)
tree80e1bc4935fb8d19f2b2d6462ce6d228aafdd048 /tests/DumpRenderTree/src/com/android/dumprendertree/WebViewEventSender.java
parentecbfb2104f61f0a364a29b431abe6ec645ea6d51 (diff)
Add support for sending touch events in DRT.
As part of this, make it possible for DRT to configure the timeout threshold between sending touch events to WebCore as the Layout Tests only synthesize single events, not a stream. Because of this, they often get dropped by the WebView for coming too quickly. Skip the multi touch test as we don't support multi touch in the Browser. Change-Id: I7b9830f43181fea33206825b49ef2e294269b4dd
Diffstat (limited to 'tests/DumpRenderTree/src/com/android/dumprendertree/WebViewEventSender.java')
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/WebViewEventSender.java173
1 files changed, 167 insertions, 6 deletions
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/WebViewEventSender.java b/tests/DumpRenderTree/src/com/android/dumprendertree/WebViewEventSender.java
index eea634636978..996eaba0b73e 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/WebViewEventSender.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/WebViewEventSender.java
@@ -16,17 +16,25 @@
package com.android.dumprendertree;
-import android.webkit.WebView;
-import android.view.KeyEvent;
+import android.os.Handler;
+import android.os.SystemClock;
import android.util.*;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.webkit.WebView;
+import java.lang.InterruptedException;
import java.util.Arrays;
+import java.util.Vector;
public class WebViewEventSender implements EventSender {
+
+ private static final String LOGTAG = "WebViewEventSender";
- WebViewEventSender(WebView webView) {
- mWebView = webView;
- }
+ WebViewEventSender(WebView webView) {
+ mWebView = webView;
+ mTouchPoints = new Vector();
+ }
public void resetMouse() {
mouseX = mouseY = 0;
@@ -186,9 +194,162 @@ public class WebViewEventSender implements EventSender {
}
return KeyEvent.KEYCODE_UNKNOWN;
}
-
+
+ public void touchStart() {
+ // We only support single touch so examine the first touch point only.
+ // If multi touch is enabled in the future, we need to re-examine this to send
+ // all the touch points with the event.
+ TouchPoint tp = mTouchPoints.get(0);
+
+ if (tp == null) {
+ return;
+ }
+
+ tp.setDownTime(SystemClock.uptimeMillis());
+ MotionEvent event = MotionEvent.obtain(tp.downTime(), tp.downTime(),
+ MotionEvent.ACTION_DOWN, tp.getX(), tp.getY(), 0);
+ mWebView.onTouchEvent(event);
+ }
+
+ public void touchMove() {
+ TouchPoint tp = mTouchPoints.get(0);
+
+ if (tp == null) {
+ return;
+ }
+
+ if (!tp.hasMoved()) {
+ return;
+ }
+
+ MotionEvent event = MotionEvent.obtain(tp.downTime(), SystemClock.uptimeMillis(),
+ MotionEvent.ACTION_MOVE, tp.getX(), tp.getY(), 0);
+ mWebView.onTouchEvent(event);
+
+ tp.setMoved(false);
+ }
+
+ public void touchEnd() {
+ TouchPoint tp = mTouchPoints.get(0);
+
+ if (tp == null) {
+ return;
+ }
+
+ MotionEvent event = MotionEvent.obtain(tp.downTime(), SystemClock.uptimeMillis(),
+ MotionEvent.ACTION_UP, tp.getX(), tp.getY(), 0);
+ mWebView.onTouchEvent(event);
+
+ if (tp.isReleased()) {
+ mTouchPoints.remove(0);
+ }
+ }
+
+ public void touchCancel() {
+ TouchPoint tp = mTouchPoints.get(0);
+ if (tp == null) {
+ return;
+ }
+
+ if (tp.cancelled()) {
+ MotionEvent event = MotionEvent.obtain(tp.downTime(), SystemClock.uptimeMillis(),
+ MotionEvent.ACTION_CANCEL, tp.getX(), tp.getY(), 0);
+ mWebView.onTouchEvent(event);
+ }
+ }
+
+ public void cancelTouchPoint(int id) {
+ TouchPoint tp = mTouchPoints.get(0);
+ if (tp == null) {
+ return;
+ }
+
+ tp.cancel();
+ }
+
+ public void addTouchPoint(int x, int y) {
+ mTouchPoints.add(new TouchPoint(contentsToWindowX(x), contentsToWindowY(y)));
+ if (mTouchPoints.size() > 1) {
+ Log.w(LOGTAG, "Adding more than one touch point, but multi touch is not supported!");
+ }
+ }
+
+ public void updateTouchPoint(int id, int x, int y) {
+ TouchPoint tp = mTouchPoints.get(0);
+ if (tp == null) {
+ return;
+ }
+
+ tp.update(contentsToWindowX(x), contentsToWindowY(y));
+ tp.setMoved(true);
+ }
+
+ public void setTouchModifier(String modifier, boolean enabled) {
+ // TODO(benm): This needs implementing when Android supports sending key modifiers
+ // in touch events.
+ }
+
+ public void releaseTouchPoint(int id) {
+ TouchPoint tp = mTouchPoints.get(0);
+ if (tp == null) {
+ return;
+ }
+
+ tp.release();
+ }
+
+ public void clearTouchPoints() {
+ mTouchPoints.clear();
+ }
+
+ private int contentsToWindowX(int x) {
+ return (int) (x * mWebView.getScale()) - mWebView.getScrollX();
+ }
+
+ private int contentsToWindowY(int y) {
+ return (int) (y * mWebView.getScale()) - mWebView.getScrollY();
+ }
+
private WebView mWebView = null;
private int mouseX;
private int mouseY;
+ private class TouchPoint {
+ private int mX;
+ private int mY;
+ private long mDownTime;
+ private boolean mReleased;
+ private boolean mMoved;
+ private boolean mCancelled;
+
+ public TouchPoint(int x, int y) {
+ mX = x;
+ mY = y;
+ mReleased = false;
+ mMoved = false;
+ mCancelled = false;
+ }
+
+ public void setDownTime(long downTime) { mDownTime = downTime; }
+ public long downTime() { return mDownTime; }
+ public void cancel() { mCancelled = true; }
+
+ public boolean cancelled() { return mCancelled; }
+
+ public void release() { mReleased = true; }
+ public boolean isReleased() { return mReleased; }
+
+ public void setMoved(boolean moved) { mMoved = moved; }
+ public boolean hasMoved() { return mMoved; }
+
+ public int getX() { return mX; }
+ public int getY() { return mY; }
+
+ public void update(int x, int y) {
+ mX = x;
+ mY = y;
+ }
+ };
+
+ private Vector<TouchPoint> mTouchPoints;
}