store nsListenerStruct instances rather than pointers. b=407442, r+sr=sicking, a=blocking1.9

This commit is contained in:
dwitte@stanford.edu 2008-02-06 20:02:25 -08:00
parent 64d3078aac
commit 53d9c34e50
2 changed files with 37 additions and 39 deletions

View File

@ -393,9 +393,9 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsEventListenerManager, nsIEventListen
NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsEventListenerManager, nsIEventListenerManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsEventListenerManager)
PRInt32 i, count = tmp->mListeners.Length();
for (i = 0; i < count; i++) {
cb.NoteXPCOMChild(tmp->mListeners.ElementAt(i)->mListener.get());
PRUint32 count = tmp->mListeners.Length();
for (PRUint32 i = 0; i < count; i++) {
cb.NoteXPCOMChild(tmp->mListeners.ElementAt(i).mListener.get());
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
@ -472,10 +472,10 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
}
}
nsListenerStruct* ls = nsnull;
PRInt32 count = mListeners.Length();
for (PRInt32 i = 0; i < count; i++) {
ls = mListeners.ElementAt(i);
nsListenerStruct* ls;
PRUint32 count = mListeners.Length();
for (PRUint32 i = 0; i < count; i++) {
ls = &mListeners.ElementAt(i);
if (ls->mListener == aListener && ls->mFlags == aFlags &&
ls->mGroupFlags == group &&
(EVENT_TYPE_EQUALS(ls, aType, aTypeAtom) ||
@ -487,7 +487,7 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
mNoListenerForEvent = NS_EVENT_TYPE_NULL;
mNoListenerForEventAtom = nsnull;
ls = new nsListenerStruct();
ls = mListeners.AppendElement();
NS_ENSURE_TRUE(ls, NS_ERROR_OUT_OF_MEMORY);
ls->mListener = aListener;
@ -497,7 +497,6 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
ls->mGroupFlags = group;
ls->mHandlerIsString = PR_FALSE;
ls->mTypeData = aTypeData;
mListeners.AppendElement(ls);
// For mutation listeners, we need to update the global bit on the DOM window.
// Otherwise we won't actually fire the mutation event.
@ -556,12 +555,12 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener,
}
}
nsListenerStruct* ls = nsnull;
nsListenerStruct* ls;
aFlags &= ~NS_PRIV_EVENT_UNTRUSTED_PERMITTED;
PRInt32 count = mListeners.Length();
for (PRInt32 i = 0; i < count; ++i) {
ls = mListeners.ElementAt(i);
PRUint32 count = mListeners.Length();
for (PRUint32 i = 0; i < count; ++i) {
ls = &mListeners.ElementAt(i);
if (ls->mListener == aListener &&
ls->mGroupFlags == group &&
((ls->mFlags & ~NS_PRIV_EVENT_UNTRUSTED_PERMITTED) == aFlags) &&
@ -640,9 +639,9 @@ nsEventListenerManager::FindJSEventListener(PRUint32 aEventType,
// Run through the listeners for this type and see if a script
// listener is registered
nsListenerStruct *ls;
PRInt32 count = mListeners.Length();
for (PRInt32 i = 0; i < count; ++i) {
ls = mListeners.ElementAt(i);
PRUint32 count = mListeners.Length();
for (PRUint32 i = 0; i < count; ++i) {
ls = &mListeners.ElementAt(i);
if (EVENT_TYPE_EQUALS(ls, aEventType, aTypeAtom) &&
ls->mFlags & NS_PRIV_EVENT_FLAG_SCRIPT) {
return ls;
@ -838,7 +837,7 @@ nsEventListenerManager::RemoveScriptEventListener(nsIAtom* aName)
nsListenerStruct* ls = FindJSEventListener(eventType, aName);
if (ls) {
mListeners.RemoveElement(ls);
mListeners.RemoveElementAt(PRUint32(ls - &mListeners.ElementAt(0)));
mNoListenerForEvent = NS_EVENT_TYPE_NULL;
mNoListenerForEventAtom = nsnull;
}
@ -1151,11 +1150,11 @@ nsEventListenerManager::HandleEvent(nsPresContext* aPresContext,
found:
nsAutoTObserverArray<nsAutoPtr<nsListenerStruct>, 2>::EndLimitedIterator iter(mListeners);
nsAutoTObserverArray<nsListenerStruct, 2>::EndLimitedIterator iter(mListeners);
nsAutoPopupStatePusher popupStatePusher(nsDOMEvent::GetEventPopupControlState(aEvent));
PRBool hasListener = PR_FALSE;
while (iter.HasMore()) {
nsListenerStruct* ls = iter.GetNext();
nsListenerStruct* ls = &iter.GetNext();
PRBool useTypeInterface =
EVENT_TYPE_DATA_EQUALS(ls->mTypeData, typeData);
PRBool useGenericInterface =
@ -1676,9 +1675,9 @@ nsEventListenerManager::HasMutationListeners(PRBool* aListener)
{
*aListener = PR_FALSE;
if (mMayHaveMutationListeners) {
PRInt32 count = mListeners.Length();
for (PRInt32 i = 0; i < count; ++i) {
nsListenerStruct* ls = mListeners.ElementAt(i);
PRUint32 count = mListeners.Length();
for (PRUint32 i = 0; i < count; ++i) {
nsListenerStruct* ls = &mListeners.ElementAt(i);
if (ls->mEventType >= NS_MUTATION_START &&
ls->mEventType <= NS_MUTATION_END) {
*aListener = PR_TRUE;
@ -1695,9 +1694,9 @@ nsEventListenerManager::MutationListenerBits()
{
PRUint32 bits = 0;
if (mMayHaveMutationListeners) {
PRInt32 i, count = mListeners.Length();
for (i = 0; i < count; ++i) {
nsListenerStruct* ls = mListeners.ElementAt(i);
PRUint32 count = mListeners.Length();
for (PRUint32 i = 0; i < count; ++i) {
nsListenerStruct* ls = &mListeners.ElementAt(i);
if (ls->mEventType >= NS_MUTATION_START &&
ls->mEventType <= NS_MUTATION_END) {
if (ls->mEventType == NS_MUTATION_SUBTREEMODIFIED) {
@ -1733,9 +1732,9 @@ nsEventListenerManager::HasListenersFor(const nsAString& aEventName)
}
found:
PRInt32 i, count = mListeners.Length();
for (i = 0; i < count; ++i) {
nsListenerStruct* ls = mListeners.ElementAt(i);
PRUint32 count = mListeners.Length();
for (PRUint32 i = 0; i < count; ++i) {
nsListenerStruct* ls = &mListeners.ElementAt(i);
if (ls->mTypeAtom == atom ||
EVENT_TYPE_DATA_EQUALS(ls->mTypeData, typeData)) {
return PR_TRUE;
@ -1747,9 +1746,9 @@ found:
PRBool
nsEventListenerManager::HasUnloadListeners()
{
PRInt32 count = mListeners.Length();
for (PRInt32 i = 0; i < count; ++i) {
nsListenerStruct* ls = mListeners.ElementAt(i);
PRUint32 count = mListeners.Length();
for (PRUint32 i = 0; i < count; ++i) {
nsListenerStruct* ls = &mListeners.ElementAt(i);
if (ls->mEventType == NS_PAGE_UNLOAD ||
ls->mEventType == NS_BEFORE_PAGE_UNLOAD ||
(ls->mTypeData && ls->mTypeData->iid &&

View File

@ -41,7 +41,6 @@
#include "nsIEventListenerManager.h"
#include "jsapi.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOM3EventTarget.h"
#include "nsHashtable.h"
@ -188,17 +187,17 @@ protected:
nsresult GetDOM2EventGroup(nsIDOMEventGroup** aGroup);
PRBool ListenerCanHandle(nsListenerStruct* aLs, nsEvent* aEvent);
nsAutoTObserverArray<nsAutoPtr<nsListenerStruct>, 2> mListeners;
nsISupports* mTarget; //WEAK
PRUint32 mMayHaveMutationListeners : 1;
nsAutoTObserverArray<nsListenerStruct, 2> mListeners;
nsISupports* mTarget; //WEAK
PRUint32 mMayHaveMutationListeners : 1;
// These two member variables are used to cache the information
// about the last event which was handled but for which event listener manager
// didn't have event listeners.
PRUint32 mNoListenerForEvent : 31;
nsCOMPtr<nsIAtom> mNoListenerForEventAtom;
PRUint32 mNoListenerForEvent : 31;
nsCOMPtr<nsIAtom> mNoListenerForEventAtom;
static PRUint32 mInstanceCount;
static jsval sAddListenerID;
static PRUint32 mInstanceCount;
static jsval sAddListenerID;
};
#endif // nsEventListenerManager_h__