diff options
author | Kris Maglione <maglione.k@gmail.com> | 2011-09-26 18:13:50 -0400 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2011-09-26 18:13:50 -0400 |
commit | 59daca20bad8da07015e62d51f15f5f5b07be436 (patch) | |
tree | 9b92fd9f7481a0497290b3b15d0f2f5b61c8f08d /common | |
parent | 8900946cf271df42fafe80421e38dd758e4f682f (diff) | |
download | pentadactyl-59daca20bad8da07015e62d51f15f5f5b07be436.tar.gz |
Add (considerably evil) dactylIUtils.getScrollable. Deal with some quirky sites without scrollable elements. Closes issue #525.
Diffstat (limited to 'common')
-rw-r--r-- | common/content/buffer.js | 27 | ||||
-rw-r--r-- | common/modules/dom.jsm | 7 |
2 files changed, 33 insertions, 1 deletions
diff --git a/common/content/buffer.js b/common/content/buffer.js index 00c96972..2a403ed8 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -784,9 +784,29 @@ var Buffer = Module("buffer", { function find(elem) { while (elem && !(elem instanceof Element) && elem.parentNode) elem = elem.parentNode; - for (; elem && elem.parentNode instanceof Element; elem = elem.parentNode) + for (; elem instanceof Element; elem = elem.parentNode) if (Buffer.isScrollable(elem, dir, horizontal)) break; + + if (!(elem instanceof Element)) + return { + __proto__: elem.documentElement || elem.ownerDocument.documentElement, + + win: elem.defaultView || elem.ownerDocument.defaultView, + + get clientWidth() this.win.innerWidth, + get clientHeight() this.win.innerHeight, + + get scrollWidth() this.win.scrollMaxX + this.win.innerWidth, + get scrollHeight() this.win.scrollMaxY + this.win.innerHeight, + + get scrollLeft() this.win.scrollX, + set scrollLeft(val) { this.win.scrollTo(val, this.win.scrollY) }, + + get scrollTop() this.win.scrollY, + set scrollTop(val) { this.win.scrollTo(this.win.scrollX, val) } + }; + return elem; } @@ -1263,6 +1283,9 @@ var Buffer = Module("buffer", { findScrollable: deprecated("buffer.findScrollable", function findScrollable() buffer.findScrollable.apply(buffer, arguments)), isScrollable: function isScrollable(elem, dir, horizontal) { + if (!DOM(elem).isScrollable(horizontal ? "horizontal" : "vertical")) + return false; + let pos = "scrollTop", size = "clientHeight", max = "scrollHeight", layoutSize = "offsetHeight", overflow = "overflowX", border1 = "borderTopWidth", border2 = "borderBottomWidth"; if (horizontal) @@ -1272,9 +1295,11 @@ var Buffer = Module("buffer", { let style = DOM(elem).style; let borderSize = Math.round(parseFloat(style[border1]) + parseFloat(style[border2])); let realSize = elem[size]; + // Stupid Gecko eccentricities. May fail for quirks mode documents. if (elem[size] + borderSize == elem[max] || elem[size] == 0) // Stupid, fallible heuristic. return false; + if (style[overflow] == "hidden") realSize += borderSize; return dir < 0 && elem[pos] > 0 || dir > 0 && elem[pos] + realSize < elem[max] || !dir && realSize < elem[max]; diff --git a/common/modules/dom.jsm b/common/modules/dom.jsm index ccb7e7ca..5a7a9a29 100644 --- a/common/modules/dom.jsm +++ b/common/modules/dom.jsm @@ -691,6 +691,9 @@ var DOM = Class("DOM", { createContents: function createContents() this.each(DOM.createContents, this), + isScrollable: function isScrollable(direction) + this.length && DOM.isScrollable(this[0], direction), + getSet: function getSet(args, get, set) { if (!args.length) return this[0] && get.call(this, this[0]); @@ -1246,6 +1249,10 @@ var DOM = Class("DOM", { createContents: Class.Memoize(function () services.has("dactyl") && services.dactyl.createContents || function (elem) {}), + isScrollable: Class.Memoize(function () services.has("dactyl") && services.dactyl.getScrollable + ? function (elem, dir) services.dactyl.getScrollable(elem) & (dir ? services.dactyl["DIRECTION_" + dir.toUpperCase()] : ~0) + : function (elem, dir) true), + /** * The set of input element type attribute values that mark the element as * an editable field. |