From e6e52595d97775d21415fadf6a310e966e7a231e Mon Sep 17 00:00:00 2001 From: piro Date: Tue, 7 Apr 2009 03:05:49 +0000 Subject: [PATCH] =?UTF-8?q?=E3=82=BF=E3=83=96=E3=83=90=E3=83=BC=E3=81=AE?= =?UTF-8?q?=E8=87=AA=E5=8B=95=E3=82=B9=E3=82=AF=E3=83=AD=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=AF=E3=83=A9=E3=82=A4=E3=83=96=E3=83=A9?= =?UTF-8?q?=E3=83=AA=E3=82=92=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@4061 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/res/autoScroll.js | 155 ++++++++++++++++++++ content/treestyletab/treestyletab.js | 6 +- content/treestyletab/treestyletab.xul | 1 + content/treestyletab/treestyletabbrowser.js | 49 ------- 4 files changed, 161 insertions(+), 50 deletions(-) create mode 100644 content/treestyletab/res/autoScroll.js diff --git a/content/treestyletab/res/autoScroll.js b/content/treestyletab/res/autoScroll.js new file mode 100644 index 00000000..f532073b --- /dev/null +++ b/content/treestyletab/res/autoScroll.js @@ -0,0 +1,155 @@ +/* + Tab Bar AutoScroll Library for Vertical and Horizontal Tab Bar + + Usage: + var scrolled = window['piro.sakura.ne.jp'] + .autoScroll + .processAutoScroll(mouseMoveOrDragOverEvent); + + lisence: The MIT License, Copyright (c) 2009 SHIMODA "Piro" Hiroshi + 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 +*/ +(function() { + const currentRevision = 1; + + 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; + } + + var Cc = Components.classes; + var Ci = Components.interfaces; + + window['piro.sakura.ne.jp'].autoScroll = { + revision : currentRevision, + + processAutoScroll : function(aEvent) + { + var target = aEvent.originalTarget; + var b = target.ownerDocument.evaluate( + 'ancestor-or-self::*[local-name()="tabbrowser"]', + target, + null, + XPathResult.FIRST_ORDERED_NODE_TYPE, + null + ).singleNodeValue; + if (!b) return false; + + var tabs = b.mTabContainer; + if (tabs.getAttribute('overflow') != 'true') + return false; + + var box = this.getScrollBox(b); + var boxObject = this.getScrollBoxObject(b); + var innerBoxObject = (box.localName == 'arrowscrollbox' ? box._scrollbox : box ).boxObject; + + var orientBox = box || tabs; + var isVertical = (orientBox.getAttribute('orient') || window.getComputedStyle(orientBox, '').getPropertyValue('-moz-box-orient')) == 'vertical'; + + 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; + 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; + var ltr = window.getComputedStyle(tabs, null).direction == 'ltr'; + 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; + }, + + getScrollBox : function(aTabBrowser) + { + return document.getAnonymousElementByAttribute(aTabBrowser.mTabContainer, 'class', 'tabs-frame') || // Tab Mix Plus + aTabBrowser.mTabContainer.mTabstrip; + }, + + getScrollBoxObject : function(aTabBrowser) + { + var box = this.getScrollBox(aTabBrowser); + return box.scrollBoxObject || + box.boxObject.QueryInterface(Ci.nsIScrollBoxObject); // Tab Mix Plus + }, + + getUpButton : function(aTabBrowser) + { + var box = this.getScrollBox(aTabBrowser); + return box._scrollButtonUp || + document.getAnonymousElementByAttribute(box, 'class', 'scrollbutton-up') || + document.getAnonymousElementByAttribute(box.previousSibling, 'class', 'scrollbutton-up'); // Tab Mix Plus + }, + getDownButton : function(aTabBrowser) + { + var box = this.getScrollBox(aTabBrowser); + return box._scrollButtonDown || + document.getAnonymousElementByAttribute(box, 'class', 'scrollbutton-down') || + document.getAnonymousElementByAttribute(box.nextSibling, 'class', 'scrollbutton-up'); // Tab Mix Plus + }, + + 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; + } + + }; +})(); diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index 17dd1c52..7e33805a 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -1110,7 +1110,11 @@ catch(e) { var TSTTabBrowser = this; if ((function(aSelf) { try{ - if (TSTTabBrowser.treeStyleTab.processAutoScroll(aEvent)) return true; + if (window['piro.sakura.ne.jp'].autoScroll.processAutoScroll(aEvent)) { + aEvent.preventDefault(); + aEvent.stopPropagation(); + return true; + } var info = TSTTabBrowser.treeStyleTab.getDropAction(aEvent, TST_DRAGSESSION); diff --git a/content/treestyletab/treestyletab.xul b/content/treestyletab/treestyletab.xul index e5d7ceba..7c2a81d2 100644 --- a/content/treestyletab/treestyletab.xul +++ b/content/treestyletab/treestyletab.xul @@ -10,6 +10,7 @@