Bug 1031351 - Don't prettify CSS source if it has more than one line per rule. r=jwalker
authorHeather Arthur <fayearthur@gmail.com>
Mon, 30 Jun 2014 18:13:00 +0200
changeset 191868 0438007c97a2a8fc03927e0fa115230d0e717451
parent 191867 e4bb377a4b86bd282ca430a4987fe4b0bd301565
child 191869 480d3f283c9df4663081d530dfdeac99828aa9da
push id45685
push usercbook@mozilla.com
push dateWed, 02 Jul 2014 13:09:48 +0000
treeherdermozilla-inbound@60133a85f8ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalker
bugs1031351
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1031351 - Don't prettify CSS source if it has more than one line per rule. r=jwalker
browser/devtools/styleeditor/StyleSheetEditor.jsm
browser/devtools/styleeditor/test/browser_styleeditor_pretty.js
browser/devtools/styleeditor/test/pretty.css
toolkit/devtools/styleinspector/css-logic.js
--- a/browser/devtools/styleeditor/StyleSheetEditor.jsm
+++ b/browser/devtools/styleeditor/StyleSheetEditor.jsm
@@ -220,17 +220,18 @@ StyleSheetEditor.prototype = {
   },
 
   /**
    * Start fetching the full text source for this editor's sheet.
    */
   fetchSource: function(callback) {
     return this.styleSheet.getText().then((longStr) => {
       longStr.string().then((source) => {
-        this._state.text = CssLogic.prettifyCSS(source);
+        let ruleCount = this.styleSheet.ruleCount;
+        this._state.text = CssLogic.prettifyCSS(source, ruleCount);
         this.sourceLoaded = true;
 
         if (callback) {
           callback(source);
         }
         return source;
       });
     }, e => {
--- a/browser/devtools/styleeditor/test/browser_styleeditor_pretty.js
+++ b/browser/devtools/styleeditor/test/browser_styleeditor_pretty.js
@@ -18,17 +18,17 @@ function test()
 
   content.location = TESTCASE_URI;
 }
 
 let editorTestedCount = 0;
 function testEditor(aEditor)
 {
   if (aEditor.styleSheet.styleSheetIndex == 0) {
-    let prettifiedSource = "body\{\r?\n\tbackground\:white;\r?\n\}\r?\n\r?\ndiv\{\r?\n\tfont\-size\:4em;\r?\n\tcolor\:red\r?\n\}\r?\n";
+    let prettifiedSource = "body\{\r?\n\tbackground\:white;\r?\n\}\r?\n\r?\ndiv\{\r?\n\tfont\-size\:4em;\r?\n\tcolor\:red\r?\n\}\r?\n\r?\nspan\{\r?\n\tcolor\:green;\r?\n\}\r?\n";
     let prettifiedSourceRE = new RegExp(prettifiedSource);
 
     ok(prettifiedSourceRE.test(aEditor.sourceEditor.getText()),
        "minified source has been prettified automatically");
     editorTestedCount++;
     let summary = gUI.editors[1].summary;
     EventUtils.synthesizeMouseAtCenter(summary, {}, gPanelWindow);
   }
--- a/browser/devtools/styleeditor/test/pretty.css
+++ b/browser/devtools/styleeditor/test/pretty.css
@@ -1,5 +1,2 @@
 
-
-body{background:white;}div{font-size:4em;color:red}
-
-
+body{background:white;}div{font-size:4em;color:red}span{color:green;}
--- a/toolkit/devtools/styleinspector/css-logic.js
+++ b/toolkit/devtools/styleinspector/css-logic.js
@@ -896,25 +896,31 @@ const TAB_CHARS = "\t";
 
 /**
  * Prettify minified CSS text.
  * This prettifies CSS code where there is no indentation in usual places while
  * keeping original indentation as-is elsewhere.
  * @param string text The CSS source to prettify.
  * @return string Prettified CSS source
  */
-CssLogic.prettifyCSS = function(text) {
+CssLogic.prettifyCSS = function(text, ruleCount) {
   if (CssLogic.LINE_SEPARATOR == null) {
     let os = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS;
     CssLogic.LINE_SEPARATOR = (os === "WINNT" ? "\r\n" : "\n");
   }
 
   // remove initial and terminating HTML comments and surrounding whitespace
   text = text.replace(/(?:^\s*<!--[\r\n]*)|(?:\s*-->\s*$)/g, "");
 
+  // don't attempt to prettify if there's more than one line per rule.
+  let lineCount = text.split("\n").length - 1;
+  if (ruleCount !== null && lineCount >= ruleCount) {
+    return text;
+  }
+
   let parts = [];    // indented parts
   let partStart = 0; // start offset of currently parsed part
   let indent = "";
   let indentLevel = 0;
 
   for (let i = 0; i < text.length; i++) {
     let c = text[i];
     let shouldIndent = false;