OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 this._dataTableBody = this._dataTable.getElementsByTagName("tbody")[0]; | 466 this._dataTableBody = this._dataTable.getElementsByTagName("tbody")[0]; |
467 if (!this._dataTableBody) { | 467 if (!this._dataTableBody) { |
468 this._dataTableBody = this.element.ownerDocument.createElement("tbod y"); | 468 this._dataTableBody = this.element.ownerDocument.createElement("tbod y"); |
469 this._dataTable.insertBefore(this._dataTableBody, this._dataTable.tF oot); | 469 this._dataTable.insertBefore(this._dataTableBody, this._dataTable.tF oot); |
470 } | 470 } |
471 | 471 |
472 return this._dataTableBody; | 472 return this._dataTableBody; |
473 }, | 473 }, |
474 | 474 |
475 /** | 475 /** |
476 * @param {Array.<number>} widths | 476 * @param {!Array.<number>} widths |
477 * @param {number} minPercent | 477 * @param {number} minPercent |
478 * @param {number=} maxPercent | 478 * @param {number=} maxPercent |
479 * @return {!Array.<number>} | |
479 */ | 480 */ |
480 _autoSizeWidths: function(widths, minPercent, maxPercent) | 481 _autoSizeWidths: function(widths, minPercent, maxPercent) |
481 { | 482 { |
482 if (minPercent) | 483 if (minPercent) |
483 minPercent = Math.min(minPercent, Math.floor(100 / widths.length)); | 484 minPercent = Math.min(minPercent, Math.floor(100 / widths.length)); |
484 var totalWidth = 0; | 485 var totalWidth = 0; |
485 for (var i = 0; i < widths.length; ++i) | 486 for (var i = 0; i < widths.length; ++i) |
486 totalWidth += widths[i]; | 487 totalWidth += widths[i]; |
487 var totalPercentWidth = 0; | 488 var totalPercentWidth = 0; |
488 for (var i = 0; i < widths.length; ++i) { | 489 for (var i = 0; i < widths.length; ++i) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 // | 573 // |
573 // IMPORTANT: This function MUST be called once after the element of the | 574 // IMPORTANT: This function MUST be called once after the element of the |
574 // DataGrid is attached to its parent element and every subsequent time the | 575 // DataGrid is attached to its parent element and every subsequent time the |
575 // width of the parent element is changed in order to make it possible to | 576 // width of the parent element is changed in order to make it possible to |
576 // resize the columns. | 577 // resize the columns. |
577 // | 578 // |
578 // If this function is not called after the DataGrid is attached to its | 579 // If this function is not called after the DataGrid is attached to its |
579 // parent element, then the DataGrid's columns will not be resizable. | 580 // parent element, then the DataGrid's columns will not be resizable. |
580 updateWidths: function() | 581 updateWidths: function() |
581 { | 582 { |
582 var headerTableColumns = this._headerTableColumnGroup.children; | 583 // Do not attempt to use offsetes if we're not attached to the document tree yet. |
583 | |
584 var tableWidth = this._dataTable.offsetWidth; | 584 var tableWidth = this._dataTable.offsetWidth; |
pfeldman
2013/10/23 13:05:38
When grid only has header and no elements, this is
aandrey
2013/10/23 13:35:59
Reverted.
| |
585 var numColumns = headerTableColumns.length - 1; // Do not process corner column. | 585 if (!tableWidth) |
586 | 586 return; |
587 // Do not attempt to use offsetes if we're not attached to the document tree yet. | 587 if (!this._columnWidthsInitialized) { |
588 if (!this._columnWidthsInitialized && this.element.offsetWidth) { | 588 var headerTableColumns = this._headerTableColumnGroup.children; |
589 var numColumns = headerTableColumns.length - 1; // Do not process co rner column. | |
589 // Give all the columns initial widths now so that during a resize, | 590 // Give all the columns initial widths now so that during a resize, |
590 // when the two columns that get resized get a percent value for | 591 // when the two columns that get resized get a percent value for |
591 // their widths, all the other columns already have percent values | 592 // their widths, all the other columns already have percent values |
592 // for their widths. | 593 // for their widths. |
593 for (var i = 0; i < numColumns; i++) { | 594 for (var i = 0; i < numColumns; i++) { |
594 var columnWidth = this.headerTableBody.rows[0].cells[i].offsetWi dth; | 595 var columnWidth = this.headerTableBody.rows[0].cells[i].offsetWi dth; |
595 var percentWidth = ((columnWidth / tableWidth) * 100) + "%"; | 596 var percentWidth = (100 * columnWidth / tableWidth) + "%"; |
pfeldman
2013/10/23 13:05:38
Why?
aandrey
2013/10/23 13:35:59
An (poor) attempt to get more precision in floatin
| |
596 this._headerTableColumnGroup.children[i].style.width = percentWi dth; | 597 this._headerTableColumnGroup.children[i].style.width = percentWi dth; |
597 this._dataTableColumnGroup.children[i].style.width = percentWidt h; | 598 this._dataTableColumnGroup.children[i].style.width = percentWidt h; |
598 } | 599 } |
599 this._columnWidthsInitialized = true; | 600 this._columnWidthsInitialized = true; |
600 } | 601 } |
601 this._positionResizers(); | 602 this._positionResizers(); |
602 this.dispatchEventToListeners(WebInspector.DataGrid.Events.ColumnsResize d); | 603 this.dispatchEventToListeners(WebInspector.DataGrid.Events.ColumnsResize d); |
603 }, | 604 }, |
604 | 605 |
605 /** | 606 /** |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 }, | 644 }, |
644 | 645 |
645 applyColumnWeights: function() | 646 applyColumnWeights: function() |
646 { | 647 { |
647 var sumOfWeights = 0.0; | 648 var sumOfWeights = 0.0; |
648 for (var i = 0; i < this._columnsArray.length; ++i) { | 649 for (var i = 0; i < this._columnsArray.length; ++i) { |
649 var column = this._columnsArray[i]; | 650 var column = this._columnsArray[i]; |
650 if (this.isColumnVisible(column)) | 651 if (this.isColumnVisible(column)) |
651 sumOfWeights += column.weight; | 652 sumOfWeights += column.weight; |
652 } | 653 } |
653 var factor = 100 / sumOfWeights; | |
654 | 654 |
655 for (var i = 0; i < this._columnsArray.length; ++i) { | 655 for (var i = 0; i < this._columnsArray.length; ++i) { |
656 var column = this._columnsArray[i]; | 656 var column = this._columnsArray[i]; |
657 var width = this.isColumnVisible(column) ? ((factor * column.weight) + "%"): "0%"; | 657 var width = this.isColumnVisible(column) ? (100 * column.weight / su mOfWeights) + "%" : "0%"; |
658 this._headerTableColumnGroup.children[i].style.width = width; | 658 this._headerTableColumnGroup.children[i].style.width = width; |
659 this._dataTableColumnGroup.children[i].style.width = width; | 659 this._dataTableColumnGroup.children[i].style.width = width; |
660 } | 660 } |
661 | 661 |
662 this._positionResizers(); | 662 this._positionResizers(); |
663 this.dispatchEventToListeners(WebInspector.DataGrid.Events.ColumnsResize d); | 663 this.dispatchEventToListeners(WebInspector.DataGrid.Events.ColumnsResize d); |
664 }, | 664 }, |
665 | 665 |
666 /** | 666 /** |
667 * @param {!WebInspector.DataGrid.ColumnDescriptor} column | 667 * @param {!WebInspector.DataGrid.ColumnDescriptor} column |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 { | 1029 { |
1030 this._resizeMethod = method; | 1030 this._resizeMethod = method; |
1031 }, | 1031 }, |
1032 | 1032 |
1033 /** | 1033 /** |
1034 * @return {boolean} | 1034 * @return {boolean} |
1035 */ | 1035 */ |
1036 _startResizerDragging: function(event) | 1036 _startResizerDragging: function(event) |
1037 { | 1037 { |
1038 this._currentResizer = event.target; | 1038 this._currentResizer = event.target; |
1039 return !!this._currentResizer.rightNeighboringColumnIndex | 1039 return !!this._currentResizer.rightNeighboringColumnIndex; |
1040 }, | 1040 }, |
1041 | 1041 |
1042 _resizerDragging: function(event) | 1042 _resizerDragging: function(event) |
1043 { | 1043 { |
1044 var resizer = this._currentResizer; | 1044 var resizer = this._currentResizer; |
1045 if (!resizer) | 1045 if (!resizer) |
1046 return; | 1046 return; |
1047 | 1047 |
1048 var tableWidth = this._dataTable.offsetWidth; // Cache it early, before we invalidate layout. | 1048 var tableWidth = this._dataTable.offsetWidth; // Cache it early, before we invalidate layout. |
1049 | 1049 |
(...skipping 22 matching lines...) Expand all Loading... | |
1072 // Give each column some padding so that they don't disappear. | 1072 // Give each column some padding so that they don't disappear. |
1073 var leftMinimum = leftEdgeOfPreviousColumn + this.ColumnResizePadding; | 1073 var leftMinimum = leftEdgeOfPreviousColumn + this.ColumnResizePadding; |
1074 var rightMaximum = rightEdgeOfNextColumn - this.ColumnResizePadding; | 1074 var rightMaximum = rightEdgeOfNextColumn - this.ColumnResizePadding; |
1075 if (leftMinimum > rightMaximum) | 1075 if (leftMinimum > rightMaximum) |
1076 return; | 1076 return; |
1077 | 1077 |
1078 dragPoint = Number.constrain(dragPoint, leftMinimum, rightMaximum); | 1078 dragPoint = Number.constrain(dragPoint, leftMinimum, rightMaximum); |
1079 | 1079 |
1080 resizer.style.left = (dragPoint - this.CenterResizerOverBorderAdjustment ) + "px"; | 1080 resizer.style.left = (dragPoint - this.CenterResizerOverBorderAdjustment ) + "px"; |
1081 | 1081 |
1082 var percentLeftColumn = (((dragPoint - leftEdgeOfPreviousColumn) / table Width) * 100) + "%"; | 1082 var percentLeftColumn = (100 * (dragPoint - leftEdgeOfPreviousColumn) / tableWidth) + "%"; |
1083 this._headerTableColumnGroup.children[leftCellIndex].style.width = perce ntLeftColumn; | 1083 this._headerTableColumnGroup.children[leftCellIndex].style.width = perce ntLeftColumn; |
1084 this._dataTableColumnGroup.children[leftCellIndex].style.width = percent LeftColumn; | 1084 this._dataTableColumnGroup.children[leftCellIndex].style.width = percent LeftColumn; |
1085 | 1085 |
1086 var percentRightColumn = (((rightEdgeOfNextColumn - dragPoint) / tableWi dth) * 100) + "%"; | 1086 var percentRightColumn = (100 * (rightEdgeOfNextColumn - dragPoint) / ta bleWidth) + "%"; |
1087 this._headerTableColumnGroup.children[rightCellIndex].style.width = per centRightColumn; | 1087 this._headerTableColumnGroup.children[rightCellIndex].style.width = per centRightColumn; |
1088 this._dataTableColumnGroup.children[rightCellIndex].style.width = percen tRightColumn; | 1088 this._dataTableColumnGroup.children[rightCellIndex].style.width = percen tRightColumn; |
1089 | 1089 |
1090 var leftColumn = this._columnsArray[leftCellIndex]; | 1090 var leftColumn = this._columnsArray[leftCellIndex]; |
1091 var rightColumn = this._columnsArray[rightCellIndex]; | 1091 var rightColumn = this._columnsArray[rightCellIndex]; |
1092 if (leftColumn.weight || rightColumn.weight) { | 1092 if (leftColumn.weight || rightColumn.weight) { |
1093 var sumOfWeights = leftColumn.weight + rightColumn.weight; | 1093 var sumOfWeights = leftColumn.weight + rightColumn.weight; |
1094 var delta = rightEdgeOfNextColumn - leftEdgeOfPreviousColumn; | 1094 var delta = rightEdgeOfNextColumn - leftEdgeOfPreviousColumn; |
1095 leftColumn.weight = (dragPoint - leftEdgeOfPreviousColumn) * sumOfWe ights / delta; | 1095 leftColumn.weight = (dragPoint - leftEdgeOfPreviousColumn) * sumOfWe ights / delta; |
1096 rightColumn.weight = (rightEdgeOfNextColumn - dragPoint) * sumOfWeig hts / delta; | 1096 rightColumn.weight = (rightEdgeOfNextColumn - dragPoint) * sumOfWeig hts / delta; |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1797 | 1797 |
1798 WebInspector.CreationDataGridNode.prototype = { | 1798 WebInspector.CreationDataGridNode.prototype = { |
1799 makeNormal: function() | 1799 makeNormal: function() |
1800 { | 1800 { |
1801 delete this.isCreationNode; | 1801 delete this.isCreationNode; |
1802 delete this.makeNormal; | 1802 delete this.makeNormal; |
1803 }, | 1803 }, |
1804 | 1804 |
1805 __proto__: WebInspector.DataGridNode.prototype | 1805 __proto__: WebInspector.DataGridNode.prototype |
1806 } | 1806 } |
OLD | NEW |