Changeset 35876 in webkit


Ignore:
Timestamp:
Aug 21, 2008 1:12:47 PM (16 years ago)
Author:
timothy@apple.com
Message:

Make the Inspector's Metrics sidebar pane editable.

https://bugs.webkit.org/show_bug.cgi?id=17218
rdar://problem/5732818

Reviewed by Kevin McCullough.

  • page/inspector/ElementsPanel.js: (WebInspector.ElementsPanel): Add an event listener for the "metrics edited" event, so the Styles pane is updated.
  • page/inspector/MetricsSidebarPane.js: (WebInspector.MetricsSidebarPane.prototype.update): Remember the node so future updates work. Add a double click event listener for the metric values to start editing. (WebInspector.MetricsSidebarPane.prototype.startEditing): Call WebInspector.startEditing with some context. (WebInspector.MetricsSidebarPane.prototype.editingCancelled): (WebInspector.MetricsSidebarPane.prototype.editingCommitted): Set the user input on the elements inline style. Fire the "metrics edited" event.
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r35875 r35876  
     12008-08-21  Timothy Hatcher  <timothy@apple.com>
     2
     3        Make the Inspector's Metrics sidebar pane editable.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=17218
     6        rdar://problem/5732818
     7
     8        Reviewed by Kevin McCullough.
     9
     10        * page/inspector/ElementsPanel.js:
     11        (WebInspector.ElementsPanel): Add an event listener for
     12        the "metrics edited" event, so the Styles pane is updated.
     13        * page/inspector/MetricsSidebarPane.js:
     14        (WebInspector.MetricsSidebarPane.prototype.update): Remember the node
     15        so future updates work. Add a double click event listener for the
     16        metric values to start editing.
     17        (WebInspector.MetricsSidebarPane.prototype.startEditing):
     18        Call WebInspector.startEditing with some context.
     19        (WebInspector.MetricsSidebarPane.prototype.editingCancelled):
     20        (WebInspector.MetricsSidebarPane.prototype.editingCommitted):
     21        Set the user input on the elements inline style. Fire the
     22        "metrics edited" event.
     23
    1242008-08-21  Steve Falkenburg  <sfalken@apple.com>
    225
  • trunk/WebCore/page/inspector/ElementsPanel.js

    r35576 r35876  
    6262    this.sidebarPanes.styles.expanded = true;
    6363
     64    this.sidebarPanes.metrics.addEventListener("metrics edited", this._metricsPaneEdited, this);
     65
    6466    this.sidebarElement = document.createElement("div");
    6567    this.sidebarElement.id = "elements-sidebar";
     
    410412        else
    411413            InspectorController.hideDOMNodeHighlight();
     414    },
     415
     416    _metricsPaneEdited: function()
     417    {
     418        this.sidebarPanes.styles.needsUpdate = true;
     419        this.updateStyles(true);
    412420    },
    413421
  • trunk/WebCore/page/inspector/MetricsSidebarPane.js

    r35859 r35876  
    3939        body.removeChildren();
    4040
    41         if (!node)
     41        if (node)
     42            this.node = node;
     43        else
     44            node = this.node;
     45
     46        if (!node || !node.ownerDocument.defaultView)
    4247            return;
    4348
     
    5358        function createBoxPartElement(style, name, side, suffix)
    5459        {
    55             var value = style.getPropertyValue((name !== "position" ? name + "-" : "") + side + suffix);
     60            var propertyName = (name !== "position" ? name + "-" : "") + side + suffix;
     61            var value = style.getPropertyValue(propertyName);
    5662            if (value === "" || (name !== "position" && value === "0px"))
    5763                value = "\u2012";
     
    6369            element.className = side;
    6470            element.textContent = value;
     71            element.addEventListener("dblclick", this.startEditing.bind(this, element, name, propertyName), false);
    6572            return element;
    6673        }
     
    110117            if (name === "content") {
    111118                var width = style.width.replace(/px$/, "");
     119                var widthElement = document.createElement("span");
     120                widthElement.textContent = width;
     121                widthElement.addEventListener("dblclick", this.startEditing.bind(this, widthElement, "width", "width"), false);
     122
    112123                var height = style.height.replace(/px$/, "");
    113                 boxElement.textContent = width + " \u00D7 " + height;
     124                var heightElement = document.createElement("span");
     125                heightElement.textContent = height;
     126                heightElement.addEventListener("dblclick", this.startEditing.bind(this, heightElement, "height", "height"), false);
     127
     128                boxElement.appendChild(widthElement);
     129                boxElement.appendChild(document.createTextNode(" \u00D7 "));
     130                boxElement.appendChild(heightElement);
    114131            } else {
    115132                var suffix = (name === "border" ? "-width" : "");
     
    120137                boxElement.appendChild(labelElement);
    121138
    122                 boxElement.appendChild(createBoxPartElement(style, name, "top", suffix));
    123                 boxElement.appendChild(createBoxPartElement(style, name, "left", suffix));
     139                boxElement.appendChild(createBoxPartElement.call(this, style, name, "top", suffix));
     140                boxElement.appendChild(document.createElement("br"));
     141                boxElement.appendChild(createBoxPartElement.call(this, style, name, "left", suffix));
    124142
    125143                if (previousBox)
    126144                    boxElement.appendChild(previousBox);
    127145
    128                 boxElement.appendChild(createBoxPartElement(style, name, "right", suffix));
    129                 boxElement.appendChild(createBoxPartElement(style, name, "bottom", suffix));
     146                boxElement.appendChild(createBoxPartElement.call(this, style, name, "right", suffix));
     147                boxElement.appendChild(document.createElement("br"));
     148                boxElement.appendChild(createBoxPartElement.call(this, style, name, "bottom", suffix));
    130149            }
    131150
     
    135154        metricsElement.appendChild(previousBox);
    136155        body.appendChild(metricsElement);
     156    },
     157
     158    startEditing: function(targetElement, box, styleProperty)
     159    {
     160        if (WebInspector.isBeingEdited(targetElement))
     161            return;
     162
     163        var context = { box: box, styleProperty: styleProperty };
     164
     165        WebInspector.startEditing(targetElement, this.editingCommitted.bind(this), this.editingCancelled.bind(this), context);
     166    },
     167
     168    editingCancelled: function(element, context)
     169    {
     170        this.update();
     171    },
     172
     173    editingCommitted: function(element, userInput, previousContent, context)
     174    {
     175        if (userInput === previousContent)
     176            return this.editingCancelled(element, context); // nothing changed, so cancel
     177
     178        if (context.box !== "position" && (!userInput || userInput === "\u2012"))
     179            userInput = "0px";
     180        else if (context.box === "position" && (!userInput || userInput === "\u2012"))
     181            userInput = "auto";
     182
     183        // Append a "px" unit if the user input was just a number.
     184        if (/^\d+$/.test(userInput))
     185            userInput += "px";
     186
     187        this.node.style.setProperty(context.styleProperty, userInput, "");
     188
     189        this.dispatchEventToListeners("metrics edited");
     190
     191        this.update();
    137192    }
    138193}
  • trunk/WebCore/page/inspector/inspector.css

    r35859 r35876  
    13931393    border: 1px rgb(66%, 66%, 66%) dotted;
    13941394    display: inline-block;
     1395    text-align: center;
    13951396    padding: 3px;
    13961397    margin: 3px;
     
    14001401    border: 1px dashed;
    14011402    display: inline-block;
     1403    text-align: center;
    14021404    vertical-align: middle;
    14031405    padding: 3px;
     
    14081410    border: 1px black solid;
    14091411    display: inline-block;
     1412    text-align: center;
    14101413    vertical-align: middle;
    14111414    padding: 3px;
     
    14161419    border: 1px grey dashed;
    14171420    display: inline-block;
     1421    text-align: center;
    14181422    vertical-align: middle;
    14191423    padding: 3px;
     
    14251429    border: 1px grey solid;
    14261430    display: inline-block;
     1431    text-align: center;
    14271432    vertical-align: middle;
    14281433    padding: 3px;
     
    14331438}
    14341439
     1440.metrics .content span {
     1441    display: inline-block;
     1442}
     1443
     1444.metrics .editing {
     1445    position: relative;
     1446    z-index: 100;
     1447}
     1448
    14351449.metrics .left {
    14361450    display: inline-block;
    1437     text-align: center;
    14381451    vertical-align: middle;
    14391452}
     
    14411454.metrics .right {
    14421455    display: inline-block;
    1443     text-align: center;
    14441456    vertical-align: middle;
    14451457}
    14461458
    14471459.metrics .top {
    1448     text-align: center;
     1460    display: inline-block;
    14491461}
    14501462
    14511463.metrics .bottom {
    1452     text-align: center;
     1464    display: inline-block;
    14531465}
    14541466
Note: See TracChangeset for help on using the changeset viewer.