Title: [108995] trunk
Revision
108995
Author
apav...@chromium.org
Date
2012-02-27 08:36:53 -0800 (Mon, 27 Feb 2012)

Log Message

Web Inspector: [Styles] Allow adding CSS properties anywhere in the style declaration, not only at the end
https://bugs.webkit.org/show_bug.cgi?id=79662

Reviewed by Pavel Feldman.

Source/WebCore:

* inspector/front-end/CSSStyleModel.js:
(WebInspector.CSSStyleDeclaration.prototype.newBlankProperty):
(WebInspector.CSSProperty.prototype.setText):
(WebInspector.CSSProperty.prototype.setValue):
* inspector/front-end/MetricsSidebarPane.js:
(WebInspector.MetricsSidebarPane.prototype._applyUserInput):
* inspector/front-end/StylesSidebarPane.js:
(WebInspector.StylePropertiesSection):
(WebInspector.StylePropertiesSection.prototype._handleSelectorContainerClick):
(WebInspector.StylePropertiesSection.prototype.addNewBlankProperty):
(WebInspector.StylePropertyTreeElement.prototype):
(WebInspector.StylePropertyTreeElement.prototype.element.userInput.previousContent.context.moveDirection):
(WebInspector.StylePropertyTreeElement.prototype.styleText.updateInterface.majorChange.isRevert):

LayoutTests:

* inspector/styles/styles-add-blank-property-expected.txt:
* inspector/styles/styles-add-blank-property.html:
* inspector/styles/styles-formatting.html:
* inspector/styles/styles-history.html:
* inspector/styles/undo-add-property-expected.txt:
* inspector/styles/undo-add-property.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (108994 => 108995)


--- trunk/LayoutTests/ChangeLog	2012-02-27 15:49:04 UTC (rev 108994)
+++ trunk/LayoutTests/ChangeLog	2012-02-27 16:36:53 UTC (rev 108995)
@@ -1,3 +1,17 @@
+2012-02-27  Alexander Pavlov  <apav...@chromium.org>
+
+        Web Inspector: [Styles] Allow adding CSS properties anywhere in the style declaration, not only at the end
+        https://bugs.webkit.org/show_bug.cgi?id=79662
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/styles/styles-add-blank-property-expected.txt:
+        * inspector/styles/styles-add-blank-property.html:
+        * inspector/styles/styles-formatting.html:
+        * inspector/styles/styles-history.html:
+        * inspector/styles/undo-add-property-expected.txt:
+        * inspector/styles/undo-add-property.html:
+
 2012-02-27  Ilya Tikhonovsky  <loi...@chromium.org>
 
         Unreviewed fix for lint error after r108992.

Modified: trunk/LayoutTests/inspector/styles/styles-add-blank-property-expected.txt (108994 => 108995)


--- trunk/LayoutTests/inspector/styles/styles-add-blank-property-expected.txt	2012-02-27 15:49:04 UTC (rev 108994)
+++ trunk/LayoutTests/inspector/styles/styles-add-blank-property-expected.txt	2012-02-27 16:36:53 UTC (rev 108995)
@@ -12,11 +12,25 @@
 display: block;
 
 
-After append:
+After insertion at index 0:
 [expanded] 
 element.style  { ()
+margin-left: 3px;
 font-size: 12px;
+
+======== Matched CSS Rules ========
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+After appending and changing a 'compound' property:
+[expanded] 
+element.style  { ()
 margin-left: 3px;
+font-size: 12px;
+color: red;
+font-weight: bold;
 
 ======== Matched CSS Rules ========
 [expanded] 
@@ -24,11 +38,12 @@
 display: block;
 
 
-After append and change of a 'compound' property:
+After insertion at index 2:
 [expanded] 
 element.style  { ()
+margin-left: 3px;
 font-size: 12px;
-margin-left: 3px;
+/-- overloaded --/ third-property: third-value;
 color: red;
 font-weight: bold;
 

Modified: trunk/LayoutTests/inspector/styles/styles-add-blank-property.html (108994 => 108995)


--- trunk/LayoutTests/inspector/styles/styles-add-blank-property.html	2012-02-27 15:49:04 UTC (rev 108994)
+++ trunk/LayoutTests/inspector/styles/styles-add-blank-property.html	2012-02-27 16:36:53 UTC (rev 108995)
@@ -7,12 +7,12 @@
 function test()
 {
     WebInspector.showPanel("elements");
-    InspectorTest.selectNodeAndWaitForStyles("inspected", step1);
+    InspectorTest.selectNodeAndWaitForStyles("inspected", addAndIncrementFirstProperty);
 
     var treeElement;
     var section;
 
-    function step1()
+    function addAndIncrementFirstProperty()
     {
         InspectorTest.addResult("Before append:");
         InspectorTest.dumpSelectedElementStyles(true);
@@ -20,7 +20,7 @@
         section.expand();
 
         // Create and increment.
-        treeElement = section.addNewBlankProperty();
+        treeElement = section.addNewBlankProperty(0);
         treeElement.startEditing();
         treeElement.nameElement.textContent = "margin-left";
         treeElement.nameElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
@@ -28,35 +28,29 @@
         treeElement.valueElement.textContent = "1px";
         treeElement.valueElement.firstChild.select();
         treeElement.valueElement.dispatchEvent(InspectorTest.createKeyEvent("Up"));
-        InspectorTest.runAfterPendingDispatches(step2);
+        InspectorTest.runAfterPendingDispatches(incrementProperty);
     }
 
-    function step2()
+    function incrementProperty()
     {
         // Increment again.
         treeElement.valueElement.dispatchEvent(InspectorTest.createKeyEvent("Up"));
-        InspectorTest.runAfterPendingDispatches(step3);
+        InspectorTest.runAfterPendingDispatches(commitProperty);
     }
 
-    function step3()
+    function commitProperty()
     {
         // Commit.
         treeElement.nameElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
-        InspectorTest.selectNodeWithId("other");
-        InspectorTest.runAfterPendingDispatches(step4);
+        reloadStyles(addAndChangeLastCompoundProperty);
     }
 
-    function step4()
+    function addAndChangeLastCompoundProperty()
     {
-        InspectorTest.selectNodeAndWaitForStyles("inspected", step5);
-    }
-
-    function step5()
-    {
-        InspectorTest.addResult("After append:");
+        InspectorTest.addResult("After insertion at index 0:");
         InspectorTest.dumpSelectedElementStyles(true);
 
-        treeElement = WebInspector.panels.elements.sidebarPanes.styles.sections[0][1].addNewBlankProperty();
+        treeElement = WebInspector.panels.elements.sidebarPanes.styles.sections[0][1].addNewBlankProperty(2);
         treeElement.startEditing();
         treeElement.nameElement.textContent = "color";
         treeElement.nameElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
@@ -68,27 +62,41 @@
         treeElement.kickFreeFlowStyleEditForTest();
 
         treeElement.valueElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
-        InspectorTest.runAfterPendingDispatches(step6);
+        InspectorTest.runAfterPendingDispatches(reloadStyles.bind(this, addAndCommitMiddleProperty));
     }
 
-    function step6()
+    function addAndCommitMiddleProperty()
     {
-        InspectorTest.selectNodeWithId("other");
-        InspectorTest.runAfterPendingDispatches(step7);
-    }
+        InspectorTest.addResult("After appending and changing a 'compound' property:");
+        InspectorTest.dumpSelectedElementStyles(true);
 
-    function step7()
-    {
-        InspectorTest.selectNodeAndWaitForStyles("inspected", step8);
+        treeElement = WebInspector.panels.elements.sidebarPanes.styles.sections[0][1].addNewBlankProperty(2);
+        treeElement.startEditing();
+        treeElement.nameElement.textContent = "third-property";
+        treeElement.nameElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
+        treeElement.valueElement.textContent = "third-value";
+
+        treeElement.nameElement.dispatchEvent(InspectorTest.createKeyEvent("Enter"));
+        InspectorTest.runAfterPendingDispatches(reloadStyles.bind(this, dumpAndComplete));
     }
 
-
-    function step8()
+    function dumpAndComplete()
     {
-        InspectorTest.addResult("After append and change of a 'compound' property:");
+        InspectorTest.addResult("After insertion at index 2:");
         InspectorTest.dumpSelectedElementStyles(true);
+
         InspectorTest.completeTest();
     }
+
+    function reloadStyles(callback) {
+        InspectorTest.selectNodeWithId("other");
+        InspectorTest.runAfterPendingDispatches(otherCallback);
+
+        function otherCallback()
+        {
+            InspectorTest.selectNodeAndWaitForStyles("inspected", callback);
+        }
+    }
 }
 
 </script>

Modified: trunk/LayoutTests/inspector/styles/styles-formatting.html (108994 => 108995)


--- trunk/LayoutTests/inspector/styles/styles-formatting.html	2012-02-27 15:49:04 UTC (rev 108994)
+++ trunk/LayoutTests/inspector/styles/styles-formatting.html	2012-02-27 16:36:53 UTC (rev 108995)
@@ -38,7 +38,7 @@
 
         function testFormattedRemoveStart(next)
         {
-            formattedStyle.allProperties[0].setText("", true, dumpFormattedAndCallNext.bind(null, next));
+            formattedStyle.allProperties[0].setText("", true, true, dumpFormattedAndCallNext.bind(null, next));
         },
 
         function testFormattedInsertMiddle(next)
@@ -48,7 +48,7 @@
 
         function testFormattedRemoveMiddle(next)
         {
-            formattedStyle.allProperties[1].setText("", true, dumpFormattedAndCallNext.bind(null, next));
+            formattedStyle.allProperties[1].setText("", true, true, dumpFormattedAndCallNext.bind(null, next));
         },
 
         function testFormattedInsertEnd(next)
@@ -58,7 +58,7 @@
 
         function testFormattedRemoveEnd(next)
         {
-            formattedStyle.allProperties[3].setText("", true, dumpFormattedAndCallNext.bind(null, next));
+            formattedStyle.allProperties[3].setText("", true, true, dumpFormattedAndCallNext.bind(null, next));
         },
 
         function testFormattedDisableStart(next)
@@ -133,7 +133,7 @@
 
         function testUnformattedRemoveStart(next)
         {
-            unformattedStyle.allProperties[0].setText("", true, dumpUnformattedAndCallNext.bind(null, next));
+            unformattedStyle.allProperties[0].setText("", true, true, dumpUnformattedAndCallNext.bind(null, next));
         },
 
         function testUnformattedInsertMiddle(next)
@@ -143,7 +143,7 @@
 
         function testUnformattedRemoveMiddle(next)
         {
-            unformattedStyle.allProperties[1].setText("", true, dumpUnformattedAndCallNext.bind(null, next));
+            unformattedStyle.allProperties[1].setText("", true, true, dumpUnformattedAndCallNext.bind(null, next));
         },
 
         function testUnformattedInsertEnd(next)
@@ -153,7 +153,7 @@
 
         function testUnformattedRemoveEnd(next)
         {
-            unformattedStyle.allProperties[3].setText("", true, dumpUnformattedAndCallNext.bind(null, next));
+            unformattedStyle.allProperties[3].setText("", true, true, dumpUnformattedAndCallNext.bind(null, next));
         },
 
         function testUnformattedDisableStart(next)

Modified: trunk/LayoutTests/inspector/styles/styles-history.html (108994 => 108995)


--- trunk/LayoutTests/inspector/styles/styles-history.html	2012-02-27 15:49:04 UTC (rev 108994)
+++ trunk/LayoutTests/inspector/styles/styles-history.html	2012-02-27 16:36:53 UTC (rev 108995)
@@ -56,7 +56,7 @@
                 {
                     var style = styleSheet.rules[0].style;
                     var property = style.getLiveProperty("margin");
-                    property.setText("margin:25px;", false, step2);
+                    property.setText("margin:25px;", false, true, step2);
                 }
 
                 function step2()
@@ -75,7 +75,7 @@
                     var style = styleSheet.rules[0].style;
                     var property = style.getLiveProperty("margin");
                     waitForRevision(next);
-                    property.setText("margin:30px;", true);
+                    property.setText("margin:30px;", true, true);
                 }
             }
         ]);

Modified: trunk/LayoutTests/inspector/styles/undo-add-property-expected.txt (108994 => 108995)


--- trunk/LayoutTests/inspector/styles/undo-add-property-expected.txt	2012-02-27 15:49:04 UTC (rev 108994)
+++ trunk/LayoutTests/inspector/styles/undo-add-property-expected.txt	2012-02-27 16:36:53 UTC (rev 108995)
@@ -1,6 +1,7 @@
 Tests that adding a property is undone properly.
 
-Initial value
+=== Last property ===
+(Initial value)
 [expanded] 
 element.style  { ()
 
@@ -14,7 +15,7 @@
 display: block;
 
 
-After adding property
+(After adding property)
 [expanded] 
 element.style  { ()
 
@@ -22,14 +23,14 @@
 [expanded] 
 .container  { (undo-add-property.html:7)
 font-weight: bold;
-margin-left: 1px;
+margin-left: 2px;
 
 [expanded] 
 div  { (user agent stylesheet)
 display: block;
 
 
-After undo
+(After undo)
 [expanded] 
 element.style  { ()
 
@@ -43,7 +44,7 @@
 display: block;
 
 
-After redo
+(After redo)
 [expanded] 
 element.style  { ()
 
@@ -51,11 +52,141 @@
 [expanded] 
 .container  { (undo-add-property.html:7)
 font-weight: bold;
-margin-left: 1px;
+margin-left: 2px;
 
 [expanded] 
 div  { (user agent stylesheet)
 display: block;
 
 
+=== First property ===
+(Initial value)
+[expanded] 
+element.style  { ()
 
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (undo-add-property.html:7)
+font-weight: bold;
+margin-left: 2px;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+(After adding property)
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (undo-add-property.html:7)
+margin-top: 0px;
+font-weight: bold;
+margin-left: 2px;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+(After undo)
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (undo-add-property.html:7)
+font-weight: bold;
+margin-left: 2px;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+(After redo)
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (undo-add-property.html:7)
+margin-top: 0px;
+font-weight: bold;
+margin-left: 2px;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+=== Middle property ===
+(Initial value)
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (undo-add-property.html:7)
+margin-top: 0px;
+font-weight: bold;
+margin-left: 2px;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+(After adding property)
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (undo-add-property.html:7)
+margin-top: 0px;
+margin-right: 1px;
+font-weight: bold;
+margin-left: 2px;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+(After undo)
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (undo-add-property.html:7)
+margin-top: 0px;
+font-weight: bold;
+margin-left: 2px;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+(After redo)
+[expanded] 
+element.style  { ()
+
+======== Matched CSS Rules ========
+[expanded] 
+.container  { (undo-add-property.html:7)
+margin-top: 0px;
+margin-right: 1px;
+font-weight: bold;
+margin-left: 2px;
+
+[expanded] 
+div  { (user agent stylesheet)
+display: block;
+
+
+

Modified: trunk/LayoutTests/inspector/styles/undo-add-property.html (108994 => 108995)


--- trunk/LayoutTests/inspector/styles/undo-add-property.html	2012-02-27 15:49:04 UTC (rev 108994)
+++ trunk/LayoutTests/inspector/styles/undo-add-property.html	2012-02-27 16:36:53 UTC (rev 108995)
@@ -13,42 +13,61 @@
 
 function test()
 {
-    InspectorTest.selectNodeAndWaitForStyles("container", step1);
+    InspectorTest.selectNodeAndWaitForStyles("container", testAppendProperty.bind(null, testInsertBegin));
 
-    function step1()
+    function testAppendProperty()
     {
-        InspectorTest.addResult("Initial value");
-        InspectorTest.dumpSelectedElementStyles(true);
+        InspectorTest.addResult("=== Last property ===");
+        testAddProperty("margin-left: 2px", undefined, testInsertBegin);
+    }
 
-        var treeItem = InspectorTest.getMatchedStylePropertyTreeItem("font-weight");
-        var treeElement = treeItem.section.addNewBlankProperty();
-        treeElement.applyStyleText("margin-left: 1px", true, false);
-        InspectorTest.waitForStyles("container", step2);
+    function testInsertBegin()
+    {
+        InspectorTest.addResult("=== First property ===");
+        testAddProperty("margin-top: 0px", 0, testInsertMiddle);
     }
 
-    function step2()
+    function testInsertMiddle()
     {
-        InspectorTest.addResult("After adding property");
-        InspectorTest.dumpSelectedElementStyles(true);
-
-        WebInspector.domAgent.undo();
-        InspectorTest.selectNodeAndWaitForStyles("other", step3);
+        InspectorTest.addResult("=== Middle property ===");
+        testAddProperty("margin-right: 1px", 1, InspectorTest.completeTest.bind(InspectorTest));
     }
 
-    function step3()
+    function testAddProperty(propertyText, index, callback)
     {
-        InspectorTest.addResult("After undo");
+
+        InspectorTest.addResult("(Initial value)");
         InspectorTest.dumpSelectedElementStyles(true);
 
-        WebInspector.domAgent.redo();
-        InspectorTest.selectNodeAndWaitForStyles("container", step4);
-    }
+        var treeItem = InspectorTest.getMatchedStylePropertyTreeItem("font-weight");
+        var treeElement = treeItem.section.addNewBlankProperty(index);
+        treeElement.applyStyleText(propertyText, true, true);
+        InspectorTest.waitForStyles("container", step1);
 
-    function step4()
-    {
-        InspectorTest.addResult("After redo");
-        InspectorTest.dumpSelectedElementStyles(true);
-        InspectorTest.completeTest();
+        function step1()
+        {
+            InspectorTest.addResult("(After adding property)");
+            InspectorTest.dumpSelectedElementStyles(true);
+
+            WebInspector.domAgent.undo();
+            InspectorTest.selectNodeAndWaitForStyles("other", step2);
+        }
+
+        function step2()
+        {
+            InspectorTest.addResult("(After undo)");
+            InspectorTest.dumpSelectedElementStyles(true);
+
+            WebInspector.domAgent.redo();
+            InspectorTest.selectNodeAndWaitForStyles("container", step3);
+        }
+
+        function step3()
+        {
+            InspectorTest.addResult("(After redo)");
+            InspectorTest.dumpSelectedElementStyles(true);
+            callback();
+        }
     }
 }
 </script>

Modified: trunk/Source/WebCore/ChangeLog (108994 => 108995)


--- trunk/Source/WebCore/ChangeLog	2012-02-27 15:49:04 UTC (rev 108994)
+++ trunk/Source/WebCore/ChangeLog	2012-02-27 16:36:53 UTC (rev 108995)
@@ -1,3 +1,24 @@
+2012-02-27  Alexander Pavlov  <apav...@chromium.org>
+
+        Web Inspector: [Styles] Allow adding CSS properties anywhere in the style declaration, not only at the end
+        https://bugs.webkit.org/show_bug.cgi?id=79662
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/front-end/CSSStyleModel.js:
+        (WebInspector.CSSStyleDeclaration.prototype.newBlankProperty):
+        (WebInspector.CSSProperty.prototype.setText):
+        (WebInspector.CSSProperty.prototype.setValue):
+        * inspector/front-end/MetricsSidebarPane.js:
+        (WebInspector.MetricsSidebarPane.prototype._applyUserInput):
+        * inspector/front-end/StylesSidebarPane.js:
+        (WebInspector.StylePropertiesSection):
+        (WebInspector.StylePropertiesSection.prototype._handleSelectorContainerClick):
+        (WebInspector.StylePropertiesSection.prototype.addNewBlankProperty):
+        (WebInspector.StylePropertyTreeElement.prototype):
+        (WebInspector.StylePropertyTreeElement.prototype.element.userInput.previousContent.context.moveDirection):
+        (WebInspector.StylePropertyTreeElement.prototype.styleText.updateInterface.majorChange.isRevert):
+
 2012-02-27  Pavel Feldman  <pfeld...@google.com>
 
         [Shadow]: Expose one ShadowRoot in the Elements panel (under experiment flag)

Modified: trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js (108994 => 108995)


--- trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js	2012-02-27 15:49:04 UTC (rev 108994)
+++ trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js	2012-02-27 16:36:53 UTC (rev 108995)
@@ -478,9 +478,13 @@
         return 0;
     },
 
-    newBlankProperty: function()
+    /**
+     * @param {number=} index
+     */
+    newBlankProperty: function(index)
     {
-        return new WebInspector.CSSProperty(this, this.pastLastSourcePropertyIndex(), "", "", "", "active", true, false, false, "");
+        index = (typeof index === "undefined") ? this.pastLastSourcePropertyIndex() : index;
+        return new WebInspector.CSSProperty(this, index, "", "", "", "active", true, false, false, "");
     },
 
     insertPropertyAt: function(index, name, value, userCallback)
@@ -619,8 +623,15 @@
         return this.status === "disabled";
     },
 
-    // Replaces "propertyName: propertyValue [!important];" in the stylesheet by an arbitrary propertyText.
-    setText: function(propertyText, majorChange, userCallback)
+    /**
+     * Replaces "propertyName: propertyValue [!important];" in the stylesheet by an arbitrary propertyText.
+     *
+     * @param {string} propertyText
+     * @param {boolean} majorChange
+     * @param {boolean} overwrite
+     * @param {Function=} userCallback
+     */
+    setText: function(propertyText, majorChange, overwrite, userCallback)
     {
         function enabledCallback(style)
         {
@@ -656,13 +667,19 @@
 
         // An index past all the properties adds a new property to the style.
         WebInspector.cssModel._pendingCommandsMajorState.push(majorChange);
-        CSSAgent.setPropertyText(this.ownerStyle.id, this.index, propertyText, this.index < this.ownerStyle.pastLastSourcePropertyIndex(), callback.bind(this));
+        CSSAgent.setPropertyText(this.ownerStyle.id, this.index, propertyText, overwrite, callback.bind(this));
     },
 
-    setValue: function(newValue, majorChange, userCallback)
+    /**
+     * @param {string} newValue
+     * @param {boolean} majorChange
+     * @param {boolean} overwrite
+     * @param {Function=} userCallback
+     */
+    setValue: function(newValue, majorChange, overwrite, userCallback)
     {
         var text = this.name + ": " + newValue + (this.priority ? " !" + this.priority : "") + ";"
-        this.setText(text, majorChange, userCallback);
+        this.setText(text, majorChange, overwrite, userCallback);
     },
 
     setDisabled: function(disabled, userCallback)

Modified: trunk/Source/WebCore/inspector/front-end/MetricsSidebarPane.js (108994 => 108995)


--- trunk/Source/WebCore/inspector/front-end/MetricsSidebarPane.js	2012-02-27 15:49:04 UTC (rev 108994)
+++ trunk/Source/WebCore/inspector/front-end/MetricsSidebarPane.js	2012-02-27 16:36:53 UTC (rev 108995)
@@ -443,7 +443,7 @@
                 continue;
 
             this.previousPropertyDataCandidate = property;
-            property.setValue(userInput, commitEditor, callback);
+            property.setValue(userInput, commitEditor, true, callback);
             return;
         }
 

Modified: trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js (108994 => 108995)


--- trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2012-02-27 15:49:04 UTC (rev 108994)
+++ trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2012-02-27 16:36:53 UTC (rev 108995)
@@ -967,6 +967,7 @@
     var openBrace = document.createElement("span");
     openBrace.textContent = " {";
     selectorContainer.appendChild(openBrace);
+    selectorContainer.addEventListener("click", this._handleSelectorContainerClick.bind(this), false);
 
     var closeBrace = document.createElement("div");
     closeBrace.textContent = "}";
@@ -996,6 +997,7 @@
     this._selectorRefElement.appendChild(this._createRuleOriginNode());
     selectorContainer.insertBefore(this._selectorRefElement, selectorContainer.firstChild);
     this.titleElement.appendChild(selectorContainer);
+    this._selectorContainer = selectorContainer;
 
     if (isInherited)
         this.element.addStyleClass("show-inherited"); // This one is related to inherited rules, not compted style.
@@ -1162,15 +1164,22 @@
         return null;
     },
 
+    _handleSelectorContainerClick: function(event)
+    {
+        if (event.target === this._selectorContainer)
+            this.addNewBlankProperty(0).startEditing();
+    },
+
     /**
-     * @param {number=} optionalIndex
+     * @param {number=} index
      */
-    addNewBlankProperty: function(optionalIndex)
+    addNewBlankProperty: function(index)
     {
         var style = this.styleRule.style;
-        var property = style.newBlankProperty();
+        var property = style.newBlankProperty(index);
         var item = new WebInspector.StylePropertyTreeElement(this, this._parentPane, this.styleRule, style, property, false, false, false);
-        this.propertiesTreeOutline.appendChild(item);
+        index = property.index;
+        this.propertiesTreeOutline.insertChild(item, index);
         item.listItemElement.textContent = "";
         item._newProperty = true;
         item.updateTitle();
@@ -1994,9 +2003,15 @@
 
     _startEditing: function(event)
     {
-        this.startEditing(event.target);
         event.stopPropagation();
         event.preventDefault();
+
+        if (event.target === this.listItemElement) {
+            this.section.addNewBlankProperty(this.property.index + 1).startEditing();
+            return;
+        }
+
+        this.startEditing(event.target);
     },
 
     _isNameElement: function(element)
@@ -2233,6 +2248,16 @@
         }
     },
 
+    _findSibling: function(moveDirection)
+    {
+        var target = this;
+        do {
+            target = (moveDirection === "forward" ? target.nextSibling : target.previousSibling);
+        } while(target && target.inherited);
+
+        return target;
+    },
+
     editingCommitted: function(element, userInput, previousContent, context, moveDirection)
     {
         this._removePrompt();
@@ -2245,10 +2270,7 @@
         var moveToOther = (isEditingName ^ (moveDirection === "forward"));
         var abandonNewProperty = this._newProperty && !userInput && (moveToOther || isEditingName);
         if (moveDirection === "forward" && !isEditingName || moveDirection === "backward" && isEditingName) {
-            do {
-                moveTo = (moveDirection === "forward" ? moveTo.nextSibling : moveTo.previousSibling);
-            } while(moveTo && moveTo.inherited);
-
+            moveTo = moveTo._findSibling(moveDirection);
             if (moveTo)
                 moveToPropertyName = moveTo.name;
             else if (moveDirection === "forward" && (!this._newProperty || userInput))
@@ -2322,7 +2344,8 @@
             }
 
             if (abandonNewProperty) {
-                var sectionToEdit = moveDirection === "backward" ? section : section.nextEditableSibling();
+                moveTo = this._findSibling(moveDirection);
+                var sectionToEdit = (moveTo || moveDirection === "backward") ? section : section.nextEditableSibling();
                 if (sectionToEdit) {
                     if (sectionToEdit.rule)
                         sectionToEdit.startEditingSelector();
@@ -2401,6 +2424,8 @@
                 return;
             }
 
+            if (this._newProperty)
+                this._newPropertyInStyle = true;
             this.style = newStyle;
             this.property = newStyle.propertyAt(this.property.index);
             this._styleRule.style = this.style;
@@ -2420,7 +2445,8 @@
         // FIXME: this does not handle trailing comments.
         if (styleText.length && !/;\s*$/.test(styleText))
             styleText += ";";
-        this.property.setText(styleText, majorChange, callback.bind(this, userOperationFinishedCallback.bind(null, this._parentPane, updateInterface), this.originalPropertyText));
+        var overwriteProperty = !!(!this._newProperty || this._newPropertyInStyle);
+        this.property.setText(styleText, majorChange, overwriteProperty, callback.bind(this, userOperationFinishedCallback.bind(null, this._parentPane, updateInterface), this.originalPropertyText));
     },
 
     ondblclick: function()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to