From 7710adbd9abe9efe0d08372d07e1413b3aa0a304 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Fri, 4 Mar 2016 22:26:26 +0900 Subject: [PATCH 01/11] Calculate number of columns by self only when it is needed --- modules/fullTooltip.js | 3 +++ modules/pseudoTreeBuilder.js | 36 +++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/modules/fullTooltip.js b/modules/fullTooltip.js index 7ad7ac58..1419e745 100644 --- a/modules/fullTooltip.js +++ b/modules/fullTooltip.js @@ -602,8 +602,11 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { if (utils.getTreePref('tooltip.columnize')) { PseudoTreeBuilder.columnizeTree(tree, { + containerBox : { width : this.lastScreen.allowedWidth, height : this.lastScreen.allowedHeight + }, + calculateCount : true }); this.window.setTimeout(this.expandTooltipInternal.bind(this), 0); } diff --git a/modules/pseudoTreeBuilder.js b/modules/pseudoTreeBuilder.js index 95e67fe8..98dc0b99 100644 --- a/modules/pseudoTreeBuilder.js +++ b/modules/pseudoTreeBuilder.js @@ -146,32 +146,42 @@ var PseudoTreeBuilder = { return container; }, - columnizeTree : function TB_columnizeTree(aTree, aContainerBox) + columnizeTree : function TB_columnizeTree(aTree, aOptions) { if (!aTree) return; - aContainerBox = aContainerBox || aTree.parentNode.boxObject; + aOptions = aOptions || {}; + var containerBox = aOptions.containerBox || aTree.parentNode.boxObject; var style = aTree.style; var height = aTree.clientHeight * (aTree.columnCount || 1); - if (height > aContainerBox.height && - aContainerBox.height < aContainerBox.width) { - let maxWidth = aContainerBox.width; + if (height > containerBox.height && + containerBox.height < containerBox.width) { + let maxWidth = containerBox.width; aTree.columnWidth = Math.floor(maxWidth * 0.9 / 2.5); + style.columnWidth = style.MozColumnWidth = aTree.columnWidth+'px'; + style.columnGap = style.MozColumnGap = '0'; + style.columnFill = style.MozColumnFill = 'auto'; + if (aOptions.calculateCount) { let count = Math.ceil( (Math.max(aTree.clientWidth, maxWidth) * aTree.clientHeight) / (aTree.columnWidth * aTree.clientHeight) ); aTree.columnCount = style.columnCount = style.MozColumnCount = count; - style.columnWidth = style.MozColumnWidth = aTree.columnWidth+'px'; - style.columnGap = style.MozColumnGap = '0'; - style.columnFill = style.MozColumnFill = 'auto'; + } + else { + aTree.columnCount = 2; + style.columnCount = style.MozColumnCount = 'auto'; + } aTree.ownerDocument.defaultView.setTimeout((function() { - let columnCount = this.getActualColumnCount(aTree); - aTree.columnCount = style.columnCount = - style.MozColumnCount = columnCount; + aTree.columnCount = this.getActualColumnCount(aTree); + if (aOptions.calculateCount) { + style.columnCount = + style.MozColumnCount = + aTree.columnCount; + } }).bind(this), 0); } else { @@ -179,12 +189,12 @@ var PseudoTreeBuilder = { style.columnCount = style.MozColumnCount = style.columnWidth = style.MozColumnWidth = style.columnGap = style.MozColumnGap = - style.columnFill = style.MozColumnFill; + style.columnFill = style.MozColumnFill = ''; } if (aTree.columnCount > 1) { style.height = style.maxHeight = - Math.floor(aContainerBox.height * 0.9) + 'px'; + Math.floor(containerBox.height * 0.9) + 'px'; } else { style.height = style.maxHeight = ''; From 392b48ee8865836e7463f6b85cc09edcf0e3693c Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Fri, 4 Mar 2016 22:26:51 +0900 Subject: [PATCH 02/11] Fix indent --- modules/fullTooltip.js | 4 ++-- modules/pseudoTreeBuilder.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/fullTooltip.js b/modules/fullTooltip.js index 1419e745..f01f9926 100644 --- a/modules/fullTooltip.js +++ b/modules/fullTooltip.js @@ -603,8 +603,8 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { if (utils.getTreePref('tooltip.columnize')) { PseudoTreeBuilder.columnizeTree(tree, { containerBox : { - width : this.lastScreen.allowedWidth, - height : this.lastScreen.allowedHeight + width : this.lastScreen.allowedWidth, + height : this.lastScreen.allowedHeight }, calculateCount : true }); diff --git a/modules/pseudoTreeBuilder.js b/modules/pseudoTreeBuilder.js index 98dc0b99..92a9b6e5 100644 --- a/modules/pseudoTreeBuilder.js +++ b/modules/pseudoTreeBuilder.js @@ -164,11 +164,11 @@ var PseudoTreeBuilder = { style.columnGap = style.MozColumnGap = '0'; style.columnFill = style.MozColumnFill = 'auto'; if (aOptions.calculateCount) { - let count = Math.ceil( - (Math.max(aTree.clientWidth, maxWidth) * aTree.clientHeight) / - (aTree.columnWidth * aTree.clientHeight) - ); - aTree.columnCount = style.columnCount = style.MozColumnCount = count; + let count = Math.ceil( + (Math.max(aTree.clientWidth, maxWidth) * aTree.clientHeight) / + (aTree.columnWidth * aTree.clientHeight) + ); + aTree.columnCount = style.columnCount = style.MozColumnCount = count; } else { aTree.columnCount = 2; From a4ea563639bbf62427e476a65366dd93e18d1d52 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sat, 5 Mar 2016 12:35:49 +0900 Subject: [PATCH 03/11] Determine number of columns more smartly --- modules/fullTooltip.js | 101 ++++++++++++++--------------------- modules/pseudoTreeBuilder.js | 63 +++++++++++----------- 2 files changed, 70 insertions(+), 94 deletions(-) diff --git a/modules/fullTooltip.js b/modules/fullTooltip.js index f01f9926..ec76afb4 100644 --- a/modules/fullTooltip.js +++ b/modules/fullTooltip.js @@ -145,38 +145,6 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { }; }, - getTotalContentSize : function FTM_getTotalContentSize(aContainer) - { - var total = { - width : 0, - height : 0 - }; - var totalHeight = 0; - var orient = this.window.getComputedStyle(aContainer, null).getPropertyValue('orient'); - var isVertical = orient == 'vertical'; - Array.forEach(aContainer.childNodes, function(aNode) { - var width, height; - var box = aNode.boxObject; - if (box) { - width = box.width; - height = box.height; - } - else { - width = aNode.clientWidth; - height = aNode.clientHeight; - } - if (isVertical) { - total.width = Math.max(total.width, width); - total.height += height; - } - else { - total.width += width; - total.height = Math.max(total.height, height); - } - }); - return total; - }, - get currentTooltipMargins() { var tooltip = this.tabFullTooltip; @@ -560,11 +528,6 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { root.appendChild(container); this.tabFullTooltip.appendChild(root); - - log(' => tree size: ', { - width : tree.clientWidth, - height : tree.clientHeight - }); }, clear : function FTM_clear() @@ -584,23 +547,32 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { { let basePosition = this.windowBasePosition; let tooltipBox = tooltip.boxObject; - log(' => current tooltip position: ', { + log(' => initial dimension: ', { screenX : tooltipBox.screenX, screenY : tooltipBox.screenY, x : tooltipBox.screenX - basePosition.x, y : tooltipBox.screenY - basePosition.y, width : tooltipBox.width, - height : tooltipBox.height + height : tooltipBox.height, + tree : { + width : tree.clientWidth, + height : tree.clientHeight + } }); } - log(' => tree: ', { - width : tree.clientWidth, - height : tree.clientHeight - }); this.lastScreen = this.getCurrentScreen(tooltip.boxObject); - if (utils.getTreePref('tooltip.columnize')) { + var header = this.tree.previousSibling; + var extraHeight = header && header.boxObject.height || 0; + + var treeBox = { + width : tree.clientWidth, + height : tree.clientHeight + }; + + var columnize = utils.getTreePref('tooltip.columnize'); + if (columnize) { PseudoTreeBuilder.columnizeTree(tree, { containerBox : { width : this.lastScreen.allowedWidth, @@ -608,11 +580,19 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { }, calculateCount : true }); - this.window.setTimeout(this.expandTooltipInternal.bind(this), 0); } - else { + + this.window.setTimeout((function() { + if (!columnize || tree.columnCount != 1) + treeBox = tree.boxObject; + + var container = this.container; + var containerStyle = container.style; + containerStyle.width = (container.width = treeBox.width)+'px'; + containerStyle.height = (container.height = (treeBox.height + extraHeight))+'px'; + this.expandTooltipInternal(); - } + }).bind(this), 0); }, expandTooltipInternal : function FTM_expandTooltipInternal() { @@ -622,30 +602,24 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { var tooltip = this.tabFullTooltip; tooltip.setAttribute('popup-shown', true); - var requiredSize = this.getTotalContentSize(this.tree.parentNode); - { - // Let's maximize the container box enough to show the tree. - // If the tree is larger thant the tooltip, - // it becomes scrollable by arrowscrollbox. - let containerStyle = this.container.style; - containerStyle.width = requiredSize.width+'px'; - containerStyle.height = requiredSize.height+'px'; - } - var currentScreen = this.lastScreen || this.getCurrentScreen(box); var box = tooltip.boxObject; var currentX = box.screenX - currentScreen.left; var currentY = box.screenY - currentScreen.top; + var container = this.container; + var maxWidth = Math.min(container.width, currentScreen.allowedWidth); + var maxHeight = Math.min(container.height, currentScreen.allowedHeight); + var style = tooltip.style; - style.maxWidth = currentScreen.allowedWidth+'px'; + style.maxWidth = maxWidth+'px'; style.maxHeight = currentScreen.allowedHeight+'px'; style.minWidth = 0; style.minHeight = 0; var margins = this.currentTooltipMargins; - var maxX = currentScreen.width - Math.min(requiredSize.width, currentScreen.allowedWidth); - var maxY = currentScreen.height - Math.min(requiredSize.height, currentScreen.allowedHeight); + var maxX = currentScreen.width - maxWidth; + var maxY = currentScreen.height - maxHeight; log(' => current dimension: ', { margins : margins, @@ -653,7 +627,12 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { y : currentY, maxX : maxX, maxY : maxY, - required : requiredSize + container : { + width : container.width, + height : container.height + }, + screen : currentScreen, + columnCount : this.tree.columnCount }); if (currentX > maxX) diff --git a/modules/pseudoTreeBuilder.js b/modules/pseudoTreeBuilder.js index 92a9b6e5..127567eb 100644 --- a/modules/pseudoTreeBuilder.js +++ b/modules/pseudoTreeBuilder.js @@ -152,31 +152,39 @@ var PseudoTreeBuilder = { return; aOptions = aOptions || {}; - var containerBox = aOptions.containerBox || aTree.parentNode.boxObject; - var style = aTree.style; - var height = aTree.clientHeight * (aTree.columnCount || 1); - if (height > containerBox.height && - containerBox.height < containerBox.width) { - let maxWidth = containerBox.width; - aTree.columnWidth = Math.floor(maxWidth * 0.9 / 2.5); - style.columnWidth = style.MozColumnWidth = aTree.columnWidth+'px'; - style.columnGap = style.MozColumnGap = '0'; - style.columnFill = style.MozColumnFill = 'auto'; - if (aOptions.calculateCount) { - let count = Math.ceil( - (Math.max(aTree.clientWidth, maxWidth) * aTree.clientHeight) / - (aTree.columnWidth * aTree.clientHeight) - ); - aTree.columnCount = style.columnCount = style.MozColumnCount = count; - } - else { - aTree.columnCount = 2; - style.columnCount = style.MozColumnCount = 'auto'; - } + style.columnWidth = style.MozColumnWidth = 'calc(20em)'; + { + let computedStyle = aTree.ownerDocument.defaultView.getComputedStyle(aTree, null) + aTree.columnWidth = Number((computedStyle.MozColumnWidth || computedStyle.columnWidth).replace(/px/, '')); + } + style.columnGap = style.MozColumnGap = '0'; + style.columnFill = style.MozColumnFill = 'auto'; + + var containerBox = aOptions.containerBox || aTree.parentNode.boxObject; + var maxWidth = containerBox.width; + if (aOptions.calculateCount) { + let count = Math.ceil( + (Math.max(aTree.clientWidth, maxWidth) * aTree.clientHeight) / + (aTree.columnWidth * aTree.clientHeight) + ); + style.columnCount = style.MozColumnCount = count; + } + else { + style.columnCount = style.MozColumnCount = 'auto'; + } + + if (aTree.columnWidth * 2 <= maxWidth || + aOptions.calculateCount) { + style.height = style.maxHeight = + Math.floor(containerBox.height * 0.9) + 'px'; + + aTree.columnCount = 0; aTree.ownerDocument.defaultView.setTimeout((function() { aTree.columnCount = this.getActualColumnCount(aTree); + if (aTree.columnCount == 1) + style.columnWidth = style.MozColumnWidth = ''; if (aOptions.calculateCount) { style.columnCount = style.MozColumnCount = @@ -184,20 +192,9 @@ var PseudoTreeBuilder = { } }).bind(this), 0); } - else { - aTree.columnCount = 1; - style.columnCount = style.MozColumnCount = - style.columnWidth = style.MozColumnWidth = - style.columnGap = style.MozColumnGap = - style.columnFill = style.MozColumnFill = ''; - } - - if (aTree.columnCount > 1) { - style.height = style.maxHeight = - Math.floor(containerBox.height * 0.9) + 'px'; - } else { style.height = style.maxHeight = ''; + aTree.columnCount = 1; } }, getActualColumnCount : function TB_getActualColumnCount(aTree) From 7bbfcbc59444a826274d0bddb3f7226aef1c24d8 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sat, 5 Mar 2016 12:49:56 +0900 Subject: [PATCH 04/11] Don't show scroll buttons if they are not required --- modules/fullTooltip.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/fullTooltip.js b/modules/fullTooltip.js index ec76afb4..153aa5c1 100644 --- a/modules/fullTooltip.js +++ b/modules/fullTooltip.js @@ -588,9 +588,13 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { var container = this.container; var containerStyle = container.style; - containerStyle.width = (container.width = treeBox.width)+'px'; + var arrowScrollBox = container.parentNode; + var scrollButtonsMargin = (arrowScrollBox.boxObject.width - arrowScrollBox._scrollbox.boxObject.width); + scrollButtonsMargin *= 2; // enough width to deactivate scroll buttons. + containerStyle.width = (container.width = treeBox.width + scrollButtonsMargin)+'px'; containerStyle.height = (container.height = (treeBox.height + extraHeight))+'px'; + this.expandTooltipInternal(); }).bind(this), 0); }, From 1624bc751c9bf548252177606b6a919c68313665 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sat, 5 Mar 2016 12:50:52 +0900 Subject: [PATCH 05/11] Remove needless blank line --- modules/fullTooltip.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/fullTooltip.js b/modules/fullTooltip.js index 153aa5c1..9704fd72 100644 --- a/modules/fullTooltip.js +++ b/modules/fullTooltip.js @@ -594,7 +594,6 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { containerStyle.width = (container.width = treeBox.width + scrollButtonsMargin)+'px'; containerStyle.height = (container.height = (treeBox.height + extraHeight))+'px'; - this.expandTooltipInternal(); }).bind(this), 0); }, From f43aa54ea056110b49a9199c0d64e9911870c85f Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sat, 5 Mar 2016 14:43:00 +0900 Subject: [PATCH 06/11] Add news topic --- history.en.md | 1 + history.ja.md | 1 + 2 files changed, 2 insertions(+) diff --git a/history.en.md b/history.en.md index 65a2cd87..6ef01940 100644 --- a/history.en.md +++ b/history.en.md @@ -1,6 +1,7 @@ # History - master/HEAD + * Activate multi-column layout only when it is required, at tooltip of tabs and dummy group tabs. - 0.17.2016030402 * Show rich tooltip with multiple columns even if there are only short title tabs. * Avoid initialization error on newly opened group tabs. diff --git a/history.ja.md b/history.ja.md index 6cd325bc..67d3c0f0 100644 --- a/history.ja.md +++ b/history.ja.md @@ -1,6 +1,7 @@ # 更新履歴 - master/HEAD + * タブのツールチップとダミーのグループ化用のタブにおいて、内容が1列に収まらないときだけマルチカラム表示するようにした - 0.17.2016030402 * 短いタイトルのタブしかない場合にツールチップの内容が段組表示されない問題を修正 * 新しく開かれた空のグループ化用のタブの初期化処理が失敗するようになっていたのを修正 From 32d71fb1f125379d4b041e3810fc9a7dc6136d79 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sat, 5 Mar 2016 14:47:55 +0900 Subject: [PATCH 07/11] Make column width configurable --- defaults/preferences/treestyletab.js | 2 ++ modules/fullTooltip.js | 1 + modules/groupTab.js | 4 +++- modules/pseudoTreeBuilder.js | 4 +++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/defaults/preferences/treestyletab.js b/defaults/preferences/treestyletab.js index 04db6447..82920270 100644 --- a/defaults/preferences/treestyletab.js +++ b/defaults/preferences/treestyletab.js @@ -346,6 +346,7 @@ pref("extensions.treestyletab.tooltip.fullTooltipDelay", 2000); * If true, too many items are shown in multiple columns. */ pref("extensions.treestyletab.tooltip.columnize", true); +pref("extensions.treestyletab.tooltip.columnize.width", "20em"); /** * Visibility of extra menu items for the context menu on tabs, inserted by TST. @@ -662,6 +663,7 @@ pref("extensions.treestyletab.pinnedTab.faviconized", true); * If true, too many items are shown in multiple columns in a dummy (group) tab. */ pref("extensions.treestyletab.groupTab.columnize", true); +pref("extensions.treestyletab.groupTab.columnize.width", "20em"); /** * Compatibility hack flags for other addons. They can be disabled by each diff --git a/modules/fullTooltip.js b/modules/fullTooltip.js index 9704fd72..68fd9230 100644 --- a/modules/fullTooltip.js +++ b/modules/fullTooltip.js @@ -574,6 +574,7 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { var columnize = utils.getTreePref('tooltip.columnize'); if (columnize) { PseudoTreeBuilder.columnizeTree(tree, { + columnWidth : utils.getTreePref('tooltip.columnize.width'), containerBox : { width : this.lastScreen.allowedWidth, height : this.lastScreen.allowedHeight diff --git a/modules/groupTab.js b/modules/groupTab.js index fba531fb..51d38929 100644 --- a/modules/groupTab.js +++ b/modules/groupTab.js @@ -411,7 +411,9 @@ GroupTab.prototype = inherit(TreeStyleTabBase, { return; var container = this.document.getElementById('tree'); var tree = container.firstChild; - PseudoTreeBuilder.columnizeTree(tree); + PseudoTreeBuilder.columnizeTree(tree, { + columnWidth : utils.getTreePref('groupTab.columnize.width') + }); }, onTabAttached : function GT_onTabAttached(aEvent) diff --git a/modules/pseudoTreeBuilder.js b/modules/pseudoTreeBuilder.js index 127567eb..f493d597 100644 --- a/modules/pseudoTreeBuilder.js +++ b/modules/pseudoTreeBuilder.js @@ -152,9 +152,11 @@ var PseudoTreeBuilder = { return; aOptions = aOptions || {}; + aOptions.width = aOptions.width || '20em'; + var style = aTree.style; - style.columnWidth = style.MozColumnWidth = 'calc(20em)'; + style.columnWidth = style.MozColumnWidth = 'calc(' + aOptions.width + ')'; { let computedStyle = aTree.ownerDocument.defaultView.getComputedStyle(aTree, null) aTree.columnWidth = Number((computedStyle.MozColumnWidth || computedStyle.columnWidth).replace(/px/, '')); From a20d24466434018b945e2e07c69b2add1cf533e3 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sat, 5 Mar 2016 15:53:26 +0900 Subject: [PATCH 08/11] Allow to customize width of columns --- modules/pseudoTreeBuilder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/pseudoTreeBuilder.js b/modules/pseudoTreeBuilder.js index f493d597..7f3fdbcd 100644 --- a/modules/pseudoTreeBuilder.js +++ b/modules/pseudoTreeBuilder.js @@ -152,11 +152,11 @@ var PseudoTreeBuilder = { return; aOptions = aOptions || {}; - aOptions.width = aOptions.width || '20em'; + aOptions.columnWidth = aOptions.columnWidth || '20em'; var style = aTree.style; - style.columnWidth = style.MozColumnWidth = 'calc(' + aOptions.width + ')'; + style.columnWidth = style.MozColumnWidth = 'calc(' + aOptions.columnWidth + ')'; { let computedStyle = aTree.ownerDocument.defaultView.getComputedStyle(aTree, null) aTree.columnWidth = Number((computedStyle.MozColumnWidth || computedStyle.columnWidth).replace(/px/, '')); From a173ed4e6639f1c3486e69600b9bf70d79f6dee3 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sat, 5 Mar 2016 16:56:09 +0900 Subject: [PATCH 09/11] Simplify --- modules/pseudoTreeBuilder.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/modules/pseudoTreeBuilder.js b/modules/pseudoTreeBuilder.js index 7f3fdbcd..4e737e37 100644 --- a/modules/pseudoTreeBuilder.js +++ b/modules/pseudoTreeBuilder.js @@ -163,20 +163,10 @@ var PseudoTreeBuilder = { } style.columnGap = style.MozColumnGap = '0'; style.columnFill = style.MozColumnFill = 'auto'; + style.columnCount = style.MozColumnCount = 'auto'; var containerBox = aOptions.containerBox || aTree.parentNode.boxObject; var maxWidth = containerBox.width; - if (aOptions.calculateCount) { - let count = Math.ceil( - (Math.max(aTree.clientWidth, maxWidth) * aTree.clientHeight) / - (aTree.columnWidth * aTree.clientHeight) - ); - style.columnCount = style.MozColumnCount = count; - } - else { - style.columnCount = style.MozColumnCount = 'auto'; - } - if (aTree.columnWidth * 2 <= maxWidth || aOptions.calculateCount) { style.height = style.maxHeight = @@ -188,6 +178,7 @@ var PseudoTreeBuilder = { if (aTree.columnCount == 1) style.columnWidth = style.MozColumnWidth = ''; if (aOptions.calculateCount) { + // This is required to expand the size of the box. style.columnCount = style.MozColumnCount = aTree.columnCount; From c42e2415d873281ab013b5d0e71f0054384a0e9c Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sun, 6 Mar 2016 00:34:27 +0900 Subject: [PATCH 10/11] Calculate required size for a tree more smartly --- modules/fullTooltip.js | 41 ++++++++++++++++++------------------ modules/pseudoTreeBuilder.js | 16 +++----------- 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/modules/fullTooltip.js b/modules/fullTooltip.js index 68fd9230..e8949391 100644 --- a/modules/fullTooltip.js +++ b/modules/fullTooltip.js @@ -543,8 +543,8 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { { log('expandTooltip'); var tooltip = this.tabFullTooltip; - var tree = this.tree; { + let tree = this.tree; let basePosition = this.windowBasePosition; let tooltipBox = tooltip.boxObject; log(' => initial dimension: ', { @@ -563,13 +563,12 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { this.lastScreen = this.getCurrentScreen(tooltip.boxObject); - var header = this.tree.previousSibling; - var extraHeight = header && header.boxObject.height || 0; - - var treeBox = { - width : tree.clientWidth, - height : tree.clientHeight - }; + this.determineTreeSize(); + this.expandTooltipInternal(); + }, + determineTreeSize : function FTM_determineTreeSize() + { + var tree = this.tree; var columnize = utils.getTreePref('tooltip.columnize'); if (columnize) { @@ -583,20 +582,22 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, { }); } - this.window.setTimeout((function() { - if (!columnize || tree.columnCount != 1) - treeBox = tree.boxObject; + var range = this.document.createRange(); + range.selectNodeContents(tree); + if (tree.previousSibling) + range.setStartBefore(tree.previousSibling); + var rect = range.getBoundingClientRect(); + range.detach(); - var container = this.container; - var containerStyle = container.style; - var arrowScrollBox = container.parentNode; - var scrollButtonsMargin = (arrowScrollBox.boxObject.width - arrowScrollBox._scrollbox.boxObject.width); - scrollButtonsMargin *= 2; // enough width to deactivate scroll buttons. - containerStyle.width = (container.width = treeBox.width + scrollButtonsMargin)+'px'; - containerStyle.height = (container.height = (treeBox.height + extraHeight))+'px'; + var container = this.container; - this.expandTooltipInternal(); - }).bind(this), 0); + var arrowScrollBox = container.parentNode; + var scrollButtonsMargin = (arrowScrollBox.boxObject.width - arrowScrollBox._scrollbox.boxObject.width); + scrollButtonsMargin *= 2; // enough width to deactivate scroll buttons. + + var containerStyle = container.style; + containerStyle.width = (container.width = rect.width + scrollButtonsMargin)+'px'; + containerStyle.height = (container.height = rect.height)+'px'; }, expandTooltipInternal : function FTM_expandTooltipInternal() { diff --git a/modules/pseudoTreeBuilder.js b/modules/pseudoTreeBuilder.js index 4e737e37..6a3cb9a4 100644 --- a/modules/pseudoTreeBuilder.js +++ b/modules/pseudoTreeBuilder.js @@ -172,22 +172,12 @@ var PseudoTreeBuilder = { style.height = style.maxHeight = Math.floor(containerBox.height * 0.9) + 'px'; - aTree.columnCount = 0; - aTree.ownerDocument.defaultView.setTimeout((function() { - aTree.columnCount = this.getActualColumnCount(aTree); - if (aTree.columnCount == 1) - style.columnWidth = style.MozColumnWidth = ''; - if (aOptions.calculateCount) { - // This is required to expand the size of the box. - style.columnCount = - style.MozColumnCount = - aTree.columnCount; - } - }).bind(this), 0); + aTree.columnCount = this.getActualColumnCount(aTree); + if (aTree.columnCount == 1) + style.columnWidth = style.MozColumnWidth = ''; } else { style.height = style.maxHeight = ''; - aTree.columnCount = 1; } }, getActualColumnCount : function TB_getActualColumnCount(aTree) From f373c987faeab838a85dc0ca6735b1d9ce1b6de2 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sun, 6 Mar 2016 00:40:13 +0900 Subject: [PATCH 11/11] Calculate actual number of columns more smartly --- modules/pseudoTreeBuilder.js | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/modules/pseudoTreeBuilder.js b/modules/pseudoTreeBuilder.js index 6a3cb9a4..f3002c5f 100644 --- a/modules/pseudoTreeBuilder.js +++ b/modules/pseudoTreeBuilder.js @@ -172,8 +172,7 @@ var PseudoTreeBuilder = { style.height = style.maxHeight = Math.floor(containerBox.height * 0.9) + 'px'; - aTree.columnCount = this.getActualColumnCount(aTree); - if (aTree.columnCount == 1) + if (this.getActualColumnCount(aTree) == 1) style.columnWidth = style.MozColumnWidth = ''; } else { @@ -182,24 +181,10 @@ var PseudoTreeBuilder = { }, getActualColumnCount : function TB_getActualColumnCount(aTree) { - var rows = aTree.querySelectorAll('*|*.' + this.kTREEROW); - if (rows.length <= 1) - return 0; - - var firstRow = rows[0]; - if (rows[0].clientWidth === 0) // ignore hidden item! - firstRow = rows[1]; - var lastRow = rows[rows.length - 1]; - - var firstWidth = firstRow.clientWidth; - var lastWidth = lastRow.clientWidth; - - // We have to see XUL box object's x instead of HTML element's clientLeft - // to get actual position of elements in a multi-column box. - var firstX = firstRow.querySelector('label').boxObject.x; - var lastX = lastRow.querySelector('label').boxObject.x; - - var totalWidth = lastX + lastWidth - firstX; - return Math.floor(totalWidth / firstWidth); + var range = aTree.ownerDocument.createRange(); + range.selectNodeContents(aTree); + var rect = range.getBoundingClientRect(); + range.detach(); + return Math.floor(rect.width / aTree.columnWidth); } };