Skip to content

Commit

Permalink
Avoid NPE for CSS rules other than CSSStyleRules (followup on issue
Browse files Browse the repository at this point in the history
5262 and 5277)
  • Loading branch information
SebastianZ committed Apr 19, 2012
1 parent 4832f20 commit 20a0cc3
Showing 1 changed file with 86 additions and 83 deletions.
169 changes: 86 additions & 83 deletions extension/content/firebug/css/cssPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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();

Expand Down

2 comments on commit 20a0cc3

@simonlindholm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@SebastianZ
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sebastian

Please sign in to comment.