Bug 664058: Remove Add/RemoveEventListenerByIID from nsImageMap and nsSliderFrame. r=smaug
authorJonas Sicking <jonas@sicking.cc>
Tue, 28 Jun 2011 10:59:14 -0700
changeset 72433 49d9e0f08eb5313ddfa88b5c17d29d9f04d4df40
parent 72432 d173bf22c9bb311c6e1f49b6a34f5d47899f0890
child 72434 2bf9296c7bd013ccafa374e17989786baa920a0e
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs664058
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 664058: Remove Add/RemoveEventListenerByIID from nsImageMap and nsSliderFrame. r=smaug
content/base/public/nsINode.h
layout/generic/nsImageMap.cpp
layout/generic/nsImageMap.h
layout/xul/base/src/nsSliderFrame.cpp
layout/xul/base/src/nsSliderFrame.h
--- a/content/base/public/nsINode.h
+++ b/content/base/public/nsINode.h
@@ -703,16 +703,17 @@ public:
   {
     return mParent;
   }
 
   /**
    * See nsIDOMEventTarget
    */
   NS_DECL_NSIDOMEVENTTARGET
+  using nsIDOMEventTarget::AddEventListener;
 
   /**
    * Adds a mutation observer to be notified when this node, or any of its
    * descendants, are modified. The node will hold a weak reference to the
    * observer, which means that it is the responsibility of the observer to
    * remove itself in case it dies before the node.  If an observer is added
    * while observers are being notified, it may also be notified.  In general,
    * adding observers while inside a notification is not a good idea.  An
--- a/layout/generic/nsImageMap.cpp
+++ b/layout/generic/nsImageMap.cpp
@@ -698,19 +698,18 @@ nsImageMap::nsImageMap() :
 {
 }
 
 nsImageMap::~nsImageMap()
 {
   NS_ASSERTION(mAreas.Length() == 0, "Destroy was not called");
 }
 
-NS_IMPL_ISUPPORTS3(nsImageMap,
+NS_IMPL_ISUPPORTS2(nsImageMap,
                    nsIMutationObserver,
-                   nsIDOMFocusListener,
                    nsIDOMEventListener)
 
 nsresult
 nsImageMap::GetBoundsForAreaContent(nsIContent *aContent,
                                     nsRect& aBounds)
 {
   NS_ENSURE_TRUE(aContent, NS_ERROR_INVALID_ARG);
 
@@ -735,17 +734,20 @@ nsImageMap::FreeAreas()
 {
   PRUint32 i, n = mAreas.Length();
   for (i = 0; i < n; i++) {
     Area* area = mAreas.ElementAt(i);
     NS_ASSERTION(area->mArea->GetPrimaryFrame() == mImageFrame,
                  "Unexpected primary frame");
     area->mArea->SetPrimaryFrame(nsnull);
 
-    area->mArea->RemoveEventListenerByIID(this, NS_GET_IID(nsIDOMFocusListener));
+    area->mArea->RemoveEventListener(NS_LITERAL_STRING("focus"), this,
+                                     PR_FALSE);
+    area->mArea->RemoveEventListener(NS_LITERAL_STRING("blur"), this,
+                                     PR_FALSE);
     delete area;
   }
   mAreas.Clear();
 }
 
 nsresult
 nsImageMap::Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIContent* aMap)
 {
@@ -854,17 +856,20 @@ nsImageMap::AddArea(nsIContent* aArea)
   default:
     NS_NOTREACHED("FindAttrValueIn returned an unexpected value.");
     break;
   }
   if (!area)
     return NS_ERROR_OUT_OF_MEMORY;
 
   //Add focus listener to track area focus changes
-  aArea->AddEventListenerByIID(this, NS_GET_IID(nsIDOMFocusListener));
+  aArea->AddEventListener(NS_LITERAL_STRING("focus"), this, PR_FALSE,
+                          PR_FALSE);
+  aArea->AddEventListener(NS_LITERAL_STRING("blur"), this, PR_FALSE,
+                          PR_FALSE);
 
   // This is a nasty hack.  It needs to go away: see bug 135040.  Once this is
   // removed, the code added to nsCSSFrameConstructor::RestyleElement,
   // nsCSSFrameConstructor::ContentRemoved (both hacks there), and
   // nsCSSFrameConstructor::ProcessRestyledFrames to work around this issue can
   // be removed.
   aArea->SetPrimaryFrame(mImageFrame);
 
@@ -956,60 +961,48 @@ nsImageMap::ContentRemoved(nsIDocument *
                            nsIContent* aChild,
                            PRInt32 aIndexInContainer,
                            nsIContent* aPreviousSibling)
 {
   MaybeUpdateAreas(aContainer);
 }
 
 nsresult
-nsImageMap::Focus(nsIDOMEvent* aEvent)
+nsImageMap::HandleEvent(nsIDOMEvent* aEvent)
 {
-  return ChangeFocus(aEvent, PR_TRUE);
-}
+  nsAutoString eventType;
+  aEvent->GetType(eventType);
+  PRBool focus = eventType.EqualsLiteral("focus");
+  NS_ABORT_IF_FALSE(focus == !eventType.EqualsLiteral("blur"),
+                    "Unexpected event type");
 
-nsresult
-nsImageMap::Blur(nsIDOMEvent* aEvent)
-{
-  return ChangeFocus(aEvent, PR_FALSE);
-}
-
-nsresult
-nsImageMap::ChangeFocus(nsIDOMEvent* aEvent, PRBool aFocus)
-{
   //Set which one of our areas changed focus
   nsCOMPtr<nsIDOMEventTarget> target;
   if (NS_SUCCEEDED(aEvent->GetTarget(getter_AddRefs(target))) && target) {
     nsCOMPtr<nsIContent> targetContent(do_QueryInterface(target));
     if (targetContent) {
       PRUint32 i, n = mAreas.Length();
       for (i = 0; i < n; i++) {
         Area* area = mAreas.ElementAt(i);
         if (area->mArea == targetContent) {
           //Set or Remove internal focus
-          area->HasFocus(aFocus);
+          area->HasFocus(focus);
           //Now invalidate the rect
           nsIFrame* imgFrame = targetContent->GetPrimaryFrame();
           if (imgFrame) {
             nsRect dmgRect;
             area->GetRect(imgFrame, dmgRect);
             imgFrame->Invalidate(dmgRect);
           }
           break;
         }
       }
     }
   }
   return NS_OK;
 }
 
-nsresult
-nsImageMap::HandleEvent(nsIDOMEvent* aEvent)
-{
-  return NS_OK;
-}
-
 void
 nsImageMap::Destroy(void)
 {
   FreeAreas();
   mMap->RemoveMutationObserver(this);
 }
--- a/layout/generic/nsImageMap.h
+++ b/layout/generic/nsImageMap.h
@@ -39,24 +39,25 @@
 
 #ifndef nsImageMap_h
 #define nsImageMap_h
 
 #include "nsISupports.h"
 #include "nsCoord.h"
 #include "nsTArray.h"
 #include "nsStubMutationObserver.h"
-#include "nsIDOMFocusListener.h"
+#include "nsIDOMEventListener.h"
 #include "nsIFrame.h"
 
 class Area;
 class nsIDOMEvent;
 class nsRenderingContext;
 
-class nsImageMap : public nsStubMutationObserver, public nsIDOMFocusListener
+class nsImageMap : public nsStubMutationObserver,
+                   public nsIDOMEventListener
 {
 public:
   nsImageMap();
 
   nsresult Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIContent* aMap);
 
   /**
    * See if the given aX,aY <b>pixel</b> coordinates are in the image
@@ -79,37 +80,33 @@ public:
   NS_DECL_ISUPPORTS
 
   // nsIMutationObserver
   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
 
-  //nsIDOMFocusListener
-  NS_IMETHOD Focus(nsIDOMEvent* aEvent);
-  NS_IMETHOD Blur(nsIDOMEvent* aEvent);
-  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
+  //nsIDOMEventListener
+  NS_DECL_NSIDOMEVENTLISTENER
 
   nsresult GetBoundsForAreaContent(nsIContent *aContent,
                                    nsRect& aBounds);
 
 protected:
   virtual ~nsImageMap();
 
   void FreeAreas();
 
   nsresult UpdateAreas();
   nsresult SearchForAreas(nsIContent* aParent, PRBool& aFoundArea,
                           PRBool& aFoundAnchor);
 
   nsresult AddArea(nsIContent* aArea);
  
-  nsresult ChangeFocus(nsIDOMEvent* aEvent, PRBool aFocus);
-
   void MaybeUpdateAreas(nsIContent *aContent);
 
   nsIPresShell* mPresShell; // WEAK - owns the frame that owns us
   nsIFrame* mImageFrame;  // the frame that owns us
   nsCOMPtr<nsIContent> mMap;
   nsAutoTArray<Area*, 8> mAreas; // almost always has some entries
   PRBool mContainsBlockContents;
 };
--- a/layout/xul/base/src/nsSliderFrame.cpp
+++ b/layout/xul/base/src/nsSliderFrame.cpp
@@ -854,47 +854,40 @@ nsSliderFrame::SetInitialChildList(nsIAt
   nsresult r = nsBoxFrame::SetInitialChildList(aListName, aChildList);
 
   AddListener();
 
   return r;
 }
 
 nsresult
-nsSliderMediator::MouseDown(nsIDOMEvent* aMouseEvent)
+nsSliderMediator::HandleEvent(nsIDOMEvent* aEvent)
 {
   // Only process the event if the thumb is not being dragged.
   if (mSlider && !mSlider->isDraggingThumb())
-    return mSlider->MouseDown(aMouseEvent);
-
-  return NS_OK;
-}
-
-nsresult
-nsSliderMediator::MouseUp(nsIDOMEvent* aMouseEvent)
-{
-  // Only process the event if the thumb is not being dragged.
-  if (mSlider && !mSlider->isDraggingThumb())
-    return mSlider->MouseUp(aMouseEvent);
+    return mSlider->MouseDown(aEvent);
 
   return NS_OK;
 }
 
 nsresult
 nsSliderFrame::MouseDown(nsIDOMEvent* aMouseEvent)
 {
 #ifdef DEBUG_SLIDER
   printf("Begin dragging\n");
 #endif
 
+  nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aMouseEvent));
+  if (!mouseEvent)
+    return NS_OK;
+
   if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
                             nsGkAtoms::_true, eCaseMatters))
     return NS_OK;
 
-  nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aMouseEvent));
   PRUint16 button = 0;
   mouseEvent->GetButton(&button);
   if (!(button == 0 || (button == 1 && gMiddlePref)))
     return NS_OK;
 
   PRBool isHorizontal = IsHorizontal();
 
   PRBool scrollToClick = PR_FALSE;
@@ -950,26 +943,16 @@ nsSliderFrame::MouseDown(nsIDOMEvent* aM
 
 #ifdef DEBUG_SLIDER
   printf("Pressed mDragStart=%d\n",mDragStart);
 #endif
 
   return NS_OK;
 }
 
-nsresult
-nsSliderFrame::MouseUp(nsIDOMEvent* aMouseEvent)
-{
-#ifdef DEBUG_SLIDER
-  printf("Finish dragging\n");
-#endif
-
-  return NS_OK;
-}
-
 void
 nsSliderFrame::DragThumb(PRBool aGrabMouseEvents)
 {
   // inform the parent <scale> that a drag is beginning or ending
   nsIFrame* parent = GetParent();
   if (parent) {
     nsCOMPtr<nsISliderListener> sliderListener = do_QueryInterface(parent->GetContent());
     if (sliderListener) {
@@ -993,31 +976,32 @@ nsSliderFrame::AddListener()
 {
   if (!mMediator) {
     mMediator = new nsSliderMediator(this);
   }
 
   nsIFrame* thumbFrame = mFrames.FirstChild();
   if (thumbFrame) {
     thumbFrame->GetContent()->
-      AddEventListenerByIID(mMediator, NS_GET_IID(nsIDOMMouseListener));
+      AddEventListener(NS_LITERAL_STRING("mousedown"), mMediator, PR_FALSE,
+                       PR_FALSE);
   }
 }
 
 void
 nsSliderFrame::RemoveListener()
 {
   NS_ASSERTION(mMediator, "No listener was ever added!!");
 
   nsIFrame* thumbFrame = mFrames.FirstChild();
   if (!thumbFrame)
     return;
 
   thumbFrame->GetContent()->
-    RemoveEventListenerByIID(mMediator, NS_GET_IID(nsIDOMMouseListener));
+    RemoveEventListener(NS_LITERAL_STRING("mousedown"), mMediator, PR_FALSE);
 }
 
 NS_IMETHODIMP
 nsSliderFrame::HandlePress(nsPresContext* aPresContext,
                            nsGUIEvent*     aEvent,
                            nsEventStatus*  aEventStatus)
 {
 #ifdef XP_MACOSX
@@ -1149,11 +1133,10 @@ void nsSliderFrame::Notify(void)
 
     if (stop) {
       StopRepeat();
     } else {
       PageUpDown(mChange);
     }
 }
 
-NS_IMPL_ISUPPORTS2(nsSliderMediator,
-                   nsIDOMMouseListener,
+NS_IMPL_ISUPPORTS1(nsSliderMediator,
                    nsIDOMEventListener)
--- a/layout/xul/base/src/nsSliderFrame.h
+++ b/layout/xul/base/src/nsSliderFrame.h
@@ -39,82 +39,38 @@
 #define nsSliderFrame_h__
 
 #include "nsRepeatService.h"
 #include "nsBoxFrame.h"
 #include "prtypes.h"
 #include "nsIAtom.h"
 #include "nsCOMPtr.h"
 #include "nsITimer.h"
-#include "nsIDOMMouseListener.h"
+#include "nsIDOMEventListener.h"
 
 class nsString;
 class nsITimer;
 class nsSliderFrame;
 
 nsIFrame* NS_NewSliderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
-class nsSliderMediator : public nsIDOMMouseListener
+class nsSliderMediator : public nsIDOMEventListener
 {
 public:
 
   NS_DECL_ISUPPORTS
 
   nsSliderFrame* mSlider;
 
   nsSliderMediator(nsSliderFrame* aSlider) {  mSlider = aSlider; }
   virtual ~nsSliderMediator() {}
 
   virtual void SetSlider(nsSliderFrame* aSlider) { mSlider = aSlider; }
 
- /**
-  * Processes a mouse down event
-  * @param aMouseEvent @see nsIDOMEvent.h 
-  * @returns whether the event was consumed or ignored. @see nsresult
-  */
-  NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
-
-  /**
-   * Processes a mouse up event
-   * @param aMouseEvent @see nsIDOMEvent.h 
-   * @returns whether the event was consumed or ignored. @see nsresult
-   */
-  NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
-
-  /**
-   * Processes a mouse click event
-   * @param aMouseEvent @see nsIDOMEvent.h 
-   * @returns whether the event was consumed or ignored. @see nsresult
-   *
-   */
-  NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }
-
-  /**
-   * Processes a mouse click event
-   * @param aMouseEvent @see nsIDOMEvent.h 
-   * @returns whether the event was consumed or ignored. @see nsresult
-   *
-   */
-  NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }
-
-  /**
-   * Processes a mouse enter event
-   * @param aMouseEvent @see nsIDOMEvent.h 
-   * @returns whether the event was consumed or ignored. @see nsresult
-   */
-  NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; }
-
-  /**
-   * Processes a mouse leave event
-   * @param aMouseEvent @see nsIDOMEvent.h 
-   * @returns whether the event was consumed or ignored. @see nsresult
-   */
-  NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent) { return NS_OK; }
-
-  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
+  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
 };
 
 class nsSliderFrame : public nsBoxFrame
 {
 public:
   NS_DECL_FRAMEARENA_HELPERS
 
   friend class nsSliderMediator;
@@ -168,20 +124,17 @@ public:
                          nsGUIEvent* aEvent,
                          nsEventStatus* aEventStatus);
 
   NS_IMETHOD SetInitialChildList(nsIAtom*        aListName,
                                  nsFrameList&    aChildList);
 
   virtual nsIAtom* GetType() const;
 
-  NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
-  NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
-
-  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
+  nsresult MouseDown(nsIDOMEvent* aMouseEvent);
 
   static PRInt32 GetCurrentPosition(nsIContent* content);
   static PRInt32 GetMinPosition(nsIContent* content);
   static PRInt32 GetMaxPosition(nsIContent* content);
   static PRInt32 GetIncrement(nsIContent* content);
   static PRInt32 GetPageIncrement(nsIContent* content);
   static PRInt32 GetIntegerAttribute(nsIContent* content, nsIAtom* atom, PRInt32 defaultValue);
   void EnsureOrient();