I have this anonymous element in the toolbarbutton
xul element. It's a xul:image
. I want to give it a pseudo element (:before
, :after
). And on hover I want to give it cursor:pointer
style. I also want to addEventListener('click', ...)
it. However none of this works.
I even modified the XBL to inject my own stack element and then try this stuff on the stack element but it just doesn't work.
Inspecting the anonymous elements DOM Inspector add-on. (I'm trying to set point on this element and give it a pseudo element and give it onMouseDown functionality)
It doesn't seem like these nested, anonymous xul:image
nodes support (::before
) pseudo-elements at all. Or maybe it is because the toolbarbutton
binding is display="xul:button"
... Somewhere deep inside the layout engine the parent element outright refused to adopt the generated ::before
pseudo-element, my debugger says. Remember that XUL
!= HTML
.
However, you can bind and/or rebind stuff to a new binding.
I used this CSS to re-bind and style the sync button (analog to your example from the question comments, but not meant to be a pixel-perfect reproduction):
#PanelUI-fxa-status {
-moz-binding: url(toolbarbutton.xml#toolbarbutton);
}
#PanelUI-fxa-status .toolbarbutton-badge {
list-style-image: url(chrome://browser/skin/places/query.png);
transform: translate(8px,8px) scale(0.7);
border: 1px solid red;
}
And the new binding, based on the default binding:
<?xml version="1.0"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<bindings
xmlns="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:xbl="http://www.mozilla.org/xbl">
<binding id="toolbarbutton" display="xul:button" role="xul:toolbarbutton"
extends="chrome://global/content/bindings/button.xml#button-base">
<resources>
<stylesheet src="chrome://global/skin/toolbarbutton.css"/>
</resources>
<content>
<children includes="observes|template|menupopup|panel|tooltip"/>
<xul:stack>
<xul:image class="toolbarbutton-icon" xbl:inherits="validate,src=bage,label"/>
<xul:image class="toolbarbutton-badge" xbl:inherits="validate,src=image,label"/>
</xul:stack>
<xul:label class="toolbarbutton-text" crop="right" flex="1"
xbl:inherits="value=label,accesskey,crop,wrap"/>
<xul:label class="toolbarbutton-multiline-text" flex="1"
xbl:inherits="xbl:text=label,accesskey,wrap"/>
</content>
</binding>
</bindings>
You could either set the badge with CSS, as I did, or using <toolbarbutton ... badge="{url}"/>
(i.e. the src=badge
inheritance in the binding).
Regarding the addEventListener
/cursor
stuff: It is not quite clear here what exactly you are asking for?
You can use all the usual methods with the toolbar button (addEventListener
, command=
/oncommand=
, ...), but not with child elements of it.
You can use cursor:
styles with the toolbarbutton
, but not with child elements of it.
Both are due to display="xul:button"
in the binding. If you don't want that, you'll need to modify the binding not to use a display=
and fix any stuff that breaks.
来源:https://stackoverflow.com/questions/24396380/to-anonymous-element-add-pseudo-element-and-cursor-style-and-event-listeners