Bug 412237. Don't parse negative sizes for the MathML fontsize attribute. Make sure we do continue to parse '-0px', since that's not actually negative. r+sr=dbaron

This commit is contained in:
roc+@cs.cmu.edu 2008-02-06 20:09:03 -08:00
parent bb395f76ba
commit e2f32405c1
3 changed files with 18 additions and 10 deletions

View File

@ -222,7 +222,7 @@ Implementation here:
/* static */ PRBool
nsMathMLElement::ParseNumericValue(const nsString& aString,
nsCSSValue& aCSSValue,
PRBool aRequireLengthUnit)
PRUint32 aFlags)
{
nsAutoString str(aString);
str.CompressWhitespace(); // aString is const in this code...
@ -267,19 +267,21 @@ nsMathMLElement::ParseNumericValue(const nsString& aString,
float floatValue = number.ToFloat(&errorCode);
if (NS_FAILED(errorCode))
return PR_FALSE;
if (floatValue < 0 && !(aFlags & PARSE_ALLOW_NEGATIVE))
return PR_FALSE;
nsCSSUnit cssUnit;
if (unit.IsEmpty()) {
if (aRequireLengthUnit) {
// We are supposed to have a length unit, but there isn't one.
if (aFlags & PARSE_ALLOW_UNITLESS) {
// no explicit unit, this is a number that will act as a multiplier
cssUnit = eCSSUnit_Number;
} else {
// We are supposed to have a unit, but there isn't one.
// If the value is 0 we can just call it "pixels" otherwise
// this is illegal.
if (floatValue != 0.0)
return PR_FALSE;
cssUnit = eCSSUnit_Pixel;
} else {
// no explicit unit, this is a number that will act as a multiplier
cssUnit = eCSSUnit_Number;
}
}
else if (unit.EqualsLiteral("%")) {
@ -328,7 +330,7 @@ nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
if (value && value->Type() == nsAttrValue::eString &&
aData->mFontData->mScriptMinSize.GetUnit() == eCSSUnit_Null) {
ParseNumericValue(value->GetStringValue(),
aData->mFontData->mScriptMinSize, PR_TRUE);
aData->mFontData->mScriptMinSize, 0);
}
value = aAttributes->GetAttr(nsGkAtoms::scriptlevel_);
@ -363,7 +365,7 @@ nsMathMLElement::MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
if (value && value->Type() == nsAttrValue::eString &&
aData->mFontData->mSize.GetUnit() == eCSSUnit_Null) {
nsAutoString str(value->GetStringValue());
if (!ParseNumericValue(str, aData->mFontData->mSize, PR_TRUE) &&
if (!ParseNumericValue(str, aData->mFontData->mSize, 0) &&
parseSizeKeywords) {
static const char sizes[3][7] = { "small", "normal", "big" };
static const PRInt32 values[NS_ARRAY_LENGTH(sizes)] = {

View File

@ -78,9 +78,13 @@ public:
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
enum {
PARSE_ALLOW_UNITLESS = 0x01, // unitless 0 will be turned into 0px
PARSE_ALLOW_NEGATIVE = 0x02
};
static PRBool ParseNumericValue(const nsString& aString,
nsCSSValue& aCSSValue,
PRBool aRequireLengthUnit);
PRUint32 aFlags);
static void MapMathMLAttributesInto(const nsMappedAttributes* aAttributes,
nsRuleData* aRuleData);

View File

@ -218,7 +218,9 @@ public:
static PRBool
ParseNumericValue(const nsString& aString,
nsCSSValue& aCSSValue) {
return nsMathMLElement::ParseNumericValue(aString, aCSSValue, PR_FALSE);
return nsMathMLElement::ParseNumericValue(aString, aCSSValue,
nsMathMLElement::PARSE_ALLOW_NEGATIVE |
nsMathMLElement::PARSE_ALLOW_UNITLESS);
}
static nscoord