diff options
author | Huahui Wu <hwu@google.com> | 2011-06-29 14:21:58 -0700 |
---|---|---|
committer | Huahui Wu <hwu@google.com> | 2011-07-07 10:59:27 -0700 |
commit | 6e64e0c61720244894dbd1fd6b36394adc63b2de (patch) | |
tree | a547cc250388a21147605a335590adce57298c05 /core/java/android/webkit | |
parent | 74e6bd7b7783fb506d7525e9ba40aac980745eaf (diff) | |
download | frameworks_base-6e64e0c61720244894dbd1fd6b36394adc63b2de.zip frameworks_base-6e64e0c61720244894dbd1fd6b36394adc63b2de.tar.gz frameworks_base-6e64e0c61720244894dbd1fd6b36394adc63b2de.tar.bz2 |
b/3302378 Passes touch pressures, size and timestamps to webkit.
Related CL in WebKit:
https://android-git.corp.google.com/g/#change,118422
Change-Id: Ibf209131a6d9ca8186c461b0c5b6286e5f669d0d
Diffstat (limited to 'core/java/android/webkit')
-rw-r--r-- | core/java/android/webkit/WebView.java | 100 | ||||
-rw-r--r-- | core/java/android/webkit/WebViewCore.java | 28 |
2 files changed, 82 insertions, 46 deletions
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, |