2005-06-17 22:11:02 +04:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
|
2012-05-21 15:12:37 +04: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/. -->
|
2005-06-17 22:11:02 +04:00
|
|
|
|
|
|
|
<bindings id="richlistboxBindings"
|
|
|
|
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">
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<binding id="richlistbox"
|
|
|
|
extends="chrome://global/content/bindings/listbox.xml#listbox-base">
|
|
|
|
<resources>
|
|
|
|
<stylesheet src="chrome://global/skin/richlistbox.css"/>
|
|
|
|
</resources>
|
|
|
|
|
2005-06-17 22:11:02 +04:00
|
|
|
<content>
|
2007-09-28 03:24:08 +04:00
|
|
|
<children includes="listheader"/>
|
2005-06-17 22:11:02 +04:00
|
|
|
<xul:scrollbox allowevents="true" orient="vertical" anonid="main-box"
|
2009-08-21 22:47:28 +04:00
|
|
|
flex="1" style="overflow: auto;" xbl:inherits="dir,pack">
|
2007-04-10 04:21:16 +04:00
|
|
|
<children/>
|
2005-06-17 22:11:02 +04:00
|
|
|
</xul:scrollbox>
|
|
|
|
</content>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<implementation>
|
2009-04-09 10:42:01 +04:00
|
|
|
<field name="_scrollbox">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "main-box");
|
|
|
|
</field>
|
|
|
|
<field name="scrollBoxObject">
|
2014-10-15 00:15:21 +04:00
|
|
|
this._scrollbox.boxObject;
|
2009-04-09 10:42:01 +04:00
|
|
|
</field>
|
2005-06-17 22:11:02 +04:00
|
|
|
<constructor>
|
|
|
|
<![CDATA[
|
2005-09-03 01:03:16 +04:00
|
|
|
// add a template build listener
|
|
|
|
if (this.builder)
|
|
|
|
this.builder.addListener(this._builderListener);
|
|
|
|
else
|
|
|
|
this._refreshSelection();
|
2005-06-17 22:11:02 +04:00
|
|
|
]]>
|
|
|
|
</constructor>
|
|
|
|
|
2005-09-03 01:03:16 +04:00
|
|
|
<destructor>
|
|
|
|
<![CDATA[
|
|
|
|
// remove the template build listener
|
|
|
|
if (this.builder)
|
|
|
|
this.builder.removeListener(this._builderListener);
|
|
|
|
]]>
|
|
|
|
</destructor>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<!-- Overriding baselistbox -->
|
|
|
|
<method name="_fireOnSelect">
|
|
|
|
<body>
|
2005-06-24 00:04:57 +04:00
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
// make sure not to modify last-selected when suppressing select events
|
|
|
|
// (otherwise we'll lose the selection when a template gets rebuilt)
|
|
|
|
if (this._suppressOnSelect || this.suppressOnSelect)
|
|
|
|
return;
|
2005-06-17 22:11:02 +04:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
// remember the current item and all selected items with IDs
|
|
|
|
var state = this.currentItem ? this.currentItem.id : "";
|
|
|
|
if (this.selType == "multiple" && this.selectedCount) {
|
2013-01-26 21:57:59 +04:00
|
|
|
let getId = function getId(aItem) { return aItem.id; }
|
2007-01-16 20:09:58 +03:00
|
|
|
state += " " + this.selectedItems.filter(getId).map(getId).join(" ");
|
2005-09-03 01:03:16 +04:00
|
|
|
}
|
2007-01-16 20:09:58 +03:00
|
|
|
if (state)
|
|
|
|
this.setAttribute("last-selected", state);
|
|
|
|
else
|
|
|
|
this.removeAttribute("last-selected");
|
2005-09-03 01:03:16 +04:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
// preserve the index just in case no IDs are available
|
|
|
|
if (this.currentIndex > -1)
|
|
|
|
this._currentIndex = this.currentIndex + 1;
|
2006-03-13 16:15:39 +03:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
var event = document.createEvent("Events");
|
|
|
|
event.initEvent("select", true, true);
|
|
|
|
this.dispatchEvent(event);
|
2006-03-13 16:15:39 +03:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
// always call this (allows a commandupdater without controller)
|
|
|
|
document.commandDispatcher.updateCommands("richlistbox-select");
|
2005-09-03 01:03:16 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2009-08-21 22:47:28 +04:00
|
|
|
<!-- We override base-listbox here because those methods don't take dir
|
|
|
|
into account on listbox (which doesn't support dir yet) -->
|
|
|
|
<method name="getNextItem">
|
|
|
|
<parameter name="aStartItem"/>
|
|
|
|
<parameter name="aDelta"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
|
|
|
var prop = this.dir == "reverse" && this._mayReverse ?
|
|
|
|
"previousSibling" :
|
|
|
|
"nextSibling";
|
|
|
|
while (aStartItem) {
|
|
|
|
aStartItem = aStartItem[prop];
|
|
|
|
if (aStartItem && aStartItem instanceof
|
|
|
|
Components.interfaces.nsIDOMXULSelectControlItemElement &&
|
|
|
|
(!this._userSelecting || this._canUserSelect(aStartItem))) {
|
|
|
|
--aDelta;
|
|
|
|
if (aDelta == 0)
|
|
|
|
return aStartItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="getPreviousItem">
|
|
|
|
<parameter name="aStartItem"/>
|
|
|
|
<parameter name="aDelta"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
|
|
|
var prop = this.dir == "reverse" && this._mayReverse ?
|
|
|
|
"nextSibling" :
|
|
|
|
"previousSibling";
|
|
|
|
while (aStartItem) {
|
|
|
|
aStartItem = aStartItem[prop];
|
|
|
|
if (aStartItem && aStartItem instanceof
|
|
|
|
Components.interfaces.nsIDOMXULSelectControlItemElement &&
|
|
|
|
(!this._userSelecting || this._canUserSelect(aStartItem))) {
|
|
|
|
--aDelta;
|
|
|
|
if (aDelta == 0)
|
|
|
|
return aStartItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<method name="appendItem">
|
|
|
|
<parameter name="aLabel"/>
|
|
|
|
<parameter name="aValue"/>
|
2006-03-13 16:15:39 +03:00
|
|
|
<body>
|
2007-01-16 20:09:58 +03:00
|
|
|
return this.insertItemAt(-1, aLabel, aValue);
|
2006-03-13 16:15:39 +03:00
|
|
|
</body>
|
2005-06-22 00:13:56 +04:00
|
|
|
</method>
|
2005-06-24 00:04:57 +04:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<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, "richlistitem");
|
|
|
|
item.setAttribute("value", aValue);
|
|
|
|
|
|
|
|
var label = this.ownerDocument.createElementNS(XULNS, "label");
|
|
|
|
label.setAttribute("value", aLabel);
|
|
|
|
label.setAttribute("flex", "1");
|
|
|
|
label.setAttribute("crop", "end");
|
|
|
|
item.appendChild(label);
|
|
|
|
|
|
|
|
var before = this.getItemAtIndex(aIndex);
|
|
|
|
if (!before)
|
|
|
|
this.appendChild(item);
|
|
|
|
else
|
|
|
|
this.insertBefore(item, before);
|
2005-07-27 01:21:14 +04:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
return item;
|
|
|
|
</body>
|
|
|
|
</method>
|
2005-06-17 22:11:02 +04:00
|
|
|
|
2007-02-16 22:16:13 +03:00
|
|
|
<property name="itemCount" readonly="true"
|
|
|
|
onget="return this.children.length"/>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<method name="getIndexOfItem">
|
2005-09-03 01:03:16 +04:00
|
|
|
<parameter name="aItem"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
// don't search the children, if we're looking for none of them
|
|
|
|
if (aItem == null)
|
|
|
|
return -1;
|
2005-09-03 01:03:16 +04:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
return this.children.indexOf(aItem);
|
2005-09-03 01:03:16 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<method name="getItemAtIndex">
|
|
|
|
<parameter name="aIndex"/>
|
|
|
|
<body>
|
|
|
|
return this.children[aIndex] || null;
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="ensureIndexIsVisible">
|
|
|
|
<parameter name="aIndex"/>
|
2005-06-17 22:11:02 +04:00
|
|
|
<body>
|
2005-06-24 00:04:57 +04:00
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
// work around missing implementation in scrollBoxObject
|
|
|
|
return this.ensureElementIsVisible(this.getItemAtIndex(aIndex));
|
2005-06-24 00:04:57 +04:00
|
|
|
]]>
|
2005-06-17 22:11:02 +04:00
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<method name="ensureElementIsVisible">
|
|
|
|
<parameter name="aElement"/>
|
2005-07-20 23:45:43 +04:00
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2009-04-09 10:42:01 +04:00
|
|
|
if (!aElement)
|
|
|
|
return;
|
|
|
|
var targetRect = aElement.getBoundingClientRect();
|
|
|
|
var scrollRect = this._scrollbox.getBoundingClientRect();
|
|
|
|
var offset = targetRect.top - scrollRect.top;
|
|
|
|
if (offset >= 0) {
|
|
|
|
// scrollRect.bottom wouldn't take a horizontal scroll bar into account
|
|
|
|
let scrollRectBottom = scrollRect.top + this._scrollbox.clientHeight;
|
|
|
|
offset = targetRect.bottom - scrollRectBottom;
|
|
|
|
if (offset <= 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._scrollbox.scrollTop += offset;
|
2005-07-20 23:45:43 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<method name="scrollToIndex">
|
|
|
|
<parameter name="aIndex"/>
|
2005-06-17 22:11:02 +04:00
|
|
|
<body>
|
2005-06-24 00:04:57 +04:00
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
var item = this.getItemAtIndex(aIndex);
|
|
|
|
if (item)
|
|
|
|
this.scrollBoxObject.scrollToElement(item);
|
2005-06-24 00:04:57 +04:00
|
|
|
]]>
|
2005-06-17 22:11:02 +04:00
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<method name="getNumberOfVisibleRows">
|
|
|
|
<!-- returns the number of currently visible rows -->
|
|
|
|
<!-- don't rely on this function, if the items' height can vary! -->
|
2005-06-17 22:11:02 +04:00
|
|
|
<body>
|
2005-06-24 00:04:57 +04:00
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
var children = this.children;
|
|
|
|
|
|
|
|
for (var top = 0; top < children.length && !this._isItemVisible(children[top]); top++);
|
|
|
|
for (var ix = top; ix < children.length && this._isItemVisible(children[ix]); ix++);
|
|
|
|
|
|
|
|
return ix - top;
|
2005-06-24 00:04:57 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<method name="getIndexOfFirstVisibleRow">
|
2005-09-16 03:54:40 +04:00
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
var children = this.children;
|
2005-09-16 03:54:40 +04:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
for (var ix = 0; ix < children.length; ix++)
|
|
|
|
if (this._isItemVisible(children[ix]))
|
|
|
|
return ix;
|
2005-09-16 03:54:40 +04:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
return -1;
|
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="getRowCount">
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
|
|
|
return this.children.length;
|
2005-09-16 03:54:40 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="scrollOnePage">
|
|
|
|
<parameter name="aDirection"/> <!-- Must be -1 or 1 -->
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2005-09-26 21:11:01 +04:00
|
|
|
var children = this.children;
|
|
|
|
|
|
|
|
if (children.length == 0)
|
2007-01-16 20:09:58 +03:00
|
|
|
return 0;
|
2005-09-16 03:54:40 +04:00
|
|
|
|
2005-09-26 21:11:01 +04:00
|
|
|
// If nothing is selected, we just select the first element
|
|
|
|
// at the extreme we're moving away from
|
2007-01-16 20:09:58 +03:00
|
|
|
if (!this.currentItem)
|
|
|
|
return aDirection == -1 ? children.length : 0;
|
2005-09-16 03:54:40 +04:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
// If the current item is visible, scroll by one page so that
|
|
|
|
// the new current item is at approximately the same position as
|
|
|
|
// the existing current item.
|
|
|
|
if (this._isItemVisible(this.currentItem))
|
2005-09-16 03:54:40 +04:00
|
|
|
this.scrollBoxObject.scrollBy(0, this.scrollBoxObject.height * aDirection);
|
|
|
|
|
|
|
|
// Figure out, how many items fully fit into the view port
|
2006-03-14 16:53:36 +03:00
|
|
|
// (including the currently selected one), and determine
|
|
|
|
// the index of the first one lying (partially) outside
|
2005-09-16 03:54:40 +04:00
|
|
|
var height = this.scrollBoxObject.height;
|
2007-08-23 12:59:59 +04:00
|
|
|
var startBorder = this.currentItem.boxObject.y;
|
2006-03-14 16:53:36 +03:00
|
|
|
if (aDirection == -1)
|
2007-08-23 12:59:59 +04:00
|
|
|
startBorder += this.currentItem.boxObject.height;
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
var index = this.currentIndex;
|
2007-08-23 12:59:59 +04:00
|
|
|
for (var ix = index; 0 <= ix && ix < children.length; ix += aDirection) {
|
|
|
|
var boxObject = children[ix].boxObject;
|
|
|
|
if (boxObject.height == 0)
|
|
|
|
continue; // hidden children have a y of 0
|
|
|
|
var endBorder = boxObject.y + (aDirection == -1 ? boxObject.height : 0);
|
|
|
|
if ((endBorder - startBorder) * aDirection > height)
|
|
|
|
break; // we've reached the desired distance
|
|
|
|
index = ix;
|
2005-09-16 03:54:40 +04:00
|
|
|
}
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
return index != this.currentIndex ? index - this.currentIndex : aDirection;
|
2005-09-16 03:54:40 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<!-- richlistbox specific -->
|
|
|
|
<property name="children" readonly="true">
|
|
|
|
<getter>
|
|
|
|
<![CDATA[
|
|
|
|
var childNodes = [];
|
2009-08-21 22:47:28 +04:00
|
|
|
var isReverse = this.dir == "reverse" && this._mayReverse;
|
|
|
|
var child = isReverse ? this.lastChild : this.firstChild;
|
|
|
|
var prop = isReverse ? "previousSibling" : "nextSibling";
|
|
|
|
while (child) {
|
2007-01-16 20:09:58 +03:00
|
|
|
if (child instanceof Components.interfaces.nsIDOMXULSelectControlItemElement)
|
|
|
|
childNodes.push(child);
|
2009-08-21 22:47:28 +04:00
|
|
|
child = child[prop];
|
2007-01-16 20:09:58 +03:00
|
|
|
}
|
|
|
|
return childNodes;
|
|
|
|
]]>
|
|
|
|
</getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<field name="_builderListener" readonly="true">
|
|
|
|
<![CDATA[
|
|
|
|
({
|
|
|
|
mOuter: this,
|
|
|
|
item: null,
|
|
|
|
willRebuild: function(builder) { },
|
|
|
|
didRebuild: function(builder) {
|
|
|
|
this.mOuter._refreshSelection();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
]]>
|
|
|
|
</field>
|
|
|
|
|
|
|
|
<method name="_refreshSelection">
|
2005-07-20 23:45:43 +04:00
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
// when this method is called, we know that either the currentItem
|
|
|
|
// and selectedItems we have are null (ctor) or a reference to an
|
|
|
|
// element no longer in the DOM (template).
|
|
|
|
|
|
|
|
// first look for the last-selected attribute
|
|
|
|
var state = this.getAttribute("last-selected");
|
|
|
|
if (state) {
|
|
|
|
var ids = state.split(" ");
|
|
|
|
|
|
|
|
var suppressSelect = this._suppressOnSelect;
|
|
|
|
this._suppressOnSelect = true;
|
|
|
|
this.clearSelection();
|
|
|
|
for (var i = 1; i < ids.length; i++) {
|
|
|
|
var selectedItem = document.getElementById(ids[i]);
|
|
|
|
if (selectedItem)
|
|
|
|
this.addItemToSelection(selectedItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
var currentItem = document.getElementById(ids[0]);
|
|
|
|
if (!currentItem && this._currentIndex)
|
|
|
|
currentItem = this.getItemAtIndex(Math.min(
|
|
|
|
this._currentIndex - 1, this.getRowCount()));
|
|
|
|
if (currentItem) {
|
|
|
|
this.currentItem = currentItem;
|
|
|
|
if (this.selType != "multiple" && this.selectedCount == 0)
|
|
|
|
this.selectedItem = currentItem;
|
|
|
|
|
2009-08-21 22:47:28 +04:00
|
|
|
if (this.scrollBoxObject.height) {
|
2007-01-16 20:09:58 +03:00
|
|
|
this.ensureElementIsVisible(currentItem);
|
2009-08-21 22:47:28 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// XXX hack around a bug in ensureElementIsVisible as it will
|
|
|
|
// scroll beyond the last element, bug 493645.
|
|
|
|
var previousElement = this.dir == "reverse" ? currentItem.nextSibling :
|
|
|
|
currentItem.previousSibling;
|
|
|
|
this.ensureElementIsVisible(previousElement);
|
|
|
|
}
|
2007-01-16 20:09:58 +03:00
|
|
|
}
|
|
|
|
this._suppressOnSelect = suppressSelect;
|
|
|
|
// XXX actually it's just a refresh, but at least
|
|
|
|
// the Extensions manager expects this:
|
|
|
|
this._fireOnSelect();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to restore the selected items according to their IDs
|
|
|
|
// (applies after a template rebuild, if last-selected was not set)
|
|
|
|
if (this.selectedItems) {
|
|
|
|
for (i = this.selectedCount - 1; i >= 0; i--) {
|
|
|
|
if (this.selectedItems[i] && this.selectedItems[i].id)
|
|
|
|
this.selectedItems[i] = document.getElementById(this.selectedItems[i].id);
|
|
|
|
else
|
|
|
|
this.selectedItems[i] = null;
|
|
|
|
if (!this.selectedItems[i])
|
|
|
|
this.selectedItems.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.currentItem && this.currentItem.id)
|
|
|
|
this.currentItem = document.getElementById(this.currentItem.id);
|
|
|
|
else
|
|
|
|
this.currentItem = null;
|
|
|
|
|
|
|
|
// if we have no previously current item or if the above check fails to
|
|
|
|
// find the previous nodes (which causes it to clear selection)
|
|
|
|
if (!this.currentItem && this.selectedCount == 0) {
|
|
|
|
this.currentIndex = this._currentIndex ? this._currentIndex - 1 : 0;
|
|
|
|
|
|
|
|
// cf. listbox constructor:
|
|
|
|
// select items according to their attributes
|
2007-07-04 16:16:55 +04:00
|
|
|
var children = this.children;
|
|
|
|
for (var i = 0; i < children.length; ++i) {
|
|
|
|
if (children[i].getAttribute("selected") == "true")
|
|
|
|
this.selectedItems.push(children[i]);
|
|
|
|
}
|
2007-01-16 20:09:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.selType != "multiple" && this.selectedCount == 0)
|
|
|
|
this.selectedItem = this.currentItem;
|
2005-07-20 23:45:43 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<method name="_isItemVisible">
|
|
|
|
<parameter name="aItem"/>
|
2005-06-24 00:04:57 +04:00
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
if (!aItem)
|
|
|
|
return false;
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
var y = this.scrollBoxObject.positionY + this.scrollBoxObject.y;
|
2005-06-29 01:30:56 +04:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
// Partially visible items are also considered visible
|
2014-10-15 00:15:21 +04:00
|
|
|
return (aItem.boxObject.y + aItem.boxObject.height > y) &&
|
|
|
|
(aItem.boxObject.y < y + this.scrollBoxObject.height);
|
2005-06-24 00:04:57 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<field name="_currentIndex">null</field>
|
|
|
|
|
|
|
|
<!-- For backwards-compatibility and for convenience.
|
|
|
|
Use getIndexOfItem instead. -->
|
|
|
|
<method name="getIndexOf">
|
2005-06-24 00:04:57 +04:00
|
|
|
<parameter name="aElement"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
return this.getIndexOfItem(aElement);
|
2005-06-24 00:04:57 +04:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<!-- For backwards-compatibility and for convenience.
|
|
|
|
Use ensureElementIsVisible instead -->
|
2005-06-24 00:04:57 +04:00
|
|
|
<method name="ensureSelectedElementIsVisible">
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
return this.ensureElementIsVisible(this.selectedItem);
|
2005-06-24 00:04:57 +04:00
|
|
|
]]>
|
2005-06-17 22:11:02 +04:00
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<!-- For backwards-compatibility and for convenience.
|
|
|
|
Use moveByOffset instead. -->
|
|
|
|
<method name="goUp">
|
|
|
|
<body>
|
2005-07-20 23:45:43 +04:00
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
var index = this.currentIndex;
|
|
|
|
this.moveByOffset(-1, true, false);
|
|
|
|
return index != this.currentIndex;
|
2005-07-20 23:45:43 +04:00
|
|
|
]]>
|
2007-01-16 20:09:58 +03:00
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
<method name="goDown">
|
2005-06-17 22:11:02 +04:00
|
|
|
<body>
|
2005-06-24 00:04:57 +04:00
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
var index = this.currentIndex;
|
|
|
|
this.moveByOffset(1, true, false);
|
|
|
|
return index != this.currentIndex;
|
2005-06-24 00:04:57 +04:00
|
|
|
]]>
|
2005-06-17 22:11:02 +04:00
|
|
|
</body>
|
|
|
|
</method>
|
2007-01-16 20:09:58 +03:00
|
|
|
|
|
|
|
<!-- deprecated (is implied by currentItem and selectItem) -->
|
|
|
|
<method name="fireActiveItemEvent"><body/></method>
|
2005-06-17 22:11:02 +04:00
|
|
|
</implementation>
|
|
|
|
|
|
|
|
<handlers>
|
|
|
|
<handler event="click">
|
2005-06-24 00:04:57 +04:00
|
|
|
<![CDATA[
|
|
|
|
// clicking into nothing should unselect
|
2009-04-09 10:42:01 +04:00
|
|
|
if (event.originalTarget == this._scrollbox) {
|
2005-06-24 00:04:57 +04:00
|
|
|
this.clearSelection();
|
2007-01-16 20:09:58 +03:00
|
|
|
this.currentItem = null;
|
|
|
|
}
|
2005-06-24 00:04:57 +04:00
|
|
|
]]>
|
2005-06-17 22:11:02 +04:00
|
|
|
</handler>
|
2009-02-21 02:16:04 +03:00
|
|
|
|
|
|
|
<handler event="MozSwipeGesture">
|
|
|
|
<![CDATA[
|
|
|
|
// Only handle swipe gestures up and down
|
|
|
|
switch (event.direction) {
|
|
|
|
case event.DIRECTION_DOWN:
|
2009-04-09 10:42:01 +04:00
|
|
|
this._scrollbox.scrollTop = this._scrollbox.scrollHeight;
|
|
|
|
break;
|
2009-02-21 02:16:04 +03:00
|
|
|
case event.DIRECTION_UP:
|
2009-04-09 10:42:01 +04:00
|
|
|
this._scrollbox.scrollTop = 0;
|
2009-02-21 02:16:04 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
]]>
|
|
|
|
</handler>
|
2005-06-17 22:11:02 +04:00
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
|
2005-06-21 22:13:01 +04:00
|
|
|
<binding id="richlistitem"
|
2007-01-16 20:09:58 +03:00
|
|
|
extends="chrome://global/content/bindings/listbox.xml#listitem">
|
2005-06-17 22:11:02 +04:00
|
|
|
<content>
|
2007-01-16 20:09:58 +03:00
|
|
|
<children/>
|
2005-06-17 22:11:02 +04:00
|
|
|
</content>
|
|
|
|
|
2005-07-06 01:07:09 +04:00
|
|
|
<resources>
|
|
|
|
<stylesheet src="chrome://global/skin/richlistbox.css"/>
|
|
|
|
</resources>
|
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<implementation>
|
2005-08-14 02:32:14 +04:00
|
|
|
<destructor>
|
2005-07-26 02:21:31 +04:00
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
var control = this.control;
|
|
|
|
if (!control)
|
|
|
|
return;
|
|
|
|
// When we are destructed and we are current or selected, unselect ourselves
|
|
|
|
// so that richlistbox's selection doesn't point to something not in the DOM.
|
|
|
|
// We don't want to reset last-selected, so we set _suppressOnSelect.
|
2005-07-26 02:21:31 +04:00
|
|
|
if (this.selected) {
|
2007-01-16 20:09:58 +03:00
|
|
|
var suppressSelect = control._suppressOnSelect;
|
|
|
|
control._suppressOnSelect = true;
|
|
|
|
control.removeItemFromSelection(this);
|
|
|
|
control._suppressOnSelect = suppressSelect;
|
2005-07-26 02:21:31 +04:00
|
|
|
}
|
2007-01-16 20:09:58 +03:00
|
|
|
if (this.current)
|
|
|
|
control.currentItem = null;
|
2005-07-26 02:21:31 +04:00
|
|
|
]]>
|
2005-08-14 02:32:14 +04:00
|
|
|
</destructor>
|
2005-07-26 02:21:31 +04:00
|
|
|
|
2007-01-16 20:09:58 +03:00
|
|
|
<property name="label" readonly="true">
|
2005-06-22 00:13:56 +04:00
|
|
|
<!-- Setter purposely not implemented; the getter returns a
|
2007-01-16 20:09:58 +03:00
|
|
|
concatentation of label text to expose via accessibility APIs -->
|
2005-06-22 00:13:56 +04:00
|
|
|
<getter>
|
|
|
|
<![CDATA[
|
2007-01-16 20:09:58 +03:00
|
|
|
const XULNS =
|
|
|
|
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
2009-10-03 22:37:57 +04:00
|
|
|
return Array.map(this.getElementsByTagNameNS(XULNS, "label"),
|
|
|
|
function (label) label.value)
|
|
|
|
.join(" ");
|
2005-06-22 00:13:56 +04:00
|
|
|
]]>
|
|
|
|
</getter>
|
|
|
|
</property>
|
2007-07-01 06:16:14 +04:00
|
|
|
|
2007-07-06 02:19:41 +04:00
|
|
|
<property name="searchLabel">
|
2007-07-01 06:16:14 +04:00
|
|
|
<getter>
|
|
|
|
<![CDATA[
|
|
|
|
return this.hasAttribute("searchlabel") ?
|
|
|
|
this.getAttribute("searchlabel") : this.label;
|
|
|
|
]]>
|
|
|
|
</getter>
|
2007-07-06 02:19:41 +04:00
|
|
|
<setter>
|
|
|
|
<![CDATA[
|
|
|
|
if (val !== null)
|
|
|
|
this.setAttribute("searchlabel", val);
|
|
|
|
else
|
|
|
|
// fall back to the label property (default value)
|
|
|
|
this.removeAttribute("searchlabel");
|
|
|
|
return val;
|
|
|
|
]]>
|
|
|
|
</setter>
|
2007-07-01 06:16:14 +04:00
|
|
|
</property>
|
2005-06-17 22:11:02 +04:00
|
|
|
</implementation>
|
|
|
|
</binding>
|
|
|
|
</bindings>
|