Commit 8cb9c735 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

2010-02-05 Pavel Feldman <pfeldman@chromium.org>

        Reviewed by Timothy Hatcher.

        Web Inspector: simplify cookies view, introduce DataGrid::autoSizeColumns.

        https://bugs.webkit.org/show_bug.cgi?id=34646

        * inspector/front-end/CookieItemsView.js:
        (WebInspector.CookieItemsView):
        (WebInspector.CookieItemsView.prototype.show):
        (WebInspector.CookieItemsView.prototype._update):
        (WebInspector.CookieItemsView.prototype._updateWithCookies):
        (WebInspector.CookieItemsView.prototype._filterCookiesForDomain):
        (WebInspector.CookieItemsView.prototype._createDataGrid):
        (WebInspector.CookieItemsView.prototype._populateDataGrid.expiresCompare):
        (WebInspector.CookieItemsView.prototype._populateDataGrid):
        (WebInspector.CookieItemsView.prototype._createSimpleDataGrid):
        (WebInspector.CookieItemsView.prototype._populateSimpleDataGrid):
        (WebInspector.CookieItemsView.prototype._deleteCookieCallback):
        (WebInspector.CookieItemsView.prototype._refreshButtonClicked):
        * inspector/front-end/DOMStorageItemsView.js:
        (WebInspector.DOMStorageItemsView.prototype._showDOMStorageEntries):
        (WebInspector.DOMStorageItemsView.prototype._dataGridForDOMStorageEntries):
        * inspector/front-end/DataGrid.js:
        (WebInspector.DataGrid):
        (WebInspector.DataGrid.prototype.autoSizeColumns):
        * inspector/front-end/DatabaseQueryView.js:
        (WebInspector.DatabaseQueryView.prototype._queryFinished):
        * inspector/front-end/DatabaseTableView.js:
        (WebInspector.DatabaseTableView.prototype._queryFinished):
        * inspector/front-end/StoragePanel.js:
        (WebInspector.StoragePanel.prototype.dataGridForResult):


git-svn-id: svn://svn.chromium.org/blink/trunk@54436 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent de3b60df
2010-02-05 Pavel Feldman <pfeldman@chromium.org>
Reviewed by Timothy Hatcher.
Web Inspector: simplify cookies view, introduce DataGrid::autoSizeColumns.
https://bugs.webkit.org/show_bug.cgi?id=34646
* inspector/front-end/CookieItemsView.js:
(WebInspector.CookieItemsView):
(WebInspector.CookieItemsView.prototype.show):
(WebInspector.CookieItemsView.prototype._update):
(WebInspector.CookieItemsView.prototype._updateWithCookies):
(WebInspector.CookieItemsView.prototype._filterCookiesForDomain):
(WebInspector.CookieItemsView.prototype._createDataGrid):
(WebInspector.CookieItemsView.prototype._populateDataGrid.expiresCompare):
(WebInspector.CookieItemsView.prototype._populateDataGrid):
(WebInspector.CookieItemsView.prototype._createSimpleDataGrid):
(WebInspector.CookieItemsView.prototype._populateSimpleDataGrid):
(WebInspector.CookieItemsView.prototype._deleteCookieCallback):
(WebInspector.CookieItemsView.prototype._refreshButtonClicked):
* inspector/front-end/DOMStorageItemsView.js:
(WebInspector.DOMStorageItemsView.prototype._showDOMStorageEntries):
(WebInspector.DOMStorageItemsView.prototype._dataGridForDOMStorageEntries):
* inspector/front-end/DataGrid.js:
(WebInspector.DataGrid):
(WebInspector.DataGrid.prototype.autoSizeColumns):
* inspector/front-end/DatabaseQueryView.js:
(WebInspector.DatabaseQueryView.prototype._queryFinished):
* inspector/front-end/DatabaseTableView.js:
(WebInspector.DatabaseTableView.prototype._queryFinished):
* inspector/front-end/StoragePanel.js:
(WebInspector.StoragePanel.prototype.dataGridForResult):
2010-02-04 Pavel Feldman <pfeldman@chromium.org>
Reviewed by Timothy Hatcher.
......
......@@ -69,7 +69,7 @@ WebInspector.DOMStorageItemsView.prototype = {
{
this._dataGrid = this._dataGridForDOMStorageEntries(entries);
this.element.appendChild(this._dataGrid.element);
this._dataGrid.updateWidths();
this._dataGrid.autoSizeColumns(10);
this.deleteButton.visible = true;
},
......@@ -85,9 +85,7 @@ WebInspector.DOMStorageItemsView.prototype = {
columns[0] = {};
columns[1] = {};
columns[0].title = WebInspector.UIString("Key");
columns[0].width = columns[0].title.length;
columns[1].title = WebInspector.UIString("Value");
columns[1].width = columns[1].title.length;
var nodes = [];
......@@ -98,31 +96,14 @@ WebInspector.DOMStorageItemsView.prototype = {
var key = entries[i][0];
data[0] = key;
if (key.length > columns[0].width)
columns[0].width = key.length;
var value = entries[i][1];
data[1] = value;
if (value.length > columns[1].width)
columns[1].width = value.length;
var node = new WebInspector.DataGridNode(data, false);
node.selectable = true;
nodes.push(node);
keys.push(key);
}
var totalColumnWidths = columns[0].width + columns[1].width;
var width = Math.round((columns[0].width * 100) / totalColumnWidths);
const minimumPrecent = 10;
if (width < minimumPrecent)
width = minimumPrecent;
if (width > 100 - minimumPrecent)
width = 100 - minimumPrecent;
columns[0].width = width;
columns[1].width = 100 - width;
columns[0].width += "%";
columns[1].width += "%";
var dataGrid = new WebInspector.DataGrid(columns, this._editingCallback.bind(this), this._deleteCallback.bind(this));
var length = nodes.length;
for (var i = 0; i < length; ++i)
......
......@@ -61,7 +61,7 @@ WebInspector.DataGrid = function(columns, editCallback, deleteCallback)
var headerRow = document.createElement("tr");
var columnGroup = document.createElement("colgroup");
var columnCount = 0;
this._columnCount = 0;
for (var columnIdentifier in columns) {
var column = columns[columnIdentifier];
......@@ -71,6 +71,7 @@ WebInspector.DataGrid = function(columns, editCallback, deleteCallback)
var col = document.createElement("col");
if (column.width)
col.style.width = column.width;
column.element = col;
columnGroup.appendChild(col);
var cell = document.createElement("th");
......@@ -98,10 +99,10 @@ WebInspector.DataGrid = function(columns, editCallback, deleteCallback)
headerRow.appendChild(cell);
++columnCount;
++this._columnCount;
}
columnGroup.span = columnCount;
columnGroup.span = this._columnCount;
var cell = document.createElement("th");
cell.className = "corner";
......@@ -114,7 +115,7 @@ WebInspector.DataGrid = function(columns, editCallback, deleteCallback)
var fillerRow = document.createElement("tr");
fillerRow.className = "filler";
for (var i = 0; i < columnCount; ++i) {
for (var i = 0; i < this._columnCount; ++i) {
var cell = document.createElement("td");
fillerRow.appendChild(cell);
}
......@@ -292,7 +293,70 @@ WebInspector.DataGrid.prototype = {
return this._dataTableBody;
},
autoSizeColumns: function(minPercent, maxPercent)
{
if (minPercent)
minPercent = Math.min(minPercent, Math.floor(100 / this._columnCount));
var widths = {};
var columns = this.columns;
for (var columnIdentifier in columns)
widths[columnIdentifier] = (columns[columnIdentifier].title || "").length;
for (var i = 0; i < this.children.length; ++i) {
var node = this.children[i];
for (var columnIdentifier in columns) {
var text = node.data[columnIdentifier] || "";
if (text.length > widths[columnIdentifier])
widths[columnIdentifier] = text.length;
}
}
var totalColumnWidths = 0;
for (var columnIdentifier in columns)
totalColumnWidths += widths[columnIdentifier];
var recoupPercent = 0;
for (var columnIdentifier in columns) {
var width = Math.round(100 * widths[columnIdentifier] / totalColumnWidths);
if (minPercent && width < minPercent) {
recoupPercent += (minPercent - width);
width = minPercent;
} else if (maxPercent && width > maxPercent) {
recoupPercent -= (width - maxPercent);
width = maxPercent;
}
widths[columnIdentifier] = width;
}
while (minPercent && recoupPercent > 0) {
for (var columnIdentifier in columns) {
if (widths[columnIdentifier] > minPercent) {
--widths[columnIdentifier];
--recoupPercent;
if (!recoupPercent)
break;
}
}
}
while (maxPercent && recoupPercent < 0) {
for (var columnIdentifier in columns) {
if (widths[columnIdentifier] < maxPercent) {
++widths[columnIdentifier];
++recoupPercent;
if (!recoupPercent)
break;
}
}
}
for (var columnIdentifier in columns)
columns[columnIdentifier].element.style.width = widths[columnIdentifier] + "%";
this.columnWidthsInitialized = false;
this.updateWidths();
},
// Updates the widths of the table, including the positions of the column
// resizers.
//
......
......@@ -144,6 +144,7 @@ WebInspector.DatabaseQueryView.prototype = {
return;
dataGrid.element.addStyleClass("inline");
this._appendQueryResult(query, dataGrid.element);
dataGrid.autoSizeColumns(5);
if (query.match(/^create /i) || query.match(/^drop table /i))
WebInspector.panels.storage.updateDatabaseTables(this.database);
......
......@@ -68,6 +68,7 @@ WebInspector.DatabaseTableView.prototype = {
}
this.element.appendChild(dataGrid.element);
dataGrid.autoSizeColumns(5);
},
_queryError: function(error)
......
......@@ -300,52 +300,14 @@ WebInspector.StoragePanel.prototype = {
var data = {};
var row = rows[i];
for (var columnIdentifier in row) {
var text = row[columnIdentifier];
data[columnIdentifier] = text;
if (text.length > columns[columnIdentifier].width)
columns[columnIdentifier].width = text.length;
}
for (var columnIdentifier in row)
data[columnIdentifier] = row[columnIdentifier];
var node = new WebInspector.DataGridNode(data, false);
node.selectable = false;
nodes.push(node);
}
var totalColumnWidths = 0;
for (var columnIdentifier in columns)
totalColumnWidths += columns[columnIdentifier].width;
// Calculate the percentage width for the columns.
const minimumPrecent = Math.min(5, Math.floor(100/numColumns));
var recoupPercent = 0;
for (var columnIdentifier in columns) {
var width = columns[columnIdentifier].width;
width = Math.round((width / totalColumnWidths) * 100);
if (width < minimumPrecent) {
recoupPercent += (minimumPrecent - width);
width = minimumPrecent;
}
columns[columnIdentifier].width = width;
}
// Enforce the minimum percentage width.
while (recoupPercent > 0) {
for (var columnIdentifier in columns) {
if (columns[columnIdentifier].width > minimumPrecent) {
--columns[columnIdentifier].width;
--recoupPercent;
if (!recoupPercent)
break;
}
}
}
// Change the width property to a string suitable for a style width.
for (var columnIdentifier in columns)
columns[columnIdentifier].width += "%";
var dataGrid = new WebInspector.DataGrid(columns);
var length = nodes.length;
for (var i = 0; i < length; ++i)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment