【发布时间】:2015-06-04 09:33:58
【问题描述】:
我正在开发一个 Firefox 扩展,在其中我对 browser.xul 进行了各种更改以自定义 Firefox 的 UI。默认情况下,Firefox 的菜单栏被禁用/不可见。我希望它始终显示菜单栏工具栏。 仅供参考,我禁用了工具栏上的右键单击,该工具栏通常会显示一个上下文菜单,其中可以使菜单栏可见或消失。
有什么方法可以进行这个设置吗?
【问题讨论】:
标签: firefox firefox-addon xul xpi
我正在开发一个 Firefox 扩展,在其中我对 browser.xul 进行了各种更改以自定义 Firefox 的 UI。默认情况下,Firefox 的菜单栏被禁用/不可见。我希望它始终显示菜单栏工具栏。 仅供参考,我禁用了工具栏上的右键单击,该工具栏通常会显示一个上下文菜单,其中可以使菜单栏可见或消失。
有什么方法可以进行这个设置吗?
【问题讨论】:
标签: firefox firefox-addon xul xpi
我找到了这个条目,因为我正在寻找一种解决方案来显示总是“最小化”的工具栏,所以我不得不点击“更多工具”,然后点击工具(例如 ublock)。
我的解决方案是转到about:config 并将值browser.chrome.toolbar_style(原为“2”)更改为“1”。重新启动 Firefox 后,所有工具再次可见。将其改回“2”并重新启动 Firefox 仍然显示所有工具.. 奇怪的行为。
【讨论】:
这不是一个解决方案,而是一个解决方案的开始。
找出如何设置一个比这个更重要的样式表:
看起来当inactive=true属性设置在它上面chrome://global/content/xul.css第289行它得到一个css重要的高度为0。我尝试用我自己的高度注册一个样式表
This is whats applied when `inactive=true` attribute is on it:
toolbar[type="menubar"][autohide="true"][inactive="true"]:not([customizing="true"]) {
min-height: 0 !important;
height: 0 !important;
-moz-appearance: none !important;
border-style: none !important;
}
我试过这个,但我的重要性并没有压倒这个,这个页面可能值得一读,它关于 css 顺序优先级我认为可以这样做:http://hungred.com/useful-information/css-priority-order-tips-tricks/
我尝试了这段代码,但它并不重要:
// globals
Cu.import('resource://gre/modules/Services.jsm');
var sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService);
try {
sss.unregisterSheet(cssUri, sss.AUTHOR_SHEET);
} catch (ignore) {}
var cssUri;
var css = 'toolbar[type="menubar"][autohide="true"][inactive="true"]:not([customizing="true"]) { height: 50px !important; min-height: 50px !important;';
var newURIParam = {
aURL: 'data:text/css,' + encodeURIComponent(css),
aOriginCharset: null,
aBaseURI: null
};
var cssUri = Services.io.newURI(newURIParam.aURL, newURIParam.aOriginCharset, newURIParam.aBaseURI);
sss.loadAndRegisterSheet(cssUri, sss.AUTHOR_SHEET);
我还尝试了var css = '#toolbar-menubar[type="menubar"][autohide="true"][inactive="true"]:not([customizing="true"]) { height: 50px !important; min-height: 50px !important;';,注意我如何使用#toolbar-menubar id 而不是标签选择器,id 具有最高的重要性,但即使我在它之后保留了选择性,它也不起作用。
突变观察者,每当附加了 inactive=true 时,将其删除。这肯定会火,不假思索。不过我认为 CSS 选项会更受欢迎,因为它可以提供更好的性能。
【讨论】:
我试过了,效果很好,
我已经编辑了browser.js和gBrowserInit函数内部onLoad函数我在整个UI加载完成后添加了以下代码sn-p。
let toolbar = window.document.getElementById("toolbar-menubar");
if (toolbar) {
window.setToolbarVisibility(toolbar, true, true);
}
【讨论】: