Bug 663461 Part 2: Remove Add/RemoveEventListenerByIID from embedding. r=smaug
authorJonas Sicking <jonas@sicking.cc>
Tue, 28 Jun 2011 08:12:42 -0700
changeset 71915 ec503528d2ef5caed7549d3eb82f0c19f619f5ef
parent 71914 ab2e92a211e18c10925cfd0dc2bfbd00bf3322de
child 71916 5af231e7a58b14572180c9c3e18fa57d09357716
push id287
push usersicking@mozilla.com
push dateTue, 28 Jun 2011 15:13:01 +0000
treeherdermozilla-inbound@ec503528d2ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs663461
milestone7.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 663461 Part 2: Remove Add/RemoveEventListenerByIID from embedding. r=smaug
embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
embedding/browser/webBrowser/nsDocShellTreeOwner.h
--- a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
+++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
@@ -1181,27 +1181,17 @@ DefaultTooltipTextProvider::GetNodeText(
   *_retval = found;
   *aText = (found) ? ToNewUnicode(outText) : nsnull;
 
   return NS_OK;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
-NS_IMPL_ADDREF(ChromeTooltipListener)
-NS_IMPL_RELEASE(ChromeTooltipListener)
-
-NS_INTERFACE_MAP_BEGIN(ChromeTooltipListener)
-    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMouseListener)
-    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMMouseListener)
-    NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener)
-    NS_INTERFACE_MAP_ENTRY(nsIDOMMouseMotionListener)
-    NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener)
-NS_INTERFACE_MAP_END
-
+NS_IMPL_ISUPPORTS1(ChromeTooltipListener, nsIDOMEventListener)
 
 //
 // ChromeTooltipListener ctor
 //
 
 ChromeTooltipListener::ChromeTooltipListener(nsWebBrowser* inBrowser,
                                              nsIWebBrowserChrome* inChrome) 
   : mWebBrowser(inBrowser), mWebBrowserChrome(inChrome),
@@ -1259,24 +1249,30 @@ ChromeTooltipListener::AddChromeListener
 // Subscribe to the events that will allow us to track tooltips. We need "mouse" for mouseExit,
 // "mouse motion" for mouseMove, and "key" for keyDown. As we add the listeners, keep track
 // of how many succeed so we can clean up correctly in Release().
 //
 NS_IMETHODIMP
 ChromeTooltipListener::AddTooltipListener()
 {
   if (mEventTarget) {
-    nsIDOMMouseListener *pListener = static_cast<nsIDOMMouseListener *>(this);
-    nsresult rv = mEventTarget->AddEventListenerByIID(pListener, NS_GET_IID(nsIDOMMouseListener));
-    nsresult rv2 = mEventTarget->AddEventListenerByIID(pListener, NS_GET_IID(nsIDOMMouseMotionListener));
-    nsresult rv3 = mEventTarget->AddEventListenerByIID(pListener, NS_GET_IID(nsIDOMKeyListener));
-    
-    // if all 3 succeed, we're a go!
-    if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(rv2) && NS_SUCCEEDED(rv3)) 
-      mTooltipListenerInstalled = PR_TRUE;
+    nsresult rv = mEventTarget->AddEventListener(NS_LITERAL_STRING("keydown"),
+                                                 this, PR_FALSE, PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = mEventTarget->AddEventListener(NS_LITERAL_STRING("mousedown"), this,
+                                        PR_FALSE, PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = mEventTarget->AddEventListener(NS_LITERAL_STRING("mouseout"), this,
+                                        PR_FALSE, PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = mEventTarget->AddEventListener(NS_LITERAL_STRING("mousemove"), this,
+                                        PR_FALSE, PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    mTooltipListenerInstalled = PR_TRUE;
   }
 
   return NS_OK;
 }
 
 
 //
 // RemoveChromeListeners
@@ -1304,112 +1300,53 @@ ChromeTooltipListener::RemoveChromeListe
 // RemoveTooltipListener
 //
 // Unsubscribe from all the various tooltip events that we were listening to
 //
 NS_IMETHODIMP 
 ChromeTooltipListener::RemoveTooltipListener()
 {
   if (mEventTarget) {
-    nsIDOMMouseListener *pListener = static_cast<nsIDOMMouseListener *>(this);
-    nsresult rv = mEventTarget->RemoveEventListenerByIID(pListener, NS_GET_IID(nsIDOMMouseListener));
-    nsresult rv2 = mEventTarget->RemoveEventListenerByIID(pListener, NS_GET_IID(nsIDOMMouseMotionListener));
-    nsresult rv3 = mEventTarget->RemoveEventListenerByIID(pListener, NS_GET_IID(nsIDOMKeyListener));
-    if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(rv2) && NS_SUCCEEDED(rv3))
-      mTooltipListenerInstalled = PR_FALSE;
+    nsresult rv =
+      mEventTarget->RemoveEventListener(NS_LITERAL_STRING("keydown"), this,
+                                        PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = mEventTarget->RemoveEventListener(NS_LITERAL_STRING("mousedown"),
+                                           this, PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = mEventTarget->RemoveEventListener(NS_LITERAL_STRING("mouseout"), this,
+                                           PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = mEventTarget->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
+                                           this, PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    mTooltipListenerInstalled = PR_FALSE;
   }
 
   return NS_OK;
 }
 
-
-//
-// KeyDown
-//
-// When the user starts typing, they generaly don't want to see any messy wax
-// builup. Hide the tooltip.
-//
-nsresult
-ChromeTooltipListener::KeyDown(nsIDOMEvent* aMouseEvent)
+NS_IMETHODIMP
+ChromeTooltipListener::HandleEvent(nsIDOMEvent* aEvent)
 {
-  return HideTooltip();
-} // KeyDown
-
-
-//
-// KeyUp
-// KeyPress
-//
-// We can ignore these as they are already handled by KeyDown
-//
-nsresult
-ChromeTooltipListener::KeyUp(nsIDOMEvent* aMouseEvent)
-{
-  return NS_OK;
-    
-} // KeyUp
-
-nsresult
-ChromeTooltipListener::KeyPress(nsIDOMEvent* aMouseEvent)
-{
-  return NS_OK;
-    
-} // KeyPress
-
+  nsAutoString eventType;
+  aEvent->GetType(eventType);
 
-//
-// MouseDown
-//
-// On a click, hide the tooltip
-//
-nsresult 
-ChromeTooltipListener::MouseDown(nsIDOMEvent* aMouseEvent)
-{
-  return HideTooltip();
-
-} // MouseDown
-
-
-nsresult 
-ChromeTooltipListener::MouseUp(nsIDOMEvent* aMouseEvent)
-{
-    return NS_OK; 
-}
-
-nsresult 
-ChromeTooltipListener::MouseClick(nsIDOMEvent* aMouseEvent)
-{
-    return NS_OK; 
-}
+  if (eventType.EqualsLiteral("keydown") ||
+      eventType.EqualsLiteral("mousedown") ||
+      eventType.EqualsLiteral("mouseout"))
+    return HideTooltip();
+  if (eventType.EqualsLiteral("mousemove"))
+    return MouseMove(aEvent);
 
-nsresult 
-ChromeTooltipListener::MouseDblClick(nsIDOMEvent* aMouseEvent)
-{
-    return NS_OK; 
-}
-
-nsresult 
-ChromeTooltipListener::MouseOver(nsIDOMEvent* aMouseEvent)
-{
-    return NS_OK; 
+  NS_ERROR("Unexpected event type");
+  return NS_OK;
 }
 
-
-//
-// MouseOut
-//
-// If we're responding to tooltips, hide the tip whenever the mouse leaves
-// the area it was in.
-nsresult 
-ChromeTooltipListener::MouseOut(nsIDOMEvent* aMouseEvent)
-{
-  return HideTooltip();
-}
-
-
 //
 // MouseMove
 //
 // If we're a tooltip, fire off a timer to see if a tooltip should be shown. If the
 // timer fires, we cache the node in |mPossibleTooltipNode|.
 //
 nsresult
 ChromeTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent)
@@ -1636,24 +1573,17 @@ ChromeTooltipListener::sAutoHideCallback
   if ( self )
     self->HideTooltip();
 
   // NOTE: |aTimer| and |self->mAutoHideTimer| are invalid after calling ClosePopup();
   
 } // sAutoHideCallback
 
 
-NS_IMPL_ADDREF(ChromeContextMenuListener)
-NS_IMPL_RELEASE(ChromeContextMenuListener)
-
-NS_INTERFACE_MAP_BEGIN(ChromeContextMenuListener)
-    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMContextMenuListener)
-    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMContextMenuListener)
-    NS_INTERFACE_MAP_ENTRY(nsIDOMContextMenuListener)
-NS_INTERFACE_MAP_END
+NS_IMPL_ISUPPORTS1(ChromeContextMenuListener, nsIDOMEventListener)
 
 
 //
 // ChromeTooltipListener ctor
 //
 ChromeContextMenuListener::ChromeContextMenuListener(nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) 
   : mContextMenuListenerInstalled(PR_FALSE),
     mWebBrowser(inBrowser),
@@ -1675,39 +1605,43 @@ ChromeContextMenuListener::~ChromeContex
 //
 // Subscribe to the events that will allow us to track context menus. Bascially, this
 // is just the context-menu DOM event.
 //
 NS_IMETHODIMP
 ChromeContextMenuListener::AddContextMenuListener()
 {
   if (mEventTarget) {
-    nsIDOMContextMenuListener *pListener = static_cast<nsIDOMContextMenuListener *>(this);
-    nsresult rv = mEventTarget->AddEventListenerByIID(pListener, NS_GET_IID(nsIDOMContextMenuListener));
-    if (NS_SUCCEEDED(rv))
-      mContextMenuListenerInstalled = PR_TRUE;
+    nsresult rv =
+      mEventTarget->AddEventListener(NS_LITERAL_STRING("contextmenu"), this,
+                                     PR_FALSE, PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    mContextMenuListenerInstalled = PR_TRUE;
   }
 
   return NS_OK;
 }
 
 
 //
 // RemoveContextMenuListener
 //
 // Unsubscribe from all the various context menu events that we were listening to. 
 //
 NS_IMETHODIMP 
 ChromeContextMenuListener::RemoveContextMenuListener()
 {
   if (mEventTarget) {
-    nsIDOMContextMenuListener *pListener = static_cast<nsIDOMContextMenuListener *>(this);
-    nsresult rv = mEventTarget->RemoveEventListenerByIID(pListener, NS_GET_IID(nsIDOMContextMenuListener));
-    if (NS_SUCCEEDED(rv))
-      mContextMenuListenerInstalled = PR_FALSE;
+    nsresult rv =
+      mEventTarget->RemoveEventListener(NS_LITERAL_STRING("contextmenu"), this,
+                                        PR_FALSE);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    mContextMenuListenerInstalled = PR_FALSE;
   }
 
   return NS_OK;
 }
 
 
 //
 // AddChromeListeners
@@ -1758,18 +1692,21 @@ ChromeContextMenuListener::RemoveChromeL
 //
 // ContextMenu
 //
 // We're on call to show the context menu. Dig around in the DOM to
 // find the type of object we're dealing with and notify the front
 // end chrome.
 //
 NS_IMETHODIMP
-ChromeContextMenuListener::ContextMenu(nsIDOMEvent* aMouseEvent)
-{     
+ChromeContextMenuListener::HandleEvent(nsIDOMEvent* aMouseEvent)
+{
+  nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
+  NS_ENSURE_TRUE(mouseEvent, NS_ERROR_UNEXPECTED);
+
   nsCOMPtr<nsIDOMNSUIEvent> uievent(do_QueryInterface(aMouseEvent));
 
   if (uievent) {
     PRBool isDefaultPrevented = PR_FALSE;
     uievent->GetPreventDefault(&isDefaultPrevented);
 
     if (isDefaultPrevented) {
       return NS_OK;
--- a/embedding/browser/webBrowser/nsDocShellTreeOwner.h
+++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.h
@@ -45,24 +45,21 @@
 #include "nsString.h"
 
 // Interfaces Needed
 #include "nsIBaseWindow.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIWebBrowserChrome.h"
-#include "nsIDOMMouseListener.h"
+#include "nsIDOMEventListener.h"
 #include "nsIDOMDocument.h"
 #include "nsIEmbeddingSiteWindow.h"
 #include "nsIWebProgressListener.h"
 #include "nsWeakReference.h"
-#include "nsIDOMKeyListener.h"
-#include "nsIDOMMouseMotionListener.h"
-#include "nsIDOMContextMenuListener.h"
 #include "nsITimer.h"
 #include "nsIPrompt.h"
 #include "nsIAuthPrompt.h"
 #include "nsITooltipListener.h"
 #include "nsITooltipTextProvider.h"
 #include "nsCTooltipTextProvider.h"
 #include "nsIDroppedLinkHandler.h"
 #include "nsIDOMEventTarget.h"
@@ -171,43 +168,26 @@ protected:
 //
 // class ChromeTooltipListener
 //
 // The class that listens to the chrome events and tells the embedding
 // chrome to show tooltips, as appropriate. Handles registering itself
 // with the DOM with AddChromeListeners() and removing itself with
 // RemoveChromeListeners().
 //
-class ChromeTooltipListener : public nsIDOMMouseListener,
-                                public nsIDOMKeyListener,
-                                public nsIDOMMouseMotionListener
+class ChromeTooltipListener : public nsIDOMEventListener
 {
 public:
   NS_DECL_ISUPPORTS
   
   ChromeTooltipListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ;
   virtual ~ChromeTooltipListener ( ) ;
 
-    // nsIDOMMouseListener
-  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) {	return NS_OK; }
-  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);
-
-    // nsIDOMMouseMotionListener
+  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
   NS_IMETHOD MouseMove(nsIDOMEvent* aMouseEvent);
-  NS_IMETHOD DragMove(nsIDOMEvent* aMouseEvent) { return NS_OK; }
-
-    // nsIDOMKeyListener
-  NS_IMETHOD KeyDown(nsIDOMEvent* aKeyEvent) ;
-  NS_IMETHOD KeyUp(nsIDOMEvent* aKeyEvent) ;
-  NS_IMETHOD KeyPress(nsIDOMEvent* aKeyEvent) ;
 
     // Add/remove the relevant listeners, based on what interfaces
     // the embedding chrome implements.
   NS_IMETHOD AddChromeListeners();
   NS_IMETHOD RemoveChromeListeners();
 
 private:
 
@@ -261,27 +241,26 @@ private:
 //
 // class ChromeContextMenuListener
 //
 // The class that listens to the chrome events and tells the embedding
 // chrome to show context menus, as appropriate. Handles registering itself
 // with the DOM with AddChromeListeners() and removing itself with
 // RemoveChromeListeners().
 //
-class ChromeContextMenuListener : public nsIDOMContextMenuListener
+class ChromeContextMenuListener : public nsIDOMEventListener
 {
 public:
   NS_DECL_ISUPPORTS
   
   ChromeContextMenuListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome ) ;
   virtual ~ChromeContextMenuListener ( ) ;
 
   // nsIDOMContextMenuListener
-  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) {	return NS_OK; }
-  NS_IMETHOD ContextMenu ( nsIDOMEvent* aEvent );
+  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
 
   // Add/remove the relevant listeners, based on what interfaces
   // the embedding chrome implements.
   NS_IMETHOD AddChromeListeners();
   NS_IMETHOD RemoveChromeListeners();
 
 private: