Make spacer attribute mapping code not depend on data in the style context (which attribute mapping code should not do). (Bug 449435) r+sr=bzbarsky

This commit is contained in:
L. David Baron 2008-09-04 13:02:08 -07:00
parent ff14b5b6ad
commit 2cf88dfb3f

View File

@ -47,7 +47,6 @@
#include "nsPresContext.h" #include "nsPresContext.h"
#include "nsRuleData.h" #include "nsRuleData.h"
#include "nsMappedAttributes.h" #include "nsMappedAttributes.h"
#include "nsStyleContext.h"
// XXX nav4 has type= start= (same as OL/UL) // XXX nav4 has type= start= (same as OL/UL)
extern nsAttrValue::EnumTable kListTypeTable[]; extern nsAttrValue::EnumTable kListTypeTable[];
@ -239,77 +238,84 @@ SpacerMapAttributesIntoRule(const nsMappedAttributes* aAttributes,
nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData); nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData);
nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData); nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) { if (aData->mSIDs & (NS_STYLE_INHERIT_BIT(Position) |
const nsStyleDisplay* display = aData->mStyleContext->GetStyleDisplay(); NS_STYLE_INHERIT_BIT(Display))) {
PRBool typeIsBlock = PR_FALSE;
PRBool typeIsBlock = (display->mDisplay == NS_STYLE_DISPLAY_BLOCK); const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::type);
if (value && value->Type() == nsAttrValue::eString) {
if (typeIsBlock) { const nsString& tmp(value->GetStringValue());
// width: value if (tmp.LowerCaseEqualsLiteral("line") ||
if (aData->mPositionData->mWidth.GetUnit() == eCSSUnit_Null) { tmp.LowerCaseEqualsLiteral("vert") ||
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width); tmp.LowerCaseEqualsLiteral("vertical") ||
if (value && value->Type() == nsAttrValue::eInteger) { tmp.LowerCaseEqualsLiteral("block")) {
aData->mPositionData-> // This is not strictly 100% compatible: if the spacer is given
mWidth.SetFloatValue((float)value->GetIntegerValue(), // a width of zero then it is basically ignored.
eCSSUnit_Pixel); typeIsBlock = PR_TRUE;
} else if (value && value->Type() == nsAttrValue::ePercent) {
aData->mPositionData->
mWidth.SetPercentValue(value->GetPercentValue());
}
}
// height: value
if (aData->mPositionData->mHeight.GetUnit() == eCSSUnit_Null) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::height);
if (value && value->Type() == nsAttrValue::eInteger) {
aData->mPositionData->
mHeight.SetFloatValue((float)value->GetIntegerValue(),
eCSSUnit_Pixel);
} else if (value && value->Type() == nsAttrValue::ePercent) {
aData->mPositionData->
mHeight.SetPercentValue(value->GetPercentValue());
}
}
} else {
// size: value
if (aData->mPositionData->mWidth.GetUnit() == eCSSUnit_Null) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::size);
if (value && value->Type() == nsAttrValue::eInteger)
aData->mPositionData->
mWidth.SetFloatValue((float)value->GetIntegerValue(),
eCSSUnit_Pixel);
}
}
}
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Display)) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
if (value && value->Type() == nsAttrValue::eEnum) {
PRInt32 align = value->GetEnumValue();
if (aData->mDisplayData->mFloat.GetUnit() == eCSSUnit_Null) {
if (align == NS_STYLE_TEXT_ALIGN_LEFT)
aData->mDisplayData->mFloat.SetIntValue(NS_STYLE_FLOAT_LEFT,
eCSSUnit_Enumerated);
else if (align == NS_STYLE_TEXT_ALIGN_RIGHT)
aData->mDisplayData->mFloat.SetIntValue(NS_STYLE_FLOAT_RIGHT,
eCSSUnit_Enumerated);
} }
} }
if (aData->mDisplayData->mDisplay.GetUnit() == eCSSUnit_Null) { if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::type); if (typeIsBlock) {
if (value && value->Type() == nsAttrValue::eString) { // width: value
nsAutoString tmp(value->GetStringValue()); if (aData->mPositionData->mWidth.GetUnit() == eCSSUnit_Null) {
if (tmp.LowerCaseEqualsLiteral("line") || const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
tmp.LowerCaseEqualsLiteral("vert") || if (value && value->Type() == nsAttrValue::eInteger) {
tmp.LowerCaseEqualsLiteral("vertical") || aData->mPositionData->
tmp.LowerCaseEqualsLiteral("block")) { mWidth.SetFloatValue((float)value->GetIntegerValue(),
// This is not strictly 100% compatible: if the spacer is given eCSSUnit_Pixel);
// a width of zero then it is basically ignored. } else if (value && value->Type() == nsAttrValue::ePercent) {
aData->mPositionData->
mWidth.SetPercentValue(value->GetPercentValue());
}
}
// height: value
if (aData->mPositionData->mHeight.GetUnit() == eCSSUnit_Null) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::height);
if (value && value->Type() == nsAttrValue::eInteger) {
aData->mPositionData->
mHeight.SetFloatValue((float)value->GetIntegerValue(),
eCSSUnit_Pixel);
} else if (value && value->Type() == nsAttrValue::ePercent) {
aData->mPositionData->
mHeight.SetPercentValue(value->GetPercentValue());
}
}
} else {
// size: value
if (aData->mPositionData->mWidth.GetUnit() == eCSSUnit_Null) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::size);
if (value && value->Type() == nsAttrValue::eInteger)
aData->mPositionData->
mWidth.SetFloatValue((float)value->GetIntegerValue(),
eCSSUnit_Pixel);
}
}
}
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Display)) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
if (value && value->Type() == nsAttrValue::eEnum) {
PRInt32 align = value->GetEnumValue();
if (aData->mDisplayData->mFloat.GetUnit() == eCSSUnit_Null) {
if (align == NS_STYLE_TEXT_ALIGN_LEFT)
aData->mDisplayData->mFloat.SetIntValue(NS_STYLE_FLOAT_LEFT,
eCSSUnit_Enumerated);
else if (align == NS_STYLE_TEXT_ALIGN_RIGHT)
aData->mDisplayData->mFloat.SetIntValue(NS_STYLE_FLOAT_RIGHT,
eCSSUnit_Enumerated);
}
}
if (typeIsBlock) {
if (aData->mDisplayData->mDisplay.GetUnit() == eCSSUnit_Null) {
aData->mDisplayData->mDisplay.SetIntValue(NS_STYLE_DISPLAY_BLOCK, aData->mDisplayData->mDisplay.SetIntValue(NS_STYLE_DISPLAY_BLOCK,
eCSSUnit_Enumerated); eCSSUnit_Enumerated);
} }
} }
} }
// Any new structs that don't need typeIsBlock should go outside
// the code that calculates it.
} }
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData); nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);