Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Issue 5643: Style disabling confuses rules

  • Loading branch information...
commit c608716c8ec2962ccb3d4129d04eae2322a7f603 1 parent ebc63e6
Simon Lindholm authored
91  extension/content/firebug/css/cssPanel.js
@@ -159,12 +159,12 @@ var CSSStyleRuleTag = domplate(CSSDomplateBase,
159 159
             $insertInto: "$rule|isEditable",
160 160
             $editGroup: "$rule|isSelectorEditable",
161 161
             _repObject: "$rule.rule",
162  
-            "ruleId": "$rule.id", role: "presentation"},
  162
+            role: "presentation"},
163 163
             DIV({"class": "cssHead focusRow", role: "listitem"},
164 164
                 SPAN({"class": "cssSelector", $editable: "$rule|isSelectorEditable"},
165 165
                     "$rule.selector"),
166  
-                    " {"
167  
-                ),
  166
+                " {"
  167
+            ),
168 168
             DIV({role: "group"},
169 169
                 DIV({"class": "cssPropertyListBox", _rule: "$rule", role: "listbox"},
170 170
                     FOR("prop", "$rule.props",
@@ -385,7 +385,7 @@ Firebug.CSSStyleSheetPanel.prototype = Obj.extend(Firebug.Panel,
385 385
         var rules = [];
386 386
         var appendRules = function(cssRules)
387 387
         {
388  
-            var i, props, ruleId;
  388
+            var i, props;
389 389
 
390 390
             if (!cssRules)
391 391
                 return;
@@ -396,14 +396,10 @@ Firebug.CSSStyleSheetPanel.prototype = Obj.extend(Firebug.Panel,
396 396
                 if (rule instanceof window.CSSStyleRule)
397 397
                 {
398 398
                     props = this.getRuleProperties(context, rule);
399  
-                    ruleId = this.getRuleId(rule);
400 399
                     rules.push({
401 400
                         tag: CSSStyleRuleTag.tag,
402 401
                         rule: rule,
403  
-                        id: ruleId,
404  
-                        // Show universal selectors with pseudo-class
405  
-                        // (http://code.google.com/p/fbug/issues/detail?id=3683)
406  
-                        selector: rule.selectorText.replace(/ :/g, " *:"),
  402
+                        selector: rule.selectorText.replace(/ :/g, " *:"), // (issue 3683)
407 403
                         props: props,
408 404
                         isSystemSheet: isSystemSheet,
409 405
                         isSelectorEditable: true
@@ -510,18 +506,18 @@ Firebug.CSSStyleSheetPanel.prototype = Obj.extend(Firebug.Panel,
510 506
     {
511 507
         var props = this.parseCSSProps(rule.style, inheritMode);
512 508
 
513  
-        var ruleId = this.getRuleId(rule);
514  
-        this.addOldProperties(context, ruleId, inheritMode, props);
  509
+        this.addDisabledProperties(context, rule, inheritMode, props);
515 510
         this.sortProperties(props);
516 511
 
517 512
         return props;
518 513
     },
519 514
 
520  
-    addOldProperties: function(context, ruleId, inheritMode, props)
  515
+    addDisabledProperties: function(context, rule, inheritMode, props)
521 516
     {
522  
-        if (context.selectorMap && context.selectorMap.hasOwnProperty(ruleId) )
  517
+        var disabledMap = this.getDisabledMap(context);
  518
+        var moreProps = disabledMap.get(rule);
  519
+        if (moreProps)
523 520
         {
524  
-            var moreProps = context.selectorMap[ruleId];
525 521
             for (var i = 0; i < moreProps.length; ++i)
526 522
             {
527 523
                 var prop = moreProps[i];
@@ -588,6 +584,22 @@ Firebug.CSSStyleSheetPanel.prototype = Obj.extend(Firebug.Panel,
588 584
 
589 585
     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
590 586
 
  587
+    getDisabledMap: function(context)
  588
+    {
  589
+        // Ideally, we'd use a WeakMap here, but WeakMaps don't allow CSS rules
  590
+        // as keys before Firefox 17. A Map is used instead. (cf. bug 777373.)
  591
+        if (!context.cssDisabledMap)
  592
+            context.cssDisabledMap = new Map();
  593
+        return context.cssDisabledMap;
  594
+    },
  595
+
  596
+    remapRule: function(context, oldRule, newRule)
  597
+    {
  598
+        var map = this.getDisabledMap(context);
  599
+        if (map.has(oldRule))
  600
+            map.set(newRule, map.get(oldRule));
  601
+    },
  602
+
591 603
     editElementStyle: function()
592 604
     {
593 605
         var rulesBox = this.panelNode.getElementsByClassName("cssElementRuleContainer")[0];
@@ -721,23 +733,28 @@ Firebug.CSSStyleSheetPanel.prototype = Obj.extend(Firebug.Panel,
721 733
     {
722 734
         var rule = Firebug.getRepObject(row);
723 735
         var propName = Dom.getChildByClass(row, "cssPropName").textContent;
724  
-        CSSModule.deleteProperty(rule, propName, this.context);
725 736
 
726  
-        // Remove the property from the selector map, if it was disabled
727  
-        var ruleId = Firebug.getRepNode(row).getAttribute("ruleId");
728  
-        if ( this.context.selectorMap && this.context.selectorMap.hasOwnProperty(ruleId) )
  737
+        // If the property was disabled, remove it from the relevant map.
  738
+        var didRemoveDisabled = false;
  739
+        var disabledMap = this.getDisabledMap(this.context);
  740
+        var map = disabledMap.get(rule);
  741
+        if (map)
729 742
         {
730  
-            var map = this.context.selectorMap[ruleId];
731 743
             for (var i = 0; i < map.length; ++i)
732 744
             {
733 745
                 if (map[i].name == propName)
734 746
                 {
735 747
                     map.splice(i, 1);
  748
+                    didRemoveDisabled = true;
736 749
                     break;
737 750
                 }
738 751
             }
739 752
         }
740 753
 
  754
+        // Otherwise, remove the actual property.
  755
+        if (!didRemoveDisabled)
  756
+            CSSModule.deleteProperty(rule, propName, this.context);
  757
+
741 758
         if (this.name == "stylesheet")
742 759
             Events.dispatch(this.fbListeners, "onInlineEditorClose", [this, row.firstChild, true]);
743 760
         row.parentNode.removeChild(row);
@@ -752,15 +769,11 @@ Firebug.CSSStyleSheetPanel.prototype = Obj.extend(Firebug.Panel,
752 769
         var rule = Firebug.getRepObject(row);
753 770
         var propName = Dom.getChildByClass(row, "cssPropName").textContent;
754 771
 
755  
-        if (!this.context.selectorMap)
756  
-            this.context.selectorMap = {};
  772
+        var disabledMap = this.getDisabledMap(this.context);
757 773
 
758  
-        // XXXjoe Generate unique key for elements too
759  
-        var ruleId = Firebug.getRepNode(row).getAttribute("ruleId");
760  
-        if (!(this.context.selectorMap.hasOwnProperty(ruleId)))
761  
-            this.context.selectorMap[ruleId] = [];
762  
-
763  
-        var map = this.context.selectorMap[ruleId];
  774
+        if (!disabledMap.has(rule))
  775
+            disabledMap.set(rule, []);
  776
+        var map = disabledMap.get(rule);
764 777
         var propValue = Dom.getChildByClass(row, "cssPropValue").textContent;
765 778
         var parsedValue = parsePriority(propValue);
766 779
 
@@ -1591,16 +1604,6 @@ Firebug.CSSStyleSheetPanel.prototype = Obj.extend(Firebug.Panel,
1591 1604
     {
1592 1605
         var props = this.getStyleDeclaration(cssSelector);
1593 1606
         System.copyToClipboard(props.join(Str.lineBreak()));
1594  
-    },
1595  
-
1596  
-    getRuleId: function(rule)
1597  
-    {
1598  
-        var line = Dom.domUtils.getRuleLine(rule);
1599  
-
1600  
-        // xxxjjb I hope % is invalid in selectortext
1601  
-        const reQuotes = /['"]/g;
1602  
-        var ruleId = rule.selectorText.replace(reQuotes,"%")+"/"+line;
1603  
-        return ruleId;
1604 1607
     }
1605 1608
 });
1606 1609
 
@@ -2175,6 +2178,8 @@ CSSRuleEditor.prototype = domplate(Firebug.InlineEditor.prototype,
2175 2178
 
2176 2179
     saveEdit: function(target, value, previousValue)
2177 2180
     {
  2181
+        var context = this.panel.context;
  2182
+
2178 2183
         if (FBTrace.DBG_CSS)
2179 2184
             FBTrace.sysout("CSSRuleEditor.saveEdit: '" + value + "'  '" + previousValue +
2180 2185
                 "'", target);
@@ -2216,7 +2221,7 @@ CSSRuleEditor.prototype = domplate(Firebug.InlineEditor.prototype,
2216 2221
                 styleSheet = this.panel.location;
2217 2222
                 if (!styleSheet)
2218 2223
                 {
2219  
-                    var doc = this.panel.context.window.document;
  2224
+                    var doc = context.window.document;
2220 2225
                     this.panel.location = styleSheet =
2221 2226
                         CSSModule.getDefaultStyleSheet(doc);
2222 2227
                 }
@@ -2306,14 +2311,8 @@ CSSRuleEditor.prototype = domplate(Firebug.InlineEditor.prototype,
2306 2311
 
2307 2312
         // Update the rep object
2308 2313
         row.repObject = rule;
2309  
-        if (!oldRule)
2310  
-        {
2311  
-            // Who knows what the domutils will return for rule line
2312  
-            // for a recently created rule. To be safe we just generate
2313  
-            // a unique value as this is only used as an internal key.
2314  
-            var ruleId = "new/"+value+"/"+(++CSSRuleEditor.uniquifier);
2315  
-            row.setAttribute("ruleId", ruleId);
2316  
-        }
  2314
+        if (oldRule)
  2315
+            this.panel.remapRule(context, oldRule, rule);
2317 2316
 
2318 2317
         this.panel.markChange(this.panel.name == "stylesheet");
2319 2318
     },
14  extension/content/firebug/css/stylePanel.js
@@ -256,11 +256,9 @@ CSSStylePanel.prototype = Obj.extend(CSSStyleSheetPanel.prototype,
256 256
                 if (!isPseudoElementSheet)
257 257
                     this.markOverriddenProps(element, props, usedProps, inheritMode);
258 258
 
259  
-                var ruleId = this.getRuleId(rule);
260  
-                rules.unshift({rule: rule, id: ruleId,
261  
-                    // Show universal selectors with pseudo-class
262  
-                    // (http://code.google.com/p/fbug/issues/detail?id=3683)
263  
-                    selector: rule.selectorText.replace(/ :/g, " *:"),
  259
+                rules.unshift({
  260
+                    rule: rule,
  261
+                    selector: rule.selectorText.replace(/ :/g, " *:"), // (issue 3683)
264 262
                     sourceLink: sourceLink,
265 263
                     props: props, inherited: inheritMode,
266 264
                     isSystemSheet: isSystemSheet,
@@ -442,7 +440,7 @@ CSSStylePanel.prototype = Obj.extend(CSSStyleSheetPanel.prototype,
442 440
     getStyleProperties: function(element, rules, usedProps, inheritMode)
443 441
     {
444 442
         var props = this.parseCSSProps(element.style, inheritMode);
445  
-        this.addOldProperties(this.context, Xpath.getElementXPath(element), inheritMode, props);
  443
+        this.addDisabledProperties(this.context, element, inheritMode, props);
446 444
 
447 445
         this.sortProperties(props);
448 446
 
@@ -450,8 +448,8 @@ CSSStylePanel.prototype = Obj.extend(CSSStyleSheetPanel.prototype,
450 448
 
451 449
         if (props.length)
452 450
         {
453  
-            rules.unshift({rule: element, id: Xpath.getElementXPath(element),
454  
-                    selector: "element.style", props: props, inherited: inheritMode});
  451
+            rules.unshift({rule: element, selector: "element.style",
  452
+                props: props, inherited: inheritMode});
455 453
         }
456 454
     },
457 455
 

0 notes on commit c608716

Please sign in to comment.
Something went wrong with that request. Please try again.