![]() |
getting started with mozilla ui hacking"What if… non-programmers could design the look and feel of a product using W3C standards instead of C++? Where platform differences could be expressed in stylesheets, not hardcoded with #ifdefs? "
- from XPFE webpages
at mozilla.org
Contributing code to the Mozilla project has never been as easy as it is today. In the past, you had to be some C/C++/platform toolkit hotshot to add code, today all you really need is an understanding of JavaScript, HTML4.0, the W3C DOM, CSS, and most importantly a sense of adventure. If you've ever downloaded a Mozilla build, and looked inside the chrome folder, and inside one or two of the little XUL or JS files residing there, you would have guessed that something interesting was going on with Mozilla. The whole user interface is built on eXtensible User interface Language ("XUL") and some HTML4.0 components, styled with CSS1 and 2, and made interactive by using JavaScript to do UI code and to make calls to the compiled core via the exposed APIs. The Good News
And In Case You're Not Convinced…Here's a snippet of sample UI code (for a toolbar):
Get to the point, Ben!So have an idea for a feature you want to add? See something busted in the browser you suspect might be just a UI issue you can fix? Well, load up your text editor, find yourself some documentation if you need it (see links at the bottom of this document), and get hacking! Here's a general guide:
Chrome Folder StructureThe chrome folder is divided into components. Under each folder are content, locale and skin folders. Content contains all the JS and XUL files that define the structure and behaviour of the user interface. Locale contains text strings for specific languages (in DTD files), and Skin contains CSS files which define the appearance of the contents XUL files.
Hacking XULBefore getting started with the XUL widgets, I suggest you have an extended play with them first, create a test XUL document, and try embedding each in. This is especially important for trees, which are the most complicated widget to use. Also, have a play with boxes (boxes are used to contain other widgets, similar to GTK boxes I guess), they're fundamental to controlling the way your interface is displayed on screen. Relatively comprehensive (although sometimes out-of-date, beware!) documents can be found at mozilla.org's XPToolkit page.
Accessing Mozilla APIsOnce you've successfully created your UI and made it interactive, you'll probably want to interact in some way with the core of Mozilla (unless you've written your own component, in which case you'll want to interact with that as well). Accessing these components appears to differ in subtle ways depending on what you're using, but the general form is fairly similar - you access core components using a process called XPConnect. Again this isn't a tutorial, have a look at the JS files. After XPConnecting, you're normally left with an object that contains a lot of attributes and member functions you can tweak with JavaScript. For example, after XPConnecting to nsIEditorShell, your editorShell JavaScript variable can access all the scriptable methods and attributes listed in nsIEditorShell.idl
Where to find API DocumentationAPI documentation is fairly nonexistent at the moment, but if you XPConnect to an interface, the stuff you can use is described in the IDL (Interface Definition Language) file for that interface. Read existing code, and you'll get the general idea soon enough. For convenience, if you have the disk space, check out the SeaMonkey source code (see the Source Code page @mozilla.org), and then you can search through the IDL files locally, and use the actual source code to figure out what the functions do if need be. Otherwise, just search on LXR for the interface you need.
LocalisationWhenever you go to put a text string in a XUL file, stop. If this is for anything other than testing, it should be an entity, and it should be placed into a DTD file. Look at XUL files and DTD files for examples of how to do this. Why do we do this? To make it easy for people to translate into other languages. When they translate, they only need translate the DTD files, or use one of the programs that people have made to assist translation.
Useful Links
NewsgroupsSee the mozilla.org Community page for a full list of Newsgroups. Some are listed here:
IRCPoint your IRC client at irc.mozilla.org, and join #mozilla to join in the live Mozilla discussion! last updated 21/09/1999 |
|||
|
Copyright © 1998-1999 The Mozilla Organization.
Last modified September 26, 1999. |
|||