Title: [139404] trunk
Revision
139404
Author
[email protected]
Date
2013-01-10 21:49:24 -0800 (Thu, 10 Jan 2013)

Log Message

Web Inspector: DataGrid refactoring: make cell editing more generic.
https://bugs.webkit.org/show_bug.cgi?id=105849

Patch by Eugene Klyuchnikov <[email protected]> on 2013-01-10
Reviewed by Pavel Feldman.

Source/WebCore:

Editing feature has been added to DataGrid to edit localStorage.
Column numbers (0 and 1) are hardcoded.

This patch makes column editing feature more generic: remove hardcoded
colums, take "editable" column property into account.

This patch is a prerequisite for cookie editing.

* inspector/front-end/DOMStorageItemsView.js:
Use meaningful column names.
* inspector/front-end/DataGrid.js:
(WebInspector.DataGrid.prototype._ondblclick): Check column editability.
(WebInspector.DataGrid.prototype._contextMenuInDataTable): Ditto.
(WebInspector.DataGridNode.prototype.createCell):
Supply cell element with column id.
(WebInspector.DataGrid.prototype.columnIdentifierFromNode):
Added utility method.
(WebInspector.DataGrid.prototype._nextEditableColumn): Ditto.
(WebInspector.DataGrid.prototype._keyDown): Calculate editable column.
(WebInspector.DataGrid.prototype._editingCommitted): Ditto.
(WebInspector.DataGrid.prototype._startEditing): Ditto.
(WebInspector.DataGrid.prototype._startEditingColumnOfDataGridNode):
Refined parameter type / name.
(WebInspector.DataGrid.prototype._resizerDragging):
Fix resizer index property names.
(WebInspector.DataGrid.prototype._startResizerDragging): Ditto.
(WebInspector.DataGrid.prototype._positionResizers): Ditto.
* inspector/front-end/NetworkPanel.js:
(WebInspector.NetworkLogView.prototype._updateDividersIfNeeded): Ditto.

LayoutTests:

* inspector/storage-panel-dom-storage-update.html: Fix column names.
* inspector/storage-panel-dom-storage.html: Ditto.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (139403 => 139404)


--- trunk/LayoutTests/ChangeLog	2013-01-11 05:33:05 UTC (rev 139403)
+++ trunk/LayoutTests/ChangeLog	2013-01-11 05:49:24 UTC (rev 139404)
@@ -1,3 +1,13 @@
+2013-01-10  Eugene Klyuchnikov  <[email protected]>
+
+        Web Inspector: DataGrid refactoring: make cell editing more generic.
+        https://bugs.webkit.org/show_bug.cgi?id=105849
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/storage-panel-dom-storage-update.html: Fix column names.
+        * inspector/storage-panel-dom-storage.html: Ditto.
+
 2013-01-10  Matt Falkenhagen  <[email protected]>
 
         Elements must be reattached when inserted/removed from top layer

Modified: trunk/LayoutTests/inspector/storage-panel-dom-storage-update.html (139403 => 139404)


--- trunk/LayoutTests/inspector/storage-panel-dom-storage-update.html	2013-01-11 05:33:05 UTC (rev 139403)
+++ trunk/LayoutTests/inspector/storage-panel-dom-storage-update.html	2013-01-11 05:49:24 UTC (rev 139404)
@@ -33,8 +33,8 @@
         var rows = [];
         for (var i = 0; i < nodes.length; ++i) {
             var node = nodes[i];
-            if (node._data[0].length)
-                rows.push(node._data[0] + node._data[1]);
+            if (node._data.key.length)
+                rows.push(node._data.key + node._data.value);
         }
         rows.sort();
         InspectorTest.addResult("KeyValue pairs: [" + rows.join() + "]");

Modified: trunk/LayoutTests/inspector/storage-panel-dom-storage.html (139403 => 139404)


--- trunk/LayoutTests/inspector/storage-panel-dom-storage.html	2013-01-11 05:33:05 UTC (rev 139403)
+++ trunk/LayoutTests/inspector/storage-panel-dom-storage.html	2013-01-11 05:49:24 UTC (rev 139404)
@@ -33,7 +33,7 @@
         var rows = [];
         for (var i = 0; i < nodes.length; ++i) {
             var node = nodes[i];
-            rows.push(node._data[0] + node._data[1]);
+            rows.push(node._data.key + node._data.value);
         }
         rows.sort();
         InspectorTest.addResult("KeyValue pairs: " + rows.join(''));

Modified: trunk/Source/WebCore/ChangeLog (139403 => 139404)


--- trunk/Source/WebCore/ChangeLog	2013-01-11 05:33:05 UTC (rev 139403)
+++ trunk/Source/WebCore/ChangeLog	2013-01-11 05:49:24 UTC (rev 139404)
@@ -1,3 +1,40 @@
+2013-01-10  Eugene Klyuchnikov  <[email protected]>
+
+        Web Inspector: DataGrid refactoring: make cell editing more generic.
+        https://bugs.webkit.org/show_bug.cgi?id=105849
+
+        Reviewed by Pavel Feldman.
+
+        Editing feature has been added to DataGrid to edit localStorage.
+        Column numbers (0 and 1) are hardcoded.
+
+        This patch makes column editing feature more generic: remove hardcoded
+        colums, take "editable" column property into account.
+
+        This patch is a prerequisite for cookie editing.
+
+        * inspector/front-end/DOMStorageItemsView.js:
+        Use meaningful column names.
+        * inspector/front-end/DataGrid.js:
+        (WebInspector.DataGrid.prototype._ondblclick): Check column editability.
+        (WebInspector.DataGrid.prototype._contextMenuInDataTable): Ditto.
+        (WebInspector.DataGridNode.prototype.createCell):
+        Supply cell element with column id.
+        (WebInspector.DataGrid.prototype.columnIdentifierFromNode):
+        Added utility method.
+        (WebInspector.DataGrid.prototype._nextEditableColumn): Ditto.
+        (WebInspector.DataGrid.prototype._keyDown): Calculate editable column.
+        (WebInspector.DataGrid.prototype._editingCommitted): Ditto.
+        (WebInspector.DataGrid.prototype._startEditing): Ditto.
+        (WebInspector.DataGrid.prototype._startEditingColumnOfDataGridNode):
+        Refined parameter type / name.
+        (WebInspector.DataGrid.prototype._resizerDragging):
+        Fix resizer index property names.
+        (WebInspector.DataGrid.prototype._startResizerDragging): Ditto.
+        (WebInspector.DataGrid.prototype._positionResizers): Ditto.
+        * inspector/front-end/NetworkPanel.js:
+        (WebInspector.NetworkLogView.prototype._updateDividersIfNeeded): Ditto.
+
 2013-01-10  Matt Falkenhagen  <[email protected]>
 
         Elements must be reattached when inserted/removed from top layer

Modified: trunk/Source/WebCore/inspector/front-end/DOMStorageItemsView.js (139403 => 139404)


--- trunk/Source/WebCore/inspector/front-end/DOMStorageItemsView.js	2013-01-11 05:33:05 UTC (rev 139403)
+++ trunk/Source/WebCore/inspector/front-end/DOMStorageItemsView.js	2013-01-11 05:49:24 UTC (rev 139404)
@@ -79,24 +79,22 @@
 
     _dataGridForDOMStorageEntries: function(entries)
     {
-        var columns = {};
-        columns[0] = {};
-        columns[1] = {};
-        columns[0].title = WebInspector.UIString("Key");
-        columns[1].title = WebInspector.UIString("Value");
+        var columns = {key: {}, value: {}};
 
+        columns.key.title = WebInspector.UIString("Key");
+        columns.key.editable = true;
+
+        columns.value.title = WebInspector.UIString("Value");
+        columns.value.editable = true;
+
         var nodes = [];
 
         var keys = [];
         var length = entries.length;
         for (var i = 0; i < entries.length; i++) {
-            var data = ""
-
             var key = entries[i][0];
-            data[0] = key;
             var value = entries[i][1];
-            data[1] = value;
-            var node = new WebInspector.DataGridNode(data, false);
+            var node = new WebInspector.DataGridNode({key: key, value: value}, false);
             node.selectable = true;
             nodes.push(node);
             keys.push(key);
@@ -128,13 +126,13 @@
     _editingCallback: function(editingNode, columnIdentifier, oldText, newText)
     {
         var domStorage = this.domStorage;
-        if (columnIdentifier === 0) {
+        if ("key" === columnIdentifier) {
             if (oldText)
                 domStorage.removeItem(oldText);
 
-            domStorage.setItem(newText, editingNode.data[1]);
+            domStorage.setItem(newText, editingNode.data.value);
         } else {
-            domStorage.setItem(editingNode.data[0], newText);
+            domStorage.setItem(editingNode.data.key, newText);
         }
 
         this.update();
@@ -146,7 +144,7 @@
             return;
 
         if (this.domStorage)
-            this.domStorage.removeItem(node.data[0]);
+            this.domStorage.removeItem(node.data.key);
 
         this.update();
     },

Modified: trunk/Source/WebCore/inspector/front-end/DataGrid.js (139403 => 139404)


--- trunk/Source/WebCore/inspector/front-end/DataGrid.js	2013-01-11 05:33:05 UTC (rev 139403)
+++ trunk/Source/WebCore/inspector/front-end/DataGrid.js	2013-01-11 05:49:24 UTC (rev 139404)
@@ -26,7 +26,7 @@
 /**
  * @constructor
  * @extends {WebInspector.View}
- * @param {function(WebInspector.DataGridNode, number, string, string)=} editCallback
+ * @param {function(WebInspector.DataGridNode, string, string, string)=} editCallback
  * @param {function(WebInspector.DataGridNode)=} deleteCallback
  */
 WebInspector.DataGrid = function(columns, editCallback, deleteCallback)
@@ -268,16 +268,23 @@
         if (this._editing || this._editingNode)
             return;
 
+        var columnIdentifier = this.columnIdentifierFromNode(event.target);
+        if (!columnIdentifier || !this.columns[columnIdentifier].editable)
+            return;
         this._startEditing(event.target);
     },
 
-    _startEditingColumnOfDataGridNode: function(node, column)
+    /**
+     * @param {!WebInspector.DataGridNode} node
+     * @param {number} columnOrdinal
+     */
+    _startEditingColumnOfDataGridNode: function(node, columnOrdinal)
     {
         this._editing = true;
         this._editingNode = node;
         this._editingNode.select();
 
-        var element = this._editingNode._element.children[column];
+        var element = this._editingNode._element.children[columnOrdinal];
         WebInspector.startEditing(element, this._startEditingConfig(element));
         window.getSelection().setBaseAndExtent(element, 0, element, 1);
     },
@@ -297,7 +304,7 @@
 
         // Force editing the 1st column when editing the creation node
         if (this._editingNode.isCreationNode)
-            return this._startEditingColumnOfDataGridNode(this._editingNode, 0);
+            return this._startEditingColumnOfDataGridNode(this._editingNode, this._nextEditableColumn(-1));
 
         this._editing = true;
         WebInspector.startEditing(element, this._startEditingConfig(element));
@@ -313,12 +320,12 @@
 
     _editingCommitted: function(element, newText, oldText, context, moveDirection)
     {
-        // FIXME: We need more column identifiers here throughout this function.
-        // Not needed yet since only editable DataGrid is DOM Storage, which is Key - Value.
-
-        // FIXME: Better way to do this than regular expressions?
-        var columnIdentifier = parseInt(element.className.match(/\b(\d+)-column\b/)[1], 10);
-
+        var columnIdentifier = this.columnIdentifierFromNode(element);
+        if (!columnIdentifier) {
+            this._editingCancelled(element);
+            return;
+        }
+        var columnOrdinal = this.columns[columnIdentifier].ordinal;
         var textBeforeEditing = this._editingNode.data[columnIdentifier];
         var currentEditingNode = this._editingNode;
 
@@ -327,29 +334,33 @@
                 return;
 
             if (moveDirection === "forward") {
-                if (currentEditingNode.isCreationNode && columnIdentifier === 0 && !wasChange)
+            var firstEditableColumn = this._nextEditableColumn(-1);
+                if (currentEditingNode.isCreationNode && columnOrdinal === firstEditableColumn && !wasChange)
                     return;
 
-                if (columnIdentifier === 0)
-                    return this._startEditingColumnOfDataGridNode(currentEditingNode, 1);
+                var nextEditableColumn = this._nextEditableColumn(columnOrdinal);
+                if (nextEditableColumn !== -1)
+                    return this._startEditingColumnOfDataGridNode(currentEditingNode, nextEditableColumn);
 
                 var nextDataGridNode = currentEditingNode.traverseNextNode(true, null, true);
                 if (nextDataGridNode)
-                    return this._startEditingColumnOfDataGridNode(nextDataGridNode, 0);
+                    return this._startEditingColumnOfDataGridNode(nextDataGridNode, firstEditableColumn);
                 if (currentEditingNode.isCreationNode && wasChange) {
                     this.addCreationNode(false);
-                    return this._startEditingColumnOfDataGridNode(this.creationNode, 0);
+                    return this._startEditingColumnOfDataGridNode(this.creationNode, firstEditableColumn);
                 }
                 return;
             }
 
             if (moveDirection === "backward") {
-                if (columnIdentifier === 1)
-                    return this._startEditingColumnOfDataGridNode(currentEditingNode, 0);
-                    var nextDataGridNode = currentEditingNode.traversePreviousNode(true, null, true);
+                var prevEditableColumn = this._nextEditableColumn(columnOrdinal, true);
+                if (prevEditableColumn !== -1)
+                    return this._startEditingColumnOfDataGridNode(currentEditingNode, prevEditableColumn);
 
+                var lastEditableColumn = this._nextEditableColumn(this._columnsArray.length, true);
+                var nextDataGridNode = currentEditingNode.traversePreviousNode(true, null, true);
                 if (nextDataGridNode)
-                    return this._startEditingColumnOfDataGridNode(nextDataGridNode, 1);
+                    return this._startEditingColumnOfDataGridNode(nextDataGridNode, lastEditableColumn);
                 return;
             }
         }
@@ -381,6 +392,22 @@
     },
 
     /**
+     * @param {number} columnOrdinal
+     * @param {boolean=} moveBackward
+     * @return {number}
+     */
+    _nextEditableColumn: function(columnOrdinal, moveBackward)
+    {
+        var increment = moveBackward ? -1 : 1;
+        var columns = this._columnsArray;
+        for (var i = columnOrdinal + increment; (i >= 0) && (i < columns.length); i += increment) {
+            if (columns[i].editable)
+                return columns[i].ordinal;
+        }
+        return -1;
+    },
+
+    /**
      * @return {?string}
      */
     get sortColumnIdentifier()
@@ -674,18 +701,18 @@
             if (columnIsVisible) {
                 resizer.style.removeProperty("display");
                 resizer.style.left = left + "px";
-                resizer.leftNeighboringColumnID = i;
+                resizer.leftNeighboringColumnIndex = i;
                 if (previousResizer)
-                    previousResizer.rightNeighboringColumnID = i;
+                    previousResizer.rightNeighboringColumnIndex = i;
                 previousResizer = resizer;
             } else {
                 resizer.style.setProperty("display", "none");
-                resizer.leftNeighboringColumnID = 0;
-                resizer.rightNeighboringColumnID = 0;
+                resizer.leftNeighboringColumnIndex = 0;
+                resizer.rightNeighboringColumnIndex = 0;
             }
         }
         if (previousResizer)
-            previousResizer.rightNeighboringColumnID = numColumns - 1;
+            previousResizer.rightNeighboringColumnIndex = numColumns - 1;
     },
 
     addCreationNode: function(hasChildren)
@@ -799,9 +826,7 @@
         } else if (isEnterKey(event)) {
             if (this._editCallback) {
                 handled = true;
-                // The first child of the selected element is the <td class="0-column">,
-                // and that's what we want to edit.
-                this._startEditing(this.selectedNode._element.children[0]);
+                this._startEditing(this.selectedNode._element.children[this._nextEditableColumn(-1)]);
             }
         }
 
@@ -814,17 +839,24 @@
             event.consume(true);
     },
 
+    /**
+     * @param {!Node} target
+     * @return {?WebInspector.DataGridNode}
+     */
     dataGridNodeFromNode: function(target)
     {
         var rowElement = target.enclosingNodeOrSelfWithNodeName("tr");
         return rowElement && rowElement._dataGridNode;
     },
 
-    dataGridNodeFromPoint: function(x, y)
+    /**
+     * @param {!Node} target
+     * @return {?string}
+     */
+    columnIdentifierFromNode: function(target)
     {
-        var node = this._dataTable.ownerDocument.elementFromPoint(x, y);
-        var rowElement = node.enclosingNodeOrSelfWithNodeName("tr");
-        return rowElement && rowElement._dataGridNode;
+        var cellElement = target.enclosingNodeOrSelfWithNodeName("td");
+        return cellElement && cellElement.columnIdentifier_;
     },
 
     _clickInHeaderCell: function(event)
@@ -896,8 +928,11 @@
             if (this._editCallback) {
                 if (gridNode === this.creationNode)
                     contextMenu.appendItem(WebInspector.UIString("Add New"), this._startEditing.bind(this, event.target));
-                else
-                    contextMenu.appendItem(WebInspector.UIString("Edit"), this._startEditing.bind(this, event.target));
+                else {
+                    var columnIdentifier = this.columnIdentifierFromNode(event.target);
+                    if (columnIdentifier && this.columns[columnIdentifier].editable)
+                        contextMenu.appendItem(WebInspector.UIString("Edit"), this._startEditing.bind(this, event.target));
+                }
             }
             if (this._deleteCallback && gridNode !== this.creationNode)
                 contextMenu.appendItem(WebInspector.UIString("Delete"), this._deleteCallback.bind(this, gridNode));
@@ -946,7 +981,7 @@
     _startResizerDragging: function(event)
     {
         this._currentResizer = event.target;
-        return !!this._currentResizer.rightNeighboringColumnID
+        return !!this._currentResizer.rightNeighboringColumnIndex
     },
 
     _resizerDragging: function(event)
@@ -960,8 +995,8 @@
         var dragPoint = event.clientX - this.element.totalOffsetLeft();
         // Constrain the dragpoint to be within the space made up by the
         // column directly to the left and the column directly to the right.
-        var leftCellIndex = resizer.leftNeighboringColumnID;
-        var rightCellIndex = resizer.rightNeighboringColumnID;
+        var leftCellIndex = resizer.leftNeighboringColumnIndex;
+        var rightCellIndex = resizer.rightNeighboringColumnIndex;
         var firstRowCells = this.headerTableBody.rows[0].cells;
         var leftEdgeOfPreviousColumn = 0;
         for (var i = 0; i < leftCellIndex; i++)
@@ -1224,6 +1259,7 @@
     {
         var cell = document.createElement("td");
         cell.className = columnIdentifier + "-column";
+        cell.columnIdentifier_ = columnIdentifier;
 
         var alignment = this.dataGrid.aligned[columnIdentifier];
         if (alignment)

Modified: trunk/Source/WebCore/inspector/front-end/NetworkPanel.js (139403 => 139404)


--- trunk/Source/WebCore/inspector/front-end/NetworkPanel.js	2013-01-11 05:33:05 UTC (rev 139403)
+++ trunk/Source/WebCore/inspector/front-end/NetworkPanel.js	2013-01-11 05:49:24 UTC (rev 139404)
@@ -535,7 +535,7 @@
             return;
         var timelineColumn = this._dataGrid.columns.timeline;
         for (var i = 0; i < this._dataGrid.resizers.length; ++i) {
-            if (timelineColumn.ordinal === this._dataGrid.resizers[i].rightNeighboringColumnID) {
+            if (timelineColumn.ordinal === this._dataGrid.resizers[i].rightNeighboringColumnIndex) {
                 // Position timline grid location.
                 this._timelineGrid.element.style.left = this._dataGrid.resizers[i].style.left;
                 this._timelineGrid.element.style.right = "18px";
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to