Title: [217744] trunk/Source/WebInspectorUI
Revision
217744
Author
[email protected]
Date
2017-06-02 16:58:39 -0700 (Fri, 02 Jun 2017)

Log Message

Web Inspector: Attributes table in Node Details Sidebar should have editable keys and values
https://bugs.webkit.org/show_bug.cgi?id=167076
<rdar://problem/30033629>

Reviewed by Timothy Hatcher.

* UserInterface/Views/DOMNodeDetailsSidebarPanel.js:
(WebInspector.DOMNodeDetailsSidebarPanel.prototype._refreshAttributes):
(WebInspector.DOMNodeDetailsSidebarPanel.prototype._attributeNodeValueChanged):
(WebInspector.DOMNodeDetailsSidebarPanel.prototype._createAttributesDataGrid): Deleted.
Rework creation of the attributes DataGrid so that it is only created once and cleared for
new content. Nodes in the DataGrid are now EditableDataGridNode instances so that attribute
names and values can be changed from within the sidebar. The DataGrid is also sorted based
on attribute name, to make finding attributes easier.

* UserInterface/Views/DataGrid.css:
(.data-grid tr.editable .cell-content > input):
(body:not(.window-inactive, .window-docked-inactive) .data-grid:matches(:focus, .force-focus) tr.editable.selected .cell-content > input):

* UserInterface/Views/DetailsSection.css:
(.details-section > .content .data-grid tr:not(.editable) td.value-column):
(.details-section > .content .data-grid tr:not(.editable) td.value-column > div):
(.details-section > .content .data-grid td.value-column): Deleted.
(.details-section > .content .data-grid td.value-column > div): Deleted.

* UserInterface/Main.html:
* UserInterface/Views/EditableDataGridNode.js: Added.
(WebInspector.EditableDataGridNode):
(WebInspector.EditableDataGridNode.prototype.get element):
(WebInspector.EditableDataGridNode.prototype.createCellContent):
(WebInspector.EditableDataGridNode.prototype._handleKeyPress):
(WebInspector.EditableDataGridNode.prototype._handleBlur):
(WebInspector.EditableDataGridNode.prototype._notifyInputElementValueChanged):
Special type of DataGridNode that wraps the content of each cell in an <input>.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (217743 => 217744)


--- trunk/Source/WebInspectorUI/ChangeLog	2017-06-02 23:48:50 UTC (rev 217743)
+++ trunk/Source/WebInspectorUI/ChangeLog	2017-06-02 23:58:39 UTC (rev 217744)
@@ -1,5 +1,42 @@
 2017-06-02  Devin Rousso  <[email protected]>
 
+        Web Inspector: Attributes table in Node Details Sidebar should have editable keys and values
+        https://bugs.webkit.org/show_bug.cgi?id=167076
+        <rdar://problem/30033629>
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/DOMNodeDetailsSidebarPanel.js:
+        (WebInspector.DOMNodeDetailsSidebarPanel.prototype._refreshAttributes):
+        (WebInspector.DOMNodeDetailsSidebarPanel.prototype._attributeNodeValueChanged):
+        (WebInspector.DOMNodeDetailsSidebarPanel.prototype._createAttributesDataGrid): Deleted.
+        Rework creation of the attributes DataGrid so that it is only created once and cleared for
+        new content. Nodes in the DataGrid are now EditableDataGridNode instances so that attribute
+        names and values can be changed from within the sidebar. The DataGrid is also sorted based
+        on attribute name, to make finding attributes easier.
+
+        * UserInterface/Views/DataGrid.css:
+        (.data-grid tr.editable .cell-content > input):
+        (body:not(.window-inactive, .window-docked-inactive) .data-grid:matches(:focus, .force-focus) tr.editable.selected .cell-content > input):
+
+        * UserInterface/Views/DetailsSection.css:
+        (.details-section > .content .data-grid tr:not(.editable) td.value-column):
+        (.details-section > .content .data-grid tr:not(.editable) td.value-column > div):
+        (.details-section > .content .data-grid td.value-column): Deleted.
+        (.details-section > .content .data-grid td.value-column > div): Deleted.
+
+        * UserInterface/Main.html:
+        * UserInterface/Views/EditableDataGridNode.js: Added.
+        (WebInspector.EditableDataGridNode):
+        (WebInspector.EditableDataGridNode.prototype.get element):
+        (WebInspector.EditableDataGridNode.prototype.createCellContent):
+        (WebInspector.EditableDataGridNode.prototype._handleKeyPress):
+        (WebInspector.EditableDataGridNode.prototype._handleBlur):
+        (WebInspector.EditableDataGridNode.prototype._notifyInputElementValueChanged):
+        Special type of DataGridNode that wraps the content of each cell in an <input>.
+
+2017-06-02  Devin Rousso  <[email protected]>
+
         Web Inspector: Existing query in Search tab doesn't perform search on reload
         https://bugs.webkit.org/show_bug.cgi?id=172663
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Main.html (217743 => 217744)


--- trunk/Source/WebInspectorUI/UserInterface/Main.html	2017-06-02 23:48:50 UTC (rev 217743)
+++ trunk/Source/WebInspectorUI/UserInterface/Main.html	2017-06-02 23:58:39 UTC (rev 217744)
@@ -554,6 +554,7 @@
     <script src=""
     <script src=""
     <script src=""
+    <script src=""
     <script src=""
     <script src=""
     <script src=""

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/DOMNodeDetailsSidebarPanel.js (217743 => 217744)


--- trunk/Source/WebInspectorUI/UserInterface/Views/DOMNodeDetailsSidebarPanel.js	2017-06-02 23:48:50 UTC (rev 217743)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/DOMNodeDetailsSidebarPanel.js	2017-06-02 23:58:39 UTC (rev 217744)
@@ -161,7 +161,33 @@
 
     _refreshAttributes()
     {
-        this._attributesDataGridRow.dataGrid = this._createAttributesDataGrid();
+        let domNode = this.domNode;
+        if (!domNode || !domNode.hasAttributes()) {
+            // Remove the DataGrid to show the placeholder text.
+            this._attributesDataGridRow.dataGrid = null;
+            return;
+        }
+
+        let dataGrid = this._attributesDataGridRow.dataGrid;
+        if (!dataGrid) {
+            const columns = {
+                name: {title: WebInspector.UIString("Name"), width: "30%"},
+                value: {title: WebInspector.UIString("Value")},
+            };
+            dataGrid = this._attributesDataGridRow.dataGrid = new WebInspector.DataGrid(columns);
+        }
+
+        dataGrid.removeChildren();
+
+        let attributes = domNode.attributes();
+        attributes.sort((a, b) => a.name.localeCompare(b.name));
+        for (let attribute of attributes) {
+            let dataGridNode = new WebInspector.EditableDataGridNode(attribute);
+            dataGridNode.addEventListener(WebInspector.EditableDataGridNode.Event.ValueChanged, this._attributeNodeValueChanged, this);
+            dataGrid.appendChild(dataGridNode);
+        }
+
+        dataGrid.updateLayoutIfNeeded();
     }
 
     _refreshProperties()
@@ -712,6 +738,19 @@
         this._refreshAccessibility();
     }
 
+    _attributeNodeValueChanged(event)
+    {
+        let change = event.data;
+        let data = ""
+
+        if (change.columnIdentifier === "name") {
+            this.domNode.removeAttribute(data[change.columnIdentifier], (error) => {
+                this.domNode.setAttribute(change.value, `${change.value}="${data.value}"`);
+            });
+        } else if (change.columnIdentifier === "value")
+            this.domNode.setAttributeValue(data.name, change.value);
+    }
+
     _characterDataModified(event)
     {
         if (event.data.node !== this.domNode)
@@ -770,26 +809,6 @@
         console.error("Unknown DOM custom element state: ", state);
         return null;
     }
-
-    _createAttributesDataGrid()
-    {
-        var domNode = this.domNode;
-        if (!domNode || !domNode.hasAttributes())
-            return null;
-
-        var columns = {name: {title: WebInspector.UIString("Name"), width: "30%"}, value: {title: WebInspector.UIString("Value")}};
-        var dataGrid = new WebInspector.DataGrid(columns);
-
-        var attributes = domNode.attributes();
-        for (var i = 0; i < attributes.length; ++i) {
-            var attribute = attributes[i];
-
-            var node = new WebInspector.DataGridNode({name: attribute.name, value: attribute.value || ""}, false);
-            dataGrid.appendChild(node);
-        }
-
-        return dataGrid;
-    }
 };
 
 WebInspector.DOMNodeDetailsSidebarPanel.EventListenerGroupingMethod = {

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/DataGrid.css (217743 => 217744)


--- trunk/Source/WebInspectorUI/UserInterface/Views/DataGrid.css	2017-06-02 23:48:50 UTC (rev 217743)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/DataGrid.css	2017-06-02 23:58:39 UTC (rev 217744)
@@ -415,3 +415,17 @@
         border-width: 0.5px;
     }
 }
+
+.data-grid tr.editable .cell-content > input {
+    width: 100%;
+    height: 100%;
+    margin: 0;
+    padding: 0;
+    background: none;
+    border: none;
+    outline: none;
+}
+
+body:not(.window-inactive, .window-docked-inactive) .data-grid:matches(:focus, .force-focus) tr.editable.selected .cell-content > input {
+    color: white;
+}

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/DetailsSection.css (217743 => 217744)


--- trunk/Source/WebInspectorUI/UserInterface/Views/DetailsSection.css	2017-06-02 23:48:50 UTC (rev 217743)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/DetailsSection.css	2017-06-02 23:58:39 UTC (rev 217744)
@@ -307,7 +307,7 @@
     border-bottom: none;
 }
 
-.details-section > .content .data-grid td.value-column {
+.details-section > .content .data-grid tr:not(.editable) td.value-column {
     height: auto;
     line-height: initial;
     white-space: normal;
@@ -315,7 +315,7 @@
     padding-bottom: 4px;
 }
 
-.details-section > .content .data-grid td.value-column > div {
+.details-section > .content .data-grid tr:not(.editable) td.value-column > div {
     white-space: normal;
     word-break: break-all;
 }

Added: trunk/Source/WebInspectorUI/UserInterface/Views/EditableDataGridNode.js (0 => 217744)


--- trunk/Source/WebInspectorUI/UserInterface/Views/EditableDataGridNode.js	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/EditableDataGridNode.js	2017-06-02 23:58:39 UTC (rev 217744)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.EditableDataGridNode = class EditableDataGridNode extends WebInspector.DataGridNode
+{
+    constructor(data)
+    {
+        const hasChildren = false;
+        super(data, hasChildren);
+    }
+
+    // Public
+
+    get element()
+    {
+        let element = super.element;
+        if (element)
+            element.classList.add("editable");
+
+        return element;
+    }
+
+    // Protected
+
+    createCellContent(columnIdentifier, cell)
+    {
+        let content = super.createCellContent(columnIdentifier, cell);
+        console.assert(typeof content === "string");
+        if (typeof content !== "string")
+            return content;
+
+        let inputElement = document.createElement("input");
+        inputElement.value = content;
+        inputElement.addEventListener("keypress", this._handleKeyPress.bind(this, columnIdentifier));
+        inputElement.addEventListener("blur", this._handleBlur.bind(this, columnIdentifier));
+        return inputElement;
+    }
+
+    // Private
+
+    _handleKeyPress(columnIdentifier, event)
+    {
+        if (event.keyCode === WebInspector.KeyboardShortcut.Key.Escape.keyCode)
+            this.dataGrid.element.focus();
+
+        if (event.keyCode === WebInspector.KeyboardShortcut.Key.Enter.keyCode)
+            this._notifyInputElementValueChanged(columnIdentifier, event.target.value);
+    }
+
+    _handleBlur(columnIdentifier, event)
+    {
+        this._notifyInputElementValueChanged(columnIdentifier, event.target.value);
+    }
+
+    _notifyInputElementValueChanged(columnIdentifier, value)
+    {
+        if (value !== this.data[columnIdentifier])
+            this.dispatchEventToListeners(WebInspector.EditableDataGridNode.Event.ValueChanged, {value, columnIdentifier});
+    }
+};
+
+WebInspector.EditableDataGridNode.Event = {
+    ValueChanged: "editable-data-grid-node-value-changed",
+};
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to