mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 07:37:58 +01:00
Move smooth-scroll plugin to the core.
This commit is contained in:
@@ -523,7 +523,7 @@ dactylUtils::LoadSubScript (const PRUnichar * aURL
|
||||
|
||||
nsCAutoString cachePath;
|
||||
cachePath.Append("jssubloader/");
|
||||
cachePath.Append(version);
|
||||
cachePath.AppendInt(version);
|
||||
if (charset) {
|
||||
cachePath.Append("/");
|
||||
cachePath.Append(NS_ConvertUTF16toUTF8(
|
||||
|
||||
@@ -1316,16 +1316,19 @@ var Buffer = Module("buffer", {
|
||||
*
|
||||
* @param {Element} elem The element to scroll.
|
||||
* @param {number|null} left The left absolute pixel offset. If
|
||||
* null, to not alter the horizontal scroll offset.
|
||||
* null, to not alter the horizontal scroll offset.
|
||||
* @param {number|null} top The top absolute pixel offset. If
|
||||
* null, to not alter the vertical scroll offset.
|
||||
* null, to not alter the vertical scroll offset.
|
||||
* @param {string} reason The reason for the scroll event. See
|
||||
* {@link marks.push}. @optional
|
||||
* {@link marks.push}. @optional
|
||||
*/
|
||||
scrollTo: function scrollTo(elem, left, top, reason) {
|
||||
if (~[elem, elem.document, elem.ownerDocument].indexOf(buffer.focusedFrame.document))
|
||||
marks.push(reason);
|
||||
|
||||
if (options["scrollsteps"] > 1)
|
||||
return this.smoothScrollTo(elem, left, top);
|
||||
|
||||
elem = Buffer.Scrollable(elem);
|
||||
if (left != null)
|
||||
elem.scrollLeft = left;
|
||||
@@ -1338,6 +1341,39 @@ var Buffer = Module("buffer", {
|
||||
.redraw();
|
||||
},
|
||||
|
||||
/**
|
||||
* Like scrollTo, but scrolls more smoothly and does not update
|
||||
* marks.
|
||||
*/
|
||||
smoothScrollTo: function smoothScrollTo(elem, x, y) {
|
||||
let time = options["scrolltime"];
|
||||
let steps = options["scrollsteps"];
|
||||
|
||||
let data = elem;
|
||||
elem = Buffer.Scrollable(elem);
|
||||
|
||||
if (data.dactylScrollTimer)
|
||||
data.dactylScrollTimer.cancel();
|
||||
|
||||
x = data.dactylScrollDestX = Math.min(x, elem.scrollWidth - elem.clientWidth);
|
||||
y = data.dactylScrollDestY = Math.min(y, elem.scrollHeight - elem.clientHeight);
|
||||
let [startX, startY] = [elem.scrollLeft, elem.scrollTop];
|
||||
let n = 0;
|
||||
(function next() {
|
||||
if (n++ === steps) {
|
||||
elem.scrollLeft = x;
|
||||
elem.scrollTop = y;
|
||||
delete data.dactylScrollDestX;
|
||||
delete data.dactylScrollDestY;
|
||||
}
|
||||
else {
|
||||
elem.scrollLeft = startX + (x - startX) / steps * n;
|
||||
elem.scrollTop = startY + (y - startY) / steps * n;
|
||||
data.dactylScrollTimer = util.timeout(next, time / steps);
|
||||
}
|
||||
}).call(this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Scrolls the currently given element horizontally.
|
||||
*
|
||||
@@ -1353,6 +1389,7 @@ var Buffer = Module("buffer", {
|
||||
scrollHorizontal: function scrollHorizontal(elem, unit, number) {
|
||||
let fontSize = parseInt(DOM(elem).style.fontSize);
|
||||
|
||||
let data = elem;
|
||||
elem = Buffer.Scrollable(elem);
|
||||
let increment;
|
||||
if (unit == "columns")
|
||||
@@ -1364,8 +1401,8 @@ var Buffer = Module("buffer", {
|
||||
|
||||
dactyl.assert(number < 0 ? elem.scrollLeft > 0 : elem.scrollLeft < elem.scrollWidth - elem.clientWidth);
|
||||
|
||||
let left = elem.dactylScrollDestX !== undefined ? elem.dactylScrollDestX : elem.scrollLeft;
|
||||
elem.dactylScrollDestX = undefined;
|
||||
let left = data.dactylScrollDestX !== undefined ? data.dactylScrollDestX : elem.scrollLeft;
|
||||
data.dactylScrollDestX = undefined;
|
||||
|
||||
Buffer.scrollTo(elem, left + number * increment, null, "h-" + unit);
|
||||
},
|
||||
@@ -1385,6 +1422,7 @@ var Buffer = Module("buffer", {
|
||||
scrollVertical: function scrollVertical(elem, unit, number) {
|
||||
let fontSize = parseInt(DOM(elem).style.lineHeight);
|
||||
|
||||
let data = elem;
|
||||
elem = Buffer.Scrollable(elem);
|
||||
let increment;
|
||||
if (unit == "lines")
|
||||
@@ -1396,8 +1434,8 @@ var Buffer = Module("buffer", {
|
||||
|
||||
dactyl.assert(number < 0 ? elem.scrollTop > 0 : elem.scrollTop < elem.scrollHeight - elem.clientHeight);
|
||||
|
||||
let top = elem.dactylScrollDestY !== undefined ? elem.dactylScrollDestY : elem.scrollTop;
|
||||
elem.dactylScrollDestY = undefined;
|
||||
let top = data.dactylScrollDestY !== undefined ? data.dactylScrollDestY : elem.scrollTop;
|
||||
data.dactylScrollDestY = undefined;
|
||||
|
||||
Buffer.scrollTo(elem, null, top + number * increment, "v-" + unit);
|
||||
},
|
||||
@@ -2234,6 +2272,28 @@ var Buffer = Module("buffer", {
|
||||
}
|
||||
});
|
||||
|
||||
options.add(["scrolltime", "st"],
|
||||
"The time, in milliseconds, in which to smooth scroll to a new position",
|
||||
"number", 100);
|
||||
|
||||
options.add(["scrollsteps", "ss"],
|
||||
"The number of steps in which to smooth scroll to a new position",
|
||||
"number", 5,
|
||||
{
|
||||
PREF: "general.smoothScroll",
|
||||
|
||||
initValue: function () {},
|
||||
|
||||
getter: function getter(value) !prefs.get(this.PREF) ? 1 : value,
|
||||
|
||||
setter: function setter(value) {
|
||||
prefs.set(this.PREF, value > 1);
|
||||
return value > 1 ? value : this.globalValue;
|
||||
},
|
||||
|
||||
validator: function (value) value > 0
|
||||
});
|
||||
|
||||
options.add(["usermode", "um"],
|
||||
"Show current website without styling defined by the author",
|
||||
"boolean", false,
|
||||
|
||||
@@ -1381,6 +1381,28 @@
|
||||
</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<tags>'ss' 'scrollsteps'</tags>
|
||||
<spec>'scrollsteps' 'ss'</spec>
|
||||
<type>&option.scrollsteps.type;</type>
|
||||
<default>&option.scrollsteps.default;</default>
|
||||
<description>
|
||||
<p>
|
||||
The number of steps in which to smooth scroll to a new position. If
|
||||
set to 1, smooth scrolling is not used.
|
||||
</p>
|
||||
</description>
|
||||
</item>
|
||||
<item>
|
||||
<tags>'st' 'scrolltime'</tags>
|
||||
<spec>'scrolltime' 'st'</spec>
|
||||
<type>&option.scrolltime.type;</type>
|
||||
<default>&option.scrolltime.default;</default>
|
||||
<description>
|
||||
<p>The time, in milliseconds, in which to smooth scroll to a new position.</p>
|
||||
</description>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<tags>'spl' 'spelllang'</tags>
|
||||
<spec>'spelllang' 'spl'</spec>
|
||||
|
||||
@@ -329,7 +329,11 @@ var File = Class("File", {
|
||||
/**
|
||||
* @property {nsIFileURL} Returns the nsIFileURL object for this file.
|
||||
*/
|
||||
get URI() services.io.newFileURI(this).QueryInterface(Ci.nsIFileURL),
|
||||
URI: Class.Memoize(function () {
|
||||
let uri = services.io.newFileURI(this).QueryInterface(Ci.nsIFileURL);
|
||||
uri.QueryInterface(Ci.nsIMutable).mutable = false;
|
||||
return uri;
|
||||
}),
|
||||
|
||||
/**
|
||||
* Iterates over the objects in this directory.
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
• Improved [macro-string] support, including automatic elision
|
||||
of optional elements, and array subscripts. [b4][b7]
|
||||
• Add -pentadactyl-remote command-line option. [b8]
|
||||
• Moved the smooth-scroll plugin to the core. [b8]
|
||||
• Improvements to marks:
|
||||
- Marks are now stored as line and column ordinals rather than percentages. [b8]
|
||||
- Marks now store the marked element and ensure its visibility when followed. [b8]
|
||||
@@ -218,6 +219,7 @@
|
||||
- Added 'passunknown' option. [b7]
|
||||
- Changed 'urlseparator' default value to "|". [b3]
|
||||
- Added "errorconsole", "passwords", and "venkman" dialogs to :dialog. [b2][b8]
|
||||
- Added 'scrollsteps' and 'scrolltime' options. [b8]
|
||||
- Added 'spelllang' option. [b8]
|
||||
- Make 'showmode' a [stringlist] option. [b7]
|
||||
- Added 'wildanchor' option. [b2]
|
||||
|
||||
Reference in New Issue
Block a user