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