From 91f41286e33b387859e4841711f3054bcf75c748 Mon Sep 17 00:00:00 2001 From: John Reck Date: Thu, 24 May 2012 14:31:43 -0700 Subject: Support skipping a touch stream due to lack of handlers Bug: 6317798 Change-Id: I8c4cd3bf4c538aff202ed0e3f84982fb112936a1 --- Source/WebCore/dom/Event.h | 4 ++++ Source/WebCore/dom/EventTarget.cpp | 15 +++++++++++++++ Source/WebCore/dom/TouchEvent.cpp | 6 ++++++ Source/WebCore/dom/TouchEvent.h | 9 +++++++++ Source/WebCore/page/EventHandler.cpp | 4 ++++ Source/WebCore/platform/PlatformTouchEvent.h | 5 +++++ .../platform/android/PlatformTouchEventAndroid.cpp | 1 + Source/WebKit/android/jni/WebViewCore.cpp | 18 ++++++++++++------ Source/WebKit/android/jni/WebViewCore.h | 5 ++++- 9 files changed, 60 insertions(+), 7 deletions(-) (limited to 'Source') diff --git a/Source/WebCore/dom/Event.h b/Source/WebCore/dom/Event.h index f6e5586..e913745 100644 --- a/Source/WebCore/dom/Event.h +++ b/Source/WebCore/dom/Event.h @@ -136,6 +136,10 @@ namespace WebCore { virtual bool isErrorEvent() const; #if ENABLE(TOUCH_EVENTS) virtual bool isTouchEvent() const; +#if PLATFORM(ANDROID) + virtual bool hitTouchHandler() const { return false; } + virtual void setHitTouchHandler() { } +#endif #endif #if ENABLE(DEVICE_ORIENTATION) virtual bool isDeviceMotionEvent() const; diff --git a/Source/WebCore/dom/EventTarget.cpp b/Source/WebCore/dom/EventTarget.cpp index d84d66b..c9cece2 100644 --- a/Source/WebCore/dom/EventTarget.cpp +++ b/Source/WebCore/dom/EventTarget.cpp @@ -326,6 +326,16 @@ bool EventTarget::fireEventListeners(Event* event) EventListenerMap::iterator result = d->eventListenerMap.find(event->type()); if (result != d->eventListenerMap.end()) fireEventListeners(event, d, *result->second); + +#if ENABLE(TOUCH_EVENTS) && PLATFORM(ANDROID) + if (event->isTouchEvent() && !event->hitTouchHandler()) { + // Check for touchmove or touchend to see if we can skip + // the rest of the stream (we always get touchstart, don't need to check that) + if (d->eventListenerMap.contains(eventNames().touchmoveEvent) + || d->eventListenerMap.contains(eventNames().touchendEvent)) + event->setHitTouchHandler(); + } +#endif return !event->defaultPrevented(); } @@ -334,6 +344,11 @@ void EventTarget::fireEventListeners(Event* event, EventTargetData* d, EventList { RefPtr protect = this; +#if ENABLE(TOUCH_EVENTS) && PLATFORM(ANDROID) + if (event->isTouchEvent()) + event->setHitTouchHandler(); +#endif + // Fire all listeners registered for this event. Don't fire listeners removed // during event dispatch. Also, don't fire event listeners added during event // dispatch. Conveniently, all new event listeners will be added after 'end', diff --git a/Source/WebCore/dom/TouchEvent.cpp b/Source/WebCore/dom/TouchEvent.cpp index 225e3ae..bd1577d 100644 --- a/Source/WebCore/dom/TouchEvent.cpp +++ b/Source/WebCore/dom/TouchEvent.cpp @@ -33,6 +33,9 @@ namespace WebCore { TouchEvent::TouchEvent() { +#if PLATFORM(ANDROID) + m_hitTouchHandler = false; +#endif } TouchEvent::TouchEvent(TouchList* touches, TouchList* targetTouches, @@ -45,6 +48,9 @@ TouchEvent::TouchEvent(TouchList* touches, TouchList* targetTouches, , m_targetTouches(targetTouches) , m_changedTouches(changedTouches) { +#if PLATFORM(ANDROID) + m_hitTouchHandler = false; +#endif } TouchEvent::~TouchEvent() diff --git a/Source/WebCore/dom/TouchEvent.h b/Source/WebCore/dom/TouchEvent.h index 1514cf8..fba613f 100644 --- a/Source/WebCore/dom/TouchEvent.h +++ b/Source/WebCore/dom/TouchEvent.h @@ -62,6 +62,11 @@ public: TouchList* targetTouches() const { return m_targetTouches.get(); } TouchList* changedTouches() const { return m_changedTouches.get(); } +#if PLATFORM(ANDROID) + virtual bool hitTouchHandler() const { return m_hitTouchHandler; } + virtual void setHitTouchHandler() { m_hitTouchHandler = true; } +#endif + private: TouchEvent(); TouchEvent(TouchList* touches, TouchList* targetTouches, @@ -72,6 +77,10 @@ private: virtual bool isTouchEvent() const { return true; } +#if PLATFORM(ANDROID) + bool m_hitTouchHandler; +#endif + RefPtr m_touches; RefPtr m_targetTouches; RefPtr m_changedTouches; diff --git a/Source/WebCore/page/EventHandler.cpp b/Source/WebCore/page/EventHandler.cpp index 45450b5..cbe01ed 100644 --- a/Source/WebCore/page/EventHandler.cpp +++ b/Source/WebCore/page/EventHandler.cpp @@ -3239,6 +3239,10 @@ bool EventHandler::handleTouchEvent(const PlatformTouchEvent& event) ExceptionCode ec = 0; touchEventTarget->dispatchEvent(touchEvent.get(), ec); defaultPrevented |= touchEvent->defaultPrevented(); +#if PLATFORM(ANDROID) + if (touchEvent->hitTouchHandler()) + const_cast(event).setHitTouchHandler(); +#endif } } diff --git a/Source/WebCore/platform/PlatformTouchEvent.h b/Source/WebCore/platform/PlatformTouchEvent.h index f7524b4..d1de018 100644 --- a/Source/WebCore/platform/PlatformTouchEvent.h +++ b/Source/WebCore/platform/PlatformTouchEvent.h @@ -68,6 +68,8 @@ public: PlatformTouchEvent(QTouchEvent*); #elif PLATFORM(ANDROID) PlatformTouchEvent(const Vector&, const Vector&, TouchEventType, const Vector&, int metaState); + bool hitTouchHandler() { return m_hitTouchHandler; } + void setHitTouchHandler() { m_hitTouchHandler = true; } #elif PLATFORM(BREWMP) PlatformTouchEvent(AEEEvent, uint16 wParam, uint32 dwParam); #elif PLATFORM(EFL) @@ -93,6 +95,9 @@ protected: bool m_shiftKey; bool m_metaKey; double m_timestamp; +#if PLATFORM(ANDROID) + bool m_hitTouchHandler; +#endif }; } diff --git a/Source/WebCore/platform/android/PlatformTouchEventAndroid.cpp b/Source/WebCore/platform/android/PlatformTouchEventAndroid.cpp index dd06400..579461a 100644 --- a/Source/WebCore/platform/android/PlatformTouchEventAndroid.cpp +++ b/Source/WebCore/platform/android/PlatformTouchEventAndroid.cpp @@ -42,6 +42,7 @@ PlatformTouchEvent::PlatformTouchEvent(const Vector& ids, const Vector& ids, Vector& points, int actionIndex, int metaState) +int WebViewCore::handleTouchEvent(int action, Vector& ids, Vector& points, int actionIndex, int metaState) { - bool preventDefault = false; + int flags = 0; #if USE(ACCELERATED_COMPOSITING) GraphicsLayerAndroid* rootLayer = graphicsRootLayer(); @@ -3251,14 +3254,17 @@ bool WebViewCore::handleTouchEvent(int action, Vector& ids, VectoreventHandler()->handleTouchEvent(te); + if (m_mainFrame->eventHandler()->handleTouchEvent(te)) + flags |= TOUCH_FLAG_PREVENT_DEFAULT; + if (te.hitTouchHandler()) + flags |= TOUCH_FLAG_HIT_HANDLER; #endif #if USE(ACCELERATED_COMPOSITING) if (rootLayer) rootLayer->pauseDisplay(false); #endif - return preventDefault; + return flags; } bool WebViewCore::performMouseClick() @@ -4596,7 +4602,7 @@ static jstring FindAddress(JNIEnv* env, jobject obj, jstring addr, return ret; } -static jboolean HandleTouchEvent(JNIEnv* env, jobject obj, jint nativeClass, +static jint HandleTouchEvent(JNIEnv* env, jobject obj, jint nativeClass, jint action, jintArray idArray, jintArray xArray, jintArray yArray, jint count, jint actionIndex, jint metaState) { @@ -5037,7 +5043,7 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = { (void*) SaveDocumentState }, { "nativeFindAddress", "(Ljava/lang/String;Z)Ljava/lang/String;", (void*) FindAddress }, - { "nativeHandleTouchEvent", "(II[I[I[IIII)Z", + { "nativeHandleTouchEvent", "(II[I[I[IIII)I", (void*) HandleTouchEvent }, { "nativeMouseClick", "(I)Z", (void*) MouseClick }, diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h index bfd9387..e7e97c3 100644 --- a/Source/WebKit/android/jni/WebViewCore.h +++ b/Source/WebKit/android/jni/WebViewCore.h @@ -322,8 +322,11 @@ namespace android { /** * Handle touch event + * Returns an int with the following flags: + * bit 0: hit an event handler + * bit 1: preventDefault was called */ - bool handleTouchEvent(int action, WTF::Vector& ids, + int handleTouchEvent(int action, WTF::Vector& ids, WTF::Vector& points, int actionIndex, int metaState); -- cgit v1.1