diff --git a/layout/html/table/src/nsTableCell.cpp b/layout/html/table/src/nsTableCell.cpp index 994832dfe782..38a1aa71053d 100644 --- a/layout/html/table/src/nsTableCell.cpp +++ b/layout/html/table/src/nsTableCell.cpp @@ -23,6 +23,9 @@ #include "nsIPresContext.h" #include "nsHTMLIIDs.h" #include "nsHTMLAtoms.h" +#include "nsIPtr.h" + +NS_DEF_PTR(nsIStyleContext); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -215,21 +218,42 @@ void nsTableCell::MapAttributesInto(nsIStyleContext* aContext, NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); if (nsnull != mAttributes) { nsHTMLValue value; + nsStyleText* textStyle = nsnull; // align: enum GetAttribute(nsHTMLAtoms::align, value); if (value.GetUnit() == eHTMLUnit_Enumerated) { - nsStyleText* text = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - text->mTextAlign = value.GetIntValue(); + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mTextAlign = value.GetIntValue(); } // valign: enum GetAttribute(nsHTMLAtoms::valign, value); if (value.GetUnit() == eHTMLUnit_Enumerated) { - nsStyleText* text = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - text->mTextAlign = value.GetIntValue(); + if (nsnull==textStyle) + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mVerticalAlign.SetIntValue(value.GetIntValue(), eStyleUnit_Enumerated); + } + // otherwise check the row for valign and inherit it + else { + if (nsnull!=mRow) + { + // TODO: optimize by putting a flag on the row to say whether valign attr is set + nsHTMLValue rowAlignValue; + mRow->GetAttribute(nsHTMLAtoms::valign, rowAlignValue); + if (rowAlignValue.GetUnit() == eHTMLUnit_Enumerated) + { + PRUint8 rowVAlign = rowAlignValue.GetIntValue(); + if (NS_STYLE_VERTICAL_ALIGN_MIDDLE!=rowVAlign) + { + if (nsnull==textStyle) + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mVerticalAlign.SetIntValue(rowVAlign, eStyleUnit_Enumerated); + } + } + } } MapBackgroundAttributesInto(aContext, aPresContext); @@ -238,8 +262,9 @@ void nsTableCell::MapAttributesInto(nsIStyleContext* aContext, GetAttribute(nsHTMLAtoms::nowrap, value); if (value.GetUnit() == eHTMLUnit_Empty) { - nsStyleText* text = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - text->mWhiteSpace = NS_STYLE_WHITESPACE_NOWRAP; + if (nsnull==textStyle) + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mWhiteSpace = NS_STYLE_WHITESPACE_NOWRAP; } // width: pixel diff --git a/layout/html/table/src/nsTableRow.cpp b/layout/html/table/src/nsTableRow.cpp index 1f4d9bd1003b..8a9f54f4fd6d 100644 --- a/layout/html/table/src/nsTableRow.cpp +++ b/layout/html/table/src/nsTableRow.cpp @@ -29,6 +29,7 @@ #include "nsStyleConsts.h" #include "nsIContentDelegate.h" #include "nsHTMLIIDs.h" +#include "nsHTMLAtoms.h" #ifdef NS_DEBUG static PRBool gsDebug = PR_FALSE; @@ -254,6 +255,51 @@ nsTableRow::RemoveChildAt (int aIndex, PRBool aNotify) return rv; } +void nsTableRow::SetAttribute(nsIAtom* aAttribute, const nsString& aValue) +{ + NS_PRECONDITION(nsnull!=aAttribute, "bad attribute arg"); + nsHTMLValue val; + if ((aAttribute == nsHTMLAtoms::align) && + ParseDivAlignParam(aValue, val)) { + nsHTMLTagContent::SetAttribute(aAttribute, val); + return; + } + if ((aAttribute == nsHTMLAtoms::valign) && + ParseAlignParam(aValue, val)) { + nsHTMLTagContent::SetAttribute(aAttribute, val); + return; + } +} + +void nsTableRow::MapAttributesInto(nsIStyleContext* aContext, + nsIPresContext* aPresContext) +{ + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + if (nsnull != mAttributes) { + nsHTMLValue value; + nsStyleText* textStyle = nsnull; + + // align: enum + GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mTextAlign = value.GetIntValue(); + } + + // valign: enum + GetAttribute(nsHTMLAtoms::valign, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + if (nsnull==textStyle) + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mVerticalAlign.SetIntValue(value.GetIntValue(), eStyleUnit_Enumerated); + } + } +} + + nsresult nsTableRow::CreateFrame(nsIPresContext* aPresContext, nsIFrame* aParentFrame, diff --git a/layout/html/table/src/nsTableRow.h b/layout/html/table/src/nsTableRow.h index 974c15217c00..7b18dc99d793 100644 --- a/layout/html/table/src/nsTableRow.h +++ b/layout/html/table/src/nsTableRow.h @@ -69,6 +69,11 @@ public: /** returns nsITableContent::kTableRowType */ virtual int GetType(); + virtual void SetAttribute(nsIAtom* aAttribute, const nsString& aValue); + + virtual void MapAttributesInto(nsIStyleContext* aContext, + nsIPresContext* aPresContext); + /** @see nsIHTMLContent::CreateFrame */ virtual nsresult CreateFrame(nsIPresContext* aPresContext, nsIFrame* aParentFrame,