nsIEventListenerService

by 3 contributors:

A service that can be used to get a list of listeners observing events; this is primarily useful for debuggers.
1.0
28
Introduced
Gecko 1.9.2
Inherits from: nsISupports Last changed in Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4)

Implemented by: @mozilla.org/eventlistenerservice;1. To create an instance, use:

var eventListenerService = Components.classes["@mozilla.org/eventlistenerservice;1"]
                           .getService(Components.interfaces.nsIEventListenerService);

UniversalXPConnect privileges are required to use this service.

Method overview

void getEventTargetChainFor(in nsIDOMEventTarget aEventTarget, [optional] out unsigned long aCount, [retval, array, size_is(aCount)] out nsIDOMEventTarget aOutArray);
void getListenerInfoFor(in nsIDOMEventTarget aEventTarget, [optional] out unsigned long aCount, [retval, array, size_is(aCount)] out nsIEventListenerInfo aOutArray);
boolean hasListenersFor(in nsIDOMEventTarget aEventTarget, in DOMString aType);
void addSystemEventListener(in nsIDOMEventTarget target, in DOMString type, in nsIDOMEventListener listener, in boolean useCapture);
void removeSystemEventListener(in nsIDOMEventTarget target, in DOMString type, in nsIDOMEventListener listener, in boolean useCapture);

Attributes

Attribute Type Description
systemEventGroup nsIDOMEventGroup Returns system event group. Read only. Obsolete since Gecko 7.0

Methods

getEventTargetChainFor()

Returns an array of event targets indicating all the targets that will receive the same events that are delivered to the specified target. aEventTarget will be at index 0. The objects are the ones that would be used as event.currentTarget while dispatching an event to aEventTarget.

Note: Some events, especially 'load', may actually have a shorter event target chain than what this methods returns.

void getEventTargetChainFor(
  in nsIDOMEventTarget aEventTarget,
  [optional] out unsigned long aCount,
  [retval, array, size_is(aCount)] out nsIDOMEventTarget aOutArray
);
Parameters
aEventTarget
The nsIDOMEventTarget for which to return the event target chain.
aCount
On return, contains the number of elements in the returned array.
aOutArray
The array into which to store the event targets.

getListenerInfoFor()

Returns an array of nsIEventListenerInfo objects describing everyone listening to the specified event target. If aEventTarget doesn't have any listeners, this returns null.

void getListenerInfoFor(
  in nsIDOMEventTarget aEventTarget,
  [optional] out unsigned long aCount,
  [retval, array, size_is(aCount)] out nsIEventListenerInfo aOutArray
);
Parameters
aEventTarget
The nsIEventTarget for which to obtain a list of listeners.
aCount
On return, the number of returned listener descriptors.
aOutArray
An array of nsIEventListenerInfo objects describing the listeners.

hasListenersFor()

Returns true if a event target has any listener for the given type.

boolean hasListenersFor(
  in nsIDOMEventTarget aEventTarget,
  in DOMString aType
);
Parameters
aEventTarget
The nsIDOMEventTarget for which to check if this has any listener for aType.
aType
An event name.

addSystemEventListener()

Add a system-group eventlistener to a event target.

System-group eventlisteners are called after all eventlisteners in default-group handle the events. So, system-group eventlisteners can implement the default action of the event. Even if an event is stopped its propagation in default-group, the event will be fired again in system-group.

void addSystemEventListener(
  in nsIDOMEventTarget target,
  in DOMString type,
  in nsIDOMEventListener listener,
  in boolean useCapture
);
Parameters
target
The nsIDOMEventTarget for the event target to listen an event.
type
The event name to listen.
listener
The nsIDOMEventListener which listens the event.
useCapture
True if to listen the event in capture phase, otherwise, false.

removeSystemEventListener()

Remove a system-group eventlistener from a event target.

void removeSystemEventListener(
  in nsIDOMEventTarget target,
  in DOMString type,
  in nsIDOMEventListener listener,
  in boolean useCapture
);
Parameters
target
The nsIDOMEventTarget for the event target listening the event.
type
The listening event name.
listener
The nsIDOMEventListener which is listening the event.
useCapture
True if listening the events in capture phase, otherwise, false.

Remarks

nsIEventListenerService was introduced with bug 448602.

See also

Document Tags and Contributors

Contributors to this page: Sheppy, Masayuki, Sevenspade
Last updated by: Sheppy,