OSDN Git Service

Bug: 2372180
authorHuahui Wu <hwu@google.com>
Thu, 2 Sep 2010 20:14:24 +0000 (13:14 -0700)
committerHuahui Wu <hwu@google.com>
Mon, 27 Sep 2010 17:20:08 +0000 (10:20 -0700)
This CL adds support to pass multi-touch event from browser to webkit.
PlatformTouchEvent.h and PlatformTouchEventAndroid.cpp:
    changed the android constructor to take multiple touch points.
PlatformTouchPoint.h and PlatformTouchPointAndroid.cpp:
    changed the android constructor to take a touch point ID.
WebViewCore.h and WebViewCore.cpp:
    1. Updated handleTouchEvent(), HandleTouchEvent(), and jni interface
       to take multiple points.
    2. Added support of action
       MotionEvent.ACTION_POINTER_DOWN & MotionEvent.ACTION_POINTER_UP.

Change-Id: I79cffdba12a60ced9a571b4c1fd5b520a0fb6074

WebCore/platform/PlatformTouchEvent.h
WebCore/platform/PlatformTouchPoint.h
WebCore/platform/android/PlatformTouchEventAndroid.cpp
WebCore/platform/android/PlatformTouchPointAndroid.cpp
WebKit/android/jni/WebViewCore.cpp
WebKit/android/jni/WebViewCore.h

index c3a0283..db0f552 100644 (file)
@@ -60,7 +60,8 @@ public:
 #if PLATFORM(QT)
     PlatformTouchEvent(QTouchEvent*);
 #elif PLATFORM(ANDROID)
-    PlatformTouchEvent(const IntPoint& windowPos, TouchEventType, PlatformTouchPoint::State, int metaState);
+    // Change in following line is in ANDROID but waiting for patch to WebKit getting accepted.
+    PlatformTouchEvent(const Vector<IntPoint>&, TouchEventType, PlatformTouchPoint::State, int metaState);
 #endif
 
     TouchEventType type() const { return m_type; }
index 3a25736..ffde863 100644 (file)
@@ -47,7 +47,8 @@ public:
     PlatformTouchPoint(const QTouchEvent::TouchPoint&);
     PlatformTouchPoint() {};
 #elif PLATFORM(ANDROID)
-    PlatformTouchPoint(const IntPoint& windowPos, State);
+    // Change in following line is in ANDROID but waiting for patch to WebKit getting accepted.
+    PlatformTouchPoint(unsigned id, const IntPoint& windowPos, State);
 #endif
 
     unsigned id() const { return m_id; }
index e33aec0..50fc203 100644 (file)
@@ -37,11 +37,15 @@ enum AndroidMetaKeyState {
     META_SYM_ON = 0x04
 };
 
-PlatformTouchEvent::PlatformTouchEvent(const IntPoint& windowPos, TouchEventType type, PlatformTouchPoint::State state, int metaState)
+// Changes in following two lines are in ANDROID but waiting for patch to WebKit getting accepted.
+PlatformTouchEvent::PlatformTouchEvent(const Vector<IntPoint>& windowPoints, TouchEventType type, PlatformTouchPoint::State state, int metaState)
     : m_type(type)
     , m_metaKey(false)
 {
-    m_touchPoints.append(PlatformTouchPoint(windowPos, state));
+    // Changes in following three lines are in ANDROID but waiting for patch to WebKit getting accepted.
+    m_touchPoints.reserveCapacity(windowPoints.size());
+    for (unsigned c = 0; c < windowPoints.size(); c++)
+        m_touchPoints.append(PlatformTouchPoint(c, windowPoints[c], state));
 
     m_altKey = metaState & META_ALT_ON;
     m_shiftKey = metaState & META_SHIFT_ON;
index f134c0e..5a181cc 100644 (file)
@@ -30,8 +30,9 @@
 
 namespace WebCore {
 
-PlatformTouchPoint::PlatformTouchPoint(const IntPoint& windowPos, State state)
-    : m_id(0)
+// Changes in following two lines are in ANDROID but waiting for patch to WebKit getting accepted.
+PlatformTouchPoint::PlatformTouchPoint(unsigned id, const IntPoint& windowPos, State state)
+    : m_id(id)
     , m_state(state)
     , m_screenPos(windowPos)
     , m_pos(windowPos) { }
index b9af546..8353b98 100644 (file)
@@ -2621,7 +2621,7 @@ GraphicsLayerAndroid* WebViewCore::graphicsRootLayer() const
 }
 #endif
 
-bool WebViewCore::handleTouchEvent(int action, int x, int y, int metaState)
+bool WebViewCore::handleTouchEvent(int action, Vector<IntPoint>& points, int metaState)
 {
     bool preventDefault = false;
 
@@ -2636,9 +2636,11 @@ bool WebViewCore::handleTouchEvent(int action, int x, int y, int metaState)
     WebCore::PlatformTouchPoint::State touchState = WebCore::PlatformTouchPoint::TouchPressed;
     switch (action) {
     case 0: // MotionEvent.ACTION_DOWN
+    case 5: // MotionEvent.ACTION_POINTER_DOWN
         type = WebCore::TouchStart;
         break;
     case 1: // MotionEvent.ACTION_UP
+    case 6: // MotionEvent.ACTION_POINTER_UP
         type = WebCore::TouchEnd;
         touchState = WebCore::PlatformTouchPoint::TouchReleased;
         break;
@@ -2666,9 +2668,11 @@ bool WebViewCore::handleTouchEvent(int action, int x, int y, int metaState)
     }
 
     // Track previous touch and if stationary set the state.
-    WebCore::IntPoint pt(x - m_scrollOffsetX, y - m_scrollOffsetY);
-
-    WebCore::PlatformTouchEvent te(pt, type, touchState, metaState);
+    for (unsigned c = 0; c < points.size(); c++) {
+        points[c].setX(points[c].x() - m_scrollOffsetX);
+        points[c].setY(points[c].y() - m_scrollOffsetY);
+    }
+    WebCore::PlatformTouchEvent te(points, type, touchState, metaState);
     preventDefault = m_mainFrame->eventHandler()->handleTouchEvent(te);
 #endif
 
@@ -3510,14 +3514,25 @@ static jstring FindAddress(JNIEnv *env, jobject obj, jstring addr,
     return ret;
 }
 
-static jboolean HandleTouchEvent(JNIEnv *env, jobject obj, jint action, jint x, jint y, jint metaState)
+static jboolean HandleTouchEvent(JNIEnv *env, jobject obj, jint action,
+                                 jintArray xArray, jintArray yArray, jint count, jint metaState)
 {
 #ifdef ANDROID_INSTRUMENT
     TimeCounterAuto counter(TimeCounter::WebViewCoreTimeCounter);
 #endif
     WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj);
     LOG_ASSERT(viewImpl, "viewImpl not set in %s", __FUNCTION__);
-    return viewImpl->handleTouchEvent(action, x, y, metaState);
+    jint* ptrXArray = env->GetIntArrayElements(xArray, 0);
+    jint* ptrYArray = env->GetIntArrayElements(yArray, 0);
+    Vector<IntPoint> points(count);
+    for (unsigned c = 0; c < count; c++) {
+        points[c].setX(ptrXArray[c]);
+        points[c].setY(ptrYArray[c]);
+    }
+    env->ReleaseIntArrayElements(xArray, ptrXArray, JNI_ABORT);
+    env->ReleaseIntArrayElements(yArray, ptrYArray, JNI_ABORT);
+
+    return viewImpl->handleTouchEvent(action, points, metaState);
 }
 
 static void TouchUp(JNIEnv *env, jobject obj, jint touchGeneration,
@@ -3852,7 +3867,7 @@ static jobject GetTouchHighlightRects(JNIEnv* env, jobject obj, jint x, jint y,
     jmethodID init = env->GetMethodID(arrayClass, "<init>", "(I)V");
     LOG_ASSERT(init, "Could not find constructor for ArrayList");
     jobject array = env->NewObject(arrayClass, init, rects.size());
-    LOG_ASSERT(vector, "Could not create a new ArrayList");
+    LOG_ASSERT(array, "Could not create a new ArrayList");
     jmethodID add = env->GetMethodID(arrayClass, "add", "(Ljava/lang/Object;)Z");
     LOG_ASSERT(add, "Could not find add method on ArrayList");
     jclass rectClass = env->FindClass("android/graphics/Rect");
@@ -3940,7 +3955,7 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = {
         (void*) SaveDocumentState },
     { "nativeFindAddress", "(Ljava/lang/String;Z)Ljava/lang/String;",
         (void*) FindAddress },
-    { "nativeHandleTouchEvent", "(IIII)Z",
+    { "nativeHandleTouchEvent", "(I[I[III)Z",
             (void*) HandleTouchEvent },
     { "nativeTouchUp", "(IIIII)V",
         (void*) TouchUp },
index 61ddd7d..0078fd9 100644 (file)
@@ -314,7 +314,7 @@ namespace android {
         /**
          * Handle touch event
          */
-        bool handleTouchEvent(int action, int x, int y, int metaState);
+        bool handleTouchEvent(int action, Vector<IntPoint>& points, int metaState);
 
         /**
          * Handle motionUp event from the UI thread (called touchUp in the