Bug 665586 Part 1: Kill AddEventListenerByIID/RemoveEventListenerByIID code from nsPluginInstanceOwner. r=josh
authorJonas Sicking <jonas@sicking.cc>
Mon, 08 Aug 2011 11:26:22 -0700
changeset 74797 ec15be691f62ae193e46bd31c8a187493baa8eb5
parent 74796 6f2c0dbb88d338df44a624041f8808c9de0a9a9b
child 74798 196eadbe49de031f1eb67c1321fb7a57159ed79c
push id235
push userbzbarsky@mozilla.com
push dateTue, 27 Sep 2011 17:13:04 +0000
treeherdermozilla-beta@2d1e082d176a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjosh
bugs665586
milestone8.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 665586 Part 1: Kill AddEventListenerByIID/RemoveEventListenerByIID code from nsPluginInstanceOwner. r=josh
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/plugins/base/nsPluginInstanceOwner.h
toolkit/components/satchel/nsFormFillController.h
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -380,29 +380,20 @@ nsPluginInstanceOwner::~nsPluginInstance
     mPluginWindow = nsnull;
   }
 
   if (mInstance) {
     mInstance->InvalidateOwner();
   }
 }
 
-NS_IMPL_ADDREF(nsPluginInstanceOwner)
-NS_IMPL_RELEASE(nsPluginInstanceOwner)
-
-NS_INTERFACE_MAP_BEGIN(nsPluginInstanceOwner)
-  NS_INTERFACE_MAP_ENTRY(nsIPluginInstanceOwner)
-  NS_INTERFACE_MAP_ENTRY(nsIPluginTagInfo)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMMouseMotionListener)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMFocusListener)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMMouseListener)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPluginInstanceOwner)
-NS_INTERFACE_MAP_END
+NS_IMPL_ISUPPORTS3(nsPluginInstanceOwner,
+                   nsIPluginInstanceOwner,
+                   nsIPluginTagInfo,
+                   nsIDOMEventListener)
 
 nsresult
 nsPluginInstanceOwner::SetInstance(nsNPAPIPluginInstance *aInstance)
 {
   NS_ASSERTION(!mInstance || !aInstance, "mInstance should only be set or unset!");
 
   // If we're going to null out mInstance after use, be sure to call
   // mInstance->InvalidateOwner() here, since it now won't be called
@@ -1668,29 +1659,16 @@ void nsPluginInstanceOwner::ScrollPositi
         mInstance->HandleEvent(&scrollEvent, nsnull);
       }
       pluginWidget->EndDrawPlugin();
     }
   }
 #endif
 }
 
-/*=============== nsIDOMFocusListener ======================*/
-nsresult nsPluginInstanceOwner::Focus(nsIDOMEvent * aFocusEvent)
-{
-  mContentFocused = PR_TRUE;
-  return DispatchFocusToPlugin(aFocusEvent);
-}
-
-nsresult nsPluginInstanceOwner::Blur(nsIDOMEvent * aFocusEvent)
-{
-  mContentFocused = PR_FALSE;
-  return DispatchFocusToPlugin(aFocusEvent);
-}
-
 nsresult nsPluginInstanceOwner::DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent)
 {
 #ifndef XP_MACOSX
   if (!mPluginWindow || (mPluginWindow->type == NPWindowTypeWindow)) {
     // continue only for cases without child window
     return aFocusEvent->PreventDefault(); // consume event
   }
 #endif
@@ -1710,44 +1688,31 @@ nsresult nsPluginInstanceOwner::Dispatch
     }
     else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchFocusToPlugin failed, focusEvent null");   
   }
   else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchFocusToPlugin failed, privateEvent null");   
   
   return NS_OK;
 }    
 
-
-/*=============== nsIKeyListener ======================*/
-nsresult nsPluginInstanceOwner::KeyDown(nsIDOMEvent* aKeyEvent)
-{
-  return DispatchKeyToPlugin(aKeyEvent);
-}
-
-nsresult nsPluginInstanceOwner::KeyUp(nsIDOMEvent* aKeyEvent)
-{
-  return DispatchKeyToPlugin(aKeyEvent);
-}
-
 nsresult nsPluginInstanceOwner::KeyPress(nsIDOMEvent* aKeyEvent)
 {
 #ifdef XP_MACOSX
 #ifndef NP_NO_CARBON
   if (GetEventModel() == NPEventModelCarbon) {
     // KeyPress events are really synthesized keyDown events.
     // Here we check the native message of the event so that
     // we won't send the plugin two keyDown events.
     nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aKeyEvent));
     if (privateEvent) {
       nsEvent *theEvent = privateEvent->GetInternalNSEvent();
-      const nsGUIEvent *guiEvent = (nsGUIEvent*)theEvent;
-      const EventRecord *ev = (EventRecord*)(guiEvent->pluginEvent); 
-      if (guiEvent &&
-          guiEvent->message == NS_KEY_PRESS &&
-          ev &&
+      const EventRecord *ev;
+      if (theEvent &&
+          theEvent->message == NS_KEY_PRESS &&
+          (ev = (EventRecord*)(((nsGUIEvent*)theEvent)->pluginEvent)) &&
           ev->what == keyDown)
         return aKeyEvent->PreventDefault(); // consume event
     }
 
     // Nasty hack to avoid recursive event dispatching with Java. Java can
     // dispatch key events to a TSM handler, which comes back and calls 
     // [ChildView insertText:] on the cocoa widget, which sends a key
     // event back down.
@@ -1784,65 +1749,32 @@ nsresult nsPluginInstanceOwner::Dispatch
   if (!mPluginWindow || (mPluginWindow->type == NPWindowTypeWindow))
     return aKeyEvent->PreventDefault(); // consume event
   // continue only for cases without child window
 #endif
 
   if (mInstance) {
     nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aKeyEvent));
     if (privateEvent) {
-      nsKeyEvent *keyEvent = (nsKeyEvent *) privateEvent->GetInternalNSEvent();
-      if (keyEvent) {
-        nsEventStatus rv = ProcessEvent(*keyEvent);
+      nsEvent *event = privateEvent->GetInternalNSEvent();
+      if (event && event->eventStructType == NS_KEY_EVENT) {
+        nsEventStatus rv = ProcessEvent(*static_cast<nsGUIEvent*>(event));
         if (nsEventStatus_eConsumeNoDefault == rv) {
           aKeyEvent->PreventDefault();
           aKeyEvent->StopPropagation();
         }
       }
       else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchKeyToPlugin failed, keyEvent null");   
     }
     else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchKeyToPlugin failed, privateEvent null");   
   }
 
   return NS_OK;
 }    
 
-/*=============== nsIDOMMouseMotionListener ======================*/
-
-nsresult
-nsPluginInstanceOwner::MouseMove(nsIDOMEvent* aMouseEvent)
-{
-#if !defined(XP_MACOSX)
-  if (!mPluginWindow || (mPluginWindow->type == NPWindowTypeWindow))
-    return aMouseEvent->PreventDefault(); // consume event
-  // continue only for cases without child window
-#endif
-
-  // don't send mouse events if we are hidden
-  if (!mWidgetVisible)
-    return NS_OK;
-
-  nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aMouseEvent));
-  if (privateEvent) {
-    nsMouseEvent* mouseEvent = (nsMouseEvent *) privateEvent->GetInternalNSEvent();
-    if (mouseEvent) {
-      nsEventStatus rv = ProcessEvent(*mouseEvent);
-      if (nsEventStatus_eConsumeNoDefault == rv) {
-        return aMouseEvent->PreventDefault(); // consume event
-      }
-    }
-    else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::MouseMove failed, mouseEvent null");   
-  }
-  else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::MouseMove failed, privateEvent null");   
-  
-  return NS_OK;
-}
-
-/*=============== nsIDOMMouseListener ======================*/
-
 nsresult
 nsPluginInstanceOwner::MouseDown(nsIDOMEvent* aMouseEvent)
 {
 #if !defined(XP_MACOSX)
   if (!mPluginWindow || (mPluginWindow->type == NPWindowTypeWindow))
     return aMouseEvent->PreventDefault(); // consume event
   // continue only for cases without child window
 #endif
@@ -1856,103 +1788,104 @@ nsPluginInstanceOwner::MouseDown(nsIDOME
     if (fm) {
       nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(mContent);
       fm->SetFocus(elem, 0);
     }
   }
 
   nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aMouseEvent));
   if (privateEvent) {
-    nsMouseEvent* mouseEvent = (nsMouseEvent *) privateEvent->GetInternalNSEvent();
-    if (mouseEvent) {
-      nsEventStatus rv = ProcessEvent(*mouseEvent);
+    nsEvent* event = privateEvent->GetInternalNSEvent();
+      if (event && event->eventStructType == NS_MOUSE_EVENT) {
+        nsEventStatus rv = ProcessEvent(*static_cast<nsGUIEvent*>(event));
       if (nsEventStatus_eConsumeNoDefault == rv) {
         return aMouseEvent->PreventDefault(); // consume event
       }
     }
     else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::MouseDown failed, mouseEvent null");   
   }
   else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::MouseDown failed, privateEvent null");   
   
   return NS_OK;
 }
 
-nsresult
-nsPluginInstanceOwner::MouseUp(nsIDOMEvent* aMouseEvent)
-{
-  // Don't send a mouse-up event to the plugin if it isn't focused.  This can
-  // happen if the previous mouse-down was sent to a DOM element above the
-  // plugin, the mouse is still above the plugin, and the mouse-down event
-  // caused the element to disappear.  See bug 627649.
-  if (!mContentFocused) {
-    aMouseEvent->PreventDefault();
-    return NS_OK;
-  }
-  return DispatchMouseToPlugin(aMouseEvent);
-}
-
-nsresult
-nsPluginInstanceOwner::MouseClick(nsIDOMEvent* aMouseEvent)
-{
-  return DispatchMouseToPlugin(aMouseEvent);
-}
-
-nsresult
-nsPluginInstanceOwner::MouseDblClick(nsIDOMEvent* aMouseEvent)
-{
-  return DispatchMouseToPlugin(aMouseEvent);
-}
-
-nsresult
-nsPluginInstanceOwner::MouseOver(nsIDOMEvent* aMouseEvent)
-{
-  return DispatchMouseToPlugin(aMouseEvent);
-}
-
-nsresult
-nsPluginInstanceOwner::MouseOut(nsIDOMEvent* aMouseEvent)
-{
-  return DispatchMouseToPlugin(aMouseEvent);
-}
-
 nsresult nsPluginInstanceOwner::DispatchMouseToPlugin(nsIDOMEvent* aMouseEvent)
 {
 #if !defined(XP_MACOSX)
   if (!mPluginWindow || (mPluginWindow->type == NPWindowTypeWindow))
     return aMouseEvent->PreventDefault(); // consume event
   // continue only for cases without child window
 #endif
   // don't send mouse events if we are hidden
   if (!mWidgetVisible)
     return NS_OK;
 
   nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aMouseEvent));
   if (privateEvent) {
-    nsMouseEvent* mouseEvent = (nsMouseEvent *) privateEvent->GetInternalNSEvent();
-    if (mouseEvent) {
-      nsEventStatus rv = ProcessEvent(*mouseEvent);
+    nsEvent* event = privateEvent->GetInternalNSEvent();
+    if (event && event->eventStructType == NS_MOUSE_EVENT) {
+      nsEventStatus rv = ProcessEvent(*static_cast<nsGUIEvent*>(event));
       if (nsEventStatus_eConsumeNoDefault == rv) {
         aMouseEvent->PreventDefault();
         aMouseEvent->StopPropagation();
       }
     }
     else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchMouseToPlugin failed, mouseEvent null");   
   }
   else NS_ASSERTION(PR_FALSE, "nsPluginInstanceOwner::DispatchMouseToPlugin failed, privateEvent null");   
   
   return NS_OK;
 }
 
 nsresult
 nsPluginInstanceOwner::HandleEvent(nsIDOMEvent* aEvent)
 {
-  if (mInstance) {
+  nsAutoString eventType;
+  aEvent->GetType(eventType);
+  if (eventType.EqualsLiteral("focus")) {
+    mContentFocused = PR_TRUE;
+    return DispatchFocusToPlugin(aEvent);
+  }
+  if (eventType.EqualsLiteral("blur")) {
+    mContentFocused = PR_FALSE;
+    return DispatchFocusToPlugin(aEvent);
+  }
+  if (eventType.EqualsLiteral("mousedown")) {
+    return MouseDown(aEvent);
+  }
+  if (eventType.EqualsLiteral("mouseup")) {
+    // Don't send a mouse-up event to the plugin if it isn't focused.  This can
+    // happen if the previous mouse-down was sent to a DOM element above the
+    // plugin, the mouse is still above the plugin, and the mouse-down event
+    // caused the element to disappear.  See bug 627649.
+    if (!mContentFocused) {
+      aEvent->PreventDefault();
+      return NS_OK;
+    }
+    return DispatchMouseToPlugin(aEvent);
+  }
+  if (eventType.EqualsLiteral("mousemove") ||
+      eventType.EqualsLiteral("click") ||
+      eventType.EqualsLiteral("dblclick") ||
+      eventType.EqualsLiteral("mouseover") ||
+      eventType.EqualsLiteral("mouseout")) {
+    return DispatchMouseToPlugin(aEvent);
+  }
+  if (eventType.EqualsLiteral("keydown") ||
+      eventType.EqualsLiteral("keyup")) {
+    return DispatchKeyToPlugin(aEvent);
+  }
+  if (eventType.EqualsLiteral("keypress")) {
+    return KeyPress(aEvent);
+  }
+
+  nsCOMPtr<nsIDOMDragEvent> dragEvent(do_QueryInterface(aEvent));
+  if (dragEvent && mInstance) {
     nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aEvent));
-    nsCOMPtr<nsIDOMDragEvent> dragEvent(do_QueryInterface(aEvent));
-    if (privateEvent && dragEvent) {
+    if (privateEvent) {
       nsEvent* ievent = privateEvent->GetInternalNSEvent();
       if (ievent && NS_IS_TRUSTED_EVENT(ievent) &&
           (ievent->message == NS_DRAGDROP_ENTER || ievent->message == NS_DRAGDROP_OVER)) {
         // set the allowed effect to none here. The plugin should set it if necessary
         nsCOMPtr<nsIDOMDataTransfer> dataTransfer;
         dragEvent->GetDataTransfer(getter_AddRefs(dataTransfer));
         if (dataTransfer)
           dataTransfer->SetEffectAllowed(NS_LITERAL_STRING("none"));
@@ -2501,48 +2434,38 @@ nsPluginInstanceOwner::Destroy()
 #endif
 
   // unregister context menu listener
   if (mCXMenuListener) {
     mCXMenuListener->Destroy(mContent);
     mCXMenuListener = nsnull;
   }
 
-  nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mContent));
-  if (target) {
-
-    nsCOMPtr<nsIDOMEventListener> listener;
-    QueryInterface(NS_GET_IID(nsIDOMEventListener), getter_AddRefs(listener));
-
-    // Unregister focus event listener
-    mContent->RemoveEventListenerByIID(listener, NS_GET_IID(nsIDOMFocusListener));
-
-    // Unregister mouse event listener
-    mContent->RemoveEventListenerByIID(listener, NS_GET_IID(nsIDOMMouseListener));
-
-    // now for the mouse motion listener
-    mContent->RemoveEventListenerByIID(listener, NS_GET_IID(nsIDOMMouseMotionListener));
-
-    // Unregister key event listener;
-    target->RemoveEventListener(NS_LITERAL_STRING("keypress"), listener, PR_TRUE);
-    target->RemoveEventListener(NS_LITERAL_STRING("keydown"), listener, PR_TRUE);
-    target->RemoveEventListener(NS_LITERAL_STRING("keyup"), listener, PR_TRUE);
-
-    // Unregister drag event listener;
-    target->RemoveEventListener(NS_LITERAL_STRING("drop"), listener, PR_TRUE);
-    target->RemoveEventListener(NS_LITERAL_STRING("dragdrop"), listener, PR_TRUE);
-    target->RemoveEventListener(NS_LITERAL_STRING("drag"), listener, PR_TRUE);
-    target->RemoveEventListener(NS_LITERAL_STRING("dragenter"), listener, PR_TRUE);
-    target->RemoveEventListener(NS_LITERAL_STRING("dragover"), listener, PR_TRUE);
-    target->RemoveEventListener(NS_LITERAL_STRING("dragexit"), listener, PR_TRUE);
-    target->RemoveEventListener(NS_LITERAL_STRING("dragleave"), listener, PR_TRUE);
-    target->RemoveEventListener(NS_LITERAL_STRING("dragstart"), listener, PR_TRUE);
-    target->RemoveEventListener(NS_LITERAL_STRING("draggesture"), listener, PR_TRUE);
-    target->RemoveEventListener(NS_LITERAL_STRING("dragend"), listener, PR_TRUE);
-  }
+  mContent->RemoveEventListener(NS_LITERAL_STRING("focus"), this, PR_FALSE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("blur"), this, PR_FALSE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("mouseup"), this, PR_FALSE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("mousedown"), this, PR_FALSE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("mousemove"), this, PR_FALSE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("click"), this, PR_FALSE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("dblclick"), this, PR_FALSE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("mouseover"), this, PR_FALSE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("mouseout"), this, PR_FALSE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("keypress"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("keydown"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("keyup"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("drop"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("dragdrop"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("drag"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("dragenter"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("dragover"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("dragleave"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("dragexit"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("dragstart"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("draggesture"), this, PR_TRUE);
+  mContent->RemoveEventListener(NS_LITERAL_STRING("dragend"), this, PR_TRUE);
 
   if (mWidget) {
     nsCOMPtr<nsIPluginWidget> pluginWidget = do_QueryInterface(mWidget);
     if (pluginWidget)
       pluginWidget->SetPluginInstanceOwner(nsnull);
 
     if (mDestroyWidget)
       mWidget->Destroy();
@@ -2962,48 +2885,47 @@ nsresult nsPluginInstanceOwner::Init(nsP
   }
 
   // register context menu listener
   mCXMenuListener = new nsPluginDOMContextMenuListener();
   if (mCXMenuListener) {    
     mCXMenuListener->Init(aContent);
   }
 
-  nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mContent));
-  if (target) {
-
-    nsCOMPtr<nsIDOMEventListener> listener;
-    QueryInterface(NS_GET_IID(nsIDOMEventListener), getter_AddRefs(listener));
-
-    // Register focus listener
-    mContent->AddEventListenerByIID(listener, NS_GET_IID(nsIDOMFocusListener));
-
-    // Register mouse listener
-    mContent->AddEventListenerByIID(listener, NS_GET_IID(nsIDOMMouseListener));
-
-    // now do the mouse motion listener
-    mContent->AddEventListenerByIID(listener, NS_GET_IID(nsIDOMMouseMotionListener));
-
-    // Register key listener
-    target->AddEventListener(NS_LITERAL_STRING("keypress"), listener, PR_TRUE);
-    target->AddEventListener(NS_LITERAL_STRING("keydown"), listener, PR_TRUE);
-    target->AddEventListener(NS_LITERAL_STRING("keyup"), listener, PR_TRUE);
-
-    // Register drag listener
-    target->AddEventListener(NS_LITERAL_STRING("drop"), listener, PR_TRUE);
-    target->AddEventListener(NS_LITERAL_STRING("dragdrop"), listener, PR_TRUE);
-    target->AddEventListener(NS_LITERAL_STRING("drag"), listener, PR_TRUE);
-    target->AddEventListener(NS_LITERAL_STRING("dragenter"), listener, PR_TRUE);
-    target->AddEventListener(NS_LITERAL_STRING("dragover"), listener, PR_TRUE);
-    target->AddEventListener(NS_LITERAL_STRING("dragleave"), listener, PR_TRUE);
-    target->AddEventListener(NS_LITERAL_STRING("dragexit"), listener, PR_TRUE);
-    target->AddEventListener(NS_LITERAL_STRING("dragstart"), listener, PR_TRUE);
-    target->AddEventListener(NS_LITERAL_STRING("draggesture"), listener, PR_TRUE);
-    target->AddEventListener(NS_LITERAL_STRING("dragend"), listener, PR_TRUE);
-  }
+  mContent->AddEventListener(NS_LITERAL_STRING("focus"), this, PR_FALSE,
+                             PR_FALSE);
+  mContent->AddEventListener(NS_LITERAL_STRING("blur"), this, PR_FALSE,
+                             PR_FALSE);
+  mContent->AddEventListener(NS_LITERAL_STRING("mouseup"), this, PR_FALSE,
+                             PR_FALSE);
+  mContent->AddEventListener(NS_LITERAL_STRING("mousedown"), this, PR_FALSE,
+                             PR_FALSE);
+  mContent->AddEventListener(NS_LITERAL_STRING("mousemove"), this, PR_FALSE,
+                             PR_FALSE);
+  mContent->AddEventListener(NS_LITERAL_STRING("click"), this, PR_FALSE,
+                             PR_FALSE);
+  mContent->AddEventListener(NS_LITERAL_STRING("dblclick"), this, PR_FALSE,
+                             PR_FALSE);
+  mContent->AddEventListener(NS_LITERAL_STRING("mouseover"), this, PR_FALSE,
+                             PR_FALSE);
+  mContent->AddEventListener(NS_LITERAL_STRING("mouseout"), this, PR_FALSE,
+                             PR_FALSE);
+  mContent->AddEventListener(NS_LITERAL_STRING("keypress"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("keydown"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("keyup"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("drop"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("dragdrop"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("drag"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("dragenter"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("dragover"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("dragleave"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("dragexit"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("dragstart"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("draggesture"), this, PR_TRUE);
+  mContent->AddEventListener(NS_LITERAL_STRING("dragend"), this, PR_TRUE);
   
   // Register scroll position listeners
   // We need to register a scroll position listener on every scrollable
   // frame up to the top
   for (nsIFrame* f = mObjectFrame; f; f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
     nsIScrollableFrame* sf = do_QueryFrame(f);
     if (sf) {
       sf->AddScrollPositionListener(this);
--- a/dom/plugins/base/nsPluginInstanceOwner.h
+++ b/dom/plugins/base/nsPluginInstanceOwner.h
@@ -47,25 +47,27 @@
 #ifndef nsPluginInstanceOwner_h_
 #define nsPluginInstanceOwner_h_
 
 #include "prtypes.h"
 #include "npapi.h"
 #include "nsCOMPtr.h"
 #include "nsIPluginInstanceOwner.h"
 #include "nsIPluginTagInfo.h"
-#include "nsIDOMMouseListener.h"
-#include "nsIDOMMouseMotionListener.h"
-#include "nsIDOMKeyListener.h"
-#include "nsIDOMFocusListener.h"
+#include "nsIDOMEventListener.h"
 #include "nsIScrollPositionListener.h"
 #include "nsPluginHost.h"
 #include "nsPluginNativeWindow.h"
 #include "gfxRect.h"
 
+// X.h defines KeyPress
+#ifdef KeyPress
+#undef KeyPress
+#endif
+
 #ifdef XP_MACOSX
 #include "nsCoreAnimationSupport.h"
 #include <ApplicationServices/ApplicationServices.h>
 #endif
 
 class nsIInputStream;
 class nsIntRect;
 class nsPluginDOMContextMenuListener;
@@ -85,22 +87,24 @@ class gfxXlibSurface;
 #endif
 
 #ifdef XP_OS2
 #define INCL_PM
 #define INCL_GPI
 #include <os2.h>
 #endif
 
+// X.h defines KeyPress
+#ifdef KeyPress
+#undef KeyPress
+#endif
+
 class nsPluginInstanceOwner : public nsIPluginInstanceOwner,
                               public nsIPluginTagInfo,
-                              public nsIDOMMouseListener,
-                              public nsIDOMMouseMotionListener,
-                              public nsIDOMKeyListener,
-                              public nsIDOMFocusListener,
+                              public nsIDOMEventListener,
                               public nsIScrollPositionListener
 {
 public:
   nsPluginInstanceOwner();
   virtual ~nsPluginInstanceOwner();
   
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPLUGININSTANCEOWNER
@@ -114,38 +118,22 @@ public:
   NPError    ShowNativeContextMenu(NPMenu* menu, void* event);
   
   NPBool     ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
                           double *destX, double *destY, NPCoordinateSpace destSpace);
   
   //nsIPluginTagInfo interface
   NS_DECL_NSIPLUGINTAGINFO
   
-  // nsIDOMMouseListener interfaces 
-  NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
-  NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
-  NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent);
-  NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent);
-  NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent);
-  NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent);
-  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);     
+  // nsIDOMEventListener interfaces 
+  NS_DECL_NSIDOMEVENTLISTENER
   
-  // nsIDOMMouseMotionListener interfaces
-  NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent);
-  NS_IMETHOD DragMove(nsIDOMEvent* aMouseEvent) { return NS_OK; }
-  
-  // nsIDOMKeyListener interfaces
-  NS_IMETHOD KeyDown(nsIDOMEvent* aKeyEvent);
-  NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent);
-  NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent);
-  
-  // nsIDOMFocusListener interfaces
-  NS_IMETHOD Focus(nsIDOMEvent * aFocusEvent);
-  NS_IMETHOD Blur(nsIDOMEvent * aFocusEvent);
-  
+  nsresult MouseDown(nsIDOMEvent* aKeyEvent);
+  nsresult KeyPress(nsIDOMEvent* aKeyEvent);
+
   nsresult Destroy();  
   
   void PrepareToStop(PRBool aDelayedStop);
   
 #ifdef XP_WIN
   void Paint(const RECT& aDirty, HDC aDC);
 #elif defined(XP_MACOSX)
   void Paint(const gfxRect& aDirtyRect, CGContextRef cgContext);  
--- a/toolkit/components/satchel/nsFormFillController.h
+++ b/toolkit/components/satchel/nsFormFillController.h
@@ -50,16 +50,21 @@
 #include "nsISupportsArray.h"
 #include "nsDataHashtable.h"
 #include "nsIDocShell.h"
 #include "nsIDOMWindow.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsILoginManager.h"
 #include "nsIMutationObserver.h"
 
+// X.h defines KeyPress
+#ifdef KeyPress
+#undef KeyPress
+#endif
+
 class nsFormHistory;
 
 class nsFormFillController : public nsIFormFillController,
                              public nsIAutoCompleteInput,
                              public nsIAutoCompleteSearch,
                              public nsIDOMEventListener,
                              public nsIMutationObserver
 {