Bug 1225254 - remove unused code from css-logic.js; r?pbro draft
authorTom Tromey <tom@tromey.com>
Thu, 23 Jun 2016 11:02:56 -0600
changeset 382473 a263ae844dd266bbb79c487dcfc885954c4925fe
parent 381565 3c55e34b5259d9e656f93b18f2aebe46af09a732
child 382474 6ea3ef30659f8e09fc3495f8606c33b733bd53c7
push id21728
push userbmo:ttromey@mozilla.com
push dateWed, 29 Jun 2016 18:24:58 +0000
reviewerspbro
bugs1225254
milestone50.0a1
Bug 1225254 - remove unused code from css-logic.js; r?pbro MozReview-Commit-ID: joVchP4T56
devtools/server/tests/mochitest/chrome.ini
devtools/server/tests/mochitest/test_css-logic-inheritance.html
devtools/shared/inspector/css-logic.js
--- a/devtools/server/tests/mochitest/chrome.ini
+++ b/devtools/server/tests/mochitest/chrome.ini
@@ -24,17 +24,16 @@ support-files =
   setup-in-parent.js
 
 [test_animation_actor-lifetime.html]
 [test_connection-manager.html]
 skip-if = buildapp == 'mulet'
 [test_connectToChild.html]
 skip-if = buildapp == 'mulet'
 [test_css-logic.html]
-[test_css-logic-inheritance.html]
 [test_css-logic-media-queries.html]
 [test_css-logic-specificity.html]
 [test_css-properties.html]
 [test_Debugger.Source.prototype.introductionScript.html]
 [test_Debugger.Source.prototype.introductionType.html]
 [test_Debugger.Source.prototype.element.html]
 [test_Debugger.Script.prototype.global.html]
 [test_device.html]
deleted file mode 100644
--- a/devtools/server/tests/mochitest/test_css-logic-inheritance.html
+++ /dev/null
@@ -1,46 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-Test that css-logic handles inherited properties correctly
--->
-<head>
-  <meta charset="utf-8">
-  <title>Test css-logic inheritance</title>
-  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
-</head>
-<body>
-  <div style="margin-left:10px; font-size: 5px">
-    <div id="innerdiv">Inner div</div>
-  </div>
-  <script type="application/javascript;version=1.8">
-
-  window.onload = function() {
-    var { classes: Cc, utils: Cu, interfaces: Ci } = Components;
-    const DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"]
-      .getService(Ci.inIDOMUtils);
-
-    const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
-    var Services = require("Services");
-    const {CssLogic} = require("devtools/shared/inspector/css-logic");
-
-
-    SimpleTest.waitForExplicitFinish();
-
-    let cssLogic = new CssLogic(DOMUtils.isInheritedProperty);
-    cssLogic.highlight(document.getElementById("innerdiv"));
-
-    let marginProp = cssLogic.getPropertyInfo("margin-left");
-    is(marginProp.matchedRuleCount, 0,
-      "margin-left should not be included in matched selectors.");
-
-    let fontSizeProp = cssLogic.getPropertyInfo("font-size");
-    is(fontSizeProp.matchedRuleCount, 1,
-      "font-size should be included in matched selectors.");
-
-    SimpleTest.finish();
-  }
-
-  </script>
-</body>
-</html>
--- a/devtools/shared/inspector/css-logic.js
+++ b/devtools/shared/inspector/css-logic.js
@@ -426,34 +426,16 @@ CssLogic.prototype = {
           sheets.splice(i, 1);
           i--;
         }
       }
     }
   },
 
   /**
-   * Process *some* cached stylesheets in the document using your callback. The
-   * callback function should return true in order to halt processing.
-   *
-   * @param {function} callback the function you want executed for some of the
-   * CssSheet objects cached.
-   * @param {object} scope the scope you want for the callback function. scope
-   * will be the this object when callback executes.
-   * @return {Boolean} true if callback returns true during any iteration,
-   * otherwise false is returned.
-   */
-  forSomeSheets: function (callback, scope) {
-    for (let cacheId in this._sheets) {
-      if (this._sheets[cacheId].some(callback, scope)) {
-        return true;
-      }
-    }
-    return false;
-  },
 
   /**
    * Get the number nsIDOMCSSRule objects in the document, counted from all of
    * the stylesheets. System sheets are excluded. If a filter is active, this
    * tells only the number of nsIDOMCSSRule objects inside the selected
    * CSSStyleSheet.
    *
    * WARNING: This only provides an estimate of the rule count, and the results
@@ -696,50 +678,16 @@ CssLogic.getShortName = function (elemen
   let temp = element;
   while ((temp = temp.previousElementSibling)) {
     priorSiblings++;
   }
   return element.tagName + "[" + priorSiblings + "]";
 };
 
 /**
- * Get an array of short names from the given element to document.body.
- *
- * @param {nsIDOMElement} element the element for which you want the array of
- * short names.
- * @return {array} The array of elements.
- * <p>Each element is an object of the form:
- * <ul>
- * <li>{ display: "what to display for the given (parent) element",
- * <li>  element: referenceToTheElement }
- * </ul>
- */
-CssLogic.getShortNamePath = function (element) {
-  let doc = element.ownerDocument;
-  let reply = [];
-
-  if (!element) {
-    return reply;
-  }
-
-  // We want to exclude nodes high up the tree (body/html) unless the user
-  // has selected that node, in which case we need to report something.
-  do {
-    reply.unshift({
-      display: CssLogic.getShortName(element),
-      element: element
-    });
-    element = element.parentNode;
-  } while (element && element != doc.body && element != doc.head &&
-           element != doc);
-
-  return reply;
-};
-
-/**
  * Get a string list of selectors for a given DOMRule.
  *
  * @param {DOMRule} domRule
  *        The DOMRule to parse.
  * @return {Array}
  *         An array of string selectors.
  */
 CssLogic.getSelectors = function (domRule) {
@@ -1181,17 +1129,16 @@ function CssSheet(cssLogic, domSheet, in
   this._rules = {};
 
   this._ruleCount = -1;
 }
 
 CssSheet.prototype = {
   _passId: null,
   _contentSheet: null,
-  _mediaMatches: null,
 
   /**
    * Tells if the stylesheet is provided by the browser or not.
    *
    * @return {boolean} false if this is a browser-provided stylesheet, or true
    * otherwise.
    */
   get contentSheet() {
@@ -1205,28 +1152,16 @@ CssSheet.prototype = {
    * Tells if the stylesheet is disabled or not.
    * @return {boolean} true if this stylesheet is disabled, or false otherwise.
    */
   get disabled() {
     return this.domSheet.disabled;
   },
 
   /**
-   * Tells if the stylesheet matches the current browser view media.
-   * @return {boolean} true if this stylesheet matches the current browser view
-   * media, or false otherwise.
-   */
-  get mediaMatches() {
-    if (this._mediaMatches === null) {
-      this._mediaMatches = this._cssLogic.mediaMatches(this.domSheet);
-    }
-    return this._mediaMatches;
-  },
-
-  /**
    * Get a source for a stylesheet, using CssLogic.href
    *
    * @return {string} the address of the stylesheet.
    */
   get href() {
     if (this._href) {
       return this._href;
     }
@@ -1319,78 +1254,16 @@ CssSheet.prototype = {
 
       rule = new CssRule(this, domRule);
       this._rules[cacheId].push(rule);
     }
 
     return rule;
   },
 
-  /**
-   * Process each rule in this stylesheet using your callback function. Your
-   * function receives one argument: the CssRule object for each CSSStyleRule
-   * inside the stylesheet.
-   *
-   * Note that this method also iterates through @media rules inside the
-   * stylesheet.
-   *
-   * @param {function} callback the function you want to execute for each of
-   * the style rules.
-   * @param {object} scope the scope you want for the callback function. scope
-   * will be the this object when callback executes.
-   */
-  forEachRule: function (callback, scope) {
-    let ruleCount = 0;
-    let domRules = this.domSheet.cssRules;
-
-    function _iterator(domRule) {
-      if (domRule.type == CSSRule.STYLE_RULE) {
-        callback.call(scope, this.getRule(domRule));
-        ruleCount++;
-      } else if (domRule.type == CSSRule.MEDIA_RULE &&
-          domRule.cssRules && this._cssLogic.mediaMatches(domRule)) {
-        Array.prototype.forEach.call(domRule.cssRules, _iterator, this);
-      }
-    }
-
-    Array.prototype.forEach.call(domRules, _iterator, this);
-
-    this._ruleCount = ruleCount;
-  },
-
-  /**
-   * Process *some* rules in this stylesheet using your callback function. Your
-   * function receives one argument: the CssRule object for each CSSStyleRule
-   * inside the stylesheet. In order to stop processing the callback function
-   * needs to return a value.
-   *
-   * Note that this method also iterates through @media rules inside the
-   * stylesheet.
-   *
-   * @param {function} callback the function you want to execute for each of
-   * the style rules.
-   * @param {object} scope the scope you want for the callback function. scope
-   * will be the this object when callback executes.
-   * @return {Boolean} true if callback returns true during any iteration,
-   * otherwise false is returned.
-   */
-  forSomeRules: function (callback, scope) {
-    let domRules = this.domSheet.cssRules;
-    function _iterator(domRule) {
-      if (domRule.type == CSSRule.STYLE_RULE) {
-        return callback.call(scope, this.getRule(domRule));
-      } else if (domRule.type == CSSRule.MEDIA_RULE &&
-          domRule.cssRules && this._cssLogic.mediaMatches(domRule)) {
-        return Array.prototype.some.call(domRule.cssRules, _iterator, this);
-      }
-      return false;
-    }
-    return Array.prototype.some.call(domRules, _iterator, this);
-  },
-
   toString: function () {
     return "CssSheet[" + this.shortSource + "]";
   }
 };
 
 /**
  * Information about a single CSSStyleRule.
  *
@@ -1657,20 +1530,16 @@ CssSelector.prototype = {
  * @constructor
  */
 function CssPropertyInfo(cssLogic, property, isInherited) {
   this._cssLogic = cssLogic;
   this.property = property;
   this._value = "";
   this._isInherited = isInherited;
 
-  // The number of matched rules holding the this.property style property.
-  // Additionally, only rules that come from allowed stylesheets are counted.
-  this._matchedRuleCount = 0;
-
   // An array holding CssSelectorInfo objects for each of the matched selectors
   // that are inside a CSS rule. Only rules that hold the this.property are
   // counted. This includes rules that come from filtered stylesheets (those
   // that have sheetAllowed = false).
   this._matchedSelectors = null;
 }
 
 CssPropertyInfo.prototype = {
@@ -1690,32 +1559,16 @@ CssPropertyInfo.prototype = {
         console.log("Error reading computed style for " + this.property);
         console.log(ex);
       }
     }
     return this._value;
   },
 
   /**
-   * Retrieve the number of matched rules holding the this.property style
-   * property. Only rules that come from allowed stylesheets are counted.
-   *
-   * @return {number} the number of matched rules.
-   */
-  get matchedRuleCount() {
-    if (!this._matchedSelectors) {
-      this._findMatchedSelectors();
-    } else if (this.needRefilter) {
-      this._refilterSelectors();
-    }
-
-    return this._matchedRuleCount;
-  },
-
-  /**
    * Retrieve the array holding CssSelectorInfo objects for each of the matched
    * selectors, from each of the matched rules. Only selectors coming from
    * allowed stylesheets are included in the array.
    *
    * @return {array} the list of CssSelectorInfo objects of selectors that match
    * the highlighted element and its parents.
    */
   get matchedSelectors() {
@@ -1732,17 +1585,16 @@ CssPropertyInfo.prototype = {
    * Find the selectors that match the highlighted element and its parents.
    * Uses CssLogic.processMatchedSelectors() to find the matched selectors,
    * passing in a reference to CssPropertyInfo._processMatchedSelector() to
    * create CssSelectorInfo objects, which we then sort
    * @private
    */
   _findMatchedSelectors: function () {
     this._matchedSelectors = [];
-    this._matchedRuleCount = 0;
     this.needRefilter = false;
 
     this._cssLogic.processMatchedSelectors(this._processMatchedSelector, this);
 
     // Sort the selectors by how well they match the given element.
     this._matchedSelectors.sort(function (selectorInfo1, selectorInfo2) {
       if (selectorInfo1.status > selectorInfo2.status) {
         return -1;
@@ -1771,19 +1623,16 @@ CssPropertyInfo.prototype = {
     let value = cssRule.getPropertyValue(this.property);
     if (value &&
         (status == CssLogic.STATUS.MATCHED ||
          (status == CssLogic.STATUS.PARENT_MATCH &&
           this._isInherited(this.property)))) {
       let selectorInfo = new CssSelectorInfo(selector, this.property, value,
           status);
       this._matchedSelectors.push(selectorInfo);
-      if (this._cssLogic._passId !== cssRule._passId && cssRule.sheetAllowed) {
-        this._matchedRuleCount++;
-      }
     }
   },
 
   /**
    * Refilter the matched selectors array when the CssLogic.sourceFilter
    * changes. This allows for quick filter changes.
    * @private
    */
@@ -1798,17 +1647,16 @@ CssPropertyInfo.prototype = {
           ruleCount++;
         }
         cssRule._passId = passId;
       }
     };
 
     if (this._matchedSelectors) {
       this._matchedSelectors.forEach(iterator);
-      this._matchedRuleCount = ruleCount;
     }
 
     this.needRefilter = false;
   },
 
   toString: function () {
     return "CssPropertyInfo[" + this.property + "]";
   },