Adding touch events for 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 @@
         handleMouseEvent(static_cast<MouseEvent*>(event));
     else if (event->isKeyboardEvent())
         handleKeyboardEvent(static_cast<KeyboardEvent*>(event));
+#if defined(ANDROID_PLUGINS)
+    else if (event->isTouchEvent())
+        handleTouchEvent(static_cast<TouchEvent*>(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 @@
     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 @@
 
         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<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);
 
@@ -258,6 +266,7 @@
         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 @@
     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 @@
 
 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 @@
                 default:
                     break;
             }
+            break;
+        }
+        case kAcceptEvents_ANPSetValue : {
+            if(value) {
+                ANPEventFlags flags = *reinterpret_cast<ANPEventFlags*>(value);
+                m_window->updateEventFlags(flags);
+                error = NPERR_NO_ERROR;
+            }
+            break;
         }
         default:
             break;
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.cpp b/WebKit/android/plugins/PluginWidgetAndroid.cpp
index 350243e..ddb07bf 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.cpp
+++ b/WebKit/android/plugins/PluginWidgetAndroid.cpp
@@ -25,6 +25,9 @@
 
 #include "config.h"
 #include "android_graphics.h"
+#include "Document.h"
+#include "Element.h"
+#include "Frame.h"
 #include "PluginPackage.h"
 #include "PluginView.h"
 #include "PluginWidgetAndroid.h"
@@ -37,6 +40,7 @@
     m_flipPixelRef = NULL;
     m_core = NULL;
     m_drawingModel = kBitmap_ANPDrawingModel;
+    m_eventFlags = 0;
     m_x = m_y = 0;
 }
 
@@ -156,3 +160,24 @@
     return false;
 }
 
+void PluginWidgetAndroid::updateEventFlags(ANPEventFlags flags) {
+
+    // if there are no differences then immediately return
+    if (m_eventFlags == flags) {
+        return;
+    }
+
+    Document* doc = m_pluginView->getParentFrame()->document();
+    if((m_eventFlags ^ flags) & kTouch_ANPEventFlag) {
+        if(flags & kTouch_ANPEventFlag)
+            doc->addTouchEventListener(m_pluginView->getElement());
+        else
+            doc->removeTouchEventListener(m_pluginView->getElement());
+    }
+
+    m_eventFlags = flags;
+}
+
+bool PluginWidgetAndroid::isAcceptingEvent(ANPEventFlag flag) {
+    return m_eventFlags & flag;
+}
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.h b/WebKit/android/plugins/PluginWidgetAndroid.h
index 157651c..1b0cfa9 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.h
+++ b/WebKit/android/plugins/PluginWidgetAndroid.h
@@ -62,7 +62,7 @@
     /*  Called whenever the plugin itself requests a new drawing model
      */
     void setDrawingModel(ANPDrawingModel);
-    
+
     /*  Utility method to convert from local (plugin) coordinates to docuemnt
         coordinates. Needed (for instance) to convert the dirty rectangle into
         document coordinates to inturn inval the screen.
@@ -78,22 +78,33 @@
         a subsequent call to draw(NULL).
      */
     void inval(const WebCore::IntRect&, bool signalRedraw);
-    
+
     /*  Called to draw into the plugin's bitmap. If canvas is non-null, the
         bitmap itself is then drawn into the canvas.
      */
     void draw(SkCanvas* canvas = NULL);
-    
+
     /*  Send this event to the plugin instance, and return true if the plugin
         handled it.
      */
     bool sendEvent(const ANPEvent&);
 
+    /*  Update the plugins event flags. If a flag is set to true then the plugin
+        wants to be notified of events of this type.
+     */
+    void updateEventFlags(ANPEventFlags);
+
+    /*  Called to check if a plugin wants to accept a given event type. It
+        returns true if the plugin wants the events and false otherwise.
+     */
+    bool isAcceptingEvent(ANPEventFlag);
+
 private:
     WebCore::PluginView*    m_pluginView;
     android::WebViewCore*   m_core;
     SkFlipPixelRef*         m_flipPixelRef;
     ANPDrawingModel         m_drawingModel;
+    ANPEventFlags           m_eventFlags;
     int                     m_x;
     int                     m_y;
 };
diff --git a/WebKit/android/plugins/android_npapi.h b/WebKit/android/plugins/android_npapi.h
index 596d2ac..32fa1c0 100644
--- a/WebKit/android/plugins/android_npapi.h
+++ b/WebKit/android/plugins/android_npapi.h
@@ -126,9 +126,9 @@
 #define kSupportedDrawingModel_ANPGetValue  ((NPNVariable)2000)
 
 ///////////////////////////////////////////////////////////////////////////////
-// NPN_GetValue
+// NPN_SetValue
 
-/** Reqeust to set the drawing model.
+/** Request to set the drawing model.
 
     NPN_SetValue(inst, ANPRequestDrawingModel_EnumValue, (void*)foo_DrawingModel)
  */
@@ -147,6 +147,24 @@
 };
 typedef int32_t ANPDrawingModel;
 
+/** Request to receive/disable events. If the pointer is NULL then all input will
+    be disabled. Otherwise, the input type will be enabled iff its corresponding
+    bit in the EventFlags bit field is set.
+
+    NPN_SetValue(inst, ANPAcceptEvents, (void*)EventFlags)
+ */
+#define kAcceptEvents_ANPSetValue           ((NPPVariable)1001)
+
+/*  The EventFlags are a set of bits used to determine which types of input the
+    plugin wishes to receive. For example, if the value is 0x03 then both key
+    and touch events will be provided to the plugin.
+ */
+enum ANPEventFlag {
+    kKey_ANPEventFlag      = 0x01,
+    kTouch_ANPEventFlag    = 0x02,
+};
+typedef uint32_t ANPEventFlags;
+
 /*  Interfaces provide additional functionality to the plugin via function ptrs.
     Once an interface is retrived, it is valid for the lifetime of the plugin
     (just like browserfuncs).
@@ -699,8 +717,10 @@
 typedef uint32_t ANPKeyModifier;
 
 enum ANPTouchActions {
-    kDown_ANPTouchAction  = 0,
-    kUp_ANPTouchAction    = 1,
+    kDown_ANPTouchAction   = 0,
+    kUp_ANPTouchAction     = 1,
+    kMove_ANPTouchAction   = 2,
+    kCancel_ANPTouchAction = 3,
 };
 typedef int32_t ANPTouchAction;