From 27a8a8f2e056a172e80bf50340a40786274bd984 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Mon, 30 May 2016 02:55:17 +0900 Subject: [PATCH] Don't expand the tab bar too much on resizing #1002 --- modules/autoHide.js | 38 ++++++++++++++++++++++---------------- modules/base.js | 8 ++++---- modules/browser.js | 5 ++++- modules/window.js | 3 +++ 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/modules/autoHide.js b/modules/autoHide.js index 410812c8..8d88e049 100644 --- a/modules/autoHide.js +++ b/modules/autoHide.js @@ -42,6 +42,7 @@ const Cu = Components.utils; Cu.import('resource://gre/modules/XPCOMUtils.jsm'); Cu.import('resource://gre/modules/Services.jsm'); +Cu.import('resource://gre/modules/Timer.jsm'); Cu.import('resource://treestyletab-modules/lib/inherit.jsm'); Cu.import('resource://treestyletab-modules/constants.js'); Cu.import('resource://treestyletab-modules/ReferenceCounter.js'); @@ -289,6 +290,7 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, { }, set tabbarWidth(aValue) { + log('setting "width" to '+aValue+' (expanded='+this.expanded+')'); if (this.expanded) return this.expandedWidth = aValue; else @@ -303,16 +305,9 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, { }, set expandedWidth(aValue) { - var newWidth = this.treeStyleTab.calculateCorrectExpandedAndShrunkenWidth({ - expanded : aValue, - shrunken : this.shrunkenWidth - }, 'expanded'); - if (newWidth.corrected) { - this.shrunkenWidth = newWidth.shrunken; - aValue = newWidth.expanded; - } this.treeStyleTab.setWindowValue(this.kTABBAR_EXPANDED_WIDTH, aValue); utils.setTreePref('tabbar.width', aValue); + this.reserveFixWidth('expanded'); return aValue; }, get shrunkenWidth() @@ -324,19 +319,30 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, { }, set shrunkenWidth(aValue) { - var newWidth = this.treeStyleTab.calculateCorrectExpandedAndShrunkenWidth({ - expanded : this.expandedWidth, - shrunken : aValue - }, 'shrunken'); - if (newWidth.corrected) { - this.expandedWidth = newWidth.expanded; - aValue = newWidth.shrunken; - } this.treeStyleTab.setWindowValue(this.kTABBAR_SHRUNKEN_WIDTH, aValue); utils.setTreePref('tabbar.shrunkenWidth', aValue); + this.reserveFixWidth('shrunken'); return aValue; }, + reserveFixWidth : function(aTrigger) + { + if (this._collectingTabbarWidth) + clearTimeout(this._collectingTabbarWidth); + var stack = new Error().stack; + this._collectingTabbarWidth = setTimeout((function() { + log('reserveFixWidth: \n'+stack); + var newWidth = this.treeStyleTab.calculateCorrectExpandedAndShrunkenWidth({ + expanded : this.expandedWidth, + shrunken : this.shrunkenWidth + }, aTrigger); + if (this.shrunkenWidth != newWidth.shrunken) + this.shrunkenWidth = newWidth.shrunken; + if (this.expandedWidth != newWidth.expanded) + this.expandedWidth = newWidth.expanded; + }).bind(this), 100); + }, + resetWidth : function AHB_resetWidth() { this.expandedWidth = utils.getTreePref('tabbar.width.default'); diff --git a/modules/base.js b/modules/base.js index 3c137347..f93b6004 100644 --- a/modules/base.js +++ b/modules/base.js @@ -2246,10 +2246,6 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { Services.obs.notifyObservers(null, this.kTOPIC_INDENT_MODIFIED, value); return; - case 'extensions.treestyletab.tabbar.width': - case 'extensions.treestyletab.tabbar.shrunkenWidth': - return this.correctMismatchedTabWidthPrefs(aPrefName); - case 'extensions.stm.tabBarMultiRows': // Super Tab Mode if (this.prefOverriding) return; @@ -2319,6 +2315,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { }, calculateCorrectExpandedAndShrunkenWidth : function TSTBase_calculateCorrectExpandedAndShrunkenWidth(aSource, aModifiedTarget) { + log('calculateCorrectExpandedAndShrunkenWidth '+JSON.stringify(aSource)+' / '+aModifiedTarget); var size = { expanded : aSource.expanded, shrunken : aSource.shrunken, @@ -2328,6 +2325,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { var originalShrunken = size.shrunken; var maxSize = this.browserWindow.gBrowser.boxObject.width * this.MAX_TABBAR_SIZE_RATIO; if (aModifiedTarget.indexOf('shrunken') > -1) { + log('fixsing expanded size'); if (size.expanded <= size.shrunken) size.expanded = parseInt(size.shrunken / this.DEFAULT_SHRUNKEN_WIDTH_RATIO); if (size.expanded > maxSize) { @@ -2337,6 +2335,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { } } else { + log('fixsing shrunken size'); if (size.expanded > maxSize) size.expanded = maxSize; if (size.expanded <= size.shrunken) @@ -2348,6 +2347,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, { size.expanded != originalExpanded || size.shrunken != originalShrunken ); + log(' => '+JSON.stringify(size)); return size; }, diff --git a/modules/browser.js b/modules/browser.js index a42a71e7..0cd65885 100644 --- a/modules/browser.js +++ b/modules/browser.js @@ -2784,7 +2784,10 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, { case 'extensions.treestyletab.tabbar.width.override': if (!this.autoHide.isResizing && this.isVertical) { this.removeTabStripAttribute('width'); - this.tabbarWidth = value; + if (aPrefName.indexOf('shrunken') > -1) + this.shrunkenWidth = value; + else + this.expandedWidth = value; this.setTabStripAttribute('width', this.autoHide.placeHolderWidthFromMode); this.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_PREF_CHANGE); } diff --git a/modules/window.js b/modules/window.js index 73b21b5a..2760ea83 100644 --- a/modules/window.js +++ b/modules/window.js @@ -1080,6 +1080,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, { width += (pos == 'left' ? delta : -delta ); width = this.maxTabbarWidth(width, b); if (expanded || b.treeStyleTab.autoHide.expanded) { + log('onTabbarResizing: setting expanded width to '+width); // b.treeStyleTab.tabbarWidth = width; b.treeStyleTab.autoHide.expandedWidth = width; if (b.treeStyleTab.autoHide.mode == b.treeStyleTab.autoHide.kMODE_SHRINK && @@ -1087,6 +1088,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, { b.treeStyleTab.tabStripPlaceHolder.setAttribute('width', b.treeStyleTab.autoHide.shrunkenWidth); } else { + log('onTabbarResizing: setting shrunken width to '+width); b.treeStyleTab.autoHide.shrunkenWidth = width; } } @@ -1094,6 +1096,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, { let delta = aEvent.screenY - this.tabbarResizeStartY; height += (pos == 'top' ? delta : -delta ); height = this.maxTabbarHeight(height, b); + log('onTabbarResizing: setting height to '+height); b.treeStyleTab.tabbarHeight = height; } b.treeStyleTab.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_TABBAR_RESIZE);