You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.




The NGLayout Event Model
Authors: Tom Pixley
Last update: October 7, 1998

 
Overview
The NGLayout Event Model has been designed to comply with the DOM Level 2 Event Model currently being developed with the DOM W3C Working Group.  It design and schedules are closely tied to NGLayout's implementation of the DOM Level 1.

The NGLayout engine will implement a union of the DOM Level 0 and DOM Level 2 Event Models.  DOM Level 0 is itself a combination of the Communicator 4.0 Event Model and Microsoft's Internet Explorer 4.0 event model.  It will attempt to maintain backwards compatibilty, whenever possible, and be fully compliant with the forthcoming DOM Event Model specification.  Additionally, sufficient enhancements will be provided to meet all requirements of DOM clients such as the Composer product.
 
Major Components

The major components of the NGLayout event model consist of the event listener interfaces by which customers of the event model receive events and the internal event dispatch system which handles event bubbling, capturing, and ordering of event delivery.

Event Listener Interfaces

The event listener interfaces are separated by event class into a number of interfaces, each containing a group of related event handlers.  The current event listeners consist of the following interfaces:

  • nsIDOMEventListener - The main event listener interface from which the others derive.
  • nsIDOMMouseListener
  • nsIDOMMouseMotionListener
  • nsIDOMKeyListener
  • nsIDOMFocusListener
  • nsIDOMFormListener
  • nsIDOMLoadListener
  • nsIDOMDragListener
  • nsIDOMPaintListener
The listeners are largely used to handle UI events and DOM Level 0 Events.  Additional interfaces will be created to handle document mutation events.

Objects which can dispatch events implement the nsIDOMEventReceiver interface.  All content objects, the document object (nsDocument), and the window object (nsGlobalWindow) implement this nsIDOMEventReceiver.  Through this interface, an event model customer wishing to receive events of a given class dispatched by that element can register the appropriate event listener interface through the nsIDOMEventReceiver::AddEventListener interface.  The registered interface will then receive all events of the appropriate type dispatched by that object.  Currently, ordering of event delivery among multiple event listeners on the same object is determined by the order in which the customers register themselves.

Currently, there is one internal customer of the event listener interfaces, the JavaScript event handler model.  When JavaScript event handlers are detected either inside a script or embedded in the HTML tags of a page, an nsIDOMEventListener interface is registered on the specified object.  This interface is implemented by the translation layer between native code and JavaScript.

Detection of JavaScript event listener's is currently accomplished from number of locations.  Checking for event handlers within HTML tags is done during the SetAttribute methods in nsGenericHTMLElement and nsGenericDOMDataNode.  The detection of event handlers declared inside the JavaScript code itself is done inside the JavaScript SetProperty method.   This method is exposed to the implementing object via the nsIJSScriptObject interface.  Currently nsGenericHTMLElement, nsDocument, and nsGlobalWindow all make use of this method to check for JavaScript event handler registration.

Event Dispatch System

Event Object

Information about each individual event is passed along to the event listener by way of the event object.  This object is passed along as the first parameter to the event handler when the event is dispatched.  This information is accessed through the nsIDOMEvent interface (or as properties of the Event object in JavaScript).

Internally, the nsIDOMEvent interface is implemented by the nsDOMEvent object.  When an nsDOMEvent is created it takes a pointer to an nsGUIEvent struct.  The nsGUIEvent struct is the main event struct used internally inside NGLayout.  The nsDOMEvent holds onto this pointer and accesses its contents when queried for information.  The nsGUIEvent struct is temporary object and must be copied to make it persistent when the lifetime of the nsDOMEvent exceeds the initial event delivery process.
 
Roadmap

Remaining design issues

The DOM Level 2 Event Model is still in its design phase.  A number of changes are likely before the final form of the model is determined.  Among those are the nature of the native code event handling.  The current event listener interface model, the specific interfaces, and their component event types are based on assumptions of what form the DOM model will take.  If the DOM model goes in a different direction we will support its methods for native event handling.  This may or may not include changing our current event listener interface model.  JavaScript event handling is unlikely to change significantly as its requirements are based on backwards compatibility with Level 0.

Additionally, the full level of backwards compatibility has not been decided.  The combination of the bubbling and capturing has created some small changes in the behavior of the event model as compared to Netscape Communicator 4.0.  Design decisions made for NGLayout have also had an effect on the event system.  Whether these changes are significant has not yet been fully determined.  If the variations are found to have a large effect on backwards compatibility with existing content, changes will be considered.
 
Known Bugs

  • Event capture has not yet been implemented.
  • Some events currently bubble which are specified as non-bubbling.
  • Some data fields in the Event object are currently inaccurate.
  • Currently unimplemented events:
    • Unload
    • Abort
    • DragDrop
Schedule