From 56ce2fa12f7492cf355cfb37b80b679d7921f6d4 Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Mon, 15 Jun 2009 11:44:16 -0400 Subject: Adding touch events for plugins. --- WebCore/plugins/PluginView.cpp | 8 ++++ WebCore/plugins/PluginView.h | 9 +++++ WebCore/plugins/android/PluginViewAndroid.cpp | 55 +++++++++++++++++++++------ 3 files changed, 61 insertions(+), 11 deletions(-) (limited to 'WebCore/plugins') diff --git a/WebCore/plugins/PluginView.cpp b/WebCore/plugins/PluginView.cpp index cdb8ca9..f32afb5 100644 --- a/WebCore/plugins/PluginView.cpp +++ b/WebCore/plugins/PluginView.cpp @@ -59,6 +59,9 @@ #include "RenderObject.h" #include "npruntime_impl.h" #include "Settings.h" +#if defined(ANDROID_PLUGINS) +#include "TouchEvent.h" +#endif #if USE(JSC) #include "JSDOMWindow.h" @@ -160,8 +163,13 @@ void PluginView::handleEvent(Event* event) handleMouseEvent(static_cast(event)); else if (event->isKeyboardEvent()) handleKeyboardEvent(static_cast(event)); +#if defined(ANDROID_PLUGINS) + else if (event->isTouchEvent()) + handleTouchEvent(static_cast(event)); +#endif } + bool PluginView::start() { if (m_isStarted) diff --git a/WebCore/plugins/PluginView.h b/WebCore/plugins/PluginView.h index d007d64..8bd0641 100644 --- a/WebCore/plugins/PluginView.h +++ b/WebCore/plugins/PluginView.h @@ -73,6 +73,9 @@ namespace WebCore { class Frame; class KeyboardEvent; class MouseEvent; +#ifdef ANDROID_PLUGINS + class TouchEvent; +#endif class KURL; #if PLATFORM(WIN_OS) && !PLATFORM(WX) && ENABLE(NETSCAPE_PLUGIN_API) class PluginMessageThrottlerWin; @@ -207,6 +210,11 @@ namespace WebCore { static bool isCallingPlugin(); +#ifdef ANDROID_PLUGINS + Frame* getParentFrame() const { return m_parentFrame; } + Element* getElement() const { return m_element; } +#endif + private: PluginView(Frame* parentFrame, const IntSize&, PluginPackage*, Element*, const KURL&, const Vector& paramNames, const Vector& paramValues, const String& mimeType, bool loadManually); @@ -258,6 +266,7 @@ namespace WebCore { void handleMouseEvent(MouseEvent*); #ifdef ANDROID_PLUGINS + void handleTouchEvent(TouchEvent*); // called at the end of the base constructor void platformInit(); #endif diff --git a/WebCore/plugins/android/PluginViewAndroid.cpp b/WebCore/plugins/android/PluginViewAndroid.cpp index f10ac45..51dd4e9 100644 --- a/WebCore/plugins/android/PluginViewAndroid.cpp +++ b/WebCore/plugins/android/PluginViewAndroid.cpp @@ -50,6 +50,7 @@ #include "PlatformKeyboardEvent.h" #include "PluginMainThreadScheduler.h" #include "PluginPackage.h" +#include "TouchEvent.h" #include "android_graphics.h" #include "SkCanvas.h" #include "npruntime_impl.h" @@ -203,25 +204,45 @@ void PluginView::init() m_status = PluginStatusLoadedSuccessfully; } +void PluginView::handleTouchEvent(TouchEvent* event) +{ + if (!m_window->isAcceptingEvent(kTouch_ANPEventFlag)) + return; + + ANPEvent evt; + SkANP::InitEvent(&evt, kTouch_ANPEventType); + + const AtomicString& type = event->type(); + if (eventNames().touchstartEvent == type) + evt.data.touch.action = kDown_ANPTouchAction; + else if (eventNames().touchendEvent == type) + evt.data.touch.action = kUp_ANPTouchAction; + else if (eventNames().touchmoveEvent == type) + evt.data.touch.action = kMove_ANPTouchAction; + else if (eventNames().touchcancelEvent == type) + evt.data.touch.action = kCancel_ANPTouchAction; + else + return; + + evt.data.touch.modifiers = 0; // todo + // these are relative to plugin + evt.data.touch.x = event->pageX() - m_npWindow.x; + evt.data.touch.y = event->pageY() - m_npWindow.y; + + if (m_plugin->pluginFuncs()->event(m_instance, &evt)) { + event->setDefaultHandled(); + } +} + void PluginView::handleMouseEvent(MouseEvent* event) { const AtomicString& type = event->type(); - bool isDown = (eventNames().mousedownEvent == type); - bool isUp = (eventNames().mouseupEvent == type); bool isOver = (eventNames().mouseoverEvent == type); bool isOut = (eventNames().mouseoutEvent == type); ANPEvent evt; - if (isDown || isUp) { - SkANP::InitEvent(&evt, kTouch_ANPEventType); - evt.data.touch.action = isDown ? kDown_ANPTouchAction : kUp_ANPTouchAction; - evt.data.touch.modifiers = 0; // todo - // these are relative to plugin - evt.data.touch.x = event->pageX() - m_npWindow.x; - evt.data.touch.y = event->pageY() - m_npWindow.y; - } - else if (isOver || isOut) { + if (isOver || isOut) { SkANP::InitEvent(&evt, kLifecycle_ANPEventType); evt.data.lifecycle.action = isOver ? kGainFocus_ANPLifecycleAction : kLooseFocus_ANPLifecycleAction; } @@ -247,6 +268,9 @@ static ANPKeyModifier make_modifiers(bool shift, bool alt) { void PluginView::handleKeyboardEvent(KeyboardEvent* event) { + if (!m_window->isAcceptingEvent(kKey_ANPEventFlag)) + return; + const PlatformKeyboardEvent* pke = event->keyEvent(); if (NULL == pke) { return; @@ -487,6 +511,15 @@ NPError PluginView::platformSetValue(NPPVariable variable, void* value) default: break; } + break; + } + case kAcceptEvents_ANPSetValue : { + if(value) { + ANPEventFlags flags = *reinterpret_cast(value); + m_window->updateEventFlags(flags); + error = NPERR_NO_ERROR; + } + break; } default: break; -- cgit v1.1