Bug 344986, Simplify nsEventListenerManager, r=sicking, sr=jst

This commit is contained in:
Olli.Pettay%helsinki.fi 2006-09-09 17:28:57 +00:00
Родитель 6e5b7b6b63
Коммит 72a64308b9
8 изменённых файлов: 596 добавлений и 1087 удалений

Просмотреть файл

@ -69,6 +69,7 @@ public:
#define NS_MUTATION_NODEINSERTEDINTODOCUMENT (NS_MUTATION_START+4)
#define NS_MUTATION_ATTRMODIFIED (NS_MUTATION_START+5)
#define NS_MUTATION_CHARACTERDATAMODIFIED (NS_MUTATION_START+6)
#define NS_MUTATION_END (NS_MUTATION_START+6)
// Bits are actually checked to optimize mutation event firing.
// That's why I don't number from 0x00. The first event should

Просмотреть файл

@ -136,7 +136,6 @@ nsDOMEvent::~nsDOMEvent()
NS_ASSERT_OWNINGTHREAD(nsDOMEvent);
if (mEventIsInternal && mEvent) {
delete mEvent->userType;
delete mEvent;
}
}
@ -160,12 +159,11 @@ NS_METHOD nsDOMEvent::GetType(nsAString& aType)
if (name) {
CopyASCIItoUTF16(name, aType);
return NS_OK;
}
else {
if (mEvent->message == NS_USER_DEFINED_EVENT && mEvent->userType) {
aType.Assign(NS_STATIC_CAST(nsStringKey*, mEvent->userType)->GetString());
return NS_OK;
}
} else if (mEvent->message == NS_USER_DEFINED_EVENT && mEvent->userType) {
nsAutoString name;
mEvent->userType->ToString(name);
aType = Substring(name, 2, name.Length() - 2); // Remove "on"
return NS_OK;
}
return NS_ERROR_FAILURE;
@ -479,7 +477,7 @@ nsDOMEvent::SetEventType(const nsAString& aEventTypeArg)
#endif // MOZ_SVG
if (mEvent->message == NS_USER_DEFINED_EVENT)
mEvent->userType = new nsStringKey(aEventTypeArg);
mEvent->userType = atom;
return NS_OK;
}
@ -816,6 +814,7 @@ NS_METHOD nsDOMEvent::DuplicatePrivateData()
newEvent->flags = mEvent->flags;
newEvent->time = mEvent->time;
newEvent->refPoint = mEvent->refPoint;
newEvent->userType = mEvent->userType;
mEvent = newEvent;
mPresContext = nsnull;

Просмотреть файл

@ -79,7 +79,6 @@ nsDOMMouseEvent::nsDOMMouseEvent(nsPresContext* aPresContext,
nsDOMMouseEvent::~nsDOMMouseEvent()
{
if (mEventIsInternal) {
delete mEvent->userType;
switch (mEvent->eventStructType)
{
case NS_MOUSE_EVENT:

Просмотреть файл

@ -53,7 +53,6 @@ nsDOMMutationEvent::nsDOMMutationEvent(nsPresContext* aPresContext,
nsDOMMutationEvent::~nsDOMMutationEvent()
{
if (mEventIsInternal) {
delete mEvent->userType;
nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent);
delete mutation;
mEvent = nsnull;

Просмотреть файл

@ -56,7 +56,6 @@ nsDOMXULCommandEvent::nsDOMXULCommandEvent(nsPresContext* aPresContext,
nsDOMXULCommandEvent::~nsDOMXULCommandEvent()
{
if (mEventIsInternal) {
delete mEvent->userType;
nsXULCommandEvent* command = NS_STATIC_CAST(nsXULCommandEvent*, mEvent);
delete command;
mEvent = nsnull;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -48,8 +48,9 @@
#include "nsJSUtils.h"
class nsIDOMEvent;
class nsIAtom;
class nsVoidArray;
class nsIAtom;
struct EventTypeData;
typedef struct {
// The nsMarkedJSFunctionHolder does magic to avoid holding strong
@ -61,52 +62,14 @@ typedef struct {
// reachability information as own-in root-out, which creates roots
// that cause reference cycles to entrain garbage.)
nsMarkedJSFunctionHolder<nsIDOMEventListener> mListener;
PRUint16 mFlags;
PRUint16 mGroupFlags;
PRUint8 mSubType;
PRUint8 mHandlerIsString;
PRUint32 mEventType;
nsCOMPtr<nsIAtom> mTypeAtom;
PRUint16 mFlags;
PRUint16 mGroupFlags;
PRBool mHandlerIsString;
const EventTypeData* mTypeData;
} nsListenerStruct;
//These define the internal type of the EventListenerManager
//No listener type defined, should happen only at creation
#define NS_ELM_NONE 0
//Simple indicates only a single event listener group type (i.e. mouse, key)
#define NS_ELM_SINGLE 1
//Multi indicates any number of listener group types accessed as member vars
#define NS_ELM_MULTI 2
//Hash indicates any number of listener group types accessed out of a hash
#define NS_ELM_HASH 4
enum EventArrayType {
eEventArrayType_Mouse = 0,
eEventArrayType_MouseMotion = 1,
eEventArrayType_ContextMenu = 2,
eEventArrayType_Key = 3,
eEventArrayType_Load = 4,
eEventArrayType_Focus = 5,
eEventArrayType_Form = 6,
eEventArrayType_Drag = 7,
eEventArrayType_Paint = 8,
eEventArrayType_Text = 9,
eEventArrayType_Composition = 10,
eEventArrayType_XUL = 11,
eEventArrayType_Scroll = 12,
eEventArrayType_Mutation = 13,
eEventArrayType_DOMUI = 14,
eEventArrayType_PageTransition = 15,
#ifdef MOZ_SVG
eEventArrayType_SVG = 16,
eEventArrayType_SVGZoom = 17,
#endif // MOZ_SVG
eEventArrayType_Hash,
eEventArrayType_None
};
//Keep this in line with event array types, not counting
//types HASH and NONE
#define EVENT_ARRAY_TYPE_LENGTH eEventArrayType_Hash
/*
* Event listener manager
*/
@ -170,20 +133,13 @@ public:
NS_IMETHOD SetListenerTarget(nsISupports* aTarget);
NS_IMETHOD HasMutationListeners(PRBool* aListener)
{
*aListener = (GetListenersByType(eEventArrayType_Mutation, nsnull,
PR_FALSE) != nsnull);
return NS_OK;
}
NS_IMETHOD HasMutationListeners(PRBool* aListener);
NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup);
virtual PRBool HasUnloadListeners();
static nsresult GetIdentifiersForType(nsIAtom* aType,
EventArrayType* aArrayType,
PRInt32* aSubType);
static PRUint32 GetIdentifierForEvent(nsIAtom* aEvent);
// nsIDOMEventTarget
NS_DECL_NSIDOMEVENTTARGET
@ -208,37 +164,34 @@ protected:
nsIDOMEventListener* aListener,
nsIDOMEvent* aDOMEvent,
nsISupports* aCurrentTarget,
PRUint32 aSubType,
PRUint32 aPhaseFlags);
nsresult CompileEventHandlerInternal(nsIScriptContext *aContext,
void *aScopeObject,
nsISupports *aObject,
nsIAtom *aName,
nsListenerStruct *aListenerStruct,
nsISupports* aCurrentTarget,
PRUint32 aSubType);
nsListenerStruct* FindJSEventListener(EventArrayType aType);
nsISupports* aCurrentTarget);
nsListenerStruct* FindJSEventListener(PRUint32 aEventType, nsIAtom* aTypeAtom);
nsresult SetJSEventListener(nsIScriptContext *aContext,
void *aScopeGlobal,
nsISupports *aObject,
nsIAtom* aName, PRBool aIsString,
PRBool aPermitUntrustedEvents);
nsresult AddEventListener(nsIDOMEventListener *aListener,
EventArrayType aType,
PRInt32 aSubType,
nsHashKey* aKey,
PRUint32 aType,
nsIAtom* aTypeAtom,
const EventTypeData* aTypeData,
PRInt32 aFlags,
nsIDOMEventGroup* aEvtGrp);
nsresult RemoveEventListener(nsIDOMEventListener *aListener,
EventArrayType aType,
PRInt32 aSubType,
nsHashKey* aKey,
PRUint32 aType,
nsIAtom* aUserType,
const EventTypeData* aTypeData,
PRInt32 aFlags,
nsIDOMEventGroup* aEvtGrp);
void ReleaseListeners(nsVoidArray** aListeners);
nsresult RemoveAllListeners();
nsVoidArray* GetListenersByType(EventArrayType aType, nsHashKey* aKey, PRBool aCreate);
EventArrayType GetTypeForIID(const nsIID& aIID);
const EventTypeData* GetTypeDataForIID(const nsIID& aIID);
const EventTypeData* GetTypeDataForEventName(nsIAtom* aName);
nsresult FixContextMenuEvent(nsPresContext* aPresContext,
nsISupports* aCurrentTarget,
nsEvent* aEvent,
@ -249,146 +202,20 @@ protected:
void GetCoordinatesFor(nsIDOMElement *aCurrentEl, nsPresContext *aPresContext,
nsIPresShell *aPresShell, nsPoint& aTargetPt);
nsresult GetDOM2EventGroup(nsIDOMEventGroup** aGroup);
PRBool ListenerCanHandle(nsListenerStruct* aLs, nsEvent* aEvent);
PRUint8 mManagerType;
PRPackedBool mListenersRemoved;
nsVoidArray mListeners;
nsISupports* mTarget; //WEAK
PRPackedBool mListenersRemoved;
PRPackedBool mMayHaveMutationListeners;
// 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;
nsCOMPtr<nsIAtom> mNoListenerForEventAtom;
EventArrayType mSingleListenerType;
nsVoidArray* mSingleListener;
nsVoidArray* mMultiListeners;
nsHashtable* mGenericListeners;
static PRUint32 mInstanceCount;
nsISupports* mTarget; //WEAK
static jsval sAddListenerID;
static PRUint32 mInstanceCount;
static jsval sAddListenerID;
};
//Set of defines for distinguishing event handlers within listener groupings
//XXX Current usage allows no more than 7 types per listener grouping
#define NS_EVENT_BITS_NONE 0x00
//nsIDOMMouseListener
#define NS_EVENT_BITS_MOUSE_NONE 0x00
#define NS_EVENT_BITS_MOUSE_MOUSEDOWN 0x01
#define NS_EVENT_BITS_MOUSE_MOUSEUP 0x02
#define NS_EVENT_BITS_MOUSE_CLICK 0x04
#define NS_EVENT_BITS_MOUSE_DBLCLICK 0x08
#define NS_EVENT_BITS_MOUSE_MOUSEOVER 0x10
#define NS_EVENT_BITS_MOUSE_MOUSEOUT 0x20
//nsIDOMMouseMotionListener
#define NS_EVENT_BITS_MOUSEMOTION_NONE 0x00
#define NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE 0x01
#define NS_EVENT_BITS_MOUSEMOTION_DRAGMOVE 0x02
//nsIDOMContextMenuListener
#define NS_EVENT_BITS_CONTEXTMENU_NONE 0x00
#define NS_EVENT_BITS_CONTEXTMENU 0x01
//nsIDOMKeyListener
#define NS_EVENT_BITS_KEY_NONE 0x00
#define NS_EVENT_BITS_KEY_KEYDOWN 0x01
#define NS_EVENT_BITS_KEY_KEYUP 0x02
#define NS_EVENT_BITS_KEY_KEYPRESS 0x04
//nsIDOMTextListener
#define NS_EVENT_BITS_TEXT_NONE 0x00
#define NS_EVENT_BITS_TEXT_TEXT 0x01
//nsIDOMCompositionListener
#define NS_EVENT_BITS_COMPOSITION_NONE 0x00
#define NS_EVENT_BITS_COMPOSITION_START 0x01
#define NS_EVENT_BITS_COMPOSITION_END 0x02
#define NS_EVENT_BITS_COMPOSITION_QUERY 0x04
#define NS_EVENT_BITS_COMPOSITION_RECONVERSION 0x08
#define NS_EVENT_BITS_COMPOSITION_QUERYCARETRECT 0x10
//nsIDOMFocusListener
#define NS_EVENT_BITS_FOCUS_NONE 0x00
#define NS_EVENT_BITS_FOCUS_FOCUS 0x01
#define NS_EVENT_BITS_FOCUS_BLUR 0x02
//nsIDOMFormListener
#define NS_EVENT_BITS_FORM_NONE 0x00
#define NS_EVENT_BITS_FORM_SUBMIT 0x01
#define NS_EVENT_BITS_FORM_RESET 0x02
#define NS_EVENT_BITS_FORM_CHANGE 0x04
#define NS_EVENT_BITS_FORM_SELECT 0x08
#define NS_EVENT_BITS_FORM_INPUT 0x10
//nsIDOMLoadListener
#define NS_EVENT_BITS_LOAD_NONE 0x00
#define NS_EVENT_BITS_LOAD_LOAD 0x01
#define NS_EVENT_BITS_LOAD_UNLOAD 0x02
#define NS_EVENT_BITS_LOAD_ABORT 0x04
#define NS_EVENT_BITS_LOAD_ERROR 0x08
#define NS_EVENT_BITS_LOAD_BEFORE_UNLOAD 0x10
//nsIDOMXULListener
#define NS_EVENT_BITS_XUL_NONE 0x00
#define NS_EVENT_BITS_XUL_POPUP_SHOWING 0x01
#define NS_EVENT_BITS_XUL_CLOSE 0x02
#define NS_EVENT_BITS_XUL_POPUP_HIDING 0x04
#define NS_EVENT_BITS_XUL_COMMAND 0x08
#define NS_EVENT_BITS_XUL_BROADCAST 0x10
#define NS_EVENT_BITS_XUL_COMMAND_UPDATE 0x20
#define NS_EVENT_BITS_XUL_POPUP_SHOWN 0x40
#define NS_EVENT_BITS_XUL_POPUP_HIDDEN 0x80
//nsIScrollListener
#define NS_EVENT_BITS_SCROLLPORT_NONE 0x00
#define NS_EVENT_BITS_SCROLLPORT_OVERFLOW 0x01
#define NS_EVENT_BITS_SCROLLPORT_UNDERFLOW 0x02
#define NS_EVENT_BITS_SCROLLPORT_OVERFLOWCHANGED 0x04
//nsIDOMDragListener
#define NS_EVENT_BITS_DRAG_NONE 0x00
#define NS_EVENT_BITS_DRAG_ENTER 0x01
#define NS_EVENT_BITS_DRAG_OVER 0x02
#define NS_EVENT_BITS_DRAG_EXIT 0x04
#define NS_EVENT_BITS_DRAG_DROP 0x08
#define NS_EVENT_BITS_DRAG_GESTURE 0x10
//nsIDOMPaintListener
#define NS_EVENT_BITS_PAINT_NONE 0x00
#define NS_EVENT_BITS_PAINT_PAINT 0x01
#define NS_EVENT_BITS_PAINT_RESIZE 0x02
#define NS_EVENT_BITS_PAINT_SCROLL 0x04
//nsIDOMMutationListener
// These bits are found in nsMutationEvent.h.
//nsIDOMContextMenuListener
#define NS_EVENT_BITS_CONTEXT_NONE 0x00
#define NS_EVENT_BITS_CONTEXT_MENU 0x01
// nsIDOMUIListener
#define NS_EVENT_BITS_UI_NONE 0x00
#define NS_EVENT_BITS_UI_ACTIVATE 0x01
#define NS_EVENT_BITS_UI_FOCUSIN 0x02
#define NS_EVENT_BITS_UI_FOCUSOUT 0x04
// nsIDOMPageTransitionListener
#define NS_EVENT_BITS_PAGETRANSITION_NONE 0x00
#define NS_EVENT_BITS_PAGETRANSITION_SHOW 0x01
#define NS_EVENT_BITS_PAGETRANSITION_HIDE 0x02
#ifdef MOZ_SVG
// nsIDOMSVGEventListener
#define NS_EVENT_BITS_SVG_NONE 0x00
#define NS_EVENT_BITS_SVG_LOAD 0x01
#define NS_EVENT_BITS_SVG_UNLOAD 0x02
#define NS_EVENT_BITS_SVG_ABORT 0x04
#define NS_EVENT_BITS_SVG_ERROR 0x08
#define NS_EVENT_BITS_SVG_RESIZE 0x10
#define NS_EVENT_BITS_SVG_SCROLL 0x20
// nsIDOMSVGZoomEventListener
#define NS_EVENT_BITS_SVGZOOM_NONE 0x00
#define NS_EVENT_BITS_SVGZOOM_ZOOM 0x01
#endif // MOZ_SVG
#endif // nsEventListenerManager_h__

Просмотреть файл

@ -53,6 +53,7 @@
#undef ERROR
#endif
#include "nsCOMPtr.h"
#include "nsIAtom.h"
#include "nsIDOMKeyEvent.h"
class nsIRenderingContext;
@ -409,7 +410,7 @@ public:
// status. This is used also to indicate whether the event is trusted.
PRUint32 flags;
// Additional type info for user defined events
nsHashKey* userType;
nsCOMPtr<nsIAtom> userType;
// Event targets, needed by DOM Events
// Using nsISupports, not nsIDOMEventTarget because in some cases
// nsIDOMEventTarget is implemented as a tearoff.