From c42e2415d873281ab013b5d0e71f0054384a0e9c Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sun, 6 Mar 2016 00:34:27 +0900 Subject: [PATCH] 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)