XUL:XPath in Overlays

From MozillaWiki
Jump to navigation Jump to search

Problem

Currently, overlaid items are inserted by matching ids. The problem with this is that a lot of chrome does not give ids to elements, making it hard to extensions for example to extend the user interface. It also isn't very flexible - what if I want to overlay something to all menus in a document who have more than 5 menuitems?

Bug on this: https://bugzilla.mozilla.org/show_bug.cgi?id=253147

Proposal

Since we are dealing with XML, it makes sense to have XPath determine the node[s] that we want to overlay onto.

So rather than defining the overlay like this:

 <menu id="help-menu">
   <menupopup id="help-popup">
     <menuitem id="help-xul" label="Help on XUL" />
   </menupopup>
 </menu>

It could look like this:

 <overlayitem match="//menupopup[@id='help-popup']">
   <menuitem id="help-xul" label="Help on XUL" />
 </overlayitem>

This also seperates the matching part and the new content, making it easier to see what exactly is being added.

Overlays also allow to finetune the position the content is added to by using position/insertbefore/insertafter. Those could also perhaps support XPath, but that might be overkill.

--Doron 08:28, 7 Mar 2005 (PST)

This may also allow multiple applications of a single overlay element. Also, does XPath support something like "first match only"?

--Eyal 08:28, 7 Mar 2005 (PST)