Bug 1154701 part 12 - Switch nsEditor::mDocStateListeners to nsTArray; r=ehsan

This commit is contained in:
Aryeh Gregor 2015-04-24 14:27:36 +03:00
parent ea5607b0ca
commit 86e6d15d10
2 changed files with 16 additions and 21 deletions

View File

@ -1882,10 +1882,8 @@ nsEditor::AddDocumentStateListener(nsIDocumentStateListener *aListener)
{
NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
if (mDocStateListeners.IndexOf(aListener) == -1)
{
if (!mDocStateListeners.AppendObject(aListener))
return NS_ERROR_FAILURE;
if (!mDocStateListeners.Contains(aListener)) {
mDocStateListeners.AppendElement(*aListener);
}
return NS_OK;
@ -1897,8 +1895,7 @@ nsEditor::RemoveDocumentStateListener(nsIDocumentStateListener *aListener)
{
NS_ENSURE_TRUE(aListener, NS_ERROR_NULL_POINTER);
if (!mDocStateListeners.RemoveObject(aListener))
return NS_ERROR_FAILURE;
mDocStateListeners.RemoveElement(aListener);
return NS_OK;
}
@ -2454,29 +2451,28 @@ nsEditor::GetFirstEditableNode(nsINode* aRoot)
NS_IMETHODIMP
nsEditor::NotifyDocumentListeners(TDocumentListenerNotification aNotificationType)
{
int32_t numListeners = mDocStateListeners.Count();
if (!numListeners) // maybe there just aren't any.
if (!mDocStateListeners.Length()) {
// Maybe there just aren't any.
return NS_OK;
}
nsCOMArray<nsIDocumentStateListener> listeners(mDocStateListeners);
nsTArray<OwningNonNull<nsIDocumentStateListener>>
listeners(mDocStateListeners);
nsresult rv = NS_OK;
int32_t i;
switch (aNotificationType)
{
case eDocumentCreated:
for (i = 0; i < numListeners;i++)
{
rv = listeners[i]->NotifyDocumentCreated();
for (auto& listener : listeners) {
rv = listener->NotifyDocumentCreated();
if (NS_FAILED(rv))
break;
}
break;
case eDocumentToBeDestroyed:
for (i = 0; i < numListeners;i++)
{
rv = listeners[i]->NotifyDocumentWillBeDestroyed();
for (auto& listener : listeners) {
rv = listener->NotifyDocumentWillBeDestroyed();
if (NS_FAILED(rv))
break;
}
@ -2493,9 +2489,8 @@ nsEditor::NotifyDocumentListeners(TDocumentListenerNotification aNotificationTyp
mDocDirtyState = docIsDirty;
for (i = 0; i < numListeners;i++)
{
rv = listeners[i]->NotifyDocumentStateChanged(mDocDirtyState);
for (auto& listener : listeners) {
rv = listener->NotifyDocumentStateChanged(mDocDirtyState);
if (NS_FAILED(rv))
break;
}

View File

@ -10,7 +10,6 @@
#include "mozilla/dom/OwningNonNull.h" // for OwningNonNull
#include "mozilla/dom/Text.h"
#include "nsAutoPtr.h" // for nsRefPtr
#include "nsCOMArray.h" // for nsCOMArray
#include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
#include "nsCycleCollectionParticipant.h"
#include "nsGkAtoms.h"
@ -835,7 +834,8 @@ protected:
nsTArray<mozilla::dom::OwningNonNull<nsIEditActionListener>> mActionListeners;
// Just notify once per high level change
nsTArray<mozilla::dom::OwningNonNull<nsIEditorObserver>> mEditorObservers;
nsCOMArray<nsIDocumentStateListener> mDocStateListeners;// listen to overall doc state (dirty or not, just created, etc)
// Listen to overall doc state (dirty or not, just created, etc)
nsTArray<mozilla::dom::OwningNonNull<nsIDocumentStateListener>> mDocStateListeners;
nsSelectionState mSavedSel; // cached selection for nsAutoSelectionReset
nsRangeUpdater mRangeUpdater; // utility class object for maintaining preserved ranges