REGRESSION(r184000): Web Inspector: Multiline CSS in Styles Sidebar is marked as invalid
https://bugs.webkit.org/show_bug.cgi?id=146178

Reviewed by Timothy Hatcher.

First changes made by Tobias Reiss  <tobi+webkit@basecode.de>

* Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-values-expected.css: Added.
* Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-values.css: Added.
* Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-rules-expected.css: Added.
* Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-rules.css: Added.
* Tools/PrettyPrinting/css-rule-tests/remove-newline-between-values-expected.css: Added.
* Tools/PrettyPrinting/css-rule-tests/remove-newline-between-values.css: Added.
* Tools/PrettyPrinting/index.html:
Add regression tests.
* UserInterface/Views/CodeMirrorFormatters.js:
Remove newlines before values that belong in one line and add whitespace between values.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@186281 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebInspectorUI/ChangeLog b/Source/WebInspectorUI/ChangeLog
index f2395ec..2d78f8b 100644
--- a/Source/WebInspectorUI/ChangeLog
+++ b/Source/WebInspectorUI/ChangeLog
@@ -1,3 +1,23 @@
+2015-07-04  Devin Rousso  <drousso@apple.com>
+
+        REGRESSION(r184000): Web Inspector: Multiline CSS in Styles Sidebar is marked as invalid
+        https://bugs.webkit.org/show_bug.cgi?id=146178
+
+        Reviewed by Timothy Hatcher.
+
+        First changes made by Tobias Reiss  <tobi+webkit@basecode.de>
+
+        * Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-values-expected.css: Added.
+        * Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-values.css: Added.
+        * Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-rules-expected.css: Added.
+        * Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-rules.css: Added.
+        * Tools/PrettyPrinting/css-rule-tests/remove-newline-between-values-expected.css: Added.
+        * Tools/PrettyPrinting/css-rule-tests/remove-newline-between-values.css: Added.
+        * Tools/PrettyPrinting/index.html:
+        Add regression tests.
+        * UserInterface/Views/CodeMirrorFormatters.js:
+        Remove newlines before values that belong in one line and add whitespace between values. 
+
 2015-07-04  Nikita Vasilyev  <nvasilyev@apple.com>
 
         Web Inspector: The arrow that appears for Web Inspector Layout & Rendering records overlaps the category switcher
diff --git a/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-rules-expected.css b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-rules-expected.css
new file mode 100644
index 0000000..8a7109d
--- /dev/null
+++ b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-rules-expected.css
@@ -0,0 +1,3 @@
+color: red;
+margin: auto;
+background-color: rgba(0, 0, 0, 0.5);
diff --git a/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-rules.css b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-rules.css
new file mode 100644
index 0000000..35ca4cb
--- /dev/null
+++ b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-rules.css
@@ -0,0 +1 @@
+color:red;margin:auto;background-color:rgba(0,0,0,0.5);
\ No newline at end of file
diff --git a/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-values-expected.css b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-values-expected.css
new file mode 100644
index 0000000..b0071fd
--- /dev/null
+++ b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-values-expected.css
@@ -0,0 +1 @@
+border: 1px solid black;
diff --git a/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-values.css b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-values.css
new file mode 100644
index 0000000..9d459b9
--- /dev/null
+++ b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/add-whitespace-between-values.css
@@ -0,0 +1,6 @@
+border
+:
+1px
+solid
+black
+;
\ No newline at end of file
diff --git a/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/remove-newline-between-values-expected.css b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/remove-newline-between-values-expected.css
new file mode 100644
index 0000000..45cb933
--- /dev/null
+++ b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/remove-newline-between-values-expected.css
@@ -0,0 +1 @@
+background: repeating-radial-gradient(circle, purple, purple 10px, #4b026f 10px, #4b026f 20px);
diff --git a/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/remove-newline-between-values.css b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/remove-newline-between-values.css
new file mode 100644
index 0000000..1aa9ef1
--- /dev/null
+++ b/Source/WebInspectorUI/Tools/PrettyPrinting/css-rule-tests/remove-newline-between-values.css
@@ -0,0 +1,7 @@
+background: repeating-radial-gradient(
+    circle,
+    purple,
+    purple 10px,
+    #4b026f 10px,
+    #4b026f 20px
+);
\ No newline at end of file
diff --git a/Source/WebInspectorUI/Tools/PrettyPrinting/index.html b/Source/WebInspectorUI/Tools/PrettyPrinting/index.html
index e3bfc93..4112f84 100644
--- a/Source/WebInspectorUI/Tools/PrettyPrinting/index.html
+++ b/Source/WebInspectorUI/Tools/PrettyPrinting/index.html
@@ -248,6 +248,7 @@
     function runCssRuleTests(callback) {
         _runTests(callback, [
             "css-rule-tests/invalid-property-is-not-removed.css",
+            "css-rule-tests/remove-newline-between-values.css",
             "css-rule-tests/remove-whitespace-before-colon.css",
             "css-rule-tests/remove-whitespace-before-semicolon.css",
             "css-rule-tests/remove-whitespace-before-property.css",
@@ -267,6 +268,8 @@
             "css-rule-tests/split-invalid-property-followed-by-invalid-property.css",
             "css-rule-tests/split-invalid-property-followed-by-comment.css",
             "css-rule-tests/split-property-without-semicolon-followed-by-comment-and-property.css",
+            "css-rule-tests/add-whitespace-between-values.css",
+            "css-rule-tests/add-whitespace-between-rules.css",
             "css-rule-tests/add-whitespace-after-colon.css",
             "css-rule-tests/add-whitespace-after-comma.css",
             "css-rule-tests/do-not-append-semicolon.css",
diff --git a/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js b/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js
index 902f112..960be2f 100644
--- a/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js
+++ b/Source/WebInspectorUI/UserInterface/Views/CodeMirrorFormatters.js
@@ -434,7 +434,15 @@
 CodeMirror.extendMode("css-rule", {
     shouldHaveSpaceBeforeToken: function(lastToken, lastContent, token, state, content, isComment)
     {
-        return lastContent === ":" && !lastToken;
+        // Add whitespace before ":_value"
+        if (lastContent === ":" && !lastToken)
+            return true;
+
+        // Add whitespace between "1px_solid_green"
+        if (lastToken && /\b(?:keyword|atom|number)\b/.test(token))
+            return true;
+
+        return false;
     },
 
     shouldHaveSpaceAfterLastToken: function(lastToken, lastContent, token, state, content, isComment)
@@ -471,7 +479,8 @@
 
     removeLastNewline: function(lastToken, lastContent, token, state, content, isComment, firstTokenOnLine)
     {
-        return false;
+        // Each property should be formatted to one line each with no extra newlines.
+        return true;
     },
 
     indentAfterToken: function(lastToken, lastContent, token, state, content, isComment)