gecko-dev/toolkit/content/widgets/listbox.xml

1146 lines
35 KiB
XML
Raw Normal View History

2002-10-13 22:44:10 +00:00
<?xml version="1.0"?>
2012-05-21 11:12:37 +00:00
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
2002-10-13 22:44:10 +00:00
<bindings id="listboxBindings"
xmlns="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:xbl="http://www.mozilla.org/xbl">
2002-10-13 22:44:10 +00:00
<!--
Interface binding that is base for bindings of xul:listbox and
xul:richlistbox elements. This binding assumes that successors bindings
will implement the following properties and methods:
/** Return the number of items */
readonly itemCount
2002-10-13 22:44:10 +00:00
/** Return index of given item
* @param aItem - given item element */
getIndexOfItem(aItem)
2002-10-13 22:44:10 +00:00
/** Return item at given index
* @param aIndex - index of item element */
getItemAtIndex(aIndex)
2002-10-13 22:44:10 +00:00
/** Return count of item elements */
getRowCount()
2002-10-13 22:44:10 +00:00
/** Return count of visible item elements */
getNumberOfVisibleRows()
2002-10-13 22:44:10 +00:00
/** Return index of first visible item element */
getIndexOfFirstVisibleRow()
/** Return true if item of given index is visible
* @param aIndex - index of item element
*
* @note XXX: this method should be removed after bug 364612 is fixed
*/
ensureIndexIsVisible(aIndex)
2002-10-13 22:44:10 +00:00
/** Return true if item element is visible
* @param aElement - given item element */
ensureElementIsVisible(aElement)
2002-10-13 22:44:10 +00:00
/** Scroll list control to make visible item of given index
* @param aIndex - index of item element
*
* @note XXX: this method should be removed after bug 364612 is fixed
*/
scrollToIndex(aIndex)
2002-10-13 22:44:10 +00:00
/** Create item element and append it to the end of listbox
* @param aLabel - label of new item element
* @param aValue - value of new item element */
appendItem(aLabel, aValue)
2002-10-13 22:44:10 +00:00
/** Create item element and insert it to given position
* @param aIndex - insertion position
* @param aLabel - label of new item element
* @param aValue - value of new item element */
insertItemAt(aIndex, aLabel, aValue)
2002-10-13 22:44:10 +00:00
/** Scroll up/down one page
* @param aDirection - specifies scrolling direction, should be either -1 or 1
* @return the number of elements the selection scrolled
*/
scrollOnePage(aDirection)
/** Fire "select" event */
_fireOnSelect()
-->
<binding id="listbox-base" role="xul:listbox"
extends="chrome://global/content/bindings/general.xml#basecontrol">
<implementation implements="nsIDOMXULMultiSelectControlElement">
<field name="_lastKeyTime">0</field>
<field name="_incrementalString">""</field>
<!-- nsIDOMXULSelectControlElement -->
<property name="selectedItem"
onset="this.selectItem(val);">
<getter>
<![CDATA[
2002-10-13 22:44:10 +00:00
return this.selectedItems.length > 0 ? this.selectedItems[0] : null;
]]>
</getter>
2002-10-13 22:44:10 +00:00
</property>
<property name="selectedIndex">
2002-10-13 22:44:10 +00:00
<getter>
<![CDATA[
if (this.selectedItems.length > 0)
return this.getIndexOfItem(this.selectedItems[0]);
return -1;
]]>
2002-10-13 22:44:10 +00:00
</getter>
<setter>
<![CDATA[
if (val >= 0) {
this.selectItem(this.getItemAtIndex(val));
} else {
this.clearSelection();
this.currentItem = null;
}
]]>
2002-10-13 22:44:10 +00:00
</setter>
</property>
<property name="value">
<getter>
2002-10-13 22:44:10 +00:00
<![CDATA[
if (this.selectedItems.length > 0)
return this.selectedItem.value;
return null;
2002-10-13 22:44:10 +00:00
]]>
</getter>
<setter>
2002-10-13 22:44:10 +00:00
<![CDATA[
var kids = this.getElementsByAttribute("value", val);
if (kids && kids.item(0))
this.selectItem(kids[0]);
return val;
2002-10-13 22:44:10 +00:00
]]>
</setter>
</property>
2002-10-13 22:44:10 +00:00
<method name="removeItemAt">
<parameter name="index"/>
<body>
<![CDATA[
var remove = this.getItemAtIndex(index);
2002-10-13 22:44:10 +00:00
if (remove)
this.removeChild(remove);
return remove;
]]>
</body>
</method>
<!-- nsIDOMXULMultiSelectControlElement -->
<property name="selType"
onget="return this.getAttribute('seltype');"
onset="this.setAttribute('seltype', val); return val;"/>
2002-10-13 22:44:10 +00:00
<property name="currentItem" onget="return this._currentItem;">
<setter>
if (this._currentItem == val)
return val;
2002-10-13 22:44:10 +00:00
if (this._currentItem)
this._currentItem.current = false;
this._currentItem = val;
if (val)
val.current = true;
2002-10-13 22:44:10 +00:00
return val;
</setter>
</property>
<property name="currentIndex">
<getter>
return this.currentItem ? this.getIndexOfItem(this.currentItem) : -1;
</getter>
<setter>
<![CDATA[
if (val >= 0)
this.currentItem = this.getItemAtIndex(val);
else
this.currentItem = null;
]]>
</setter>
</property>
<field name="selectedItems">[]</field>
2002-10-13 22:44:10 +00:00
<method name="addItemToSelection">
<parameter name="aItem"/>
2002-10-13 22:44:10 +00:00
<body>
<![CDATA[
if (this.selType != "multiple" && this.selectedCount)
return;
if (aItem.selected)
2002-10-13 22:44:10 +00:00
return;
this.selectedItems.push(aItem);
aItem.selected = true;
2002-10-13 22:44:10 +00:00
this._fireOnSelect();
]]>
</body>
</method>
2002-10-13 22:44:10 +00:00
<method name="removeItemFromSelection">
<parameter name="aItem"/>
2002-10-13 22:44:10 +00:00
<body>
<![CDATA[
if (!aItem.selected)
2002-10-13 22:44:10 +00:00
return;
2002-10-13 22:44:10 +00:00
for (var i = 0; i < this.selectedItems.length; ++i) {
if (this.selectedItems[i] == aItem) {
2002-10-13 22:44:10 +00:00
this.selectedItems.splice(i, 1);
aItem.selected = false;
2002-10-13 22:44:10 +00:00
break;
}
}
2002-10-13 22:44:10 +00:00
this._fireOnSelect();
]]>
</body>
</method>
2002-10-13 22:44:10 +00:00
<method name="toggleItemSelection">
<parameter name="aItem"/>
2002-10-13 22:44:10 +00:00
<body>
<![CDATA[
if (aItem.selected)
this.removeItemFromSelection(aItem);
2002-10-13 22:44:10 +00:00
else
this.addItemToSelection(aItem);
2002-10-13 22:44:10 +00:00
]]>
</body>
</method>
2002-10-13 22:44:10 +00:00
<method name="selectItem">
<parameter name="aItem"/>
2002-10-13 22:44:10 +00:00
<body>
<![CDATA[
if (!aItem)
2002-10-13 22:44:10 +00:00
return;
if (this.selectedItems.length == 1 && this.selectedItems[0] == aItem)
2002-10-13 22:44:10 +00:00
return;
2002-10-13 22:44:10 +00:00
this._selectionStart = null;
2002-10-13 22:44:10 +00:00
var suppress = this._suppressOnSelect;
this._suppressOnSelect = true;
this.clearSelection();
this.addItemToSelection(aItem);
this.currentItem = aItem;
2002-10-13 22:44:10 +00:00
this._suppressOnSelect = suppress;
this._fireOnSelect();
]]>
</body>
</method>
2002-10-13 22:44:10 +00:00
<method name="selectItemRange">
<parameter name="aStartItem"/>
<parameter name="aEndItem"/>
2002-10-13 22:44:10 +00:00
<body>
<![CDATA[
if (this.selType != "multiple")
return;
if (!aStartItem)
aStartItem = this._selectionStart ?
this._selectionStart : this.currentItem;
if (!aStartItem)
aStartItem = aEndItem;
2002-10-13 22:44:10 +00:00
var suppressSelect = this._suppressOnSelect;
this._suppressOnSelect = true;
this._selectionStart = aStartItem;
2002-10-13 22:44:10 +00:00
var currentItem;
var startIndex = this.getIndexOfItem(aStartItem);
var endIndex = this.getIndexOfItem(aEndItem);
2002-10-13 22:44:10 +00:00
if (endIndex < startIndex) {
currentItem = aEndItem;
aEndItem = aStartItem;
aStartItem = currentItem;
2002-10-13 22:44:10 +00:00
} else {
currentItem = aStartItem;
2002-10-13 22:44:10 +00:00
}
2002-10-13 22:44:10 +00:00
while (currentItem) {
this.addItemToSelection(currentItem);
if (currentItem == aEndItem) {
currentItem = this.getNextItem(currentItem, 1);
2002-10-13 22:44:10 +00:00
break;
}
2002-10-13 22:44:10 +00:00
currentItem = this.getNextItem(currentItem, 1);
}
// Clear around new selection
// Don't use clearSelection() because it causes a lot of noise
// with respect to selection removed notifications used by the
// accessibility API support.
var userSelecting = this._userSelecting;
this._userSelecting = false; // that's US automatically unselecting
for (; currentItem; currentItem = this.getNextItem(currentItem, 1))
this.removeItemFromSelection(currentItem);
for (currentItem = this.getItemAtIndex(0); currentItem != aStartItem;
currentItem = this.getNextItem(currentItem, 1))
this.removeItemFromSelection(currentItem);
this._userSelecting = userSelecting;
2002-10-13 22:44:10 +00:00
this._suppressOnSelect = suppressSelect;
2002-10-13 22:44:10 +00:00
this._fireOnSelect();
]]>
</body>
</method>
2002-10-13 22:44:10 +00:00
<method name="selectAll">
<body>
this._selectionStart = null;
2002-10-13 22:44:10 +00:00
var suppress = this._suppressOnSelect;
this._suppressOnSelect = true;
2002-10-13 22:44:10 +00:00
var item = this.getItemAtIndex(0);
while (item) {
this.addItemToSelection(item);
item = this.getNextItem(item, 1);
2002-10-13 22:44:10 +00:00
}
2002-10-13 22:44:10 +00:00
this._suppressOnSelect = suppress;
this._fireOnSelect();
</body>
</method>
2002-10-13 22:44:10 +00:00
<method name="invertSelection">
<body>
this._selectionStart = null;
2002-10-13 22:44:10 +00:00
var suppress = this._suppressOnSelect;
this._suppressOnSelect = true;
2002-10-13 22:44:10 +00:00
var item = this.getItemAtIndex(0);
while (item) {
if (item.selected)
this.removeItemFromSelection(item);
else
this.addItemToSelection(item);
item = this.getNextItem(item, 1);
2002-10-13 22:44:10 +00:00
}
2002-10-13 22:44:10 +00:00
this._suppressOnSelect = suppress;
this._fireOnSelect();
</body>
</method>
2002-10-13 22:44:10 +00:00
<method name="clearSelection">
<body>
<![CDATA[
if (this.selectedItems) {
for (var i = this.selectedItems.length - 1; i >= 0; --i)
2002-10-13 22:44:10 +00:00
this.selectedItems[i].selected = false;
this.selectedItems.length = 0;
2002-10-13 22:44:10 +00:00
}
2002-10-13 22:44:10 +00:00
this._selectionStart = null;
this._fireOnSelect();
]]>
</body>
</method>
<property name="selectedCount" readonly="true"
onget="return this.selectedItems.length;"/>
<method name="getSelectedItem">
<parameter name="aIndex"/>
<body>
<![CDATA[
return aIndex < this.selectedItems.length ?
this.selectedItems[aIndex] : null;
]]>
</body>
</method>
<!-- Other public members -->
<property name="disableKeyNavigation"
onget="return this.hasAttribute('disableKeyNavigation');">
<setter>
if (val)
this.setAttribute("disableKeyNavigation", "true");
else
this.removeAttribute("disableKeyNavigation");
return val;
</setter>
</property>
<property name="suppressOnSelect"
onget="return this.getAttribute('suppressonselect') == 'true';"
onset="this.setAttribute('suppressonselect', val);"/>
<property name="_selectDelay"
onset="this.setAttribute('_selectDelay', val);"
onget="return this.getAttribute('_selectDelay') || 50;"/>
<method name="timedSelect">
<parameter name="aItem"/>
<parameter name="aTimeout"/>
<body>
<![CDATA[
var suppress = this._suppressOnSelect;
if (aTimeout != -1)
this._suppressOnSelect = true;
this.selectItem(aItem);
this._suppressOnSelect = suppress;
if (aTimeout != -1) {
if (this._selectTimeout)
window.clearTimeout(this._selectTimeout);
this._selectTimeout =
window.setTimeout(this._selectTimeoutHandler, aTimeout, this);
}
]]>
</body>
</method>
<method name="moveByOffset">
<parameter name="aOffset"/>
<parameter name="aIsSelecting"/>
<parameter name="aIsSelectingRange"/>
<body>
<![CDATA[
if ((aIsSelectingRange || !aIsSelecting) &&
this.selType != "multiple")
return;
var newIndex = this.currentIndex + aOffset;
if (newIndex < 0)
newIndex = 0;
var numItems = this.getRowCount();
if (newIndex > numItems - 1)
newIndex = numItems - 1;
var newItem = this.getItemAtIndex(newIndex);
// make sure that the item is actually visible/selectable
if (this._userSelecting && newItem && !this._canUserSelect(newItem))
newItem =
aOffset > 0 ? this.getNextItem(newItem, 1) || this.getPreviousItem(newItem, 1) :
this.getPreviousItem(newItem, 1) || this.getNextItem(newItem, 1);
if (newItem) {
this.ensureIndexIsVisible(this.getIndexOfItem(newItem));
if (aIsSelectingRange)
this.selectItemRange(null, newItem);
else if (aIsSelecting)
this.selectItem(newItem);
this.currentItem = newItem;
}
]]>
</body>
</method>
<!-- Private -->
2002-10-13 22:44:10 +00:00
<method name="getNextItem">
<parameter name="aStartItem"/>
<parameter name="aDelta"/>
<body>
<![CDATA[
while (aStartItem) {
aStartItem = aStartItem.nextSibling;
if (aStartItem && aStartItem instanceof
Components.interfaces.nsIDOMXULSelectControlItemElement &&
(!this._userSelecting || this._canUserSelect(aStartItem))) {
--aDelta;
if (aDelta == 0)
return aStartItem;
2002-10-13 22:44:10 +00:00
}
}
return null;
]]></body>
</method>
2002-10-13 22:44:10 +00:00
<method name="getPreviousItem">
<parameter name="aStartItem"/>
<parameter name="aDelta"/>
<body>
<![CDATA[
while (aStartItem) {
aStartItem = aStartItem.previousSibling;
if (aStartItem && aStartItem instanceof
Components.interfaces.nsIDOMXULSelectControlItemElement &&
(!this._userSelecting || this._canUserSelect(aStartItem))) {
--aDelta;
if (aDelta == 0)
return aStartItem;
2002-10-13 22:44:10 +00:00
}
}
return null;
]]>
</body>
</method>
<method name="_moveByOffsetFromUserEvent">
<parameter name="aOffset"/>
<parameter name="aEvent"/>
<body>
<![CDATA[
if (!aEvent.defaultPrevented) {
this._userSelecting = true;
this._mayReverse = true;
this.moveByOffset(aOffset, !aEvent.ctrlKey, aEvent.shiftKey);
this._userSelecting = false;
this._mayReverse = false;
aEvent.preventDefault();
}
]]>
</body>
</method>
<method name="_canUserSelect">
<parameter name="aItem"/>
<body>
<![CDATA[
var style = document.defaultView.getComputedStyle(aItem, "");
return style.display != "none" && style.visibility == "visible";
]]>
</body>
</method>
<method name="_selectTimeoutHandler">
<parameter name="aMe"/>
<body>
aMe._fireOnSelect();
aMe._selectTimeout = null;
</body>
2002-10-13 22:44:10 +00:00
</method>
<field name="_suppressOnSelect">false</field>
<field name="_userSelecting">false</field>
<field name="_mayReverse">false</field>
<field name="_selectTimeout">null</field>
<field name="_currentItem">null</field>
<field name="_selectionStart">null</field>
</implementation>
<handlers>
<handler event="keypress" keycode="VK_UP" modifiers="control shift any"
action="this._moveByOffsetFromUserEvent(-1, event);"
group="system"/>
<handler event="keypress" keycode="VK_DOWN" modifiers="control shift any"
action="this._moveByOffsetFromUserEvent(1, event);"
group="system"/>
<handler event="keypress" keycode="VK_HOME" modifiers="control shift any"
group="system">
<![CDATA[
this._mayReverse = true;
this._moveByOffsetFromUserEvent(-this.currentIndex, event);
this._mayReverse = false;
]]>
</handler>
<handler event="keypress" keycode="VK_END" modifiers="control shift any"
group="system">
<![CDATA[
this._mayReverse = true;
this._moveByOffsetFromUserEvent(this.getRowCount() - this.currentIndex - 1, event);
this._mayReverse = false;
]]>
</handler>
<handler event="keypress" keycode="VK_PAGE_UP" modifiers="control shift any"
group="system">
<![CDATA[
this._mayReverse = true;
this._moveByOffsetFromUserEvent(this.scrollOnePage(-1), event);
this._mayReverse = false;
]]>
</handler>
<handler event="keypress" keycode="VK_PAGE_DOWN" modifiers="control shift any"
group="system">
<![CDATA[
this._mayReverse = true;
this._moveByOffsetFromUserEvent(this.scrollOnePage(1), event);
this._mayReverse = false;
]]>
</handler>
<handler event="keypress" key=" " modifiers="control" phase="target">
<![CDATA[
if (this.currentItem && this.selType == "multiple")
this.toggleItemSelection(this.currentItem);
]]>
</handler>
<handler event="focus">
<![CDATA[
if (this.getRowCount() > 0) {
if (this.currentIndex == -1) {
this.currentIndex = this.getIndexOfFirstVisibleRow();
}
else {
this.currentItem._fireEvent("DOMMenuItemActive");
}
}
this._lastKeyTime = 0;
]]>
</handler>
<handler event="keypress" phase="target">
<![CDATA[
if (this.disableKeyNavigation || !event.charCode ||
event.altKey || event.ctrlKey || event.metaKey)
return;
if (event.timeStamp - this._lastKeyTime > 1000)
this._incrementalString = "";
var key = String.fromCharCode(event.charCode).toLowerCase();
this._incrementalString += key;
this._lastKeyTime = event.timeStamp;
// If all letters in the incremental string are the same, just
// try to match the first one
var incrementalString = /^(.)\1+$/.test(this._incrementalString) ?
RegExp.$1 : this._incrementalString;
var length = incrementalString.length;
var rowCount = this.getRowCount();
var l = this.selectedItems.length;
var start = l > 0 ? this.getIndexOfItem(this.selectedItems[l - 1]) : -1;
// start from the first element if none was selected or from the one
// following the selected one if it's a new or a repeated-letter search
if (start == -1 || length == 1)
start++;
for (var i = 0; i < rowCount; i++) {
var k = (start + i) % rowCount;
var listitem = this.getItemAtIndex(k);
if (!this._canUserSelect(listitem))
continue;
// allow richlistitems to specify the string being searched for
var searchText = "searchLabel" in listitem ? listitem.searchLabel :
listitem.getAttribute("label"); // (see also bug 250123)
searchText = searchText.substring(0, length).toLowerCase();
if (searchText == incrementalString) {
this.ensureIndexIsVisible(k);
this.timedSelect(listitem, this._selectDelay);
break;
}
}
]]>
</handler>
</handlers>
</binding>
<!-- Binding for xul:listbox element.
-->
<binding id="listbox"
extends="#listbox-base">
<resources>
<stylesheet src="chrome://global/skin/listbox.css"/>
</resources>
<content>
<children includes="listcols">
<xul:listcols>
<xul:listcol flex="1"/>
</xul:listcols>
</children>
<xul:listrows>
<children includes="listhead"/>
<xul:listboxbody xbl:inherits="rows,size,minheight">
<children includes="listitem"/>
</xul:listboxbody>
</xul:listrows>
</content>
<implementation>
<!-- ///////////////// public listbox members ///////////////// -->
<property name="listBoxObject"
onget="return this.boxObject.QueryInterface(Components.interfaces.nsIListBoxObject);"
readonly="true"/>
<!-- ///////////////// private listbox members ///////////////// -->
<method name="_fireOnSelect">
<body>
<![CDATA[
if (!this._suppressOnSelect && !this.suppressOnSelect) {
var event = document.createEvent("Events");
event.initEvent("select", true, true);
this.dispatchEvent(event);
}
]]>
</body>
</method>
<constructor>
<![CDATA[
var count = this.itemCount;
for (var index = 0; index < count; index++) {
var item = this.getItemAtIndex(index);
if (item.getAttribute("selected") == "true")
this.selectedItems.push(item);
}
]]>
</constructor>
<!-- ///////////////// nsIDOMXULSelectControlElement ///////////////// -->
<method name="appendItem">
<parameter name="aLabel"/>
<parameter name="aValue"/>
<body>
const XULNS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var item = this.ownerDocument.createElementNS(XULNS, "listitem");
item.setAttribute("label", aLabel);
item.setAttribute("value", aValue);
this.appendChild(item);
return item;
</body>
</method>
<method name="insertItemAt">
<parameter name="aIndex"/>
<parameter name="aLabel"/>
<parameter name="aValue"/>
<body>
const XULNS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var item = this.ownerDocument.createElementNS(XULNS, "listitem");
item.setAttribute("label", aLabel);
item.setAttribute("value", aValue);
var before = this.getItemAtIndex(aIndex);
if (before)
this.insertBefore(item, before);
else
this.appendChild(item);
return item;
</body>
</method>
<property name="itemCount" readonly="true"
onget="return this.listBoxObject.getRowCount()"/>
<!-- ///////////////// nsIListBoxObject ///////////////// -->
2002-10-13 22:44:10 +00:00
<method name="getIndexOfItem">
<parameter name="item"/>
<body>
return this.listBoxObject.getIndexOfItem(item);
</body>
</method>
<method name="getItemAtIndex">
<parameter name="index"/>
<body>
return this.listBoxObject.getItemAtIndex(index);
</body>
</method>
<method name="ensureIndexIsVisible">
<parameter name="index"/>
<body>
return this.listBoxObject.ensureIndexIsVisible(index);
</body>
</method>
<method name="ensureElementIsVisible">
<parameter name="element"/>
<body>
return this.ensureIndexIsVisible(this.listBoxObject.getIndexOfItem(element));
</body>
</method>
<method name="scrollToIndex">
<parameter name="index"/>
<body>
return this.listBoxObject.scrollToIndex(index);
</body>
</method>
<method name="getNumberOfVisibleRows">
<body>
return this.listBoxObject.getNumberOfVisibleRows();
</body>
</method>
<method name="getIndexOfFirstVisibleRow">
<body>
return this.listBoxObject.getIndexOfFirstVisibleRow();
</body>
</method>
<method name="getRowCount">
<body>
return this.listBoxObject.getRowCount();
</body>
</method>
<method name="scrollOnePage">
<parameter name="direction"/> <!-- Must be -1 or 1 -->
<body>
<![CDATA[
var pageOffset = this.getNumberOfVisibleRows() * direction;
// skip over invisible elements - the user won't care about them
for (var i = 0; i != pageOffset; i += direction) {
var item = this.getItemAtIndex(this.currentIndex + i);
if (item && !this._canUserSelect(item))
pageOffset += direction;
}
var newTop = this.getIndexOfFirstVisibleRow() + pageOffset;
if (direction == 1) {
var maxTop = this.getRowCount() - this.getNumberOfVisibleRows();
for (i = this.getRowCount(); i >= 0 && i > maxTop; i--) {
item = this.getItemAtIndex(i);
if (item && !this._canUserSelect(item))
maxTop--;
}
if (newTop >= maxTop)
newTop = maxTop;
}
if (newTop < 0)
newTop = 0;
this.scrollToIndex(newTop);
return pageOffset;
]]>
</body>
</method>
2002-10-13 22:44:10 +00:00
</implementation>
<handlers>
<handler event="keypress" key=" " phase="target">
<![CDATA[
if (this.currentItem) {
if (this.currentItem.getAttribute("type") != "checkbox")
this.addItemToSelection(this.currentItem);
else if (!this.currentItem.disabled) {
this.currentItem.checked = !this.currentItem.checked;
this.currentItem.doCommand();
}
}
]]>
</handler>
<handler event="MozSwipeGesture">
<![CDATA[
// Figure out which index to show
let targetIndex = 0;
// Only handle swipe gestures up and down
switch (event.direction) {
case event.DIRECTION_DOWN:
targetIndex = this.itemCount - 1;
// Fall through for actual action
case event.DIRECTION_UP:
this.ensureIndexIsVisible(targetIndex);
break;
}
]]>
</handler>
2002-10-13 22:44:10 +00:00
</handlers>
</binding>
<binding id="listrows">
<resources>
<stylesheet src="chrome://global/skin/listbox.css"/>
</resources>
2002-10-13 22:44:10 +00:00
<handlers>
<handler event="DOMMouseScroll" phase="capturing">
2002-10-13 22:44:10 +00:00
<![CDATA[
if (event.axis == event.HORIZONTAL_AXIS)
return;
var listBox = this.parentNode.listBoxObject;
var rows = event.detail;
if (rows == UIEvent.SCROLL_PAGE_UP)
rows = -listBox.getNumberOfVisibleRows();
else if (rows == UIEvent.SCROLL_PAGE_DOWN)
rows = listBox.getNumberOfVisibleRows();
listBox.scrollByLines(rows);
event.preventDefault();
2002-10-13 22:44:10 +00:00
]]>
</handler>
<handler event="MozMousePixelScroll" phase="capturing">
<![CDATA[
if (event.axis == event.HORIZONTAL_AXIS)
return;
// shouldn't be scrolled by pixel scrolling events before a line/page
// scrolling event.
event.preventDefault();
]]>
</handler>
2002-10-13 22:44:10 +00:00
</handlers>
</binding>
<binding id="listitem" role="xul:listitem"
extends="chrome://global/content/bindings/general.xml#basetext">
2002-10-13 22:44:10 +00:00
<resources>
<stylesheet src="chrome://global/skin/listbox.css"/>
</resources>
<content>
<children>
<xul:listcell xbl:inherits="label,crop,disabled,flexlabel"/>
</children>
</content>
<implementation implements="nsIDOMXULSelectControlItemElement">
2002-10-13 22:44:10 +00:00
<property name="current" onget="return this.getAttribute('current') == 'true';">
<setter><![CDATA[
if (val)
this.setAttribute("current", "true");
else
this.removeAttribute("current");
this._fireEvent(val ? "DOMMenuItemActive" : "DOMMenuItemInactive");
2002-10-13 22:44:10 +00:00
return val;
]]></setter>
</property>
<!-- ///////////////// nsIDOMXULSelectControlItemElement ///////////////// -->
<property name="value" onget="return this.getAttribute('value');"
onset="this.setAttribute('value', val); return val;"/>
<property name="label" onget="return this.getAttribute('label');"
onset="this.setAttribute('label', val); return val;"/>
<property name="selected" onget="return this.getAttribute('selected') == 'true';">
<setter><![CDATA[
if (val)
this.setAttribute("selected", "true");
else
this.removeAttribute("selected");
return val;
]]></setter>
</property>
<property name="control">
<getter><![CDATA[
var parent = this.parentNode;
while (parent) {
if (parent instanceof Components.interfaces.nsIDOMXULSelectControlElement)
2002-10-13 22:44:10 +00:00
return parent;
parent = parent.parentNode;
}
return null;
]]></getter>
</property>
<method name="_fireEvent">
<parameter name="name"/>
<body>
<![CDATA[
var event = document.createEvent("Events");
event.initEvent(name, true, true);
this.dispatchEvent(event);
]]>
</body>
</method>
2002-10-13 22:44:10 +00:00
</implementation>
<handlers>
<!-- If there is no modifier key, we select on mousedown, not
click, so that drags work correctly. -->
<handler event="mousedown">
<![CDATA[
var control = this.control;
if (!control || control.disabled)
return;
if ((!event.ctrlKey
#ifdef XP_MACOSX
|| event.button == 2
#endif
) && !event.shiftKey && !event.metaKey) {
if (!this.selected) {
control.selectItem(this);
}
control.currentItem = this;
}
]]>
</handler>
<!-- On a click (up+down on the same item), deselect everything
except this item. -->
<handler event="click" button="0">
<![CDATA[
var control = this.control;
if (!control || control.disabled)
return;
control._userSelecting = true;
if (control.selType != "multiple") {
control.selectItem(this);
}
else if (event.ctrlKey || event.metaKey) {
control.toggleItemSelection(this);
control.currentItem = this;
}
else if (event.shiftKey) {
control.selectItemRange(null, this);
control.currentItem = this;
}
else {
/* We want to deselect all the selected items except what was
clicked, UNLESS it was a right-click. We have to do this
in click rather than mousedown so that you can drag a
selected group of items */
// use selectItemRange instead of selectItem, because this
// doesn't de- and reselect this item if it is selected
control.selectItemRange(this, this);
}
control._userSelecting = false;
]]>
</handler>
</handlers>
2002-10-13 22:44:10 +00:00
</binding>
<binding id="listitem-iconic"
extends="chrome://global/content/bindings/listbox.xml#listitem">
2002-10-13 22:44:10 +00:00
<content>
<children>
<xul:listcell class="listcell-iconic" xbl:inherits="label,image,crop,disabled,flexlabel"/>
</children>
</content>
</binding>
<binding id="listitem-checkbox"
extends="chrome://global/content/bindings/listbox.xml#listitem">
2002-10-13 22:44:10 +00:00
<content>
<children>
<xul:listcell type="checkbox" xbl:inherits="label,crop,checked,disabled,flexlabel"/>
</children>
</content>
<implementation>
<property name="checked"
onget="return this.getAttribute('checked') == 'true';">
<setter><![CDATA[
if (val)
this.setAttribute('checked', 'true');
else
this.removeAttribute('checked');
var event = document.createEvent('Events');
event.initEvent('CheckboxStateChange', true, true);
2002-10-13 22:44:10 +00:00
this.dispatchEvent(event);
return val;
]]></setter>
</property>
</implementation>
<handlers>
<handler event="mousedown" button="0">
<![CDATA[
if (!this.disabled && !this.control.disabled) {
this.checked = !this.checked;
this.doCommand();
}
]]>
</handler>
2002-10-13 22:44:10 +00:00
</handlers>
</binding>
<binding id="listitem-checkbox-iconic"
extends="chrome://global/content/bindings/listbox.xml#listitem-checkbox">
2002-10-13 22:44:10 +00:00
<content>
<children>
<xul:listcell type="checkbox" class="listcell-iconic" xbl:inherits="label,image,crop,checked,disabled,flexlabel"/>
</children>
</content>
</binding>
<binding id="listcell" role="xul:listcell"
extends="chrome://global/content/bindings/general.xml#basecontrol">
<resources>
<stylesheet src="chrome://global/skin/listbox.css"/>
</resources>
2002-10-13 22:44:10 +00:00
<content>
<children>
<xul:label class="listcell-label" xbl:inherits="value=label,flex=flexlabel,crop,disabled" flex="1" crop="right"/>
</children>
</content>
</binding>
<binding id="listcell-iconic"
extends="chrome://global/content/bindings/listbox.xml#listcell">
2002-10-13 22:44:10 +00:00
<content>
<children>
<xul:image class="listcell-icon" xbl:inherits="src=image"/>
<xul:label class="listcell-label" xbl:inherits="value=label,flex=flexlabel,crop,disabled" flex="1" crop="right"/>
</children>
</content>
</binding>
<binding id="listcell-checkbox"
extends="chrome://global/content/bindings/listbox.xml#listcell">
2002-10-13 22:44:10 +00:00
<content>
<children>
<xul:image class="listcell-check" xbl:inherits="checked,disabled"/>
<xul:label class="listcell-label" xbl:inherits="value=label,flex=flexlabel,crop,disabled" flex="1" crop="right"/>
2002-10-13 22:44:10 +00:00
</children>
</content>
</binding>
<binding id="listcell-checkbox-iconic"
extends="chrome://global/content/bindings/listbox.xml#listcell-checkbox">
2002-10-13 22:44:10 +00:00
<content>
<children>
<xul:image class="listcell-check" xbl:inherits="checked,disabled"/>
<xul:image class="listcell-icon" xbl:inherits="src=image"/>
<xul:label class="listcell-label" xbl:inherits="value=label,flex=flexlabel,crop,disabled" flex="1" crop="right"/>
2002-10-13 22:44:10 +00:00
</children>
</content>
</binding>
<binding id="listhead" role="xul:listhead">
<resources>
<stylesheet src="chrome://global/skin/listbox.css"/>
</resources>
2002-10-13 22:44:10 +00:00
<content>
<xul:listheaditem>
<children includes="listheader"/>
</xul:listheaditem>
</content>
</binding>
<binding id="listheader" display="xul:button" role="xul:listheader">
<resources>
<stylesheet src="chrome://global/skin/listbox.css"/>
</resources>
2002-10-13 22:44:10 +00:00
<content>
<xul:image class="listheader-icon"/>
<xul:label class="listheader-label" xbl:inherits="value=label,crop" flex="1" crop="right"/>
<xul:image class="listheader-sortdirection" xbl:inherits="sortDirection"/>
</content>
</binding>
</bindings>