2009-04-06 23:05:49 -04:00
|
|
|
/*
|
|
|
|
Tab Bar AutoScroll Library for Vertical and Horizontal Tab Bar
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
var scrolled = window['piro.sakura.ne.jp']
|
|
|
|
.autoScroll
|
|
|
|
.processAutoScroll(mouseMoveOrDragOverEvent);
|
|
|
|
|
2010-08-26 11:40:13 -04:00
|
|
|
license: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi
|
2009-04-06 23:05:49 -04:00
|
|
|
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
|
|
|
|
original:
|
|
|
|
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/autoScroll.js
|
|
|
|
*/
|
2010-06-22 19:46:51 -04:00
|
|
|
|
2010-08-26 11:40:13 -04:00
|
|
|
/* To work as a JS Code Module */
|
2010-08-27 05:58:57 -04:00
|
|
|
if (typeof window == 'undefined' ||
|
|
|
|
(window && typeof window.constructor == 'function')) {
|
2010-06-22 21:32:31 -04:00
|
|
|
this.EXPORTED_SYMBOLS = ['autoScroll'];
|
2010-06-22 19:46:51 -04:00
|
|
|
|
2010-06-26 11:13:11 -04:00
|
|
|
// If namespace.jsm is available, export symbols to the shared namespace.
|
|
|
|
// See: http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/namespace.jsm
|
|
|
|
try {
|
|
|
|
let ns = {};
|
2010-12-06 07:04:52 -05:00
|
|
|
Components.utils.import('resource://treestyletab-modules/lib/namespace.jsm', ns);
|
2010-06-26 11:13:11 -04:00
|
|
|
/* var */ window = ns.getNamespaceFor('piro.sakura.ne.jp');
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
window = {};
|
|
|
|
}
|
2010-06-22 19:46:51 -04:00
|
|
|
}
|
|
|
|
|
2009-04-06 23:05:49 -04:00
|
|
|
(function() {
|
2010-06-23 08:00:33 -04:00
|
|
|
const currentRevision = 4;
|
2009-04-06 23:05:49 -04:00
|
|
|
|
|
|
|
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
|
|
|
|
|
|
|
|
var loadedRevision = 'autoScroll' in window['piro.sakura.ne.jp'] ?
|
|
|
|
window['piro.sakura.ne.jp'].autoScroll.revision :
|
|
|
|
0 ;
|
|
|
|
if (loadedRevision && loadedRevision > currentRevision) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-22 14:00:16 -04:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
2009-04-06 23:05:49 -04:00
|
|
|
|
|
|
|
window['piro.sakura.ne.jp'].autoScroll = {
|
|
|
|
revision : currentRevision,
|
|
|
|
|
|
|
|
processAutoScroll : function(aEvent)
|
|
|
|
{
|
|
|
|
var target = aEvent.originalTarget;
|
2010-06-23 08:00:33 -04:00
|
|
|
var b = this.getTabBrowserFromChild(target);
|
2009-04-06 23:05:49 -04:00
|
|
|
if (!b) return false;
|
|
|
|
|
|
|
|
var tabs = b.mTabContainer;
|
|
|
|
if (tabs.getAttribute('overflow') != 'true')
|
|
|
|
return false;
|
|
|
|
|
2010-06-22 14:00:16 -04:00
|
|
|
var view = target.ownerDocument.defaultView;
|
|
|
|
|
2009-04-06 23:05:49 -04:00
|
|
|
var box = this.getScrollBox(b);
|
|
|
|
var boxObject = this.getScrollBoxObject(b);
|
|
|
|
var innerBoxObject = (box.localName == 'arrowscrollbox' ? box._scrollbox : box ).boxObject;
|
|
|
|
|
|
|
|
var orientBox = box || tabs;
|
2010-01-13 14:03:24 -05:00
|
|
|
var isMultirow = tabs.getAttribute('flowing') == 'multibar'; // Tab Mix Plus
|
2009-07-16 06:28:27 -04:00
|
|
|
var isVertical = (
|
|
|
|
isMultirow ||
|
2010-06-22 14:00:16 -04:00
|
|
|
((orientBox.getAttribute('orient') || view.getComputedStyle(orientBox, '').getPropertyValue('-moz-box-orient')) == 'vertical')
|
2009-07-16 06:28:27 -04:00
|
|
|
);
|
2009-04-06 23:05:49 -04:00
|
|
|
|
|
|
|
var maxX = {}, maxY = {}, curX = {}, curY = {};
|
|
|
|
boxObject.getScrolledSize(maxX, maxY);
|
|
|
|
boxObject.getPosition(curX, curY);
|
|
|
|
|
|
|
|
var pixels;
|
|
|
|
if (isVertical) {
|
|
|
|
pixels = tabs.childNodes[0].boxObject.height * 0.5;
|
2009-07-16 06:28:27 -04:00
|
|
|
if (isMultirow) pixels *= 0.5;
|
2009-04-06 23:05:49 -04:00
|
|
|
if (aEvent.screenY < boxObject.screenY + this.getUpButtonHeight(b)) {
|
|
|
|
if (curY.value == 0) return false;
|
|
|
|
pixels *= -1;
|
|
|
|
}
|
|
|
|
else if (aEvent.screenY > boxObject.screenY + boxObject.height - this.getDownButtonHeight(b)) {
|
|
|
|
if (innerBoxObject.height + curY.value == maxY.value) return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pixels = box.scrollIncrement;
|
2010-06-22 14:00:16 -04:00
|
|
|
var ltr = view.getComputedStyle(tabs, null).direction == 'ltr';
|
2009-04-06 23:05:49 -04:00
|
|
|
if (aEvent.screenX < boxObject.screenX + this.getUpButtonWidth(b)) {
|
|
|
|
if (curX.value == 0) return false;
|
|
|
|
pixels *= -1;
|
|
|
|
}
|
|
|
|
else if (aEvent.screenX > boxObject.screenX + boxObject.width - this.getDownButtonWidth(b)) {
|
|
|
|
if (innerBoxObject.width + curX.value == maxX.value) return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pixels = (ltr ? 1 : -1) * pixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('scrollByPixels' in box) {
|
|
|
|
box.scrollByPixels(pixels);
|
|
|
|
}
|
|
|
|
else { // Tab Mix Plus?
|
|
|
|
if (isVertical)
|
|
|
|
boxObject.scrollBy(0, pixels);
|
|
|
|
else
|
|
|
|
boxObject.scrollBy(pixels, 0);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2010-06-23 08:00:33 -04:00
|
|
|
|
|
|
|
getTabBrowserFromChild : function(aTabBrowserChild)
|
|
|
|
{
|
|
|
|
if (aTabBrowserChild.localName == 'tabbrowser') // itself
|
|
|
|
return aTabBrowserChild;
|
|
|
|
|
|
|
|
if (aTabBrowserChild.tabbrowser) // tabs, Firefox 3.7 or later
|
|
|
|
return aTabBrowserChild.tabbrowser;
|
|
|
|
|
|
|
|
if (aTabBrowserChild.id == 'TabsToolbar') // tabs toolbar, Firefox 3.7 or later
|
|
|
|
return aTabBrowserChild.getElementsByTagName('tabs')[0].tabbrowser;
|
|
|
|
|
|
|
|
var b = aTabBrowserChild.ownerDocument.evaluate(
|
|
|
|
'ancestor::*[local-name()="tabbrowser"] | '+
|
|
|
|
'ancestor::*[local-name()="tabs" and @tabbrowser] |'+
|
|
|
|
'ancestor::*[local-name()="toolbar" and @id="TabsToolbar"]/descendant::*[local-name()="tabs"]',
|
|
|
|
aTabBrowserChild,
|
|
|
|
null,
|
|
|
|
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE,
|
|
|
|
null
|
|
|
|
).singleNodeValue;
|
|
|
|
return (b && b.tabbrowser) || b;
|
|
|
|
},
|
2009-04-06 23:05:49 -04:00
|
|
|
|
|
|
|
getScrollBox : function(aTabBrowser)
|
|
|
|
{
|
2010-06-22 14:00:16 -04:00
|
|
|
return aTabBrowser.ownerDocument.getAnonymousElementByAttribute(aTabBrowser.mTabContainer, 'class', 'tabs-frame') || // Tab Mix Plus
|
2010-01-13 14:03:24 -05:00
|
|
|
aTabBrowser.mTabContainer.mTabstrip;
|
2009-04-06 23:05:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
getScrollBoxObject : function(aTabBrowser)
|
|
|
|
{
|
|
|
|
var box = this.getScrollBox(aTabBrowser);
|
2009-07-16 06:28:27 -04:00
|
|
|
return (box.scrollBoxObject || box.boxObject)
|
2010-01-13 14:03:24 -05:00
|
|
|
.QueryInterface(Ci.nsIScrollBoxObject); // Tab Mix Plus
|
2009-04-06 23:05:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
getUpButton : function(aTabBrowser)
|
|
|
|
{
|
|
|
|
var box = this.getScrollBox(aTabBrowser);
|
|
|
|
return box._scrollButtonUp ||
|
2010-06-22 14:00:16 -04:00
|
|
|
aTabBrowser.ownerDocument.getAnonymousElementByAttribute(box, 'class', 'scrollbutton-up') ||
|
|
|
|
aTabBrowser.ownerDocument.getAnonymousElementByAttribute(box.previousSibling, 'class', 'scrollbutton-up'); // Tab Mix Plus
|
2009-04-06 23:05:49 -04:00
|
|
|
},
|
|
|
|
getDownButton : function(aTabBrowser)
|
|
|
|
{
|
|
|
|
var box = this.getScrollBox(aTabBrowser);
|
|
|
|
return box._scrollButtonDown ||
|
2010-06-22 14:00:16 -04:00
|
|
|
aTabBrowser.ownerDocument.getAnonymousElementByAttribute(box, 'class', 'scrollbutton-down') ||
|
|
|
|
aTabBrowser.ownerDocument.getAnonymousElementByAttribute(box.nextSibling, 'class', 'scrollbutton-up'); // Tab Mix Plus
|
2009-04-06 23:05:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
autoScrollArea : 20,
|
|
|
|
|
|
|
|
getUpButtonHeight : function(aTabBrowser)
|
|
|
|
{
|
|
|
|
var button = this.getUpButton(aTabBrowser);
|
|
|
|
return (button ? button.boxObject.height : 0 ) || this.autoScrollArea;
|
|
|
|
},
|
|
|
|
getUpButtonWidth : function(aTabBrowser)
|
|
|
|
{
|
|
|
|
var button = this.getUpButton(aTabBrowser);
|
|
|
|
return (button ? button.boxObject.width : 0 ) || this.autoScrollArea;
|
|
|
|
},
|
|
|
|
|
|
|
|
getDownButtonHeight : function(aTabBrowser)
|
|
|
|
{
|
|
|
|
var button = this.getDownButton(aTabBrowser);
|
|
|
|
return (button ? button.boxObject.height : 0 ) || this.autoScrollArea;
|
|
|
|
},
|
|
|
|
getDownButtonWidth : function(aTabBrowser)
|
|
|
|
{
|
|
|
|
var button = this.getDownButton(aTabBrowser);
|
|
|
|
return (button ? button.boxObject.width : 0 ) || this.autoScrollArea;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
})();
|
2010-06-22 19:46:51 -04:00
|
|
|
|
|
|
|
if (window != this) { // work as a JS Code Module
|
2010-06-22 21:32:31 -04:00
|
|
|
this.autoScroll = window['piro.sakura.ne.jp'].autoScroll;
|
2010-06-22 19:46:51 -04:00
|
|
|
}
|