Toolbar context menu showing inside toolbarbutton's xul panel

余生颓废 提交于 2019-12-11 04:54:48

问题


I have a toolbarbutton that when clicked, shows a panel. When i right click the panel i'm getting the following:

This is the same context menu that shows when i click on the main toolbar or even the toolbarbuttons.

The xul is:

<toolbarpalette id="BrowserToolbarPalette">
  <toolbarbutton id="testToolbarIcon"
           image="chrome://myext/content/images/aicon.png"
           type="panel"
           class="toolbarbutton-1 chromeclass-toolbar-additional">
    <panel id="testPanel"
         type="arrow"
         level="parent">
      <vbox id="testbox" align="top" width="200" height="200">
        <label value="Test Label" />
        <textbox></textbox>
      </vbox>
    </panel>
  </toolbarbutton>        
</toolbarpalette>

Any idea on how to stop this behavior from passing to the panel?


回答1:


Adding an click event listener to the panel and .preventDefault() and/or .stopPropagation() should do the trick, if memory served right.

Another way is simply not to use a type="panel" button, put the panel somewhere else (a popupset) and open the panel from js using .openPopup(). To get the button state right, you need to do a button.open = true when the popup is shown, and revert that once it is hidden again (at least that is what the download-indicator button does).




回答2:


I have

<toolbarbutton id="search-button" label="Search" type="panel" oncommand="signage.onMenuItemCommand(event);" onclick="signage.emptyFn(event);" ondblclick="signage.emptyFn(event);"></toolbarbutton>

where

signage.emptyFn: function (event) {
    event.preventDefault();
    //event.stopPropagation();
},

And works fine!



来源:https://stackoverflow.com/questions/18553627/toolbar-context-menu-showing-inside-toolbarbuttons-xul-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!