2002-10-14 02:44:10 +04:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
|
|
|
|
<bindings id="menulistBindings"
|
|
|
|
xmlns="http://www.mozilla.org/xbl"
|
|
|
|
xmlns:html="http://www.w3.org/1999/xhtml"
|
|
|
|
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
xmlns:xbl="http://www.mozilla.org/xbl">
|
|
|
|
|
|
|
|
<binding id="menulist-base">
|
|
|
|
<resources>
|
|
|
|
<stylesheet src="chrome://global/skin/menulist.css"/>
|
|
|
|
</resources>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
<binding id="menulist" display="xul:menu"
|
2003-11-20 08:14:08 +03:00
|
|
|
extends="chrome://global/content/bindings/menulist.xml#menulist-base">
|
2003-08-17 15:09:50 +04:00
|
|
|
<content sizetopopup="pref">
|
2002-10-14 02:44:10 +04:00
|
|
|
<xul:hbox class="menulist-label-box" flex="1">
|
|
|
|
<xul:image class="menulist-icon" xbl:inherits="src"/>
|
|
|
|
<xul:label class="menulist-label" xbl:inherits="value=label,crop,accesskey" crop="right" flex="1"/>
|
|
|
|
</xul:hbox>
|
|
|
|
<xul:dropmarker class="menulist-dropmarker" type="menu"/>
|
|
|
|
<children includes="menupopup"/>
|
|
|
|
</content>
|
|
|
|
|
|
|
|
<handlers>
|
2004-12-01 07:48:44 +03:00
|
|
|
<handler event="command" phase="capturing">
|
|
|
|
<![CDATA[
|
|
|
|
// XXX see bug #196755
|
|
|
|
// originalTarget is workaround for arrowscrollbox retargeting bug
|
|
|
|
if (event.originalTarget.parentNode.parentNode == this)
|
|
|
|
this.selectedItem = event.originalTarget;
|
|
|
|
]]>
|
|
|
|
</handler>
|
2002-10-14 02:44:10 +04:00
|
|
|
|
|
|
|
<handler event="popupshowing">
|
|
|
|
<![CDATA[
|
2004-12-01 07:48:44 +03:00
|
|
|
// XXX see bug #196755
|
|
|
|
// originalTarget is workaround for arrowscrollbox retargeting bug
|
|
|
|
if (event.originalTarget.parentNode == this && this.selectedItem)
|
2002-10-14 02:44:10 +04:00
|
|
|
// Not ready for auto-setting the active child in hierarchies yet.
|
|
|
|
// For now, only do this when the outermost menupopup opens.
|
2003-08-17 15:09:50 +04:00
|
|
|
this.menuBoxObject.activeChild = this.selectedInternal;
|
2002-10-14 02:44:10 +04:00
|
|
|
]]>
|
|
|
|
</handler>
|
2004-12-01 21:59:12 +03:00
|
|
|
|
|
|
|
<handler event="keypress" phase="target">
|
|
|
|
<![CDATA[
|
|
|
|
this.menuBoxObject.activeChild = this.selectedInternal;
|
|
|
|
if (this.menuBoxObject.handleKeyPress(event))
|
|
|
|
this.menuBoxObject.activeChild.doCommand();
|
|
|
|
]]>
|
|
|
|
</handler>
|
2002-10-14 02:44:10 +04:00
|
|
|
</handlers>
|
|
|
|
|
2003-08-17 15:09:50 +04:00
|
|
|
<implementation implements="nsIDOMXULMenuListElement, nsIAccessibleProvider">
|
2002-10-14 02:44:10 +04:00
|
|
|
<constructor>
|
|
|
|
this.setInitialSelection()
|
|
|
|
</constructor>
|
|
|
|
|
|
|
|
<method name="setInitialSelection">
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2003-08-17 15:09:50 +04:00
|
|
|
var popup = this.menupopup;
|
|
|
|
if (popup) {
|
|
|
|
var arr = popup.getElementsByAttribute('selected', 'true');
|
|
|
|
|
2004-12-01 16:45:12 +03:00
|
|
|
if (!arr.item(0) && this.value)
|
2003-08-17 15:09:50 +04:00
|
|
|
arr = popup.getElementsByAttribute('value', this.value);
|
2002-10-14 02:44:10 +04:00
|
|
|
|
2004-12-01 16:45:12 +03:00
|
|
|
if (arr.item(0))
|
2003-08-17 15:09:50 +04:00
|
|
|
this.selectedItem = arr[0];
|
|
|
|
else
|
|
|
|
this.selectedIndex = 0;
|
2002-10-14 02:44:10 +04:00
|
|
|
}
|
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<property name="value" onget="return this.getAttribute('value');">
|
|
|
|
<setter>
|
|
|
|
<![CDATA[
|
2003-08-17 15:09:50 +04:00
|
|
|
var arr = null;
|
|
|
|
var popup = this.menupopup;
|
|
|
|
if (popup)
|
|
|
|
arr = popup.getElementsByAttribute('value', val);
|
2002-10-14 02:44:10 +04:00
|
|
|
|
2004-12-01 16:45:12 +03:00
|
|
|
if (arr && arr.item(0))
|
2002-10-14 02:44:10 +04:00
|
|
|
this.selectedItem = arr[0];
|
|
|
|
else
|
|
|
|
this.setAttribute('value', val);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
]]>
|
|
|
|
</setter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<property name="crop" onset="this.setAttribute('crop',val); return val;"
|
|
|
|
onget="return this.getAttribute('crop');"/>
|
|
|
|
<property name="src" onset="this.setAttribute('src',val); return val;"
|
|
|
|
onget="return this.getAttribute('src');"/>
|
2004-12-01 21:59:12 +03:00
|
|
|
<property name="label" readonly="true" onget="return this.getAttribute('label');"/>
|
2002-10-14 02:44:10 +04:00
|
|
|
<property name="disabled" onset="if (val) this.setAttribute('disabled',true);
|
|
|
|
else this.removeAttribute('disabled');
|
|
|
|
return val;"
|
|
|
|
onget="return this.hasAttribute('disabled');"/>
|
|
|
|
|
2003-08-17 15:09:50 +04:00
|
|
|
<property name="open" onset="this.menuBoxObject.openMenu(val);
|
|
|
|
return val;"
|
|
|
|
onget="return this.hasAttribute('open');"/>
|
|
|
|
|
|
|
|
<property name="menupopup" readonly="true">
|
|
|
|
<getter>
|
|
|
|
<![CDATA[
|
|
|
|
var popup = this.firstChild;
|
|
|
|
while (popup && popup.localName != "menupopup")
|
|
|
|
popup = popup.nextSibling;
|
|
|
|
return popup;
|
|
|
|
]]>
|
|
|
|
</getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<field name="menuBoxObject" readonly="true">
|
|
|
|
this.boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject)
|
|
|
|
</field>
|
2002-10-14 02:44:10 +04:00
|
|
|
|
|
|
|
<field name="selectedInternal">
|
|
|
|
null
|
|
|
|
</field>
|
|
|
|
|
|
|
|
<property name="selectedIndex">
|
|
|
|
<getter>
|
|
|
|
<![CDATA[
|
|
|
|
// Quick and dirty. We won't deal with hierarchical menulists yet.
|
2003-08-17 15:09:50 +04:00
|
|
|
if (!this.selectedItem ||
|
|
|
|
!this.selectedInternal.parentNode ||
|
|
|
|
this.selectedInternal.parentNode.parentNode != this)
|
2002-10-14 02:44:10 +04:00
|
|
|
return -1;
|
|
|
|
|
2003-08-17 15:09:50 +04:00
|
|
|
var children = this.selectedInternal.parentNode.childNodes;
|
|
|
|
var i = children.length;
|
|
|
|
while (i--)
|
|
|
|
if (children[i] == this.selectedInternal)
|
|
|
|
break;
|
2002-10-14 02:44:10 +04:00
|
|
|
|
2003-08-17 15:09:50 +04:00
|
|
|
return i;
|
2002-10-14 02:44:10 +04:00
|
|
|
]]>
|
|
|
|
</getter>
|
|
|
|
<setter>
|
|
|
|
<![CDATA[
|
2003-08-17 15:09:50 +04:00
|
|
|
var popup = this.menupopup;
|
|
|
|
if (popup && 0 <= val && val < popup.childNodes.length)
|
|
|
|
this.selectedItem = popup.childNodes[val];
|
|
|
|
else
|
2002-10-14 02:44:10 +04:00
|
|
|
this.selectedItem = null;
|
|
|
|
return val;
|
|
|
|
]]>
|
|
|
|
</setter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<property name="selectedItem">
|
|
|
|
<getter>
|
|
|
|
<![CDATA[
|
|
|
|
return this.selectedInternal;
|
|
|
|
]]>
|
|
|
|
</getter>
|
|
|
|
<setter>
|
|
|
|
<![CDATA[
|
|
|
|
if (this.selectedInternal == val)
|
|
|
|
return val;
|
|
|
|
|
|
|
|
if (this.selectedInternal)
|
|
|
|
this.selectedInternal.removeAttribute('selected');
|
|
|
|
|
|
|
|
this.selectedInternal = val;
|
|
|
|
if (!this.selectedInternal) {
|
|
|
|
this.removeAttribute('value');
|
|
|
|
this.removeAttribute('src');
|
|
|
|
this.removeAttribute('label');
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
val.setAttribute('selected', 'true');
|
|
|
|
|
|
|
|
this.setAttribute('value', val.getAttribute('value'));
|
|
|
|
this.setAttribute('src', val.getAttribute('src'));
|
|
|
|
this.setAttribute('label', val.getAttribute('label'));
|
|
|
|
|
|
|
|
return val;
|
|
|
|
]]>
|
|
|
|
</setter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<method name="appendItem">
|
|
|
|
<parameter name="label"/>
|
|
|
|
<parameter name="value"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2003-08-17 15:09:50 +04:00
|
|
|
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
var popup = this.menupopup ||
|
|
|
|
this.appendChild(document.createElementNS(XULNS, "menupopup"));
|
|
|
|
var item = document.createElementNS(XULNS, "menuitem");
|
|
|
|
item.setAttribute("label", label);
|
|
|
|
item.setAttribute("value", value);
|
|
|
|
popup.appendChild(item);
|
|
|
|
return item;
|
2002-10-14 02:44:10 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="insertItemAt">
|
|
|
|
<parameter name="index"/>
|
|
|
|
<parameter name="label"/>
|
|
|
|
<parameter name="value"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2003-08-17 15:09:50 +04:00
|
|
|
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
|
|
|
var popup = this.menupopup ||
|
|
|
|
this.appendChild(document.createElementNS(XULNS, "menupopup"));
|
|
|
|
var item = document.createElementNS(XULNS, "menuitem");
|
|
|
|
item.setAttribute("label", label);
|
|
|
|
item.setAttribute("value", value);
|
|
|
|
if (index < popup.childNodes.length)
|
|
|
|
popup.insertBefore(item, popup.childNodes[index]);
|
|
|
|
else
|
|
|
|
popup.appendChild(item);
|
|
|
|
return item;
|
2002-10-14 02:44:10 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="removeItemAt">
|
|
|
|
<parameter name="index"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2003-08-17 15:09:50 +04:00
|
|
|
var popup = this.menupopup;
|
|
|
|
if (popup && 0 <= index && index < popup.childNodes.length) {
|
2002-10-14 02:44:10 +04:00
|
|
|
var remove = popup.childNodes[index];
|
2003-08-17 15:09:50 +04:00
|
|
|
popup.removeChild(remove);
|
2002-10-14 02:44:10 +04:00
|
|
|
return remove;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2003-08-17 15:09:50 +04:00
|
|
|
<method name="removeAllItems">
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
|
|
|
this.selectedInternal = null;
|
|
|
|
var popup = this.menupopup;
|
|
|
|
if (popup)
|
|
|
|
this.removeChild(popup);
|
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2002-10-14 02:44:10 +04:00
|
|
|
<property name="accessible">
|
|
|
|
<getter>
|
|
|
|
<![CDATA[
|
|
|
|
var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
|
|
|
|
return accService.createXULComboboxAccessible(this);
|
|
|
|
]]>
|
|
|
|
</getter>
|
|
|
|
</property>
|
|
|
|
</implementation>
|
|
|
|
</binding>
|
|
|
|
|
2003-11-20 08:14:08 +03:00
|
|
|
<binding id="menulist-editable" extends="chrome://global/content/bindings/menulist.xml#menulist">
|
2003-08-17 15:09:50 +04:00
|
|
|
<content sizetopopup="pref">
|
|
|
|
<xul:hbox class="menulist-editable-box textbox-input-box" xbl:inherits="context" flex="1">
|
|
|
|
<html:input class="menulist-editable-input" flex="1" anonid="input" allowevents="true"
|
2002-10-14 02:44:10 +04:00
|
|
|
xbl:inherits="value=label,disabled"/>
|
|
|
|
</xul:hbox>
|
|
|
|
<xul:dropmarker class="menulist-dropmarker" type="menu"/>
|
|
|
|
<children includes="menupopup"/>
|
|
|
|
</content>
|
|
|
|
|
|
|
|
<implementation>
|
|
|
|
<constructor><![CDATA[
|
|
|
|
this.setInitialSelection();
|
|
|
|
]]></constructor>
|
|
|
|
|
|
|
|
<method name="_selectInputFieldValueInList">
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
|
|
|
if (this.hasAttribute("disableautoselect"))
|
|
|
|
return "";
|
|
|
|
|
|
|
|
// Find and select the menuitem that matches inputField's "value"
|
2003-08-17 15:09:50 +04:00
|
|
|
var arr = null;
|
|
|
|
var popup = this.menupopup;
|
2002-10-14 02:44:10 +04:00
|
|
|
|
2003-08-17 15:09:50 +04:00
|
|
|
if (popup)
|
|
|
|
arr = popup.getElementsByAttribute('label', this.inputField.value);
|
2002-10-14 02:44:10 +04:00
|
|
|
|
2004-12-01 19:21:02 +03:00
|
|
|
this.setSelectionInternal(arr ? arr.item(0) : null);
|
2002-10-14 02:44:10 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="setSelectionInternal">
|
|
|
|
<parameter name="val"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
|
|
|
// This is called internally to set selected item
|
|
|
|
// without triggering infinite loop
|
|
|
|
// when using selectedItem's setter
|
|
|
|
if (this.selectedInternal == val)
|
|
|
|
return val;
|
|
|
|
|
|
|
|
if (this.selectedInternal)
|
|
|
|
this.selectedInternal.removeAttribute('selected');
|
|
|
|
|
|
|
|
this.selectedInternal = val;
|
|
|
|
|
2003-08-17 15:09:50 +04:00
|
|
|
if (val)
|
|
|
|
val.setAttribute('selected', 'true');
|
2002-10-14 02:44:10 +04:00
|
|
|
|
2003-08-17 15:09:50 +04:00
|
|
|
//Do NOT change the "value", which is owned by inputField
|
2002-10-14 02:44:10 +04:00
|
|
|
return val;
|
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2003-08-17 15:09:50 +04:00
|
|
|
<field name="mInputField">null</field>
|
|
|
|
|
|
|
|
<property name="inputField" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
if (!this.mInputField)
|
|
|
|
this.mInputField = document.getAnonymousElementByAttribute(this, "anonid", "input");
|
|
|
|
return this.mInputField;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2002-10-14 02:44:10 +04:00
|
|
|
<property name="label" onset="this.inputField.value = val; return val;"
|
|
|
|
onget="return this.inputField.value;"/>
|
|
|
|
|
|
|
|
<property name="value" onget="return this.inputField.value;">
|
|
|
|
<setter>
|
|
|
|
<![CDATA[
|
|
|
|
// Override menulist's value setter to refer to the inputField's value
|
|
|
|
// (Allows using "menulist.value" instead of "menulist.inputField.value")
|
|
|
|
this.inputField.value = val;
|
|
|
|
this.setAttribute('value', val);
|
|
|
|
this.setAttribute('label', val);
|
|
|
|
this._selectInputFieldValueInList();
|
|
|
|
return val;
|
|
|
|
]]>
|
|
|
|
</setter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<property name="selectedItem">
|
|
|
|
<getter>
|
|
|
|
<![CDATA[
|
|
|
|
// Make sure internally-selected item
|
|
|
|
// is in sync with inputField.value
|
|
|
|
this._selectInputFieldValueInList();
|
|
|
|
return this.selectedInternal;
|
|
|
|
]]>
|
|
|
|
</getter>
|
|
|
|
<setter>
|
|
|
|
<![CDATA[
|
|
|
|
// This doesn't touch inputField.value or "value" and "label" attributes
|
|
|
|
this.setSelectionInternal(val);
|
|
|
|
|
|
|
|
if (!this.selectedInternal) {
|
|
|
|
this.inputField.value = "";
|
|
|
|
this.removeAttribute('value');
|
|
|
|
this.removeAttribute('label');
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Editable menulist uses "label" as its "value"
|
|
|
|
var label = val.getAttribute('label');
|
|
|
|
this.inputField.value = label;
|
|
|
|
this.setAttribute('value', label);
|
|
|
|
this.setAttribute('label', label);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
]]>
|
|
|
|
</setter>
|
|
|
|
</property>
|
|
|
|
<property name="disableautoselect"
|
|
|
|
onset="if (val) this.setAttribute('disableautoselect','true');
|
|
|
|
else this.removeAttribute('disableautoselect'); return val;"
|
|
|
|
onget="return this.hasAttribute('disableautoselect');"/>
|
|
|
|
|
2003-08-17 15:09:50 +04:00
|
|
|
<method name="select">
|
|
|
|
<body>
|
|
|
|
this.inputField.select();
|
|
|
|
</body>
|
|
|
|
</method>
|
2002-10-14 02:44:10 +04:00
|
|
|
</implementation>
|
|
|
|
|
|
|
|
<handlers>
|
|
|
|
<handler event="focus" phase="capturing">
|
2003-08-17 15:09:50 +04:00
|
|
|
<![CDATA[
|
|
|
|
if (!this.hasAttribute('focused')) {
|
|
|
|
if (document.commandDispatcher.focusedElement != this.inputField)
|
|
|
|
this.inputField.focus();
|
|
|
|
this.setAttribute('focused','true');
|
|
|
|
}
|
|
|
|
]]>
|
2002-10-14 02:44:10 +04:00
|
|
|
</handler>
|
|
|
|
|
|
|
|
<handler event="blur" phase="capturing">
|
2003-08-17 15:09:50 +04:00
|
|
|
<![CDATA[
|
2002-10-14 02:44:10 +04:00
|
|
|
this.removeAttribute('focused');
|
2003-08-17 15:09:50 +04:00
|
|
|
]]>
|
2002-10-14 02:44:10 +04:00
|
|
|
</handler>
|
|
|
|
|
|
|
|
<handler event="popupshowing">
|
|
|
|
<![CDATA[
|
2003-08-17 15:09:50 +04:00
|
|
|
// editable menulists elements aren't in the focus order,
|
|
|
|
// so when the popup opens we need to force the focus to the inputField
|
2004-12-01 07:48:44 +03:00
|
|
|
// XXX see bug #196755
|
|
|
|
// originalTarget is workaround for arrowscrollbox retargeting bug
|
|
|
|
if (event.originalTarget.parentNode == this) {
|
2002-10-14 02:44:10 +04:00
|
|
|
if (document.commandDispatcher.focusedElement != this.inputField)
|
|
|
|
this.inputField.focus();
|
|
|
|
|
2003-08-17 15:09:50 +04:00
|
|
|
if (this.selectedItem)
|
2002-10-14 02:44:10 +04:00
|
|
|
// Not ready for auto-setting the active child in hierarchies yet.
|
|
|
|
// For now, only do this when the outermost menupopup opens.
|
2003-08-17 15:09:50 +04:00
|
|
|
this.menuBoxObject.activeChild = this.selectedInternal;
|
2002-10-14 02:44:10 +04:00
|
|
|
}
|
|
|
|
]]>
|
|
|
|
</handler>
|
|
|
|
|
|
|
|
<handler event="keypress">
|
|
|
|
<![CDATA[
|
2003-08-17 15:09:50 +04:00
|
|
|
// open popup if key is up arrow, down arrow, or F4
|
|
|
|
if (!event.ctrlKey && !event.shiftKey) {
|
|
|
|
if (event.keyCode == KeyEvent.DOM_VK_UP ||
|
|
|
|
event.keyCode == KeyEvent.DOM_VK_DOWN ||
|
|
|
|
(event.keyCode == KeyEvent.DOM_VK_F4 && !event.altKey)) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.open = true;
|
|
|
|
}
|
2002-10-14 02:44:10 +04:00
|
|
|
}
|
|
|
|
]]>
|
|
|
|
</handler>
|
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
<binding id="menulist-compact" display="xul:menu"
|
2003-11-20 08:14:08 +03:00
|
|
|
extends="chrome://global/content/bindings/menulist.xml#menulist">
|
2003-08-17 15:09:50 +04:00
|
|
|
<content sizetopopup="false">
|
2002-10-14 02:44:10 +04:00
|
|
|
<xul:dropmarker class="menulist-dropmarker" type="menu"/>
|
|
|
|
<xul:image class="menulist-icon" xbl:inherits="src"/>
|
|
|
|
<xul:label class="menulist-label" xbl:inherits="value=label,crop,accesskey" crop="right" flex="1"/>
|
|
|
|
<children includes="menupopup"/>
|
|
|
|
</content>
|
|
|
|
</binding>
|
2004-12-01 07:48:44 +03:00
|
|
|
|
2002-10-14 02:44:10 +04:00
|
|
|
</bindings>
|