Calculate actual number of columns more smartly

This commit is contained in:
Piro / YUKI Hiroshi 2016-03-06 00:40:13 +09:00
parent c42e2415d8
commit f373c987fa

View File

@ -172,8 +172,7 @@ var PseudoTreeBuilder = {
style.height = style.maxHeight = style.height = style.maxHeight =
Math.floor(containerBox.height * 0.9) + 'px'; Math.floor(containerBox.height * 0.9) + 'px';
aTree.columnCount = this.getActualColumnCount(aTree); if (this.getActualColumnCount(aTree) == 1)
if (aTree.columnCount == 1)
style.columnWidth = style.MozColumnWidth = ''; style.columnWidth = style.MozColumnWidth = '';
} }
else { else {
@ -182,24 +181,10 @@ var PseudoTreeBuilder = {
}, },
getActualColumnCount : function TB_getActualColumnCount(aTree) getActualColumnCount : function TB_getActualColumnCount(aTree)
{ {
var rows = aTree.querySelectorAll('*|*.' + this.kTREEROW); var range = aTree.ownerDocument.createRange();
if (rows.length <= 1) range.selectNodeContents(aTree);
return 0; var rect = range.getBoundingClientRect();
range.detach();
var firstRow = rows[0]; return Math.floor(rect.width / aTree.columnWidth);
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);
} }
}; };