Don't expand the tab bar too much on resizing #1002

This commit is contained in:
Piro / YUKI Hiroshi 2016-05-30 02:55:17 +09:00
parent 8b8410a58a
commit 27a8a8f2e0
4 changed files with 33 additions and 21 deletions

View File

@ -42,6 +42,7 @@ const Cu = Components.utils;
Cu.import('resource://gre/modules/XPCOMUtils.jsm'); Cu.import('resource://gre/modules/XPCOMUtils.jsm');
Cu.import('resource://gre/modules/Services.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/lib/inherit.jsm');
Cu.import('resource://treestyletab-modules/constants.js'); Cu.import('resource://treestyletab-modules/constants.js');
Cu.import('resource://treestyletab-modules/ReferenceCounter.js'); Cu.import('resource://treestyletab-modules/ReferenceCounter.js');
@ -289,6 +290,7 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
}, },
set tabbarWidth(aValue) set tabbarWidth(aValue)
{ {
log('setting "width" to '+aValue+' (expanded='+this.expanded+')');
if (this.expanded) if (this.expanded)
return this.expandedWidth = aValue; return this.expandedWidth = aValue;
else else
@ -303,16 +305,9 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
}, },
set expandedWidth(aValue) 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); this.treeStyleTab.setWindowValue(this.kTABBAR_EXPANDED_WIDTH, aValue);
utils.setTreePref('tabbar.width', aValue); utils.setTreePref('tabbar.width', aValue);
this.reserveFixWidth('expanded');
return aValue; return aValue;
}, },
get shrunkenWidth() get shrunkenWidth()
@ -324,19 +319,30 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
}, },
set shrunkenWidth(aValue) 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); this.treeStyleTab.setWindowValue(this.kTABBAR_SHRUNKEN_WIDTH, aValue);
utils.setTreePref('tabbar.shrunkenWidth', aValue); utils.setTreePref('tabbar.shrunkenWidth', aValue);
this.reserveFixWidth('shrunken');
return aValue; 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() resetWidth : function AHB_resetWidth()
{ {
this.expandedWidth = utils.getTreePref('tabbar.width.default'); this.expandedWidth = utils.getTreePref('tabbar.width.default');

View File

@ -2246,10 +2246,6 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
Services.obs.notifyObservers(null, this.kTOPIC_INDENT_MODIFIED, value); Services.obs.notifyObservers(null, this.kTOPIC_INDENT_MODIFIED, value);
return; return;
case 'extensions.treestyletab.tabbar.width':
case 'extensions.treestyletab.tabbar.shrunkenWidth':
return this.correctMismatchedTabWidthPrefs(aPrefName);
case 'extensions.stm.tabBarMultiRows': // Super Tab Mode case 'extensions.stm.tabBarMultiRows': // Super Tab Mode
if (this.prefOverriding) if (this.prefOverriding)
return; return;
@ -2319,6 +2315,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
}, },
calculateCorrectExpandedAndShrunkenWidth : function TSTBase_calculateCorrectExpandedAndShrunkenWidth(aSource, aModifiedTarget) calculateCorrectExpandedAndShrunkenWidth : function TSTBase_calculateCorrectExpandedAndShrunkenWidth(aSource, aModifiedTarget)
{ {
log('calculateCorrectExpandedAndShrunkenWidth '+JSON.stringify(aSource)+' / '+aModifiedTarget);
var size = { var size = {
expanded : aSource.expanded, expanded : aSource.expanded,
shrunken : aSource.shrunken, shrunken : aSource.shrunken,
@ -2328,6 +2325,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
var originalShrunken = size.shrunken; var originalShrunken = size.shrunken;
var maxSize = this.browserWindow.gBrowser.boxObject.width * this.MAX_TABBAR_SIZE_RATIO; var maxSize = this.browserWindow.gBrowser.boxObject.width * this.MAX_TABBAR_SIZE_RATIO;
if (aModifiedTarget.indexOf('shrunken') > -1) { if (aModifiedTarget.indexOf('shrunken') > -1) {
log('fixsing expanded size');
if (size.expanded <= size.shrunken) if (size.expanded <= size.shrunken)
size.expanded = parseInt(size.shrunken / this.DEFAULT_SHRUNKEN_WIDTH_RATIO); size.expanded = parseInt(size.shrunken / this.DEFAULT_SHRUNKEN_WIDTH_RATIO);
if (size.expanded > maxSize) { if (size.expanded > maxSize) {
@ -2337,6 +2335,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
} }
} }
else { else {
log('fixsing shrunken size');
if (size.expanded > maxSize) if (size.expanded > maxSize)
size.expanded = maxSize; size.expanded = maxSize;
if (size.expanded <= size.shrunken) if (size.expanded <= size.shrunken)
@ -2348,6 +2347,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
size.expanded != originalExpanded || size.expanded != originalExpanded ||
size.shrunken != originalShrunken size.shrunken != originalShrunken
); );
log(' => '+JSON.stringify(size));
return size; return size;
}, },

View File

@ -2784,7 +2784,10 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
case 'extensions.treestyletab.tabbar.width.override': case 'extensions.treestyletab.tabbar.width.override':
if (!this.autoHide.isResizing && this.isVertical) { if (!this.autoHide.isResizing && this.isVertical) {
this.removeTabStripAttribute('width'); 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.setTabStripAttribute('width', this.autoHide.placeHolderWidthFromMode);
this.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_PREF_CHANGE); this.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_PREF_CHANGE);
} }

View File

@ -1080,6 +1080,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
width += (pos == 'left' ? delta : -delta ); width += (pos == 'left' ? delta : -delta );
width = this.maxTabbarWidth(width, b); width = this.maxTabbarWidth(width, b);
if (expanded || b.treeStyleTab.autoHide.expanded) { if (expanded || b.treeStyleTab.autoHide.expanded) {
log('onTabbarResizing: setting expanded width to '+width);
// b.treeStyleTab.tabbarWidth = width; // b.treeStyleTab.tabbarWidth = width;
b.treeStyleTab.autoHide.expandedWidth = width; b.treeStyleTab.autoHide.expandedWidth = width;
if (b.treeStyleTab.autoHide.mode == b.treeStyleTab.autoHide.kMODE_SHRINK && 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); b.treeStyleTab.tabStripPlaceHolder.setAttribute('width', b.treeStyleTab.autoHide.shrunkenWidth);
} }
else { else {
log('onTabbarResizing: setting shrunken width to '+width);
b.treeStyleTab.autoHide.shrunkenWidth = width; b.treeStyleTab.autoHide.shrunkenWidth = width;
} }
} }
@ -1094,6 +1096,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
let delta = aEvent.screenY - this.tabbarResizeStartY; let delta = aEvent.screenY - this.tabbarResizeStartY;
height += (pos == 'top' ? delta : -delta ); height += (pos == 'top' ? delta : -delta );
height = this.maxTabbarHeight(height, b); height = this.maxTabbarHeight(height, b);
log('onTabbarResizing: setting height to '+height);
b.treeStyleTab.tabbarHeight = height; b.treeStyleTab.tabbarHeight = height;
} }
b.treeStyleTab.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_TABBAR_RESIZE); b.treeStyleTab.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_TABBAR_RESIZE);