Bug 1031351 - Don't prettify CSS source if it has more than one line per rule. r=jwalker, a=lmandel
authorHeather Arthur <fayearthur@gmail.com>
Mon, 30 Jun 2014 18:13:00 +0200
changeset 208791 c486eb0414a6e511feee5862bcfb3d5a09185471
parent 208790 04559e01d82026889ca7faa549f3be1d9f05af23
child 208792 261407ec0ea7873966f256b6adbb6324f4ceb2de
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalker, lmandel
bugs1031351
milestone32.0a2
Bug 1031351 - Don't prettify CSS source if it has more than one line per rule. r=jwalker, a=lmandel
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
@@ -221,17 +221,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
@@ -932,25 +932,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;