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.



Event Handling In Mozilla

Alexander Larsson <alex@cendio.se>

When the user presses a key on the keyboard this eventually gets to the Xserver. The Xserver then creates an X events and sends to the focused window.

This event is captured by gtk which creates an GDK event and passes it to any signal handlers registered on the focused GtkWidget.

This signal callback always ends up in handle_key_press_event in nsGtkEventHandler.cpp, which passes control to the correct nsWindow. Then an nsKeyEvent (derived from nsGUIEvent) is created and sent to the EventCallback registered on the widget when it's created.

Most (all) widgets get created with an event callback pointing to HandleEvent() in nsView.cpp. This function locates the correct nsViewManager for the view and calls viewmanager->DispatchEvent() with the event.

The viewmanager the handles certain types of events (NS_SIZE, NS_PAINT and NS_DESTROY), and the rest is passed to view->HandleEvent().

nsView::HandleEvent() recurses down into the view hierarchy to the innermost view that contains the (x, y) point where the event happened. Then each view calls obs->HandleEvent() on the nsIViewObserver that is registered with that view.

The only object that implements nsIViewObserver is nsPresShell. Which means all view events goes to nsPresShell::HandleEvent(), which does the following (in order):

  1. Give event to event manager for pre event state changes and generation of synthetic events: manager->PreHandleEvent()
  2. Give event to the DOM for third party and JS use: focusContent->HandleDOMEvent() or targetContent->HandleDOMEvent()
  3. Give event to the Frames for browser default processing: mCurrentEventFrame->HandleEvent()
  4. Give event to event manager for post event state changes and generation of synthetic events: manager->PostHandleEvent()