我想如何使用与Firefox窗口相同的自定义紧凑菜单创建 Firefox插件。 刚才我在Echofon看到了。这是图像,它看起来很棒!
所以,请告诉我,我们如何在插件窗口中创建这样的内容。
答案 0 :(得分:2)
我认为没有一个简单的解决方案。必须删除默认窗口标题栏(通过chromemargin
attribute)并将其替换为自己的(使用<xul:titlebar>
)。然后必须使用所有操作系统和主题(Windows XP常规,Windows XP经典主题,带有Aero的Vista / 7,没有Aero的Vista / 7,......)来确定其外观。您可以通过查看chrome://browser/skin/browser.css
,搜索“appmenu-button”和“titlebar”来获得所需代码量的印象。请记住,您只能看到一个操作系统的样式 - Firefox为不同的操作系统使用不同的主题。
我得到的一个例子主要是在Windows 7上使用Aero(下拉箭头需要被不同的图像替换,当窗口最大化时按钮位置仍然是错误的)。窗口本身(test.xul
)如下所示:
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="test.css" type="text/css"?>
<window
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Test window"
width="800"
height="500"
chromemargin="0,-1,-1,-1">
<titlebar id="titlebar" allowevents="true">
<button id="appmenu-button" type="menu" label="Test">
<menupopup/>
</button>
<spacer id="titlebar-spacer" flex="1"/>
<hbox id="titlebar-buttonbox">
<toolbarbutton class="titlebar-button" id="titlebar-min"
oncommand="window.minimize();"/>
<toolbarbutton class="titlebar-button" id="titlebar-max"
oncommand="window.windowState == 1 ? window.restore() : window.maximize();"/>
<toolbarbutton class="titlebar-button" id="titlebar-close"
oncommand="window.close();"/>
</hbox>
</titlebar>
<description flex="1">window content</description>
</window>
test.css
中的样式如下(主要是从browser.css
复制而来):
:root {
-moz-appearance: -moz-win-borderless-glass;
background-color: transparent;
}
#appmenu-button:hover:active,
#appmenu-button[open] {
border-radius: 0;
}
#appmenu-button {
-moz-appearance: none;
-moz-user-focus: ignore;
background-clip: padding-box;
border-radius: 0 0 4px 4px;
color: white;
text-shadow: 0 0 1px rgba(0,0,0,.7),
0 1px 1.5px rgba(0,0,0,.5);
font-weight: bold;
padding: 0 1.5em .05em;
margin: 2px 0 2px;
background-image: -moz-linear-gradient(rgb(247,182,82), rgb(215,98,10) 95%);
border: 2px solid rgba(83,42,6,.9);
border-top-style: none;
-moz-border-left-colors: rgba(255,255,255,.5) rgba(83,42,6,.9);
-moz-border-bottom-colors: rgba(255,255,255,.5) rgba(83,42,6,.9);
-moz-border-right-colors: rgba(255,255,255,.5) rgba(83,42,6,.9);
margin-bottom: -1px; /* compensate white outer border */
box-shadow: 0 1px 0 rgba(255,255,255,.25) inset,
0 0 2px 1px rgba(255,255,255,.25) inset;
}
#appmenu-button:hover:not(:active):not([open]) {
background-image: -moz-radial-gradient(center bottom, farthest-side, rgba(252,240,89,.5) 10%, rgba(252,240,89,0) 70%),
-moz-radial-gradient(center bottom, farthest-side, rgb(236,133,0), rgba(255,229,172,0)),
-moz-linear-gradient(rgb(246,170,69), rgb(209,74,0) 95%);
border-color: rgba(83,42,6,.9);
box-shadow: 0 1px 0 rgba(255,255,255,.1) inset,
0 0 2px 1px rgba(250,234,169,.7) inset,
0 -1px 0 rgba(250,234,169,.5) inset;
}
#appmenu-button:hover:active,
#appmenu-button[open] {
background-image: -moz-linear-gradient(rgb(246,170,69), rgb(209,74,0) 95%);
box-shadow: 0 2px 3px rgba(0,0,0,.4) inset,
0 1px 1px rgba(0,0,0,.2) inset;
}
#appmenu-button > .button-box {
border-style: none;
padding: 0px;
margin: 0px;
}
#titlebar-spacer {
pointer-events: none;
}
#titlebar-buttonbox {
-moz-appearance: -moz-window-button-box;
-moz-margin-end: 20px;
}
:root[sizemode="maximized"] #titlebar-buttonbox {
-moz-appearance: -moz-window-button-box-maximized;
}
#titlebar-min {
-moz-appearance: -moz-window-button-minimize;
}
#titlebar-max {
-moz-appearance: -moz-window-button-maximize;
}
:root[sizemode=maximized] #titlebar-max {
-moz-appearance: -moz-window-button-restore;
}
#titlebar-close {
-moz-appearance: -moz-window-button-close;
}
我用以下命令打开了窗口:
window.open("chrome://.../test.xul", "_blank", "chrome,all,centerscreen,resizable");
这是最终结果: