Overlays are an important aspect of XUL, but this is a subject that Iíve barely mentioned in previous articles. Overlays can be used for a variety of purposes when designing/writing XUL applications and come in either explicit or dynamic flavors. Explicit overlays are used within your own application and form the basis of code modularization.
Overlays in XUL - Creating a dynamic overlay (Page 4 of 4 )
Creating dynamic overlays is very similar to creating explicit overlays; although this time the overlays do need to be registered fully with the chrome in order to instruct Mozilla to apply the overlay files to the target application. With this method, the source file of the application that has the overlay applied to it doesnít need to be modified. This makes it an excellent method of creating updates or add-ons to an application that are fully packaged and made available for distribution or download. It also means that you can create add-on components to Mozilla itself without modifying Mozillaís source code.
You could add a menuitem to one of Mozillaís menus in this way so that an application youíve written can be accessed easily. To do this, you first create the main overlay file, like you would any other overlay by starting with the XML declaration and the overlay container:
This simple little script calls the openDialog method and takes, most importantly, the relevant chrome URL and two additional parameters.
All you need now is the new menuitem that you want added to Mozilla and the closing tag:
The first code block lists the file that you are going to overlay, the second lists the file to be used as the overlay. Add these just before the closing </RDF:RDF> tag.
Finally, you need to browse to the Mozilla Chrome directory and delete the folder called "overlayinfo." This directory will be recreated when Mozilla is next launched, so launch Mozilla and go into the overlayinfo directory. There will be several folders in here depending on which Mozilla suite components are installed; if you go into the one called communicator, then into the content folder, youíll find an overlays.rdf file. Open this file in a text editor and if everything worked, there will be an Li statement that matches the one you just added to your applications contents.rdf file. One final check that it has worked of course is to open the Window menu in Mozilla to check that your overlaid menuitem appears and that it launches your application when selected.
In addition to adding content to Mozilla without altering the base files of the applications, this is the same mechanism that you can use to release additional or add-on content to your own XUL applications once they have been distributed. You could simply create a new XUL module for your application and then package it in an installer that adds the required files and the new contents.rdf file to the existing directory structure.
So as you can see, overlays are an important aspect of XUL that can be used to add modularity to the bigger applications you create or add to the functionality of either Mozilla itself, or applications that you write.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.