summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorHuahui Wu <hwu@google.com>2011-07-07 11:05:13 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-07-07 11:05:13 -0700
commitb083fa61d9411e9c1f3933fd8657d86e99e7eccd (patch)
tree0edb28be04459d26135797522df4460c1196398f /core
parent2ad31117591816ecc6c52f07459aef987b025462 (diff)
parent6e64e0c61720244894dbd1fd6b36394adc63b2de (diff)
downloadframeworks_base-b083fa61d9411e9c1f3933fd8657d86e99e7eccd.zip
frameworks_base-b083fa61d9411e9c1f3933fd8657d86e99e7eccd.tar.gz
frameworks_base-b083fa61d9411e9c1f3933fd8657d86e99e7eccd.tar.bz2
Merge "b/3302378 Passes touch pressures, size and timestamps to webkit."
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/MotionEvent.java4
-rw-r--r--core/java/android/webkit/WebView.java100
-rw-r--r--core/java/android/webkit/WebViewCore.java28
3 files changed, 86 insertions, 46 deletions
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java
index 88f59d4..72263a7 100644
--- a/core/java/android/view/MotionEvent.java
+++ b/core/java/android/view/MotionEvent.java
@@ -2881,6 +2881,10 @@ public final class MotionEvent extends InputEvent implements Parcelable {
msg.append(", id[").append(i).append("]=").append(getPointerId(i));
msg.append(", x[").append(i).append("]=").append(getX(i));
msg.append(", y[").append(i).append("]=").append(getY(i));
+ msg.append(", pressure[").append(i).append("]=").append(getPressure(i));
+ msg.append(", touchMajor[").append(i).append("]=").append(getTouchMajor(i));
+ msg.append(", touchMinor[").append(i).append("]=").append(getTouchMinor(i));
+ msg.append(", orientation[").append(i).append("]=").append(getOrientation(i));
msg.append(", toolType[").append(i).append("]=").append(
toolTypeToString(getToolType(i)));
}
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 7ba86a5..ffa52d1 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -3467,6 +3467,40 @@ public class WebView extends AbsoluteLayout
return Math.min(duration, MAX_DURATION);
}
+
+ // Helper to build a TouchEventData object from a MotionEvent object.
+ // A few fields are allocated now but will be set later:
+ // mAction, mPoints and mPointsInView.
+ private static TouchEventData buildTouchFromEvent(MotionEvent ev) {
+ TouchEventData ted = new TouchEventData();
+ ted.mAction = ev.getActionMasked();
+ ted.mEventTime = ev.getEventTime();
+
+ final int count = ev.getPointerCount();
+ ted.mIds = new int[count];
+ ted.mPoints = new Point[count];
+ ted.mPointsInView = new Point[count];
+ ted.mPressures = new float[count];
+ ted.mTouchMajor = new int[count];
+ ted.mTouchMinor = new int[count];
+ ted.mOrientation = new float[count];
+ for (int c = 0; c < count; c++) {
+ ted.mIds[c] = ev.getPointerId(c);
+ ted.mPressures[c] = ev.getPressure(c);
+ ted.mTouchMajor[c] = (int) ev.getTouchMajor(c);
+ ted.mTouchMinor[c] = (int) ev.getTouchMinor(c);
+ ted.mOrientation[c] = ev.getOrientation(c);
+ }
+
+ if (ted.mAction == MotionEvent.ACTION_POINTER_DOWN
+ || ted.mAction == MotionEvent.ACTION_POINTER_UP) {
+ ted.mActionIndex = ev.getActionIndex();
+ }
+ ted.mMetaState = ev.getMetaState();
+
+ return ted;
+ }
+
// helper to pin the scrollBy parameters (already in view coordinates)
// returns true if the scroll was changed
private boolean pinScrollBy(int dx, int dy, boolean animate, int animationDuration) {
@@ -5865,15 +5899,10 @@ public class WebView extends AbsoluteLayout
}
// pass the touch events from UI thread to WebCore thread
if (shouldForwardTouchEvent()) {
- TouchEventData ted = new TouchEventData();
+ TouchEventData ted = buildTouchFromEvent(ev);
ted.mAction = action;
- ted.mIds = new int[1];
- ted.mIds[0] = ev.getPointerId(0);
- ted.mPoints = new Point[1];
ted.mPoints[0] = new Point(contentX, contentY);
- ted.mPointsInView = new Point[1];
ted.mPointsInView[0] = new Point(x, y);
- ted.mMetaState = ev.getMetaState();
ted.mReprocess = mDeferTouchProcess;
ted.mNativeLayer = nativeScrollableLayer(
contentX, contentY, ted.mNativeLayerRect, null);
@@ -5915,15 +5944,10 @@ public class WebView extends AbsoluteLayout
// pass the touch events from UI thread to WebCore thread
if (shouldForwardTouchEvent() && mConfirmMove && (firstMove
|| eventTime - mLastSentTouchTime > mCurrentTouchInterval)) {
- TouchEventData ted = new TouchEventData();
+ TouchEventData ted = buildTouchFromEvent(ev);
ted.mAction = action;
- ted.mIds = new int[1];
- ted.mIds[0] = ev.getPointerId(0);
- ted.mPoints = new Point[1];
ted.mPoints[0] = new Point(contentX, contentY);
- ted.mPointsInView = new Point[1];
ted.mPointsInView[0] = new Point(x, y);
- ted.mMetaState = ev.getMetaState();
ted.mReprocess = mDeferTouchProcess;
ted.mNativeLayer = mScrollingLayer;
ted.mNativeLayerRect.set(mScrollingLayerRect);
@@ -6093,15 +6117,10 @@ public class WebView extends AbsoluteLayout
if (!isFocused()) requestFocus();
// pass the touch events from UI thread to WebCore thread
if (shouldForwardTouchEvent()) {
- TouchEventData ted = new TouchEventData();
- ted.mIds = new int[1];
- ted.mIds[0] = ev.getPointerId(0);
+ TouchEventData ted = buildTouchFromEvent(ev);
ted.mAction = action;
- ted.mPoints = new Point[1];
ted.mPoints[0] = new Point(contentX, contentY);
- ted.mPointsInView = new Point[1];
ted.mPointsInView[0] = new Point(x, y);
- ted.mMetaState = ev.getMetaState();
ted.mReprocess = mDeferTouchProcess;
ted.mNativeLayer = mScrollingLayer;
ted.mNativeLayerRect.set(mScrollingLayerRect);
@@ -6118,15 +6137,10 @@ public class WebView extends AbsoluteLayout
mPrivateHandler.removeMessages(SWITCH_TO_SHORTPRESS);
mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
if (inFullScreenMode() || mDeferTouchProcess) {
- TouchEventData ted = new TouchEventData();
- ted.mIds = new int[1];
- ted.mIds[0] = ev.getPointerId(0);
+ TouchEventData ted = buildTouchFromEvent(ev);
ted.mAction = WebViewCore.ACTION_DOUBLETAP;
- ted.mPoints = new Point[1];
ted.mPoints[0] = new Point(contentX, contentY);
- ted.mPointsInView = new Point[1];
ted.mPointsInView[0] = new Point(x, y);
- ted.mMetaState = ev.getMetaState();
ted.mReprocess = mDeferTouchProcess;
ted.mNativeLayer = nativeScrollableLayer(
contentX, contentY,
@@ -6258,24 +6272,14 @@ public class WebView extends AbsoluteLayout
}
private void passMultiTouchToWebKit(MotionEvent ev, long sequence) {
- TouchEventData ted = new TouchEventData();
- ted.mAction = ev.getActionMasked();
- final int count = ev.getPointerCount();
- ted.mIds = new int[count];
- ted.mPoints = new Point[count];
- ted.mPointsInView = new Point[count];
- for (int c = 0; c < count; c++) {
+ TouchEventData ted = buildTouchFromEvent(ev);
+ for (int c = 0; c < ev.getPointerCount(); c++) {
ted.mIds[c] = ev.getPointerId(c);
int x = viewToContentX((int) ev.getX(c) + mScrollX);
int y = viewToContentY((int) ev.getY(c) + mScrollY);
ted.mPoints[c] = new Point(x, y);
ted.mPointsInView[c] = new Point((int) ev.getX(c), (int) ev.getY(c));
}
- if (ted.mAction == MotionEvent.ACTION_POINTER_DOWN
- || ted.mAction == MotionEvent.ACTION_POINTER_UP) {
- ted.mActionIndex = ev.getActionIndex();
- }
- ted.mMetaState = ev.getMetaState();
ted.mReprocess = true;
ted.mMotionEvent = MotionEvent.obtain(ev);
ted.mSequence = sequence;
@@ -6349,7 +6353,11 @@ public class WebView extends AbsoluteLayout
if (removeEvents) {
mWebViewCore.removeMessages(EventHub.TOUCH_EVENT);
}
+
TouchEventData ted = new TouchEventData();
+ ted.mAction = MotionEvent.ACTION_CANCEL;
+ ted.mEventTime = mLastTouchTime;
+ ted.mMetaState = 0;
ted.mIds = new int[1];
ted.mIds[0] = 0;
ted.mPoints = new Point[1];
@@ -6358,7 +6366,15 @@ public class WebView extends AbsoluteLayout
int viewX = contentToViewX(x) - mScrollX;
int viewY = contentToViewY(y) - mScrollY;
ted.mPointsInView[0] = new Point(viewX, viewY);
- ted.mAction = MotionEvent.ACTION_CANCEL;
+ ted.mPressures = new float[1];
+ ted.mPressures[0] = 1;
+ ted.mTouchMajor = new int[1];
+ ted.mTouchMajor[0] = 1;
+ ted.mTouchMinor = new int[1];
+ ted.mTouchMinor[0] = 1;
+ ted.mOrientation = new float[1];
+ ted.mOrientation[0] = 0;
+
ted.mNativeLayer = nativeScrollableLayer(
x, y, ted.mNativeLayerRect, null);
ted.mSequence = mTouchEventQueue.nextTouchSequence();
@@ -8037,6 +8053,7 @@ public class WebView extends AbsoluteLayout
if (inFullScreenMode() || mDeferTouchProcess) {
TouchEventData ted = new TouchEventData();
ted.mAction = WebViewCore.ACTION_LONGPRESS;
+ ted.mEventTime = mLastTouchTime;
ted.mIds = new int[1];
ted.mIds[0] = 0;
ted.mPoints = new Point[1];
@@ -8044,6 +8061,15 @@ public class WebView extends AbsoluteLayout
viewToContentY(mLastTouchY + mScrollY));
ted.mPointsInView = new Point[1];
ted.mPointsInView[0] = new Point(mLastTouchX, mLastTouchY);
+ ted.mPressures = new float[1];
+ ted.mPressures[0] = 1;
+ ted.mTouchMajor = new int[1];
+ ted.mTouchMajor[0] = 1;
+ ted.mTouchMinor = new int[1];
+ ted.mTouchMinor[0] = 1;
+ ted.mOrientation = new float[1];
+ ted.mOrientation[0] = 0;
+
// metaState for long press is tricky. Should it be the
// state when the press started or when the press was
// released? Or some intermediary key state? For
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 4f97066..3357220 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -577,8 +577,10 @@ public final class WebViewCore {
private native void nativeTouchUp(int touchGeneration,
int framePtr, int nodePtr, int x, int y);
- private native boolean nativeHandleTouchEvent(int action, int[] idArray,
- int[] xArray, int[] yArray, int count, int actionIndex, int metaState);
+ private native boolean nativeHandleTouchEvent(int action, long eventTime,
+ int[] idArray, int[] xArray, int[] yArray, float[] pressureArray,
+ int[] touchMajorArray, int[] touchMinorArray, float[] orientationArray,
+ int count, int actionIndex, int metaState);
private native void nativeUpdateFrameCache();
@@ -833,16 +835,21 @@ public final class WebViewCore {
static class TouchEventData {
int mAction;
- int[] mIds; // Ids of the touch points
+ long mEventTime; // Time (in ms) this event was generated.
+ int[] mIds; // Ids of the touch points.
Point[] mPoints;
- Point[] mPointsInView; // the point coordinates in view axis.
- int mActionIndex; // Associated pointer index for ACTION_POINTER_DOWN/UP
+ Point[] mPointsInView; // Point coordinates in view axis.
+ float[] mPressures; // Pressures of the touch points.
+ int[] mTouchMajor; // Length of the major axis of the touch area.
+ int[] mTouchMinor; // Length of the minor axis of the touch area.
+ float[] mOrientation; // The orientation of the touch area.
+ int mActionIndex; // Associated pointer index for ACTION_POINTER_DOWN/UP.
int mMetaState;
boolean mReprocess;
- MotionEvent mMotionEvent;
+ MotionEvent mMotionEvent; // Only used for multi-touch.
int mNativeLayer;
Rect mNativeLayerRect = new Rect();
- long mSequence;
+ long mSequence; // For queuing the events.
boolean mNativeResult;
}
@@ -1351,8 +1358,11 @@ public final class WebViewCore {
nativeScrollLayer(ted.mNativeLayer,
ted.mNativeLayerRect);
}
- ted.mNativeResult = nativeHandleTouchEvent(ted.mAction, ted.mIds,
- xArray, yArray, count, ted.mActionIndex, ted.mMetaState);
+ ted.mNativeResult = nativeHandleTouchEvent(
+ ted.mAction, ted.mEventTime, ted.mIds,
+ xArray, yArray, ted.mPressures,
+ ted.mTouchMajor, ted.mTouchMinor, ted.mOrientation,
+ count, ted.mActionIndex, ted.mMetaState);
Message.obtain(
mWebView.mPrivateHandler,
WebView.PREVENT_TOUCH_ID,