Mozilla research-Xul Window Creation and Event Processing
Reprinted please indicate the source and the author contact: http://blog.csdn.net/absurd
Contact information of the author: Li xianjing <xianjimli at Hotmail dot com>
Last Updated: 2007-3-25
Mozilla is a browser-centered software platform, which plays an important role in our platform. We use it to implement applications such as Web browsers, WAP browsers, mail systems, e-books, and help readers. For this reason, I recently spent a lot of time reading Mozilla code and documentation. I will write a series of blogs as my notes for reference by friends who need them. This topic describes Window Creation and event processing.
Window Creation
1. For the prompt window, which is opened by functions such as alert/confirm in JavaScript. The process is as follows: nspromptservice: dodialog à ns1_wwatcher: OpenWindow à nsxulwindow: showmodal. If you want to customize the behavior of the prompt window, such as the prompt in the command line, you can re-implement the nsipromptservice2/nspipromptservice interface.
2. For normal windows, the creation process is as follows: ns1_wwatcher: OpenWindow à windowcreator: createchromewindow2 à nswindowconstructor.
Close Window
1. Call the close function in JavaScript to close the window.
2. Call nsglobalwindow: Close through xpconnect.
3. nsglobalwindow: Close call nsglobalwindow: reallyclosewindow to close the window.
Event registration
1. After the XUL document is parsed, nsxuldocument: preparetowalk creates all nsxulelements.
2. nsxulelement: create calls nsxulelement: addscripteventlistener to register the event handler.
3. nsxulelement: addscripteventlistener calls nseventlistenermanager: addscripteventlistener to register the event handler.
4. nseventlistenermanager: addscripteventlistener through nsjscontext, finally calls ns_newjseventlistener to package the Javascript event processing function into nsidomeventlistener and register it with nseventlistenermanager.
Event Distribution
1. functions such as xxx_event_cb in nswindow. cpp forward GTK + events to the nswindow: onxxxevent function.
2. nscommonwidget: dispatchevent forwards the event to the handleevent callback function registered by the view.
3. nsview. cpp: handleevent: locate the current view through the event widget, find the corresponding ViewManager, and send messages through nsviewmanager: dispatchevent.
4. nsviewmanager forwards messages to the corresponding nsxulelement through presshell.
5. nsxulelement forwards messages to nsjseventlistener through nseventlistenermanager.
6. nsjseventlistener: handleevent is then called by the javascript interpreter to handle JavaScript events.
~~ End ~~