Permalink
Browse files

Avoid NPE for CSS rules other than CSSStyleRules (followup on issue

5262 and 5277)
  • Loading branch information...
SebastianZ committed Apr 19, 2012
1 parent 4832f20 commit 20a0cc3e0f6360dd29e819fd719a3f7882e8ff93
Showing with 86 additions and 83 deletions.
  1. +86 −83 extension/content/firebug/css/cssPanel.js
@@ -1504,7 +1504,92 @@ CSSEditor.prototype = domplate(Firebug.InlineEditor.prototype,
var rule = Firebug.getRepObject(target);
if (rule instanceof window.CSSImportRule && Css.hasClass(target, "cssMediaQuery"))
if (rule instanceof window.CSSStyleRule)
{
if (Css.hasClass(target, "cssPropName"))
{
if (value && previousValue != value) // name of property has changed.
{
// Record the original CSS text for the inline case so we can reconstruct at a later
// point for diffing purposes
var baseText = rule.style ? rule.style.cssText : rule.cssText;
propValue = Dom.getChildByClass(row, "cssPropValue").textContent;
parsedValue = parsePriority(propValue);
if (FBTrace.DBG_CSS)
FBTrace.sysout("CSSEditor.saveEdit : " + previousValue + "->" + value +
" = " + propValue);
if (propValue && propValue != "undefined")
{
if (FBTrace.DBG_CSS)
FBTrace.sysout("CSSEditor.saveEdit : " + previousValue + "->" + value +
" = " + propValue);
if (previousValue)
Firebug.CSSModule.removeProperty(rule, previousValue);
Firebug.CSSModule.setProperty(rule, value, parsedValue.value,
parsedValue.priority);
}
Events.dispatch(this.fbListeners, "onCSSPropertyNameChanged", [rule, value,
previousValue, baseText]);
}
else if (!value)
{
// name of the property has been deleted, so remove the property.
Firebug.CSSModule.removeProperty(rule, previousValue);
}
}
else if (Dom.getAncestorByClass(target, "cssPropValue"))
{
propName = Dom.getChildByClass(row, "cssPropName").textContent;
propValue = Dom.getChildByClass(row, "cssPropValue").textContent;
if (FBTrace.DBG_CSS)
{
FBTrace.sysout("CSSEditor.saveEdit propName=propValue: "+propName +
" = "+propValue+"\n");
// FBTrace.sysout("CSSEditor.saveEdit BEFORE style:",style);
}
if (value && value != "null")
{
parsedValue = parsePriority(value);
Firebug.CSSModule.setProperty(rule, propName, parsedValue.value,
parsedValue.priority);
}
else if (previousValue && previousValue != "null")
{
Firebug.CSSModule.removeProperty(rule, propName);
}
}
if (value)
{
var saveSuccess = !!rule.style.getPropertyValue(propName || value);
if(!saveSuccess && !propName)
{
propName = value.replace(/-./g, function(match)
{
return match[1].toUpperCase()
});
if (propName in rule.style || propName == "float")
saveSuccess = "almost";
}
this.box.setAttribute("saveSuccess", saveSuccess);
}
else
{
this.box.removeAttribute("saveSuccess");
}
}
else if (rule instanceof window.CSSImportRule && Css.hasClass(target, "cssMediaQuery"))
{
if (FBTrace.DBG_CSS)
{
@@ -1529,88 +1614,6 @@ CSSEditor.prototype = domplate(Firebug.InlineEditor.prototype,
rule.encoding = value;
}
else if (Css.hasClass(target, "cssPropName"))
{
if (value && previousValue != value) // name of property has changed.
{
// Record the original CSS text for the inline case so we can reconstruct at a later
// point for diffing purposes
var baseText = rule.style ? rule.style.cssText : rule.cssText;
propValue = Dom.getChildByClass(row, "cssPropValue").textContent;
parsedValue = parsePriority(propValue);
if (FBTrace.DBG_CSS)
FBTrace.sysout("CSSEditor.saveEdit : " + previousValue + "->" + value +
" = " + propValue);
if (propValue && propValue != "undefined")
{
if (FBTrace.DBG_CSS)
FBTrace.sysout("CSSEditor.saveEdit : " + previousValue + "->" + value +
" = " + propValue);
if (previousValue)
Firebug.CSSModule.removeProperty(rule, previousValue);
Firebug.CSSModule.setProperty(rule, value, parsedValue.value,
parsedValue.priority);
}
Events.dispatch(this.fbListeners, "onCSSPropertyNameChanged", [rule, value,
previousValue, baseText]);
}
else if (!value)
{
// name of the property has been deleted, so remove the property.
Firebug.CSSModule.removeProperty(rule, previousValue);
}
}
else if (Dom.getAncestorByClass(target, "cssPropValue"))
{
propName = Dom.getChildByClass(row, "cssPropName").textContent;
propValue = Dom.getChildByClass(row, "cssPropValue").textContent;
if (FBTrace.DBG_CSS)
{
FBTrace.sysout("CSSEditor.saveEdit propName=propValue: "+propName +
" = "+propValue+"\n");
// FBTrace.sysout("CSSEditor.saveEdit BEFORE style:",style);
}
if (value && value != "null")
{
parsedValue = parsePriority(value);
Firebug.CSSModule.setProperty(rule, propName, parsedValue.value,
parsedValue.priority);
}
else if (previousValue && previousValue != "null")
{
Firebug.CSSModule.removeProperty(rule, propName);
}
}
if (value)
{
var saveSuccess = !!rule.style.getPropertyValue(propName || value);
if(!saveSuccess && !propName)
{
propName = value.replace(/-./g, function(match)
{
return match[1].toUpperCase()
});
if(propName in rule.style || propName == "float")
saveSuccess = "almost";
}
this.box.setAttribute("saveSuccess",saveSuccess);
}
else
{
this.box.removeAttribute("saveSuccess");
}
Firebug.Inspector.repaint();

2 comments on commit 20a0cc3

@simonlindholm

This comment has been minimized.

Show comment
Hide comment
@simonlindholm

simonlindholm Apr 27, 2012

Member

Did this break editing inline styles? Because I can't get that to work.

Member

simonlindholm replied Apr 27, 2012

Did this break editing inline styles? Because I can't get that to work.

@SebastianZ

This comment has been minimized.

Show comment
Hide comment
@SebastianZ

SebastianZ Apr 28, 2012

Member

Thanks for pointing that out. Should be fixed in 53ab73b.
We're missing a test case for this...

Sebastian

Member

SebastianZ replied Apr 28, 2012

Thanks for pointing that out. Should be fixed in 53ab73b.
We're missing a test case for this...

Sebastian

Please sign in to comment.