Chapter 7

XUL Overlays and XBL

"If you build systems and then reflect on what you build, you will see patterns in what you do." - Gamma, Helm, Johnson, Vlissides, Design Patterns, Addison-Wesley, Reading, Mass, 1995.

In software projects, the development of reusable components into modular software libraries helps save development time. Both reusability and extensibility are important concepts that can be used to make a software system flexible and less complex in the software development cycle. This chapter introduces how these concepts of code reuse and extensibility are applied to the XUL language with XUL Overlays and the XML Binding Language (XBL).

XUL Overlays are part of the core XUL language, and these files contain XUL content that can be reused over and over again by different XUL-based applications. When a XUL file references an overlay file, XUL content from that overlay file is dynamically inserted into that XUL application. Typically, a XUL Overlay file contains things that are used and shared repeatedly in many XUL applications, like toolbars with common buttons, menus with common menu items, and other widgets with common characteristics. By using XUL overlays, the developer can write XUL content once, so that it could be used repeatedly in an application.

Unlike XUL overlays, XBL is a separate language that is not dependent on XUL. XBL stands for the XML Binding Language, and it is a markup language for describing bindings that can be used to add to the behavior elements in any XML document. An XBL document can describe bindings that add new properties, methods, event handlers, and content that can be attached to XUL elements. When a XUL element is attached to such a binding described in an XBL file, that element is extended to include this new data and behavior. Bindings can be re-used throughout a code base of an application, or between applications, promoting the concepts of both re-use and extensibility in XML-based software projects. Although the XBL language is not limited to XUL, it is used repeatedly in the code for the Netscape/Mozilla Browser, and it is an exciting technology for dynamically changing document content.

Both XUL Overlays and XBL can be used in similar fashion - they can be used to create reusable software modules in XUL applications. In this chapter, we will describe the syntax of XUL overlays and XBL, and we will provide examples and demonstrations of how these mechanisms work. Both XUL overlays and XBL are easy to learn, and they can be valuable in any XUL project.