Layer XUL Elements/Images/Backgrounds in Firefox 3 Extensions Using Stack
While working on the Read It Later Firefox Extension, I wanted a way to layer multiple background images on a toolbar button so I could create a nice looking notification indicator like on the iPhone. (Note I opt-ed later to use a simpler look, but this method might still be helpful for other applications).
In order to make this work you’ll need to familarize yourself with XBL and XUL Stacks. XBL allows you to essentially reconfigure how an XUL element works/looks.
In this case, we’ll use XBL to replace a normal ToolbarButton into a Stack Element.
So first you’ll need your toolbarbutton added to your XUL overlay:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="toolbarbutton"
display="xul:menu"
extends="chrome://global/content/bindings/button.xml#menu-button-base">
<resources>
<stylesheet src="chrome://global/skin/toolbarbutton.css" />
</resources>
<content>
<xul:toolbarbutton
class="buttonstack"
anonid="button"
flex="1"
allowevents="true"
xbl:inherits="disabled,crop,image,label,accesskey,command,align,
dir,pack,orient,toolbarmode,buttonstyle,status,notifyNumber" />
</content>
</binding>
<binding id="buttonstack">
<content>
<children>
<xul:stack
align="center"
pack="center"
xbl:inherits="allowevents">
<xul:image src="chrome://urextension/skin/buttonimage.png" />
<xul:image src="chrome://urextension/skin/number_circle.png" />
<xul:label value="" xbl:inherits="value=notifyNumber,allowevents" />
</xul:stack>
</children>
</content>
</binding>
</bindings>
#tButton {
-moz-binding: url("chrome://urextension/content/yourxblfile.xml#toolbarbutton");
}
.buttonstack {
-moz-binding: url("chrome://urextension/content/yourxblfile.xml#buttonstack");
}
Replace Standard Menupop in XUL
I came across a time I needed to open a different element then a standard popup menu when clicking the dropdown selector on a toolbar button. I wanted to open a panel instead. To open a different element and hide the popup you can do something similar to this: