B2G/gecko/browser/devtools/styleinspector/CssLogic.jsm
/**
   * Retrieve specificity information for the current selector.
   *
   * @see http://www.w3.org/TR/css3-selectors/#specificity
   * @see http://www.w3.org/TR/CSS2/selector.html
   *
   * @return {object} an object holding specificity information for the current
   * selector.
   */
Retrieve specificity information for the current selector.

@return {object} an object holding specificity information for the current
selector.
Retrieve specificity information for the current selector . @return { object } an object holding specificity information for the current selector .
get specificity()
  {
    if (this._specificity) {
      return this._specificity;
    }
    let specificity = {
      ids: 0,
      classes: 0,
      tags: 0
    };
    let text = this.text;
    if (!this.elementStyle) {
      text = text.replace(RX_UNIVERSAL_SELECTOR, "");
      text = text.replace(RX_NOT, " $1");
      text = text.replace(RX_PSEUDO_CLASS_OR_ELT, " $1)");
      text = text.replace(RX_CONNECTORS, " ");
      text.split(/\s/).forEach(function(aSimple) {
        aSimple = aSimple.replace(RX_ID, function() {
          specificity.ids++;
          return "";
        });
        aSimple = aSimple.replace(RX_CLASS_OR_ATTRIBUTE, function() {
          specificity.classes++;
          return "";
        });
        aSimple = aSimple.replace(RX_PSEUDO, function(aDummy, aPseudoName) {
          if (this.pseudoElements.has(aPseudoName)) {
            specificity.tags++;
          } else {
            specificity.classes++;
          }
          return "";
        }.bind(this));
        if (aSimple) {
          specificity.tags++;
        }
      }, this);
    }
    this._specificity = specificity;
    return this._specificity;
  }
get specificity ( ) { if ( this . _specificity ) { return this . _specificity ; } let specificity = { ids : 0 , classes : 0 , tags : 0 } ; let text = this . text ; if ( ! this . elementStyle ) { text = text . replace ( RX_UNIVERSAL_SELECTOR , "" ) ; text = text . replace ( RX_NOT , " $1" ) ; text = text . replace ( RX_PSEUDO_CLASS_OR_ELT , " $1)" ) ; text = text . replace ( RX_CONNECTORS , " " ) ; text . split ( / \s / ) . forEach ( function ( aSimple ) { aSimple = aSimple . replace ( RX_ID , function ( ) { specificity . ids ++ ; return "" ; } ) ; aSimple = aSimple . replace ( RX_CLASS_OR_ATTRIBUTE , function ( ) { specificity . classes ++ ; return "" ; } ) ; aSimple = aSimple . replace ( RX_PSEUDO , function ( aDummy , aPseudoName ) { if ( this . pseudoElements . has ( aPseudoName ) ) { specificity . tags ++ ; } else { specificity . classes ++ ; } return "" ; } . bind ( this ) ) ; if ( aSimple ) { specificity . tags ++ ; } } , this ) ; } this . _specificity = specificity ; return this . _specificity ; }
Retrieve specificity information for the current selector.
Retrieve specificity information for the current selector .
// Remove universal selectors as they are not relevant as far as specificity // is concerned. // not() is ignored but any selectors contained by it are counted. Let's // remove the not() and keep the contents. // Simplify remaining psuedo classes & elements. // Replace connectors with spaces // Count IDs. // Count class names and attribute matchers. // Pseudo elements count as tags. // Pseudo classes count as classes.