mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 05:38:01 +01:00
Some scrollable element fixes. Closes issue #151.
This commit is contained in:
@@ -394,22 +394,20 @@ const Buffer = Module("buffer", {
|
|||||||
* @property {number} The buffer's horizontal scroll percentile.
|
* @property {number} The buffer's horizontal scroll percentile.
|
||||||
*/
|
*/
|
||||||
get scrollXPercent() {
|
get scrollXPercent() {
|
||||||
let win = Buffer.findScrollableWindow();
|
let elem = Buffer.findScrollable(0, true);
|
||||||
if (win.scrollMaxX > 0)
|
if (elem.scrollWidth - elem.clientWidth === 0)
|
||||||
return Math.round(win.scrollX / win.scrollMaxX * 100);
|
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
|
return elem.scrollLeft * 100 / (elem.scrollWidth - elem.clientWidth);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} The buffer's vertical scroll percentile.
|
* @property {number} The buffer's vertical scroll percentile.
|
||||||
*/
|
*/
|
||||||
get scrollYPercent() {
|
get scrollYPercent() {
|
||||||
let win = Buffer.findScrollableWindow();
|
let elem = Buffer.findScrollable(0, false);
|
||||||
if (win.scrollMaxY > 0)
|
if (elem.scrollHeight - elem.clientHeight === 0)
|
||||||
return Math.round(win.scrollY / win.scrollMaxY * 100);
|
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
|
return elem.scrollTop * 100 / (elem.scrollHeight - elem.clientHeight);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -705,7 +703,7 @@ const Buffer = Module("buffer", {
|
|||||||
* Scrolls to the bottom of the current buffer.
|
* Scrolls to the bottom of the current buffer.
|
||||||
*/
|
*/
|
||||||
scrollBottom: function () {
|
scrollBottom: function () {
|
||||||
Buffer.scrollToPercent(null, 100);
|
Buffer.scrollToPercent(null, null, 100);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -719,10 +717,10 @@ const Buffer = Module("buffer", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scrolls to the top of the current buffer.
|
* Scrolls to the end of the current buffer.
|
||||||
*/
|
*/
|
||||||
scrollEnd: function () {
|
scrollEnd: function () {
|
||||||
Buffer.scrollToPercent(100, null);
|
Buffer.scrollToPercent(null, 100, null);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -777,7 +775,7 @@ const Buffer = Module("buffer", {
|
|||||||
* @param {number} y The vertical page percentile.
|
* @param {number} y The vertical page percentile.
|
||||||
*/
|
*/
|
||||||
scrollToPercent: function (x, y) {
|
scrollToPercent: function (x, y) {
|
||||||
Buffer.scrollToPercent(x, y);
|
Buffer.scrollToPercent(null, x, y);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -795,14 +793,14 @@ const Buffer = Module("buffer", {
|
|||||||
* Scrolls the current buffer laterally to its leftmost.
|
* Scrolls the current buffer laterally to its leftmost.
|
||||||
*/
|
*/
|
||||||
scrollStart: function () {
|
scrollStart: function () {
|
||||||
Buffer.scrollToPercent(0, null);
|
Buffer.scrollToPercent(null, 0, null);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scrolls the current buffer vertically to the top.
|
* Scrolls the current buffer vertically to the top.
|
||||||
*/
|
*/
|
||||||
scrollTop: function () {
|
scrollTop: function () {
|
||||||
Buffer.scrollToPercent(null, 0);
|
Buffer.scrollToPercent(null, null, 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: allow callback for filtering out unwanted frames? User defined?
|
// TODO: allow callback for filtering out unwanted frames? User defined?
|
||||||
@@ -1085,26 +1083,29 @@ const Buffer = Module("buffer", {
|
|||||||
return win;
|
return win;
|
||||||
},
|
},
|
||||||
|
|
||||||
findScrollable: function findScrollable(dir, horizontal) {
|
isScrollable: function isScrollable(elem, dir, horizontal) {
|
||||||
let pos = "scrollTop", size = "clientHeight", max = "scrollHeight", layoutSize = "offsetHeight",
|
let pos = "scrollTop", size = "clientHeight", max = "scrollHeight", layoutSize = "offsetHeight",
|
||||||
overflow = "overflowX", border1 = "borderTopWidth", border2 = "borderBottomWidth";
|
overflow = "overflowX", border1 = "borderTopWidth", border2 = "borderBottomWidth";
|
||||||
if (horizontal)
|
if (horizontal)
|
||||||
pos = "scrollLeft", size = "clientWidth", max = "scrollWidth", layoutSize = "offsetWidth",
|
pos = "scrollLeft", size = "clientWidth", max = "scrollWidth", layoutSize = "offsetWidth",
|
||||||
overflow = "overflowX", border1 = "borderLeftWidth", border2 = "borderRightWidth";
|
overflow = "overflowX", border1 = "borderLeftWidth", border2 = "borderRightWidth";
|
||||||
|
|
||||||
function find(elem) {
|
|
||||||
for (; elem && elem.parentNode instanceof Element; elem = elem.parentNode) {
|
|
||||||
let style = util.computedStyle(elem);
|
let style = util.computedStyle(elem);
|
||||||
let borderSize = parseInt(style[border1]) + parseInt(style[border2]);
|
let borderSize = parseInt(style[border1]) + parseInt(style[border2]);
|
||||||
let realSize = elem[size];
|
let realSize = elem[size];
|
||||||
// Stupid Gecko eccentricities. May fail for quirks mode documents.
|
// Stupid Gecko eccentricities. May fail for quirks mode documents.
|
||||||
if (elem[size] + borderSize == elem[max] || elem[size] == 0) // Stupid, fallible heuristic.
|
if (elem[size] + borderSize == elem[max] || elem[size] == 0) // Stupid, fallible heuristic.
|
||||||
continue;
|
return false;
|
||||||
if (style[overflow] == "hidden")
|
if (style[overflow] == "hidden")
|
||||||
realSize += borderSize;
|
realSize += borderSize;
|
||||||
if (dir < 0 && elem[pos] > 0 || dir > 0 && elem[pos] + realSize < elem[max])
|
return dir < 0 && elem[pos] > 0 || dir > 0 && elem[pos] + realSize < elem[max] || !dir && realSize < elem[max];
|
||||||
|
},
|
||||||
|
|
||||||
|
findScrollable: function findScrollable(dir, horizontal) {
|
||||||
|
function find(elem) {
|
||||||
|
for (; elem && elem.parentNode instanceof Element; elem = elem.parentNode)
|
||||||
|
if (Buffer.isScrollable(elem, dir, horizontal))
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1152,8 +1153,8 @@ const Buffer = Module("buffer", {
|
|||||||
dactyl.beep();
|
dactyl.beep();
|
||||||
},
|
},
|
||||||
|
|
||||||
scrollElemToPercent: function scrollElemToPercent(elem, horizontal, vertical) {
|
scrollToPercent: function scrollElemToPercent(elem, horizontal, vertical) {
|
||||||
elem = elem || Buffer.findScrollable();
|
elem = elem || Buffer.findScrollable(0, vertical == null);
|
||||||
marks.add("'", true);
|
marks.add("'", true);
|
||||||
|
|
||||||
if (horizontal != null)
|
if (horizontal != null)
|
||||||
@@ -1163,24 +1164,6 @@ const Buffer = Module("buffer", {
|
|||||||
elem.scrollTop = (elem.scrollHeight - elem.clientHeight) * (vertical / 100);
|
elem.scrollTop = (elem.scrollHeight - elem.clientHeight) * (vertical / 100);
|
||||||
},
|
},
|
||||||
|
|
||||||
scrollToPercent: function scrollToPercent(horizontal, vertical) {
|
|
||||||
let win = Buffer.findScrollableWindow();
|
|
||||||
let h, v;
|
|
||||||
|
|
||||||
if (horizontal == null)
|
|
||||||
h = win.scrollX;
|
|
||||||
else
|
|
||||||
h = win.scrollMaxX / 100 * horizontal;
|
|
||||||
|
|
||||||
if (vertical == null)
|
|
||||||
v = win.scrollY;
|
|
||||||
else
|
|
||||||
v = win.scrollMaxY / 100 * vertical;
|
|
||||||
|
|
||||||
marks.add("'", true);
|
|
||||||
win.scrollTo(h, v);
|
|
||||||
},
|
|
||||||
|
|
||||||
openUploadPrompt: function openUploadPrompt(elem) {
|
openUploadPrompt: function openUploadPrompt(elem) {
|
||||||
commandline.input("Upload file: ", function (path) {
|
commandline.input("Upload file: ", function (path) {
|
||||||
let file = io.File(path);
|
let file = io.File(path);
|
||||||
@@ -1529,19 +1512,19 @@ const Buffer = Module("buffer", {
|
|||||||
|
|
||||||
mappings.add(myModes, ["gg", "<Home>"],
|
mappings.add(myModes, ["gg", "<Home>"],
|
||||||
"Go to the top of the document",
|
"Go to the top of the document",
|
||||||
function (count) { buffer.scrollToPercent(buffer.scrollXPercent, Math.max(count, 0)); },
|
function (count) { buffer.scrollToPercent(null, count != null ? count : 0); },
|
||||||
{ count: true });
|
{ count: true });
|
||||||
|
|
||||||
mappings.add(myModes, ["G", "<End>"],
|
mappings.add(myModes, ["G", "<End>"],
|
||||||
"Go to the end of the document",
|
"Go to the end of the document",
|
||||||
function (count) { buffer.scrollToPercent(buffer.scrollXPercent, count != null ? count : 100); },
|
function (count) { buffer.scrollToPercent(null, count != null ? count : 100); },
|
||||||
{ count: true });
|
{ count: true });
|
||||||
|
|
||||||
mappings.add(myModes, ["%"],
|
mappings.add(myModes, ["%"],
|
||||||
"Scroll to {count} percent of the document",
|
"Scroll to {count} percent of the document",
|
||||||
function (count) {
|
function (count) {
|
||||||
dactyl.assert(count > 0 && count <= 100);
|
dactyl.assert(count > 0 && count <= 100);
|
||||||
buffer.scrollToPercent(buffer.scrollXPercent, count);
|
buffer.scrollToPercent(null, count);
|
||||||
},
|
},
|
||||||
{ count: true });
|
{ count: true });
|
||||||
|
|
||||||
|
|||||||
@@ -52,12 +52,10 @@ const Marks = Module("marks", {
|
|||||||
let win = buffer.focusedFrame;
|
let win = buffer.focusedFrame;
|
||||||
let doc = win.document;
|
let doc = win.document;
|
||||||
|
|
||||||
let x = win.scrollMaxX ? win.pageXOffset / win.scrollMaxX : 0;
|
let position = { x: buffer.scrollXPercent / 100, y: buffer.scrollYPercent / 100 };
|
||||||
let y = win.scrollMaxY ? win.pageYOffset / win.scrollMaxY : 0;
|
|
||||||
let position = { x: x, y: y };
|
|
||||||
|
|
||||||
if (Marks.isURLMark(mark)) {
|
if (Marks.isURLMark(mark)) {
|
||||||
let res = this._urlMarks.set(mark, { location: doc.URL, position: position, tab: Cu.getWeakReference(tabs.getTab()), timestamp: Date.now()*1000 });
|
let res = this._urlMarks.set(mark, { location: doc.documentURI, position: position, tab: Cu.getWeakReference(tabs.getTab()), timestamp: Date.now()*1000 });
|
||||||
if (!silent)
|
if (!silent)
|
||||||
dactyl.log("Adding URL mark: " + Marks.markToString(mark, res), 5);
|
dactyl.log("Adding URL mark: " + Marks.markToString(mark, res), 5);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user