bug 7112, PDT+ 1802 - added custom style rule to handle <th> text alignment. Other text alignment changes. r=attinasi

This commit is contained in:
karnaze%netscape.com 2000-02-16 01:08:54 +00:00
parent a536a762d8
commit c75793821e
11 changed files with 382 additions and 128 deletions

View File

@ -1954,7 +1954,7 @@ static nsGenericHTMLElement::EnumTable kCompatTableCellHAlignTable[] = {
{ "justify",NS_STYLE_TEXT_ALIGN_JUSTIFY },
// The following are non-standard but necessary for Nav4 compatibility
{ "middle", NS_STYLE_TEXT_ALIGN_CENTER },
{ "middle", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
{ "absmiddle", NS_STYLE_TEXT_ALIGN_CENTER },// XXX is this right???
{ 0 }

View File

@ -1183,7 +1183,13 @@ MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
// illegal)
aAttributes->GetAttribute(nsHTMLAtoms::align, value);
if (value.GetUnit() == eHTMLUnit_Enumerated) {
if (NS_STYLE_TEXT_ALIGN_CENTER == value.GetIntValue()) {
if ((NS_STYLE_TEXT_ALIGN_CENTER == value.GetIntValue()) ||
(NS_STYLE_TEXT_ALIGN_MOZ_CENTER == value.GetIntValue())) {
if (eCompatibility_Standard == mode) {
nsStyleText* text = (nsStyleText*)
aContext->GetMutableStyleData(eStyleStruct_Text);
text->mTextAlign = NS_STYLE_TEXT_ALIGN_CENTER;
}
nsStyleCoord otto(eStyleUnit_Auto);
spacing->mMargin.SetLeft(otto);
spacing->mMargin.SetRight(otto);
@ -1197,6 +1203,7 @@ MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
break;
case NS_STYLE_TEXT_ALIGN_RIGHT:
case NS_STYLE_TEXT_ALIGN_MOZ_RIGHT:
display->mFloats = NS_STYLE_FLOAT_RIGHT;
break;
}

View File

@ -186,13 +186,10 @@ HTMLDocumentColorRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresCon
return NS_OK;
}
// -----------------------------------------------------------
// this rule only applies in NavQuirks mode
// -----------------------------------------------------------
class TableBackgroundRule: public nsIStyleRule {
class GenericTableRule: public nsIStyleRule {
public:
TableBackgroundRule(nsIHTMLStyleSheet* aSheet);
virtual ~TableBackgroundRule();
GenericTableRule(nsIHTMLStyleSheet* aSheet);
virtual ~GenericTableRule();
NS_DECL_ISUPPORTS
@ -213,34 +210,34 @@ public:
nsIHTMLStyleSheet* mSheet; // not ref-counted, cleared by content
};
TableBackgroundRule::TableBackgroundRule(nsIHTMLStyleSheet* aSheet)
GenericTableRule::GenericTableRule(nsIHTMLStyleSheet* aSheet)
{
NS_INIT_REFCNT();
mSheet = aSheet;
}
TableBackgroundRule::~TableBackgroundRule()
GenericTableRule::~GenericTableRule()
{
}
NS_IMPL_ISUPPORTS(TableBackgroundRule, kIStyleRuleIID);
NS_IMPL_ISUPPORTS(GenericTableRule, kIStyleRuleIID);
NS_IMETHODIMP
TableBackgroundRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
GenericTableRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
{
aResult = PRBool(this == aRule);
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::HashValue(PRUint32& aValue) const
GenericTableRule::HashValue(PRUint32& aValue) const
{
aValue = 0;
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
GenericTableRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
aSheet = mSheet;
return NS_OK;
@ -249,18 +246,50 @@ TableBackgroundRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
// Strength is an out-of-band weighting, useful for mapping CSS ! important
// always 0 here
NS_IMETHODIMP
TableBackgroundRule::GetStrength(PRInt32& aStrength) const
GenericTableRule::GetStrength(PRInt32& aStrength) const
{
aStrength = 0;
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::MapFontStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
GenericTableRule::MapFontStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
return NS_OK;
}
NS_IMETHODIMP
GenericTableRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
return NS_OK;
}
NS_IMETHODIMP
GenericTableRule::List(FILE* out, PRInt32 aIndent) const
{
return NS_OK;
}
// -----------------------------------------------------------
// this rule only applies in NavQuirks mode
// -----------------------------------------------------------
class TableBackgroundRule: public GenericTableRule {
public:
TableBackgroundRule(nsIHTMLStyleSheet* aSheet);
virtual ~TableBackgroundRule();
NS_IMETHOD MapStyleInto(nsIMutableStyleContext* aContext,
nsIPresContext* aPresContext);
};
TableBackgroundRule::TableBackgroundRule(nsIHTMLStyleSheet* aSheet)
: GenericTableRule(aSheet)
{
}
TableBackgroundRule::~TableBackgroundRule()
{
}
NS_IMETHODIMP
TableBackgroundRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
@ -288,9 +317,44 @@ TableBackgroundRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresConte
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::List(FILE* out, PRInt32 aIndent) const
// -----------------------------------------------------------
// this rule handles <th> inheritance
// -----------------------------------------------------------
class TableTHRule: public GenericTableRule {
public:
TableTHRule(nsIHTMLStyleSheet* aSheet);
virtual ~TableTHRule();
NS_IMETHOD MapStyleInto(nsIMutableStyleContext* aContext,
nsIPresContext* aPresContext);
};
TableTHRule::TableTHRule(nsIHTMLStyleSheet* aSheet)
: GenericTableRule(aSheet)
{
}
TableTHRule::~TableTHRule()
{
}
NS_IMETHODIMP
TableTHRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
nsIStyleContext* parentContext = aContext->GetParent();
if (parentContext) {
nsStyleText* styleText =
(nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text);
if (NS_STYLE_TEXT_ALIGN_DEFAULT == styleText->mTextAlign) {
const nsStyleText* parentStyleText =
(const nsStyleText*)parentContext->GetStyleData(eStyleStruct_Text);
PRUint8 parentAlign = parentStyleText->mTextAlign;
styleText->mTextAlign = (NS_STYLE_TEXT_ALIGN_DEFAULT == parentAlign)
? NS_STYLE_TEXT_ALIGN_CENTER : parentAlign;
}
}
return NS_OK;
}
@ -474,6 +538,7 @@ protected:
HTMLColorRule* mActiveRule;
HTMLDocumentColorRule* mDocumentColorRule;
TableBackgroundRule* mTableBackgroundRule;
TableTHRule* mTableTHRule;
nsHashtable mMappedAttrTable;
};
@ -524,6 +589,8 @@ HTMLStyleSheetImpl::HTMLStyleSheetImpl(void)
NS_INIT_REFCNT();
mTableBackgroundRule = new TableBackgroundRule(this);
NS_ADDREF(mTableBackgroundRule);
mTableTHRule = new TableTHRule(this);
NS_ADDREF(mTableTHRule);
}
PRBool MappedDropSheet(nsHashKey *aKey, void *aData, void* closure)
@ -556,6 +623,10 @@ HTMLStyleSheetImpl::~HTMLStyleSheetImpl()
mTableBackgroundRule->mSheet = nsnull;
NS_RELEASE(mTableBackgroundRule);
}
if (nsnull != mTableTHRule) {
mTableTHRule->mSheet = nsnull;
NS_RELEASE(mTableTHRule);
}
mMappedAttrTable.Enumerate(MappedDropSheet);
}
@ -709,12 +780,17 @@ HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
} // end active rule
} // end A tag
// add the quirks background compatibility rule if in quirks mode
// and/or the Table TH rule for handling <TH> differently than <TD>
else if ((tag == nsHTMLAtoms::td) ||
(tag == nsHTMLAtoms::th) ||
(tag == nsHTMLAtoms::tr) ||
(tag == nsHTMLAtoms::thead) || // Nav4.X doesn't support row groups, but it is a lot
(tag == nsHTMLAtoms::tbody) || // easier passing from the table to rows this way
(tag == nsHTMLAtoms::tfoot)) {
// add the rule to handle text-align for a <th>
if (tag == nsHTMLAtoms::th) {
aResults->AppendElement(mTableTHRule);
}
nsCompatibility mode;
aPresContext->GetCompatibilityMode(&mode);
if (eCompatibility_NavQuirks == mode) {
@ -909,6 +985,10 @@ NS_IMETHODIMP HTMLStyleSheetImpl::Reset(nsIURI* aURL)
mTableBackgroundRule->mSheet = nsnull;
NS_RELEASE(mTableBackgroundRule);
}
if (mTableTHRule) {
mTableTHRule->mSheet = nsnull;
NS_RELEASE(mTableTHRule);
}
mMappedAttrTable.Enumerate(MappedDropSheet);
mMappedAttrTable.Reset();

View File

@ -1954,7 +1954,7 @@ static nsGenericHTMLElement::EnumTable kCompatTableCellHAlignTable[] = {
{ "justify",NS_STYLE_TEXT_ALIGN_JUSTIFY },
// The following are non-standard but necessary for Nav4 compatibility
{ "middle", NS_STYLE_TEXT_ALIGN_CENTER },
{ "middle", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
{ "absmiddle", NS_STYLE_TEXT_ALIGN_CENTER },// XXX is this right???
{ 0 }

View File

@ -1183,7 +1183,13 @@ MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
// illegal)
aAttributes->GetAttribute(nsHTMLAtoms::align, value);
if (value.GetUnit() == eHTMLUnit_Enumerated) {
if (NS_STYLE_TEXT_ALIGN_CENTER == value.GetIntValue()) {
if ((NS_STYLE_TEXT_ALIGN_CENTER == value.GetIntValue()) ||
(NS_STYLE_TEXT_ALIGN_MOZ_CENTER == value.GetIntValue())) {
if (eCompatibility_Standard == mode) {
nsStyleText* text = (nsStyleText*)
aContext->GetMutableStyleData(eStyleStruct_Text);
text->mTextAlign = NS_STYLE_TEXT_ALIGN_CENTER;
}
nsStyleCoord otto(eStyleUnit_Auto);
spacing->mMargin.SetLeft(otto);
spacing->mMargin.SetRight(otto);
@ -1197,6 +1203,7 @@ MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
break;
case NS_STYLE_TEXT_ALIGN_RIGHT:
case NS_STYLE_TEXT_ALIGN_MOZ_RIGHT:
display->mFloats = NS_STYLE_FLOAT_RIGHT;
break;
}

View File

@ -153,14 +153,15 @@ table {
}
/* must never set padding in td, th */
td, th {
td {
vertical-align: inherit;
text-align: left;
text-align: inherit;
display: table-cell;
}
th {
font-weight: bold;
text-align: center;
vertical-align: inherit;
display: table-cell;
}
caption {
text-align: center;

View File

@ -186,13 +186,10 @@ HTMLDocumentColorRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresCon
return NS_OK;
}
// -----------------------------------------------------------
// this rule only applies in NavQuirks mode
// -----------------------------------------------------------
class TableBackgroundRule: public nsIStyleRule {
class GenericTableRule: public nsIStyleRule {
public:
TableBackgroundRule(nsIHTMLStyleSheet* aSheet);
virtual ~TableBackgroundRule();
GenericTableRule(nsIHTMLStyleSheet* aSheet);
virtual ~GenericTableRule();
NS_DECL_ISUPPORTS
@ -213,34 +210,34 @@ public:
nsIHTMLStyleSheet* mSheet; // not ref-counted, cleared by content
};
TableBackgroundRule::TableBackgroundRule(nsIHTMLStyleSheet* aSheet)
GenericTableRule::GenericTableRule(nsIHTMLStyleSheet* aSheet)
{
NS_INIT_REFCNT();
mSheet = aSheet;
}
TableBackgroundRule::~TableBackgroundRule()
GenericTableRule::~GenericTableRule()
{
}
NS_IMPL_ISUPPORTS(TableBackgroundRule, kIStyleRuleIID);
NS_IMPL_ISUPPORTS(GenericTableRule, kIStyleRuleIID);
NS_IMETHODIMP
TableBackgroundRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
GenericTableRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
{
aResult = PRBool(this == aRule);
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::HashValue(PRUint32& aValue) const
GenericTableRule::HashValue(PRUint32& aValue) const
{
aValue = 0;
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
GenericTableRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
aSheet = mSheet;
return NS_OK;
@ -249,18 +246,50 @@ TableBackgroundRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
// Strength is an out-of-band weighting, useful for mapping CSS ! important
// always 0 here
NS_IMETHODIMP
TableBackgroundRule::GetStrength(PRInt32& aStrength) const
GenericTableRule::GetStrength(PRInt32& aStrength) const
{
aStrength = 0;
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::MapFontStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
GenericTableRule::MapFontStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
return NS_OK;
}
NS_IMETHODIMP
GenericTableRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
return NS_OK;
}
NS_IMETHODIMP
GenericTableRule::List(FILE* out, PRInt32 aIndent) const
{
return NS_OK;
}
// -----------------------------------------------------------
// this rule only applies in NavQuirks mode
// -----------------------------------------------------------
class TableBackgroundRule: public GenericTableRule {
public:
TableBackgroundRule(nsIHTMLStyleSheet* aSheet);
virtual ~TableBackgroundRule();
NS_IMETHOD MapStyleInto(nsIMutableStyleContext* aContext,
nsIPresContext* aPresContext);
};
TableBackgroundRule::TableBackgroundRule(nsIHTMLStyleSheet* aSheet)
: GenericTableRule(aSheet)
{
}
TableBackgroundRule::~TableBackgroundRule()
{
}
NS_IMETHODIMP
TableBackgroundRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
@ -288,9 +317,44 @@ TableBackgroundRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresConte
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::List(FILE* out, PRInt32 aIndent) const
// -----------------------------------------------------------
// this rule handles <th> inheritance
// -----------------------------------------------------------
class TableTHRule: public GenericTableRule {
public:
TableTHRule(nsIHTMLStyleSheet* aSheet);
virtual ~TableTHRule();
NS_IMETHOD MapStyleInto(nsIMutableStyleContext* aContext,
nsIPresContext* aPresContext);
};
TableTHRule::TableTHRule(nsIHTMLStyleSheet* aSheet)
: GenericTableRule(aSheet)
{
}
TableTHRule::~TableTHRule()
{
}
NS_IMETHODIMP
TableTHRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
nsIStyleContext* parentContext = aContext->GetParent();
if (parentContext) {
nsStyleText* styleText =
(nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text);
if (NS_STYLE_TEXT_ALIGN_DEFAULT == styleText->mTextAlign) {
const nsStyleText* parentStyleText =
(const nsStyleText*)parentContext->GetStyleData(eStyleStruct_Text);
PRUint8 parentAlign = parentStyleText->mTextAlign;
styleText->mTextAlign = (NS_STYLE_TEXT_ALIGN_DEFAULT == parentAlign)
? NS_STYLE_TEXT_ALIGN_CENTER : parentAlign;
}
}
return NS_OK;
}
@ -474,6 +538,7 @@ protected:
HTMLColorRule* mActiveRule;
HTMLDocumentColorRule* mDocumentColorRule;
TableBackgroundRule* mTableBackgroundRule;
TableTHRule* mTableTHRule;
nsHashtable mMappedAttrTable;
};
@ -524,6 +589,8 @@ HTMLStyleSheetImpl::HTMLStyleSheetImpl(void)
NS_INIT_REFCNT();
mTableBackgroundRule = new TableBackgroundRule(this);
NS_ADDREF(mTableBackgroundRule);
mTableTHRule = new TableTHRule(this);
NS_ADDREF(mTableTHRule);
}
PRBool MappedDropSheet(nsHashKey *aKey, void *aData, void* closure)
@ -556,6 +623,10 @@ HTMLStyleSheetImpl::~HTMLStyleSheetImpl()
mTableBackgroundRule->mSheet = nsnull;
NS_RELEASE(mTableBackgroundRule);
}
if (nsnull != mTableTHRule) {
mTableTHRule->mSheet = nsnull;
NS_RELEASE(mTableTHRule);
}
mMappedAttrTable.Enumerate(MappedDropSheet);
}
@ -709,12 +780,17 @@ HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
} // end active rule
} // end A tag
// add the quirks background compatibility rule if in quirks mode
// and/or the Table TH rule for handling <TH> differently than <TD>
else if ((tag == nsHTMLAtoms::td) ||
(tag == nsHTMLAtoms::th) ||
(tag == nsHTMLAtoms::tr) ||
(tag == nsHTMLAtoms::thead) || // Nav4.X doesn't support row groups, but it is a lot
(tag == nsHTMLAtoms::tbody) || // easier passing from the table to rows this way
(tag == nsHTMLAtoms::tfoot)) {
// add the rule to handle text-align for a <th>
if (tag == nsHTMLAtoms::th) {
aResults->AppendElement(mTableTHRule);
}
nsCompatibility mode;
aPresContext->GetCompatibilityMode(&mode);
if (eCompatibility_NavQuirks == mode) {
@ -909,6 +985,10 @@ NS_IMETHODIMP HTMLStyleSheetImpl::Reset(nsIURI* aURL)
mTableBackgroundRule->mSheet = nsnull;
NS_RELEASE(mTableBackgroundRule);
}
if (mTableTHRule) {
mTableTHRule->mSheet = nsnull;
NS_RELEASE(mTableTHRule);
}
mMappedAttrTable.Enumerate(MappedDropSheet);
mMappedAttrTable.Reset();

View File

@ -917,14 +917,13 @@ void nsTableCellFrame::MapVAlignAttribute(nsIPresContext* aPresContext, nsTableF
const nsStyleText* textStyle;
GetStyleData(eStyleStruct_Text,(const nsStyleStruct *&)textStyle);
// check if valign is set on the cell
// this condition will also be true if we inherited valign from the row or rowgroup
if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated)
{
// this condition will also be true if we inherited valign from the row or rowgroup
if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
return; // valign is already set on this cell
}
// check if valign is set on the cell's COL (or COLGROUP by inheritance)
nsTableColFrame *colFrame;
nsTableColFrame* colFrame;
PRInt32 colIndex;
GetColIndex(colIndex);
aTableFrame->GetColumnFrame(colIndex, colFrame);
@ -932,70 +931,70 @@ void nsTableCellFrame::MapVAlignAttribute(nsIPresContext* aPresContext, nsTableF
const nsStyleText* colTextStyle;
colFrame->GetStyleData(eStyleStruct_Text,(const nsStyleStruct *&)colTextStyle);
if (colTextStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
nsStyleText* mutableTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
mutableTextStyle->mVerticalAlign.SetIntValue(colTextStyle->mVerticalAlign.GetIntValue(), eStyleUnit_Enumerated);
nsStyleText* cellTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
cellTextStyle->mVerticalAlign.SetIntValue(colTextStyle->mVerticalAlign.GetIntValue(), eStyleUnit_Enumerated);
return; // valign set from COL info
}
}
}
// otherwise, set the vertical align attribute to the HTML default
nsStyleText* mutableTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
mutableTextStyle->mVerticalAlign.SetIntValue(NS_STYLE_VERTICAL_ALIGN_MIDDLE, eStyleUnit_Enumerated);
nsStyleText* cellTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
cellTextStyle->mVerticalAlign.SetIntValue(NS_STYLE_VERTICAL_ALIGN_MIDDLE, eStyleUnit_Enumerated);
}
/* XXX: this code will not work properly until the style and layout code has been updated
* as outlined in Bugzilla bug report 1802 and 915.
* In particular, mTextAlign has to be an nsStyleCoord, not just an int */
void nsTableCellFrame::MapHAlignAttribute(nsIPresContext* aPresContext, nsTableFrame *aTableFrame)
void nsTableCellFrame::MapHAlignAttribute(nsIPresContext* aPresContext,
nsTableFrame* aTableFrame)
{
#if 0
const nsStyleText* textStyle;
GetStyleData(eStyleStruct_Text,(const nsStyleStruct *&)textStyle);
// check if halign is set on the cell
// cells do not inherited halign from the row or rowgroup
if (textStyle->mTextAlign.GetUnit() == eStyleUnit_Enumerated)
{
if (textStyle->mTextAlign.GetIntValue() != NS_STYLE_TEXT_ALIGN_DEFAULT)
return; // valign is already set on this cell
// cells do not inherited halign from the row or rowgroup
if (NS_STYLE_TEXT_ALIGN_DEFAULT != textStyle->mTextAlign) {
return; // text align is already set on this cell
}
// check if halign is set on the cell's ROW (or ROWGROUP by inheritance)
nsIFrame *rowFrame;
aTableFrame->GetContentParent(rowFrame);
nsIFrame* rowFrame;
GetParent(&rowFrame);
const nsStyleText* rowTextStyle;
rowFrame->GetStyleData(eStyleStruct_Text,(const nsStyleStruct *&)rowTextStyle);
if (rowTextStyle->mTextAlign.GetUnit() == eStyleUnit_Enumerated)
{
nsStyleText* mutableTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
mutableTextStyle->mTextAlign.SetIntValue(rowTextStyle->mTextAlign.GetIntValue(), eStyleUnit_Enumerated);
if (NS_STYLE_TEXT_ALIGN_DEFAULT != rowTextStyle->mTextAlign) {
nsStyleText* cellTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
cellTextStyle->mTextAlign = rowTextStyle->mTextAlign;
return; // halign set from ROW info
}
// check if halign is set on the cell's COL (or COLGROUP by inheritance)
nsTableColFrame *colFrame;
nsTableColFrame* colFrame;
PRInt32 colIndex;
GetColIndex(colIndex);
aTableFrame->GetColumnFrame(colIndex, colFrame);
if (colFrame) {
const nsStyleText* colTextStyle;
colFrame->GetStyleData(eStyleStruct_Text,(const nsStyleStruct *&)colTextStyle);
if (colTextStyle->mTextAlign.GetUnit() == eStyleUnit_Enumerated)
{
nsStyleText* mutableTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
mutableTextStyle->mTextAlign.SetIntValue(colTextStyle->mTextAlign.GetIntValue(), eStyleUnit_Enumerated);
if (NS_STYLE_TEXT_ALIGN_DEFAULT != colTextStyle->mTextAlign) {
nsStyleText* cellTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
cellTextStyle->mTextAlign = colTextStyle->mTextAlign;
return; // halign set from COL info
}
}
}
// otherwise, set the vertical align attribute to the HTML default (center for TH, left for TD and all others)
nsStyleText* mutableTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
nsIAtom *tag=nsnull;
if (nsnull!=mContent)
// otherwise, set the text align to the HTML default (center for TH, left for TD)
nsStyleText* cellTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
nsIAtom* tag;
if (mContent) {
mContent->GetTag(tag);
if (nsHTMLAtoms::th==tag)
mutableTextStyle->mVerticalAlign.SetIntValue(NS_STYLE_TEXT_ALIGN_CENTER, eStyleUnit_Enumerated);
else
mutableTextStyle->mVerticalAlign.SetIntValue(NS_STYLE_TEXT_ALIGN_LEFT, eStyleUnit_Enumerated);
if (tag) {
cellTextStyle->mTextAlign = (nsHTMLAtoms::th == tag)
? NS_STYLE_TEXT_ALIGN_CENTER
: NS_STYLE_TEXT_ALIGN_LEFT;
}
NS_IF_RELEASE(tag);
}
#endif
}

View File

@ -153,14 +153,15 @@ table {
}
/* must never set padding in td, th */
td, th {
td {
vertical-align: inherit;
text-align: left;
text-align: inherit;
display: table-cell;
}
th {
font-weight: bold;
text-align: center;
vertical-align: inherit;
display: table-cell;
}
caption {
text-align: center;

View File

@ -186,13 +186,10 @@ HTMLDocumentColorRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresCon
return NS_OK;
}
// -----------------------------------------------------------
// this rule only applies in NavQuirks mode
// -----------------------------------------------------------
class TableBackgroundRule: public nsIStyleRule {
class GenericTableRule: public nsIStyleRule {
public:
TableBackgroundRule(nsIHTMLStyleSheet* aSheet);
virtual ~TableBackgroundRule();
GenericTableRule(nsIHTMLStyleSheet* aSheet);
virtual ~GenericTableRule();
NS_DECL_ISUPPORTS
@ -213,34 +210,34 @@ public:
nsIHTMLStyleSheet* mSheet; // not ref-counted, cleared by content
};
TableBackgroundRule::TableBackgroundRule(nsIHTMLStyleSheet* aSheet)
GenericTableRule::GenericTableRule(nsIHTMLStyleSheet* aSheet)
{
NS_INIT_REFCNT();
mSheet = aSheet;
}
TableBackgroundRule::~TableBackgroundRule()
GenericTableRule::~GenericTableRule()
{
}
NS_IMPL_ISUPPORTS(TableBackgroundRule, kIStyleRuleIID);
NS_IMPL_ISUPPORTS(GenericTableRule, kIStyleRuleIID);
NS_IMETHODIMP
TableBackgroundRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
GenericTableRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
{
aResult = PRBool(this == aRule);
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::HashValue(PRUint32& aValue) const
GenericTableRule::HashValue(PRUint32& aValue) const
{
aValue = 0;
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
GenericTableRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
aSheet = mSheet;
return NS_OK;
@ -249,18 +246,50 @@ TableBackgroundRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
// Strength is an out-of-band weighting, useful for mapping CSS ! important
// always 0 here
NS_IMETHODIMP
TableBackgroundRule::GetStrength(PRInt32& aStrength) const
GenericTableRule::GetStrength(PRInt32& aStrength) const
{
aStrength = 0;
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::MapFontStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
GenericTableRule::MapFontStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
return NS_OK;
}
NS_IMETHODIMP
GenericTableRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
return NS_OK;
}
NS_IMETHODIMP
GenericTableRule::List(FILE* out, PRInt32 aIndent) const
{
return NS_OK;
}
// -----------------------------------------------------------
// this rule only applies in NavQuirks mode
// -----------------------------------------------------------
class TableBackgroundRule: public GenericTableRule {
public:
TableBackgroundRule(nsIHTMLStyleSheet* aSheet);
virtual ~TableBackgroundRule();
NS_IMETHOD MapStyleInto(nsIMutableStyleContext* aContext,
nsIPresContext* aPresContext);
};
TableBackgroundRule::TableBackgroundRule(nsIHTMLStyleSheet* aSheet)
: GenericTableRule(aSheet)
{
}
TableBackgroundRule::~TableBackgroundRule()
{
}
NS_IMETHODIMP
TableBackgroundRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
@ -288,9 +317,44 @@ TableBackgroundRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresConte
return NS_OK;
}
NS_IMETHODIMP
TableBackgroundRule::List(FILE* out, PRInt32 aIndent) const
// -----------------------------------------------------------
// this rule handles <th> inheritance
// -----------------------------------------------------------
class TableTHRule: public GenericTableRule {
public:
TableTHRule(nsIHTMLStyleSheet* aSheet);
virtual ~TableTHRule();
NS_IMETHOD MapStyleInto(nsIMutableStyleContext* aContext,
nsIPresContext* aPresContext);
};
TableTHRule::TableTHRule(nsIHTMLStyleSheet* aSheet)
: GenericTableRule(aSheet)
{
}
TableTHRule::~TableTHRule()
{
}
NS_IMETHODIMP
TableTHRule::MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext)
{
nsIStyleContext* parentContext = aContext->GetParent();
if (parentContext) {
nsStyleText* styleText =
(nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text);
if (NS_STYLE_TEXT_ALIGN_DEFAULT == styleText->mTextAlign) {
const nsStyleText* parentStyleText =
(const nsStyleText*)parentContext->GetStyleData(eStyleStruct_Text);
PRUint8 parentAlign = parentStyleText->mTextAlign;
styleText->mTextAlign = (NS_STYLE_TEXT_ALIGN_DEFAULT == parentAlign)
? NS_STYLE_TEXT_ALIGN_CENTER : parentAlign;
}
}
return NS_OK;
}
@ -474,6 +538,7 @@ protected:
HTMLColorRule* mActiveRule;
HTMLDocumentColorRule* mDocumentColorRule;
TableBackgroundRule* mTableBackgroundRule;
TableTHRule* mTableTHRule;
nsHashtable mMappedAttrTable;
};
@ -524,6 +589,8 @@ HTMLStyleSheetImpl::HTMLStyleSheetImpl(void)
NS_INIT_REFCNT();
mTableBackgroundRule = new TableBackgroundRule(this);
NS_ADDREF(mTableBackgroundRule);
mTableTHRule = new TableTHRule(this);
NS_ADDREF(mTableTHRule);
}
PRBool MappedDropSheet(nsHashKey *aKey, void *aData, void* closure)
@ -556,6 +623,10 @@ HTMLStyleSheetImpl::~HTMLStyleSheetImpl()
mTableBackgroundRule->mSheet = nsnull;
NS_RELEASE(mTableBackgroundRule);
}
if (nsnull != mTableTHRule) {
mTableTHRule->mSheet = nsnull;
NS_RELEASE(mTableTHRule);
}
mMappedAttrTable.Enumerate(MappedDropSheet);
}
@ -709,12 +780,17 @@ HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
} // end active rule
} // end A tag
// add the quirks background compatibility rule if in quirks mode
// and/or the Table TH rule for handling <TH> differently than <TD>
else if ((tag == nsHTMLAtoms::td) ||
(tag == nsHTMLAtoms::th) ||
(tag == nsHTMLAtoms::tr) ||
(tag == nsHTMLAtoms::thead) || // Nav4.X doesn't support row groups, but it is a lot
(tag == nsHTMLAtoms::tbody) || // easier passing from the table to rows this way
(tag == nsHTMLAtoms::tfoot)) {
// add the rule to handle text-align for a <th>
if (tag == nsHTMLAtoms::th) {
aResults->AppendElement(mTableTHRule);
}
nsCompatibility mode;
aPresContext->GetCompatibilityMode(&mode);
if (eCompatibility_NavQuirks == mode) {
@ -909,6 +985,10 @@ NS_IMETHODIMP HTMLStyleSheetImpl::Reset(nsIURI* aURL)
mTableBackgroundRule->mSheet = nsnull;
NS_RELEASE(mTableBackgroundRule);
}
if (mTableTHRule) {
mTableTHRule->mSheet = nsnull;
NS_RELEASE(mTableTHRule);
}
mMappedAttrTable.Enumerate(MappedDropSheet);
mMappedAttrTable.Reset();

View File

@ -917,14 +917,13 @@ void nsTableCellFrame::MapVAlignAttribute(nsIPresContext* aPresContext, nsTableF
const nsStyleText* textStyle;
GetStyleData(eStyleStruct_Text,(const nsStyleStruct *&)textStyle);
// check if valign is set on the cell
// this condition will also be true if we inherited valign from the row or rowgroup
if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated)
{
// this condition will also be true if we inherited valign from the row or rowgroup
if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
return; // valign is already set on this cell
}
// check if valign is set on the cell's COL (or COLGROUP by inheritance)
nsTableColFrame *colFrame;
nsTableColFrame* colFrame;
PRInt32 colIndex;
GetColIndex(colIndex);
aTableFrame->GetColumnFrame(colIndex, colFrame);
@ -932,70 +931,70 @@ void nsTableCellFrame::MapVAlignAttribute(nsIPresContext* aPresContext, nsTableF
const nsStyleText* colTextStyle;
colFrame->GetStyleData(eStyleStruct_Text,(const nsStyleStruct *&)colTextStyle);
if (colTextStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
nsStyleText* mutableTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
mutableTextStyle->mVerticalAlign.SetIntValue(colTextStyle->mVerticalAlign.GetIntValue(), eStyleUnit_Enumerated);
nsStyleText* cellTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
cellTextStyle->mVerticalAlign.SetIntValue(colTextStyle->mVerticalAlign.GetIntValue(), eStyleUnit_Enumerated);
return; // valign set from COL info
}
}
}
// otherwise, set the vertical align attribute to the HTML default
nsStyleText* mutableTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
mutableTextStyle->mVerticalAlign.SetIntValue(NS_STYLE_VERTICAL_ALIGN_MIDDLE, eStyleUnit_Enumerated);
nsStyleText* cellTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
cellTextStyle->mVerticalAlign.SetIntValue(NS_STYLE_VERTICAL_ALIGN_MIDDLE, eStyleUnit_Enumerated);
}
/* XXX: this code will not work properly until the style and layout code has been updated
* as outlined in Bugzilla bug report 1802 and 915.
* In particular, mTextAlign has to be an nsStyleCoord, not just an int */
void nsTableCellFrame::MapHAlignAttribute(nsIPresContext* aPresContext, nsTableFrame *aTableFrame)
void nsTableCellFrame::MapHAlignAttribute(nsIPresContext* aPresContext,
nsTableFrame* aTableFrame)
{
#if 0
const nsStyleText* textStyle;
GetStyleData(eStyleStruct_Text,(const nsStyleStruct *&)textStyle);
// check if halign is set on the cell
// cells do not inherited halign from the row or rowgroup
if (textStyle->mTextAlign.GetUnit() == eStyleUnit_Enumerated)
{
if (textStyle->mTextAlign.GetIntValue() != NS_STYLE_TEXT_ALIGN_DEFAULT)
return; // valign is already set on this cell
// cells do not inherited halign from the row or rowgroup
if (NS_STYLE_TEXT_ALIGN_DEFAULT != textStyle->mTextAlign) {
return; // text align is already set on this cell
}
// check if halign is set on the cell's ROW (or ROWGROUP by inheritance)
nsIFrame *rowFrame;
aTableFrame->GetContentParent(rowFrame);
nsIFrame* rowFrame;
GetParent(&rowFrame);
const nsStyleText* rowTextStyle;
rowFrame->GetStyleData(eStyleStruct_Text,(const nsStyleStruct *&)rowTextStyle);
if (rowTextStyle->mTextAlign.GetUnit() == eStyleUnit_Enumerated)
{
nsStyleText* mutableTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
mutableTextStyle->mTextAlign.SetIntValue(rowTextStyle->mTextAlign.GetIntValue(), eStyleUnit_Enumerated);
if (NS_STYLE_TEXT_ALIGN_DEFAULT != rowTextStyle->mTextAlign) {
nsStyleText* cellTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
cellTextStyle->mTextAlign = rowTextStyle->mTextAlign;
return; // halign set from ROW info
}
// check if halign is set on the cell's COL (or COLGROUP by inheritance)
nsTableColFrame *colFrame;
nsTableColFrame* colFrame;
PRInt32 colIndex;
GetColIndex(colIndex);
aTableFrame->GetColumnFrame(colIndex, colFrame);
if (colFrame) {
const nsStyleText* colTextStyle;
colFrame->GetStyleData(eStyleStruct_Text,(const nsStyleStruct *&)colTextStyle);
if (colTextStyle->mTextAlign.GetUnit() == eStyleUnit_Enumerated)
{
nsStyleText* mutableTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
mutableTextStyle->mTextAlign.SetIntValue(colTextStyle->mTextAlign.GetIntValue(), eStyleUnit_Enumerated);
if (NS_STYLE_TEXT_ALIGN_DEFAULT != colTextStyle->mTextAlign) {
nsStyleText* cellTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
cellTextStyle->mTextAlign = colTextStyle->mTextAlign;
return; // halign set from COL info
}
}
}
// otherwise, set the vertical align attribute to the HTML default (center for TH, left for TD and all others)
nsStyleText* mutableTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
nsIAtom *tag=nsnull;
if (nsnull!=mContent)
// otherwise, set the text align to the HTML default (center for TH, left for TD)
nsStyleText* cellTextStyle = (nsStyleText*)mStyleContext->GetMutableStyleData(eStyleStruct_Text);
nsIAtom* tag;
if (mContent) {
mContent->GetTag(tag);
if (nsHTMLAtoms::th==tag)
mutableTextStyle->mVerticalAlign.SetIntValue(NS_STYLE_TEXT_ALIGN_CENTER, eStyleUnit_Enumerated);
else
mutableTextStyle->mVerticalAlign.SetIntValue(NS_STYLE_TEXT_ALIGN_LEFT, eStyleUnit_Enumerated);
if (tag) {
cellTextStyle->mTextAlign = (nsHTMLAtoms::th == tag)
? NS_STYLE_TEXT_ALIGN_CENTER
: NS_STYLE_TEXT_ALIGN_LEFT;
}
NS_IF_RELEASE(tag);
}
#endif
}