2002-10-14 02:44:10 +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/. -->
|
|
|
|
|
2002-10-14 02:44:10 +04:00
|
|
|
|
|
|
|
<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">
|
|
|
|
|
2018-05-21 16:01:23 +03:00
|
|
|
<binding id="arrowscrollbox" extends="chrome://global/content/bindings/general.xml#basecontrol">
|
2002-10-14 02:44:10 +04:00
|
|
|
<content>
|
2018-06-01 13:15:36 +03:00
|
|
|
<xul:toolbarbutton class="scrollbutton-up"
|
|
|
|
anonid="scrollbutton-up"
|
|
|
|
xbl:inherits="orient,collapsed=notoverflowing,disabled=scrolledtostart"
|
2018-12-24 18:34:24 +03:00
|
|
|
onclick="_onButtonClick(event);"
|
|
|
|
onmousedown="_onButtonMouseDown(event, -1);"
|
|
|
|
onmouseup="_onButtonMouseUp(event);"
|
|
|
|
onmouseover="_onButtonMouseOver(-1);"
|
|
|
|
onmouseout="_onButtonMouseOut();"/>
|
2014-06-10 18:56:14 +04:00
|
|
|
<xul:spacer class="arrowscrollbox-overflow-start-indicator"
|
|
|
|
xbl:inherits="collapsed=scrolledtostart"/>
|
2010-11-24 12:50:20 +03:00
|
|
|
<xul:scrollbox class="arrowscrollbox-scrollbox"
|
|
|
|
anonid="scrollbox"
|
|
|
|
flex="1"
|
2017-08-02 23:50:02 +03:00
|
|
|
xbl:inherits="orient,align,pack,dir,smoothscroll">
|
2002-10-14 02:44:10 +04:00
|
|
|
<children/>
|
|
|
|
</xul:scrollbox>
|
2014-06-10 18:56:14 +04:00
|
|
|
<xul:spacer class="arrowscrollbox-overflow-end-indicator"
|
|
|
|
xbl:inherits="collapsed=scrolledtoend"/>
|
2018-06-01 13:15:36 +03:00
|
|
|
<xul:toolbarbutton class="scrollbutton-down"
|
|
|
|
anonid="scrollbutton-down"
|
|
|
|
xbl:inherits="orient,collapsed=notoverflowing,disabled=scrolledtoend"
|
2018-12-24 18:34:24 +03:00
|
|
|
onclick="_onButtonClick(event);"
|
|
|
|
onmousedown="_onButtonMouseDown(event, 1);"
|
|
|
|
onmouseup="_onButtonMouseUp(event);"
|
|
|
|
onmouseover="_onButtonMouseOver(1);"
|
|
|
|
onmouseout="_onButtonMouseOut();"/>
|
2002-10-14 02:44:10 +04:00
|
|
|
</content>
|
2007-08-15 10:52:00 +04:00
|
|
|
|
2003-08-17 15:10:56 +04:00
|
|
|
<implementation>
|
2014-06-10 18:56:14 +04:00
|
|
|
<constructor><![CDATA[
|
2017-08-02 23:50:02 +03:00
|
|
|
if (!this.hasAttribute("smoothscroll")) {
|
|
|
|
this.smoothScroll = this._prefBranch
|
|
|
|
.getBoolPref("toolkit.scrollbox.smoothScroll", true);
|
|
|
|
}
|
|
|
|
|
2014-06-10 18:56:14 +04:00
|
|
|
this.setAttribute("notoverflowing", "true");
|
|
|
|
this._updateScrollButtonsDisabledState();
|
|
|
|
]]></constructor>
|
|
|
|
|
2018-06-01 13:15:36 +03:00
|
|
|
<destructor><![CDATA[
|
|
|
|
// Release timer to avoid reference cycles.
|
|
|
|
if (this._scrollTimer) {
|
|
|
|
this._scrollTimer.cancel();
|
|
|
|
this._scrollTimer = null;
|
|
|
|
}
|
|
|
|
]]></destructor>
|
|
|
|
|
2019-01-04 18:07:12 +03:00
|
|
|
<field name="scrollbox">
|
2006-07-04 10:49:46 +04:00
|
|
|
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>
|
|
|
|
|
2018-12-26 17:49:14 +03:00
|
|
|
<field name="_scrollIndex">0</field>
|
|
|
|
|
|
|
|
<field name="_arrowScrollAnim"><![CDATA[({
|
|
|
|
scrollbox: this,
|
|
|
|
requestHandle: 0, /* 0 indicates there is no pending request */
|
|
|
|
start: function arrowSmoothScroll_start() {
|
|
|
|
this.lastFrameTime = window.performance.now();
|
|
|
|
if (!this.requestHandle)
|
|
|
|
this.requestHandle = window.requestAnimationFrame(this.sample.bind(this));
|
|
|
|
},
|
|
|
|
stop: function arrowSmoothScroll_stop() {
|
|
|
|
window.cancelAnimationFrame(this.requestHandle);
|
|
|
|
this.requestHandle = 0;
|
|
|
|
},
|
|
|
|
sample: function arrowSmoothScroll_handleEvent(timeStamp) {
|
|
|
|
const scrollIndex = this.scrollbox._scrollIndex;
|
|
|
|
const timePassed = timeStamp - this.lastFrameTime;
|
|
|
|
this.lastFrameTime = timeStamp;
|
|
|
|
|
|
|
|
const scrollDelta = 0.5 * timePassed * scrollIndex;
|
|
|
|
this.scrollbox.scrollByPixels(scrollDelta, true);
|
|
|
|
this.requestHandle = window.requestAnimationFrame(this.sample.bind(this));
|
|
|
|
},
|
|
|
|
})]]></field>
|
|
|
|
|
|
|
|
<property name="_clickToScroll" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
return this.hasAttribute("clicktoscroll");
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<property name="_scrollDelay" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
if (this._clickToScroll) {
|
|
|
|
return this._prefBranch.getIntPref(
|
|
|
|
"toolkit.scrollbox.clickToScroll.scrollDelay", 150);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the same REPEAT_DELAY as "nsRepeatService.h".
|
|
|
|
return /Mac/.test(navigator.platform) ? 25 : 50;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2007-08-15 10:52:00 +04:00
|
|
|
<field name="__prefBranch">null</field>
|
|
|
|
<property name="_prefBranch" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
if (this.__prefBranch === null) {
|
2018-02-28 20:51:33 +03:00
|
|
|
this.__prefBranch = Cc["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Ci.nsIPrefBranch);
|
2007-08-15 10:52:00 +04:00
|
|
|
}
|
|
|
|
return this.__prefBranch;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<field name="_scrollIncrement">null</field>
|
2006-06-27 02:35:08 +04:00
|
|
|
<property name="scrollIncrement" readonly="true">
|
|
|
|
<getter><![CDATA[
|
2007-08-15 10:52:00 +04:00
|
|
|
if (this._scrollIncrement === null) {
|
2017-03-07 17:29:48 +03:00
|
|
|
this._scrollIncrement = this._prefBranch
|
|
|
|
.getIntPref("toolkit.scrollbox.scrollIncrement", 20);
|
2006-06-27 02:35:08 +04:00
|
|
|
}
|
|
|
|
return this._scrollIncrement;
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2007-08-15 10:52:00 +04:00
|
|
|
<property name="smoothScroll">
|
|
|
|
<getter><![CDATA[
|
2017-08-02 23:50:02 +03:00
|
|
|
return this.getAttribute("smoothscroll") == "true";
|
2007-08-15 10:52:00 +04:00
|
|
|
]]></getter>
|
|
|
|
<setter><![CDATA[
|
2017-08-02 23:50:02 +03:00
|
|
|
this.setAttribute("smoothscroll", !!val);
|
2007-08-15 10:52:00 +04:00
|
|
|
return val;
|
|
|
|
]]></setter>
|
|
|
|
</property>
|
|
|
|
|
2009-04-09 16:40:59 +04:00
|
|
|
<property name="scrollClientRect" readonly="true">
|
|
|
|
<getter><![CDATA[
|
2019-01-04 18:07:12 +03:00
|
|
|
return this.scrollbox.getBoundingClientRect();
|
2009-04-09 16:40:59 +04:00
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<property name="scrollClientSize" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
return this.orient == "vertical" ?
|
2019-01-04 18:07:12 +03:00
|
|
|
this.scrollbox.clientHeight :
|
|
|
|
this.scrollbox.clientWidth;
|
2009-04-09 16:40:59 +04:00
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<property name="scrollSize" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
return this.orient == "vertical" ?
|
2019-01-04 18:07:12 +03:00
|
|
|
this.scrollbox.scrollHeight :
|
|
|
|
this.scrollbox.scrollWidth;
|
2009-04-09 16:40:59 +04:00
|
|
|
]]></getter>
|
|
|
|
</property>
|
2016-11-13 13:17:07 +03:00
|
|
|
|
|
|
|
<property name="lineScrollAmount" readonly="true">
|
|
|
|
<getter><![CDATA[
|
2016-12-10 05:39:34 +03:00
|
|
|
// line scroll amout should be the width (at horizontal scrollbox) or
|
|
|
|
// the height (at vertical scrollbox) of the scrolled elements.
|
|
|
|
// However, the elements may have different width or height. So,
|
|
|
|
// for consistent speed, let's use avalage with of the elements.
|
|
|
|
var elements = this._getScrollableElements();
|
2017-08-05 13:17:11 +03:00
|
|
|
return elements.length && (this.scrollSize / elements.length);
|
2016-11-13 13:17:07 +03:00
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2017-11-09 01:05:06 +03:00
|
|
|
<property name="scrollPosition" readonly="true">
|
|
|
|
<getter><![CDATA[
|
|
|
|
return this.orient == "vertical" ?
|
2019-01-04 18:07:12 +03:00
|
|
|
this.scrollbox.scrollTop :
|
|
|
|
this.scrollbox.scrollLeft;
|
2017-11-09 01:05:06 +03:00
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2017-06-09 16:00:38 +03:00
|
|
|
<field name="_startEndProps"><![CDATA[
|
|
|
|
this.orient == "vertical" ? ["top", "bottom"] : ["left", "right"];
|
|
|
|
]]></field>
|
2009-04-13 21:38:09 +04:00
|
|
|
|
|
|
|
<field name="_isRTLScrollbox"><![CDATA[
|
|
|
|
this.orient != "vertical" &&
|
2019-01-04 18:07:12 +03:00
|
|
|
document.defaultView.getComputedStyle(this.scrollbox).direction == "rtl";
|
2009-04-13 21:38:09 +04:00
|
|
|
]]></field>
|
2006-07-04 10:49:46 +04:00
|
|
|
|
2018-12-24 18:34:24 +03:00
|
|
|
<method name="_onButtonClick">
|
|
|
|
<parameter name="event"/>
|
|
|
|
<body><![CDATA[
|
2018-12-26 17:49:14 +03:00
|
|
|
if (this._clickToScroll) {
|
|
|
|
this._distanceScroll(event);
|
|
|
|
}
|
2018-12-24 18:34:24 +03:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_onButtonMouseDown">
|
|
|
|
<parameter name="event"/>
|
|
|
|
<parameter name="index"/>
|
|
|
|
<body><![CDATA[
|
2018-12-26 17:49:14 +03:00
|
|
|
if (this._clickToScroll && event.button == 0) {
|
|
|
|
this._startScroll(index);
|
|
|
|
}
|
2018-12-24 18:34:24 +03:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_onButtonMouseUp">
|
|
|
|
<parameter name="event"/>
|
|
|
|
<body><![CDATA[
|
2018-12-26 17:49:14 +03:00
|
|
|
if (this._clickToScroll && event.button == 0) {
|
|
|
|
this._stopScroll();
|
|
|
|
}
|
2018-12-24 18:34:24 +03:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_onButtonMouseOver">
|
|
|
|
<parameter name="index"/>
|
|
|
|
<body><![CDATA[
|
2018-12-26 17:49:14 +03:00
|
|
|
if (this._clickToScroll) {
|
|
|
|
this._continueScroll(index);
|
|
|
|
} else {
|
|
|
|
this._startScroll(index);
|
|
|
|
}
|
2018-12-24 18:34:24 +03:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_onButtonMouseOut">
|
|
|
|
<parameter name="index"/>
|
|
|
|
<body><![CDATA[
|
2018-12-26 17:49:14 +03:00
|
|
|
if (this._clickToScroll) {
|
|
|
|
this._pauseScroll();
|
|
|
|
} else {
|
|
|
|
this._stopScroll();
|
|
|
|
}
|
2018-12-24 18:34:24 +03:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2017-06-09 16:00:48 +03:00
|
|
|
<method name="_boundsWithoutFlushing">
|
|
|
|
<parameter name="element"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (!("_DOMWindowUtils" in this)) {
|
2018-07-25 02:47:42 +03:00
|
|
|
this._DOMWindowUtils = window.windowUtils;
|
2017-06-09 16:00:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return this._DOMWindowUtils ?
|
|
|
|
this._DOMWindowUtils.getBoundsWithoutFlushing(element) :
|
|
|
|
element.getBoundingClientRect();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2010-06-24 18:29:02 +04:00
|
|
|
<method name="_canScrollToElement">
|
|
|
|
<parameter name="element"/>
|
2014-03-31 18:28:57 +04:00
|
|
|
<body><![CDATA[
|
2017-06-09 16:00:48 +03:00
|
|
|
if (element.hidden) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if the element is hidden via CSS without the hidden attribute.
|
|
|
|
// If we get only zeros for the client rect, this means the element
|
|
|
|
// is hidden. As a performance optimization, we don't flush layout
|
|
|
|
// here which means that on the fly changes aren't fully supported.
|
|
|
|
let rect = this._boundsWithoutFlushing(element);
|
|
|
|
return !!(rect.top || rect.left || rect.width || rect.height);
|
2014-03-31 18:28:57 +04:00
|
|
|
]]></body>
|
2010-06-24 18:29:02 +04:00
|
|
|
</method>
|
|
|
|
|
2018-08-04 14:24:56 +03:00
|
|
|
<field name="_ensureElementIsVisibleAnimationFrame">0</field>
|
2006-06-27 02:35:08 +04:00
|
|
|
<method name="ensureElementIsVisible">
|
2007-08-15 10:52:00 +04:00
|
|
|
<parameter name="element"/>
|
2017-08-05 11:12:38 +03:00
|
|
|
<parameter name="aInstant"/>
|
2006-06-27 02:35:08 +04:00
|
|
|
<body><![CDATA[
|
2010-06-24 18:29:02 +04:00
|
|
|
if (!this._canScrollToElement(element))
|
|
|
|
return;
|
|
|
|
|
2018-08-04 14:24:56 +03:00
|
|
|
if (this._ensureElementIsVisibleAnimationFrame) {
|
|
|
|
window.cancelAnimationFrame(this._ensureElementIsVisibleAnimationFrame);
|
|
|
|
}
|
|
|
|
this._ensureElementIsVisibleAnimationFrame = window.requestAnimationFrame(() => {
|
2019-01-04 18:07:12 +03:00
|
|
|
element.scrollIntoView({ block: "nearest",
|
|
|
|
behavior: aInstant ? "instant" : "auto" });
|
2018-08-04 14:24:56 +03:00
|
|
|
this._ensureElementIsVisibleAnimationFrame = 0;
|
|
|
|
});
|
2008-03-04 14:24:41 +03:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2003-08-17 15:10:56 +04:00
|
|
|
<method name="scrollByIndex">
|
2007-08-15 10:52:00 +04:00
|
|
|
<parameter name="index"/>
|
2017-08-05 11:12:38 +03:00
|
|
|
<parameter name="aInstant"/>
|
2003-08-17 15:10:56 +04:00
|
|
|
<body><![CDATA[
|
2007-08-15 10:52:00 +04:00
|
|
|
if (index == 0)
|
|
|
|
return;
|
2009-04-09 16:40:59 +04:00
|
|
|
|
2009-04-09 16:40:59 +04:00
|
|
|
var rect = this.scrollClientRect;
|
2009-04-13 21:38:09 +04:00
|
|
|
var [start, end] = this._startEndProps;
|
|
|
|
var x = index > 0 ? rect[end] + 1 : rect[start] - 1;
|
|
|
|
var nextElement = this._elementFromPoint(x, index);
|
2007-08-15 10:52:00 +04:00
|
|
|
if (!nextElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var targetElement;
|
2009-04-13 21:38:09 +04:00
|
|
|
if (this._isRTLScrollbox)
|
|
|
|
index *= -1;
|
2007-08-15 10:52:00 +04:00
|
|
|
while (index < 0 && nextElement) {
|
2010-07-15 22:07:20 +04:00
|
|
|
if (this._canScrollToElement(nextElement))
|
|
|
|
targetElement = nextElement;
|
2018-08-09 01:22:53 +03:00
|
|
|
nextElement = nextElement.previousElementSibling;
|
2007-08-15 10:52:00 +04:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
while (index > 0 && nextElement) {
|
2010-07-15 22:07:20 +04:00
|
|
|
if (this._canScrollToElement(nextElement))
|
|
|
|
targetElement = nextElement;
|
2018-08-09 01:22:53 +03:00
|
|
|
nextElement = nextElement.nextElementSibling;
|
2007-08-15 10:52:00 +04:00
|
|
|
index--;
|
|
|
|
}
|
2010-07-15 22:07:20 +04:00
|
|
|
if (!targetElement)
|
|
|
|
return;
|
2007-08-15 10:52:00 +04:00
|
|
|
|
2017-08-05 11:12:38 +03:00
|
|
|
this.ensureElementIsVisible(targetElement, aInstant);
|
2006-06-27 02:35:08 +04:00
|
|
|
]]></body>
|
|
|
|
</method>
|
2003-08-17 15:10:56 +04:00
|
|
|
|
2009-01-25 11:06:45 +03:00
|
|
|
<method name="_getScrollableElements">
|
|
|
|
<body><![CDATA[
|
2018-08-09 01:22:53 +03:00
|
|
|
var nodes = this.children;
|
2013-07-04 02:07:28 +04:00
|
|
|
if (nodes.length == 1 &&
|
|
|
|
nodes[0].localName == "children" &&
|
|
|
|
nodes[0].namespaceURI == "http://www.mozilla.org/xbl") {
|
2018-08-09 01:22:53 +03:00
|
|
|
nodes = document.getBindingParent(this).children;
|
2013-07-04 02:07:28 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 02:31:58 +04:00
|
|
|
return Array.filter(nodes, this._canScrollToElement, this);
|
2009-01-25 11:06:45 +03:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2007-10-14 05:57:47 +04:00
|
|
|
<method name="_elementFromPoint">
|
|
|
|
<parameter name="aX"/>
|
2009-04-13 21:38:09 +04:00
|
|
|
<parameter name="aPhysicalScrollDir"/>
|
2007-10-14 05:57:47 +04:00
|
|
|
<body><![CDATA[
|
2009-01-25 11:06:45 +03:00
|
|
|
var elements = this._getScrollableElements();
|
2009-04-13 21:38:09 +04:00
|
|
|
if (!elements.length)
|
2009-04-14 10:37:26 +04:00
|
|
|
return null;
|
2009-04-13 21:38:09 +04:00
|
|
|
|
2010-07-23 02:31:58 +04:00
|
|
|
if (this._isRTLScrollbox)
|
2009-04-13 21:38:09 +04:00
|
|
|
elements.reverse();
|
|
|
|
|
|
|
|
var [start, end] = this._startEndProps;
|
2007-10-14 05:57:47 +04:00
|
|
|
var low = 0;
|
|
|
|
var high = elements.length - 1;
|
|
|
|
|
2009-04-13 21:38:09 +04:00
|
|
|
if (aX < elements[low].getBoundingClientRect()[start] ||
|
|
|
|
aX > elements[high].getBoundingClientRect()[end])
|
|
|
|
return null;
|
|
|
|
|
|
|
|
var mid, rect;
|
2007-10-14 05:57:47 +04:00
|
|
|
while (low <= high) {
|
2009-04-13 21:38:09 +04:00
|
|
|
mid = Math.floor((low + high) / 2);
|
|
|
|
rect = elements[mid].getBoundingClientRect();
|
2009-04-09 16:40:59 +04:00
|
|
|
if (rect[start] > aX)
|
2016-02-04 01:22:33 +03:00
|
|
|
high = mid - 1;
|
2009-04-09 16:40:59 +04:00
|
|
|
else if (rect[end] < aX)
|
2007-10-14 05:57:47 +04:00
|
|
|
low = mid + 1;
|
|
|
|
else
|
2009-04-13 21:38:09 +04:00
|
|
|
return elements[mid];
|
2007-10-14 05:57:47 +04:00
|
|
|
}
|
|
|
|
|
2009-04-13 21:38:09 +04: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-14 05:57:47 +04:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2018-06-01 13:15:36 +03:00
|
|
|
<method name="_startScroll">
|
|
|
|
<parameter name="index"/>
|
2007-10-29 06:03:46 +03:00
|
|
|
<body><![CDATA[
|
2018-06-01 13:15:36 +03:00
|
|
|
if (this._isRTLScrollbox) {
|
|
|
|
index *= -1;
|
|
|
|
}
|
2007-10-29 06:03:46 +03:00
|
|
|
|
2018-12-26 17:49:14 +03:00
|
|
|
if (this._clickToScroll) {
|
|
|
|
this._scrollIndex = index;
|
|
|
|
this._mousedown = true;
|
|
|
|
|
|
|
|
if (this.smoothScroll) {
|
|
|
|
this._arrowScrollAnim.start();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-01 13:15:36 +03:00
|
|
|
if (!this._scrollTimer) {
|
|
|
|
this._scrollTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
} else {
|
|
|
|
this._scrollTimer.cancel();
|
|
|
|
}
|
2007-10-29 06:03:46 +03:00
|
|
|
|
2018-12-26 17:49:14 +03:00
|
|
|
let callback;
|
|
|
|
if (this._clickToScroll) {
|
|
|
|
callback = () => {
|
|
|
|
if (!document && this._scrollTimer) {
|
|
|
|
this._scrollTimer.cancel();
|
|
|
|
}
|
|
|
|
this.scrollByIndex(this._scrollIndex);
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
callback = () => this.scrollByPixels(this.scrollIncrement * index);
|
|
|
|
}
|
2018-06-01 13:15:36 +03:00
|
|
|
|
2018-12-26 17:49:14 +03:00
|
|
|
this._scrollTimer.initWithCallback(callback, this._scrollDelay,
|
2018-06-01 13:15:36 +03:00
|
|
|
Ci.nsITimer.TYPE_REPEATING_SLACK);
|
2018-12-26 17:49:14 +03:00
|
|
|
|
2018-06-01 13:15:36 +03:00
|
|
|
callback();
|
|
|
|
]]>
|
|
|
|
</body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_stopScroll">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this._scrollTimer)
|
|
|
|
this._scrollTimer.cancel();
|
2018-12-26 17:49:14 +03:00
|
|
|
|
|
|
|
if (this._clickToScroll) {
|
|
|
|
this._mousedown = false;
|
|
|
|
if (!this._scrollIndex || !this.smoothScroll)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.scrollByIndex(this._scrollIndex);
|
|
|
|
this._scrollIndex = 0;
|
|
|
|
|
|
|
|
this._arrowScrollAnim.stop();
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_pauseScroll">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this._mousedown) {
|
|
|
|
this._stopScroll();
|
|
|
|
this._mousedown = true;
|
|
|
|
document.addEventListener("mouseup", this);
|
|
|
|
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="_distanceScroll">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (aEvent.detail < 2 || aEvent.detail > 3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var scrollBack = (aEvent.originalTarget == this._scrollButtonUp);
|
|
|
|
var scrollLeftOrUp = this._isRTLScrollbox ? !scrollBack : scrollBack;
|
|
|
|
var targetElement;
|
|
|
|
|
|
|
|
if (aEvent.detail == 2) {
|
|
|
|
// scroll by the size of the scrollbox
|
|
|
|
let [start, end] = this._startEndProps;
|
|
|
|
let x;
|
|
|
|
if (scrollLeftOrUp)
|
|
|
|
x = this.scrollClientRect[start] - this.scrollClientSize;
|
|
|
|
else
|
|
|
|
x = this.scrollClientRect[end] + this.scrollClientSize;
|
|
|
|
targetElement = this._elementFromPoint(x, scrollLeftOrUp ? -1 : 1);
|
|
|
|
|
|
|
|
// the next partly-hidden element will become fully visible,
|
|
|
|
// so don't scroll too far
|
|
|
|
if (targetElement)
|
|
|
|
targetElement = scrollBack ?
|
|
|
|
targetElement.nextElementSibling :
|
|
|
|
targetElement.previousElementSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!targetElement) {
|
|
|
|
// scroll to the first resp. last element
|
|
|
|
let elements = this._getScrollableElements();
|
|
|
|
targetElement = scrollBack ?
|
|
|
|
elements[0] :
|
|
|
|
elements[elements.length - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.ensureElementIsVisible(targetElement);
|
|
|
|
]]></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);
|
|
|
|
document.removeEventListener("blur", this, true);
|
|
|
|
}
|
2007-10-29 06:03:46 +03:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2006-06-27 02:35:08 +04:00
|
|
|
<method name="scrollByPixels">
|
2017-08-05 11:12:38 +03:00
|
|
|
<parameter name="aPixels"/>
|
|
|
|
<parameter name="aInstant"/>
|
2006-06-27 02:35:08 +04:00
|
|
|
<body><![CDATA[
|
2017-08-05 11:12:38 +03:00
|
|
|
let scrollOptions = { behavior: aInstant ? "instant" : "auto" };
|
|
|
|
scrollOptions[this._startEndProps[0]] = aPixels;
|
2019-01-04 18:07:12 +03:00
|
|
|
this.scrollbox.scrollBy(scrollOptions);
|
2003-08-17 15:10:56 +04:00
|
|
|
]]></body>
|
2006-07-04 10:49:46 +04:00
|
|
|
</method>
|
|
|
|
|
2010-06-23 21:28:12 +04:00
|
|
|
<field name="_prevMouseScrolls">[null, null]</field>
|
2007-08-15 10:52:00 +04:00
|
|
|
|
2016-09-29 17:05:25 +03:00
|
|
|
<field name="_touchStart">-1</field>
|
|
|
|
|
2017-06-21 16:08:30 +03:00
|
|
|
<field name="_scrollButtonUpdatePending">false</field>
|
2006-07-04 10:49:46 +04:00
|
|
|
<method name="_updateScrollButtonsDisabledState">
|
|
|
|
<body><![CDATA[
|
2014-06-10 18:56:14 +04:00
|
|
|
if (this.hasAttribute("notoverflowing")) {
|
2017-06-01 00:39:30 +03:00
|
|
|
this.setAttribute("scrolledtoend", "true");
|
|
|
|
this.setAttribute("scrolledtostart", "true");
|
2017-06-21 16:08:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._scrollButtonUpdatePending) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._scrollButtonUpdatePending = true;
|
|
|
|
|
|
|
|
// Wait until after the next paint to get current layout data from
|
|
|
|
// getBoundsWithoutFlushing.
|
|
|
|
window.requestAnimationFrame(() => {
|
|
|
|
setTimeout(() => {
|
2019-01-04 18:07:12 +03:00
|
|
|
if (!this._startEndProps) {
|
|
|
|
// We've been destroyed in the meantime.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-21 16:08:30 +03:00
|
|
|
this._scrollButtonUpdatePending = false;
|
|
|
|
|
|
|
|
let scrolledToStart = false;
|
|
|
|
let scrolledToEnd = false;
|
|
|
|
|
|
|
|
if (this.hasAttribute("notoverflowing")) {
|
|
|
|
scrolledToStart = true;
|
|
|
|
scrolledToEnd = true;
|
|
|
|
} else {
|
2017-06-30 01:56:21 +03:00
|
|
|
let [leftOrTop, rightOrBottom] = this._startEndProps;
|
|
|
|
let leftOrTopEdge = ele => Math.round(this._boundsWithoutFlushing(ele)[leftOrTop]);
|
|
|
|
let rightOrBottomEdge = ele => Math.round(this._boundsWithoutFlushing(ele)[rightOrBottom]);
|
|
|
|
|
|
|
|
let elements = this._getScrollableElements();
|
|
|
|
let [leftOrTopElement, rightOrBottomElement] = [elements[0], elements[elements.length - 1]];
|
2017-06-21 16:08:30 +03:00
|
|
|
if (this._isRTLScrollbox) {
|
2017-06-30 01:56:21 +03:00
|
|
|
[leftOrTopElement, rightOrBottomElement] = [rightOrBottomElement, leftOrTopElement];
|
2017-06-21 16:08:30 +03:00
|
|
|
}
|
|
|
|
|
2017-06-30 01:56:21 +03:00
|
|
|
if (leftOrTopElement &&
|
2019-01-04 18:07:12 +03:00
|
|
|
leftOrTopEdge(leftOrTopElement) >= leftOrTopEdge(this.scrollbox)) {
|
2017-06-30 01:56:21 +03:00
|
|
|
scrolledToStart = !this._isRTLScrollbox;
|
|
|
|
scrolledToEnd = this._isRTLScrollbox;
|
|
|
|
} else if (rightOrBottomElement &&
|
2019-01-04 18:07:12 +03:00
|
|
|
rightOrBottomEdge(rightOrBottomElement) <= rightOrBottomEdge(this.scrollbox)) {
|
2017-06-30 01:56:21 +03:00
|
|
|
scrolledToStart = this._isRTLScrollbox;
|
|
|
|
scrolledToEnd = !this._isRTLScrollbox;
|
2017-06-21 16:08:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scrolledToEnd) {
|
|
|
|
this.setAttribute("scrolledtoend", "true");
|
|
|
|
} else {
|
|
|
|
this.removeAttribute("scrolledtoend");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scrolledToStart) {
|
|
|
|
this.setAttribute("scrolledtostart", "true");
|
|
|
|
} else {
|
|
|
|
this.removeAttribute("scrolledtostart");
|
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
});
|
2006-07-04 10:49:46 +04:00
|
|
|
]]></body>
|
|
|
|
</method>
|
2017-11-09 01:05:06 +03:00
|
|
|
|
|
|
|
<field name="_isScrolling">false</field>
|
|
|
|
<field name="_destination">0</field>
|
|
|
|
<field name="_direction">0</field>
|
2007-08-15 10:52:00 +04:00
|
|
|
</implementation>
|
2003-08-17 15:10:56 +04:00
|
|
|
|
2002-10-14 02:44:10 +04:00
|
|
|
<handlers>
|
2016-01-05 20:35:23 +03:00
|
|
|
<handler event="wheel"><![CDATA[
|
2018-11-30 17:36:15 +03:00
|
|
|
// Don't consume the event if we can't scroll.
|
|
|
|
if (this.hasAttribute("notoverflowing")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
let doScroll = false;
|
2017-08-05 11:12:38 +03:00
|
|
|
let instant;
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
let scrollAmount = 0;
|
2010-06-23 21:28:12 +04:00
|
|
|
if (this.orient == "vertical") {
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
doScroll = true;
|
2016-01-05 20:35:23 +03:00
|
|
|
if (event.deltaMode == event.DOM_DELTA_PIXEL)
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
scrollAmount = event.deltaY;
|
2016-05-05 20:39:54 +03:00
|
|
|
else if (event.deltaMode == event.DOM_DELTA_PAGE)
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
scrollAmount = event.deltaY * this.scrollClientSize;
|
2016-01-05 20:35:23 +03:00
|
|
|
else
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
scrollAmount = event.deltaY * this.lineScrollAmount;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else {
|
|
|
|
// We allow vertical scrolling to scroll a horizontal scrollbox
|
|
|
|
// because many users have a vertical scroll wheel but no
|
|
|
|
// horizontal support.
|
|
|
|
// 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.
|
|
|
|
// For diagonal scroll events we only respect the dominant axis.
|
2016-01-05 20:35:23 +03:00
|
|
|
let isVertical = Math.abs(event.deltaY) > Math.abs(event.deltaX);
|
|
|
|
let delta = isVertical ? event.deltaY : event.deltaX;
|
|
|
|
let scrollByDelta = isVertical && this._isRTLScrollbox ? -delta : delta;
|
2010-06-23 21:28:12 +04:00
|
|
|
|
2016-01-05 20:35:23 +03:00
|
|
|
if (this._prevMouseScrolls.every(prev => prev == isVertical)) {
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
doScroll = true;
|
2017-08-05 11:12:38 +03:00
|
|
|
if (event.deltaMode == event.DOM_DELTA_PIXEL) {
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
scrollAmount = scrollByDelta;
|
2017-08-05 11:12:38 +03:00
|
|
|
instant = true;
|
|
|
|
} else if (event.deltaMode == event.DOM_DELTA_PAGE) {
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
scrollAmount = scrollByDelta * this.scrollClientSize;
|
2017-08-05 11:12:38 +03:00
|
|
|
} else {
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
scrollAmount = scrollByDelta * this.lineScrollAmount;
|
2017-08-05 11:12:38 +03:00
|
|
|
}
|
2016-01-05 20:35:23 +03:00
|
|
|
}
|
2010-06-23 21:28:12 +04:00
|
|
|
|
|
|
|
if (this._prevMouseScrolls.length > 1)
|
|
|
|
this._prevMouseScrolls.shift();
|
|
|
|
this._prevMouseScrolls.push(isVertical);
|
|
|
|
}
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
|
|
|
|
if (doScroll) {
|
2017-11-09 01:05:06 +03:00
|
|
|
let direction = scrollAmount < 0 ? -1 : 1;
|
|
|
|
let startPos = this.scrollPosition;
|
|
|
|
|
|
|
|
if (!this._isScrolling || this._direction != direction) {
|
|
|
|
this._destination = startPos + scrollAmount;
|
|
|
|
this._direction = direction;
|
|
|
|
} else {
|
|
|
|
// We were already in the process of scrolling in this direction
|
|
|
|
this._destination = this._destination + scrollAmount;
|
|
|
|
scrollAmount = this._destination - startPos;
|
|
|
|
}
|
2017-08-05 11:12:38 +03:00
|
|
|
this.scrollByPixels(scrollAmount, instant);
|
Bug 1320609 part.1 wheel event handler of <scrollbox> should use |_smoothScrollByPixels| instead of |scrollByPixels| when the deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE r=mstange
<scrollbox> should scroll its contents smoothly even if wheel device doesn't support high resolution scroll.
This patch makes the wheel event handler use |_smoothScrollByPixels| when deltaMode is DOM_DELTA_LINE or DOM_DELTA_PAGE. The reason why ignoring DOM_DELTA_PIXEL is, such devices are typically supports high resolution scroll. Therefore, <scrollbox> doesn't need to animate its scroll by itself.
However, |_smoothScrollByPixels| doesn't work fine without some additional fixes.
First, this patch doesn't stop pending scroll from |_smoothScrollByPixels| because discarding some pending scroll causes slower scroll. Actually, when you turn mouse wheel faster, scroll amount becomes smaller without this fix.
Next, this patch adds continous scroll mode to |_scrollAnim| object. If it's requested new animation during processing previous scroll, it keeps previous scroll amount and restart animation with new destination. Additionally, accumulating the scroll distance as fractional value. Therefore, it scrolls 3px when 1.5px scroll is requested twice.
Finally, this patch discards pending scrolls when user tries to scroll to reverse direction. When user tries to scroll to reserse direction, the user must want to scroll the contents from current position rather than actual scroll destination. Therefore, this patch discards pending scrolls in |_smoothScrollByPixels|. Although, it might be better to handle this in |_scrollAnim|. However, |_isScrolling| is not managed by it and changing the behavior in private method is safer than changing utility object (i.e., |_scrollAnim|).
Additionally, this patch fixes timestamp issue at callback of requestAnimationFrame(). Sometimes, the given timestamp is older than start time. In that case, current code scrolls to reverse diretion. Therefore, we should treat such old timestamp as same as start time.
MozReview-Commit-ID: DluWUN2VhVw
--HG--
extra : rebase_source : 067467444c7a0aee4d551410c50de3a8a97601c5
2016-12-22 14:04:35 +03:00
|
|
|
}
|
2008-08-13 07:08:59 +04:00
|
|
|
|
|
|
|
event.stopPropagation();
|
2011-09-08 17:31:01 +04:00
|
|
|
event.preventDefault();
|
|
|
|
]]></handler>
|
|
|
|
|
2016-09-29 17:05:25 +03:00
|
|
|
<handler event="touchstart"><![CDATA[
|
|
|
|
if (event.touches.length > 1) {
|
|
|
|
// Multiple touch points detected, abort. In particular this aborts
|
|
|
|
// the panning gesture when the user puts a second finger down after
|
|
|
|
// already panning with one finger. Aborting at this point prevents
|
|
|
|
// the pan gesture from being resumed until all fingers are lifted
|
|
|
|
// (as opposed to when the user is back down to one finger).
|
|
|
|
this._touchStart = -1;
|
|
|
|
} else {
|
|
|
|
this._touchStart = (this.orient == "vertical"
|
|
|
|
? event.touches[0].screenY
|
|
|
|
: event.touches[0].screenX);
|
|
|
|
}
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="touchmove"><![CDATA[
|
|
|
|
if (event.touches.length == 1 &&
|
|
|
|
this._touchStart >= 0) {
|
|
|
|
var touchPoint = (this.orient == "vertical"
|
|
|
|
? event.touches[0].screenY
|
|
|
|
: event.touches[0].screenX);
|
|
|
|
var delta = this._touchStart - touchPoint;
|
|
|
|
if (Math.abs(delta) > 0) {
|
2017-08-05 11:12:38 +03:00
|
|
|
this.scrollByPixels(delta, true);
|
2016-09-29 17:05:25 +03:00
|
|
|
this._touchStart = touchPoint;
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="touchend"><![CDATA[
|
|
|
|
this._touchStart = -1;
|
|
|
|
]]></handler>
|
|
|
|
|
2009-02-12 12:18:37 +03:00
|
|
|
<handler event="underflow" phase="capturing"><![CDATA[
|
2018-02-15 22:03:51 +03:00
|
|
|
// Ignore underflow events:
|
|
|
|
// - from nested scrollable elements
|
|
|
|
// - corresponding to an overflow event that we ignored
|
|
|
|
if (event.target != this ||
|
|
|
|
this.hasAttribute("notoverflowing")) {
|
2006-08-02 21:20:13 +04:00
|
|
|
return;
|
2018-02-15 22:03:51 +03:00
|
|
|
}
|
2006-08-02 21:20:13 +04:00
|
|
|
|
2007-01-28 01:50:18 +03:00
|
|
|
// Ignore events that doesn't match our orientation.
|
|
|
|
// Scrollport event orientation:
|
|
|
|
// 0: vertical
|
|
|
|
// 1: horizontal
|
|
|
|
// 2: both
|
2009-04-09 16:40:59 +04:00
|
|
|
if (this.orient == "vertical") {
|
|
|
|
if (event.detail == 1)
|
2007-01-28 01:50:18 +03:00
|
|
|
return;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else if (event.detail == 0) {
|
2016-08-12 18:50:35 +03:00
|
|
|
// horizontal scrollbox
|
|
|
|
return;
|
2007-01-28 01:50:18 +03:00
|
|
|
}
|
|
|
|
|
2014-06-10 18:56:14 +04:00
|
|
|
this.setAttribute("notoverflowing", "true");
|
2017-08-05 15:43:41 +03:00
|
|
|
this._updateScrollButtonsDisabledState();
|
2002-10-14 02:44:10 +04:00
|
|
|
]]></handler>
|
|
|
|
|
2009-02-12 12:18:37 +03:00
|
|
|
<handler event="overflow" phase="capturing"><![CDATA[
|
2018-02-15 22:03:51 +03:00
|
|
|
// Ignore overflow events:
|
|
|
|
// - from nested scrollable elements
|
2018-07-04 22:53:53 +03:00
|
|
|
if (event.target != this) {
|
2006-08-02 21:20:13 +04:00
|
|
|
return;
|
2018-02-15 22:03:51 +03:00
|
|
|
}
|
2006-08-02 21:20:13 +04:00
|
|
|
|
2007-01-28 01:50:18 +03:00
|
|
|
// Ignore events that doesn't match our orientation.
|
|
|
|
// Scrollport event orientation:
|
|
|
|
// 0: vertical
|
|
|
|
// 1: horizontal
|
|
|
|
// 2: both
|
2009-04-09 16:40:59 +04:00
|
|
|
if (this.orient == "vertical") {
|
|
|
|
if (event.detail == 1)
|
2007-01-28 01:50:18 +03:00
|
|
|
return;
|
2016-12-31 05:47:25 +03:00
|
|
|
} else if (event.detail == 0) {
|
2016-08-12 18:50:35 +03:00
|
|
|
// horizontal scrollbox
|
|
|
|
return;
|
2007-01-28 01:50:18 +03:00
|
|
|
}
|
|
|
|
|
2014-06-10 18:56:14 +04:00
|
|
|
this.removeAttribute("notoverflowing");
|
2017-08-05 15:43:41 +03:00
|
|
|
this._updateScrollButtonsDisabledState();
|
2002-10-14 02:44:10 +04:00
|
|
|
]]></handler>
|
2006-07-04 10:49:46 +04:00
|
|
|
|
2017-05-25 16:08:54 +03:00
|
|
|
<handler event="scroll"><![CDATA[
|
2017-11-09 01:05:06 +03:00
|
|
|
this._isScrolling = true;
|
2017-06-21 16:08:30 +03:00
|
|
|
this._updateScrollButtonsDisabledState();
|
2017-05-25 16:08:54 +03:00
|
|
|
]]></handler>
|
2017-11-09 01:05:06 +03:00
|
|
|
|
|
|
|
<handler event="scrollend"><![CDATA[
|
|
|
|
this._isScrolling = false;
|
|
|
|
this._destination = 0;
|
|
|
|
this._direction = 0;
|
|
|
|
]]></handler>
|
2002-10-14 02:44:10 +04:00
|
|
|
</handlers>
|
|
|
|
</binding>
|
2003-08-17 15:10:56 +04:00
|
|
|
</bindings>
|