From edc5f268b3be4a9294cf74e22bd4847be645c75a Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Fri, 24 Apr 2015 14:27:35 +0300 Subject: [PATCH] Bug 1154701 part 5 - Switch nsHTMLEditor::objectResizeEventListeners to nsTArray; r=ehsan --- editor/libeditor/nsHTMLEditor.cpp | 2 +- editor/libeditor/nsHTMLEditor.h | 3 +-- editor/libeditor/nsHTMLObjectResizer.cpp | 34 +++++++----------------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/editor/libeditor/nsHTMLEditor.cpp b/editor/libeditor/nsHTMLEditor.cpp index c881907d2323..d732088b320e 100644 --- a/editor/libeditor/nsHTMLEditor.cpp +++ b/editor/libeditor/nsHTMLEditor.cpp @@ -195,7 +195,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLEditor, nsPlaintextEdito NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMouseMotionListenerP) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSelectionListenerP) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResizeEventListenerP) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(objectResizeEventListeners) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mObjectResizeEventListeners) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAbsolutelyPositionedObject) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGrabber) diff --git a/editor/libeditor/nsHTMLEditor.h b/editor/libeditor/nsHTMLEditor.h index 99d47abff1f7..d6b0636c4a00 100644 --- a/editor/libeditor/nsHTMLEditor.h +++ b/editor/libeditor/nsHTMLEditor.h @@ -7,7 +7,6 @@ #define nsHTMLEditor_h__ #include "nsCOMPtr.h" -#include "nsCOMArray.h" #include "nsPlaintextEditor.h" #include "nsIEditor.h" #include "nsIHTMLEditor.h" @@ -850,7 +849,7 @@ protected: nsCOMPtr mSelectionListenerP; nsCOMPtr mResizeEventListenerP; - nsCOMArray objectResizeEventListeners; + nsTArray> mObjectResizeEventListeners; int32_t mOriginalX; int32_t mOriginalY; diff --git a/editor/libeditor/nsHTMLObjectResizer.cpp b/editor/libeditor/nsHTMLObjectResizer.cpp index 96cca62f4d48..3948aec4d3aa 100644 --- a/editor/libeditor/nsHTMLObjectResizer.cpp +++ b/editor/libeditor/nsHTMLObjectResizer.cpp @@ -499,14 +499,8 @@ nsresult nsHTMLEditor::StartResizing(nsIDOMElement *aHandle) { // First notify the listeners if any - int32_t listenersCount = objectResizeEventListeners.Count(); - if (listenersCount) { - nsCOMPtr listener; - int32_t index; - for (index = 0; index < listenersCount; index++) { - listener = objectResizeEventListeners[index]; - listener->OnStartResizing(static_cast(GetAsDOMNode(mResizedObject))); - } + for (auto& listener : mObjectResizeEventListeners) { + listener->OnStartResizing(static_cast(GetAsDOMNode(mResizedObject))); } mIsResizing = true; @@ -976,16 +970,10 @@ nsHTMLEditor::SetFinalSize(int32_t aX, int32_t aY) EmptyString()); } // finally notify the listeners if any - int32_t listenersCount = objectResizeEventListeners.Count(); - if (listenersCount) { - nsCOMPtr listener; - int32_t index; - for (index = 0; index < listenersCount; index++) { - listener = objectResizeEventListeners[index]; - listener->OnEndResizing(static_cast(GetAsDOMNode(mResizedObject)), - mResizedObjectWidth, mResizedObjectHeight, - width, height); - } + for (auto& listener : mObjectResizeEventListeners) { + listener->OnEndResizing(static_cast(GetAsDOMNode(mResizedObject)), + mResizedObjectWidth, mResizedObjectHeight, width, + height); } // keep track of that size @@ -1021,14 +1009,13 @@ NS_IMETHODIMP nsHTMLEditor::AddObjectResizeEventListener(nsIHTMLObjectResizeListener * aListener) { NS_ENSURE_ARG_POINTER(aListener); - if (objectResizeEventListeners.Count() && - objectResizeEventListeners.IndexOf(aListener) != -1) { + if (mObjectResizeEventListeners.Contains(aListener)) { /* listener already registered */ NS_ASSERTION(false, "trying to register an already registered object resize event listener"); return NS_OK; } - objectResizeEventListeners.AppendObject(aListener); + mObjectResizeEventListeners.AppendElement(*aListener); return NS_OK; } @@ -1036,14 +1023,13 @@ NS_IMETHODIMP nsHTMLEditor::RemoveObjectResizeEventListener(nsIHTMLObjectResizeListener * aListener) { NS_ENSURE_ARG_POINTER(aListener); - if (!objectResizeEventListeners.Count() || - objectResizeEventListeners.IndexOf(aListener) == -1) { + if (!mObjectResizeEventListeners.Contains(aListener)) { /* listener was not registered */ NS_ASSERTION(false, "trying to remove an object resize event listener that was not already registered"); return NS_OK; } - objectResizeEventListeners.RemoveObject(aListener); + mObjectResizeEventListeners.RemoveElement(aListener); return NS_OK; }