2007-03-22 10:30:00 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
|
|
|
|
<bindings id="arrowscrollboxBindings"
|
|
|
|
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">
|
|
|
|
|
|
|
|
<binding id="scrollbox-base" extends="chrome://global/content/bindings/general.xml#basecontrol">
|
|
|
|
<resources>
|
|
|
|
<stylesheet src="chrome://global/skin/scrollbox.css"/>
|
|
|
|
</resources>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
<binding id="scrollbox" extends="chrome://global/content/bindings/scrollbox.xml#scrollbox-base">
|
|
|
|
<content>
|
|
|
|
<xul:box class="box-inherit scrollbox-innerbox" xbl:inherits="orient,align,pack,dir" flex="1">
|
|
|
|
<children/>
|
|
|
|
</xul:box>
|
|
|
|
</content>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
<binding id="arrowscrollbox" extends="chrome://global/content/bindings/scrollbox.xml#scrollbox-base">
|
|
|
|
<content>
|
|
|
|
<xul:autorepeatbutton class="autorepeatbutton-up"
|
|
|
|
anonid="scrollbutton-up"
|
|
|
|
collapsed="true"
|
|
|
|
xbl:inherits="orient"
|
2007-10-28 20:03:46 -07:00
|
|
|
oncommand="_autorepeatbuttonScroll(event);"/>
|
2010-11-24 01:50:20 -08:00
|
|
|
<xul:scrollbox class="arrowscrollbox-scrollbox"
|
|
|
|
anonid="scrollbox"
|
|
|
|
flex="1"
|
|
|
|
xbl:inherits="orient,align,pack,dir">
|
2007-03-22 10:30:00 -07:00
|
|
|
<children/>
|
|
|
|
</xul:scrollbox>
|
|
|
|
<xul:autorepeatbutton class="autorepeatbutton-down"
|
|
|
|
anonid="scrollbutton-down"
|
|
|
|
collapsed="true"
|
|
|
|
xbl:inherits="orient"
|
2007-10-28 20:03:46 -07:00
|
|
|
oncommand="_autorepeatbuttonScroll(event);"/>
|
2007-03-22 10:30:00 -07:00
|
|
|
</content>
|
2007-08-14 23:52:00 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<implementation>
|
2008-10-20 09:52:12 -07:00
|
|
|
<destructor><![CDATA[
|
|
|
|
this._stopSmoothScroll();
|
|
|
|
]]></destructor>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<field name="_scrollbox">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "scrollbox");
|
|
|
|
</field>
|
|
|
|
<field name="_scrollButtonUp">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "scrollbutton-up");
|
|
|
|
</field>
|
|
|
|
<field name="_scrollButtonDown">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "scrollbutton-down");
|
|
|
|
</field>
|
|
|
|
|
2007-08-14 23:52:00 -07:00
|
|
|
<field name="__prefBranch">null</field>
|
|
|
|
<property name="_prefBranch" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
if (this.__prefBranch === null) {
|
|
|
|
this.__prefBranch = Components.classes['@mozilla.org/preferences-service;1']
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch2);
|
|
|
|
}
|
|
|
|
return this.__prefBranch;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<field name="_scrollIncrement">null</field>
|
2007-03-22 10:30:00 -07:00
|
|
|
<property name="scrollIncrement" readonly="true">
|
|
|
|
<getter><![CDATA[
|
2007-08-14 23:52:00 -07:00
|
|
|
if (this._scrollIncrement === null) {
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
2007-08-14 23:52:00 -07:00
|
|
|
this._scrollIncrement = this._prefBranch
|
|
|
|
.getIntPref("toolkit.scrollbox.scrollIncrement");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (ex) {
|
2007-08-14 23:52:00 -07:00
|
|
|
this._scrollIncrement = 20;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return this._scrollIncrement;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2007-08-14 23:52:00 -07:00
|
|
|
<field name="_smoothScroll">null</field>
|
|
|
|
<property name="smoothScroll">
|
|
|
|
<getter><![CDATA[
|
|
|
|
if (this._smoothScroll === null) {
|
|
|
|
if (this.hasAttribute("smoothscroll")) {
|
|
|
|
this._smoothScroll = (this.getAttribute("smoothscroll") == "true");
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
this._smoothScroll = this._prefBranch
|
|
|
|
.getBoolPref("toolkit.scrollbox.smoothScroll");
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
this._smoothScroll = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this._smoothScroll;
|
|
|
|
]]></getter>
|
|
|
|
<setter><![CDATA[
|
|
|
|
this._smoothScroll = val;
|
|
|
|
return val;
|
|
|
|
]]></setter>
|
|
|
|
</property>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<field name="_scrollBoxObject">null</field>
|
|
|
|
<property name="scrollBoxObject" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
if (!this._scrollBoxObject) {
|
|
|
|
this._scrollBoxObject =
|
|
|
|
this._scrollbox.boxObject
|
|
|
|
.QueryInterface(Components.interfaces.nsIScrollBoxObject);
|
|
|
|
}
|
|
|
|
return this._scrollBoxObject;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2009-04-09 05:40:59 -07:00
|
|
|
<property name="scrollClientRect" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
return this._scrollbox.getBoundingClientRect();
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<property name="scrollClientSize" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
return this.orient == "vertical" ?
|
|
|
|
this._scrollbox.clientHeight :
|
|
|
|
this._scrollbox.clientWidth;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<property name="scrollSize" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
return this.orient == "vertical" ?
|
|
|
|
this._scrollbox.scrollHeight :
|
|
|
|
this._scrollbox.scrollWidth;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
2010-11-24 01:50:20 -08:00
|
|
|
<property name="scrollPaddingRect" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
// This assumes that this._scrollbox doesn't have any border.
|
|
|
|
var outerRect = this.scrollClientRect;
|
|
|
|
var innerRect = {};
|
|
|
|
innerRect.left = outerRect.left - this._scrollbox.scrollLeft;
|
|
|
|
innerRect.top = outerRect.top - this._scrollbox.scrollTop;
|
|
|
|
innerRect.right = innerRect.left + this._scrollbox.scrollWidth;
|
|
|
|
innerRect.bottom = innerRect.top + this._scrollbox.scrollHeight;
|
|
|
|
return innerRect;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
<property name="scrollboxPaddingStart" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
var ltr = (window.getComputedStyle(this, null).direction == "ltr");
|
|
|
|
var paddingStartName = ltr ? "padding-left" : "padding-right";
|
|
|
|
var scrollboxStyle = window.getComputedStyle(this._scrollbox, null);
|
|
|
|
return parseFloat(scrollboxStyle.getPropertyValue(paddingStartName));
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
2009-04-09 05:40:59 -07:00
|
|
|
<property name="scrollPosition">
|
|
|
|
<getter><![CDATA[
|
|
|
|
return this.orient == "vertical" ?
|
|
|
|
this._scrollbox.scrollTop :
|
|
|
|
this._scrollbox.scrollLeft;
|
|
|
|
]]></getter>
|
|
|
|
<setter><![CDATA[
|
|
|
|
if (this.orient == "vertical")
|
|
|
|
this._scrollbox.scrollTop = val;
|
|
|
|
else
|
|
|
|
this._scrollbox.scrollLeft = val;
|
|
|
|
return val;
|
|
|
|
]]></setter>
|
|
|
|
</property>
|
|
|
|
|
2009-04-13 10:38:09 -07:00
|
|
|
<property name="_startEndProps" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
return this.orient == "vertical" ?
|
|
|
|
["top", "bottom"] : ["left", "right"];
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<field name="_isRTLScrollbox"><![CDATA[
|
|
|
|
this.orient != "vertical" &&
|
|
|
|
document.defaultView.getComputedStyle(this._scrollbox, "").direction == "rtl";
|
|
|
|
]]></field>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-13 23:37:26 -07:00
|
|
|
<field name="_scrollTarget">null</field>
|
|
|
|
|
2010-06-24 07:29:02 -07:00
|
|
|
<method name="_canScrollToElement">
|
|
|
|
<parameter name="element"/>
|
|
|
|
<body>
|
|
|
|
return true;
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<method name="ensureElementIsVisible">
|
2007-08-14 23:52:00 -07:00
|
|
|
<parameter name="element"/>
|
2009-04-09 05:40:59 -07:00
|
|
|
<parameter name="aSmoothScroll"/>
|
2007-03-22 10:30:00 -07:00
|
|
|
<body><![CDATA[
|
2010-06-24 07:29:02 -07:00
|
|
|
if (!this._canScrollToElement(element))
|
|
|
|
return;
|
|
|
|
|
2009-04-09 05:40:59 -07:00
|
|
|
var vertical = this.orient == "vertical";
|
|
|
|
var rect = this.scrollClientRect;
|
|
|
|
var containerStart = vertical ? rect.top : rect.left;
|
|
|
|
var containerEnd = vertical ? rect.bottom : rect.right;
|
2008-04-22 09:34:11 -07:00
|
|
|
rect = element.getBoundingClientRect();
|
2009-04-09 05:40:59 -07:00
|
|
|
var elementStart = vertical ? rect.top : rect.left;
|
|
|
|
var elementEnd = vertical ? rect.bottom : rect.right;
|
2010-11-24 01:50:20 -08:00
|
|
|
|
|
|
|
var scrollPaddingRect = this.scrollPaddingRect;
|
|
|
|
let style = window.getComputedStyle(this._scrollbox, null);
|
|
|
|
var scrollContentRect = {
|
|
|
|
left: scrollPaddingRect.left + parseFloat(style.paddingLeft),
|
|
|
|
top: scrollPaddingRect.top + parseFloat(style.paddingTop),
|
|
|
|
right: scrollPaddingRect.right - parseFloat(style.paddingRight),
|
|
|
|
bottom: scrollPaddingRect.bottom - parseFloat(style.paddingBottom)
|
|
|
|
};
|
|
|
|
|
|
|
|
if (elementStart <= (vertical ? scrollContentRect.top : scrollContentRect.left)) {
|
|
|
|
elementStart = vertical ? scrollPaddingRect.top : scrollPaddingRect.left;
|
|
|
|
}
|
|
|
|
if (elementEnd >= (vertical ? scrollContentRect.bottom : scrollContentRect.right)) {
|
|
|
|
elementEnd = vertical ? scrollPaddingRect.bottom : scrollPaddingRect.right;
|
|
|
|
}
|
|
|
|
|
2007-08-14 23:52:00 -07:00
|
|
|
var amountToScroll;
|
|
|
|
|
|
|
|
if (elementStart < containerStart) {
|
|
|
|
amountToScroll = elementStart - containerStart;
|
|
|
|
} else if (containerEnd < elementEnd) {
|
|
|
|
amountToScroll = elementEnd - containerEnd;
|
|
|
|
} else if (this._isScrolling) {
|
|
|
|
// decelerate if a currently-visible element is selected during the scroll
|
|
|
|
const STOP_DISTANCE = 15;
|
|
|
|
if (this._isScrolling == -1 && elementStart - STOP_DISTANCE < containerStart)
|
|
|
|
amountToScroll = elementStart - containerStart;
|
|
|
|
else if (this._isScrolling == 1 && containerEnd - STOP_DISTANCE < elementEnd)
|
|
|
|
amountToScroll = elementEnd - containerEnd;
|
|
|
|
else
|
|
|
|
amountToScroll = this._isScrolling * STOP_DISTANCE;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-09 05:40:59 -07:00
|
|
|
this._stopSmoothScroll();
|
|
|
|
|
2009-04-13 23:37:26 -07:00
|
|
|
if (aSmoothScroll != false && this.smoothScroll) {
|
|
|
|
this._scrollTarget = element;
|
2009-04-09 05:40:59 -07:00
|
|
|
this._smoothScrollByPixels(amountToScroll);
|
2009-04-13 23:37:26 -07:00
|
|
|
} else {
|
2009-04-09 05:40:59 -07:00
|
|
|
this.scrollByPixels(amountToScroll);
|
2009-04-13 23:37:26 -07:00
|
|
|
}
|
2008-03-04 03:24:41 -08:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_smoothScrollByPixels">
|
|
|
|
<parameter name="amountToScroll"/>
|
|
|
|
<body><![CDATA[
|
2009-04-09 05:40:59 -07:00
|
|
|
if (amountToScroll == 0)
|
|
|
|
return;
|
|
|
|
|
2007-08-14 23:52:00 -07:00
|
|
|
this._stopSmoothScroll();
|
|
|
|
|
|
|
|
// Positive amountToScroll makes us scroll right (elements fly left), negative scrolls left.
|
2010-08-20 22:16:33 -07:00
|
|
|
this._isScrolling = amountToScroll < 0 ? -1 : 1;
|
2008-05-05 13:50:59 -07:00
|
|
|
|
2010-08-20 22:16:33 -07:00
|
|
|
this._scrollAnim.start(amountToScroll);
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2010-08-20 22:16:33 -07:00
|
|
|
<field name="_scrollAnim"><![CDATA[({
|
|
|
|
scrollbox: this,
|
|
|
|
start: function scrollAnim_start(distance) {
|
|
|
|
this.distance = distance;
|
|
|
|
this.startPos = this.scrollbox.scrollPosition;
|
|
|
|
this.duration = Math.min(1000, Math.round(50 * Math.sqrt(Math.abs(distance))));
|
|
|
|
this.startTime = window.mozAnimationStartTime;
|
|
|
|
|
|
|
|
window.addEventListener("MozBeforePaint", this, false);
|
|
|
|
window.mozRequestAnimationFrame();
|
|
|
|
},
|
|
|
|
stop: function scrollAnim_stop() {
|
|
|
|
window.removeEventListener("MozBeforePaint", this, false);
|
|
|
|
},
|
|
|
|
handleEvent: function scrollAnim_handleEvent(event) {
|
|
|
|
const timePassed = event.timeStamp - this.startTime;
|
|
|
|
const pos = timePassed >= this.duration ? 1 :
|
2010-08-23 01:17:49 -07:00
|
|
|
1 - Math.pow(1 - timePassed / this.duration, 4);
|
2010-08-20 22:16:33 -07:00
|
|
|
|
|
|
|
this.scrollbox.scrollPosition = this.startPos + (this.distance * pos);
|
|
|
|
|
|
|
|
if (pos == 1)
|
|
|
|
this.scrollbox._stopSmoothScroll();
|
|
|
|
else
|
|
|
|
window.mozRequestAnimationFrame();
|
|
|
|
}
|
|
|
|
})]]></field>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<method name="scrollByIndex">
|
2007-08-14 23:52:00 -07:00
|
|
|
<parameter name="index"/>
|
2009-05-13 15:46:34 -07:00
|
|
|
<parameter name="aSmoothScroll"/>
|
2007-03-22 10:30:00 -07:00
|
|
|
<body><![CDATA[
|
2007-08-14 23:52:00 -07:00
|
|
|
if (index == 0)
|
|
|
|
return;
|
2009-04-09 05:40:59 -07:00
|
|
|
|
2009-05-13 15:46:34 -07:00
|
|
|
// Each scrollByIndex call is expected to scroll the given number of
|
|
|
|
// items. If a previous call is still in progress because of smooth
|
|
|
|
// scrolling, we need to complete it before starting a new one.
|
|
|
|
if (this._scrollTarget) {
|
|
|
|
let elements = this._getScrollableElements();
|
|
|
|
if (this._scrollTarget != elements[0] &&
|
|
|
|
this._scrollTarget != elements[elements.length - 1])
|
|
|
|
this.ensureElementIsVisible(this._scrollTarget, false);
|
|
|
|
}
|
|
|
|
|
2009-04-09 05:40:59 -07:00
|
|
|
var rect = this.scrollClientRect;
|
2009-04-13 10:38:09 -07:00
|
|
|
var [start, end] = this._startEndProps;
|
|
|
|
var x = index > 0 ? rect[end] + 1 : rect[start] - 1;
|
|
|
|
var nextElement = this._elementFromPoint(x, index);
|
2007-08-14 23:52:00 -07:00
|
|
|
if (!nextElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var targetElement;
|
2009-04-13 10:38:09 -07:00
|
|
|
if (this._isRTLScrollbox)
|
|
|
|
index *= -1;
|
2007-08-14 23:52:00 -07:00
|
|
|
while (index < 0 && nextElement) {
|
2010-07-15 11:07:20 -07:00
|
|
|
if (this._canScrollToElement(nextElement))
|
|
|
|
targetElement = nextElement;
|
2007-08-14 23:52:00 -07:00
|
|
|
nextElement = nextElement.previousSibling;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
while (index > 0 && nextElement) {
|
2010-07-15 11:07:20 -07:00
|
|
|
if (this._canScrollToElement(nextElement))
|
|
|
|
targetElement = nextElement;
|
2007-08-14 23:52:00 -07:00
|
|
|
nextElement = nextElement.nextSibling;
|
|
|
|
index--;
|
|
|
|
}
|
2010-07-15 11:07:20 -07:00
|
|
|
if (!targetElement)
|
|
|
|
return;
|
2007-08-14 23:52:00 -07:00
|
|
|
|
2009-05-13 15:46:34 -07:00
|
|
|
this.ensureElementIsVisible(targetElement, aSmoothScroll);
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2009-01-25 00:06:45 -08:00
|
|
|
<method name="_getScrollableElements">
|
|
|
|
<body><![CDATA[
|
2010-07-22 15:31:58 -07:00
|
|
|
var nodes = this.hasChildNodes() ?
|
|
|
|
this.childNodes : document.getBindingParent(this).childNodes;
|
|
|
|
return Array.filter(nodes, this._canScrollToElement, this);
|
2009-01-25 00:06:45 -08:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-10-13 18:57:47 -07:00
|
|
|
<method name="_elementFromPoint">
|
|
|
|
<parameter name="aX"/>
|
2009-04-13 10:38:09 -07:00
|
|
|
<parameter name="aPhysicalScrollDir"/>
|
2007-10-13 18:57:47 -07:00
|
|
|
<body><![CDATA[
|
2009-01-25 00:06:45 -08:00
|
|
|
var elements = this._getScrollableElements();
|
2009-04-13 10:38:09 -07:00
|
|
|
if (!elements.length)
|
2009-04-13 23:37:26 -07:00
|
|
|
return null;
|
2009-04-13 10:38:09 -07:00
|
|
|
|
2010-07-22 15:31:58 -07:00
|
|
|
if (this._isRTLScrollbox)
|
2009-04-13 10:38:09 -07:00
|
|
|
elements.reverse();
|
|
|
|
|
|
|
|
var [start, end] = this._startEndProps;
|
2007-10-13 18:57:47 -07:00
|
|
|
var low = 0;
|
|
|
|
var high = elements.length - 1;
|
|
|
|
|
2009-04-13 10:38:09 -07:00
|
|
|
if (aX < elements[low].getBoundingClientRect()[start] ||
|
|
|
|
aX > elements[high].getBoundingClientRect()[end])
|
|
|
|
return null;
|
|
|
|
|
|
|
|
var mid, rect;
|
2007-10-13 18:57:47 -07:00
|
|
|
while (low <= high) {
|
2009-04-13 10:38:09 -07:00
|
|
|
mid = Math.floor((low + high) / 2);
|
|
|
|
rect = elements[mid].getBoundingClientRect();
|
2009-04-09 05:40:59 -07:00
|
|
|
if (rect[start] > aX)
|
2007-10-13 18:57:47 -07:00
|
|
|
high = mid - 1;
|
2009-04-09 05:40:59 -07:00
|
|
|
else if (rect[end] < aX)
|
2007-10-13 18:57:47 -07:00
|
|
|
low = mid + 1;
|
|
|
|
else
|
2009-04-13 10:38:09 -07:00
|
|
|
return elements[mid];
|
2007-10-13 18:57:47 -07:00
|
|
|
}
|
|
|
|
|
2009-04-13 10:38:09 -07:00
|
|
|
// There's no element at the requested coordinate, but the algorithm
|
|
|
|
// from above yields an element next to it, in a random direction.
|
|
|
|
// The desired scrolling direction leads to the correct element.
|
|
|
|
|
|
|
|
if (!aPhysicalScrollDir)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if (aPhysicalScrollDir < 0 && rect[start] > aX)
|
|
|
|
mid = Math.max(mid - 1, 0);
|
|
|
|
else if (aPhysicalScrollDir > 0 && rect[end] < aX)
|
|
|
|
mid = Math.min(mid + 1, elements.length - 1);
|
|
|
|
|
|
|
|
return elements[mid];
|
2007-10-13 18:57:47 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-10-28 20:03:46 -07:00
|
|
|
<method name="_autorepeatbuttonScroll">
|
|
|
|
<parameter name="event"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
var dir = event.originalTarget == this._scrollButtonUp ? -1 : 1;
|
2009-04-13 10:38:09 -07:00
|
|
|
if (this._isRTLScrollbox)
|
2007-10-28 20:03:46 -07:00
|
|
|
dir *= -1;
|
|
|
|
|
|
|
|
this.scrollByPixels(this.scrollIncrement * dir);
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<method name="scrollByPixels">
|
|
|
|
<parameter name="px"/>
|
|
|
|
<body><![CDATA[
|
2009-04-09 05:40:59 -07:00
|
|
|
this.scrollPosition += px;
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-08-14 23:52:00 -07:00
|
|
|
<!-- 0: idle
|
|
|
|
1: scrolling right
|
|
|
|
-1: scrolling left -->
|
|
|
|
<field name="_isScrolling">0</field>
|
2010-06-23 10:28:12 -07:00
|
|
|
<field name="_prevMouseScrolls">[null, null]</field>
|
2007-08-14 23:52:00 -07:00
|
|
|
|
|
|
|
<method name="_stopSmoothScroll">
|
|
|
|
<body><![CDATA[
|
2008-10-20 09:52:12 -07:00
|
|
|
if (this._isScrolling) {
|
2010-08-20 22:16:33 -07:00
|
|
|
this._scrollAnim.stop();
|
2008-10-20 09:52:12 -07:00
|
|
|
this._isScrolling = 0;
|
2009-04-13 23:37:26 -07:00
|
|
|
this._scrollTarget = null;
|
2008-10-20 09:52:12 -07:00
|
|
|
}
|
2007-08-14 23:52:00 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
<method name="_updateScrollButtonsDisabledState">
|
|
|
|
<body><![CDATA[
|
|
|
|
var disableUpButton = false;
|
|
|
|
var disableDownButton = false;
|
|
|
|
|
2009-04-09 05:40:59 -07:00
|
|
|
if (this.scrollPosition == 0) {
|
|
|
|
// In the RTL case, this means the _last_ element in the
|
|
|
|
// scrollbox is visible
|
2009-04-13 10:38:09 -07:00
|
|
|
if (this._isRTLScrollbox)
|
2009-04-09 05:40:59 -07:00
|
|
|
disableDownButton = true;
|
|
|
|
else
|
|
|
|
disableUpButton = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-04-09 05:40:59 -07:00
|
|
|
else if (this.scrollClientSize + this.scrollPosition == this.scrollSize) {
|
|
|
|
// In the RTL case, this means the _first_ element in the
|
|
|
|
// scrollbox is visible
|
2009-04-13 10:38:09 -07:00
|
|
|
if (this._isRTLScrollbox)
|
2007-03-22 10:30:00 -07:00
|
|
|
disableUpButton = true;
|
2009-04-09 05:40:59 -07:00
|
|
|
else
|
2007-03-22 10:30:00 -07:00
|
|
|
disableDownButton = true;
|
|
|
|
}
|
|
|
|
|
2009-10-14 05:48:18 -07:00
|
|
|
this._scrollButtonUp.disabled = disableUpButton;
|
|
|
|
this._scrollButtonDown.disabled = disableDownButton;
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
2007-08-14 23:52:00 -07:00
|
|
|
</implementation>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
<handlers>
|
2008-08-12 20:08:59 -07:00
|
|
|
<handler event="DOMMouseScroll"><![CDATA[
|
2010-06-23 10:28:12 -07:00
|
|
|
if (this.orient == "vertical") {
|
|
|
|
// prevent horizontal scrolling from scrolling a vertical scrollbox
|
|
|
|
if (event.axis == event.HORIZONTAL_AXIS)
|
|
|
|
return;
|
|
|
|
this.scrollByIndex(event.detail);
|
|
|
|
}
|
2008-08-12 20:08:59 -07:00
|
|
|
// We allow vertical scrolling to scroll a horizontal scrollbox
|
|
|
|
// because many users have a vertical scroll wheel but no
|
|
|
|
// horizontal support.
|
2010-06-23 10:28:12 -07:00
|
|
|
// Because of this, we need to avoid scrolling chaos on trackpads
|
|
|
|
// and mouse wheels that support simultaneous scrolling in both axes.
|
|
|
|
// We do this by scrolling only when the last two scroll events were
|
|
|
|
// on the same axis as the current scroll event.
|
|
|
|
else {
|
|
|
|
let isVertical = event.axis == event.VERTICAL_AXIS;
|
|
|
|
|
|
|
|
if (this._prevMouseScrolls.every(function(prev) prev == isVertical))
|
|
|
|
this.scrollByIndex(event.detail);
|
|
|
|
|
|
|
|
if (this._prevMouseScrolls.length > 1)
|
|
|
|
this._prevMouseScrolls.shift();
|
|
|
|
this._prevMouseScrolls.push(isVertical);
|
|
|
|
}
|
2008-08-12 20:08:59 -07:00
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
]]></handler>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-12 01:18:37 -08:00
|
|
|
<handler event="underflow" phase="capturing"><![CDATA[
|
2007-03-22 10:30:00 -07:00
|
|
|
// filter underflow events which were dispatched on nested scrollboxes
|
|
|
|
if (event.target != this)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ignore events that doesn't match our orientation.
|
|
|
|
// Scrollport event orientation:
|
|
|
|
// 0: vertical
|
|
|
|
// 1: horizontal
|
|
|
|
// 2: both
|
2009-04-09 05:40:59 -07:00
|
|
|
if (this.orient == "vertical") {
|
|
|
|
if (event.detail == 1)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-04-09 05:40:59 -07:00
|
|
|
else { // horizontal scrollbox
|
|
|
|
if (event.detail == 0)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._scrollButtonUp.collapsed = true;
|
|
|
|
this._scrollButtonDown.collapsed = true;
|
|
|
|
try {
|
|
|
|
// See bug 341047 and comments in overflow handler as to why
|
|
|
|
// try..catch is needed here
|
2009-04-09 05:40:59 -07:00
|
|
|
let childNodes = this._getScrollableElements();
|
2007-08-14 23:52:00 -07:00
|
|
|
if (childNodes && childNodes.length)
|
2009-04-09 05:40:59 -07:00
|
|
|
this.ensureElementIsVisible(childNodes[0], false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
this._scrollButtonUp.collapsed = false;
|
|
|
|
this._scrollButtonDown.collapsed = false;
|
|
|
|
}
|
|
|
|
]]></handler>
|
|
|
|
|
2009-02-12 01:18:37 -08:00
|
|
|
<handler event="overflow" phase="capturing"><![CDATA[
|
2007-03-22 10:30:00 -07:00
|
|
|
// filter underflow events which were dispatched on nested scrollboxes
|
|
|
|
if (event.target != this)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ignore events that doesn't match our orientation.
|
|
|
|
// Scrollport event orientation:
|
|
|
|
// 0: vertical
|
|
|
|
// 1: horizontal
|
|
|
|
// 2: both
|
2009-04-09 05:40:59 -07:00
|
|
|
if (this.orient == "vertical") {
|
|
|
|
if (event.detail == 1)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-04-09 05:40:59 -07:00
|
|
|
else { // horizontal scrollbox
|
|
|
|
if (event.detail == 0)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._scrollButtonUp.collapsed = false;
|
|
|
|
this._scrollButtonDown.collapsed = false;
|
|
|
|
try {
|
|
|
|
// See bug 341047, the overflow event is dispatched when the
|
|
|
|
// scrollbox already is mostly destroyed. This causes some code in
|
|
|
|
// _updateScrollButtonsDisabledState() to throw an error. It also
|
|
|
|
// means that the scrollbarbuttons were uncollapsed when that should
|
|
|
|
// not be happening, because the whole overflow event should not be
|
|
|
|
// happening in that case.
|
|
|
|
this._updateScrollButtonsDisabledState();
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
this._scrollButtonUp.collapsed = true;
|
|
|
|
this._scrollButtonDown.collapsed = true;
|
|
|
|
}
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="scroll" action="this._updateScrollButtonsDisabledState()"/>
|
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
<binding id="autorepeatbutton" extends="chrome://global/content/bindings/scrollbox.xml#scrollbox-base">
|
2009-07-29 11:33:53 -07:00
|
|
|
<content repeat="hover">
|
2007-03-22 10:30:00 -07:00
|
|
|
<xul:image class="autorepeatbutton-icon"/>
|
|
|
|
</content>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
<binding id="arrowscrollbox-clicktoscroll" extends="chrome://global/content/bindings/scrollbox.xml#arrowscrollbox">
|
|
|
|
<content>
|
|
|
|
<xul:toolbarbutton class="scrollbutton-up" collapsed="true"
|
|
|
|
xbl:inherits="orient"
|
|
|
|
anonid="scrollbutton-up"
|
2007-08-26 02:17:54 -07:00
|
|
|
onclick="_distanceScroll(event);"
|
2010-07-26 16:02:58 -07:00
|
|
|
onmousedown="if (event.button == 0) _startScroll(-1);"
|
|
|
|
onmouseup="if (event.button == 0) _stopScroll();"
|
2007-08-25 17:37:18 -07:00
|
|
|
onmouseover="_continueScroll(-1);"
|
2009-07-29 11:33:53 -07:00
|
|
|
onmouseout="_pauseScroll();"/>
|
2010-11-24 01:50:20 -08:00
|
|
|
<xul:scrollbox class="arrowscrollbox-scrollbox"
|
|
|
|
anonid="scrollbox"
|
|
|
|
flex="1"
|
|
|
|
xbl:inherits="orient,align,pack,dir">
|
2007-03-22 10:30:00 -07:00
|
|
|
<children/>
|
|
|
|
</xul:scrollbox>
|
|
|
|
<xul:toolbarbutton class="scrollbutton-down" collapsed="true"
|
|
|
|
xbl:inherits="orient"
|
|
|
|
anonid="scrollbutton-down"
|
2007-08-26 02:17:54 -07:00
|
|
|
onclick="_distanceScroll(event);"
|
2010-07-26 16:02:58 -07:00
|
|
|
onmousedown="if (event.button == 0) _startScroll(1);"
|
|
|
|
onmouseup="if (event.button == 0) _stopScroll();"
|
2007-08-25 17:37:18 -07:00
|
|
|
onmouseover="_continueScroll(1);"
|
2009-07-29 11:33:53 -07:00
|
|
|
onmouseout="_pauseScroll();"/>
|
2007-03-22 10:30:00 -07:00
|
|
|
</content>
|
2007-08-25 17:37:18 -07:00
|
|
|
<implementation implements="nsITimerCallback, nsIDOMEventListener">
|
2007-03-22 10:30:00 -07:00
|
|
|
<constructor><![CDATA[
|
|
|
|
try {
|
2007-08-14 23:52:00 -07:00
|
|
|
this._scrollDelay = this._prefBranch
|
|
|
|
.getIntPref("toolkit.scrollbox.clickToScroll.scrollDelay");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
}
|
|
|
|
]]></constructor>
|
|
|
|
|
|
|
|
<destructor><![CDATA[
|
|
|
|
// Release timer to avoid reference cycles.
|
|
|
|
if (this._scrollTimer) {
|
|
|
|
this._scrollTimer.cancel();
|
|
|
|
this._scrollTimer = null;
|
|
|
|
}
|
|
|
|
]]></destructor>
|
|
|
|
|
2007-08-14 23:52:00 -07:00
|
|
|
<field name="_scrollIndex">0</field>
|
2007-03-22 10:30:00 -07:00
|
|
|
<field name="_scrollDelay">150</field>
|
|
|
|
|
|
|
|
<method name="notify">
|
|
|
|
<parameter name="aTimer"/>
|
|
|
|
<body>
|
|
|
|
<![CDATA[
|
|
|
|
if (!document)
|
|
|
|
aTimer.cancel();
|
|
|
|
|
2007-08-26 00:53:42 -07:00
|
|
|
if (this.smoothScroll)
|
|
|
|
this.scrollByPixels(25 * this._scrollIndex);
|
|
|
|
else
|
2009-04-09 05:40:59 -07:00
|
|
|
this.scrollByIndex(this._scrollIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_startScroll">
|
2007-08-14 23:52:00 -07:00
|
|
|
<parameter name="index"/>
|
2007-03-22 10:30:00 -07:00
|
|
|
<body><![CDATA[
|
2009-04-13 10:38:09 -07:00
|
|
|
if (this._isRTLScrollbox)
|
2007-10-28 20:03:46 -07:00
|
|
|
index *= -1;
|
2007-08-26 00:53:42 -07:00
|
|
|
this._scrollIndex = index;
|
|
|
|
var scrollDelay = this.smoothScroll ? 60 : this._scrollDelay;
|
|
|
|
if (!this._scrollTimer)
|
|
|
|
this._scrollTimer =
|
|
|
|
Components.classes["@mozilla.org/timer;1"]
|
|
|
|
.createInstance(Components.interfaces.nsITimer);
|
|
|
|
else
|
2007-10-28 20:03:46 -07:00
|
|
|
this._scrollTimer.cancel();
|
2007-08-14 23:52:00 -07:00
|
|
|
|
2007-10-28 20:03:46 -07:00
|
|
|
this._scrollTimer.initWithCallback(this, scrollDelay,
|
|
|
|
this._scrollTimer.TYPE_REPEATING_SLACK);
|
2007-08-26 00:53:42 -07:00
|
|
|
this.notify(this._scrollTimer);
|
2007-08-25 17:37:18 -07:00
|
|
|
this._mousedown = true;
|
2007-08-14 23:52:00 -07:00
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
<method name="_stopScroll">
|
|
|
|
<body><![CDATA[
|
2007-08-26 00:53:42 -07:00
|
|
|
if (this._scrollTimer)
|
2007-03-22 10:30:00 -07:00
|
|
|
this._scrollTimer.cancel();
|
2007-08-25 17:37:18 -07:00
|
|
|
this._mousedown = false;
|
2007-08-26 00:53:42 -07:00
|
|
|
if (!this._scrollIndex || !this.smoothScroll)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.scrollByIndex(this._scrollIndex);
|
|
|
|
this._scrollIndex = 0;
|
2007-08-25 17:37:18 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_pauseScroll">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this._mousedown) {
|
|
|
|
this._stopScroll();
|
|
|
|
this._mousedown = true;
|
|
|
|
document.addEventListener("mouseup", this, false);
|
|
|
|
document.addEventListener("blur", this, true);
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_continueScroll">
|
|
|
|
<parameter name="index"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this._mousedown)
|
|
|
|
this._startScroll(index);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="handleEvent">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (aEvent.type == "mouseup" ||
|
|
|
|
aEvent.type == "blur" && aEvent.target == document) {
|
|
|
|
this._mousedown = false;
|
|
|
|
document.removeEventListener("mouseup", this, false);
|
|
|
|
document.removeEventListener("blur", this, true);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
]]></body>
|
2007-08-14 23:52:00 -07:00
|
|
|
</method>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-26 02:17:54 -07:00
|
|
|
<method name="_distanceScroll">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
2009-04-13 10:38:09 -07:00
|
|
|
if (aEvent.detail < 2 || aEvent.detail > 3)
|
2007-08-26 02:17:54 -07:00
|
|
|
return;
|
|
|
|
|
2009-04-13 10:38:09 -07:00
|
|
|
var scrollBack = (aEvent.originalTarget == this._scrollButtonUp);
|
|
|
|
var scrollLeftOrUp = this._isRTLScrollbox ? !scrollBack : scrollBack;
|
2007-08-26 02:17:54 -07:00
|
|
|
var targetElement;
|
|
|
|
|
|
|
|
if (aEvent.detail == 2) {
|
2009-04-13 10:38:09 -07:00
|
|
|
// scroll by the size of the scrollbox
|
|
|
|
let [start, end] = this._startEndProps;
|
2009-04-09 05:40:59 -07:00
|
|
|
let x;
|
2009-04-13 10:38:09 -07:00
|
|
|
if (scrollLeftOrUp)
|
|
|
|
x = this.scrollClientRect[start] - this.scrollClientSize;
|
2007-10-13 18:57:47 -07:00
|
|
|
else
|
2009-04-13 10:38:09 -07:00
|
|
|
x = this.scrollClientRect[end] + this.scrollClientSize;
|
|
|
|
targetElement = this._elementFromPoint(x, scrollLeftOrUp ? -1 : 1);
|
2007-10-13 18:57:47 -07:00
|
|
|
|
2009-04-13 10:38:09 -07:00
|
|
|
// the next partly-hidden element will become fully visible,
|
|
|
|
// so don't scroll too far
|
2007-10-13 18:57:47 -07:00
|
|
|
if (targetElement)
|
2009-04-13 10:38:09 -07:00
|
|
|
targetElement = scrollBack ?
|
2007-10-13 18:57:47 -07:00
|
|
|
targetElement.nextSibling :
|
|
|
|
targetElement.previousSibling;
|
2007-08-26 02:17:54 -07:00
|
|
|
}
|
|
|
|
|
2007-10-13 18:57:47 -07:00
|
|
|
if (!targetElement) {
|
2007-08-26 02:17:54 -07:00
|
|
|
// scroll to the first resp. last element
|
2009-04-13 10:38:09 -07:00
|
|
|
let elements = this._getScrollableElements();
|
|
|
|
targetElement = scrollBack ?
|
|
|
|
elements[0] :
|
|
|
|
elements[elements.length - 1];
|
2007-10-13 18:57:47 -07:00
|
|
|
}
|
2007-08-26 02:17:54 -07:00
|
|
|
|
|
|
|
this.ensureElementIsVisible(targetElement);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
</implementation>
|
|
|
|
</binding>
|
|
|
|
</bindings>
|