Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Issue 5850: Modifying CSS doesn't update element visibility in HTML p…

  • Loading branch information...
commit e4c3e0ef54b1361d0ed1e1bdbf73343cb46835d2 1 parent 8f0a4d5
@simonlindholm simonlindholm authored
View
14 extension/content/firebug/css/cssModule.js
@@ -10,9 +10,10 @@ define([
"firebug/chrome/window",
"firebug/lib/xml",
"firebug/lib/options",
- "firebug/lib/array"
+ "firebug/lib/array",
+ "firebug/editor/editorSelector"
],
-function(Obj, Firebug, Xpcom, Events, Url, Css, Win, Xml, Options, Arr) {
+function(Obj, Firebug, Xpcom, Events, Url, Css, Win, Xml, Options, Arr, EditorSelector) {
// ********************************************************************************************* //
// Constants
@@ -89,9 +90,10 @@ Firebug.CSSModule = Obj.extend(Firebug.Module, Firebug.EditorSelector,
deleteRule: function(src, ruleIndex)
{
+ var inlineStyle = (src instanceof window.Element);
if (FBTrace.DBG_CSS)
{
- if (src instanceof window.Element)
+ if (inlineStyle)
{
FBTrace.sysout("deleteRule: element.style", src);
}
@@ -102,12 +104,18 @@ Firebug.CSSModule = Obj.extend(Firebug.Module, Firebug.EditorSelector,
}
}
+ var rule = (inlineStyle ? src : src.cssRules[ruleIndex]);
+ var afterParams = [src, rule.style.cssText];
+ afterParams.push(inlineStyle ? "" : rule.selectorText);
+
Events.dispatch(this.fbListeners, "onCSSDeleteRule", [src, ruleIndex]);
if (src instanceof window.Element)
src.removeAttribute("style");
else
src.deleteRule(ruleIndex);
+
+ Events.dispatch(this.fbListeners, "onAfterCSSDeleteRule", afterParams);
},
setProperty: function(rule, propName, propValue, propPriority)
View
73 extension/content/firebug/html/htmlPanel.js
@@ -20,6 +20,7 @@ define([
"firebug/lib/persist",
"firebug/chrome/menu",
"firebug/lib/url",
+ "firebug/css/cssModule",
"firebug/css/cssReps",
"firebug/js/breakpoint",
"firebug/editor/editor",
@@ -30,7 +31,7 @@ define([
],
function(Obj, Firebug, Domplate, FirebugReps, Locale, HTMLLib, Events,
SourceLink, Css, Dom, Win, Options, Xpath, Str, Xml, Arr, Persist, Menu,
- Url, CSSInfoTip) {
+ Url, CSSModule, CSSInfoTip) {
with (Domplate) {
@@ -1182,6 +1183,74 @@ Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+ // CSS Listener
+
+ updateVisibilitiesForSelectorInSheet: function(sheet, selector)
+ {
+ if (!selector)
+ return;
+ var doc = (sheet && sheet.ownerNode && sheet.ownerNode.ownerDocument);
+ if (!doc)
+ return;
+
+ var affected = doc.querySelectorAll(selector);
+ if (!affected.length || !this.ioBox.isInExistingRoot(affected[0]))
+ return;
+
+ for (var i = 0; i < affected.length; ++i)
+ {
+ var node = this.ioBox.findObjectBox(affected[i]);
+ if (node)
+ this.updateNodeVisibility(node);
+ }
+ },
+
+ updateVisibilitiesForRule: function(rule)
+ {
+ this.updateVisibilitiesForSelectorInSheet(rule.parentStyleSheet, rule.selectorText);
+ },
+
+ cssPropAffectsVisibility: function(propName)
+ {
+ // Pretend that "display" is the only property which affects visibility,
+ // which is a half-truth. We could make this more technically correct
+ // by unconditionally returning true, but forcing a synchronous reflow
+ // and computing offsetWidth/Height on up to every element on the page
+ // isn't worth it.
+ return (propName === "display");
+ },
+
+ cssTextAffectsVisibility: function(cssText)
+ {
+ return (cssText.indexOf("display:") !== -1);
+ },
+
+ onAfterCSSDeleteRule: function(styleSheet, cssText, selector)
+ {
+ if (this.cssTextAffectsVisibility(cssText))
+ this.updateVisibilitiesForSelectorInSheet(styleSheet, selector);
+ },
+
+ onCSSInsertRule: function(styleSheet, cssText, ruleIndex)
+ {
+ if (this.cssTextAffectsVisibility(cssText))
+ this.updateVisibilitiesForRule(styleSheet.cssRules[ruleIndex]);
+ },
+
+ onCSSSetProperty: function(style, propName, propValue, propPriority, prevValue,
+ prevPriority, rule, baseText)
+ {
+ if (this.cssPropAffectsVisibility(propName))
+ this.updateVisibilitiesForRule(rule);
+ },
+
+ onCSSRemoveProperty: function(style, propName, prevValue, prevPriority, rule, baseText)
+ {
+ if (this.cssPropAffectsVisibility(propName))
+ this.updateVisibilitiesForRule(rule);
+ },
+
+ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// extends Panel
name: "html",
@@ -1202,6 +1271,7 @@ Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
this.onKeyPress = Obj.bind(this.onKeyPress, this);
Firebug.Panel.initialize.apply(this, arguments);
+ Firebug.CSSModule.addListener(this);
},
destroy: function(state)
@@ -1220,6 +1290,7 @@ Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
delete this.inspectorHistory[i];
delete this.inspectorHistory;
+ Firebug.CSSModule.removeListener(this);
this.unregisterMutationListeners();
},

0 comments on commit e4c3e0e

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