To anonymous element add pseudo element and cursor style and event listeners

前端 未结 1 1523
忘掉有多难
忘掉有多难 2021-01-22 09:49

I have this anonymous element in the toolbarbutton xul element. It\'s a xul:image. I want to give it a pseudo element (:before, :aft

相关标签:
1条回答
  • 2021-01-22 10:08

    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.

    0 讨论(0)
提交回复
热议问题