Event Handling In Mozilla
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):
- Give event to event manager for pre event state changes and
generation of synthetic events:
manager->PreHandleEvent()
- Give event to the DOM for third party and JS use:
focusContent->HandleDOMEvent()
ortargetContent->HandleDOMEvent()
- Give event to the Frames for browser default processing:
mCurrentEventFrame->HandleEvent()
- Give event to event manager for post event state changes and
generation of synthetic events:
manager->PostHandleEvent()