Fix the way HTML's align attribute works for horizontal alignment of blocks. Use the -moz-center and -moz-right even in strict mode, and apply them to blocks in addition to tables. r=attinasi b=37083, 40038

git-svn-id: svn://10.0.0.236/trunk@74966 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dbaron%fas.harvard.edu
2000-07-27 23:37:44 +00:00
parent eea96f3b7f
commit 5c317da98a
11 changed files with 140 additions and 114 deletions

View File

@@ -2837,6 +2837,20 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext, PRBool aRecurse)
}
mParent = holdParent;
}
} else {
// In strict mode, we still have to support one "quirky" thing
// for tables. HTML's alignment attributes have always worked
// so they don't inherit into tables, but instead align the
// tables. We should keep doing this, because HTML alignment
// is just weird, and we shouldn't force it to match CSS.
if (GETSCDATA(Display).mDisplay == NS_STYLE_DISPLAY_TABLE) {
// -moz-center and -moz-right are used for HTML's alignment
if ((GETSCDATA(Text).mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) ||
(GETSCDATA(Text).mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT))
{
GETSCDATA(Text).mTextAlign = NS_STYLE_TEXT_ALIGN_DEFAULT;
}
}
}
RecalcAutomaticData(aPresContext);

View File

@@ -2425,7 +2425,7 @@ static nsGenericHTMLElement::EnumTable kAlignTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kCompatDivAlignTable[] = {
static nsGenericHTMLElement::EnumTable kDivAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
@@ -2434,15 +2434,6 @@ static nsGenericHTMLElement::EnumTable kCompatDivAlignTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kDivAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_CENTER },
{ "middle", NS_STYLE_TEXT_ALIGN_CENTER },
{ "justify", NS_STYLE_TEXT_ALIGN_JUSTIFY },
{ 0 }
};
static nsGenericHTMLElement::EnumTable kFrameborderQuirksTable[] = {
{ "yes", NS_STYLE_FRAME_YES },
{ "no", NS_STYLE_FRAME_NO },
@@ -2550,12 +2541,18 @@ nsGenericHTMLElement::TableHAlignValueToString(const nsHTMLValue& aValue,
//----------------------------------------
// This table is used for TD,TH,TR, etc (but not TABLE) when in
// compatability mode
// These tables are used for TD,TH,TR, etc (but not TABLE)
static nsGenericHTMLElement::EnumTable kTableCellHAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
{ "char", NS_STYLE_TEXT_ALIGN_CHAR },
{ "justify",NS_STYLE_TEXT_ALIGN_JUSTIFY },
{ 0 }
};
static nsGenericHTMLElement::EnumTable kCompatTableCellHAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
// Note: use compatible version of alignment constants so that
// nested tables will be right aligned or center aligned.
{ "right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
{ "char", NS_STYLE_TEXT_ALIGN_CHAR },
@@ -2578,7 +2575,7 @@ nsGenericHTMLElement::ParseTableCellHAlignValue(const nsString& aString,
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatTableCellHAlignTable, aResult);
}
return ParseEnumValue(aString, kTableHAlignTable, aResult);
return ParseEnumValue(aString, kTableCellHAlignTable, aResult);
}
PRBool
@@ -2588,7 +2585,7 @@ nsGenericHTMLElement::TableCellHAlignValueToString(const nsHTMLValue& aValue,
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatTableCellHAlignTable, aResult);
}
return EnumValueToString(aValue, kTableHAlignTable, aResult);
return EnumValueToString(aValue, kTableCellHAlignTable, aResult);
}
//----------------------------------------
@@ -2618,9 +2615,6 @@ PRBool
nsGenericHTMLElement::ParseDivAlignValue(const nsString& aString,
nsHTMLValue& aResult) const
{
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatDivAlignTable, aResult);
}
return ParseEnumValue(aString, kDivAlignTable, aResult);
}
@@ -2628,9 +2622,6 @@ PRBool
nsGenericHTMLElement::DivAlignValueToString(const nsHTMLValue& aValue,
nsString& aResult) const
{
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatDivAlignTable, aResult);
}
return EnumValueToString(aValue, kDivAlignTable, aResult);
}

View File

@@ -34,6 +34,7 @@ class nsLineLayout;
struct nsStyleDisplay;
struct nsStylePosition;
struct nsStyleSpacing;
struct nsStyleText;
struct nsHypotheticalBox;
/**
@@ -206,6 +207,7 @@ struct nsHTMLReflowState {
const nsStyleDisplay* mStyleDisplay;
const nsStylePosition* mStylePosition;
const nsStyleSpacing* mStyleSpacing;
const nsStyleText* mStyleText;
// This value keeps track of how deeply nested a given reflow state
// is from the top of the frame tree.

View File

@@ -2837,6 +2837,20 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext, PRBool aRecurse)
}
mParent = holdParent;
}
} else {
// In strict mode, we still have to support one "quirky" thing
// for tables. HTML's alignment attributes have always worked
// so they don't inherit into tables, but instead align the
// tables. We should keep doing this, because HTML alignment
// is just weird, and we shouldn't force it to match CSS.
if (GETSCDATA(Display).mDisplay == NS_STYLE_DISPLAY_TABLE) {
// -moz-center and -moz-right are used for HTML's alignment
if ((GETSCDATA(Text).mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) ||
(GETSCDATA(Text).mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT))
{
GETSCDATA(Text).mTextAlign = NS_STYLE_TEXT_ALIGN_DEFAULT;
}
}
}
RecalcAutomaticData(aPresContext);

View File

@@ -185,39 +185,26 @@ nsBlockReflowContext::AlignBlockHorizontally(nscoord aWidth,
}
else if (eStyleUnit_Auto != rightUnit) {
// The block/table doesn't have auto margins.
PRBool doCSS = PR_TRUE;
if (mIsTable) {
const nsStyleText* styleText;
mOuterReflowState.frame->GetStyleData(eStyleStruct_Text,
(const nsStyleStruct*&)styleText);
// This is a navigator compatability case: tables are
// affected by the text alignment of the containing
// block. CSS doesn't do this, so we use special
// text-align attribute values to signal these
// compatability cases.
switch (styleText->mTextAlign) {
case NS_STYLE_TEXT_ALIGN_MOZ_RIGHT:
case NS_STYLE_TEXT_ALIGN_RIGHT:
aAlign.mXOffset += remainingSpace;
doCSS = PR_FALSE;
break;
case NS_STYLE_TEXT_ALIGN_MOZ_CENTER:
case NS_STYLE_TEXT_ALIGN_CENTER:
{
nsCompatibility mode;
mPresContext->GetCompatibilityMode(&mode);
if (eCompatibility_NavQuirks == mode) {
aAlign.mXOffset += remainingSpace / 2;
doCSS = PR_FALSE;
}
}
break;
}
}
if (doCSS) {
// XXX It's not clear we can ever get here because for normal blocks,
// their size will be well defined by the nsHTMLReflowState logic
// (maybe width=0 cases get here?)
// For normal (non-table) blocks we don't get here because
// nsHTMLReflowState::CalculateBlockSideMargins handles this.
// (I think there may be an exception to that, though...)
// We use a special value of the text-align property for
// HTML alignment (the CENTER element and DIV ALIGN=...)
// since it acts on blocks and tables rather than just
// being a text-align.
// So, check the text-align value from the parent to see if
// it has one of these special values.
const nsStyleText* styleText = mOuterReflowState.mStyleText;
if (styleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT) {
aAlign.mXOffset += remainingSpace;
} else if (styleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) {
aAlign.mXOffset += remainingSpace / 2;
} else {
// If we don't have a special text-align value indicating
// HTML alignment, then use the CSS rules.
// When neither margin is auto then the block is said to
// be over constrained, Depending on the direction, choose
// which margin to treat as auto.
@@ -226,9 +213,9 @@ nsBlockReflowContext::AlignBlockHorizontally(nscoord aWidth,
// The left margin becomes auto
aAlign.mXOffset += remainingSpace;
}
else {
//else {
// The right margin becomes auto which is a no-op
}
//}
}
}
}

View File

@@ -178,6 +178,8 @@ nsHTMLReflowState::Init(nsIPresContext* aPresContext,
(const nsStyleStruct*&)mStyleDisplay);
frame->GetStyleData(eStyleStruct_Spacing,
(const nsStyleStruct*&)mStyleSpacing);
frame->GetStyleData(eStyleStruct_Text,
(const nsStyleStruct*&)mStyleText);
mFrameType = DetermineFrameType(frame, mStylePosition, mStyleDisplay);
InitConstraints(aPresContext, aContainingBlockWidth, aContainingBlockHeight);
}
@@ -2001,6 +2003,16 @@ nsHTMLReflowState::CalculateBlockSideMargins(nscoord aAvailWidth,
const nsHTMLReflowState* prs = (const nsHTMLReflowState*)
parentReflowState;
if (prs) {
// First check if there is an HTML alignment that we should honor
if ((prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) ||
(prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT))
{
isAutoLeftMargin = PR_TRUE;
isAutoRightMargin =
(prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER);
} else
// Otherwise apply the CSS rules
if (NS_STYLE_DIRECTION_LTR == prs->mStyleDisplay->mDirection) {
// The specified value of margin-right is ignored (== forced
// to auto)

View File

@@ -34,6 +34,7 @@ class nsLineLayout;
struct nsStyleDisplay;
struct nsStylePosition;
struct nsStyleSpacing;
struct nsStyleText;
struct nsHypotheticalBox;
/**
@@ -206,6 +207,7 @@ struct nsHTMLReflowState {
const nsStyleDisplay* mStyleDisplay;
const nsStylePosition* mStylePosition;
const nsStyleSpacing* mStyleSpacing;
const nsStyleText* mStyleText;
// This value keeps track of how deeply nested a given reflow state
// is from the top of the frame tree.

View File

@@ -185,39 +185,26 @@ nsBlockReflowContext::AlignBlockHorizontally(nscoord aWidth,
}
else if (eStyleUnit_Auto != rightUnit) {
// The block/table doesn't have auto margins.
PRBool doCSS = PR_TRUE;
if (mIsTable) {
const nsStyleText* styleText;
mOuterReflowState.frame->GetStyleData(eStyleStruct_Text,
(const nsStyleStruct*&)styleText);
// This is a navigator compatability case: tables are
// affected by the text alignment of the containing
// block. CSS doesn't do this, so we use special
// text-align attribute values to signal these
// compatability cases.
switch (styleText->mTextAlign) {
case NS_STYLE_TEXT_ALIGN_MOZ_RIGHT:
case NS_STYLE_TEXT_ALIGN_RIGHT:
aAlign.mXOffset += remainingSpace;
doCSS = PR_FALSE;
break;
case NS_STYLE_TEXT_ALIGN_MOZ_CENTER:
case NS_STYLE_TEXT_ALIGN_CENTER:
{
nsCompatibility mode;
mPresContext->GetCompatibilityMode(&mode);
if (eCompatibility_NavQuirks == mode) {
aAlign.mXOffset += remainingSpace / 2;
doCSS = PR_FALSE;
}
}
break;
}
}
if (doCSS) {
// XXX It's not clear we can ever get here because for normal blocks,
// their size will be well defined by the nsHTMLReflowState logic
// (maybe width=0 cases get here?)
// For normal (non-table) blocks we don't get here because
// nsHTMLReflowState::CalculateBlockSideMargins handles this.
// (I think there may be an exception to that, though...)
// We use a special value of the text-align property for
// HTML alignment (the CENTER element and DIV ALIGN=...)
// since it acts on blocks and tables rather than just
// being a text-align.
// So, check the text-align value from the parent to see if
// it has one of these special values.
const nsStyleText* styleText = mOuterReflowState.mStyleText;
if (styleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT) {
aAlign.mXOffset += remainingSpace;
} else if (styleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) {
aAlign.mXOffset += remainingSpace / 2;
} else {
// If we don't have a special text-align value indicating
// HTML alignment, then use the CSS rules.
// When neither margin is auto then the block is said to
// be over constrained, Depending on the direction, choose
// which margin to treat as auto.
@@ -226,9 +213,9 @@ nsBlockReflowContext::AlignBlockHorizontally(nscoord aWidth,
// The left margin becomes auto
aAlign.mXOffset += remainingSpace;
}
else {
//else {
// The right margin becomes auto which is a no-op
}
//}
}
}
}

View File

@@ -178,6 +178,8 @@ nsHTMLReflowState::Init(nsIPresContext* aPresContext,
(const nsStyleStruct*&)mStyleDisplay);
frame->GetStyleData(eStyleStruct_Spacing,
(const nsStyleStruct*&)mStyleSpacing);
frame->GetStyleData(eStyleStruct_Text,
(const nsStyleStruct*&)mStyleText);
mFrameType = DetermineFrameType(frame, mStylePosition, mStyleDisplay);
InitConstraints(aPresContext, aContainingBlockWidth, aContainingBlockHeight);
}
@@ -2001,6 +2003,16 @@ nsHTMLReflowState::CalculateBlockSideMargins(nscoord aAvailWidth,
const nsHTMLReflowState* prs = (const nsHTMLReflowState*)
parentReflowState;
if (prs) {
// First check if there is an HTML alignment that we should honor
if ((prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) ||
(prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT))
{
isAutoLeftMargin = PR_TRUE;
isAutoRightMargin =
(prs->mStyleText->mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER);
} else
// Otherwise apply the CSS rules
if (NS_STYLE_DIRECTION_LTR == prs->mStyleDisplay->mDirection) {
// The specified value of margin-right is ignored (== forced
// to auto)

View File

@@ -2425,7 +2425,7 @@ static nsGenericHTMLElement::EnumTable kAlignTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kCompatDivAlignTable[] = {
static nsGenericHTMLElement::EnumTable kDivAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
@@ -2434,15 +2434,6 @@ static nsGenericHTMLElement::EnumTable kCompatDivAlignTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kDivAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_CENTER },
{ "middle", NS_STYLE_TEXT_ALIGN_CENTER },
{ "justify", NS_STYLE_TEXT_ALIGN_JUSTIFY },
{ 0 }
};
static nsGenericHTMLElement::EnumTable kFrameborderQuirksTable[] = {
{ "yes", NS_STYLE_FRAME_YES },
{ "no", NS_STYLE_FRAME_NO },
@@ -2550,12 +2541,18 @@ nsGenericHTMLElement::TableHAlignValueToString(const nsHTMLValue& aValue,
//----------------------------------------
// This table is used for TD,TH,TR, etc (but not TABLE) when in
// compatability mode
// These tables are used for TD,TH,TR, etc (but not TABLE)
static nsGenericHTMLElement::EnumTable kTableCellHAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
{ "char", NS_STYLE_TEXT_ALIGN_CHAR },
{ "justify",NS_STYLE_TEXT_ALIGN_JUSTIFY },
{ 0 }
};
static nsGenericHTMLElement::EnumTable kCompatTableCellHAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
// Note: use compatible version of alignment constants so that
// nested tables will be right aligned or center aligned.
{ "right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
{ "char", NS_STYLE_TEXT_ALIGN_CHAR },
@@ -2578,7 +2575,7 @@ nsGenericHTMLElement::ParseTableCellHAlignValue(const nsString& aString,
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatTableCellHAlignTable, aResult);
}
return ParseEnumValue(aString, kTableHAlignTable, aResult);
return ParseEnumValue(aString, kTableCellHAlignTable, aResult);
}
PRBool
@@ -2588,7 +2585,7 @@ nsGenericHTMLElement::TableCellHAlignValueToString(const nsHTMLValue& aValue,
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatTableCellHAlignTable, aResult);
}
return EnumValueToString(aValue, kTableHAlignTable, aResult);
return EnumValueToString(aValue, kTableCellHAlignTable, aResult);
}
//----------------------------------------
@@ -2618,9 +2615,6 @@ PRBool
nsGenericHTMLElement::ParseDivAlignValue(const nsString& aString,
nsHTMLValue& aResult) const
{
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatDivAlignTable, aResult);
}
return ParseEnumValue(aString, kDivAlignTable, aResult);
}
@@ -2628,9 +2622,6 @@ PRBool
nsGenericHTMLElement::DivAlignValueToString(const nsHTMLValue& aValue,
nsString& aResult) const
{
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatDivAlignTable, aResult);
}
return EnumValueToString(aValue, kDivAlignTable, aResult);
}

View File

@@ -2837,6 +2837,20 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext, PRBool aRecurse)
}
mParent = holdParent;
}
} else {
// In strict mode, we still have to support one "quirky" thing
// for tables. HTML's alignment attributes have always worked
// so they don't inherit into tables, but instead align the
// tables. We should keep doing this, because HTML alignment
// is just weird, and we shouldn't force it to match CSS.
if (GETSCDATA(Display).mDisplay == NS_STYLE_DISPLAY_TABLE) {
// -moz-center and -moz-right are used for HTML's alignment
if ((GETSCDATA(Text).mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) ||
(GETSCDATA(Text).mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT))
{
GETSCDATA(Text).mTextAlign = NS_STYLE_TEXT_ALIGN_DEFAULT;
}
}
}
RecalcAutomaticData(aPresContext);