Bug 477256 - Implement menubar auto-hiding in toolkit. r=neil,enn

This commit is contained in:
Dão Gottwald 2009-06-13 08:03:02 +02:00
parent 0b7582d2b3
commit eea852f5dd
3 changed files with 148 additions and 5 deletions

View File

@ -92,10 +92,10 @@ function onUnload()
function finishToolbarCustomization()
{
gToolbox.customizing = false;
removeToolboxListeners();
unwrapToolbarItems();
persistCurrentSets();
gToolbox.customizing = false;
notifyParentComplete();
}

View File

@ -26,9 +26,18 @@
</field>
<!-- Set by customizeToolbar.js -->
<field name="customizing">
false
</field>
<property name="customizing">
<getter><![CDATA[
return this.getAttribute("customizing") == "true";
]]></getter>
<setter><![CDATA[
if (val)
this.setAttribute("customizing", "true");
else
this.removeAttribute("customizing");
return val;
]]></setter>
</property>
<constructor>
<![CDATA[
@ -154,7 +163,10 @@
}
node = node.nextSibling;
}
if ("currentSetChanged" in this)
this.currentSetChanged(currentSet);
return currentSet ? currentSet : "__empty";
]]>
</getter>
@ -201,6 +213,9 @@
}
}
if ("currentSetChanged" in this)
this.currentSetChanged(val);
return val;
]]>
</setter>
@ -272,6 +287,121 @@
</implementation>
</binding>
<binding id="toolbar-menubar-autohide"
extends="chrome://global/content/bindings/toolbar.xml#toolbar">
<implementation>
<constructor>
this._setInactive();
</constructor>
<field name="_inactiveTimeout">null</field>
<field name="_contextMenuListener"><![CDATA[({
toolbar: this,
contextMenu: null,
get active () !!this.contextMenu,
init: function (event) {
var node = event.target;
while (node != this.toolbar) {
if (node.localName == "menupopup")
return;
node = node.parentNode;
}
var contextMenuId = this.toolbar.getAttribute("context");
if (!contextMenuId)
return;
this.contextMenu = document.getElementById(contextMenuId);
if (!this.contextMenu)
return;
this.contextMenu.addEventListener("popupshown", this, false);
this.contextMenu.addEventListener("popuphiding", this, false);
this.toolbar.addEventListener("mousemove", this, false);
},
handleEvent: function (event) {
switch (event.type) {
case "popupshown":
this.toolbar.removeEventListener("mousemove", this, false);
break;
case "popuphiding":
case "mousemove":
this.toolbar._setInactiveAsync();
this.toolbar.removeEventListener("mousemove", this, false);
this.contextMenu.removeEventListener("popuphiding", this, false);
this.contextMenu.removeEventListener("popupshown", this, false);
this.contextMenu = null;
break;
}
}
})]]></field>
<method name="currentSetChanged">
<parameter name="aCurrentSet"/>
<body><![CDATA[
var defaultSet = this.getAttribute("defaultset");
if (!defaultSet || aCurrentSet == defaultSet) {
this.removeAttribute("customized");
return;
}
function normalize(aSet) {
return aSet.split(",").filter(function (element) {
return element != "separator" &&
element != "spacer" &&
element != "spring" &&
element != "__empty";
}).sort().join(",");
}
if (normalize(aCurrentSet) == normalize(defaultSet)) {
this.removeAttribute("customized");
return;
}
this.setAttribute("customized", "true");
]]></body>
</method>
<method name="_setInactive">
<body><![CDATA[
this.setAttribute("inactive", "true");
]]></body>
</method>
<method name="_setInactiveAsync">
<body><![CDATA[
this._inactiveTimeout = setTimeout(function (self) {
self._inactiveTimeout = null;
self._setInactive();
}, 0, this);
]]></body>
</method>
<method name="_setActive">
<body><![CDATA[
if (this._inactiveTimeout) {
clearTimeout(this._inactiveTimeout);
this._inactiveTimeout = null;
}
this.removeAttribute("inactive");
]]></body>
</method>
</implementation>
<handlers>
<handler event="DOMMenuBarActive" action="this._setActive();"/>
<handler event="popupshowing" action="this._setActive();"/>
<handler event="mousedown" button="2" action="this._contextMenuListener.init(event);"/>
<handler event="DOMMenuBarInactive"><![CDATA[
if (!this._contextMenuListener.active)
this._setInactiveAsync();
]]></handler>
</handlers>
</binding>
<binding id="toolbar-drag"
extends="chrome://global/content/bindings/toolbar.xml#toolbar">
<implementation>

View File

@ -239,6 +239,19 @@ toolbar[type="menubar"] {
min-height: 0 !important;
border: 0 !important;
}
%else
toolbar[type="menubar"][autohide="true"] {
-moz-binding: url("chrome://global/content/bindings/toolbar.xml#toolbar-menubar-autohide");
overflow: hidden;
}
toolbar[type="menubar"][autohide="true"]:not([customizable="true"])[inactive="true"],
toolbox:not([customizing="true"]) > toolbar[type="menubar"][autohide="true"][customizable="true"][inactive="true"]:not([customized="true"]) {
min-height: 0 !important;
height: 0 !important;
-moz-appearance: none !important;
border-style: none !important;
}
%endif
toolbarseparator {