diff --git a/mozilla/content/html/content/src/makefile.win b/mozilla/content/html/content/src/makefile.win index 0b065850275..47ab2f2c65a 100644 --- a/mozilla/content/html/content/src/makefile.win +++ b/mozilla/content/html/content/src/makefile.win @@ -78,6 +78,7 @@ CPPSRCS= \ nsHTMLTableCaptionElement.cpp \ nsHTMLTableCellElement.cpp \ nsHTMLTableColElement.cpp \ + nsHTMLTableColGroupElement.cpp \ nsHTMLTableRowElement.cpp \ nsHTMLTableSectionElement.cpp \ nsHTMLTextAreaElement.cpp \ @@ -143,6 +144,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsHTMLTableCaptionElement.obj \ .\$(OBJDIR)\nsHTMLTableCellElement.obj \ .\$(OBJDIR)\nsHTMLTableColElement.obj \ + .\$(OBJDIR)\nsHTMLTableColGroupElement.obj \ .\$(OBJDIR)\nsHTMLTableRowElement.obj \ .\$(OBJDIR)\nsHTMLTableSectionElement.obj \ .\$(OBJDIR)\nsHTMLTextAreaElement.obj \ diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index cef73f58b73..fec252a2ddc 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -1866,6 +1866,32 @@ nsGenericHTMLElement::CreateFrame(nsIPresContext* aPresContext, rv = NS_NewWBRFrame(mContent, aParentFrame, frame); } + // the table content frames... + else if (mTag == nsHTMLAtoms::caption) { + rv = NS_NewBodyFrame(mContent, aParentFrame, frame); + } + else if (mTag == nsHTMLAtoms::table) { + rv = NS_NewTableFrame(mContent, aParentFrame, frame); + } + else if ((mTag == nsHTMLAtoms::tbody) || + (mTag == nsHTMLAtoms::thead) || + (mTag == nsHTMLAtoms::tfoot)) { + rv = NS_NewTableRowGroupFrame(mContent, aParentFrame, frame); + } + else if (mTag == nsHTMLAtoms::tr) { + rv = NS_NewTableRowFrame(mContent, aParentFrame, frame); + } + else if (mTag == nsHTMLAtoms::colgroup) { + rv = NS_NewTableColGroupFrame(mContent, aParentFrame, frame); + } + else if (mTag == nsHTMLAtoms::col) { + rv = NS_NewTableColFrame(mContent, aParentFrame, frame); + } + else if ((mTag == nsHTMLAtoms::td) || + (mTag == nsHTMLAtoms::th)) { + rv = NS_NewTableCellFrame(mContent, aParentFrame, frame); + } + if (NS_OK != rv) { return rv; } @@ -2489,6 +2515,23 @@ static nsGenericHTMLElement::EnumTable kScrollingStandardTable[] = { { 0 } }; +static nsGenericHTMLElement::EnumTable kTableHAlignTable[] = { + { "left", NS_STYLE_TEXT_ALIGN_LEFT }, + { "right", NS_STYLE_TEXT_ALIGN_RIGHT }, + { "center", NS_STYLE_TEXT_ALIGN_CENTER }, + { "char", NS_STYLE_TEXT_ALIGN_CHAR }, + { "justify",NS_STYLE_TEXT_ALIGN_JUSTIFY }, + { 0 } +}; + +static nsGenericHTMLElement::EnumTable kTableVAlignTable[] = { + { "top", NS_STYLE_VERTICAL_ALIGN_TOP }, + { "middle", NS_STYLE_VERTICAL_ALIGN_MIDDLE }, + { "bottom", NS_STYLE_VERTICAL_ALIGN_BOTTOM }, + { "baseline",NS_STYLE_VERTICAL_ALIGN_BASELINE }, + { 0 } +}; + PRBool nsGenericHTMLElement::ParseAlignValue(const nsString& aString, nsHTMLValue& aResult) @@ -2496,6 +2539,20 @@ nsGenericHTMLElement::ParseAlignValue(const nsString& aString, return ParseEnumValue(aString, kAlignTable, aResult); } +PRBool +nsGenericHTMLElement::ParseTableHAlignValue(const nsString& aString, + nsHTMLValue& aResult) +{ + return ParseEnumValue(aString, kTableHAlignTable, aResult); +} + +PRBool +nsGenericHTMLElement::ParseTableVAlignValue(const nsString& aString, + nsHTMLValue& aResult) +{ + return ParseEnumValue(aString, kTableVAlignTable, aResult); +} + PRBool nsGenericHTMLElement::AlignValueToString(const nsHTMLValue& aValue, nsString& aResult) @@ -2503,6 +2560,20 @@ nsGenericHTMLElement::AlignValueToString(const nsHTMLValue& aValue, return EnumValueToString(aValue, kAlignTable, aResult); } +PRBool +nsGenericHTMLElement::TableHAlignValueToString(const nsHTMLValue& aValue, + nsString& aResult) +{ + return EnumValueToString(aValue, kTableHAlignTable, aResult); +} + +PRBool +nsGenericHTMLElement::TableVAlignValueToString(const nsHTMLValue& aValue, + nsString& aResult) +{ + return EnumValueToString(aValue, kTableVAlignTable, aResult); +} + PRBool nsGenericHTMLElement::ParseDivAlignValue(const nsString& aString, nsHTMLValue& aResult) diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.h b/mozilla/content/html/content/src/nsGenericHTMLElement.h index 954b1a291a9..442533dd817 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.h +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.h @@ -238,6 +238,18 @@ public: static PRBool ParseDivAlignValue(const nsString& aString, nsHTMLValue& aResult); + static PRBool ParseTableHAlignValue(const nsString& aString, + nsHTMLValue& aResult); + + static PRBool ParseTableVAlignValue(const nsString& aString, + nsHTMLValue& aResult); + + static PRBool TableHAlignValueToString(const nsHTMLValue& aValue, + nsString& aResult); + + static PRBool TableVAlignValueToString(const nsHTMLValue& aValue, + nsString& aResult); + static PRBool AlignValueToString(const nsHTMLValue& aValue, nsString& aResult); diff --git a/mozilla/content/html/content/src/nsHTMLAtoms.cpp b/mozilla/content/html/content/src/nsHTMLAtoms.cpp index dc4e0cae588..c31e1918ea5 100644 --- a/mozilla/content/html/content/src/nsHTMLAtoms.cpp +++ b/mozilla/content/html/content/src/nsHTMLAtoms.cpp @@ -43,6 +43,7 @@ nsIAtom* nsHTMLAtoms::border; nsIAtom* nsHTMLAtoms::bordercolor; nsIAtom* nsHTMLAtoms::bottompadding; nsIAtom* nsHTMLAtoms::br; +nsIAtom* nsHTMLAtoms::caption; nsIAtom* nsHTMLAtoms::cellpadding; nsIAtom* nsHTMLAtoms::cellspacing; nsIAtom* nsHTMLAtoms::ch; @@ -58,6 +59,8 @@ nsIAtom* nsHTMLAtoms::code; nsIAtom* nsHTMLAtoms::codebase; nsIAtom* nsHTMLAtoms::codetype; nsIAtom* nsHTMLAtoms::color; +nsIAtom* nsHTMLAtoms::col; +nsIAtom* nsHTMLAtoms::colgroup; nsIAtom* nsHTMLAtoms::cols; nsIAtom* nsHTMLAtoms::colspan; nsIAtom* nsHTMLAtoms::columnPseudo; @@ -189,13 +192,17 @@ nsIAtom* nsHTMLAtoms::tabindex; nsIAtom* nsHTMLAtoms::table; nsIAtom* nsHTMLAtoms::tabstop; nsIAtom* nsHTMLAtoms::target; +nsIAtom* nsHTMLAtoms::tbody; nsIAtom* nsHTMLAtoms::td; +nsIAtom* nsHTMLAtoms::tfoot; +nsIAtom* nsHTMLAtoms::thead; nsIAtom* nsHTMLAtoms::text; nsIAtom* nsHTMLAtoms::textarea; nsIAtom* nsHTMLAtoms::th; nsIAtom* nsHTMLAtoms::title; nsIAtom* nsHTMLAtoms::top; nsIAtom* nsHTMLAtoms::toppadding; +nsIAtom* nsHTMLAtoms::tr; nsIAtom* nsHTMLAtoms::type; nsIAtom* nsHTMLAtoms::ul; nsIAtom* nsHTMLAtoms::usemap; @@ -243,6 +250,7 @@ void nsHTMLAtoms::AddrefAtoms() bordercolor = NS_NewAtom("BORDERCOLOR"); bottompadding = NS_NewAtom("BOTTOMPADDING"); br = NS_NewAtom("BR"); + caption = NS_NewAtom("CAPTION"); cellpadding = NS_NewAtom("CELLPADDING"); cellspacing = NS_NewAtom("CELLSPACING"); ch = NS_NewAtom("CH"); @@ -258,6 +266,8 @@ void nsHTMLAtoms::AddrefAtoms() codebase = NS_NewAtom("CODEBASE"); codetype = NS_NewAtom("CODETYPE"); color = NS_NewAtom("COLOR"); + col = NS_NewAtom("COL"); + colgroup = NS_NewAtom("COLGROUP"); cols = NS_NewAtom("COLS"); colspan = NS_NewAtom("COLSPAN"); columnPseudo = NS_NewAtom(":BODY-COLUMN"); @@ -388,13 +398,17 @@ void nsHTMLAtoms::AddrefAtoms() table = NS_NewAtom("TABLE"); tabstop = NS_NewAtom("TABSTOP"); target = NS_NewAtom("TARGET"); + tbody = NS_NewAtom("TBODY"); td = NS_NewAtom("TD"); + tfoot = NS_NewAtom("TFOOT"); + thead = NS_NewAtom("THEAD"); text = NS_NewAtom("TEXT"); textarea = NS_NewAtom("TEXTAREA"); th = NS_NewAtom("TH"); title = NS_NewAtom("TITLE"); top = NS_NewAtom("TOP"); toppadding = NS_NewAtom("TOPPADDING"); + tr = NS_NewAtom("TR"); type = NS_NewAtom("TYPE"); ul = NS_NewAtom("UL"); usemap = NS_NewAtom("USEMAP"); @@ -440,6 +454,7 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(bordercolor); NS_RELEASE(bottompadding); NS_RELEASE(br); + NS_RELEASE(caption); NS_RELEASE(cellpadding); NS_RELEASE(cellspacing); NS_RELEASE(ch); @@ -455,6 +470,8 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(codebase); NS_RELEASE(codetype); NS_RELEASE(color); + NS_RELEASE(col); + NS_RELEASE(colgroup); NS_RELEASE(cols); NS_RELEASE(colspan); NS_RELEASE(columnPseudo); @@ -579,12 +596,16 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(table); NS_RELEASE(tabstop); NS_RELEASE(target); + NS_RELEASE(tbody); NS_RELEASE(td); + NS_RELEASE(tfoot); + NS_RELEASE(thead); NS_RELEASE(text); NS_RELEASE(textarea); NS_RELEASE(th); NS_RELEASE(top); NS_RELEASE(toppadding); + NS_RELEASE(tr); NS_RELEASE(type); NS_RELEASE(ul); NS_RELEASE(usemap); diff --git a/mozilla/content/html/content/src/nsHTMLAtoms.h b/mozilla/content/html/content/src/nsHTMLAtoms.h index 0a55c79afe2..cec83e499d1 100644 --- a/mozilla/content/html/content/src/nsHTMLAtoms.h +++ b/mozilla/content/html/content/src/nsHTMLAtoms.h @@ -64,6 +64,7 @@ public: static nsIAtom* bottompadding; static nsIAtom* br; + static nsIAtom* caption; static nsIAtom* cellpadding; static nsIAtom* cellspacing; static nsIAtom* ch; @@ -79,6 +80,8 @@ public: static nsIAtom* codebase; static nsIAtom* codetype; static nsIAtom* color; + static nsIAtom* col; + static nsIAtom* colgroup; static nsIAtom* cols; static nsIAtom* colspan; static nsIAtom* columnPseudo; @@ -224,13 +227,17 @@ public: static nsIAtom* table; static nsIAtom* tabstop; static nsIAtom* target; + static nsIAtom* tbody; static nsIAtom* td; + static nsIAtom* tfoot; + static nsIAtom* thead; static nsIAtom* text; static nsIAtom* textarea; static nsIAtom* th; static nsIAtom* title; static nsIAtom* top; static nsIAtom* toppadding; + static nsIAtom* tr; static nsIAtom* type; static nsIAtom* ul; diff --git a/mozilla/content/html/content/src/nsHTMLTableCaptionElement.cpp b/mozilla/content/html/content/src/nsHTMLTableCaptionElement.cpp index e5503b7254a..60fb88f1f31 100644 --- a/mozilla/content/html/content/src/nsHTMLTableCaptionElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableCaptionElement.cpp @@ -26,6 +26,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" +#include "nsIHTMLAttributes.h" static NS_DEFINE_IID(kIDOMHTMLTableCaptionElementIID, NS_IDOMHTMLTABLECAPTIONELEMENT_IID); @@ -124,12 +125,24 @@ nsHTMLTableCaptionElement::CloneNode(nsIDOMNode** aReturn) NS_IMPL_STRING_ATTR(nsHTMLTableCaptionElement, Align, align, eSetAttrNotify_Reflow) +static nsGenericHTMLElement::EnumTable kTableCaptionAlignTable[] = { + { "left", NS_STYLE_TEXT_ALIGN_LEFT }, + { "right", NS_STYLE_TEXT_ALIGN_RIGHT }, + { "top", NS_STYLE_VERTICAL_ALIGN_TOP}, + { "bottom",NS_STYLE_VERTICAL_ALIGN_BOTTOM}, + { 0 } +}; + NS_IMETHODIMP nsHTMLTableCaptionElement::StringToAttribute(nsIAtom* aAttribute, const nsString& aValue, nsHTMLValue& aResult) { - // XXX write me + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseEnumValue(aValue, kTableCaptionAlignTable, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return NS_CONTENT_ATTR_NOT_THERE; } @@ -138,7 +151,12 @@ nsHTMLTableCaptionElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + if (aAttribute == nsHTMLAtoms::align) { + if (eHTMLUnit_Enumerated == aValue.GetUnit()) { + nsGenericHTMLElement::AlignValueToString(aValue, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return mInner.AttributeToString(aAttribute, aValue, aResult); } @@ -147,7 +165,32 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me + if (nsnull != aAttributes) { + nsHTMLValue value; + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) { + PRUint8 align = value.GetIntValue(); + nsStyleText* text = (nsStyleText*) + aContext->GetMutableStyleData(eStyleStruct_Text); + switch (align) { + case NS_STYLE_VERTICAL_ALIGN_TOP: + case NS_STYLE_VERTICAL_ALIGN_BOTTOM: + text->mVerticalAlign.SetIntValue(align, eStyleUnit_Enumerated); + break; + // XXX: this is not right, it sets the content's h-align + // what it should do is actually move the caption to the left or right of the table! + /* + case NS_STYLE_TEXT_ALIGN_LEFT: + case NS_STYLE_TEXT_ALIGN_RIGHT: + text->mTextAlign = align; + break; + */ + default: + // illegal value -- ignore it. + break; + } + } + } nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); } diff --git a/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp b/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp index 4ed7853d237..709f4ec697a 100644 --- a/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp @@ -16,10 +16,12 @@ * Corporation. Portions created by Netscape are Copyright (C) 1998 * Netscape Communications Corporation. All Rights Reserved. */ +#include "nsIHTMLTableCellElement.h" #include "nsIDOMHTMLTableCellElement.h" #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" +#include "nsIHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" @@ -28,29 +30,40 @@ #include "nsIPresContext.h" static NS_DEFINE_IID(kIDOMHTMLTableCellElementIID, NS_IDOMHTMLTABLECELLELEMENT_IID); +static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID); -class nsHTMLTableCellElement : public nsIDOMHTMLTableCellElement, - public nsIScriptObjectOwner, - public nsIDOMEventReceiver, - public nsIHTMLContent +class nsHTMLTableCellElement : public nsIHTMLTableCellElement, + public nsIDOMHTMLTableCellElement, + public nsIScriptObjectOwner, + public nsIDOMEventReceiver, + public nsIHTMLContent { public: nsHTMLTableCellElement(nsIAtom* aTag); ~nsHTMLTableCellElement(); - // nsISupports +// nsISupports NS_DECL_ISUPPORTS - // nsIDOMNode +// nsIHTMLTableCellElement + + /** @return the starting column for this cell. Always >= 1 */ + NS_METHOD GetColIndex (PRInt32* aColIndex); + + /** set the starting column for this cell. Always >= 1 */ + NS_METHOD SetColIndex (PRInt32 aColIndex); + + +// nsIDOMNode NS_IMPL_IDOMNODE_USING_GENERIC(mInner) - // nsIDOMElement +// nsIDOMElement NS_IMPL_IDOMELEMENT_USING_GENERIC(mInner) - // nsIDOMHTMLElement +// nsIDOMHTMLElement NS_IMPL_IDOMHTMLELEMENT_USING_GENERIC(mInner) - // nsIDOMHTMLTableCellElement +// nsIDOMHTMLTableCellElement NS_IMETHOD GetCellIndex(PRInt32* aCellIndex); NS_IMETHOD SetCellIndex(PRInt32 aCellIndex); NS_IMETHOD GetAbbr(nsString& aAbbr); @@ -82,20 +95,21 @@ public: NS_IMETHOD GetWidth(nsString& aWidth); NS_IMETHOD SetWidth(const nsString& aWidth); - // nsIScriptObjectOwner +// nsIScriptObjectOwner NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC(mInner) - // nsIDOMEventReceiver +// nsIDOMEventReceiver NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC(mInner) - // nsIContent +// nsIContent NS_IMPL_ICONTENT_USING_GENERIC(mInner) - // nsIHTMLContent +// nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) protected: nsGenericHTMLContainerElement mInner; + PRInt32 mColIndex; }; nsresult @@ -116,6 +130,7 @@ nsHTMLTableCellElement::nsHTMLTableCellElement(nsIAtom* aTag) { NS_INIT_REFCNT(); mInner.Init(this, aTag); + mColIndex=0; } nsHTMLTableCellElement::~nsHTMLTableCellElement() @@ -136,6 +151,12 @@ nsHTMLTableCellElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) mRefCnt++; return NS_OK; } + else if (aIID.Equals(kIHTMLTableCellElementIID)) { + nsIHTMLTableCellElement* tmp = this; + *aInstancePtr = (void*) tmp; + mRefCnt++; + return NS_OK; + } return NS_NOINTERFACE; } @@ -150,6 +171,20 @@ nsHTMLTableCellElement::CloneNode(nsIDOMNode** aReturn) return it->QueryInterface(kIDOMNodeIID, (void**) aReturn); } +/** @return the starting column for this cell in aColIndex. Always >= 1 */ +NS_METHOD nsHTMLTableCellElement::GetColIndex (PRInt32* aColIndex) +{ + *aColIndex = mColIndex; + return NS_OK; +} + +/** set the starting column for this cell. Always >= 1 */ +NS_METHOD nsHTMLTableCellElement::SetColIndex (PRInt32 aColIndex) +{ + mColIndex = aColIndex; + return NS_OK; +} + NS_IMETHODIMP nsHTMLTableCellElement::GetCellIndex(PRInt32* aCellIndex) { @@ -179,12 +214,73 @@ NS_IMPL_STRING_ATTR(nsHTMLTableCellElement, Scope, scope, eSetAttrNotify_None) NS_IMPL_STRING_ATTR(nsHTMLTableCellElement, VAlign, valign, eSetAttrNotify_Reflow) NS_IMPL_STRING_ATTR(nsHTMLTableCellElement, Width, width, eSetAttrNotify_Reflow) + +static nsGenericHTMLElement::EnumTable kCellScopeTable[] = { + { "row", NS_STYLE_CELL_SCOPE_ROW }, + { "col", NS_STYLE_CELL_SCOPE_COL }, + { "rowgroup", NS_STYLE_CELL_SCOPE_ROWGROUP }, + { "colgroup", NS_STYLE_CELL_SCOPE_COLGROUP }, + { 0 } +}; + NS_IMETHODIMP nsHTMLTableCellElement::StringToAttribute(nsIAtom* aAttribute, const nsString& aValue, nsHTMLValue& aResult) { - // XXX write me + /* ignore these attributes, stored simply as strings + abbr, axis, ch, headers + */ + /* attributes that resolve to integers */ + if ((aAttribute == nsHTMLAtoms::choff) || + (aAttribute == nsHTMLAtoms::colspan) || + (aAttribute == nsHTMLAtoms::rowspan)) { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Integer); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents */ + else if (aAttribute == nsHTMLAtoms::height) { + nsGenericHTMLElement::ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents or proportions */ + else if (aAttribute == nsHTMLAtoms::width) { + nsGenericHTMLElement::ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* other attributes */ + else if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseTableHAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::background) { + nsAutoString href(aValue); + href.StripWhitespace(); + aResult.SetStringValue(href); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::bgcolor) { + nsGenericHTMLElement::ParseColor(aValue, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::nowrap) { + aResult.SetEmptyValue(); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::scope) { + if (nsGenericHTMLElement::ParseEnumValue(aValue, kCellScopeTable, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::ParseTableVAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return NS_CONTENT_ATTR_NOT_THERE; } @@ -193,7 +289,27 @@ nsHTMLTableCellElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + /* ignore these attributes, stored already as strings + abbr, axis, ch, headers + */ + /* ignore attributes that are of standard types + choff, colspan, rowspan, height, width, nowrap, background, bgcolor + */ + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::TableHAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::scope) { + if (nsGenericHTMLElement::EnumValueToString(aValue, kCellScopeTable, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::TableVAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return mInner.AttributeToString(aAttribute, aValue, aResult); } @@ -202,8 +318,68 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + + if (nsnull!=aAttributes) + { + nsHTMLValue value; + nsHTMLValue widthValue; + nsStyleText* textStyle = nsnull; + + // align: enum + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mTextAlign = value.GetIntValue(); + } + + // valign: enum + aAttributes->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); + } + + // width: pixel + float p2t = aPresContext->GetPixelsToTwips(); + nsStylePosition* pos = (nsStylePosition*) + aContext->GetMutableStyleData(eStyleStruct_Position); + aAttributes->GetAttribute(nsHTMLAtoms::width, widthValue); + if (widthValue.GetUnit() == eHTMLUnit_Pixel) { + nscoord twips = NSIntPixelsToTwips(widthValue.GetPixelValue(), p2t); + pos->mWidth.SetCoordValue(twips); + } + else if (widthValue.GetUnit() == eHTMLUnit_Percent) { + pos->mWidth.SetPercentValue(widthValue.GetPercentValue()); + } + + // height: pixel + aAttributes->GetAttribute(nsHTMLAtoms::height, value); + if (value.GetUnit() == eHTMLUnit_Pixel) { + nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t); + pos->mHeight.SetCoordValue(twips); + } + + // nowrap + // nowrap depends on the width attribute, so be sure to handle it after width is mapped! + aAttributes->GetAttribute(nsHTMLAtoms::nowrap, value); + if (value.GetUnit() == eHTMLUnit_Empty) + { + if (widthValue.GetUnit() != eHTMLUnit_Pixel) + { + if (nsnull==textStyle) + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mWhiteSpace = NS_STYLE_WHITESPACE_NOWRAP; + } + } + + nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); + nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + } } NS_IMETHODIMP diff --git a/mozilla/content/html/content/src/nsHTMLTableColElement.cpp b/mozilla/content/html/content/src/nsHTMLTableColElement.cpp index 1169edb826b..850e382bfec 100644 --- a/mozilla/content/html/content/src/nsHTMLTableColElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableColElement.cpp @@ -17,9 +17,11 @@ * Netscape Communications Corporation. All Rights Reserved. */ #include "nsIDOMHTMLTableColElement.h" +#include "nsIHTMLTableColElement.h" #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" +#include "nsIHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" @@ -28,11 +30,13 @@ #include "nsIPresContext.h" static NS_DEFINE_IID(kIDOMHTMLTableColElementIID, NS_IDOMHTMLTABLECOLELEMENT_IID); +static NS_DEFINE_IID(kIHTMLTableColElementIID, NS_IHTMLTABLECOLELEMENT_IID); -class nsHTMLTableColElement : public nsIDOMHTMLTableColElement, - public nsIScriptObjectOwner, - public nsIDOMEventReceiver, - public nsIHTMLContent +class nsHTMLTableColElement : public nsIDOMHTMLTableColElement, + public nsIScriptObjectOwner, + public nsIDOMEventReceiver, + public nsIHTMLContent, + public nsIHTMLTableColElement { public: nsHTMLTableColElement(nsIAtom* aTag); @@ -76,6 +80,9 @@ public: // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) + // nsIHTMLTableColElement + NS_IMETHOD GetSpanValue(PRInt32* aSpan); + protected: nsGenericHTMLContainerElement mInner; }; @@ -118,6 +125,12 @@ nsHTMLTableColElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) mRefCnt++; return NS_OK; } + if (aIID.Equals(kIHTMLTableColElementIID)) { + nsIHTMLTableColElement* tmp = this; + *aInstancePtr = (void*) tmp; + mRefCnt++; + return NS_OK; + } return NS_NOINTERFACE; } @@ -144,7 +157,36 @@ nsHTMLTableColElement::StringToAttribute(nsIAtom* aAttribute, const nsString& aValue, nsHTMLValue& aResult) { - // XXX write me + /* ignore these attributes, stored simply as strings + ch + */ + /* attributes that resolve to integers */ + if (aAttribute == nsHTMLAtoms::choff) { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Integer); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::repeat) { + nsGenericHTMLElement::ParseValue(aValue, 1, aResult, eHTMLUnit_Integer); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents or proportions */ + else if (aAttribute == nsHTMLAtoms::width) { + nsGenericHTMLElement::ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* other attributes */ + else if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseTableHAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::ParseTableVAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return NS_CONTENT_ATTR_NOT_THERE; } @@ -153,7 +195,22 @@ nsHTMLTableColElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + /* ignore these attributes, stored already as strings + ch + */ + /* ignore attributes that are of standard types + choff, repeat, width + */ + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::TableHAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::TableVAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return mInner.AttributeToString(aAttribute, aValue, aResult); } @@ -162,10 +219,52 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + if (nsnull != aAttributes) { + + float p2t; + nsHTMLValue value; + nsStyleText* textStyle = nsnull; + + // width + aAttributes->GetAttribute(nsHTMLAtoms::width, value); + if (value.GetUnit() != eHTMLUnit_Null) { + nsStylePosition* position = (nsStylePosition*) + aContext->GetMutableStyleData(eStyleStruct_Position); + switch (value.GetUnit()) { + case eHTMLUnit_Percent: + position->mWidth.SetPercentValue(value.GetPercentValue()); + break; + + case eHTMLUnit_Pixel: + p2t = aPresContext->GetPixelsToTwips(); + position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + break; + } + } + + // align: enum + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mTextAlign = value.GetIntValue(); + } + + // valign: enum + aAttributes->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); + } + } nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); } + NS_IMETHODIMP nsHTMLTableColElement::GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const { @@ -184,3 +283,16 @@ nsHTMLTableColElement::HandleDOMEvent(nsIPresContext& aPresContext, return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); } + +NS_METHOD nsHTMLTableColElement::GetSpanValue(PRInt32* aSpan) +{ + if (nsnull!=aSpan) + { + PRInt32 span=-1; + GetSpan(&span); + if (-1==span) + span=1; // the default; + *aSpan = span; + } + return NS_OK; +} \ No newline at end of file diff --git a/mozilla/content/html/content/src/nsHTMLTableElement.cpp b/mozilla/content/html/content/src/nsHTMLTableElement.cpp index c3e141a738b..4a4fcd20f6b 100644 --- a/mozilla/content/html/content/src/nsHTMLTableElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableElement.cpp @@ -20,6 +20,7 @@ #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" +#include "nsIHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" @@ -156,6 +157,9 @@ nsHTMLTableElement::CloneNode(nsIDOMNode** aReturn) return it->QueryInterface(kIDOMNodeIID, (void**) aReturn); } +// the DOM spec says border, cellpadding, cellSpacing are all "wstring" +// in fact, they are integers or they are meaningless. so we store them here as ints. + NS_IMPL_STRING_ATTR(nsHTMLTableElement, Align, align, eSetAttrNotify_Reflow) NS_IMPL_STRING_ATTR(nsHTMLTableElement, BgColor, bgcolor, eSetAttrNotify_Render) NS_IMPL_STRING_ATTR(nsHTMLTableElement, Border, border, eSetAttrNotify_Reflow) @@ -283,12 +287,109 @@ nsHTMLTableElement::DeleteRow(PRInt32 aValue) return NS_OK; // XXX write me } +static nsGenericHTMLElement::EnumTable kFrameTable[] = { + { "void", NS_STYLE_TABLE_FRAME_NONE }, + { "above", NS_STYLE_TABLE_FRAME_ABOVE }, + { "below", NS_STYLE_TABLE_FRAME_BELOW }, + { "hsides", NS_STYLE_TABLE_FRAME_HSIDES }, + { "lhs", NS_STYLE_TABLE_FRAME_LEFT }, + { "rhs", NS_STYLE_TABLE_FRAME_RIGHT }, + { "vsides", NS_STYLE_TABLE_FRAME_VSIDES }, + { "box", NS_STYLE_TABLE_FRAME_BOX }, + { "border", NS_STYLE_TABLE_FRAME_BORDER }, + { 0 } +}; + +static nsGenericHTMLElement::EnumTable kRulesTable[] = { + { "none", NS_STYLE_TABLE_RULES_NONE }, + { "groups", NS_STYLE_TABLE_RULES_GROUPS }, + { "rows", NS_STYLE_TABLE_RULES_ROWS }, + { "cols", NS_STYLE_TABLE_RULES_COLS }, + { "all", NS_STYLE_TABLE_RULES_ALL }, + { 0 } +}; + + NS_IMETHODIMP nsHTMLTableElement::StringToAttribute(nsIAtom* aAttribute, - const nsString& aValue, - nsHTMLValue& aResult) + const nsString& aValue, + nsHTMLValue& aResult) { - // XXX write me + /* ignore summary, just a string */ + /* attributes that resolve to pixels */ + if ((aAttribute == nsHTMLAtoms::cellspacing) || + (aAttribute == nsHTMLAtoms::cellpadding)) { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that are either empty, or integers */ + else if (aAttribute == nsHTMLAtoms::cols) { + nsAutoString tmp(aValue); + tmp.StripWhitespace(); + if (0 == tmp.Length()) { + // Just set COLS, same as COLS=number of columns + aResult.SetEmptyValue(); + } + else + { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Integer); + } + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that are either empty, or pixels */ + else if (aAttribute == nsHTMLAtoms::cols) { + nsAutoString tmp(aValue); + tmp.StripWhitespace(); + if (0 == tmp.Length()) { + // Just enable the border; same as border=1 + aResult.SetEmptyValue(); + } + else + { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Pixel); + } + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents */ + else if (aAttribute == nsHTMLAtoms::height) { + nsGenericHTMLElement::ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents or proportions */ + else if (aAttribute == nsHTMLAtoms::width) { + nsGenericHTMLElement::ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* other attributes */ + else if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseTableHAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::background) { + nsAutoString href(aValue); + href.StripWhitespace(); + aResult.SetStringValue(href); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::bgcolor) { + nsGenericHTMLElement::ParseColor(aValue, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::frame) { + nsGenericHTMLElement::ParseEnumValue(aValue, kFrameTable, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::rules) { + nsGenericHTMLElement::ParseEnumValue(aValue, kRulesTable, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + return NS_CONTENT_ATTR_NOT_THERE; } @@ -297,17 +398,164 @@ nsHTMLTableElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + /* ignore summary, just a string */ + /* ignore attributes that are of standard types + border, cellpadding, cellspacing, cols, height, width, background, bgcolor + */ + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::TableHAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::frame) { + if (nsGenericHTMLElement::EnumValueToString(aValue, kFrameTable, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::rules) { + if (nsGenericHTMLElement::EnumValueToString(aValue, kRulesTable, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + return mInner.AttributeToString(aAttribute, aValue, aResult); } +// XXX: this is only sufficient for Nav4/HTML3.2 +// XXX: needs to be filled in for HTML4 +static void +MapTableBorderInto(nsIHTMLAttributes* aAttributes, + nsIStyleContext* aContext, + nsIPresContext* aPresContext) +{ + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + + nsHTMLValue value; + + aAttributes->GetAttribute(nsHTMLAtoms::border, value); + if (value.GetUnit() == eHTMLUnit_String) + { + nsAutoString borderAsString; + value.GetStringValue(borderAsString); + nsGenericHTMLElement::ParseValue(borderAsString, 0, value, eHTMLUnit_Pixel); + } + if ((value.GetUnit() == eHTMLUnit_Pixel) || + (value.GetUnit() == eHTMLUnit_Empty)) { + nsStyleSpacing* spacing = (nsStyleSpacing*) + aContext->GetMutableStyleData(eStyleStruct_Spacing); + float p2t = aPresContext->GetPixelsToTwips(); + nsStyleCoord twips; + if (value.GetUnit() == eHTMLUnit_Empty) { + twips.SetCoordValue(NSIntPixelsToTwips(1, p2t)); + } + else { + twips.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + } + + spacing->mBorder.SetTop(twips); + spacing->mBorder.SetRight(twips); + spacing->mBorder.SetBottom(twips); + spacing->mBorder.SetLeft(twips); + + if (spacing->mBorderStyle[0] == NS_STYLE_BORDER_STYLE_NONE) { + spacing->mBorderStyle[0] = NS_STYLE_BORDER_STYLE_SOLID; + } + if (spacing->mBorderStyle[1] == NS_STYLE_BORDER_STYLE_NONE) { + spacing->mBorderStyle[1] = NS_STYLE_BORDER_STYLE_SOLID; + } + if (spacing->mBorderStyle[2] == NS_STYLE_BORDER_STYLE_NONE) { + spacing->mBorderStyle[2] = NS_STYLE_BORDER_STYLE_SOLID; + } + if (spacing->mBorderStyle[3] == NS_STYLE_BORDER_STYLE_NONE) { + spacing->mBorderStyle[3] = NS_STYLE_BORDER_STYLE_SOLID; + } + } +} + static void MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + + if (nsnull!=aAttributes) + { + float p2t = aPresContext->GetPixelsToTwips(); + nsHTMLValue value; + + // width + aAttributes->GetAttribute(nsHTMLAtoms::width, value); + if (value.GetUnit() != eHTMLUnit_Null) { + nsStylePosition* position = (nsStylePosition*) + aContext->GetMutableStyleData(eStyleStruct_Position); + switch (value.GetUnit()) { + case eHTMLUnit_Percent: + position->mWidth.SetPercentValue(value.GetPercentValue()); + break; + + case eHTMLUnit_Pixel: + position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + break; + } + } + // border + MapTableBorderInto(aAttributes, aContext, aPresContext); + + // align + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) { // it may be another type if illegal + nsStyleDisplay* display = (nsStyleDisplay*)aContext->GetMutableStyleData(eStyleStruct_Display); + switch (value.GetIntValue()) { + case NS_STYLE_TEXT_ALIGN_LEFT: + display->mFloats = NS_STYLE_FLOAT_LEFT; + break; + + case NS_STYLE_TEXT_ALIGN_RIGHT: + display->mFloats = NS_STYLE_FLOAT_RIGHT; + break; + } + } + + // cellpadding + nsStyleTable* tableStyle=nsnull; + aAttributes->GetAttribute(nsHTMLAtoms::cellpadding, value); + if (value.GetUnit() == eHTMLUnit_Pixel) { + tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + tableStyle->mCellPadding.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + } + + // cellspacing (reuses tableStyle if already resolved) + aAttributes->GetAttribute(nsHTMLAtoms::cellspacing, value); + if (value.GetUnit() == eHTMLUnit_Pixel) { + if (nsnull==tableStyle) + tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + tableStyle->mCellSpacing.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + } + else + { // XXX: remove me as soon as we get this from the style sheet + if (nsnull==tableStyle) + tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + tableStyle->mCellSpacing.SetCoordValue(NSIntPixelsToTwips(2, p2t)); + } + + // cols + aAttributes->GetAttribute(nsHTMLAtoms::cols, value); + if (value.GetUnit() != eHTMLUnit_Null) { + if (nsnull==tableStyle) + tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + if (value.GetUnit() == eHTMLUnit_Integer) + tableStyle->mCols = value.GetIntValue(); + else // COLS had no value, so it refers to all columns + tableStyle->mCols = NS_STYLE_TABLE_COLS_ALL; + } + + //background: color + nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); + nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + } } NS_IMETHODIMP diff --git a/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp b/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp index 794cb3985db..ca1bcff4b35 100644 --- a/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp @@ -20,6 +20,7 @@ #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" +#include "nsIHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" @@ -204,12 +205,54 @@ NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, Ch, ch, eSetAttrNotify_Reflow) NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, ChOff, choff, eSetAttrNotify_Reflow) NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, VAlign, valign, eSetAttrNotify_Reflow) + NS_IMETHODIMP nsHTMLTableRowElement::StringToAttribute(nsIAtom* aAttribute, const nsString& aValue, nsHTMLValue& aResult) { - // XXX write me + /* ignore these attributes, stored simply as strings + ch + */ + /* attributes that resolve to integers */ + if (aAttribute == nsHTMLAtoms::choff) { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Integer); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents */ + else if (aAttribute == nsHTMLAtoms::height) { + nsGenericHTMLElement::ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents or proportions */ + else if (aAttribute == nsHTMLAtoms::width) { + nsGenericHTMLElement::ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* other attributes */ + else if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseTableHAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::background) { + nsAutoString href(aValue); + href.StripWhitespace(); + aResult.SetStringValue(href); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::bgcolor) { + nsGenericHTMLElement::ParseColor(aValue, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::ParseTableVAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return NS_CONTENT_ATTR_NOT_THERE; } @@ -218,7 +261,22 @@ nsHTMLTableRowElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + /* ignore these attributes, stored already as strings + ch + */ + /* ignore attributes that are of standard types + choff, height, width, background, bgcolor + */ + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::TableHAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::TableVAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return mInner.AttributeToString(aAttribute, aValue, aResult); } @@ -227,8 +285,44 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + + if (nsnull!=aAttributes) + { + nsHTMLValue value; + nsHTMLValue widthValue; + nsStyleText* textStyle = nsnull; + + // align: enum + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mTextAlign = value.GetIntValue(); + } + + // valign: enum + aAttributes->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); + } + + // height: pixel + aAttributes->GetAttribute(nsHTMLAtoms::height, value); + if (value.GetUnit() == eHTMLUnit_Pixel) { + float p2t = aPresContext->GetPixelsToTwips(); + nsStylePosition* pos = (nsStylePosition*) + aContext->GetMutableStyleData(eStyleStruct_Position); + nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t); + pos->mHeight.SetCoordValue(twips); + } + nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); + nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + } } NS_IMETHODIMP diff --git a/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp b/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp index cfa8d1ce995..f1ffad73d03 100644 --- a/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp @@ -20,6 +20,7 @@ #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" +#include "nsIHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" @@ -29,6 +30,8 @@ static NS_DEFINE_IID(kIDOMHTMLTableSectionElementIID, NS_IDOMHTMLTABLESECTIONELEMENT_IID); +// you will see the phrases "rowgroup" and "section" used interchangably + class nsHTMLTableSectionElement : public nsIDOMHTMLTableSectionElement, public nsIScriptObjectOwner, public nsIDOMEventReceiver, @@ -166,7 +169,43 @@ nsHTMLTableSectionElement::StringToAttribute(nsIAtom* aAttribute, const nsString& aValue, nsHTMLValue& aResult) { - // XXX write me + /* ignore these attributes, stored simply as strings + ch + */ + /* attributes that resolve to integers */ + if (aAttribute == nsHTMLAtoms::choff) { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Integer); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents */ + else if (aAttribute == nsHTMLAtoms::height) { + nsGenericHTMLElement::ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* other attributes */ + else if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseTableHAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::background) { + nsAutoString href(aValue); + href.StripWhitespace(); + aResult.SetStringValue(href); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::bgcolor) { + nsGenericHTMLElement::ParseColor(aValue, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::ParseTableVAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + return NS_CONTENT_ATTR_NOT_THERE; } @@ -175,7 +214,22 @@ nsHTMLTableSectionElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + /* ignore these attributes, stored already as strings + ch + */ + /* ignore attributes that are of standard types + choff, height, width, background, bgcolor + */ + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::TableHAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::TableVAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return mInner.AttributeToString(aAttribute, aValue, aResult); } @@ -184,8 +238,45 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + + if (nsnull!=aAttributes) + { + nsHTMLValue value; + nsHTMLValue widthValue; + nsStyleText* textStyle = nsnull; + + // align: enum + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mTextAlign = value.GetIntValue(); + } + + // valign: enum + aAttributes->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); + } + + // height: pixel + aAttributes->GetAttribute(nsHTMLAtoms::height, value); + if (value.GetUnit() == eHTMLUnit_Pixel) { + float p2t = aPresContext->GetPixelsToTwips(); + nsStylePosition* pos = (nsStylePosition*) + aContext->GetMutableStyleData(eStyleStruct_Position); + nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t); + pos->mHeight.SetCoordValue(twips); + } + nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); + nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + } + } NS_IMETHODIMP diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index abb7cdff3dd..7ec6fe90e8a 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -34,10 +34,6 @@ #include "nsHTMLParts.h" #include "nsITextContent.h" - -#include "nsTablePart.h" -#include "nsTableRow.h" -#include "nsTableCell.h" #include "nsIDOMText.h" #include "nsHTMLForms.h" @@ -487,13 +483,13 @@ MakeContentObject(nsHTMLTag aNodeType, rv = NS_NewHTMLBRElement(aResult, aAtom); break; case eHTMLTag_caption: - rv = NS_NewTableCaptionPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableCaptionElement(aResult, aAtom); break; case eHTMLTag_col: - rv = NS_NewTableColPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableColElement(aResult, aAtom); break; case eHTMLTag_colgroup: - rv = NS_NewTableColGroupPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableColGroupElement(aResult, aAtom); break; case eHTMLTag_dir: rv = NS_NewHTMLDirectoryElement(aResult, aAtom); @@ -603,16 +599,16 @@ MakeContentObject(nsHTMLTag aNodeType, rv = NS_NewHTMLStyleElement(aResult, aAtom); break; case eHTMLTag_table: - rv = NS_NewTablePart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableElement(aResult, aAtom); break; case eHTMLTag_tbody: case eHTMLTag_thead: case eHTMLTag_tfoot: - rv = NS_NewTableRowGroupPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableSectionElement(aResult, aAtom); break; case eHTMLTag_td: case eHTMLTag_th: - rv = NS_NewTableCellPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableCellElement(aResult, aAtom); break; case eHTMLTag_textarea: rv = NS_NewHTMLTextAreaElement(aResult, aAtom); @@ -621,7 +617,7 @@ MakeContentObject(nsHTMLTag aNodeType, rv = NS_NewHTMLTitleElement(aResult, aAtom); break; case eHTMLTag_tr: - rv = NS_NewTableRowPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableRowElement(aResult, aAtom); break; case eHTMLTag_ul: rv = NS_NewHTMLUListElement(aResult, aAtom); diff --git a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp index afe16c1ea0f..f43a071509e 100644 --- a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp @@ -31,7 +31,7 @@ #include "nsIPresContext.h" #include "nsILinkHandler.h" #include "nsIDocument.h" -#include "nsTableCell.h" +#include "nsIHTMLTableCellElement.h" #include "nsTableColFrame.h" #include "nsTableFrame.h" #include "nsHTMLIIDs.h" @@ -46,6 +46,7 @@ static NS_DEFINE_IID(kIHTMLStyleSheetIID, NS_IHTML_STYLE_SHEET_IID); static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID); static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID); static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID); +static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID); class HTMLAnchorRule : public nsIStyleRule { @@ -520,8 +521,6 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext, // makes table cells process attributes from other content // inherit based style (ie: font-size: 110%) can double on row & cell PRInt32 backstopInsertPoint = 0; - nsTableCell* cell = (nsTableCell*)aContent; - PRInt32 colIndex = cell->GetColIndex(); nsIFrame* rowFrame = aParentFrame; nsIFrame* rowGroupFrame; @@ -530,17 +529,24 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext, rowFrame->GetContentParent(rowGroupFrame); rowGroupFrame->GetContentParent(tableFrame); - nsTableColFrame* colFrame; - nsIFrame* colGroupFrame; + nsIHTMLTableCellElement* cell=nsnull; + nsresult rv = aContent->QueryInterface(kIHTMLTableCellElementIID, + (void **)&cell); // cell: REFCNT++ + if (NS_SUCCEEDED(rv)) { + PRInt32 colIndex; + rv = cell->GetColIndex(&colIndex); + nsTableColFrame* colFrame; + nsIFrame* colGroupFrame; - ((nsTableFrame*)tableFrame)->GetColumnFrame(colIndex, colFrame); - colFrame->GetContentParent(colGroupFrame); + ((nsTableFrame*)tableFrame)->GetColumnFrame(colIndex, colFrame); + colFrame->GetContentParent(colGroupFrame); - matchCount += AppendRulesFrom(colGroupFrame, aPresContext, backstopInsertPoint, aResults); - matchCount += AppendRulesFrom(colFrame, aPresContext, backstopInsertPoint, aResults); + matchCount += AppendRulesFrom(colGroupFrame, aPresContext, backstopInsertPoint, aResults); + matchCount += AppendRulesFrom(colFrame, aPresContext, backstopInsertPoint, aResults); + NS_RELEASE(cell); // cell: REFCNT-- + } matchCount += AppendRulesFrom(rowGroupFrame, aPresContext, backstopInsertPoint, aResults); matchCount += AppendRulesFrom(rowFrame, aPresContext, backstopInsertPoint, aResults); - } // end TD/TH tag // just get the one and only style rule from the content @@ -1055,9 +1061,6 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, else if (nsHTMLAtoms::wbr == aTag) { rv = NS_NewWBRFrame(aContent, aParentFrame, frame); } - else if (nsHTMLAtoms::table == aTag) { - rv = nsTableOuterFrame::NewFrame(&frame, aContent, aParentFrame); - } else if (nsHTMLAtoms::input == aTag) { rv = CreateInputFrame(aContent, aParentFrame, frame); } @@ -1071,6 +1074,32 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, rv = NS_NewHTMLFrameOuterFrame(aContent, aParentFrame, frame); } + // the table content frames... + else if (nsHTMLAtoms::caption == aTag) { + rv = NS_NewBodyFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::table == aTag) { + rv = NS_NewTableOuterFrame(aContent, aParentFrame, frame); + } + else if ((nsHTMLAtoms::tbody == aTag) || + (nsHTMLAtoms::thead == aTag) || + (nsHTMLAtoms::tfoot == aTag)) { + rv = NS_NewTableRowGroupFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::tr == aTag) { + rv = NS_NewTableRowFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::colgroup == aTag) { + rv = NS_NewTableColGroupFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::col == aTag) { + rv = NS_NewTableColFrame(aContent, aParentFrame, frame); + } + else if ((nsHTMLAtoms::td == aTag) || + (nsHTMLAtoms::th == aTag)) { + rv = NS_NewTableCellFrame(aContent, aParentFrame, frame); + } + if (NS_OK != rv) { return rv; } diff --git a/mozilla/content/shared/public/nsHTMLAtoms.h b/mozilla/content/shared/public/nsHTMLAtoms.h index 0a55c79afe2..cec83e499d1 100644 --- a/mozilla/content/shared/public/nsHTMLAtoms.h +++ b/mozilla/content/shared/public/nsHTMLAtoms.h @@ -64,6 +64,7 @@ public: static nsIAtom* bottompadding; static nsIAtom* br; + static nsIAtom* caption; static nsIAtom* cellpadding; static nsIAtom* cellspacing; static nsIAtom* ch; @@ -79,6 +80,8 @@ public: static nsIAtom* codebase; static nsIAtom* codetype; static nsIAtom* color; + static nsIAtom* col; + static nsIAtom* colgroup; static nsIAtom* cols; static nsIAtom* colspan; static nsIAtom* columnPseudo; @@ -224,13 +227,17 @@ public: static nsIAtom* table; static nsIAtom* tabstop; static nsIAtom* target; + static nsIAtom* tbody; static nsIAtom* td; + static nsIAtom* tfoot; + static nsIAtom* thead; static nsIAtom* text; static nsIAtom* textarea; static nsIAtom* th; static nsIAtom* title; static nsIAtom* top; static nsIAtom* toppadding; + static nsIAtom* tr; static nsIAtom* type; static nsIAtom* ul; diff --git a/mozilla/content/shared/src/nsHTMLAtoms.cpp b/mozilla/content/shared/src/nsHTMLAtoms.cpp index dc4e0cae588..c31e1918ea5 100644 --- a/mozilla/content/shared/src/nsHTMLAtoms.cpp +++ b/mozilla/content/shared/src/nsHTMLAtoms.cpp @@ -43,6 +43,7 @@ nsIAtom* nsHTMLAtoms::border; nsIAtom* nsHTMLAtoms::bordercolor; nsIAtom* nsHTMLAtoms::bottompadding; nsIAtom* nsHTMLAtoms::br; +nsIAtom* nsHTMLAtoms::caption; nsIAtom* nsHTMLAtoms::cellpadding; nsIAtom* nsHTMLAtoms::cellspacing; nsIAtom* nsHTMLAtoms::ch; @@ -58,6 +59,8 @@ nsIAtom* nsHTMLAtoms::code; nsIAtom* nsHTMLAtoms::codebase; nsIAtom* nsHTMLAtoms::codetype; nsIAtom* nsHTMLAtoms::color; +nsIAtom* nsHTMLAtoms::col; +nsIAtom* nsHTMLAtoms::colgroup; nsIAtom* nsHTMLAtoms::cols; nsIAtom* nsHTMLAtoms::colspan; nsIAtom* nsHTMLAtoms::columnPseudo; @@ -189,13 +192,17 @@ nsIAtom* nsHTMLAtoms::tabindex; nsIAtom* nsHTMLAtoms::table; nsIAtom* nsHTMLAtoms::tabstop; nsIAtom* nsHTMLAtoms::target; +nsIAtom* nsHTMLAtoms::tbody; nsIAtom* nsHTMLAtoms::td; +nsIAtom* nsHTMLAtoms::tfoot; +nsIAtom* nsHTMLAtoms::thead; nsIAtom* nsHTMLAtoms::text; nsIAtom* nsHTMLAtoms::textarea; nsIAtom* nsHTMLAtoms::th; nsIAtom* nsHTMLAtoms::title; nsIAtom* nsHTMLAtoms::top; nsIAtom* nsHTMLAtoms::toppadding; +nsIAtom* nsHTMLAtoms::tr; nsIAtom* nsHTMLAtoms::type; nsIAtom* nsHTMLAtoms::ul; nsIAtom* nsHTMLAtoms::usemap; @@ -243,6 +250,7 @@ void nsHTMLAtoms::AddrefAtoms() bordercolor = NS_NewAtom("BORDERCOLOR"); bottompadding = NS_NewAtom("BOTTOMPADDING"); br = NS_NewAtom("BR"); + caption = NS_NewAtom("CAPTION"); cellpadding = NS_NewAtom("CELLPADDING"); cellspacing = NS_NewAtom("CELLSPACING"); ch = NS_NewAtom("CH"); @@ -258,6 +266,8 @@ void nsHTMLAtoms::AddrefAtoms() codebase = NS_NewAtom("CODEBASE"); codetype = NS_NewAtom("CODETYPE"); color = NS_NewAtom("COLOR"); + col = NS_NewAtom("COL"); + colgroup = NS_NewAtom("COLGROUP"); cols = NS_NewAtom("COLS"); colspan = NS_NewAtom("COLSPAN"); columnPseudo = NS_NewAtom(":BODY-COLUMN"); @@ -388,13 +398,17 @@ void nsHTMLAtoms::AddrefAtoms() table = NS_NewAtom("TABLE"); tabstop = NS_NewAtom("TABSTOP"); target = NS_NewAtom("TARGET"); + tbody = NS_NewAtom("TBODY"); td = NS_NewAtom("TD"); + tfoot = NS_NewAtom("TFOOT"); + thead = NS_NewAtom("THEAD"); text = NS_NewAtom("TEXT"); textarea = NS_NewAtom("TEXTAREA"); th = NS_NewAtom("TH"); title = NS_NewAtom("TITLE"); top = NS_NewAtom("TOP"); toppadding = NS_NewAtom("TOPPADDING"); + tr = NS_NewAtom("TR"); type = NS_NewAtom("TYPE"); ul = NS_NewAtom("UL"); usemap = NS_NewAtom("USEMAP"); @@ -440,6 +454,7 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(bordercolor); NS_RELEASE(bottompadding); NS_RELEASE(br); + NS_RELEASE(caption); NS_RELEASE(cellpadding); NS_RELEASE(cellspacing); NS_RELEASE(ch); @@ -455,6 +470,8 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(codebase); NS_RELEASE(codetype); NS_RELEASE(color); + NS_RELEASE(col); + NS_RELEASE(colgroup); NS_RELEASE(cols); NS_RELEASE(colspan); NS_RELEASE(columnPseudo); @@ -579,12 +596,16 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(table); NS_RELEASE(tabstop); NS_RELEASE(target); + NS_RELEASE(tbody); NS_RELEASE(td); + NS_RELEASE(tfoot); + NS_RELEASE(thead); NS_RELEASE(text); NS_RELEASE(textarea); NS_RELEASE(th); NS_RELEASE(top); NS_RELEASE(toppadding); + NS_RELEASE(tr); NS_RELEASE(type); NS_RELEASE(ul); NS_RELEASE(usemap); diff --git a/mozilla/layout/base/src/nsStyleConsts.h b/mozilla/layout/base/src/nsStyleConsts.h index 6d582e16131..e1985590506 100644 --- a/mozilla/layout/base/src/nsStyleConsts.h +++ b/mozilla/layout/base/src/nsStyleConsts.h @@ -206,6 +206,7 @@ #define NS_STYLE_TEXT_ALIGN_RIGHT 2 #define NS_STYLE_TEXT_ALIGN_CENTER 3 #define NS_STYLE_TEXT_ALIGN_JUSTIFY 4 +#define NS_STYLE_TEXT_ALIGN_CHAR 5 //align based on a certain character, for table cell // See nsStyleText, nsStyleFont #define NS_STYLE_TEXT_DECORATION_NONE 0 @@ -265,4 +266,11 @@ #define NS_STYLE_TABLE_COLS_NONE (-1) #define NS_STYLE_TABLE_COLS_ALL PRInt32(1 << 30) +// constants for cell "scope" attribute +#define NS_STYLE_CELL_SCOPE_ROW 0 +#define NS_STYLE_CELL_SCOPE_COL 1 +#define NS_STYLE_CELL_SCOPE_ROWGROUP 2 +#define NS_STYLE_CELL_SCOPE_COLGROUP 3 + + #endif /* nsStyleConsts_h___ */ diff --git a/mozilla/layout/generic/nsHTMLParts.h b/mozilla/layout/generic/nsHTMLParts.h index cec33e44295..086ac72e8de 100644 --- a/mozilla/layout/generic/nsHTMLParts.h +++ b/mozilla/layout/generic/nsHTMLParts.h @@ -187,6 +187,9 @@ NS_NewHTMLTableCellElement(nsIHTMLContent** aResult, nsIAtom* aTag); extern nsresult NS_NewHTMLTableColElement(nsIHTMLContent** aResult, nsIAtom* aTag); +extern nsresult +NS_NewHTMLTableColGroupElement(nsIHTMLContent** aResult, nsIAtom* aTag); + extern nsresult NS_NewHTMLTableElement(nsIHTMLContent** aResult, nsIAtom* aTag); @@ -322,6 +325,40 @@ extern nsresult NS_NewBulletFrame(nsIContent* aContent, nsIFrame* aParentFrame, nsIFrame*& aResult); +// table frame factories + +extern nsresult +NS_NewTableOuterFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableCaptionFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableColFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableColGroupFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableRowFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableRowGroupFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableCellFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + // Everything below this line is obsolete... //---------------------------------------------------------------------- // XXX naming consistency puhleeze! diff --git a/mozilla/layout/html/base/src/nsHTMLAtoms.cpp b/mozilla/layout/html/base/src/nsHTMLAtoms.cpp index dc4e0cae588..c31e1918ea5 100644 --- a/mozilla/layout/html/base/src/nsHTMLAtoms.cpp +++ b/mozilla/layout/html/base/src/nsHTMLAtoms.cpp @@ -43,6 +43,7 @@ nsIAtom* nsHTMLAtoms::border; nsIAtom* nsHTMLAtoms::bordercolor; nsIAtom* nsHTMLAtoms::bottompadding; nsIAtom* nsHTMLAtoms::br; +nsIAtom* nsHTMLAtoms::caption; nsIAtom* nsHTMLAtoms::cellpadding; nsIAtom* nsHTMLAtoms::cellspacing; nsIAtom* nsHTMLAtoms::ch; @@ -58,6 +59,8 @@ nsIAtom* nsHTMLAtoms::code; nsIAtom* nsHTMLAtoms::codebase; nsIAtom* nsHTMLAtoms::codetype; nsIAtom* nsHTMLAtoms::color; +nsIAtom* nsHTMLAtoms::col; +nsIAtom* nsHTMLAtoms::colgroup; nsIAtom* nsHTMLAtoms::cols; nsIAtom* nsHTMLAtoms::colspan; nsIAtom* nsHTMLAtoms::columnPseudo; @@ -189,13 +192,17 @@ nsIAtom* nsHTMLAtoms::tabindex; nsIAtom* nsHTMLAtoms::table; nsIAtom* nsHTMLAtoms::tabstop; nsIAtom* nsHTMLAtoms::target; +nsIAtom* nsHTMLAtoms::tbody; nsIAtom* nsHTMLAtoms::td; +nsIAtom* nsHTMLAtoms::tfoot; +nsIAtom* nsHTMLAtoms::thead; nsIAtom* nsHTMLAtoms::text; nsIAtom* nsHTMLAtoms::textarea; nsIAtom* nsHTMLAtoms::th; nsIAtom* nsHTMLAtoms::title; nsIAtom* nsHTMLAtoms::top; nsIAtom* nsHTMLAtoms::toppadding; +nsIAtom* nsHTMLAtoms::tr; nsIAtom* nsHTMLAtoms::type; nsIAtom* nsHTMLAtoms::ul; nsIAtom* nsHTMLAtoms::usemap; @@ -243,6 +250,7 @@ void nsHTMLAtoms::AddrefAtoms() bordercolor = NS_NewAtom("BORDERCOLOR"); bottompadding = NS_NewAtom("BOTTOMPADDING"); br = NS_NewAtom("BR"); + caption = NS_NewAtom("CAPTION"); cellpadding = NS_NewAtom("CELLPADDING"); cellspacing = NS_NewAtom("CELLSPACING"); ch = NS_NewAtom("CH"); @@ -258,6 +266,8 @@ void nsHTMLAtoms::AddrefAtoms() codebase = NS_NewAtom("CODEBASE"); codetype = NS_NewAtom("CODETYPE"); color = NS_NewAtom("COLOR"); + col = NS_NewAtom("COL"); + colgroup = NS_NewAtom("COLGROUP"); cols = NS_NewAtom("COLS"); colspan = NS_NewAtom("COLSPAN"); columnPseudo = NS_NewAtom(":BODY-COLUMN"); @@ -388,13 +398,17 @@ void nsHTMLAtoms::AddrefAtoms() table = NS_NewAtom("TABLE"); tabstop = NS_NewAtom("TABSTOP"); target = NS_NewAtom("TARGET"); + tbody = NS_NewAtom("TBODY"); td = NS_NewAtom("TD"); + tfoot = NS_NewAtom("TFOOT"); + thead = NS_NewAtom("THEAD"); text = NS_NewAtom("TEXT"); textarea = NS_NewAtom("TEXTAREA"); th = NS_NewAtom("TH"); title = NS_NewAtom("TITLE"); top = NS_NewAtom("TOP"); toppadding = NS_NewAtom("TOPPADDING"); + tr = NS_NewAtom("TR"); type = NS_NewAtom("TYPE"); ul = NS_NewAtom("UL"); usemap = NS_NewAtom("USEMAP"); @@ -440,6 +454,7 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(bordercolor); NS_RELEASE(bottompadding); NS_RELEASE(br); + NS_RELEASE(caption); NS_RELEASE(cellpadding); NS_RELEASE(cellspacing); NS_RELEASE(ch); @@ -455,6 +470,8 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(codebase); NS_RELEASE(codetype); NS_RELEASE(color); + NS_RELEASE(col); + NS_RELEASE(colgroup); NS_RELEASE(cols); NS_RELEASE(colspan); NS_RELEASE(columnPseudo); @@ -579,12 +596,16 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(table); NS_RELEASE(tabstop); NS_RELEASE(target); + NS_RELEASE(tbody); NS_RELEASE(td); + NS_RELEASE(tfoot); + NS_RELEASE(thead); NS_RELEASE(text); NS_RELEASE(textarea); NS_RELEASE(th); NS_RELEASE(top); NS_RELEASE(toppadding); + NS_RELEASE(tr); NS_RELEASE(type); NS_RELEASE(ul); NS_RELEASE(usemap); diff --git a/mozilla/layout/html/base/src/nsHTMLAtoms.h b/mozilla/layout/html/base/src/nsHTMLAtoms.h index 0a55c79afe2..cec83e499d1 100644 --- a/mozilla/layout/html/base/src/nsHTMLAtoms.h +++ b/mozilla/layout/html/base/src/nsHTMLAtoms.h @@ -64,6 +64,7 @@ public: static nsIAtom* bottompadding; static nsIAtom* br; + static nsIAtom* caption; static nsIAtom* cellpadding; static nsIAtom* cellspacing; static nsIAtom* ch; @@ -79,6 +80,8 @@ public: static nsIAtom* codebase; static nsIAtom* codetype; static nsIAtom* color; + static nsIAtom* col; + static nsIAtom* colgroup; static nsIAtom* cols; static nsIAtom* colspan; static nsIAtom* columnPseudo; @@ -224,13 +227,17 @@ public: static nsIAtom* table; static nsIAtom* tabstop; static nsIAtom* target; + static nsIAtom* tbody; static nsIAtom* td; + static nsIAtom* tfoot; + static nsIAtom* thead; static nsIAtom* text; static nsIAtom* textarea; static nsIAtom* th; static nsIAtom* title; static nsIAtom* top; static nsIAtom* toppadding; + static nsIAtom* tr; static nsIAtom* type; static nsIAtom* ul; diff --git a/mozilla/layout/html/base/src/nsHTMLParts.h b/mozilla/layout/html/base/src/nsHTMLParts.h index cec33e44295..086ac72e8de 100644 --- a/mozilla/layout/html/base/src/nsHTMLParts.h +++ b/mozilla/layout/html/base/src/nsHTMLParts.h @@ -187,6 +187,9 @@ NS_NewHTMLTableCellElement(nsIHTMLContent** aResult, nsIAtom* aTag); extern nsresult NS_NewHTMLTableColElement(nsIHTMLContent** aResult, nsIAtom* aTag); +extern nsresult +NS_NewHTMLTableColGroupElement(nsIHTMLContent** aResult, nsIAtom* aTag); + extern nsresult NS_NewHTMLTableElement(nsIHTMLContent** aResult, nsIAtom* aTag); @@ -322,6 +325,40 @@ extern nsresult NS_NewBulletFrame(nsIContent* aContent, nsIFrame* aParentFrame, nsIFrame*& aResult); +// table frame factories + +extern nsresult +NS_NewTableOuterFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableCaptionFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableColFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableColGroupFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableRowFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableRowGroupFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + +extern nsresult +NS_NewTableCellFrame(nsIContent* aContent, nsIFrame* aParentFrame, + nsIFrame*& aResult); + // Everything below this line is obsolete... //---------------------------------------------------------------------- // XXX naming consistency puhleeze! diff --git a/mozilla/layout/html/content/src/Makefile b/mozilla/layout/html/content/src/Makefile index c734b1bba6b..42104c5d4da 100644 --- a/mozilla/layout/html/content/src/Makefile +++ b/mozilla/layout/html/content/src/Makefile @@ -76,6 +76,7 @@ CPPSRCS= \ nsHTMLTableCaptionElement.cpp \ nsHTMLTableCellElement.cpp \ nsHTMLTableColElement.cpp \ + nsHTMLTableColGroupElement.cpp \ nsHTMLTableRowElement.cpp \ nsHTMLTableSectionElement.cpp \ nsHTMLTextAreaElement.cpp \ diff --git a/mozilla/layout/html/content/src/makefile.win b/mozilla/layout/html/content/src/makefile.win index 0b065850275..47ab2f2c65a 100644 --- a/mozilla/layout/html/content/src/makefile.win +++ b/mozilla/layout/html/content/src/makefile.win @@ -78,6 +78,7 @@ CPPSRCS= \ nsHTMLTableCaptionElement.cpp \ nsHTMLTableCellElement.cpp \ nsHTMLTableColElement.cpp \ + nsHTMLTableColGroupElement.cpp \ nsHTMLTableRowElement.cpp \ nsHTMLTableSectionElement.cpp \ nsHTMLTextAreaElement.cpp \ @@ -143,6 +144,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsHTMLTableCaptionElement.obj \ .\$(OBJDIR)\nsHTMLTableCellElement.obj \ .\$(OBJDIR)\nsHTMLTableColElement.obj \ + .\$(OBJDIR)\nsHTMLTableColGroupElement.obj \ .\$(OBJDIR)\nsHTMLTableRowElement.obj \ .\$(OBJDIR)\nsHTMLTableSectionElement.obj \ .\$(OBJDIR)\nsHTMLTextAreaElement.obj \ diff --git a/mozilla/layout/html/content/src/nsGenericHTMLElement.cpp b/mozilla/layout/html/content/src/nsGenericHTMLElement.cpp index cef73f58b73..fec252a2ddc 100644 --- a/mozilla/layout/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/layout/html/content/src/nsGenericHTMLElement.cpp @@ -1866,6 +1866,32 @@ nsGenericHTMLElement::CreateFrame(nsIPresContext* aPresContext, rv = NS_NewWBRFrame(mContent, aParentFrame, frame); } + // the table content frames... + else if (mTag == nsHTMLAtoms::caption) { + rv = NS_NewBodyFrame(mContent, aParentFrame, frame); + } + else if (mTag == nsHTMLAtoms::table) { + rv = NS_NewTableFrame(mContent, aParentFrame, frame); + } + else if ((mTag == nsHTMLAtoms::tbody) || + (mTag == nsHTMLAtoms::thead) || + (mTag == nsHTMLAtoms::tfoot)) { + rv = NS_NewTableRowGroupFrame(mContent, aParentFrame, frame); + } + else if (mTag == nsHTMLAtoms::tr) { + rv = NS_NewTableRowFrame(mContent, aParentFrame, frame); + } + else if (mTag == nsHTMLAtoms::colgroup) { + rv = NS_NewTableColGroupFrame(mContent, aParentFrame, frame); + } + else if (mTag == nsHTMLAtoms::col) { + rv = NS_NewTableColFrame(mContent, aParentFrame, frame); + } + else if ((mTag == nsHTMLAtoms::td) || + (mTag == nsHTMLAtoms::th)) { + rv = NS_NewTableCellFrame(mContent, aParentFrame, frame); + } + if (NS_OK != rv) { return rv; } @@ -2489,6 +2515,23 @@ static nsGenericHTMLElement::EnumTable kScrollingStandardTable[] = { { 0 } }; +static nsGenericHTMLElement::EnumTable kTableHAlignTable[] = { + { "left", NS_STYLE_TEXT_ALIGN_LEFT }, + { "right", NS_STYLE_TEXT_ALIGN_RIGHT }, + { "center", NS_STYLE_TEXT_ALIGN_CENTER }, + { "char", NS_STYLE_TEXT_ALIGN_CHAR }, + { "justify",NS_STYLE_TEXT_ALIGN_JUSTIFY }, + { 0 } +}; + +static nsGenericHTMLElement::EnumTable kTableVAlignTable[] = { + { "top", NS_STYLE_VERTICAL_ALIGN_TOP }, + { "middle", NS_STYLE_VERTICAL_ALIGN_MIDDLE }, + { "bottom", NS_STYLE_VERTICAL_ALIGN_BOTTOM }, + { "baseline",NS_STYLE_VERTICAL_ALIGN_BASELINE }, + { 0 } +}; + PRBool nsGenericHTMLElement::ParseAlignValue(const nsString& aString, nsHTMLValue& aResult) @@ -2496,6 +2539,20 @@ nsGenericHTMLElement::ParseAlignValue(const nsString& aString, return ParseEnumValue(aString, kAlignTable, aResult); } +PRBool +nsGenericHTMLElement::ParseTableHAlignValue(const nsString& aString, + nsHTMLValue& aResult) +{ + return ParseEnumValue(aString, kTableHAlignTable, aResult); +} + +PRBool +nsGenericHTMLElement::ParseTableVAlignValue(const nsString& aString, + nsHTMLValue& aResult) +{ + return ParseEnumValue(aString, kTableVAlignTable, aResult); +} + PRBool nsGenericHTMLElement::AlignValueToString(const nsHTMLValue& aValue, nsString& aResult) @@ -2503,6 +2560,20 @@ nsGenericHTMLElement::AlignValueToString(const nsHTMLValue& aValue, return EnumValueToString(aValue, kAlignTable, aResult); } +PRBool +nsGenericHTMLElement::TableHAlignValueToString(const nsHTMLValue& aValue, + nsString& aResult) +{ + return EnumValueToString(aValue, kTableHAlignTable, aResult); +} + +PRBool +nsGenericHTMLElement::TableVAlignValueToString(const nsHTMLValue& aValue, + nsString& aResult) +{ + return EnumValueToString(aValue, kTableVAlignTable, aResult); +} + PRBool nsGenericHTMLElement::ParseDivAlignValue(const nsString& aString, nsHTMLValue& aResult) diff --git a/mozilla/layout/html/content/src/nsGenericHTMLElement.h b/mozilla/layout/html/content/src/nsGenericHTMLElement.h index 954b1a291a9..442533dd817 100644 --- a/mozilla/layout/html/content/src/nsGenericHTMLElement.h +++ b/mozilla/layout/html/content/src/nsGenericHTMLElement.h @@ -238,6 +238,18 @@ public: static PRBool ParseDivAlignValue(const nsString& aString, nsHTMLValue& aResult); + static PRBool ParseTableHAlignValue(const nsString& aString, + nsHTMLValue& aResult); + + static PRBool ParseTableVAlignValue(const nsString& aString, + nsHTMLValue& aResult); + + static PRBool TableHAlignValueToString(const nsHTMLValue& aValue, + nsString& aResult); + + static PRBool TableVAlignValueToString(const nsHTMLValue& aValue, + nsString& aResult); + static PRBool AlignValueToString(const nsHTMLValue& aValue, nsString& aResult); diff --git a/mozilla/layout/html/content/src/nsHTMLTableCaptionElement.cpp b/mozilla/layout/html/content/src/nsHTMLTableCaptionElement.cpp index e5503b7254a..60fb88f1f31 100644 --- a/mozilla/layout/html/content/src/nsHTMLTableCaptionElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLTableCaptionElement.cpp @@ -26,6 +26,7 @@ #include "nsIStyleContext.h" #include "nsStyleConsts.h" #include "nsIPresContext.h" +#include "nsIHTMLAttributes.h" static NS_DEFINE_IID(kIDOMHTMLTableCaptionElementIID, NS_IDOMHTMLTABLECAPTIONELEMENT_IID); @@ -124,12 +125,24 @@ nsHTMLTableCaptionElement::CloneNode(nsIDOMNode** aReturn) NS_IMPL_STRING_ATTR(nsHTMLTableCaptionElement, Align, align, eSetAttrNotify_Reflow) +static nsGenericHTMLElement::EnumTable kTableCaptionAlignTable[] = { + { "left", NS_STYLE_TEXT_ALIGN_LEFT }, + { "right", NS_STYLE_TEXT_ALIGN_RIGHT }, + { "top", NS_STYLE_VERTICAL_ALIGN_TOP}, + { "bottom",NS_STYLE_VERTICAL_ALIGN_BOTTOM}, + { 0 } +}; + NS_IMETHODIMP nsHTMLTableCaptionElement::StringToAttribute(nsIAtom* aAttribute, const nsString& aValue, nsHTMLValue& aResult) { - // XXX write me + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseEnumValue(aValue, kTableCaptionAlignTable, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return NS_CONTENT_ATTR_NOT_THERE; } @@ -138,7 +151,12 @@ nsHTMLTableCaptionElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + if (aAttribute == nsHTMLAtoms::align) { + if (eHTMLUnit_Enumerated == aValue.GetUnit()) { + nsGenericHTMLElement::AlignValueToString(aValue, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return mInner.AttributeToString(aAttribute, aValue, aResult); } @@ -147,7 +165,32 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me + if (nsnull != aAttributes) { + nsHTMLValue value; + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) { + PRUint8 align = value.GetIntValue(); + nsStyleText* text = (nsStyleText*) + aContext->GetMutableStyleData(eStyleStruct_Text); + switch (align) { + case NS_STYLE_VERTICAL_ALIGN_TOP: + case NS_STYLE_VERTICAL_ALIGN_BOTTOM: + text->mVerticalAlign.SetIntValue(align, eStyleUnit_Enumerated); + break; + // XXX: this is not right, it sets the content's h-align + // what it should do is actually move the caption to the left or right of the table! + /* + case NS_STYLE_TEXT_ALIGN_LEFT: + case NS_STYLE_TEXT_ALIGN_RIGHT: + text->mTextAlign = align; + break; + */ + default: + // illegal value -- ignore it. + break; + } + } + } nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); } diff --git a/mozilla/layout/html/content/src/nsHTMLTableCellElement.cpp b/mozilla/layout/html/content/src/nsHTMLTableCellElement.cpp index 4ed7853d237..709f4ec697a 100644 --- a/mozilla/layout/html/content/src/nsHTMLTableCellElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLTableCellElement.cpp @@ -16,10 +16,12 @@ * Corporation. Portions created by Netscape are Copyright (C) 1998 * Netscape Communications Corporation. All Rights Reserved. */ +#include "nsIHTMLTableCellElement.h" #include "nsIDOMHTMLTableCellElement.h" #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" +#include "nsIHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" @@ -28,29 +30,40 @@ #include "nsIPresContext.h" static NS_DEFINE_IID(kIDOMHTMLTableCellElementIID, NS_IDOMHTMLTABLECELLELEMENT_IID); +static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID); -class nsHTMLTableCellElement : public nsIDOMHTMLTableCellElement, - public nsIScriptObjectOwner, - public nsIDOMEventReceiver, - public nsIHTMLContent +class nsHTMLTableCellElement : public nsIHTMLTableCellElement, + public nsIDOMHTMLTableCellElement, + public nsIScriptObjectOwner, + public nsIDOMEventReceiver, + public nsIHTMLContent { public: nsHTMLTableCellElement(nsIAtom* aTag); ~nsHTMLTableCellElement(); - // nsISupports +// nsISupports NS_DECL_ISUPPORTS - // nsIDOMNode +// nsIHTMLTableCellElement + + /** @return the starting column for this cell. Always >= 1 */ + NS_METHOD GetColIndex (PRInt32* aColIndex); + + /** set the starting column for this cell. Always >= 1 */ + NS_METHOD SetColIndex (PRInt32 aColIndex); + + +// nsIDOMNode NS_IMPL_IDOMNODE_USING_GENERIC(mInner) - // nsIDOMElement +// nsIDOMElement NS_IMPL_IDOMELEMENT_USING_GENERIC(mInner) - // nsIDOMHTMLElement +// nsIDOMHTMLElement NS_IMPL_IDOMHTMLELEMENT_USING_GENERIC(mInner) - // nsIDOMHTMLTableCellElement +// nsIDOMHTMLTableCellElement NS_IMETHOD GetCellIndex(PRInt32* aCellIndex); NS_IMETHOD SetCellIndex(PRInt32 aCellIndex); NS_IMETHOD GetAbbr(nsString& aAbbr); @@ -82,20 +95,21 @@ public: NS_IMETHOD GetWidth(nsString& aWidth); NS_IMETHOD SetWidth(const nsString& aWidth); - // nsIScriptObjectOwner +// nsIScriptObjectOwner NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC(mInner) - // nsIDOMEventReceiver +// nsIDOMEventReceiver NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC(mInner) - // nsIContent +// nsIContent NS_IMPL_ICONTENT_USING_GENERIC(mInner) - // nsIHTMLContent +// nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) protected: nsGenericHTMLContainerElement mInner; + PRInt32 mColIndex; }; nsresult @@ -116,6 +130,7 @@ nsHTMLTableCellElement::nsHTMLTableCellElement(nsIAtom* aTag) { NS_INIT_REFCNT(); mInner.Init(this, aTag); + mColIndex=0; } nsHTMLTableCellElement::~nsHTMLTableCellElement() @@ -136,6 +151,12 @@ nsHTMLTableCellElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) mRefCnt++; return NS_OK; } + else if (aIID.Equals(kIHTMLTableCellElementIID)) { + nsIHTMLTableCellElement* tmp = this; + *aInstancePtr = (void*) tmp; + mRefCnt++; + return NS_OK; + } return NS_NOINTERFACE; } @@ -150,6 +171,20 @@ nsHTMLTableCellElement::CloneNode(nsIDOMNode** aReturn) return it->QueryInterface(kIDOMNodeIID, (void**) aReturn); } +/** @return the starting column for this cell in aColIndex. Always >= 1 */ +NS_METHOD nsHTMLTableCellElement::GetColIndex (PRInt32* aColIndex) +{ + *aColIndex = mColIndex; + return NS_OK; +} + +/** set the starting column for this cell. Always >= 1 */ +NS_METHOD nsHTMLTableCellElement::SetColIndex (PRInt32 aColIndex) +{ + mColIndex = aColIndex; + return NS_OK; +} + NS_IMETHODIMP nsHTMLTableCellElement::GetCellIndex(PRInt32* aCellIndex) { @@ -179,12 +214,73 @@ NS_IMPL_STRING_ATTR(nsHTMLTableCellElement, Scope, scope, eSetAttrNotify_None) NS_IMPL_STRING_ATTR(nsHTMLTableCellElement, VAlign, valign, eSetAttrNotify_Reflow) NS_IMPL_STRING_ATTR(nsHTMLTableCellElement, Width, width, eSetAttrNotify_Reflow) + +static nsGenericHTMLElement::EnumTable kCellScopeTable[] = { + { "row", NS_STYLE_CELL_SCOPE_ROW }, + { "col", NS_STYLE_CELL_SCOPE_COL }, + { "rowgroup", NS_STYLE_CELL_SCOPE_ROWGROUP }, + { "colgroup", NS_STYLE_CELL_SCOPE_COLGROUP }, + { 0 } +}; + NS_IMETHODIMP nsHTMLTableCellElement::StringToAttribute(nsIAtom* aAttribute, const nsString& aValue, nsHTMLValue& aResult) { - // XXX write me + /* ignore these attributes, stored simply as strings + abbr, axis, ch, headers + */ + /* attributes that resolve to integers */ + if ((aAttribute == nsHTMLAtoms::choff) || + (aAttribute == nsHTMLAtoms::colspan) || + (aAttribute == nsHTMLAtoms::rowspan)) { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Integer); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents */ + else if (aAttribute == nsHTMLAtoms::height) { + nsGenericHTMLElement::ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents or proportions */ + else if (aAttribute == nsHTMLAtoms::width) { + nsGenericHTMLElement::ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* other attributes */ + else if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseTableHAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::background) { + nsAutoString href(aValue); + href.StripWhitespace(); + aResult.SetStringValue(href); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::bgcolor) { + nsGenericHTMLElement::ParseColor(aValue, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::nowrap) { + aResult.SetEmptyValue(); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::scope) { + if (nsGenericHTMLElement::ParseEnumValue(aValue, kCellScopeTable, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::ParseTableVAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return NS_CONTENT_ATTR_NOT_THERE; } @@ -193,7 +289,27 @@ nsHTMLTableCellElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + /* ignore these attributes, stored already as strings + abbr, axis, ch, headers + */ + /* ignore attributes that are of standard types + choff, colspan, rowspan, height, width, nowrap, background, bgcolor + */ + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::TableHAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::scope) { + if (nsGenericHTMLElement::EnumValueToString(aValue, kCellScopeTable, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::TableVAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return mInner.AttributeToString(aAttribute, aValue, aResult); } @@ -202,8 +318,68 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + + if (nsnull!=aAttributes) + { + nsHTMLValue value; + nsHTMLValue widthValue; + nsStyleText* textStyle = nsnull; + + // align: enum + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mTextAlign = value.GetIntValue(); + } + + // valign: enum + aAttributes->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); + } + + // width: pixel + float p2t = aPresContext->GetPixelsToTwips(); + nsStylePosition* pos = (nsStylePosition*) + aContext->GetMutableStyleData(eStyleStruct_Position); + aAttributes->GetAttribute(nsHTMLAtoms::width, widthValue); + if (widthValue.GetUnit() == eHTMLUnit_Pixel) { + nscoord twips = NSIntPixelsToTwips(widthValue.GetPixelValue(), p2t); + pos->mWidth.SetCoordValue(twips); + } + else if (widthValue.GetUnit() == eHTMLUnit_Percent) { + pos->mWidth.SetPercentValue(widthValue.GetPercentValue()); + } + + // height: pixel + aAttributes->GetAttribute(nsHTMLAtoms::height, value); + if (value.GetUnit() == eHTMLUnit_Pixel) { + nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t); + pos->mHeight.SetCoordValue(twips); + } + + // nowrap + // nowrap depends on the width attribute, so be sure to handle it after width is mapped! + aAttributes->GetAttribute(nsHTMLAtoms::nowrap, value); + if (value.GetUnit() == eHTMLUnit_Empty) + { + if (widthValue.GetUnit() != eHTMLUnit_Pixel) + { + if (nsnull==textStyle) + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mWhiteSpace = NS_STYLE_WHITESPACE_NOWRAP; + } + } + + nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); + nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + } } NS_IMETHODIMP diff --git a/mozilla/layout/html/content/src/nsHTMLTableColElement.cpp b/mozilla/layout/html/content/src/nsHTMLTableColElement.cpp index 1169edb826b..850e382bfec 100644 --- a/mozilla/layout/html/content/src/nsHTMLTableColElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLTableColElement.cpp @@ -17,9 +17,11 @@ * Netscape Communications Corporation. All Rights Reserved. */ #include "nsIDOMHTMLTableColElement.h" +#include "nsIHTMLTableColElement.h" #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" +#include "nsIHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" @@ -28,11 +30,13 @@ #include "nsIPresContext.h" static NS_DEFINE_IID(kIDOMHTMLTableColElementIID, NS_IDOMHTMLTABLECOLELEMENT_IID); +static NS_DEFINE_IID(kIHTMLTableColElementIID, NS_IHTMLTABLECOLELEMENT_IID); -class nsHTMLTableColElement : public nsIDOMHTMLTableColElement, - public nsIScriptObjectOwner, - public nsIDOMEventReceiver, - public nsIHTMLContent +class nsHTMLTableColElement : public nsIDOMHTMLTableColElement, + public nsIScriptObjectOwner, + public nsIDOMEventReceiver, + public nsIHTMLContent, + public nsIHTMLTableColElement { public: nsHTMLTableColElement(nsIAtom* aTag); @@ -76,6 +80,9 @@ public: // nsIHTMLContent NS_IMPL_IHTMLCONTENT_USING_GENERIC(mInner) + // nsIHTMLTableColElement + NS_IMETHOD GetSpanValue(PRInt32* aSpan); + protected: nsGenericHTMLContainerElement mInner; }; @@ -118,6 +125,12 @@ nsHTMLTableColElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) mRefCnt++; return NS_OK; } + if (aIID.Equals(kIHTMLTableColElementIID)) { + nsIHTMLTableColElement* tmp = this; + *aInstancePtr = (void*) tmp; + mRefCnt++; + return NS_OK; + } return NS_NOINTERFACE; } @@ -144,7 +157,36 @@ nsHTMLTableColElement::StringToAttribute(nsIAtom* aAttribute, const nsString& aValue, nsHTMLValue& aResult) { - // XXX write me + /* ignore these attributes, stored simply as strings + ch + */ + /* attributes that resolve to integers */ + if (aAttribute == nsHTMLAtoms::choff) { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Integer); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::repeat) { + nsGenericHTMLElement::ParseValue(aValue, 1, aResult, eHTMLUnit_Integer); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents or proportions */ + else if (aAttribute == nsHTMLAtoms::width) { + nsGenericHTMLElement::ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* other attributes */ + else if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseTableHAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::ParseTableVAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return NS_CONTENT_ATTR_NOT_THERE; } @@ -153,7 +195,22 @@ nsHTMLTableColElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + /* ignore these attributes, stored already as strings + ch + */ + /* ignore attributes that are of standard types + choff, repeat, width + */ + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::TableHAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::TableVAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return mInner.AttributeToString(aAttribute, aValue, aResult); } @@ -162,10 +219,52 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + if (nsnull != aAttributes) { + + float p2t; + nsHTMLValue value; + nsStyleText* textStyle = nsnull; + + // width + aAttributes->GetAttribute(nsHTMLAtoms::width, value); + if (value.GetUnit() != eHTMLUnit_Null) { + nsStylePosition* position = (nsStylePosition*) + aContext->GetMutableStyleData(eStyleStruct_Position); + switch (value.GetUnit()) { + case eHTMLUnit_Percent: + position->mWidth.SetPercentValue(value.GetPercentValue()); + break; + + case eHTMLUnit_Pixel: + p2t = aPresContext->GetPixelsToTwips(); + position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + break; + } + } + + // align: enum + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mTextAlign = value.GetIntValue(); + } + + // valign: enum + aAttributes->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); + } + } nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); } + NS_IMETHODIMP nsHTMLTableColElement::GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const { @@ -184,3 +283,16 @@ nsHTMLTableColElement::HandleDOMEvent(nsIPresContext& aPresContext, return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); } + +NS_METHOD nsHTMLTableColElement::GetSpanValue(PRInt32* aSpan) +{ + if (nsnull!=aSpan) + { + PRInt32 span=-1; + GetSpan(&span); + if (-1==span) + span=1; // the default; + *aSpan = span; + } + return NS_OK; +} \ No newline at end of file diff --git a/mozilla/layout/html/content/src/nsHTMLTableElement.cpp b/mozilla/layout/html/content/src/nsHTMLTableElement.cpp index c3e141a738b..4a4fcd20f6b 100644 --- a/mozilla/layout/html/content/src/nsHTMLTableElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLTableElement.cpp @@ -20,6 +20,7 @@ #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" +#include "nsIHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" @@ -156,6 +157,9 @@ nsHTMLTableElement::CloneNode(nsIDOMNode** aReturn) return it->QueryInterface(kIDOMNodeIID, (void**) aReturn); } +// the DOM spec says border, cellpadding, cellSpacing are all "wstring" +// in fact, they are integers or they are meaningless. so we store them here as ints. + NS_IMPL_STRING_ATTR(nsHTMLTableElement, Align, align, eSetAttrNotify_Reflow) NS_IMPL_STRING_ATTR(nsHTMLTableElement, BgColor, bgcolor, eSetAttrNotify_Render) NS_IMPL_STRING_ATTR(nsHTMLTableElement, Border, border, eSetAttrNotify_Reflow) @@ -283,12 +287,109 @@ nsHTMLTableElement::DeleteRow(PRInt32 aValue) return NS_OK; // XXX write me } +static nsGenericHTMLElement::EnumTable kFrameTable[] = { + { "void", NS_STYLE_TABLE_FRAME_NONE }, + { "above", NS_STYLE_TABLE_FRAME_ABOVE }, + { "below", NS_STYLE_TABLE_FRAME_BELOW }, + { "hsides", NS_STYLE_TABLE_FRAME_HSIDES }, + { "lhs", NS_STYLE_TABLE_FRAME_LEFT }, + { "rhs", NS_STYLE_TABLE_FRAME_RIGHT }, + { "vsides", NS_STYLE_TABLE_FRAME_VSIDES }, + { "box", NS_STYLE_TABLE_FRAME_BOX }, + { "border", NS_STYLE_TABLE_FRAME_BORDER }, + { 0 } +}; + +static nsGenericHTMLElement::EnumTable kRulesTable[] = { + { "none", NS_STYLE_TABLE_RULES_NONE }, + { "groups", NS_STYLE_TABLE_RULES_GROUPS }, + { "rows", NS_STYLE_TABLE_RULES_ROWS }, + { "cols", NS_STYLE_TABLE_RULES_COLS }, + { "all", NS_STYLE_TABLE_RULES_ALL }, + { 0 } +}; + + NS_IMETHODIMP nsHTMLTableElement::StringToAttribute(nsIAtom* aAttribute, - const nsString& aValue, - nsHTMLValue& aResult) + const nsString& aValue, + nsHTMLValue& aResult) { - // XXX write me + /* ignore summary, just a string */ + /* attributes that resolve to pixels */ + if ((aAttribute == nsHTMLAtoms::cellspacing) || + (aAttribute == nsHTMLAtoms::cellpadding)) { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that are either empty, or integers */ + else if (aAttribute == nsHTMLAtoms::cols) { + nsAutoString tmp(aValue); + tmp.StripWhitespace(); + if (0 == tmp.Length()) { + // Just set COLS, same as COLS=number of columns + aResult.SetEmptyValue(); + } + else + { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Integer); + } + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that are either empty, or pixels */ + else if (aAttribute == nsHTMLAtoms::cols) { + nsAutoString tmp(aValue); + tmp.StripWhitespace(); + if (0 == tmp.Length()) { + // Just enable the border; same as border=1 + aResult.SetEmptyValue(); + } + else + { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Pixel); + } + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents */ + else if (aAttribute == nsHTMLAtoms::height) { + nsGenericHTMLElement::ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents or proportions */ + else if (aAttribute == nsHTMLAtoms::width) { + nsGenericHTMLElement::ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* other attributes */ + else if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseTableHAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::background) { + nsAutoString href(aValue); + href.StripWhitespace(); + aResult.SetStringValue(href); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::bgcolor) { + nsGenericHTMLElement::ParseColor(aValue, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::frame) { + nsGenericHTMLElement::ParseEnumValue(aValue, kFrameTable, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::rules) { + nsGenericHTMLElement::ParseEnumValue(aValue, kRulesTable, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + return NS_CONTENT_ATTR_NOT_THERE; } @@ -297,17 +398,164 @@ nsHTMLTableElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + /* ignore summary, just a string */ + /* ignore attributes that are of standard types + border, cellpadding, cellspacing, cols, height, width, background, bgcolor + */ + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::TableHAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::frame) { + if (nsGenericHTMLElement::EnumValueToString(aValue, kFrameTable, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::rules) { + if (nsGenericHTMLElement::EnumValueToString(aValue, kRulesTable, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + return mInner.AttributeToString(aAttribute, aValue, aResult); } +// XXX: this is only sufficient for Nav4/HTML3.2 +// XXX: needs to be filled in for HTML4 +static void +MapTableBorderInto(nsIHTMLAttributes* aAttributes, + nsIStyleContext* aContext, + nsIPresContext* aPresContext) +{ + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + + nsHTMLValue value; + + aAttributes->GetAttribute(nsHTMLAtoms::border, value); + if (value.GetUnit() == eHTMLUnit_String) + { + nsAutoString borderAsString; + value.GetStringValue(borderAsString); + nsGenericHTMLElement::ParseValue(borderAsString, 0, value, eHTMLUnit_Pixel); + } + if ((value.GetUnit() == eHTMLUnit_Pixel) || + (value.GetUnit() == eHTMLUnit_Empty)) { + nsStyleSpacing* spacing = (nsStyleSpacing*) + aContext->GetMutableStyleData(eStyleStruct_Spacing); + float p2t = aPresContext->GetPixelsToTwips(); + nsStyleCoord twips; + if (value.GetUnit() == eHTMLUnit_Empty) { + twips.SetCoordValue(NSIntPixelsToTwips(1, p2t)); + } + else { + twips.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + } + + spacing->mBorder.SetTop(twips); + spacing->mBorder.SetRight(twips); + spacing->mBorder.SetBottom(twips); + spacing->mBorder.SetLeft(twips); + + if (spacing->mBorderStyle[0] == NS_STYLE_BORDER_STYLE_NONE) { + spacing->mBorderStyle[0] = NS_STYLE_BORDER_STYLE_SOLID; + } + if (spacing->mBorderStyle[1] == NS_STYLE_BORDER_STYLE_NONE) { + spacing->mBorderStyle[1] = NS_STYLE_BORDER_STYLE_SOLID; + } + if (spacing->mBorderStyle[2] == NS_STYLE_BORDER_STYLE_NONE) { + spacing->mBorderStyle[2] = NS_STYLE_BORDER_STYLE_SOLID; + } + if (spacing->mBorderStyle[3] == NS_STYLE_BORDER_STYLE_NONE) { + spacing->mBorderStyle[3] = NS_STYLE_BORDER_STYLE_SOLID; + } + } +} + static void MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + + if (nsnull!=aAttributes) + { + float p2t = aPresContext->GetPixelsToTwips(); + nsHTMLValue value; + + // width + aAttributes->GetAttribute(nsHTMLAtoms::width, value); + if (value.GetUnit() != eHTMLUnit_Null) { + nsStylePosition* position = (nsStylePosition*) + aContext->GetMutableStyleData(eStyleStruct_Position); + switch (value.GetUnit()) { + case eHTMLUnit_Percent: + position->mWidth.SetPercentValue(value.GetPercentValue()); + break; + + case eHTMLUnit_Pixel: + position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + break; + } + } + // border + MapTableBorderInto(aAttributes, aContext, aPresContext); + + // align + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) { // it may be another type if illegal + nsStyleDisplay* display = (nsStyleDisplay*)aContext->GetMutableStyleData(eStyleStruct_Display); + switch (value.GetIntValue()) { + case NS_STYLE_TEXT_ALIGN_LEFT: + display->mFloats = NS_STYLE_FLOAT_LEFT; + break; + + case NS_STYLE_TEXT_ALIGN_RIGHT: + display->mFloats = NS_STYLE_FLOAT_RIGHT; + break; + } + } + + // cellpadding + nsStyleTable* tableStyle=nsnull; + aAttributes->GetAttribute(nsHTMLAtoms::cellpadding, value); + if (value.GetUnit() == eHTMLUnit_Pixel) { + tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + tableStyle->mCellPadding.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + } + + // cellspacing (reuses tableStyle if already resolved) + aAttributes->GetAttribute(nsHTMLAtoms::cellspacing, value); + if (value.GetUnit() == eHTMLUnit_Pixel) { + if (nsnull==tableStyle) + tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + tableStyle->mCellSpacing.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + } + else + { // XXX: remove me as soon as we get this from the style sheet + if (nsnull==tableStyle) + tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + tableStyle->mCellSpacing.SetCoordValue(NSIntPixelsToTwips(2, p2t)); + } + + // cols + aAttributes->GetAttribute(nsHTMLAtoms::cols, value); + if (value.GetUnit() != eHTMLUnit_Null) { + if (nsnull==tableStyle) + tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + if (value.GetUnit() == eHTMLUnit_Integer) + tableStyle->mCols = value.GetIntValue(); + else // COLS had no value, so it refers to all columns + tableStyle->mCols = NS_STYLE_TABLE_COLS_ALL; + } + + //background: color + nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); + nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + } } NS_IMETHODIMP diff --git a/mozilla/layout/html/content/src/nsHTMLTableRowElement.cpp b/mozilla/layout/html/content/src/nsHTMLTableRowElement.cpp index 794cb3985db..ca1bcff4b35 100644 --- a/mozilla/layout/html/content/src/nsHTMLTableRowElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLTableRowElement.cpp @@ -20,6 +20,7 @@ #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" +#include "nsIHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" @@ -204,12 +205,54 @@ NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, Ch, ch, eSetAttrNotify_Reflow) NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, ChOff, choff, eSetAttrNotify_Reflow) NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, VAlign, valign, eSetAttrNotify_Reflow) + NS_IMETHODIMP nsHTMLTableRowElement::StringToAttribute(nsIAtom* aAttribute, const nsString& aValue, nsHTMLValue& aResult) { - // XXX write me + /* ignore these attributes, stored simply as strings + ch + */ + /* attributes that resolve to integers */ + if (aAttribute == nsHTMLAtoms::choff) { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Integer); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents */ + else if (aAttribute == nsHTMLAtoms::height) { + nsGenericHTMLElement::ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents or proportions */ + else if (aAttribute == nsHTMLAtoms::width) { + nsGenericHTMLElement::ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* other attributes */ + else if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseTableHAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::background) { + nsAutoString href(aValue); + href.StripWhitespace(); + aResult.SetStringValue(href); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::bgcolor) { + nsGenericHTMLElement::ParseColor(aValue, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::ParseTableVAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return NS_CONTENT_ATTR_NOT_THERE; } @@ -218,7 +261,22 @@ nsHTMLTableRowElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + /* ignore these attributes, stored already as strings + ch + */ + /* ignore attributes that are of standard types + choff, height, width, background, bgcolor + */ + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::TableHAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::TableVAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return mInner.AttributeToString(aAttribute, aValue, aResult); } @@ -227,8 +285,44 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + + if (nsnull!=aAttributes) + { + nsHTMLValue value; + nsHTMLValue widthValue; + nsStyleText* textStyle = nsnull; + + // align: enum + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mTextAlign = value.GetIntValue(); + } + + // valign: enum + aAttributes->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); + } + + // height: pixel + aAttributes->GetAttribute(nsHTMLAtoms::height, value); + if (value.GetUnit() == eHTMLUnit_Pixel) { + float p2t = aPresContext->GetPixelsToTwips(); + nsStylePosition* pos = (nsStylePosition*) + aContext->GetMutableStyleData(eStyleStruct_Position); + nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t); + pos->mHeight.SetCoordValue(twips); + } + nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); + nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + } } NS_IMETHODIMP diff --git a/mozilla/layout/html/content/src/nsHTMLTableSectionElement.cpp b/mozilla/layout/html/content/src/nsHTMLTableSectionElement.cpp index cfa8d1ce995..f1ffad73d03 100644 --- a/mozilla/layout/html/content/src/nsHTMLTableSectionElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLTableSectionElement.cpp @@ -20,6 +20,7 @@ #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIHTMLContent.h" +#include "nsIHTMLAttributes.h" #include "nsGenericHTMLElement.h" #include "nsHTMLAtoms.h" #include "nsHTMLIIDs.h" @@ -29,6 +30,8 @@ static NS_DEFINE_IID(kIDOMHTMLTableSectionElementIID, NS_IDOMHTMLTABLESECTIONELEMENT_IID); +// you will see the phrases "rowgroup" and "section" used interchangably + class nsHTMLTableSectionElement : public nsIDOMHTMLTableSectionElement, public nsIScriptObjectOwner, public nsIDOMEventReceiver, @@ -166,7 +169,43 @@ nsHTMLTableSectionElement::StringToAttribute(nsIAtom* aAttribute, const nsString& aValue, nsHTMLValue& aResult) { - // XXX write me + /* ignore these attributes, stored simply as strings + ch + */ + /* attributes that resolve to integers */ + if (aAttribute == nsHTMLAtoms::choff) { + nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Integer); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* attributes that resolve to integers or percents */ + else if (aAttribute == nsHTMLAtoms::height) { + nsGenericHTMLElement::ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel); + return NS_CONTENT_ATTR_HAS_VALUE; + } + + /* other attributes */ + else if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::ParseTableHAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::background) { + nsAutoString href(aValue); + href.StripWhitespace(); + aResult.SetStringValue(href); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::bgcolor) { + nsGenericHTMLElement::ParseColor(aValue, aResult); + return NS_CONTENT_ATTR_HAS_VALUE; + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::ParseTableVAlignValue(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + return NS_CONTENT_ATTR_NOT_THERE; } @@ -175,7 +214,22 @@ nsHTMLTableSectionElement::AttributeToString(nsIAtom* aAttribute, nsHTMLValue& aValue, nsString& aResult) const { - // XXX write me + /* ignore these attributes, stored already as strings + ch + */ + /* ignore attributes that are of standard types + choff, height, width, background, bgcolor + */ + if (aAttribute == nsHTMLAtoms::align) { + if (nsGenericHTMLElement::TableHAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } + else if (aAttribute == nsHTMLAtoms::valign) { + if (nsGenericHTMLElement::TableVAlignValueToString(aValue, aResult)) { + return NS_CONTENT_ATTR_HAS_VALUE; + } + } return mInner.AttributeToString(aAttribute, aValue, aResult); } @@ -184,8 +238,45 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, nsIPresContext* aPresContext) { - // XXX write me - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); + NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); + + if (nsnull!=aAttributes) + { + nsHTMLValue value; + nsHTMLValue widthValue; + nsStyleText* textStyle = nsnull; + + // align: enum + aAttributes->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); + textStyle->mTextAlign = value.GetIntValue(); + } + + // valign: enum + aAttributes->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); + } + + // height: pixel + aAttributes->GetAttribute(nsHTMLAtoms::height, value); + if (value.GetUnit() == eHTMLUnit_Pixel) { + float p2t = aPresContext->GetPixelsToTwips(); + nsStylePosition* pos = (nsStylePosition*) + aContext->GetMutableStyleData(eStyleStruct_Position); + nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t); + pos->mHeight.SetCoordValue(twips); + } + nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); + nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); + } + } NS_IMETHODIMP diff --git a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp index abb7cdff3dd..7ec6fe90e8a 100644 --- a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp @@ -34,10 +34,6 @@ #include "nsHTMLParts.h" #include "nsITextContent.h" - -#include "nsTablePart.h" -#include "nsTableRow.h" -#include "nsTableCell.h" #include "nsIDOMText.h" #include "nsHTMLForms.h" @@ -487,13 +483,13 @@ MakeContentObject(nsHTMLTag aNodeType, rv = NS_NewHTMLBRElement(aResult, aAtom); break; case eHTMLTag_caption: - rv = NS_NewTableCaptionPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableCaptionElement(aResult, aAtom); break; case eHTMLTag_col: - rv = NS_NewTableColPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableColElement(aResult, aAtom); break; case eHTMLTag_colgroup: - rv = NS_NewTableColGroupPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableColGroupElement(aResult, aAtom); break; case eHTMLTag_dir: rv = NS_NewHTMLDirectoryElement(aResult, aAtom); @@ -603,16 +599,16 @@ MakeContentObject(nsHTMLTag aNodeType, rv = NS_NewHTMLStyleElement(aResult, aAtom); break; case eHTMLTag_table: - rv = NS_NewTablePart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableElement(aResult, aAtom); break; case eHTMLTag_tbody: case eHTMLTag_thead: case eHTMLTag_tfoot: - rv = NS_NewTableRowGroupPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableSectionElement(aResult, aAtom); break; case eHTMLTag_td: case eHTMLTag_th: - rv = NS_NewTableCellPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableCellElement(aResult, aAtom); break; case eHTMLTag_textarea: rv = NS_NewHTMLTextAreaElement(aResult, aAtom); @@ -621,7 +617,7 @@ MakeContentObject(nsHTMLTag aNodeType, rv = NS_NewHTMLTitleElement(aResult, aAtom); break; case eHTMLTag_tr: - rv = NS_NewTableRowPart(aResult, aAtom);/* XXX old style */ + rv = NS_NewHTMLTableRowElement(aResult, aAtom); break; case eHTMLTag_ul: rv = NS_NewHTMLUListElement(aResult, aAtom); diff --git a/mozilla/layout/html/makefile.win b/mozilla/layout/html/makefile.win index 80470763315..e58522d008f 100644 --- a/mozilla/layout/html/makefile.win +++ b/mozilla/layout/html/makefile.win @@ -17,6 +17,6 @@ DEPTH=..\.. -DIRS = base content document forms style table tests +DIRS = base content document forms style table include <$(DEPTH)\layout\config\rules.mak> diff --git a/mozilla/layout/html/style/src/Makefile b/mozilla/layout/html/style/src/Makefile index 280025c2b7c..529ffbf09bb 100644 --- a/mozilla/layout/html/style/src/Makefile +++ b/mozilla/layout/html/style/src/Makefile @@ -53,7 +53,7 @@ EXPORTS = \ MODULE = raptor -INCLUDES += -I../../base/src -I../../../base/src -I../../table/src -I. +INCLUDES += -I../../base/src -I../../../base/src -I../../table/src -I../../content/src -I. REQUIRES = xpcom raptor dom netlib js diff --git a/mozilla/layout/html/style/src/makefile.win b/mozilla/layout/html/style/src/makefile.win index 2d8ecbb1586..eafe4b9071e 100644 --- a/mozilla/layout/html/style/src/makefile.win +++ b/mozilla/layout/html/style/src/makefile.win @@ -42,7 +42,7 @@ CPP_OBJS=.\$(OBJDIR)\nsCSSKeywords.obj .\$(OBJDIR)\nsCSSLayout.obj \ LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\netlib \ -I..\..\..\base\src \ - -I..\..\base\src -I..\..\table\src -I$(PUBLIC)\js -I$(PUBLIC)\dom + -I..\..\base\src -I..\..\table\src -I..\..\content\src -I$(PUBLIC)\js -I$(PUBLIC)\dom LCFLAGS = \ $(LCFLAGS) \ diff --git a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp index afe16c1ea0f..f43a071509e 100644 --- a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp @@ -31,7 +31,7 @@ #include "nsIPresContext.h" #include "nsILinkHandler.h" #include "nsIDocument.h" -#include "nsTableCell.h" +#include "nsIHTMLTableCellElement.h" #include "nsTableColFrame.h" #include "nsTableFrame.h" #include "nsHTMLIIDs.h" @@ -46,6 +46,7 @@ static NS_DEFINE_IID(kIHTMLStyleSheetIID, NS_IHTML_STYLE_SHEET_IID); static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID); static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID); static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID); +static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID); class HTMLAnchorRule : public nsIStyleRule { @@ -520,8 +521,6 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext, // makes table cells process attributes from other content // inherit based style (ie: font-size: 110%) can double on row & cell PRInt32 backstopInsertPoint = 0; - nsTableCell* cell = (nsTableCell*)aContent; - PRInt32 colIndex = cell->GetColIndex(); nsIFrame* rowFrame = aParentFrame; nsIFrame* rowGroupFrame; @@ -530,17 +529,24 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext, rowFrame->GetContentParent(rowGroupFrame); rowGroupFrame->GetContentParent(tableFrame); - nsTableColFrame* colFrame; - nsIFrame* colGroupFrame; + nsIHTMLTableCellElement* cell=nsnull; + nsresult rv = aContent->QueryInterface(kIHTMLTableCellElementIID, + (void **)&cell); // cell: REFCNT++ + if (NS_SUCCEEDED(rv)) { + PRInt32 colIndex; + rv = cell->GetColIndex(&colIndex); + nsTableColFrame* colFrame; + nsIFrame* colGroupFrame; - ((nsTableFrame*)tableFrame)->GetColumnFrame(colIndex, colFrame); - colFrame->GetContentParent(colGroupFrame); + ((nsTableFrame*)tableFrame)->GetColumnFrame(colIndex, colFrame); + colFrame->GetContentParent(colGroupFrame); - matchCount += AppendRulesFrom(colGroupFrame, aPresContext, backstopInsertPoint, aResults); - matchCount += AppendRulesFrom(colFrame, aPresContext, backstopInsertPoint, aResults); + matchCount += AppendRulesFrom(colGroupFrame, aPresContext, backstopInsertPoint, aResults); + matchCount += AppendRulesFrom(colFrame, aPresContext, backstopInsertPoint, aResults); + NS_RELEASE(cell); // cell: REFCNT-- + } matchCount += AppendRulesFrom(rowGroupFrame, aPresContext, backstopInsertPoint, aResults); matchCount += AppendRulesFrom(rowFrame, aPresContext, backstopInsertPoint, aResults); - } // end TD/TH tag // just get the one and only style rule from the content @@ -1055,9 +1061,6 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, else if (nsHTMLAtoms::wbr == aTag) { rv = NS_NewWBRFrame(aContent, aParentFrame, frame); } - else if (nsHTMLAtoms::table == aTag) { - rv = nsTableOuterFrame::NewFrame(&frame, aContent, aParentFrame); - } else if (nsHTMLAtoms::input == aTag) { rv = CreateInputFrame(aContent, aParentFrame, frame); } @@ -1071,6 +1074,32 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, rv = NS_NewHTMLFrameOuterFrame(aContent, aParentFrame, frame); } + // the table content frames... + else if (nsHTMLAtoms::caption == aTag) { + rv = NS_NewBodyFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::table == aTag) { + rv = NS_NewTableOuterFrame(aContent, aParentFrame, frame); + } + else if ((nsHTMLAtoms::tbody == aTag) || + (nsHTMLAtoms::thead == aTag) || + (nsHTMLAtoms::tfoot == aTag)) { + rv = NS_NewTableRowGroupFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::tr == aTag) { + rv = NS_NewTableRowFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::colgroup == aTag) { + rv = NS_NewTableColGroupFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::col == aTag) { + rv = NS_NewTableColFrame(aContent, aParentFrame, frame); + } + else if ((nsHTMLAtoms::td == aTag) || + (nsHTMLAtoms::th == aTag)) { + rv = NS_NewTableCellFrame(aContent, aParentFrame, frame); + } + if (NS_OK != rv) { return rv; } diff --git a/mozilla/layout/html/table/src/Makefile b/mozilla/layout/html/table/src/Makefile index 578f380f321..fa0b0920f9f 100644 --- a/mozilla/layout/html/table/src/Makefile +++ b/mozilla/layout/html/table/src/Makefile @@ -25,20 +25,12 @@ LIBRARY_NAME = raptorhtmltable_s CPPSRCS = \ BasicTableLayoutStrategy.cpp \ nsCellMap.cpp \ - nsTableCaption.cpp \ - nsTableCell.cpp \ nsTableCellFrame.cpp \ - nsTableCol.cpp \ nsTableColFrame.cpp \ - nsTableColGroup.cpp \ nsTableColGroupFrame.cpp \ - nsTableContent.cpp \ nsTableFrame.cpp \ nsTableOuterFrame.cpp \ - nsTablePart.cpp \ - nsTableRow.cpp \ nsTableRowFrame.cpp \ - nsTableRowGroup.cpp \ nsTableRowGroupFrame.cpp \ $(NULL) diff --git a/mozilla/layout/html/table/src/makefile.win b/mozilla/layout/html/table/src/makefile.win index 05ed221e6e2..97fa3824694 100644 --- a/mozilla/layout/html/table/src/makefile.win +++ b/mozilla/layout/html/table/src/makefile.win @@ -23,26 +23,23 @@ REQUIRES=xpcom raptor js DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN -CPPSRCS= nsCellMap.cpp \ - nsTableCaption.cpp \ - nsTableCell.cpp nsTableCol.cpp \ - nsTableCellFrame.cpp nsTableColFrame.cpp \ - nsTableColGroup.cpp nsTableColGroupFrame.cpp \ - nsTableContent.cpp nsTableFrame.cpp \ - nsTableOuterFrame.cpp nsTablePart.cpp \ - nsTableRow.cpp nsTableRowFrame.cpp \ - nsTableRowGroup.cpp nsTableRowGroupFrame.cpp \ +CPPSRCS= nsCellMap.cpp \ + nsTableCellFrame.cpp \ + nsTableColFrame.cpp \ + nsTableColGroupFrame.cpp \ + nsTableFrame.cpp \ + nsTableOuterFrame.cpp \ + nsTableRowFrame.cpp \ + nsTableRowGroupFrame.cpp \ BasicTableLayoutStrategy.cpp CPP_OBJS= .\$(OBJDIR)\nsCellMap.obj \ - .\$(OBJDIR)\nsTableCaption.obj \ - .\$(OBJDIR)\nsTableCell.obj .\$(OBJDIR)\nsTableCol.obj \ .\$(OBJDIR)\nsTableCellFrame.obj .\$(OBJDIR)\nsTableColFrame.obj \ - .\$(OBJDIR)\nsTableColGroup.obj .\$(OBJDIR)\nsTableColGroupFrame.obj \ - .\$(OBJDIR)\nsTableContent.obj .\$(OBJDIR)\nsTableFrame.obj \ - .\$(OBJDIR)\nsTableOuterFrame.obj .\$(OBJDIR)\nsTablePart.obj \ - .\$(OBJDIR)\nsTableRow.obj .\$(OBJDIR)\nsTableRowFrame.obj \ - .\$(OBJDIR)\nsTableRowGroup.obj .\$(OBJDIR)\nsTableRowGroupFrame.obj \ + .\$(OBJDIR)\nsTableColGroupFrame.obj \ + .\$(OBJDIR)\nsTableFrame.obj \ + .\$(OBJDIR)\nsTableOuterFrame.obj \ + .\$(OBJDIR)\nsTableRowFrame.obj \ + .\$(OBJDIR)\nsTableRowGroupFrame.obj \ .\$(OBJDIR)\BasicTableLayoutStrategy.obj LINCS=-I$(XPDIST)\public\xpcom -I$(XPDIST)\public\raptor \ diff --git a/mozilla/layout/html/table/src/nsCellMap.h b/mozilla/layout/html/table/src/nsCellMap.h index a461ba9bfa0..f83136f801d 100644 --- a/mozilla/layout/html/table/src/nsCellMap.h +++ b/mozilla/layout/html/table/src/nsCellMap.h @@ -20,8 +20,8 @@ #include "nscore.h" #include "celldata.h" +#include "nsVoidArray.h" -class nsVoidArray; class nsTableColFrame; class nsTableCellFrame; diff --git a/mozilla/layout/html/table/src/nsITableContent.h b/mozilla/layout/html/table/src/nsITableContent.h deleted file mode 100644 index 67eeec18483..00000000000 --- a/mozilla/layout/html/table/src/nsITableContent.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#ifndef nsITableContent_h__ -#define nsITableContent_h__ - -#include "nsISupports.h" -#include "nscore.h" - -class nsTablePart; - -#define NS_ITABLECONTENT_IID \ - { /* 34a59b40-a71d-11d1-8f2f-006008159b0c */ \ - 0x34a59b40, 0xa71d, 0x11d1, \ - {0x8f, 0x2f, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x0c} } - -/** - * nsITableContent is a concrete subclass for all content nodes contained directly - * within a table. - * - * @author sclark - * @see nsTablePart - */ -class nsITableContent : public nsISupports -{ - -public: - - /** constants representing well-known table content types */ - static const int kTableRowGroupType; - static const int kTableRowType; - static const int kTableColGroupType; - static const int kTableColType; - static const int kTableCaptionType; - static const int kTableCellType; - -protected: - /** protected constructor. Never create an object of type nsITableContent directly.*/ - nsITableContent (); - -public: - /** returns the TablePart that contains this content node. - * every table content has one and only one parent, - * and may not be replicated within different hierarchies. - */ - virtual nsTablePart *GetTable ()=0; - - /** set the parent of this table content object. - * @param aTable the new parent. May be null to disconnect this object from - * the hierarchy it is in. Note that we don't have formalized - * relationship objects, so the caller must also remove this - * from it's prarent's child list. - */ - virtual void SetTable (nsTablePart *aTable)=0; - - /** returns PR_TRUE if there is an actual input tag corresponding to - * this content object. - */ - NS_IMETHOD IsSynthetic(PRBool& aResult) = 0; - - /** returns PR_TRUE if this content object should NOT be written to the output stream. - * for example, we don't generally want to output implicit tags when saving. - */ - virtual PRBool SkipSelfForSaving ()=0; - - /** return the type of TableContent this object represents. */ - virtual int GetType()=0; - -}; - -#endif - diff --git a/mozilla/layout/html/table/src/nsTableCaption.cpp b/mozilla/layout/html/table/src/nsTableCaption.cpp deleted file mode 100644 index d1498c8b66a..00000000000 --- a/mozilla/layout/html/table/src/nsTableCaption.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#include "nsTableCaption.h" -#include "nsBodyFrame.h" -#include "nsTablePart.h" -#include "nsHTMLParts.h" -#include "nsHTMLContainer.h" -#include "nsContainerFrame.h" -#include "nsIReflowCommand.h" -#include "nsIStyleContext.h" -#include "nsStyleConsts.h" -#include "nsIPresContext.h" -#include "nsHTMLIIDs.h" -#include "nsHTMLAtoms.h" -#include "nsIHTMLAttributes.h" -#include "nsGenericHTMLElement.h" - - -#ifdef NS_DEBUG -static PRBool gsDebug = PR_FALSE; -static PRBool gsNoisyRefs = PR_FALSE; -#else -static const PRBool gsDebug = PR_FALSE; -static const PRBool gsNoisyRefs = PR_FALSE; -#endif - - -nsTableCaption::nsTableCaption(nsIAtom* aTag) - : nsTableContent(aTag) -{ - mImplicit = PR_FALSE; -} - -nsTableCaption::nsTableCaption(PRBool aImplicit) - : nsTableContent(NS_NewAtom(nsTablePart::kCaptionTagString)) -{ - mImplicit = aImplicit; -} - -nsTableCaption::~nsTableCaption() -{ -} - -nsrefcnt nsTableCaption::AddRef(void) -{ - if (gsNoisyRefs) printf("Add Ref: %x, nsTableCaption cnt = %d \n",this, mRefCnt+1); - return ++mRefCnt; -} - -nsrefcnt nsTableCaption::Release(void) -{ - if (gsNoisyRefs==PR_TRUE) printf("Release: %x, nsTableCaption cnt = %d \n",this, mRefCnt-1); - if (--mRefCnt == 0) { - if (gsNoisyRefs==PR_TRUE) printf("Delete: %x, nsTableCaption \n",this); - delete this; - return 0; - } - return mRefCnt; -} - -int nsTableCaption::GetType() -{ - return nsITableContent::kTableCaptionType; -} - -NS_IMETHODIMP -nsTableCaption::SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify) -{ - nsHTMLValue val; - - if (aAttribute == nsHTMLAtoms::align) { - if (ParseTableCaptionAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - return nsTableContent::SetAttribute(aAttribute, aValue, aNotify); -} - -static void -MapAttributesInto(nsIHTMLAttributes* aAttributes, - nsIStyleContext* aContext, - nsIPresContext* aPresContext) -{ - NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); - NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); - - nsHTMLValue value; - - // align - aAttributes->GetAttribute(nsHTMLAtoms::align, value); - if (value.GetUnit() != eHTMLUnit_Null) { - NS_ASSERTION(value.GetUnit() == eHTMLUnit_Enumerated, "unexpected unit"); - - PRUint8 alignValue = value.GetIntValue(); - // this code relies on top, bottom, left, and right all being unique values - if (NS_STYLE_VERTICAL_ALIGN_BOTTOM==alignValue || - NS_STYLE_VERTICAL_ALIGN_TOP==alignValue) - { - nsStyleText* textStyle = - (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - textStyle->mVerticalAlign.SetIntValue(alignValue, eStyleUnit_Enumerated); - } - // XXX: this isn't the right place to put this attribute! probably on the float guy - // talk to Peter and Troy - else if (NS_STYLE_TEXT_ALIGN_LEFT==alignValue || - NS_STYLE_TEXT_ALIGN_RIGHT==alignValue) - { - nsStyleText* textStyle = - (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - textStyle->mTextAlign = alignValue; - } - } - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); -} - -NS_IMETHODIMP -nsTableCaption::GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const -{ - aMapFunc = &MapAttributesInto; - return NS_OK; -} - - - -NS_IMETHODIMP -nsTableCaption::CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult) -{ - NS_PRECONDITION(nsnull!=aPresContext, "bad arg"); - - nsIFrame* frame; - nsresult rv = NS_NewBodyFrame(this, aParentFrame, frame); - if (NS_OK != rv) { - return rv; - } - frame->SetStyleContext(aPresContext, aStyleContext); - aResult = frame; - return rv; -} - - -nsresult -NS_NewTableCaptionPart(nsIHTMLContent** aInstancePtrResult, - nsIAtom* aTag) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIHTMLContent* body = new nsTableCaption(aTag); - if (nsnull == body) { - return NS_ERROR_OUT_OF_MEMORY; - } - return body->QueryInterface(kIHTMLContentIID, (void **) aInstancePtrResult); -} diff --git a/mozilla/layout/html/table/src/nsTableCaption.h b/mozilla/layout/html/table/src/nsTableCaption.h deleted file mode 100644 index 14e8fb7b9b4..00000000000 --- a/mozilla/layout/html/table/src/nsTableCaption.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#ifndef nsTableCaption_h__ -#define nsTableCaption_h__ - -#include "nscore.h" -#include "nsTableContent.h" - -/** - * nsTableCaption is the content object that represents table captions - * (HTML tag CAPTION). This class cannot be reused - * outside of an nsTablePart. It assumes that its parent is an nsTablePart, and - * it has a single nsBodyPart child. - * - * @see nsTablePart - * @see nsTableRow - * @see nsBodyPart - * - * @author sclark - */ -class nsTableCaption : public nsTableContent -{ -public: - - /** constructor - * @param aImplicit PR_TRUE if there is no actual input tag corresponding to - * this caption. - */ - nsTableCaption (PRBool aImplicit); - - /** constructor - * @param aTag the HTML tag causing this caption to get constructed. - */ - nsTableCaption (nsIAtom* aTag); - - /** destructor, not responsible for any memory destruction itself */ - virtual ~nsTableCaption(); - - // For debugging purposes only - NS_IMETHOD_(nsrefcnt) AddRef(); - NS_IMETHOD_(nsrefcnt) Release(); - - /** returns nsITableContent::kTableCaptionType */ - virtual int GetType(); - - /* ---------- overrides ---------- */ - NS_IMETHOD SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify); - - NS_IMETHOD GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const; - - /** @see nsIHTMLContent::CreateFrame */ - NS_IMETHOD CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult); -}; - -#endif - - - diff --git a/mozilla/layout/html/table/src/nsTableCell.cpp b/mozilla/layout/html/table/src/nsTableCell.cpp deleted file mode 100644 index 3c9901c1e0c..00000000000 --- a/mozilla/layout/html/table/src/nsTableCell.cpp +++ /dev/null @@ -1,353 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#include "nsTableCell.h" -#include "nsTableCellFrame.h" -#include "nsHTMLParts.h" -#include "nsIStyleContext.h" -#include "nsStyleConsts.h" -#include "nsIPresContext.h" -#include "nsIDocument.h" -#include "nsIURL.h" -#include "nsHTMLIIDs.h" -#include "nsHTMLAtoms.h" -#include "nsIPtr.h" -#include "nsIHTMLAttributes.h" -#include "nsGenericHTMLElement.h" - -// hack, remove when hack in nsTableCol constructor is removed -static PRInt32 HACKcounter=0; -static nsIAtom *HACKattribute=nsnull; -#include "prprf.h" // remove when nsTableCol constructor hack is removed -// end hack code - - -NS_DEF_PTR(nsIStyleContext); - -#ifdef NS_DEBUG -static PRBool gsDebug = PR_FALSE; -static PRBool gsNoisyRefs = PR_FALSE; -#else -static const PRBool gsDebug = PR_FALSE; -static const PRBool gsNoisyRefs = PR_FALSE; -#endif - -// nsTableContent checks aTag -nsTableCell::nsTableCell(nsIAtom* aTag) - : nsTableContent(aTag), - mRow(0), - mRowSpan(1), - mColSpan(1), - mColIndex(0) -{ - mImplicit = PR_FALSE; - Init(); -} - -nsTableCell::nsTableCell(PRBool aImplicit) - : nsTableContent(NS_NewAtom(nsTablePart::kDataCellTagString)), - mRow(0), - mRowSpan(1), - mColSpan(1), - mColIndex(0) -{ - mImplicit = aImplicit; - Init(); -} - -// nsTableContent checks aTag -nsTableCell::nsTableCell (nsIAtom* aTag, int aRowSpan, int aColSpan) - : nsTableContent(aTag), - mRow(0), - mRowSpan(aRowSpan), - mColSpan(aColSpan), - mColIndex(0) -{ - NS_ASSERTION(0Init(mRowSpan, mColSpan, mColIndex); - frame->SetStyleContext(aPresContext, aStyleContext); - aResult = frame; - return rv; -} - -NS_IMETHODIMP -nsTableCell::SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify) -{ - NS_PRECONDITION(nsnull!=aAttribute, "bad attribute arg"); - nsHTMLValue val; - if ((aAttribute == nsHTMLAtoms::align) && - ParseDivAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if ((aAttribute == nsHTMLAtoms::valign) && - ParseAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::background) { - nsAutoString href(aValue); - href.StripWhitespace(); - return nsHTMLTagContent::SetAttribute(aAttribute, href, aNotify); - } - if (aAttribute == nsHTMLAtoms::bgcolor) { - ParseColor(aValue, val); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::rowspan) { - ParseValue(aValue, 1, 10000, val, eHTMLUnit_Integer); - SetRowSpan(val.GetIntValue()); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::colspan) { - ParseValue(aValue, 1, 1000, val, eHTMLUnit_Integer); - SetColSpan(val.GetIntValue()); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::width) { - ParseValueOrPercent(aValue, val, eHTMLUnit_Pixel); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::height) { - ParseValueOrPercent(aValue, val, eHTMLUnit_Pixel); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if (aAttribute == nsHTMLAtoms::nowrap) { - val.SetEmptyValue(); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - - // Use default attribute catching code - return nsTableContent::SetAttribute(aAttribute, aValue, aNotify); -} - - - -static void -MapAttributesInto(nsIHTMLAttributes* aAttributes, - nsIStyleContext* aContext, - nsIPresContext* aPresContext) -{ - NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); - NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); - - nsHTMLValue value; - nsHTMLValue widthValue; - nsStyleText* textStyle = nsnull; - - // align: enum - aAttributes->GetAttribute(nsHTMLAtoms::align, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) - { - textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - textStyle->mTextAlign = value.GetIntValue(); - } - - // valign: enum - aAttributes->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); - } - - // width: pixel - float p2t = aPresContext->GetPixelsToTwips(); - nsStylePosition* pos = (nsStylePosition*) - aContext->GetMutableStyleData(eStyleStruct_Position); - aAttributes->GetAttribute(nsHTMLAtoms::width, widthValue); - if (widthValue.GetUnit() == eHTMLUnit_Pixel) { - nscoord twips = NSIntPixelsToTwips(widthValue.GetPixelValue(), p2t); - pos->mWidth.SetCoordValue(twips); - } - else if (widthValue.GetUnit() == eHTMLUnit_Percent) { - pos->mWidth.SetPercentValue(widthValue.GetPercentValue()); - } - - // height: pixel - aAttributes->GetAttribute(nsHTMLAtoms::height, value); - if (value.GetUnit() == eHTMLUnit_Pixel) { - nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t); - pos->mHeight.SetCoordValue(twips); - } - - // nowrap - // nowrap depends on the width attribute, so be sure to handle it after width is mapped! - aAttributes->GetAttribute(nsHTMLAtoms::nowrap, value); - if (value.GetUnit() == eHTMLUnit_Empty) - { - if (widthValue.GetUnit() != eHTMLUnit_Pixel) - { - if (nsnull==textStyle) - textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - textStyle->mWhiteSpace = NS_STYLE_WHITESPACE_NOWRAP; - } - } - - nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); -} - -NS_IMETHODIMP -nsTableCell::GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const -{ - aMapFunc = &MapAttributesInto; - return NS_OK; -} - - - -NS_IMETHODIMP -nsTableCell::AttributeToString(nsIAtom* aAttribute, - nsHTMLValue& aValue, - nsString& aResult) const -{ - nsresult ca = NS_CONTENT_ATTR_NOT_THERE; - if (aAttribute == nsHTMLAtoms::valign) { - AlignParamToString(aValue, aResult); - ca = NS_CONTENT_ATTR_HAS_VALUE; - } - else { - ca = nsTableContent::AttributeToString(aAttribute, aValue, aResult); - } - return ca; -} - -void nsTableCell::SetRowSpan(int aRowSpan) -{ - NS_ASSERTION(0QueryInterface(kIHTMLContentIID, (void **) aInstancePtrResult); -} diff --git a/mozilla/layout/html/table/src/nsTableCell.h b/mozilla/layout/html/table/src/nsTableCell.h deleted file mode 100644 index a0a877ff5e7..00000000000 --- a/mozilla/layout/html/table/src/nsTableCell.h +++ /dev/null @@ -1,139 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#ifndef nsTableCell_h__ -#define nsTableCell_h__ - -#include "nsCoord.h" -#include "nscore.h" -#include "nsTableContent.h" -#include "nsTableRow.h" - -// forward declarations -struct nsStyleColor; - -/** - * nsTableCell is the content object that represents table cells - * (HTML tags TD and TH). This class cannot be reused - * outside of an nsTableRow. It assumes that its parent is an nsTableRow, and - * it has a single nsBodyPart child. - * - * @see nsTablePart - * @see nsTableRow - * @see nsBodyPart - * - * @author sclark - */ -class nsTableCell : public nsTableContent -{ - -private: - - /** parent pointer */ - nsTableRow * mRow; - - /** the number of rows spanned by this cell */ - int mRowSpan; - - /** the number of columns spanned by this cell */ - int mColSpan; - - /** the starting column for this cell */ - int mColIndex; - -public: - - /** constructor - * @param aImplicit PR_TRUE if there is no actual input tag corresponding to - * this cell. - */ - nsTableCell (PRBool aImplicit); - - /** constructor - * @param aTag the HTML tag causing this cell to get constructed. - */ - nsTableCell (nsIAtom* aTag); - - /** constructor - * @param aTag the HTML tag causing this caption to get constructed. - * @param aRowSpan the number of rows spanned - * @param aColSpan the number of columns spanned - */ - nsTableCell (nsIAtom* aTag, int aRowSpan, int aColSpan); - - /** destructor, not responsible for any memory destruction itself */ - virtual ~nsTableCell(); - - // For debugging purposes only - NS_IMETHOD_(nsrefcnt) AddRef(); - NS_IMETHOD_(nsrefcnt) Release(); - - - /** returns nsITableContent::kTableCellType */ - virtual int GetType(); - - /** @see nsIHTMLContent::CreateFrame */ - NS_IMETHOD CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult); - - NS_IMETHOD SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify); - - NS_IMETHOD GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const; - - NS_IMETHOD AttributeToString(nsIAtom* aAttribute, - nsHTMLValue& aValue, - nsString& aResult) const; - - - /** @return the number of rows spanned by this cell. Always >= 1 */ - virtual int GetRowSpan (); - - /** set the number of rows spanned. Must be >= 1 */ - virtual void SetRowSpan (int aRowSpan); - - /** @return the number of columns spanned by this cell. Always >= 1 */ - virtual int GetColSpan (); - - /** set the number of columns spanned. Must be >= 1 */ - virtual void SetColSpan (int aColSpan); - - /** return a pointer to this cell's parent, the row containing the cell */ - virtual nsTableRow * GetRow (); - - /** set this cell's parent. - * Note: Since mRow is the parent of the table cell, - * reference counting should not be done on - * this variable when setting the row. - * see /ns/raptor/doc/MemoryModel.html - */ - virtual void SetRow (nsTableRow * aRow); - - /** @return the starting column for this cell. Always >= 1 */ - virtual int GetColIndex (); - - /** set the starting column for this cell. Always >= 1 */ - virtual void SetColIndex (int aColIndex); - -protected: - - virtual void Init(); -}; - -#endif diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.cpp b/mozilla/layout/html/table/src/nsTableCellFrame.cpp index 7cec23b353c..430d9cfc851 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableCellFrame.cpp @@ -25,6 +25,8 @@ #include "nsCSSRendering.h" #include "nsIContent.h" #include "nsIContentDelegate.h" +#include "nsIHTMLContent.h" +#include "nsHTMLIIDs.h" #include "nsCSSLayout.h" #include "nsHTMLValue.h" #include "nsHTMLAtoms.h" @@ -55,8 +57,6 @@ nsTableCellFrame::nsTableCellFrame(nsIContent* aContent, nsIFrame* aParentFrame) : nsContainerFrame(aContent, aParentFrame) { - mRowSpan=1; - mColSpan=1; mColIndex=0; mPriorAvailWidth=0; mDesiredSize.width=0; @@ -216,7 +216,39 @@ nsTableFrame* nsTableCellFrame::GetTableFrame() return (nsTableFrame*)frame; } +PRInt32 nsTableCellFrame::GetRowSpan() +{ + PRInt32 rowSpan=1; + nsIHTMLContent *hc=nsnull; + nsresult rv = mContent->QueryInterface(kIHTMLContentIID, (void**) &hc); + if (NS_OK==rv) + { + nsHTMLValue val; + hc->GetAttribute(nsHTMLAtoms::rowspan, val); + if (eHTMLUnit_Integer == val.GetUnit()) { + rowSpan=val.GetIntValue(); + } + NS_RELEASE(hc); + } + return rowSpan; +} +PRInt32 nsTableCellFrame::GetColSpan() +{ + PRInt32 colSpan=1; + nsIHTMLContent *hc=nsnull; + nsresult rv = mContent->QueryInterface(kIHTMLContentIID, (void**) &hc); + if (NS_OK==rv) + { + nsHTMLValue val; + hc->GetAttribute(nsHTMLAtoms::colspan, val); + if (eHTMLUnit_Integer == val.GetUnit()) { + colSpan=val.GetIntValue(); + } + NS_RELEASE(hc); + } + return colSpan; +} /** @@ -510,7 +542,7 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) nscoord border = 1; nsTableFrame* tableFrame = GetTableFrame(); - tableFrame->GetGeometricParent((nsIFrame *&)tableFrame); // get the outer frame + //tableFrame->GetGeometricParent((nsIFrame *&)tableFrame); // get the outer frame NS_ASSERTION(tableFrame,"Table Must not be null"); if (!tableFrame) return; @@ -579,21 +611,18 @@ nsTableCellFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) return nsContainerFrame::QueryInterface(aIID, aInstancePtr); } -/* ----- static methods ----- */ +/* ----- global methods ----- */ -nsresult nsTableCellFrame::NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +nsresult +NS_NewTableCellFrame( nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableCellFrame(aContent, aParent); + nsIFrame* it = new nsTableCellFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.h b/mozilla/layout/html/table/src/nsTableCellFrame.h index c6b99bee5f9..68e7a9080ae 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.h +++ b/mozilla/layout/html/table/src/nsTableCellFrame.h @@ -41,11 +41,19 @@ class nsTableCellFrame : public nsContainerFrame { public: - void Init(PRInt32 aRowSpan, PRInt32 aColSpan, PRInt32 aColIndex); + void InitCellFrame(PRInt32 aColIndex); - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + /** instantiate a new instance of nsTableCellFrame. + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame + * + * @return NS_OK if the frame was properly allocated, otherwise an error code + */ + friend nsresult + NS_NewTableCellFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); // nsISupports NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); @@ -206,11 +214,6 @@ protected: PRBool ConvertToPixelValue(nsHTMLValue& aValue, PRInt32 aDefault, PRInt32& aResult); protected: - /** the number of rows spanned by this cell */ - int mRowSpan; - - /** the number of columns spanned by this cell */ - int mColSpan; /** the starting column for this cell */ int mColIndex; @@ -232,18 +235,12 @@ protected: }; -inline void nsTableCellFrame::Init(PRInt32 aRowSpan, PRInt32 aColSpan, PRInt32 aColIndex) +inline void nsTableCellFrame::InitCellFrame(PRInt32 aColIndex) { - NS_PRECONDITION(0GetAttribute(nsHTMLAtoms::width, value); - if (value.GetUnit() != eHTMLUnit_Null) { - nsStylePosition* position = (nsStylePosition*) - aContext->GetMutableStyleData(eStyleStruct_Position); - switch (value.GetUnit()) { - case eHTMLUnit_Percent: - position->mWidth.SetPercentValue(value.GetPercentValue()); - break; - - case eHTMLUnit_Pixel: - p2t = aPresContext->GetPixelsToTwips(); - position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); - break; - } - } - - // align: enum - aAttributes->GetAttribute(nsHTMLAtoms::align, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) - { - textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - textStyle->mTextAlign = value.GetIntValue(); - } - - // valign: enum - aAttributes->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); - } - } - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); -} - -NS_IMETHODIMP -nsTableCol::GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const -{ - aMapFunc = &MapAttributesInto; - return NS_OK; -} - - - -NS_IMETHODIMP -nsTableCol::CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult) -{ - NS_PRECONDITION(nsnull!=aPresContext, "bad arg"); - - nsIFrame* frame; - nsresult rv = nsTableColFrame::NewFrame(&frame, this, aParentFrame); - if (NS_OK != rv) { - return rv; - } - ((nsTableColFrame*)frame)->Init(mColIndex, mRepeat); - frame->SetStyleContext(aPresContext, aStyleContext); - aResult = frame; - return rv; -} - -void nsTableCol::ResetColumns () -{ - if (nsnull != mColGroup) - mColGroup->ResetColumns (); -} - -/* ---------- Global Functions ---------- */ - -nsresult -NS_NewTableColPart(nsIHTMLContent** aInstancePtrResult, - nsIAtom* aTag) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIHTMLContent* body = new nsTableCol(aTag); - if (nsnull == body) { - return NS_ERROR_OUT_OF_MEMORY; - } - return body->QueryInterface(kIHTMLContentIID, (void **) aInstancePtrResult); -} diff --git a/mozilla/layout/html/table/src/nsTableCol.h b/mozilla/layout/html/table/src/nsTableCol.h deleted file mode 100644 index 387f1b74b6a..00000000000 --- a/mozilla/layout/html/table/src/nsTableCol.h +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#ifndef nsTableCol_h__ -#define nsTableCol_h__ - -#include "nscore.h" -#include "nsTableContent.h" -#include "nsTableColGroup.h" - -class nsTablePart; - -/** - * nsTableCol is the content object that represents table cols - * (HTML tag COL). This class cannot be reused - * outside of an nsTableColGroup. It assumes that its parent is an nsTableColGroup, and - * it has no children. - * - * @see nsTablePart - * @see nsTableColGroup - * - * @author sclark - */ -class nsTableCol : public nsTableContent -{ - -private: - - /** parent pointer, the column group to which this column belongs */ - nsTableColGroup * mColGroup; - - /** the starting index of the column (starting at 0) that this col object represents */ - PRInt32 mColIndex; - - /** the number of columns that the attributes of this column extend to */ - PRInt32 mRepeat; - -public: - - /** default constructor */ - nsTableCol (); - - /** constructor - * @param aImplicit PR_TRUE if there is no actual input tag corresponding to - * this col. - */ - nsTableCol (PRBool aImplicit); - - /** constructor - * @param aTag the HTML tag causing this col to get constructed. - */ - nsTableCol (nsIAtom* aTag); - - /** destructor, not responsible for any memory destruction itself */ - virtual ~nsTableCol(); - - // For debugging purposes only - NS_IMETHOD_(nsrefcnt) AddRef(); - NS_IMETHOD_(nsrefcnt) Release(); - - /** returns nsITableContent::kTableCellType */ - virtual int GetType(); - - NS_IMETHOD SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify); - - NS_IMETHOD GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const; - - /** @see nsIHTMLContent::CreateFrame */ - NS_IMETHOD CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult); - - /** return the number of columns this content object represents. always >= 1*/ - virtual int GetRepeat (); - - /** set the number of columns this content object represents. must be >= 1*/ - void SetRepeat (int aRepeat); - - virtual nsTableColGroup *GetColGroup (); - - /** set the parent col group.
- * NOTE: Since mColGroup is the parent of the table column, - * reference counting should NOT be done on - * this variable when setting the row. - * see /ns/raptor/doc/MemoryModel.html - **/ - virtual void SetColGroup (nsTableColGroup * aColGroup); - - /** return the index of the column this content object represents. always >= 0 */ - virtual int GetColumnIndex (); - - /** set the index of the column this content object represents. must be >= 0 */ - virtual void SetColumnIndex (int aColIndex); - - virtual void ResetColumns (); - -private: - void Init(); - - -}; - -/* ---------- inlines ---------- */ - - -inline int nsTableCol::GetType() -{ return nsITableContent::kTableColType;} - -inline int nsTableCol::GetRepeat () -{ - if (0 < mRepeat) - return mRepeat; - return 1; -} - -inline nsTableColGroup * nsTableCol::GetColGroup () -{ - NS_IF_ADDREF(mColGroup); - return mColGroup; -} - -inline void nsTableCol::SetColGroup (nsTableColGroup * aColGroup) -{ mColGroup = aColGroup;} - -inline int nsTableCol::GetColumnIndex () -{ return mColIndex;} - -inline void nsTableCol::SetColumnIndex (int aColIndex) -{ mColIndex = aColIndex;} - -inline void nsTableCol::SetRepeat (int aRepeat) -{ - mRepeat = aRepeat; - ResetColumns (); -} - -#endif - - - diff --git a/mozilla/layout/html/table/src/nsTableColFrame.cpp b/mozilla/layout/html/table/src/nsTableColFrame.cpp index bfe76797dc7..03b9065ddc6 100644 --- a/mozilla/layout/html/table/src/nsTableColFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableColFrame.cpp @@ -37,7 +37,7 @@ nsTableColFrame::nsTableColFrame(nsIContent* aContent, nsIFrame* aParentFrame) : nsFrame(aContent, aParentFrame) { mColIndex = 0; - mRepeat = 0; + mRepeat = 1; mMaxColWidth = 0; mMinColWidth = 0; mMaxEffectiveColWidth = 0; @@ -79,21 +79,18 @@ NS_METHOD nsTableColFrame::Reflow(nsIPresContext* aPresContext, } -/* ----- static methods ------ */ +/* ----- global methods ----- */ -nsresult nsTableColFrame::NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +nsresult +NS_NewTableColFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableColFrame(aContent, aParent); + nsIFrame* it = new nsTableColFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } diff --git a/mozilla/layout/html/table/src/nsTableColFrame.h b/mozilla/layout/html/table/src/nsTableColFrame.h index 3f0ad33873c..8b388559783 100644 --- a/mozilla/layout/html/table/src/nsTableColFrame.h +++ b/mozilla/layout/html/table/src/nsTableColFrame.h @@ -29,11 +29,19 @@ public: eWIDTH_SOURCE_CELL_WITH_SPAN=2 // a cell implicitly specified a width via colspan }; - void Init(PRInt32 aColIndex, PRInt32 aRepeat); + void InitColFrame(PRInt32 aColIndex, PRInt32 aRepeat); - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + /** instantiate a new instance of nsTableColFrame. + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame + * + * @return NS_OK if the frame was properly allocated, otherwise an error code + */ + friend nsresult + NS_NewTableColFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); NS_IMETHOD Paint(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, @@ -104,7 +112,7 @@ protected: }; -inline void nsTableColFrame::Init(PRInt32 aColIndex, PRInt32 aRepeat) +inline void nsTableColFrame::InitColFrame(PRInt32 aColIndex, PRInt32 aRepeat) { NS_ASSERTION(0<=aColIndex, "bad col index param"); NS_ASSERTION(0<=aRepeat, "bad repeat param"); diff --git a/mozilla/layout/html/table/src/nsTableColGroup.cpp b/mozilla/layout/html/table/src/nsTableColGroup.cpp deleted file mode 100644 index e3d6189d7a7..00000000000 --- a/mozilla/layout/html/table/src/nsTableColGroup.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#include "nsTableColGroup.h" -#include "nsTableColGroupFrame.h" -#include "nsTableCol.h" -#include "nsTablePart.h" -#include "nsContainerFrame.h" -#include "nsIReflowCommand.h" -#include "nsIStyleContext.h" -#include "nsStyleConsts.h" -#include "nsIPresContext.h" -#include "nsHTMLIIDs.h" -#include "nsHTMLAtoms.h" -#include "nsIHTMLAttributes.h" -#include "nsGenericHTMLElement.h" - -#ifdef NS_DEBUG -static PRBool gsDebug = PR_FALSE; -static PRBool gsNoisyRefs = PR_FALSE; -#else -static const PRBool gsDebug = PR_FALSE; -static const PRBool gsNoisyRefs = PR_FALSE; -#endif - -static NS_DEFINE_IID(kITableContentIID, NS_ITABLECONTENT_IID); - - -nsTableColGroup::nsTableColGroup(nsIAtom* aTag, int aSpan) - : nsTableContent(aTag), - mSpan(aSpan), - mStartColIndex(0), - mColCount(0) -{ -} - -nsTableColGroup::nsTableColGroup (PRBool aImplicit) - : nsTableContent(NS_NewAtom(nsTablePart::kColGroupTagString)), - mSpan(0), - mStartColIndex(0), - mColCount(0) -{ - mImplicit = aImplicit; -} - - -nsTableColGroup::~nsTableColGroup() -{ -} - -// Added for debuging purposes -- remove from final build -nsrefcnt nsTableColGroup::AddRef(void) -{ - if (gsNoisyRefs==PR_TRUE) - printf("Add Ref: %x, nsTableColGroup cnt = %d \n",this,mRefCnt+1); - return ++mRefCnt; -} - -nsrefcnt nsTableColGroup::Release(void) -{ - if (gsNoisyRefs==PR_TRUE) - if (gsNoisyRefs==PR_TRUE) printf("Release: %x, nsTableColGroup cnt = %d \n",this,mRefCnt-1); - if (--mRefCnt == 0) { - if (gsNoisyRefs==PR_TRUE) printf("Delete: %x, nsTableColGroup \n",this); - delete this; - return 0; - } - return mRefCnt; -} - -/** returns the number of columns represented by this group. - * if there are col children, count them (taking into account the span of each) - * else, check my own span attribute. - */ -int nsTableColGroup::GetColumnCount () -{ - if (0 == mColCount) - { - int count; - ChildCount (count); - if (0 < count) - { - for (int index = 0; index < count; index++) - { - nsIContent * child; - ChildAt (index, child); // child: REFCNT++ - NS_ASSERTION(nsnull!=child, "bad child"); - // is child a column? - nsTableContent *tableContent = (nsTableContent *)child; - if (tableContent->GetType() == nsITableContent::kTableColType) - { - nsTableCol * col = (nsTableCol *)tableContent; - col->SetColumnIndex (mStartColIndex + mColCount); - mColCount += col->GetRepeat (); - } - NS_RELEASE(child); // child: REFCNT-- - } - } - else - mColCount = GetSpan (); - } - return mColCount; -} - -void nsTableColGroup::ResetColumns () -{ - mColCount = 0; -} - -NS_IMETHODIMP -nsTableColGroup::AppendChildTo (nsIContent *aContent, PRBool aNotify) -{ - NS_ASSERTION(nsnull!=aContent, "bad arg"); - - // is aContent a TableRow? - PRBool isCol = IsCol(aContent); - - if (PR_FALSE==isCol) - { - // you should go talk to my parent if you want to insert something other than a column - return NS_OK; - } - - nsresult result = NS_ERROR_FAILURE; - PRBool contentHandled = PR_FALSE; - // SEC: TODO verify that aContent is table content - nsTableContent *tableContent = (nsTableContent *)aContent; - PRBool isImplicit; - tableContent->IsSynthetic(isImplicit); - if (PR_FALSE==isImplicit) - { - /* if aContent is not implicit, - * and if we already have an implicit column for this actual column, - * then replace the implicit col with this actual col. - */ - PRInt32 childCount; - ChildCount(childCount); - for (PRInt32 colIndex=0; colIndexIsSynthetic(colIsImplicit); - if (PR_TRUE==colIsImplicit) - { - ReplaceChildAt(aContent, colIndex, aNotify); - contentHandled = PR_TRUE; - break; - } - } - } - if (PR_FALSE==contentHandled) - result = nsTableContent::AppendChildTo (aContent, aNotify); - if (NS_OK==result) - { - ((nsTableCol *)aContent)->SetColGroup (this); - ((nsTableCol *)aContent)->SetColumnIndex (mStartColIndex + mColCount); - ResetColumns (); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsTableColGroup::InsertChildAt (nsIContent *aContent, PRInt32 aIndex, - PRBool aNotify) -{ - NS_ASSERTION(nsnull!=aContent, "bad arg"); - - // is aContent a TableCol? - PRBool isCol = IsCol(aContent); - - // if not, ignore the request to add aContent - if (PR_FALSE==isCol) - { - // you should go talk to my parent if you want to insert something other than a column - return NS_OK; - } - - // if so, add the row to this group - nsresult result = nsTableContent::InsertChildAt (aContent, aIndex, aNotify); - if (NS_OK==result) - { - ((nsTableCol *)aContent)->SetColGroup (this); - ResetColumns (); - } - return NS_OK; -} - - -NS_IMETHODIMP -nsTableColGroup::ReplaceChildAt (nsIContent * aContent, PRInt32 aIndex, - PRBool aNotify) -{ - PRInt32 numKids; - ChildCount(numKids); - NS_ASSERTION(nsnull!=aContent, "bad arg"); - NS_ASSERTION((0<=aIndex && numKids>aIndex), "bad arg"); - if ((nsnull==aContent) || !(0<=aIndex && numKids>aIndex)) - return PR_FALSE; - - // is aContent a TableRow? - PRBool isCol = IsCol(aContent); - - // if not, ignore the request to replace the child at aIndex - if (PR_FALSE==isCol) - { - // you should go talk to my parent if you want to insert something other than a column - return NS_OK; - } - - nsIContent * lastChild; - ChildAt (aIndex, lastChild); // lastChild : REFCNT++ - NS_ASSERTION(nsnull!=lastChild, "bad child"); - nsresult result = nsTableContent::ReplaceChildAt (aContent, aIndex, aNotify); - if (NS_OK==result) - { - ((nsTableCol *)aContent)->SetColGroup (this); - if (nsnull != lastChild) - ((nsTableCol *)lastChild)->SetColGroup (nsnull); - ResetColumns (); - } - NS_RELEASE(lastChild); // lastChild : REFCNT-- - - return NS_OK; -} - -/** - * Remove a child at the given position. The method is ignored if - * the index is invalid (too small or too large). - */ -NS_IMETHODIMP -nsTableColGroup::RemoveChildAt (PRInt32 aIndex, PRBool aNotify) -{ -#ifdef NS_DEBUG - PRInt32 numKids; - ChildCount(numKids); - NS_ASSERTION((0<=aIndex && numKids>aIndex), "bad arg"); -#endif - - nsIContent * lastChild; - ChildAt (aIndex, lastChild); // lastChild: REFCNT++ - NS_ASSERTION(nsnull!=lastChild, "bad child"); - nsresult result = nsTableContent::RemoveChildAt (aIndex, aNotify); - if (NS_OK==result) - { - if (nsnull != lastChild) - ((nsTableCol *)lastChild)->SetColGroup (nsnull); - ResetColumns (); - } - NS_IF_RELEASE(lastChild); // lastChild REFCNT-- - - return NS_OK; -} - -/** support method to determine if the param aContent is an nsTableCol object */ -PRBool nsTableColGroup::IsCol(nsIContent * aContent) const -{ - PRBool result = PR_FALSE; - if (nsnull!=aContent) - { - // is aContent a col? - nsITableContent *tableContentInterface = nsnull; - nsresult rv = aContent->QueryInterface(kITableContentIID, - (void **)&tableContentInterface); // tableContentInterface: REFCNT++ - - if (NS_SUCCEEDED(rv)) - { - const int contentType = tableContentInterface->GetType(); - NS_RELEASE(tableContentInterface); - if (contentType == nsITableContent::kTableColType) - result = PR_TRUE; - } - } - return result; -} - -NS_IMETHODIMP -nsTableColGroup::SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify) -{ - nsHTMLValue val; - - if (aAttribute == nsHTMLAtoms::width) - { - ParseValueOrPercentOrProportional(aValue, val, eHTMLUnit_Pixel); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - else if ( aAttribute == nsHTMLAtoms::span) - { - ParseValue(aValue, 0, val, eHTMLUnit_Integer); - SetSpan(val.GetIntValue()); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - else if (aAttribute == nsHTMLAtoms::align) { - nsHTMLValue val; - if (ParseTableAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - else if (aAttribute == nsHTMLAtoms::valign) { - nsHTMLValue val; - if (ParseTableAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - return nsTableContent::SetAttribute(aAttribute, aValue, aNotify); -} - -static void -MapAttributesInto(nsIHTMLAttributes* aAttributes, - nsIStyleContext* aContext, - nsIPresContext* aPresContext) -{ - NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); - NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); - if (nsnull != aAttributes) { - - float p2t; - nsHTMLValue value; - nsStyleText* textStyle = nsnull; - - // width - aAttributes->GetAttribute(nsHTMLAtoms::width, value); - if (value.GetUnit() != eHTMLUnit_Null) { - nsStylePosition* position = (nsStylePosition*) - aContext->GetMutableStyleData(eStyleStruct_Position); - switch (value.GetUnit()) { - case eHTMLUnit_Percent: - position->mWidth.SetPercentValue(value.GetPercentValue()); - break; - - case eHTMLUnit_Pixel: - p2t = aPresContext->GetPixelsToTwips(); - position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); - break; - } - } - - // align: enum - aAttributes->GetAttribute(nsHTMLAtoms::align, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) - { - textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - textStyle->mTextAlign = value.GetIntValue(); - } - - // valign: enum - aAttributes->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); - } - } - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); -} - -NS_IMETHODIMP -nsTableColGroup::GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const -{ - aMapFunc = &MapAttributesInto; - return NS_OK; -} - - - -NS_IMETHODIMP -nsTableColGroup::CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult) -{ - NS_PRECONDITION(nsnull!=aPresContext, "bad arg"); - - nsIFrame* frame; - nsresult rv = nsTableColGroupFrame::NewFrame(&frame, this, aParentFrame); - if (NS_OK != rv) { - return rv; - } - frame->SetStyleContext(aPresContext, aStyleContext); - aResult = frame; - return rv; -} - -/* ---------- Global Functions ---------- */ - -NS_HTML nsresult -NS_NewTableColGroupPart(nsIHTMLContent** aInstancePtrResult, - nsIAtom* aTag) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIHTMLContent* body = new nsTableColGroup(aTag, 0); - if (nsnull == body) { - return NS_ERROR_OUT_OF_MEMORY; - } - return body->QueryInterface(kIHTMLContentIID, (void **) aInstancePtrResult); -} diff --git a/mozilla/layout/html/table/src/nsTableColGroup.h b/mozilla/layout/html/table/src/nsTableColGroup.h deleted file mode 100644 index 43939d3239b..00000000000 --- a/mozilla/layout/html/table/src/nsTableColGroup.h +++ /dev/null @@ -1,183 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#ifndef nsTableColGroup_h__ -#define nsTableColGroup_h__ - -#include "nscore.h" -#include "nsTableContent.h" - -class nsIPresContext; - -/** - * nsTableColGroup is the content object that represents table col groups - * (HTML tag COLGROUP). This class cannot be reused - * outside of an nsTablePart. It assumes that its parent is an nsTablePart, and - * its children are nsTableCols. - * - * @see nsTablePart - * @see nsTableCol - * - * @author sclark - */ -class nsTableColGroup : public nsTableContent -{ -protected: - - /** the number of columns this col group represents. Must be >=1. - * Default is 1. - * Must be ignored if the colgroup contains any explicit col content objects. - */ - int mSpan; - - /** the starting column index this col group represents. Must be >= 0. */ - int mStartColIndex; - - /** the number of columns represented by this col group when col content - * objects are contained herein. If no col children, then mSpan is the - * proper place to check. - * @see GetColumnCount - */ - int mColCount; - -public: - - /** constructor - * @param aImplicit PR_TRUE if there is no actual input tag corresponding to - * this col group. - */ - nsTableColGroup (PRBool aImplicit); - - /** constructor - * @param aTag the HTML tag causing this caption to get constructed. - * @param aSpan the number of columns this col group represents - * (unless overridden by col children.) - */ - nsTableColGroup (nsIAtom* aTag, int aSpan); - - /** destructor, not responsible for any memory destruction itself */ - virtual ~nsTableColGroup(); - - // For debugging purposes only - NS_IMETHOD_(nsrefcnt) AddRef(); - NS_IMETHOD_(nsrefcnt) Release(); - - NS_IMETHOD SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify); - - NS_IMETHOD GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const; - - /** @see nsIHTMLContent::CreateFrame */ - NS_IMETHOD CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult); - - /** returns nsITableContent::kTableColGroupType */ - virtual int GetType(); - - /** returns the span attribute, always >= 1. Not necessarily representative - * of the number of columns spanned, since span is overridden by any COL - * children. - * @see GetColumnCount - */ - virtual int GetSpan (); - - /** set the span attribute, must be >= 1. */ - virtual void SetSpan (int aSpan); - - /** get the starting column index, always >= 0. */ - virtual int GetStartColumnIndex (); - - /** set the starting column index, must be >= 0. */ - virtual void SetStartColumnIndex (int aIndex); - - /** called whenever the col structure changes. - * Propogates change notification up to the nsTablePart parent - */ - virtual void ResetColumns (); - - /** returns the number of columns represented by this group. - * if there are col children, count them (taking into account the span of each) - * else, check my own span attribute. - */ - virtual int GetColumnCount (); - - /** helper routine returns PR_TRUE if aContent represents a column */ - virtual PRBool IsCol(nsIContent * aContent) const; - - /** can only append objects that are columns (implement nsITableContent and are . - * of type nsITableContent::kTableColType.) - * @see nsIContent::AppendChildTo - */ - NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify); - - /** can only insert objects that are columns (implement nsITableContent and are . - * of type nsITableContent::kTableColType.) - * @see nsIContent::InsertChildAt - */ - NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify); - - /** can only replace child objects with objects that are columns - * (implement nsITableContent and are * of type nsITableContent::kTableColType.) - * @param aContent the object to insert, must be a column - * @param aIndex the index of the object to replace. Must be in the range - * 0<=aIndexQueryInterface(kITableContentIID, + rv = kid->QueryInterface(kITableContentIID, (void **)&tableContentInterface); // tableContentInterface: REFCNT++ if (NS_FAILED(rv)) { @@ -92,7 +96,7 @@ NS_METHOD nsTableColGroupFrame::Reflow(nsIPresContext& aPresContext, continue; } NS_RELEASE(tableContentInterface); // tableContentInterface: REFCNT-- - +*/ if (mChildCount<=colIndex) { // Resolve style @@ -106,6 +110,21 @@ NS_METHOD nsTableColGroupFrame::Reflow(nsIPresContext& aPresContext, kidDel = kid->GetDelegate(&aPresContext); rv = kidDel->CreateFrame(&aPresContext, kid, this, kidSC, kidFrame); NS_RELEASE(kidDel); + if (NS_FAILED(rv)) + return rv; + + // set the preliminary values for the column frame + PRInt32 repeat=1; + nsIHTMLTableColElement* colContent = nsnull; + kid->QueryInterface(kIHTMLTableColElementIID, + (void**) &colContent); // colContent: ADDREF++ + if (rv==NS_OK) + { + colContent->GetSpanValue(&repeat); + NS_RELEASE(colContent); + } + ((nsTableColFrame *)(kidFrame))->InitColFrame (mStartColIndex + mColCount, repeat); + mColCount+= repeat; // give the child frame a chance to reflow, even though we know it'll have 0 size nsReflowMetrics kidSize(nsnull); @@ -238,21 +257,18 @@ int nsTableColGroupFrame::GetColumnCount () return mColCount; } -/* ----- static methods ----- */ +/* ----- global methods ----- */ -nsresult nsTableColGroupFrame::NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +nsresult +NS_NewTableColGroupFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableColGroupFrame(aContent, aParent); + nsIFrame* it = new nsTableColGroupFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } diff --git a/mozilla/layout/html/table/src/nsTableColGroupFrame.h b/mozilla/layout/html/table/src/nsTableColGroupFrame.h index d98eb7b5ad7..bf9498c96ad 100644 --- a/mozilla/layout/html/table/src/nsTableColGroupFrame.h +++ b/mozilla/layout/html/table/src/nsTableColGroupFrame.h @@ -31,9 +31,17 @@ class nsTableColGroupFrame : public nsContainerFrame { public: - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + /** instantiate a new instance of nsTableColGroupFrame. + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame + * + * @return NS_OK if the frame was properly allocated, otherwise an error code + */ + friend nsresult + NS_NewTableColGroupFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); NS_IMETHOD Paint(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, diff --git a/mozilla/layout/html/table/src/nsTableContent.h b/mozilla/layout/html/table/src/nsTableContent.h deleted file mode 100644 index 4af0813b51a..00000000000 --- a/mozilla/layout/html/table/src/nsTableContent.h +++ /dev/null @@ -1,119 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#ifndef nsTableContent_h__ -#define nsTableContent_h__ - -#include "nscore.h" -#include "nsITableContent.h" -#include "nsHTMLContainer.h" -#include "nsTablePart.h" -#include "nsIAtom.h" - -/** - * TableContent is a concrete base class for all content nodes contained directly - * within a table. - * - * @author sclark - * @version $Revision: 3.8 $ - * @see - */ -class nsTableContent : public nsHTMLContainer, public nsITableContent -{ - -public: - -protected: - /** the table to which this content belongs */ - nsTablePart *mTable; - - /** PR_TRUE if this content was generated in response to incomplete input, - * meaning there is no actual input tag matching this container. - */ - PRBool mImplicit; - -public: - - /** constructor - * @param aTag the HTML tag causing this caption to get constructed. - */ - nsTableContent (nsIAtom* aTag); - - /** constructor - * @param aTag the HTML tag causing this caption to get constructed. - * @param aImplicit PR_TRUE if there is no actual input tag corresponding to - * this caption. - */ - nsTableContent (nsIAtom* aTag, PRBool aImplicit); - - virtual ~nsTableContent(); - - /** supports implementation */ - NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtrResult); - - // For debugging purposes only - NS_IMETHOD_(nsrefcnt) AddRef(); - NS_IMETHOD_(nsrefcnt) Release(); - - /** @see nsITableContent::GetTable */ - nsTablePart* GetTable (); - - /** @see nsITableContent::SetTable - * Note: Since mColGroup is the parent of the table column, - * reference counting should NOT be done. - * see /ns/raptor/doc/MemoryModel.html - **/ - void SetTable (nsTablePart *aTable); - - - /** Set the children of this piece of content to - * be aTable - **/ - void SetTableForChildren(nsTablePart *aTable); - - - /** @see nsITableContent::IsImplicit */ - NS_IMETHOD IsSynthetic(PRBool& aResult); - - /** @see nsITableContent::SkipSelfForSaving */ - virtual PRBool SkipSelfForSaving (); - - /** @see nsITableContent::GetType */ - virtual int GetType()=0; - - /** debug method prints out this and all child frames */ - NS_IMETHOD List(FILE* out, PRInt32 aIndent) const; - - NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify); - NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify); - NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify); - NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify); - - -private: - /** - * - * If the content is a nsTableContent then call SetTable on - * aContent, otherwise, do nothing. - * - */ - void SetTableForTableContent(nsIContent* aContent, nsTablePart *aTable); - -}; - -#endif - diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp index 79231610418..4640d2e517d 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableFrame.cpp @@ -16,19 +16,18 @@ * Reserved. */ #include "nsTableFrame.h" -#include "nsTablePart.h" #include "nsIRenderingContext.h" #include "nsIStyleContext.h" #include "nsIContent.h" #include "nsIContentDelegate.h" #include "nsCellMap.h" #include "nsTableCellFrame.h" -#include "nsTableCol.h" // needed for building implicit columns -#include "nsTableColGroup.h" // needed for building implicit colgroups +#include "nsHTMLParts.h" #include "nsTableColFrame.h" #include "nsTableColGroupFrame.h" #include "nsTableRowFrame.h" #include "nsTableRowGroupFrame.h" +#include "nsIHTMLContent.h" #include "BasicTableLayoutStrategy.h" @@ -495,11 +494,8 @@ PRInt32 nsTableFrame::GetEffectiveCOLSAttribute() NS_PRECONDITION (nsnull!=cellMap, "bad call, cellMap not yet allocated."); PRInt32 result; nsIFrame *tableFrame = this; -// begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! XXX - tableFrame->GetGeometricParent(tableFrame); -// end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! XXX - nsStyleTable *tableStyle; - tableFrame->GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle); + nsStyleTable *tableStyle=nsnull; + GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle); result = tableStyle->mCols; PRInt32 numCols = GetColCount(); if (result>numCols) @@ -526,6 +522,7 @@ void nsTableFrame::EnsureColumns(nsIPresContext* aPresContext, const nsReflowState& aReflowState, nsReflowStatus& aStatus) { +#ifdef XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // XXX sec should only be called on firstInFlow SetMinColSpanForTable(); if (nsnull==mCellMap) @@ -564,14 +561,9 @@ void nsTableFrame::EnsureColumns(nsIPresContext* aPresContext, nsTableColGroup *lastColGroup=nsnull; if (nsnull==lastColGroupFrame) { - //QQQ - // need to find the generic way to stamp out this content, and ::AppendChildTo it - // this might be ok. no matter what my mcontent is, I know it needs a colgroup as a kid? - lastColGroup = new nsTableColGroup (PR_TRUE); // create an implicit colgroup // XXX: instead of Append, maybe this should be insertAt(0)? mContent->AppendChildTo(lastColGroup, PR_FALSE); // add the implicit colgroup to my content - NS_ADDREF(lastColGroup); // ADDREF a: lastColGroup++ // Resolve style for the child nsIStyleContext* colGroupStyleContext = aPresContext->ResolveStyleContextFor(lastColGroup, this, PR_TRUE); // kidStyleContext: REFCNT++ @@ -613,24 +605,26 @@ void nsTableFrame::EnsureColumns(nsIPresContext* aPresContext, { //QQQ // need to find the generic way to stamp out this content, and ::AppendChildTo it nsTableCol *col = new nsTableCol(PR_TRUE); - NS_ADDREF(col); lastColGroup->AppendChildTo (col, PR_FALSE); } NS_RELEASE(lastColGroup); // ADDREF: lastColGroup-- lastColGroupFrame->Reflow(*aPresContext, aDesiredSize, aReflowState, aStatus); } +#endif } /** sum the columns represented by all nsTableColGroup objects * if the cell map says there are more columns than this, * add extra implicit columns to the content tree. */ +// XXX should be nsresult, not void void nsTableFrame::EnsureColumnFrameAt(PRInt32 aColIndex, nsIPresContext* aPresContext, nsReflowMetrics& aDesiredSize, const nsReflowState& aReflowState, nsReflowStatus& aStatus) { + nsresult rv; PRInt32 actualColumns = 0; nsTableColGroupFrame *lastColGroupFrame = nsnull; nsIFrame * firstRowGroupFrame=nsnull; @@ -646,7 +640,7 @@ void nsTableFrame::EnsureColumnFrameAt(PRInt32 aColIndex, actualColumns += numCols; lastColGroupFrame = (nsTableColGroupFrame *)childFrame; if (actualColumns > aColIndex) - break; // we gave enough col frames at this point + break; // we have enough col frames at this point } else if (NS_STYLE_DISPLAY_TABLE_ROW_GROUP == childDisplay->mDisplay || NS_STYLE_DISPLAY_TABLE_HEADER_GROUP == childDisplay->mDisplay || @@ -660,18 +654,21 @@ void nsTableFrame::EnsureColumnFrameAt(PRInt32 aColIndex, } if (actualColumns <= aColIndex) { - nsTableColGroup *lastColGroup=nsnull; + nsIHTMLContent *lastColGroup=nsnull; if (nsnull==lastColGroupFrame) { - lastColGroup = new nsTableColGroup (PR_TRUE); // create an implicit colgroup + // create an implicit colgroup + nsAutoString colGroupTag; + nsHTMLAtoms::colgroup->ToString(colGroupTag); + rv = NS_CreateHTMLElement(&lastColGroup, colGroupTag); // ADDREF a: lastColGroup++ + //XXX mark it as implicit! mContent->AppendChildTo(lastColGroup, PR_FALSE); // add the implicit colgroup to my content - NS_ADDREF(lastColGroup); // ADDREF a: lastColGroup++ // Resolve style for the child nsIStyleContext* colGroupStyleContext = aPresContext->ResolveStyleContextFor(lastColGroup, this, PR_TRUE); // kidStyleContext: REFCNT++ nsIContentDelegate* kidDel = nsnull; kidDel = lastColGroup->GetDelegate(aPresContext); // kidDel: REFCNT++ - nsresult rv = kidDel->CreateFrame(aPresContext, lastColGroup, this, + rv = kidDel->CreateFrame(aPresContext, lastColGroup, this, colGroupStyleContext, (nsIFrame *&)lastColGroupFrame); NS_RELEASE(kidDel); // kidDel: REFCNT-- NS_RELEASE(colGroupStyleContext); // kidStyleContenxt: REFCNT-- @@ -702,12 +699,17 @@ void nsTableFrame::EnsureColumnFrameAt(PRInt32 aColIndex, lastColGroupFrame->GetContent((nsIContent *&)lastColGroup); // ADDREF b: lastColGroup++ } + nsAutoString colTag; + nsHTMLAtoms::col->ToString(colTag); PRInt32 excessColumns = aColIndex - actualColumns; for ( ; excessColumns >= 0; excessColumns--) { - nsTableCol *col = new nsTableCol(PR_TRUE); - NS_ADDREF(col); - lastColGroup->AppendChildTo(col, PR_FALSE); + nsIHTMLContent *col=nsnull; + // create an implicit col + rv = NS_CreateHTMLElement(&col, colTag); // ADDREF: col++ + //XXX mark the col implicit + lastColGroup->AppendChildTo((nsIContent*)col, PR_FALSE); + NS_RELEASE(col); // ADDREF: col-- } NS_RELEASE(lastColGroup); // ADDREF: lastColGroup-- lastColGroupFrame->Reflow(*aPresContext, aDesiredSize, aReflowState, aStatus); @@ -2480,21 +2482,9 @@ void nsTableFrame::BalanceColumnWidths(nsIPresContext* aPresContext, // need to figure out the overall table width constraint // default case, get 100% of available space - // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - nsIFrame * outerTableFrame = nsnull; - const nsStylePosition* position; - GetGeometricParent(outerTableFrame); - outerTableFrame->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)position)); - // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED - - - PRInt32 maxWidth; - /* const nsStylePosition* position = (const nsStylePosition*)mStyleContext->GetStyleData(eStyleStruct_Position); - use this line when tableFrame contains its own position style info - */ switch (position->mWidth.GetUnit()) { case eStyleUnit_Coord: maxWidth = position->mWidth.GetCoordValue(); @@ -2849,8 +2839,6 @@ nsTableFrame::CreateContinuingFrame(nsIPresContext& aPresContext, nsIFrame * rg = nsnull; firstInFlow->FirstChild(rg); NS_ASSERTION (nsnull!=rg, "previous frame has no children"); - nsIAtom * tHeadTag = NS_NewAtom(nsTablePart::kRowGroupHeadTagString); // tHeadTag: REFCNT++ - nsIAtom * tFootTag = NS_NewAtom(nsTablePart::kRowGroupFootTagString); // tFootTag: REFCNT++ PRInt32 index = 0; nsIFrame * bodyRowGroupFromOverflow = mOverflowList; nsIFrame * lastSib = nsnull; @@ -2859,10 +2847,10 @@ nsTableFrame::CreateContinuingFrame(nsIPresContext& aPresContext, nsIContent *content = nsnull; rg->GetContent(content); // content: REFCNT++ NS_ASSERTION(nsnull!=content, "bad frame, returned null content."); - nsIAtom * rgTag; - content->GetTag(rgTag); - // if we've found a header or a footer, replicate it - if (tHeadTag==rgTag || tFootTag==rgTag) + const nsStyleDisplay* display; + GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display); + if ((display->mDisplay == NS_STYLE_DISPLAY_TABLE_HEADER_GROUP) || + (display->mDisplay == NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP)) { printf("found a head or foot in continuing frame\n"); // Resolve style for the child @@ -2887,13 +2875,10 @@ nsTableFrame::CreateContinuingFrame(nsIPresContext& aPresContext, duplicateFrame->SetNextSibling(bodyRowGroupFromOverflow); lastSib = duplicateFrame; } - NS_IF_RELEASE(rgTag); NS_RELEASE(content); // content: REFCNT-- // get the next row group rg->GetNextSibling(rg); } - NS_RELEASE(tFootTag); // tHeadTag: REFCNT -- - NS_RELEASE(tHeadTag); // tFootTag: REFCNT -- aContinuingFrame = cf; return NS_OK; } @@ -3020,6 +3005,7 @@ PRBool nsTableFrame::ConvertToPixelValue(nsHTMLValue& aValue, PRInt32 aDefault, void nsTableFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) { +#if 0 // Check to see if the table has either cell padding or // Cell spacing defined for the table. If true, then // this setting overrides any specific border, margin or @@ -3039,7 +3025,7 @@ void nsTableFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) float p2t = aPresContext->GetPixelsToTwips(); - nsTablePart* table = (nsTablePart*)mContent; + nsIHTMLContent* table = (nsIHTMLContent*)mContent; NS_ASSERTION(table,"Table Must not be null"); if (!table) @@ -3056,6 +3042,7 @@ void nsTableFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) border = NSIntPixelsToTwips(intValue, p2t); } MapHTMLBorderStyle(*spacingData,border); +#endif } @@ -3066,13 +3053,6 @@ NS_METHOD nsTableFrame::DidSetStyleContext(nsIPresContext* aPresContext) { #ifdef NOISY_STYLE printf("nsTableFrame::DidSetStyleContext \n"); -#endif - // XXX This may have been needed before we had a style system, but it's not - // needed now. It's forcing the table to always have a border (which is bad), - // and it's duplicating the border-syle and border-color information that's - // in the ua.css -#if 0 - MapBorderMarginPadding(aPresContext); #endif return NS_OK; } @@ -3092,10 +3072,8 @@ NS_METHOD nsTableFrame::GetCellMarginData(nsTableCellFrame* aKidFrame, nsMargin& nscoord nsTableFrame::GetCellSpacing() { nsTableFrame* tableFrame = this; - //XXX remove when table style is fully resolved! - GetGeometricParent((nsIFrame *&)tableFrame); // get the outer frame nsStyleTable* tableStyle; - tableFrame->GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle); + GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle); nscoord cellSpacing = 0; if (tableStyle->mCellSpacing.GetUnit() == eStyleUnit_Coord) cellSpacing = tableStyle->mCellSpacing.GetCoordValue(); @@ -3125,27 +3103,25 @@ nsTableFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) } -/* ---------- static methods ---------- */ +/* ----- global methods ----- */ -nsresult nsTableFrame::NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +nsresult +NS_NewTableFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableFrame(aContent, aParent); + nsIFrame* it = new nsTableFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } /* helper method for determining if this is a nested table or not */ PRBool nsTableFrame::IsNested(const nsReflowState& aReflowState, nsStylePosition *& aPosition) const { + nsresult rv; PRBool result = PR_FALSE; #ifdef NS_DEBUG PRInt32 counter=0; @@ -3159,8 +3135,8 @@ PRBool nsTableFrame::IsNested(const nsReflowState& aReflowState, nsStylePosition NS_ASSERTION(counter<100000, "infinite loop in IsNested"); #endif nsIFrame* parentTable = nsnull; - rs->frame->QueryInterface(kTableFrameCID, (void**) &parentTable); - if (nsnull!=parentTable) + rv = rs->frame->QueryInterface(kTableFrameCID, (void**) &parentTable); + if (NS_OK==rv) { result = PR_TRUE; parentTable->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)aPosition)); @@ -3174,6 +3150,7 @@ PRBool nsTableFrame::IsNested(const nsReflowState& aReflowState, nsStylePosition /* helper method for getting the width of the table's containing block */ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) { + nsresult rv; nscoord parentWidth = aReflowState.maxSize.width; // Walk up the reflow state chain until we find a block @@ -3186,8 +3163,8 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) { // if it's a block, use its max width nsIFrame* block = nsnull; - rs->frame->QueryInterface(kBlockFrameCID, (void**) &block); - if (nsnull != block) + rv = rs->frame->QueryInterface(kBlockFrameCID, (void**) &block); + if (NS_OK==rv) { // we found a block, see if it's really a table cell (which means we're a nested table) PRBool skipThisBlock=PR_FALSE; if (PR_TRUE==((nsContainerFrame*)block)->IsPseudoFrame()) @@ -3199,8 +3176,8 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) if (nsnull!=parentRS) { nsIFrame* cell = nsnull; - parentRS->frame->QueryInterface(kTableCellFrameCID, (void**) &cell); - if (nsnull != cell) { + rv = parentRS->frame->QueryInterface(kTableCellFrameCID, (void**) &cell); + if (rv == NS_OK) { if (PR_TRUE==gsDebugNT) printf("%p: found a block pframe %p in a cell, skipping it.\n", aReflowState.frame, block); skipThisBlock = PR_TRUE; @@ -3229,9 +3206,9 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) const nsStylePosition* tablePosition; const nsStyleSpacing* spacing; nsIFrame* cell = nsnull; - rs->frame->QueryInterface(kTableCellFrameCID, (void**) &cell); + rv = rs->frame->QueryInterface(kTableCellFrameCID, (void**) &cell); // if the cell has a specified width, use it - if (nsnull != cell) + if (NS_OK==rv) { // Compute and subtract out the insets (sum of border and padding) for the table cell->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)tablePosition)); @@ -3268,8 +3245,8 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) else { nsIFrame* table = nsnull; - rs->frame->QueryInterface(kTableFrameCID, (void**) &table); - if (nsnull != table) { + rv = rs->frame->QueryInterface(kTableFrameCID, (void**) &table); + if (NS_OK==rv) { /* We found the nearest containing table (actually, the inner table). This defines what our percentage size is relative to. Use its desired width as the basis for computing our width. @@ -3280,14 +3257,8 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) ********************************************************************************** */ // Compute and subtract out the insets (sum of border and padding) for the table - /* the following hack is because the outer table really holds the position info */ - // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - nsIFrame * outerTableFrame = nsnull; - table->GetGeometricParent(outerTableFrame); - outerTableFrame->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)tablePosition)); - outerTableFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - + table->GetStyleData(eStyleStruct_Position, (const nsStyleStruct *&)tablePosition); + table->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); if (eStyleUnit_Auto == tablePosition->mWidth.GetUnit()) { parentWidth = NS_UNCONSTRAINEDSIZE; @@ -3399,17 +3370,7 @@ PRBool nsTableFrame::TableIsAutoWidth(nsTableFrame *aTableFrame, PRBool result = PR_TRUE; // the default if (nsnull!=aTableStyle) { - //nsStylePosition* tablePosition = (nsStylePosition*)aTableStyle->GetData(eStyleStruct_Position); - /* this is sick and wrong, but what the hell - we grab the style of our parent (nsTableOuterFrame) and ask it for width info, - until the style resolution stuff does the cool stuff about splitting style between outer and inner - */ - // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - nsIFrame * parent = nsnull; - aTableFrame->GetGeometricParent(parent); - const nsStylePosition* tablePosition; - parent->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)tablePosition)); - // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! + nsStylePosition* tablePosition = (nsStylePosition*)aTableStyle->GetStyleData(eStyleStruct_Position); nsMargin borderPadding; const nsStyleSpacing* spacing; switch (tablePosition->mWidth.GetUnit()) { diff --git a/mozilla/layout/html/table/src/nsTableFrame.h b/mozilla/layout/html/table/src/nsTableFrame.h index 029385a74ca..ac6d6b09d77 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.h +++ b/mozilla/layout/html/table/src/nsTableFrame.h @@ -60,15 +60,16 @@ public: friend class nsTableOuterFrame; /** instantiate a new instance of nsTableFrame. - * @param aInstancePtrResult the new object is returned in this out-param - * @param aContent the table object to map - * @param aParent the parent of the new frame + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame * * @return NS_OK if the frame was properly allocated, otherwise an error code */ - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + friend nsresult + NS_NewTableFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); // nsISupports NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); diff --git a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp index ac39911bb94..7ce83d1e2ff 100644 --- a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp @@ -17,8 +17,6 @@ */ #include "nsTableOuterFrame.h" #include "nsTableFrame.h" -#include "nsITableContent.h" -#include "nsTableContent.h" #include "nsBodyFrame.h" #include "nsIReflowCommand.h" #include "nsIStyleContext.h" @@ -45,8 +43,6 @@ static const PRBool gsDebug = PR_FALSE; static const PRBool gsTiming = PR_FALSE; #endif -static NS_DEFINE_IID(kITableContentIID, NS_ITABLECONTENT_IID); - NS_DEF_PTR(nsIStyleContext); NS_DEF_PTR(nsIContent); @@ -623,13 +619,13 @@ nsresult nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) if (NS_STYLE_DISPLAY_TABLE_CAPTION == childDisplay->mDisplay) { // Create the caption frame. - // XXX In general (e.g. in an XML document) there's no reason to assume - // that the content object is of type nsIHTMLContent - result = ((nsIHTMLContent*)(nsIContent*)caption)->CreateFrame(aPresContext, - this, captionSC, - mCaptionFrame); - if (NS_OK != result) { - return result; + nsIContentDelegate* kidDel = nsnull; + kidDel = caption->GetDelegate(aPresContext); + nsresult rv = kidDel->CreateFrame(aPresContext, caption, this, captionSC, + mCaptionFrame); + NS_RELEASE(kidDel); + if (NS_OK != rv) { + return rv; } // Determine if the caption is a top or bottom caption @@ -849,21 +845,18 @@ nsresult nsTableOuterFrame::CreateInnerTableFrame(nsIPresContext* aPresContext, return NS_OK; } -/* ----- static methods ----- */ +/* ----- global methods ----- */ -nsresult nsTableOuterFrame::NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +nsresult +NS_NewTableOuterFrame( nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableOuterFrame(aContent, aParent); + nsIFrame* it = new nsTableOuterFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } diff --git a/mozilla/layout/html/table/src/nsTableOuterFrame.h b/mozilla/layout/html/table/src/nsTableOuterFrame.h index 43a22d09721..5e13f6bcd70 100644 --- a/mozilla/layout/html/table/src/nsTableOuterFrame.h +++ b/mozilla/layout/html/table/src/nsTableOuterFrame.h @@ -38,16 +38,17 @@ class nsTableOuterFrame : public nsContainerFrame { public: - /** instantiate a new instance of nsTableFrame. - * @param aInstancePtrResult the new object is returned in this out-param - * @param aContent the table object to map - * @param aParent the parent of the new frame + /** instantiate a new instance of nsTableOuterFrame. + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame * * @return NS_OK if the frame was properly allocated, otherwise an error code */ - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + friend nsresult + NS_NewTableOuterFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); /** @see nsIFrame::Paint */ NS_IMETHOD Paint(nsIPresContext& aPresContext, diff --git a/mozilla/layout/html/table/src/nsTablePart.cpp b/mozilla/layout/html/table/src/nsTablePart.cpp deleted file mode 100644 index d0677b7b345..00000000000 --- a/mozilla/layout/html/table/src/nsTablePart.cpp +++ /dev/null @@ -1,883 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#include "nsTablePart.h" -#include "nsTableOuterFrame.h" -#include "nsITableContent.h" -#include "nsTableCol.h" -#include "nsTableColGroup.h" -#include "nsTableRowGroup.h" -#include "nsTableCaption.h" -#include "nsTableRow.h" -#include "nsTableCell.h" -#include "nsHTMLParts.h" -#include "nsIPresContext.h" -#include "nsContainerFrame.h" -#include "nsIRenderingContext.h" -#include "nsHTMLIIDs.h" -#include "nsIAtom.h" -#include "nsIStyleContext.h" -#include "nsHTMLAtoms.h" -#include "nsStyleConsts.h" -#include "nsUnitConversion.h" -#include "nsIHTMLAttributes.h" -#include "nsGenericHTMLElement.h" - -static NS_DEFINE_IID(kITableContentIID, NS_ITABLECONTENT_IID); - -#ifdef NS_DEBUG -static PRBool gsDebug = PR_FALSE; -static PRBool gsNoisyRefs = PR_FALSE; -static PRBool gsDebugWarnings = PR_TRUE; -#else -static const PRBool gsDebug = PR_FALSE; -static const PRBool gsNoisyRefs = PR_FALSE; -static const PRBool gsDebugWarnings = PR_FALSE; -#endif - -const char *nsTablePart::kCaptionTagString="CAPTION"; -const char *nsTablePart::kRowGroupBodyTagString="TBODY"; -const char *nsTablePart::kRowGroupHeadTagString="THEAD"; -const char *nsTablePart::kRowGroupFootTagString="TFOOT"; -const char *nsTablePart::kRowTagString="TR"; -const char *nsTablePart::kColGroupTagString="COLGROUP"; -const char *nsTablePart::kColTagString="COL"; -const char *nsTablePart::kDataCellTagString="TD"; -const char *nsTablePart::kHeaderCellTagString="TH"; - -/*---------- nsTablePart implementation -----------*/ - -/** - * - * BUGS: - *
    - *
  • centering (etc.) is leaking into table cell's from the outer environment - *
- * - * TODO: - *
    - *
  • colspan creating empty cells on rows w/o matching cells - *
  • draw table borders ala navigator - *
  • border sizing - *
  • bordercolor - *
  • draw cell borders ala navigator - *
  • cellspacing - *
  • colspan not the last cell - *
  • floaters in table cells - *
      - *
    • rowspan truncation (rowspan sticking out past the bottom of the table) - *
    • effect on subsequent row structure - *
    - *
  • inherit table border color ala nav4 (use inherited text color) when - * the border is enabled and the bordercolor value nsnull. - *
- * - * - * CSS1: - *
    - *
  • table margin - *
  • table border-width - *
  • table padding - *
  • row margin - *
  • row border-width - *
  • row padding - *
  • cell margin - *
  • cell border-width - *
  • cell padding - *
  • what about colgroup, thead, tbody, tfoot margin/border-width/padding? - *
  • map css1 style (borders, padding, margins) in some sensible manner - *
- * - * CSS2: - *
    - *
  • watch it - *
- * - */ - -//QQQ can remove mColCount? - -/** constructor - * I do not check or addref aTag because my superclass does that for me - */ -nsTablePart::nsTablePart(nsIAtom* aTag) - : nsHTMLContainer(aTag) -{ -} - -/** - */ -nsTablePart::~nsTablePart() -{ -} - -/** - */ -/* -nsTablePart::void compact() { - compact(); -} -*/ - -// for debugging only -nsrefcnt nsTablePart::AddRef(void) -{ - if (gsNoisyRefs==PR_TRUE) printf("Add Ref: nsTablePart cnt = %d \n",mRefCnt+1); - return ++mRefCnt; -} - -// for debugging only -nsrefcnt nsTablePart::Release(void) -{ - if (gsNoisyRefs==PR_TRUE) printf("Release: nsTablePart cnt = %d \n",mRefCnt-1); - if (--mRefCnt == 0) { - if (gsNoisyRefs==PR_TRUE) printf("Delete: nsTablePart \n"); - delete this; - return 0; - } - return mRefCnt; -} - -/** add a child to the table content. - * tables are special because they require the content to be normalized, in order. - * so this function doesn't really "append" the content, but adds it in the proper place, - * possibly nested inside of implicit parents. - * order is: - * Captions (optional) - * Column Groups (1 or more, possibly implicit) - * Row Groups - * THEADs (optional) - * TFOOTs (optional) - * TBODY (at least 1, possibly implicit) - * - */ -NS_IMETHODIMP -nsTablePart::AppendChildTo (nsIContent * aContent, PRBool aNotify) -{ - NS_PRECONDITION(nsnull!=aContent, "bad arg"); - PRBool contentHandled = PR_FALSE; - - // wait, stop! need to check to see if this is really tableContent or not! - nsITableContent *tableContentInterface = nsnull; - PRBool result = PR_TRUE; // to be removed when called methods are COM-ized - nsresult rv = aContent->QueryInterface(kITableContentIID, - (void **)&tableContentInterface); // tableContentInterface: REFCNT++ - if (NS_FAILED(rv)) - { // hold onto the non-table content, but do nothing with it - if (PR_TRUE==gsDebugWarnings) - printf ("non-table content inserted into table."); - rv = nsHTMLContainer::AppendChildTo(aContent, aNotify); - return rv; - } - else - { - nsTableContent *tableContent = (nsTableContent *)tableContentInterface; - const int contentType = tableContent->GetType(); - if ((contentType == nsITableContent::kTableCellType) || - (contentType==nsITableContent::kTableRowType)) - { - if (gsDebug==PR_TRUE) - { - if (contentType == nsITableContent::kTableRowType) - printf ("nsTablePart::AppendChildTo -- adding a row.\n"); - else - printf ("nsTablePart::AppendChildTo -- adding a cell.\n"); - } - // find last row group, if ! implicit, make one, append there - nsTableRowGroup *group = nsnull; - int index; - ChildCount (index); - while ((0 < index) && (nsnull==group)) - { - nsIContent *child; - ChildAt (--index, child); // child: REFCNT++ - if (nsnull != child) - { - nsTableContent * content = (nsTableContent *)child; - if (content->GetType()==nsITableContent::kTableRowGroupType) - { - group = (nsTableRowGroup *)content; - NS_ADDREF(group); // group: REFCNT++ - // SEC: this code might be a space leak for tables >1 row group - } - } - NS_RELEASE(child); // child: REFCNT-- - } - PRBool groupIsImplicit = PR_FALSE; - if (nsnull!=group) - group->IsSynthetic(groupIsImplicit); - if ((nsnull == group) || (PR_FALSE==groupIsImplicit)) - { - if (gsDebug==PR_TRUE) printf ("nsTablePart::AppendChildTo -- creating an implicit row group.\n"); - nsIAtom * rowGroupTag = NS_NewAtom(kRowGroupBodyTagString); // rowGroupTag: REFCNT++ - group = new nsTableRowGroup (rowGroupTag, PR_TRUE); - NS_ADDREF(group); // group: REFCNT++ - rv = AppendChildTo (group, PR_FALSE); - if (NS_OK==rv) - group->SetTable(this); - NS_RELEASE(rowGroupTag); // rowGroupTag: REFCNT-- - } - // group is guaranteed to be allocated at this point - rv = group->AppendChildTo(aContent, PR_FALSE); - contentHandled = PR_TRUE; - NS_RELEASE(group); // group: REFCNT-- - } - else if (contentType == nsITableContent::kTableColType) - { - // TODO: switch Append* to COM interfaces - result = AppendColumn((nsTableCol *)aContent); - contentHandled = PR_TRUE; - } - else if (contentType == nsITableContent::kTableCaptionType) - { - result = AppendCaption((nsTableCaption *)aContent); - contentHandled = PR_TRUE; // whether we succeeded or not, we've "handled" this request - } - else if (contentType == nsITableContent::kTableRowGroupType) - { - result = AppendRowGroup((nsTableRowGroup *)aContent); - if (PR_FALSE==result) - rv=NS_ERROR_FAILURE; - contentHandled = PR_TRUE; // whether we succeeded or not, we've "handled" this request - } - else if (contentType == nsITableContent::kTableColGroupType) - { - result = AppendColGroup((nsTableColGroup *)aContent); - if (PR_FALSE==result) - rv = NS_ERROR_FAILURE; - contentHandled = PR_TRUE; // whether we succeeded or not, we've "handled" this request - } - - /* if aContent is not a known content type, make a capion out of it */ - // SEC the logic here is very suspicious!!!! - if (PR_FALSE==contentHandled) - { - if (gsDebug==PR_TRUE) printf ("nsTablePart::AppendChildTo -- content not handled!!!\n"); - nsTableCaption *caption = nsnull; - nsIContent *lastChild; - PRInt32 numKids; - ChildCount(numKids); - ChildAt (numKids - 1, lastChild); // lastChild: REFCNT++ - if (nsnull != lastChild) - { - nsTableContent * content = (nsTableContent *)lastChild; - if (content->GetType()==nsITableContent::kTableCaptionType) - caption = (nsTableCaption *)content; - NS_RELEASE(lastChild); // lastChild: REFCNT-- - } - PRBool captionIsImplicit = PR_FALSE; - if (nsnull!=caption) - caption->IsSynthetic(captionIsImplicit); - if ((nsnull == caption) || (PR_FALSE==captionIsImplicit)) - { - if (gsDebug==PR_TRUE) printf ("nsTablePart::AppendChildTo -- adding an implicit caption.\n"); - caption = new nsTableCaption (PR_TRUE); - result = AppendCaption (caption); - // check result - } - result = caption->AppendChildTo (aContent, PR_FALSE); - } - } - NS_RELEASE(tableContentInterface); // tableContentInterface: REFCNT-- - - return rv; -} - -/* SEC: why can we only insertChildAt (captions or groups) ? */ -NS_IMETHODIMP -nsTablePart::InsertChildAt(nsIContent * aContent, PRInt32 aIndex, - PRBool aNotify) -{ - NS_PRECONDITION(nsnull!=aContent, "bad arg"); - // aIndex checked in nsHTMLContainer - - nsresult rv = NS_OK; - nsTableContent *tableContent = (nsTableContent *)aContent; - const int contentType = tableContent->GetType(); - if ((contentType == nsITableContent::kTableCaptionType) || - (contentType == nsITableContent::kTableColGroupType) || - (contentType == nsITableContent::kTableRowGroupType)) - { - rv = nsHTMLContainer::InsertChildAt (aContent, aIndex, PR_FALSE); - if (NS_OK == rv) - { - tableContent->SetTable (this); - } - } - - return rv; -} - -NS_IMETHODIMP -nsTablePart::ReplaceChildAt (nsIContent *aContent, PRInt32 aIndex, - PRBool aNotify) -{ - PRInt32 numKids; - ChildCount(numKids); - NS_PRECONDITION(nsnull!=aContent, "bad aContent arg to ReplaceChildAt"); - NS_PRECONDITION(0<=aIndex && aIndexGetType(); - if ( (contentType == nsITableContent::kTableCaptionType) || - (contentType == nsITableContent::kTableColGroupType) || - (contentType == nsITableContent::kTableRowGroupType)) - { - nsIContent *lastChild; - ChildAt (aIndex, lastChild);// lastChild: REFCNT++ - rv = nsHTMLContainer::ReplaceChildAt (aContent, aIndex, PR_FALSE); - if (NS_OK == rv) - { - if (nsnull != lastChild) - tableContent->SetTable (nsnull); - tableContent->SetTable (this); - } - NS_IF_RELEASE(lastChild); // lastChild: REFCNT-- - } - - return rv; -} - -/** - * Remove a child at the given position. The method is a no-op if - * the index is invalid (too small or too large). - */ -NS_IMETHODIMP -nsTablePart::RemoveChildAt (PRInt32 aIndex, PRBool aNotify) -{ - PRInt32 numKids; - ChildCount(numKids); - NS_PRECONDITION(0<=aIndex && aIndexGetType(); - if (contentType == nsITableContent::kTableRowType) - { - if (nsnull != lastChild) - ((nsTableRow *)tableContent)->SetRowGroup (nsnull); - tableContent->SetTable(nsnull); - } - } - NS_IF_RELEASE(lastChild); - - return rv; -} - -/** protected method for appending a column group to this table */ -PRBool nsTablePart::AppendRowGroup (nsTableRowGroup *aContent) -{ - PRInt32 childIndex; - NS_PRECONDITION(nsnull!=aContent, "null arg."); - PRBool result = PR_TRUE; - if (gsDebug==PR_TRUE) - printf ("nsTablePart::AppendRowGroup -- adding a row group.\n"); - // find the last row group of this kind and insert this row group after it - // if there is no row group of this type already in the table, - // find the appropriate slot depending on this row group tag - nsIAtom * rowGroupTag; - aContent->GetTag(rowGroupTag); - PRInt32 childCount; - ChildCount (childCount); - nsIAtom * tHeadTag = NS_NewAtom(kRowGroupHeadTagString); // tHeadTag: REFCNT++ - nsIAtom * tFootTag = NS_NewAtom(kRowGroupFootTagString); // tFootTag: REFCNT++ - nsIAtom * tBodyTag = NS_NewAtom(kRowGroupBodyTagString); // tBodyTag: REFCNT++ - for (childIndex = 0; childIndex < childCount; childIndex++) - { - nsITableContent *tableContentInterface = nsnull; - nsIContent * child; - ChildAt(childIndex, child); // tableChild: REFCNT++ - nsresult rv = child->QueryInterface(kITableContentIID, - (void **)&tableContentInterface); // tableContentInterface: REFCNT++ - if (NS_FAILED(rv)) - { - NS_RELEASE(child); // tableChild: REFCNT-- (a) - continue; - } - nsTableContent *tableChild = (nsTableContent *)tableContentInterface; - const int tableChildType = tableChild->GetType(); - // if we've found caption or colgroup, then just skip it and keep going - if ((tableChildType == nsITableContent::kTableCaptionType) || - (tableChildType == nsITableContent::kTableColGroupType)) - { - NS_RELEASE(child); // tableChild: REFCNT-- (b) - NS_RELEASE(tableContentInterface); // tableContentInterface: REFCNT-- - continue; - } - // if we've found a row group, our action depends on what kind of row group - else if (tableChildType == nsITableContent::kTableRowGroupType) - { - // XXX we are leaking tableChildTag - nsIAtom * tableChildTag; - tableChild->GetTag(tableChildTag); - NS_RELEASE(child); // tableChild: REFCNT-- (c) - NS_RELEASE(tableContentInterface); // tableContentInterface: REFCNT-- - // if aContent is a header and the current child is a header, keep going - if (tHeadTag==rowGroupTag && tHeadTag==tableChildTag) - { - continue; - } - // if aContent is a footer and the current child is either a header or a footer, keep going - else if (tFootTag==rowGroupTag && - (tHeadTag==tableChildTag || - tFootTag==tableChildTag)) - { - continue; - } - // if aContent is a body and the current child is a footer, stop, we've found the spot - else if (tBodyTag==rowGroupTag && tFootTag==tableChildTag) - { - continue; - } - // if aContent is a body and we've gotten this far, keep going - else if (tBodyTag==rowGroupTag) - { - continue; - } - // otherwise, we must have found the right spot so stop - else - { - break; - } - } - // otherwise we're already at the right spot, so stop - else - { - NS_RELEASE(child); // tableChild: REFCNT-- (d) - NS_RELEASE(tableContentInterface); // tableContentInterface: REFCNT-- - break; - } - } - NS_RELEASE(tFootTag); - NS_RELEASE(tHeadTag); - NS_RELEASE(tBodyTag); - - nsresult rv = nsHTMLContainer::InsertChildAt(aContent, childIndex, PR_FALSE); - if (NS_OK==rv) - ((nsTableContent *)aContent)->SetTable (this); - else - result = PR_FALSE; - - return result; -} - -/** protected method for appending a column group to this table */ -PRBool nsTablePart::AppendColGroup(nsTableColGroup *aContent) -{ - PRBool result = PR_TRUE; // to be removed when I'm COM-ized - PRInt32 childIndex; - NS_PRECONDITION(nsnull!=aContent, "null arg."); - if (gsDebug==PR_TRUE) - printf ("nsTablePart::AppendColGroup -- adding a column group.\n"); - // find the last column group and insert this column group after it. - // if there is no column group already in the table, make this the first child - // after any caption - PRInt32 childCount; - ChildCount (childCount); - for (childIndex = 0; childIndex < childCount; childIndex++) - { - nsIContent *child; - ChildAt(childIndex, child); // child: REFCNT++ - nsITableContent *tableContentInterface = nsnull; - nsresult rv = child->QueryInterface(kITableContentIID, - (void **)&tableContentInterface); // tableContentInterface: REFCNT++ - if (NS_FAILED(rv)) - { - NS_RELEASE(child); - continue; - } - const int tableChildType = tableContentInterface->GetType(); - NS_RELEASE(child); // tableChild: REFCNT-- - NS_RELEASE(tableContentInterface); - if (!((tableChildType == nsITableContent::kTableCaptionType) || - (tableChildType == nsITableContent::kTableColGroupType))) - break; - } - nsresult rv = nsHTMLContainer::InsertChildAt(aContent, childIndex, PR_FALSE); - if (NS_OK==rv) - ((nsTableContent *)aContent)->SetTable (this); - else - result = PR_FALSE; - - // if col group has a SPAN attribute, create implicit columns for - // the value of SPAN what sucks is if we then get a COL for this - // COLGROUP, we have to delete all the COLs we created for SPAN, and - // just contain the explicit COLs. - - // TODO: move this into the OK clause above - - PRInt32 span = 0; // SEC: TODO find a way to really get this - for (PRInt32 i=0; iAppendChildTo (col, PR_FALSE); - if (NS_OK!=rv) - { - result = PR_FALSE; - break; - } - } - - return result; -} - -/** protected method for appending a column group to this table */ -PRBool nsTablePart::AppendColumn(nsTableCol *aContent) -{ - NS_PRECONDITION(nsnull!=aContent, "null arg."); - nsresult rv = NS_OK; - if (gsDebug==PR_TRUE) - printf ("nsTablePart::AppendColumn -- adding a column.\n"); - // find last col group, if ! implicit, make one, append there - nsTableColGroup *group = nsnull; - PRBool foundColGroup = PR_FALSE; - PRInt32 index; - ChildCount (index); - while ((0 < index) && (PR_FALSE==foundColGroup)) - { - nsITableContent *tableContentInterface = nsnull; - nsIContent *child; - ChildAt (--index, child); // child: REFCNT++ - nsresult rv = child->QueryInterface(kITableContentIID, - (void **)&tableContentInterface); // tableContentInterface: REFCNT++ - NS_RELEASE(child); // tableChild: REFCNT-- (a) - if (NS_FAILED(rv)) - { - continue; - } - - group = (nsTableColGroup *)tableContentInterface; - foundColGroup = (PRBool) - (group->GetType()==nsITableContent::kTableColGroupType); - if (PR_FALSE==foundColGroup) - { // release all the table contents that are not a col group - NS_RELEASE(tableContentInterface); // tableContentInterface: REFCNT-- (a) - } - } - PRBool groupIsImplicit = PR_FALSE; - if (nsnull!=group) - group->IsSynthetic(groupIsImplicit); - if ((PR_FALSE == foundColGroup) || (PR_FALSE==groupIsImplicit)) - { - if (gsDebug==PR_TRUE) - printf ("nsTablePart::AppendChildTo -- creating an implicit column group.\n"); - group = new nsTableColGroup (PR_TRUE); - rv = AppendChildTo (group, PR_FALSE); - if (NS_OK==rv) - group->SetTable(this); - } - if (NS_OK==rv) - rv = group->AppendChildTo (aContent, PR_FALSE); - - NS_IF_RELEASE(group); // tableContentInterface: REFCNT-- (b) - return (PRBool)(NS_OK==rv); -} - -/** protected method for appending a column group to this table */ -PRBool nsTablePart::AppendCaption(nsTableCaption *aContent) -{ - nsresult rv = NS_OK; - PRInt32 childIndex; - NS_PRECONDITION(nsnull!=aContent, "null arg."); - if (gsDebug==PR_TRUE) - printf ("nsTablePart::AppendCaption -- adding a caption.\n"); - // find the last caption and insert this caption after it. - // if there is no caption already in the table, make this the first child - PRInt32 childCount; - ChildCount (childCount); - for (childIndex = 0; childIndex < childCount; childIndex++) - { - nsITableContent *tableContentInterface = nsnull; - nsIContent *child; - ChildAt (childIndex, child); // child: REFCNT++ - nsresult rv = child->QueryInterface(kITableContentIID, - (void **)&tableContentInterface); // tableContentInterface: REFCNT++ - NS_RELEASE(child); // tableChild: REFCNT-- (a) - if (NS_FAILED(rv)) - { - continue; - } - const int tableChildType = tableContentInterface->GetType(); - NS_RELEASE(tableContentInterface); - if (tableChildType != nsITableContent::kTableCaptionType) - break; - } - rv = nsHTMLContainer::InsertChildAt(aContent, childIndex, PR_FALSE); - if (NS_OK==rv) - ((nsTableContent *)aContent)->SetTable (this); - - return (PRBool)(NS_OK==rv); -} - -/** - * Create a frame object that will layout this table. - */ -nsresult -nsTablePart::CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult) -{ - NS_PRECONDITION(nsnull!=aPresContext, "bad arg"); - - nsIFrame* frame; - nsresult rv = nsTableOuterFrame::NewFrame(&frame, this, aParentFrame); - if (NS_OK != rv) { - return rv; - } - frame->SetStyleContext(aPresContext, aStyleContext); - aResult = frame; - return rv; -} - -NS_IMETHODIMP -nsTablePart::SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify) -{ - nsHTMLValue val; - - - if (aAttribute == nsHTMLAtoms::width) - { - ParseValueOrPercent(aValue, val, eHTMLUnit_Pixel); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - else if ( aAttribute == nsHTMLAtoms::cols) - { // it'll either be empty, or have an integer value - nsAutoString tmp(aValue); - tmp.StripWhitespace(); - if (0 == tmp.Length()) { - val.SetEmptyValue(); - } - else - { - ParseValue(aValue, 0, val, eHTMLUnit_Integer); - } - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - else if ( aAttribute == nsHTMLAtoms::border) - { - nsAutoString tmp(aValue); - tmp.StripWhitespace(); - if (0 == tmp.Length()) { - // Just enable the border; same as border=1 - val.SetEmptyValue();/* XXX pixels? */ - } - else - { - ParseValue(aValue, 0, val, eHTMLUnit_Pixel); - } - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - else if (aAttribute == nsHTMLAtoms::cellspacing || - aAttribute == nsHTMLAtoms::cellpadding) - { - ParseValue(aValue, 0, val, eHTMLUnit_Pixel); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - else if (aAttribute == nsHTMLAtoms::bgcolor) - { - ParseColor(aValue, val); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - else if (aAttribute == nsHTMLAtoms::align) { - if (ParseTableAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - } - /* HTML 4 attributes */ - // TODO: only partially implemented - else if (aAttribute == nsHTMLAtoms::summary) { - val.SetStringValue(aValue); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - - // Use default attribute catching code - return nsHTMLTagContent::SetAttribute(aAttribute, aValue, aNotify); -} - -static void -MapTableBorderInto(nsIHTMLAttributes* aAttributes, - nsIStyleContext* aContext, - nsIPresContext* aPresContext) -{ - NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); - NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); - - nsHTMLValue value; - - aAttributes->GetAttribute(nsHTMLAtoms::border, value); - if ((value.GetUnit() == eHTMLUnit_Pixel) || - (value.GetUnit() == eHTMLUnit_Empty)) { - nsStyleSpacing* spacing = (nsStyleSpacing*) - aContext->GetMutableStyleData(eStyleStruct_Spacing); - float p2t = aPresContext->GetPixelsToTwips(); - nsStyleCoord twips; - if (value.GetUnit() == eHTMLUnit_Empty) { - twips.SetCoordValue(NSIntPixelsToTwips(1, p2t)); - } - else { - twips.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); - } - -#if 0 - nsStyleCoord two(NSIntPixelsToTwips(2, p2t)); - - spacing->mPadding.SetTop(two); - spacing->mPadding.SetRight(two); - spacing->mPadding.SetBottom(two); - spacing->mPadding.SetLeft(two); -#endif - - spacing->mBorder.SetTop(twips); - spacing->mBorder.SetRight(twips); - spacing->mBorder.SetBottom(twips); - spacing->mBorder.SetLeft(twips); - - if (spacing->mBorderStyle[0] == NS_STYLE_BORDER_STYLE_NONE) { - spacing->mBorderStyle[0] = NS_STYLE_BORDER_STYLE_SOLID; - } - if (spacing->mBorderStyle[1] == NS_STYLE_BORDER_STYLE_NONE) { - spacing->mBorderStyle[1] = NS_STYLE_BORDER_STYLE_SOLID; - } - if (spacing->mBorderStyle[2] == NS_STYLE_BORDER_STYLE_NONE) { - spacing->mBorderStyle[2] = NS_STYLE_BORDER_STYLE_SOLID; - } - if (spacing->mBorderStyle[3] == NS_STYLE_BORDER_STYLE_NONE) { - spacing->mBorderStyle[3] = NS_STYLE_BORDER_STYLE_SOLID; - } - } -} - -static void -MapAttributesInto(nsIHTMLAttributes* aAttributes, - nsIStyleContext* aContext, - nsIPresContext* aPresContext) -{ - NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); - NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); - - float p2t = aPresContext->GetPixelsToTwips(); - nsHTMLValue value; - - // width - aAttributes->GetAttribute(nsHTMLAtoms::width, value); - if (value.GetUnit() != eHTMLUnit_Null) { - nsStylePosition* position = (nsStylePosition*) - aContext->GetMutableStyleData(eStyleStruct_Position); - switch (value.GetUnit()) { - case eHTMLUnit_Percent: - position->mWidth.SetPercentValue(value.GetPercentValue()); - break; - - case eHTMLUnit_Pixel: - position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); - break; - } - } - // border - MapTableBorderInto(aAttributes, aContext, aPresContext); - - // align - aAttributes->GetAttribute(nsHTMLAtoms::align, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) { // it may be another type if illegal - nsStyleDisplay* display = (nsStyleDisplay*)aContext->GetMutableStyleData(eStyleStruct_Display); - switch (value.GetIntValue()) { - case NS_STYLE_TEXT_ALIGN_LEFT: - display->mFloats = NS_STYLE_FLOAT_LEFT; - break; - - case NS_STYLE_TEXT_ALIGN_RIGHT: - display->mFloats = NS_STYLE_FLOAT_RIGHT; - break; - } - } - - // cellpadding - nsStyleTable* tableStyle=nsnull; - aAttributes->GetAttribute(nsHTMLAtoms::cellpadding, value); - if (value.GetUnit() == eHTMLUnit_Pixel) { - tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); - tableStyle->mCellPadding.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); - } - - // cellspacing (reuses tableStyle if already resolved) - aAttributes->GetAttribute(nsHTMLAtoms::cellspacing, value); - if (value.GetUnit() == eHTMLUnit_Pixel) { - if (nsnull==tableStyle) - tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); - tableStyle->mCellSpacing.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); - } - else - { // XXX: remove me as soon as we get this from the style sheet - if (nsnull==tableStyle) - tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); - tableStyle->mCellSpacing.SetCoordValue(NSIntPixelsToTwips(2, p2t)); - } - - // cols - aAttributes->GetAttribute(nsHTMLAtoms::cols, value); - if (value.GetUnit() != eHTMLUnit_Null) { - if (nsnull==tableStyle) - tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); - if (value.GetUnit() == eHTMLUnit_Integer) - tableStyle->mCols = value.GetIntValue(); - else // COLS had no value, so it refers to all columns - tableStyle->mCols = NS_STYLE_TABLE_COLS_ALL; - } - - //background: color - nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); -} - -NS_IMETHODIMP -nsTablePart::GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const -{ - aMapFunc = &MapAttributesInto; - return NS_OK; -} - - -/* ---------- Global Functions ---------- */ - -/** - */ -nsresult -NS_NewTablePart(nsIHTMLContent** aInstancePtrResult, - nsIAtom* aTag) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIHTMLContent* table = new nsTablePart(aTag); - if (nsnull == table) { - return NS_ERROR_OUT_OF_MEMORY; - } - return table->QueryInterface(kIHTMLContentIID, (void **) aInstancePtrResult); -} - diff --git a/mozilla/layout/html/table/src/nsTablePart.h b/mozilla/layout/html/table/src/nsTablePart.h deleted file mode 100644 index c82a5c451e9..00000000000 --- a/mozilla/layout/html/table/src/nsTablePart.h +++ /dev/null @@ -1,125 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#ifndef nsTablePart_h___ -#define nsTablePart_h___ - - -// nsTablePart.h -#include "nsHTMLContainer.h" - -// forward declarations -class nsTableRowGroup; -class nsTableColGroup; -class nsTableCol; -class nsTableCaption; - -/** - * Table Content Model. - * We build a full rationalized content model, so the structure of a table - * will always be regular and predictable. - * A Table can contain RowGroups (THEAD, TBODY, TFOOT), ColumnGroups (COLGROUP), - * and Captions (CAPTION). Any other table content (TH, TD, COL) belongs in - * one of these containers, and if the container doesn't explicitly exist in - * the source, an implicit container will get created. - * - * @author sclark - */ -class nsTablePart : public nsHTMLContainer { - -public: - - /** known HTML tags */ - static const char *kCaptionTagString; - static const char *kRowGroupBodyTagString; - static const char *kRowGroupHeadTagString; - static const char *kRowGroupFootTagString; - static const char *kRowTagString; - static const char *kColGroupTagString; - static const char *kColTagString; - static const char *kDataCellTagString; - static const char *kHeaderCellTagString; - - /** constructor - * @param aTag the HTML tag that caused this content node to be instantiated - */ - nsTablePart(nsIAtom* aTag); - - /** constructor - * @param aTag the HTML tag that caused this content node to be instantiated - * @param aColumnCount the number of columns in this table - */ - nsTablePart(nsIAtom* aTag, PRInt32 aColumnCount); - - // For debugging purposes only - NS_IMETHOD_(nsrefcnt) AddRef(); - NS_IMETHOD_(nsrefcnt) Release(); - - NS_IMETHOD SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify); - - NS_IMETHOD GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const; - - -/* overrides from nsHTMLContainer */ - - NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify); - NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify); - NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify); - NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify); - - NS_IMETHOD CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult); - - - static void GetTableBorder(nsIHTMLContent* aContent, - nsIStyleContext* aContext, - nsIPresContext* aPresContext); - -protected: - /** destructor - */ - virtual ~nsTablePart(); - - /** append aContent to my child list - * @return PR_TRUE on success, PR_FALSE if aContent could not be appended - */ - virtual PRBool AppendRowGroup(nsTableRowGroup *aContent); - - /** append aContent to my child list - * @return PR_TRUE on success, PR_FALSE if aContent could not be appended - */ - virtual PRBool AppendColGroup(nsTableColGroup *aContent); - - /** append aContent to my child list - * @return PR_TRUE on success, PR_FALSE if aContent could not be appended - */ - virtual PRBool AppendColumn(nsTableCol *aContent); - - /** append aContent to my child list - * @return PR_TRUE on success, PR_FALSE if aContent could not be appended - */ - virtual PRBool AppendCaption(nsTableCaption *aContent); - -private: - - static nsIAtom *kDefaultTag; -}; - -#endif // nsTablePart_h___ diff --git a/mozilla/layout/html/table/src/nsTableRow.cpp b/mozilla/layout/html/table/src/nsTableRow.cpp deleted file mode 100644 index c1afd2f5b14..00000000000 --- a/mozilla/layout/html/table/src/nsTableRow.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#include "nsTableRow.h" -#include "nsTableRowFrame.h" -#include "nsTableRowGroup.h" -#include "nsTableCell.h" -#include "nsTableFrame.h" -#include "nsHTMLParts.h" -#include "nsHTMLContainer.h" -#include "nsTableRowFrame.h" -#include "nsIReflowCommand.h" -#include "nsIStyleContext.h" -#include "nsStyleConsts.h" -#include "nsIContentDelegate.h" -#include "nsHTMLIIDs.h" -#include "nsHTMLAtoms.h" -#include "nsIHTMLAttributes.h" -#include "nsGenericHTMLElement.h" - -static NS_DEFINE_IID(kITableContentIID, NS_ITABLECONTENT_IID); - -#ifdef NS_DEBUG -static PRBool gsDebug = PR_FALSE; -static PRBool gsNoisyRefs = PR_FALSE; -#else -static const PRBool gsDebug = PR_FALSE; -static const PRBool gsNoisyRefs = PR_FALSE; -#endif - -// nsTableContent checks aTag -nsTableRow::nsTableRow(nsIAtom* aTag) - : nsTableContent(aTag), - mRowGroup(0), - mRowIndex(0) -{ -} - -// nsTableContent checks aTag -nsTableRow::nsTableRow(nsIAtom* aTag, PRBool aImplicit) - : nsTableContent(aTag), - mRowGroup(0), - mRowIndex(0) -{ - mImplicit = aImplicit; -} - -nsTableRow::~nsTableRow() -{ -} - -int nsTableRow::GetType() -{ - return nsITableContent::kTableRowType; -} - -nsTableRowGroup * nsTableRow::GetRowGroup () -{ - NS_IF_ADDREF(mRowGroup); - return mRowGroup; -} - -void nsTableRow::SetRowGroup (nsTableRowGroup * aRowGroup) -{ - if (aRowGroup != mRowGroup) - { - mRowGroup = aRowGroup; - } -} - -PRInt32 nsTableRow::GetRowIndex () -{ - NS_PRECONDITION(0<=mRowIndex, "bad mRowIndex"); - return mRowIndex; -} - -void nsTableRow::SetRowIndex (int aRowIndex) -{ - mRowIndex = aRowIndex; -} - -// Added for debuging purposes -- remove from final build -nsrefcnt nsTableRow::AddRef(void) -{ - if (gsNoisyRefs==PR_TRUE) printf("Add Ref: %x, nsTableRow cnt = %d \n",this, mRefCnt+1); - return ++mRefCnt; -} - -nsrefcnt nsTableRow::Release(void) -{ - if (gsNoisyRefs==PR_TRUE) printf("Release: %x, nsTableRow cnt = %d \n",this,mRefCnt-1); - if (--mRefCnt == 0) { - if (gsNoisyRefs==PR_TRUE) printf("Delete: %x, nsTableRow \n",this); - delete this; - return 0; - } - return mRefCnt; -} - - -NS_IMETHODIMP -nsTableRow::AppendChildTo (nsIContent *aContent, PRBool aNotify) -{ - NS_PRECONDITION(nsnull != aContent, "null ptr"); - nsresult rv = NS_OK; - if (nsnull!=aContent) - { - if (!IsTableCell(aContent)) - { - if (gsDebug==PR_TRUE) printf ("nsTableRow::AppendChildTo -- didn't get a cell, giving up to parent.\n"); - if (nsnull != mRowGroup) - return mRowGroup->AppendChildTo (aContent, aNotify); // let parent have it - return PR_FALSE; - } - else - { - rv = nsTableContent::AppendChildTo (aContent, aNotify); - if (NS_OK == rv) - { - ((nsTableCell *)aContent)->SetRow (this); - } - } - } - return rv; -} - -NS_IMETHODIMP -nsTableRow::InsertChildAt (nsIContent *aContent, PRInt32 aIndex, - PRBool aNotify) -{ - NS_PRECONDITION(nsnull != aContent, "null ptr"); - nsresult rv = NS_OK; - if (nsnull!=aContent) - { - if (!IsTableCell(aContent)) - { // I only insert cells for now - // TODO: wrap whatever I'm given here in a cell and insert it - NS_ASSERTION(PR_FALSE, "unimplemented attempt to insert a non-cell into a row"); - return NS_ERROR_FAILURE; - } - else - { - rv = nsTableContent::InsertChildAt (aContent, aIndex, aNotify); - if (NS_OK == rv) - { - ((nsTableCell *)aContent)->SetRow (this); - } - } - } - return rv; -} - - -NS_IMETHODIMP -nsTableRow::ReplaceChildAt (nsIContent *aContent, PRInt32 aIndex, - PRBool aNotify) -{ - nsresult rv = NS_OK; - - PRInt32 numKids; - ChildCount(numKids); - NS_PRECONDITION(nsnull!=aContent, "bad aContent arg to ReplaceChildAt"); - NS_PRECONDITION(0<=aIndex && aIndexSetRow (this); - if (nsnull!=oldChild) - ((nsTableCell *)oldChild)->SetRow (nsnull); - } - NS_IF_RELEASE(oldChild); // oldChild: REFCNT-- -#endif - } -} - -/** - * Remove a child at the given position. The method is ignored if - * the index is invalid (too small or too large). - */ -NS_IMETHODIMP -nsTableRow::RemoveChildAt (int aIndex, PRBool aNotify) -{ - PRInt32 numKids; - ChildCount(numKids); - NS_PRECONDITION(0<=aIndex && aIndexSetRow (nsnull); - } - } - NS_IF_RELEASE(oldChild); // oldChild: REFCNT-- - return rv; -} - -NS_IMETHODIMP -nsTableRow::SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify) -{ - NS_PRECONDITION(nsnull!=aAttribute, "bad attribute arg"); - nsHTMLValue val; - if (aAttribute == nsHTMLAtoms::bgcolor) { - ParseColor(aValue, val); - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if ((aAttribute == nsHTMLAtoms::align) && - ParseDivAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if ((aAttribute == nsHTMLAtoms::valign) && - ParseAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - return nsTableContent::SetAttribute(aAttribute, aValue, aNotify); -} - -static void -MapAttributesInto(nsIHTMLAttributes* aAttributes, - nsIStyleContext* aContext, - nsIPresContext* aPresContext) -{ - NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); - NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); - if (nsnull != aAttributes) { - nsHTMLValue value; - nsStyleText* textStyle = nsnull; - - // align: enum - aAttributes->GetAttribute(nsHTMLAtoms::align, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) - { - textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - textStyle->mTextAlign = value.GetIntValue(); - } - - // valign: enum - aAttributes->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); - } - - //background: color - nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); - } - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); -} - -NS_IMETHODIMP -nsTableRow::GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const -{ - aMapFunc = &MapAttributesInto; - return NS_OK; -} - - - -NS_IMETHODIMP -nsTableRow::AttributeToString(nsIAtom* aAttribute, - nsHTMLValue& aValue, - nsString& aResult) const -{ - nsresult ca = NS_CONTENT_ATTR_NOT_THERE; - if (aAttribute == nsHTMLAtoms::valign) { - AlignParamToString(aValue, aResult); - ca = NS_CONTENT_ATTR_HAS_VALUE; - } - else { - ca = nsTableContent::AttributeToString(aAttribute, aValue, aResult); - } - return ca; -} - -nsresult -nsTableRow::CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult) -{ - NS_PRECONDITION(nsnull!=aPresContext, "bad arg"); - - nsIFrame* frame; - nsresult rv = nsTableRowFrame::NewFrame(&frame, this, aParentFrame); - if (NS_OK != rv) { - return rv; - } - ((nsTableRowFrame*)frame)->Init(mRowIndex); - frame->SetStyleContext(aPresContext, aStyleContext); - aResult = frame; - return rv; -} - -/** support method to determine if the param aContent is a TableCell object */ -PRBool nsTableRow::IsTableCell(nsIContent * aContent) const -{ - PRBool result = PR_FALSE; - if (nsnull!=aContent) - { - // is aContent a table cell? - nsITableContent *tableContentInterface = nsnull; - nsresult rv = aContent->QueryInterface(kITableContentIID, - (void **)&tableContentInterface); // tableContentInterface: REFCNT++ - - const int contentType = tableContentInterface->GetType(); - NS_RELEASE(tableContentInterface); - if (contentType == nsITableContent::kTableCellType) - result = PR_TRUE; - } - return result; -} - -/* ---------- Global Functions ---------- */ - -nsresult -NS_NewTableRowPart(nsIHTMLContent** aInstancePtrResult, - nsIAtom* aTag) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIHTMLContent* body = new nsTableRow(aTag); - if (nsnull == body) { - return NS_ERROR_OUT_OF_MEMORY; - } - return body->QueryInterface(kIHTMLContentIID, (void **) aInstancePtrResult); -} diff --git a/mozilla/layout/html/table/src/nsTableRow.h b/mozilla/layout/html/table/src/nsTableRow.h deleted file mode 100644 index 4021d6c2aa6..00000000000 --- a/mozilla/layout/html/table/src/nsTableRow.h +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#ifndef nsTableRow_h__ -#define nsTableRow_h__ - -#include "nscore.h" -#include "nsTableContent.h" -#include "nsTableRowGroup.h" - - -/** - * nsTableRow is the content object that represents table rows - * (HTML tag TR). This class cannot be reused - * outside of an nsTableRowGroup. It assumes that its parent is an nsTableRowGroup, and - * its children are nsTableCells. - * - * @see nsTablePart - * @see nsTableRowGroup - * @see nsTableCell - * - * @author sclark - */ -class nsTableRow : public nsTableContent -{ - -private: - /** parent pointer */ - nsTableRowGroup * mRowGroup; - - /** the index of the row this content object represents */ - PRInt32 mRowIndex; - -public: - - /** constructor - * @param aTag the HTML tag causing this row to get constructed. - */ - nsTableRow (nsIAtom* aTag); - - /** constructor - * @param aTag the HTML tag causing this row to get constructed. - * @param aImplicit PR_TRUE if there is no actual input tag corresponding to - * this row. - */ - nsTableRow (nsIAtom* aTag, PRBool aImplicit); - - /** destructor, not responsible for any memory destruction itself */ - virtual ~nsTableRow(); - - // For debugging purposes only - NS_IMETHOD_(nsrefcnt) AddRef(); - NS_IMETHOD_(nsrefcnt) Release(); - - /** returns nsITableContent::kTableRowType */ - virtual int GetType(); - - NS_IMETHOD SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify); - - NS_IMETHOD GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const; - - /** @see nsIHTMLContent::CreateFrame */ - NS_IMETHOD CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult); - - NS_IMETHOD AttributeToString(nsIAtom* aAttribute, - nsHTMLValue& aValue, - nsString& aResult) const; - - /** return the row group that contains me (my parent) */ - virtual nsTableRowGroup *GetRowGroup (); - - - /** Set my parent row group.
- * NOTE: Since mRowGroup is the parent of the table row, - * reference counting should not be done on - * this variable when setting the row. - * see /ns/raptor/doc/MemoryModel.html - **/ - virtual void SetRowGroup (nsTableRowGroup * aRowGroup); - - /** return this row's starting row index */ - virtual PRInt32 GetRowIndex (); - - /** set this row's starting row index */ - virtual void SetRowIndex (int aRowIndex); - - - /* ----------- nsTableContent overrides ----------- */ - - /** can only append objects that are cells (implement nsITableContent and are . - * of type nsITableContent::kTableCellType.) - * @see nsIContent::AppendChildTo - */ - NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify); - - /** can only insert objects that are cells (implement nsITableContent and are . - * of type nsITableContent::kTableCellType.) - * @see nsIContent::InsertChildAt - */ - NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify); - - /** can only replace child objects with objects that are cells - * (implement nsITableContent and are * of type nsITableContent::kTableCellType.) - * @param aContent the object to insert, must be a cell - * @param aIndex the index of the object to replace. Must be in the range - * 0<=aIndexQueryInterface(kITableContentIID, - (void **)&tableContentInterface); // tableContentInterface: REFCNT++ + nsIHTMLTableCellElement *cellContent = nsnull; + nsresult rv = cell->QueryInterface(kIHTMLTableCellElementIID, + (void **)&cellContent); // cellContent: REFCNT++ if (NS_SUCCEEDED(rv)) - { // we know it's a table part of some sort, is it a cell? - const int contentType = ((nsTableContent *)tableContentInterface)->GetType(); - if (contentType == nsITableContent::kTableCellType) - { - ((nsTableCell *)tableContentInterface)->SetColIndex(colIndex); - if (gsDebug) printf("%p : set cell content %p to col index = %d\n", this, tableContentInterface, colIndex); - } - NS_RELEASE(tableContentInterface); + { // we know it's a table cell + cellContent->SetColIndex(colIndex); + if (gsDebug) printf("%p : set cell content %p to col index = %d\n", this, cellContent, colIndex); + NS_RELEASE(cellContent); } // part of the style optimization is to ensure that the column frame for the cell exists // we used to do this post-pass1, now we do it incrementally for the optimization @@ -587,7 +582,7 @@ nsTableRowFrame::InitialReflow(nsIPresContext& aPresContext, break; } // this sets the frame's notion of it's column index - ((nsTableCellFrame *)kidFrame)->SetColIndex(colIndex); + ((nsTableCellFrame *)kidFrame)->InitCellFrame(colIndex); if (gsDebug) printf("%p : set cell frame %p to col index = %d\n", this, kidFrame, colIndex); // add the cell frame to the table's cell map aState.tableFrame->AddCellToTable(this, (nsTableCellFrame *)kidFrame, isFirst); @@ -1005,19 +1000,18 @@ nsTableRowFrame::CreateContinuingFrame(nsIPresContext& aPresContext, return NS_ERROR_NOT_IMPLEMENTED; } -nsresult nsTableRowFrame::NewFrame( nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +/* ----- global methods ----- */ + +nsresult +NS_NewTableRowFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableRowFrame(aContent, aParent); + nsIFrame* it = new nsTableRowFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } diff --git a/mozilla/layout/html/table/src/nsTableRowFrame.h b/mozilla/layout/html/table/src/nsTableRowFrame.h index db8e4adf89c..395d852b083 100644 --- a/mozilla/layout/html/table/src/nsTableRowFrame.h +++ b/mozilla/layout/html/table/src/nsTableRowFrame.h @@ -42,15 +42,16 @@ public: void Init(PRInt32 aRowIndex); /** instantiate a new instance of nsTableRowFrame. - * @param aInstancePtrResult the new object is returned in this out-param - * @param aContent the table object to map - * @param aParent the parent of the new frame + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame * * @return NS_OK if the frame was properly allocated, otherwise an error code */ - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + friend nsresult + NS_NewTableRowFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); /** @see nsIFrame::Paint */ NS_IMETHOD Paint(nsIPresContext& aPresContext, diff --git a/mozilla/layout/html/table/src/nsTableRowGroup.cpp b/mozilla/layout/html/table/src/nsTableRowGroup.cpp deleted file mode 100644 index 90246bc1aa1..00000000000 --- a/mozilla/layout/html/table/src/nsTableRowGroup.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#include "nsTableRowGroup.h" -#include "nsTableRowGroupFrame.h" -#include "nsTableRowFrame.h" -#include "nsTablePart.h" -#include "nsTableRow.h" -#include "nsHTMLParts.h" -#include "nsHTMLContainer.h" -#include "nsIContentDelegate.h" -#include "nsIReflowCommand.h" -#include "nsIStyleContext.h" -#include "nsIRenderingContext.h" -#include "nsStyleConsts.h" -#include "nsIPresContext.h" -#include "nsIDocument.h" -#include "nsHTMLIIDs.h" -#include "nsHTMLAtoms.h" -#include "nsIHTMLAttributes.h" -#include "nsGenericHTMLElement.h" - -#ifdef NS_DEBUG -static PRBool gsDebug = PR_FALSE; -static PRBool gsNoisyRefs = PR_FALSE; -#else -static const PRBool gsDebug = PR_FALSE; -static const PRBool gsNoisyRefs = PR_FALSE; -#endif - -static NS_DEFINE_IID(kITableContentIID, NS_ITABLECONTENT_IID); - -// nsTableContent checks aTag -nsTableRowGroup::nsTableRowGroup(nsIAtom* aTag) - : nsTableContent(aTag) -{ -} - -// nsTableContent checks aTag -nsTableRowGroup::nsTableRowGroup(nsIAtom* aTag, PRBool aImplicit) - : nsTableContent(aTag) -{ - mImplicit = aImplicit; -} - -nsTableRowGroup::~nsTableRowGroup() -{ -} - -// Added for debuging purposes -- remove from final build -nsrefcnt nsTableRowGroup::AddRef(void) -{ - if (gsNoisyRefs==PR_TRUE) - printf("Add Ref: %x, nsTableRowGroup cnt = %d \n",this,mRefCnt+1); - return ++mRefCnt; -} - -nsrefcnt nsTableRowGroup::Release(void) -{ - if (gsNoisyRefs==PR_TRUE) - printf("Release: %x, nsTableRowGroup cnt = %d \n",this,mRefCnt-1); - if (--mRefCnt == 0) { - if (gsNoisyRefs==PR_TRUE) printf("Delete: %x, nsTableRowGroup \n",this); - delete this; - return 0; - } - return mRefCnt; -} - -NS_IMETHODIMP -nsTableRowGroup::SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify) -{ - NS_PRECONDITION(nsnull!=aAttribute, "bad attribute arg"); - nsHTMLValue val; - if ((aAttribute == nsHTMLAtoms::align) && - ParseDivAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - if ((aAttribute == nsHTMLAtoms::valign) && - ParseAlignParam(aValue, val)) { - return nsHTMLTagContent::SetAttribute(aAttribute, val, aNotify); - } - return nsTableContent::SetAttribute(aAttribute, aValue, aNotify); -} - -static void -MapAttributesInto(nsIHTMLAttributes* aAttributes, - nsIStyleContext* aContext, - nsIPresContext* aPresContext) -{ - NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); - NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); - if (nsnull != aAttributes) { - nsHTMLValue value; - nsStyleText* textStyle = nsnull; - - // align: enum - aAttributes->GetAttribute(nsHTMLAtoms::align, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) - { - textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text); - textStyle->mTextAlign = value.GetIntValue(); - } - - // valign: enum - aAttributes->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); - } - } - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); -} - -NS_IMETHODIMP -nsTableRowGroup::GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const -{ - aMapFunc = &MapAttributesInto; - return NS_OK; -} - - -nsresult -nsTableRowGroup::CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult) -{ - NS_PRECONDITION(nsnull!=aPresContext, "bad arg"); - - nsIFrame* frame; - nsresult rv = nsTableRowGroupFrame::NewFrame(&frame, this, aParentFrame); - if (NS_OK != rv) { - return rv; - } - frame->SetStyleContext(aPresContext, aStyleContext); - aResult = frame; - return rv; -} - -NS_IMETHODIMP -nsTableRowGroup::AppendChildTo (nsIContent *aContent, PRBool aNotify) -{ - NS_PRECONDITION(nsnull!=aContent, "bad arg to AppendChildTo"); - nsresult result = NS_OK; - - // is aContent a TableRow? - PRBool isRow = IsRow(aContent); - - // if so, simply add it - if (PR_TRUE==isRow) - { - if (gsDebug==PR_TRUE) printf ("nsTableRowGroup::AppendChildTo -- inserting a row into this row group.\n"); - // if it is, we'll add it here - result = nsTableContent::AppendChildTo (aContent, PR_FALSE); - if (NS_OK==result) - { - ((nsTableRow *)aContent)->SetRowGroup (this); - // make sure the table cell map gets rebuilt - } - } - // otherwise, if it's a cell, create an implicit row for it - else if (IsTableCell(aContent)) - { - // find last row, if ! implicit, make one, append there - nsTableRow *row = nsnull; - PRInt32 index; - ChildCount (index); - while ((0 < index) && (nsnull==row)) - { - nsIContent *child; - ChildAt (--index, child); // child: REFCNT++ - if (nsnull != child) - { - if (IsRow(child)) - row = (nsTableRow *)child; - NS_RELEASE(child); // child: REFCNT-- - } - } - PRBool rowIsImplicit = PR_FALSE; - if (nsnull!=row) - row->IsSynthetic(rowIsImplicit); - if ((nsnull == row) || (PR_FALSE==rowIsImplicit)) - { - printf ("nsTableRow::AppendChildTo -- creating an implicit row.\n"); - nsIAtom * trDefaultTag = NS_NewAtom(nsTablePart::kRowTagString); // trDefaultTag: REFCNT++ - row = new nsTableRow (trDefaultTag, PR_TRUE); - NS_RELEASE(trDefaultTag); // trDefaultTag: REFCNT-- - result = AppendChildTo (row, PR_FALSE); - // SEC: check result - } - // group is guaranteed to be allocated at this point - result = row->AppendChildTo(aContent, PR_FALSE); - } - // otherwise, punt and let the table try to insert it. Or maybe just return a failure? - else - { - // you should go talk to my parent if you want to insert something other than a row - result = NS_ERROR_FAILURE; - } - return result; -} - -NS_IMETHODIMP -nsTableRowGroup::InsertChildAt (nsIContent *aContent, PRInt32 aIndex, - PRBool aNotify) -{ - NS_PRECONDITION(nsnull!=aContent, "bad arg to InsertChildAt"); - - // is aContent a TableRow? - PRBool isRow = IsRow(aContent); - - // if not, ignore the request to add aContent - if (PR_FALSE==isRow) - { - // you should go talk to my parent if you want to insert something other than a column - return NS_ERROR_FAILURE; - } - - // if so, add the row to this group - nsresult result = nsTableContent::InsertChildAt (aContent, aIndex, PR_FALSE); - if (NS_OK==result) - { - ((nsTableRow *)aContent)->SetRowGroup (this); - } - - return result; -} - - -NS_IMETHODIMP -nsTableRowGroup::ReplaceChildAt (nsIContent *aContent, PRInt32 aIndex, - PRBool aNotify) -{ - PRInt32 numKids; - ChildCount(numKids); - NS_PRECONDITION(nsnull!=aContent, "bad aContent arg to ReplaceChildAt"); - NS_PRECONDITION(0<=aIndex && aIndexSetRowGroup (this); - if (nsnull != lastChild) - ((nsTableRow *)lastChild)->SetRowGroup (nsnull); - } - NS_IF_RELEASE(lastChild); // lastChild: REFCNT-- - return result; -} - -/** - * Remove a child at the given position. The method is ignored if - * the index is invalid (too small or too large). - */ -NS_IMETHODIMP -nsTableRowGroup::RemoveChildAt (PRInt32 aIndex, PRBool aNotify) -{ - PRInt32 numKids; - ChildCount(numKids); - NS_PRECONDITION(0<=aIndex && aIndexSetRowGroup (nsnull); - } - NS_IF_RELEASE(lastChild); // lastChild: REFCNT-- - return result; -} - -/** support method to determine if the param aContent is a TableRow object */ -PRBool nsTableRowGroup::IsRow(nsIContent * aContent) const -{ - PRBool result = PR_FALSE; - if (nsnull!=aContent) - { - // is aContent a row? - nsITableContent *tableContentInterface = nsnull; - nsresult rv = aContent->QueryInterface(kITableContentIID, - (void **)&tableContentInterface); // tableContentInterface: REFCNT++ - - if (NS_SUCCEEDED(rv)) - { - const int contentType = tableContentInterface->GetType(); - NS_RELEASE(tableContentInterface); - if (contentType == nsITableContent::kTableRowType) - result = PR_TRUE; - } - } - return result; -} - -/** support method to determine if the param aContent is a TableCell object */ -PRBool nsTableRowGroup::IsTableCell(nsIContent * aContent) const -{ - PRBool result = PR_FALSE; - if (nsnull!=aContent) - { - // is aContent a table cell? - nsITableContent *tableContentInterface = nsnull; - nsresult rv = aContent->QueryInterface(kITableContentIID, - (void **)&tableContentInterface); // tableContentInterface: REFCNT++ - if (NS_SUCCEEDED(rv)) - { - const int contentType = tableContentInterface->GetType(); - NS_RELEASE(tableContentInterface); - if (contentType == nsITableContent::kTableCellType) - result = PR_TRUE; - } - } - return result; -} - -/* ----------- Global Functions ---------- */ - -nsresult -NS_NewTableRowGroupPart(nsIHTMLContent** aInstancePtrResult, - nsIAtom* aTag) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIHTMLContent* content = new nsTableRowGroup(aTag); - if (nsnull == content) { - return NS_ERROR_OUT_OF_MEMORY; - } - return content->QueryInterface(kIHTMLContentIID, (void **) aInstancePtrResult); -} diff --git a/mozilla/layout/html/table/src/nsTableRowGroup.h b/mozilla/layout/html/table/src/nsTableRowGroup.h deleted file mode 100644 index 07e786ee91b..00000000000 --- a/mozilla/layout/html/table/src/nsTableRowGroup.h +++ /dev/null @@ -1,121 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#ifndef nsTableRowGroup_h__ -#define nsTableRowGroup_h__ - -#include "nscore.h" -#include "nsTableContent.h" - -class nsIPresContext; - -/** - * nsTableRowGroup is the content object that represents table row groups - * (HTML tags THEAD, TFOOT, and TBODY). This class cannot be reused - * outside of an nsTablePart. It assumes that its parent is an nsTableParte, and - * its children are nsTableRows. - * - * @see nsTablePart - * @see nsTableRow - * - * @author sclark - * TODO: make getter/setters inline - */ -class nsTableRowGroup : public nsTableContent -{ - -public: - - /** constructor - * @param aTag the HTML tag causing this row group to get constructed. - */ - nsTableRowGroup (nsIAtom* aTag); - - /** constructor - * @param aTag the HTML tag causing this row group to get constructed. - * @param aImplicit PR_TRUE if there is no actual input tag corresponding to - * this row group. - */ - nsTableRowGroup (nsIAtom* aTag, PRBool aImplicit); - - /** destructor, not responsible for any memory destruction itself */ - virtual ~nsTableRowGroup(); - - // For debugging purposes only - NS_IMETHOD_(nsrefcnt) AddRef(); - NS_IMETHOD_(nsrefcnt) Release(); - - - NS_IMETHOD SetAttribute(nsIAtom* aAttribute, const nsString& aValue, - PRBool aNotify); - - NS_IMETHOD GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const; - - /** @see nsIHTMLContent::CreateFrame */ - NS_IMETHOD CreateFrame(nsIPresContext* aPresContext, - nsIFrame* aParentFrame, - nsIStyleContext* aStyleContext, - nsIFrame*& aResult); - - /** returns nsITableContent::kTableRowGroupType */ - virtual int GetType(); - - /* ----------- overrides from nsTableContent ---------- */ - - /** can only append objects that are rows (implement nsITableContent and are . - * of type nsITableContent::kTableRowType.) - * @see nsIContent::AppendChildTo - */ - NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify); - - /** can only insert objects that are rows (implement nsITableContent and are . - * of type nsITableContent::kTableRowType.) - * @see nsIContent::InsertChildAt - */ - NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify); - - /** can only replace child objects with objects that are rows - * (implement nsITableContent and are * of type nsITableContent::kTableRowe.) - * @param aContent the object to insert, must be a row - * @param aIndex the index of the object to replace. Must be in the range - * 0<=aIndexGetColIndex(); nsIFrame* rowFrame = aParentFrame; nsIFrame* rowGroupFrame; @@ -530,17 +529,24 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext, rowFrame->GetContentParent(rowGroupFrame); rowGroupFrame->GetContentParent(tableFrame); - nsTableColFrame* colFrame; - nsIFrame* colGroupFrame; + nsIHTMLTableCellElement* cell=nsnull; + nsresult rv = aContent->QueryInterface(kIHTMLTableCellElementIID, + (void **)&cell); // cell: REFCNT++ + if (NS_SUCCEEDED(rv)) { + PRInt32 colIndex; + rv = cell->GetColIndex(&colIndex); + nsTableColFrame* colFrame; + nsIFrame* colGroupFrame; - ((nsTableFrame*)tableFrame)->GetColumnFrame(colIndex, colFrame); - colFrame->GetContentParent(colGroupFrame); + ((nsTableFrame*)tableFrame)->GetColumnFrame(colIndex, colFrame); + colFrame->GetContentParent(colGroupFrame); - matchCount += AppendRulesFrom(colGroupFrame, aPresContext, backstopInsertPoint, aResults); - matchCount += AppendRulesFrom(colFrame, aPresContext, backstopInsertPoint, aResults); + matchCount += AppendRulesFrom(colGroupFrame, aPresContext, backstopInsertPoint, aResults); + matchCount += AppendRulesFrom(colFrame, aPresContext, backstopInsertPoint, aResults); + NS_RELEASE(cell); // cell: REFCNT-- + } matchCount += AppendRulesFrom(rowGroupFrame, aPresContext, backstopInsertPoint, aResults); matchCount += AppendRulesFrom(rowFrame, aPresContext, backstopInsertPoint, aResults); - } // end TD/TH tag // just get the one and only style rule from the content @@ -1055,9 +1061,6 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, else if (nsHTMLAtoms::wbr == aTag) { rv = NS_NewWBRFrame(aContent, aParentFrame, frame); } - else if (nsHTMLAtoms::table == aTag) { - rv = nsTableOuterFrame::NewFrame(&frame, aContent, aParentFrame); - } else if (nsHTMLAtoms::input == aTag) { rv = CreateInputFrame(aContent, aParentFrame, frame); } @@ -1071,6 +1074,32 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, rv = NS_NewHTMLFrameOuterFrame(aContent, aParentFrame, frame); } + // the table content frames... + else if (nsHTMLAtoms::caption == aTag) { + rv = NS_NewBodyFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::table == aTag) { + rv = NS_NewTableOuterFrame(aContent, aParentFrame, frame); + } + else if ((nsHTMLAtoms::tbody == aTag) || + (nsHTMLAtoms::thead == aTag) || + (nsHTMLAtoms::tfoot == aTag)) { + rv = NS_NewTableRowGroupFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::tr == aTag) { + rv = NS_NewTableRowFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::colgroup == aTag) { + rv = NS_NewTableColGroupFrame(aContent, aParentFrame, frame); + } + else if (nsHTMLAtoms::col == aTag) { + rv = NS_NewTableColFrame(aContent, aParentFrame, frame); + } + else if ((nsHTMLAtoms::td == aTag) || + (nsHTMLAtoms::th == aTag)) { + rv = NS_NewTableCellFrame(aContent, aParentFrame, frame); + } + if (NS_OK != rv) { return rv; } diff --git a/mozilla/layout/tables/nsCellMap.h b/mozilla/layout/tables/nsCellMap.h index a461ba9bfa0..f83136f801d 100644 --- a/mozilla/layout/tables/nsCellMap.h +++ b/mozilla/layout/tables/nsCellMap.h @@ -20,8 +20,8 @@ #include "nscore.h" #include "celldata.h" +#include "nsVoidArray.h" -class nsVoidArray; class nsTableColFrame; class nsTableCellFrame; diff --git a/mozilla/layout/tables/nsTableCellFrame.cpp b/mozilla/layout/tables/nsTableCellFrame.cpp index 7cec23b353c..430d9cfc851 100644 --- a/mozilla/layout/tables/nsTableCellFrame.cpp +++ b/mozilla/layout/tables/nsTableCellFrame.cpp @@ -25,6 +25,8 @@ #include "nsCSSRendering.h" #include "nsIContent.h" #include "nsIContentDelegate.h" +#include "nsIHTMLContent.h" +#include "nsHTMLIIDs.h" #include "nsCSSLayout.h" #include "nsHTMLValue.h" #include "nsHTMLAtoms.h" @@ -55,8 +57,6 @@ nsTableCellFrame::nsTableCellFrame(nsIContent* aContent, nsIFrame* aParentFrame) : nsContainerFrame(aContent, aParentFrame) { - mRowSpan=1; - mColSpan=1; mColIndex=0; mPriorAvailWidth=0; mDesiredSize.width=0; @@ -216,7 +216,39 @@ nsTableFrame* nsTableCellFrame::GetTableFrame() return (nsTableFrame*)frame; } +PRInt32 nsTableCellFrame::GetRowSpan() +{ + PRInt32 rowSpan=1; + nsIHTMLContent *hc=nsnull; + nsresult rv = mContent->QueryInterface(kIHTMLContentIID, (void**) &hc); + if (NS_OK==rv) + { + nsHTMLValue val; + hc->GetAttribute(nsHTMLAtoms::rowspan, val); + if (eHTMLUnit_Integer == val.GetUnit()) { + rowSpan=val.GetIntValue(); + } + NS_RELEASE(hc); + } + return rowSpan; +} +PRInt32 nsTableCellFrame::GetColSpan() +{ + PRInt32 colSpan=1; + nsIHTMLContent *hc=nsnull; + nsresult rv = mContent->QueryInterface(kIHTMLContentIID, (void**) &hc); + if (NS_OK==rv) + { + nsHTMLValue val; + hc->GetAttribute(nsHTMLAtoms::colspan, val); + if (eHTMLUnit_Integer == val.GetUnit()) { + colSpan=val.GetIntValue(); + } + NS_RELEASE(hc); + } + return colSpan; +} /** @@ -510,7 +542,7 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) nscoord border = 1; nsTableFrame* tableFrame = GetTableFrame(); - tableFrame->GetGeometricParent((nsIFrame *&)tableFrame); // get the outer frame + //tableFrame->GetGeometricParent((nsIFrame *&)tableFrame); // get the outer frame NS_ASSERTION(tableFrame,"Table Must not be null"); if (!tableFrame) return; @@ -579,21 +611,18 @@ nsTableCellFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) return nsContainerFrame::QueryInterface(aIID, aInstancePtr); } -/* ----- static methods ----- */ +/* ----- global methods ----- */ -nsresult nsTableCellFrame::NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +nsresult +NS_NewTableCellFrame( nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableCellFrame(aContent, aParent); + nsIFrame* it = new nsTableCellFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } diff --git a/mozilla/layout/tables/nsTableCellFrame.h b/mozilla/layout/tables/nsTableCellFrame.h index c6b99bee5f9..68e7a9080ae 100644 --- a/mozilla/layout/tables/nsTableCellFrame.h +++ b/mozilla/layout/tables/nsTableCellFrame.h @@ -41,11 +41,19 @@ class nsTableCellFrame : public nsContainerFrame { public: - void Init(PRInt32 aRowSpan, PRInt32 aColSpan, PRInt32 aColIndex); + void InitCellFrame(PRInt32 aColIndex); - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + /** instantiate a new instance of nsTableCellFrame. + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame + * + * @return NS_OK if the frame was properly allocated, otherwise an error code + */ + friend nsresult + NS_NewTableCellFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); // nsISupports NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); @@ -206,11 +214,6 @@ protected: PRBool ConvertToPixelValue(nsHTMLValue& aValue, PRInt32 aDefault, PRInt32& aResult); protected: - /** the number of rows spanned by this cell */ - int mRowSpan; - - /** the number of columns spanned by this cell */ - int mColSpan; /** the starting column for this cell */ int mColIndex; @@ -232,18 +235,12 @@ protected: }; -inline void nsTableCellFrame::Init(PRInt32 aRowSpan, PRInt32 aColSpan, PRInt32 aColIndex) +inline void nsTableCellFrame::InitCellFrame(PRInt32 aColIndex) { - NS_PRECONDITION(0QueryInterface(kITableContentIID, + rv = kid->QueryInterface(kITableContentIID, (void **)&tableContentInterface); // tableContentInterface: REFCNT++ if (NS_FAILED(rv)) { @@ -92,7 +96,7 @@ NS_METHOD nsTableColGroupFrame::Reflow(nsIPresContext& aPresContext, continue; } NS_RELEASE(tableContentInterface); // tableContentInterface: REFCNT-- - +*/ if (mChildCount<=colIndex) { // Resolve style @@ -106,6 +110,21 @@ NS_METHOD nsTableColGroupFrame::Reflow(nsIPresContext& aPresContext, kidDel = kid->GetDelegate(&aPresContext); rv = kidDel->CreateFrame(&aPresContext, kid, this, kidSC, kidFrame); NS_RELEASE(kidDel); + if (NS_FAILED(rv)) + return rv; + + // set the preliminary values for the column frame + PRInt32 repeat=1; + nsIHTMLTableColElement* colContent = nsnull; + kid->QueryInterface(kIHTMLTableColElementIID, + (void**) &colContent); // colContent: ADDREF++ + if (rv==NS_OK) + { + colContent->GetSpanValue(&repeat); + NS_RELEASE(colContent); + } + ((nsTableColFrame *)(kidFrame))->InitColFrame (mStartColIndex + mColCount, repeat); + mColCount+= repeat; // give the child frame a chance to reflow, even though we know it'll have 0 size nsReflowMetrics kidSize(nsnull); @@ -238,21 +257,18 @@ int nsTableColGroupFrame::GetColumnCount () return mColCount; } -/* ----- static methods ----- */ +/* ----- global methods ----- */ -nsresult nsTableColGroupFrame::NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +nsresult +NS_NewTableColGroupFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableColGroupFrame(aContent, aParent); + nsIFrame* it = new nsTableColGroupFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } diff --git a/mozilla/layout/tables/nsTableColGroupFrame.h b/mozilla/layout/tables/nsTableColGroupFrame.h index d98eb7b5ad7..bf9498c96ad 100644 --- a/mozilla/layout/tables/nsTableColGroupFrame.h +++ b/mozilla/layout/tables/nsTableColGroupFrame.h @@ -31,9 +31,17 @@ class nsTableColGroupFrame : public nsContainerFrame { public: - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + /** instantiate a new instance of nsTableColGroupFrame. + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame + * + * @return NS_OK if the frame was properly allocated, otherwise an error code + */ + friend nsresult + NS_NewTableColGroupFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); NS_IMETHOD Paint(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, diff --git a/mozilla/layout/tables/nsTableFrame.cpp b/mozilla/layout/tables/nsTableFrame.cpp index 79231610418..4640d2e517d 100644 --- a/mozilla/layout/tables/nsTableFrame.cpp +++ b/mozilla/layout/tables/nsTableFrame.cpp @@ -16,19 +16,18 @@ * Reserved. */ #include "nsTableFrame.h" -#include "nsTablePart.h" #include "nsIRenderingContext.h" #include "nsIStyleContext.h" #include "nsIContent.h" #include "nsIContentDelegate.h" #include "nsCellMap.h" #include "nsTableCellFrame.h" -#include "nsTableCol.h" // needed for building implicit columns -#include "nsTableColGroup.h" // needed for building implicit colgroups +#include "nsHTMLParts.h" #include "nsTableColFrame.h" #include "nsTableColGroupFrame.h" #include "nsTableRowFrame.h" #include "nsTableRowGroupFrame.h" +#include "nsIHTMLContent.h" #include "BasicTableLayoutStrategy.h" @@ -495,11 +494,8 @@ PRInt32 nsTableFrame::GetEffectiveCOLSAttribute() NS_PRECONDITION (nsnull!=cellMap, "bad call, cellMap not yet allocated."); PRInt32 result; nsIFrame *tableFrame = this; -// begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! XXX - tableFrame->GetGeometricParent(tableFrame); -// end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! XXX - nsStyleTable *tableStyle; - tableFrame->GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle); + nsStyleTable *tableStyle=nsnull; + GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle); result = tableStyle->mCols; PRInt32 numCols = GetColCount(); if (result>numCols) @@ -526,6 +522,7 @@ void nsTableFrame::EnsureColumns(nsIPresContext* aPresContext, const nsReflowState& aReflowState, nsReflowStatus& aStatus) { +#ifdef XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // XXX sec should only be called on firstInFlow SetMinColSpanForTable(); if (nsnull==mCellMap) @@ -564,14 +561,9 @@ void nsTableFrame::EnsureColumns(nsIPresContext* aPresContext, nsTableColGroup *lastColGroup=nsnull; if (nsnull==lastColGroupFrame) { - //QQQ - // need to find the generic way to stamp out this content, and ::AppendChildTo it - // this might be ok. no matter what my mcontent is, I know it needs a colgroup as a kid? - lastColGroup = new nsTableColGroup (PR_TRUE); // create an implicit colgroup // XXX: instead of Append, maybe this should be insertAt(0)? mContent->AppendChildTo(lastColGroup, PR_FALSE); // add the implicit colgroup to my content - NS_ADDREF(lastColGroup); // ADDREF a: lastColGroup++ // Resolve style for the child nsIStyleContext* colGroupStyleContext = aPresContext->ResolveStyleContextFor(lastColGroup, this, PR_TRUE); // kidStyleContext: REFCNT++ @@ -613,24 +605,26 @@ void nsTableFrame::EnsureColumns(nsIPresContext* aPresContext, { //QQQ // need to find the generic way to stamp out this content, and ::AppendChildTo it nsTableCol *col = new nsTableCol(PR_TRUE); - NS_ADDREF(col); lastColGroup->AppendChildTo (col, PR_FALSE); } NS_RELEASE(lastColGroup); // ADDREF: lastColGroup-- lastColGroupFrame->Reflow(*aPresContext, aDesiredSize, aReflowState, aStatus); } +#endif } /** sum the columns represented by all nsTableColGroup objects * if the cell map says there are more columns than this, * add extra implicit columns to the content tree. */ +// XXX should be nsresult, not void void nsTableFrame::EnsureColumnFrameAt(PRInt32 aColIndex, nsIPresContext* aPresContext, nsReflowMetrics& aDesiredSize, const nsReflowState& aReflowState, nsReflowStatus& aStatus) { + nsresult rv; PRInt32 actualColumns = 0; nsTableColGroupFrame *lastColGroupFrame = nsnull; nsIFrame * firstRowGroupFrame=nsnull; @@ -646,7 +640,7 @@ void nsTableFrame::EnsureColumnFrameAt(PRInt32 aColIndex, actualColumns += numCols; lastColGroupFrame = (nsTableColGroupFrame *)childFrame; if (actualColumns > aColIndex) - break; // we gave enough col frames at this point + break; // we have enough col frames at this point } else if (NS_STYLE_DISPLAY_TABLE_ROW_GROUP == childDisplay->mDisplay || NS_STYLE_DISPLAY_TABLE_HEADER_GROUP == childDisplay->mDisplay || @@ -660,18 +654,21 @@ void nsTableFrame::EnsureColumnFrameAt(PRInt32 aColIndex, } if (actualColumns <= aColIndex) { - nsTableColGroup *lastColGroup=nsnull; + nsIHTMLContent *lastColGroup=nsnull; if (nsnull==lastColGroupFrame) { - lastColGroup = new nsTableColGroup (PR_TRUE); // create an implicit colgroup + // create an implicit colgroup + nsAutoString colGroupTag; + nsHTMLAtoms::colgroup->ToString(colGroupTag); + rv = NS_CreateHTMLElement(&lastColGroup, colGroupTag); // ADDREF a: lastColGroup++ + //XXX mark it as implicit! mContent->AppendChildTo(lastColGroup, PR_FALSE); // add the implicit colgroup to my content - NS_ADDREF(lastColGroup); // ADDREF a: lastColGroup++ // Resolve style for the child nsIStyleContext* colGroupStyleContext = aPresContext->ResolveStyleContextFor(lastColGroup, this, PR_TRUE); // kidStyleContext: REFCNT++ nsIContentDelegate* kidDel = nsnull; kidDel = lastColGroup->GetDelegate(aPresContext); // kidDel: REFCNT++ - nsresult rv = kidDel->CreateFrame(aPresContext, lastColGroup, this, + rv = kidDel->CreateFrame(aPresContext, lastColGroup, this, colGroupStyleContext, (nsIFrame *&)lastColGroupFrame); NS_RELEASE(kidDel); // kidDel: REFCNT-- NS_RELEASE(colGroupStyleContext); // kidStyleContenxt: REFCNT-- @@ -702,12 +699,17 @@ void nsTableFrame::EnsureColumnFrameAt(PRInt32 aColIndex, lastColGroupFrame->GetContent((nsIContent *&)lastColGroup); // ADDREF b: lastColGroup++ } + nsAutoString colTag; + nsHTMLAtoms::col->ToString(colTag); PRInt32 excessColumns = aColIndex - actualColumns; for ( ; excessColumns >= 0; excessColumns--) { - nsTableCol *col = new nsTableCol(PR_TRUE); - NS_ADDREF(col); - lastColGroup->AppendChildTo(col, PR_FALSE); + nsIHTMLContent *col=nsnull; + // create an implicit col + rv = NS_CreateHTMLElement(&col, colTag); // ADDREF: col++ + //XXX mark the col implicit + lastColGroup->AppendChildTo((nsIContent*)col, PR_FALSE); + NS_RELEASE(col); // ADDREF: col-- } NS_RELEASE(lastColGroup); // ADDREF: lastColGroup-- lastColGroupFrame->Reflow(*aPresContext, aDesiredSize, aReflowState, aStatus); @@ -2480,21 +2482,9 @@ void nsTableFrame::BalanceColumnWidths(nsIPresContext* aPresContext, // need to figure out the overall table width constraint // default case, get 100% of available space - // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - nsIFrame * outerTableFrame = nsnull; - const nsStylePosition* position; - GetGeometricParent(outerTableFrame); - outerTableFrame->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)position)); - // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED - - - PRInt32 maxWidth; - /* const nsStylePosition* position = (const nsStylePosition*)mStyleContext->GetStyleData(eStyleStruct_Position); - use this line when tableFrame contains its own position style info - */ switch (position->mWidth.GetUnit()) { case eStyleUnit_Coord: maxWidth = position->mWidth.GetCoordValue(); @@ -2849,8 +2839,6 @@ nsTableFrame::CreateContinuingFrame(nsIPresContext& aPresContext, nsIFrame * rg = nsnull; firstInFlow->FirstChild(rg); NS_ASSERTION (nsnull!=rg, "previous frame has no children"); - nsIAtom * tHeadTag = NS_NewAtom(nsTablePart::kRowGroupHeadTagString); // tHeadTag: REFCNT++ - nsIAtom * tFootTag = NS_NewAtom(nsTablePart::kRowGroupFootTagString); // tFootTag: REFCNT++ PRInt32 index = 0; nsIFrame * bodyRowGroupFromOverflow = mOverflowList; nsIFrame * lastSib = nsnull; @@ -2859,10 +2847,10 @@ nsTableFrame::CreateContinuingFrame(nsIPresContext& aPresContext, nsIContent *content = nsnull; rg->GetContent(content); // content: REFCNT++ NS_ASSERTION(nsnull!=content, "bad frame, returned null content."); - nsIAtom * rgTag; - content->GetTag(rgTag); - // if we've found a header or a footer, replicate it - if (tHeadTag==rgTag || tFootTag==rgTag) + const nsStyleDisplay* display; + GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display); + if ((display->mDisplay == NS_STYLE_DISPLAY_TABLE_HEADER_GROUP) || + (display->mDisplay == NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP)) { printf("found a head or foot in continuing frame\n"); // Resolve style for the child @@ -2887,13 +2875,10 @@ nsTableFrame::CreateContinuingFrame(nsIPresContext& aPresContext, duplicateFrame->SetNextSibling(bodyRowGroupFromOverflow); lastSib = duplicateFrame; } - NS_IF_RELEASE(rgTag); NS_RELEASE(content); // content: REFCNT-- // get the next row group rg->GetNextSibling(rg); } - NS_RELEASE(tFootTag); // tHeadTag: REFCNT -- - NS_RELEASE(tHeadTag); // tFootTag: REFCNT -- aContinuingFrame = cf; return NS_OK; } @@ -3020,6 +3005,7 @@ PRBool nsTableFrame::ConvertToPixelValue(nsHTMLValue& aValue, PRInt32 aDefault, void nsTableFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) { +#if 0 // Check to see if the table has either cell padding or // Cell spacing defined for the table. If true, then // this setting overrides any specific border, margin or @@ -3039,7 +3025,7 @@ void nsTableFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) float p2t = aPresContext->GetPixelsToTwips(); - nsTablePart* table = (nsTablePart*)mContent; + nsIHTMLContent* table = (nsIHTMLContent*)mContent; NS_ASSERTION(table,"Table Must not be null"); if (!table) @@ -3056,6 +3042,7 @@ void nsTableFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) border = NSIntPixelsToTwips(intValue, p2t); } MapHTMLBorderStyle(*spacingData,border); +#endif } @@ -3066,13 +3053,6 @@ NS_METHOD nsTableFrame::DidSetStyleContext(nsIPresContext* aPresContext) { #ifdef NOISY_STYLE printf("nsTableFrame::DidSetStyleContext \n"); -#endif - // XXX This may have been needed before we had a style system, but it's not - // needed now. It's forcing the table to always have a border (which is bad), - // and it's duplicating the border-syle and border-color information that's - // in the ua.css -#if 0 - MapBorderMarginPadding(aPresContext); #endif return NS_OK; } @@ -3092,10 +3072,8 @@ NS_METHOD nsTableFrame::GetCellMarginData(nsTableCellFrame* aKidFrame, nsMargin& nscoord nsTableFrame::GetCellSpacing() { nsTableFrame* tableFrame = this; - //XXX remove when table style is fully resolved! - GetGeometricParent((nsIFrame *&)tableFrame); // get the outer frame nsStyleTable* tableStyle; - tableFrame->GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle); + GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle); nscoord cellSpacing = 0; if (tableStyle->mCellSpacing.GetUnit() == eStyleUnit_Coord) cellSpacing = tableStyle->mCellSpacing.GetCoordValue(); @@ -3125,27 +3103,25 @@ nsTableFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) } -/* ---------- static methods ---------- */ +/* ----- global methods ----- */ -nsresult nsTableFrame::NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +nsresult +NS_NewTableFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableFrame(aContent, aParent); + nsIFrame* it = new nsTableFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } /* helper method for determining if this is a nested table or not */ PRBool nsTableFrame::IsNested(const nsReflowState& aReflowState, nsStylePosition *& aPosition) const { + nsresult rv; PRBool result = PR_FALSE; #ifdef NS_DEBUG PRInt32 counter=0; @@ -3159,8 +3135,8 @@ PRBool nsTableFrame::IsNested(const nsReflowState& aReflowState, nsStylePosition NS_ASSERTION(counter<100000, "infinite loop in IsNested"); #endif nsIFrame* parentTable = nsnull; - rs->frame->QueryInterface(kTableFrameCID, (void**) &parentTable); - if (nsnull!=parentTable) + rv = rs->frame->QueryInterface(kTableFrameCID, (void**) &parentTable); + if (NS_OK==rv) { result = PR_TRUE; parentTable->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)aPosition)); @@ -3174,6 +3150,7 @@ PRBool nsTableFrame::IsNested(const nsReflowState& aReflowState, nsStylePosition /* helper method for getting the width of the table's containing block */ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) { + nsresult rv; nscoord parentWidth = aReflowState.maxSize.width; // Walk up the reflow state chain until we find a block @@ -3186,8 +3163,8 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) { // if it's a block, use its max width nsIFrame* block = nsnull; - rs->frame->QueryInterface(kBlockFrameCID, (void**) &block); - if (nsnull != block) + rv = rs->frame->QueryInterface(kBlockFrameCID, (void**) &block); + if (NS_OK==rv) { // we found a block, see if it's really a table cell (which means we're a nested table) PRBool skipThisBlock=PR_FALSE; if (PR_TRUE==((nsContainerFrame*)block)->IsPseudoFrame()) @@ -3199,8 +3176,8 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) if (nsnull!=parentRS) { nsIFrame* cell = nsnull; - parentRS->frame->QueryInterface(kTableCellFrameCID, (void**) &cell); - if (nsnull != cell) { + rv = parentRS->frame->QueryInterface(kTableCellFrameCID, (void**) &cell); + if (rv == NS_OK) { if (PR_TRUE==gsDebugNT) printf("%p: found a block pframe %p in a cell, skipping it.\n", aReflowState.frame, block); skipThisBlock = PR_TRUE; @@ -3229,9 +3206,9 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) const nsStylePosition* tablePosition; const nsStyleSpacing* spacing; nsIFrame* cell = nsnull; - rs->frame->QueryInterface(kTableCellFrameCID, (void**) &cell); + rv = rs->frame->QueryInterface(kTableCellFrameCID, (void**) &cell); // if the cell has a specified width, use it - if (nsnull != cell) + if (NS_OK==rv) { // Compute and subtract out the insets (sum of border and padding) for the table cell->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)tablePosition)); @@ -3268,8 +3245,8 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) else { nsIFrame* table = nsnull; - rs->frame->QueryInterface(kTableFrameCID, (void**) &table); - if (nsnull != table) { + rv = rs->frame->QueryInterface(kTableFrameCID, (void**) &table); + if (NS_OK==rv) { /* We found the nearest containing table (actually, the inner table). This defines what our percentage size is relative to. Use its desired width as the basis for computing our width. @@ -3280,14 +3257,8 @@ nscoord nsTableFrame::GetTableContainerWidth(const nsReflowState& aReflowState) ********************************************************************************** */ // Compute and subtract out the insets (sum of border and padding) for the table - /* the following hack is because the outer table really holds the position info */ - // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - nsIFrame * outerTableFrame = nsnull; - table->GetGeometricParent(outerTableFrame); - outerTableFrame->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)tablePosition)); - outerTableFrame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); - // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - + table->GetStyleData(eStyleStruct_Position, (const nsStyleStruct *&)tablePosition); + table->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct *&)spacing); if (eStyleUnit_Auto == tablePosition->mWidth.GetUnit()) { parentWidth = NS_UNCONSTRAINEDSIZE; @@ -3399,17 +3370,7 @@ PRBool nsTableFrame::TableIsAutoWidth(nsTableFrame *aTableFrame, PRBool result = PR_TRUE; // the default if (nsnull!=aTableStyle) { - //nsStylePosition* tablePosition = (nsStylePosition*)aTableStyle->GetData(eStyleStruct_Position); - /* this is sick and wrong, but what the hell - we grab the style of our parent (nsTableOuterFrame) and ask it for width info, - until the style resolution stuff does the cool stuff about splitting style between outer and inner - */ - // begin REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! - nsIFrame * parent = nsnull; - aTableFrame->GetGeometricParent(parent); - const nsStylePosition* tablePosition; - parent->GetStyleData(eStyleStruct_Position, ((nsStyleStruct *&)tablePosition)); - // end REMOVE_ME_WHEN_TABLE_STYLE_IS_RESOLVED! + nsStylePosition* tablePosition = (nsStylePosition*)aTableStyle->GetStyleData(eStyleStruct_Position); nsMargin borderPadding; const nsStyleSpacing* spacing; switch (tablePosition->mWidth.GetUnit()) { diff --git a/mozilla/layout/tables/nsTableFrame.h b/mozilla/layout/tables/nsTableFrame.h index 029385a74ca..ac6d6b09d77 100644 --- a/mozilla/layout/tables/nsTableFrame.h +++ b/mozilla/layout/tables/nsTableFrame.h @@ -60,15 +60,16 @@ public: friend class nsTableOuterFrame; /** instantiate a new instance of nsTableFrame. - * @param aInstancePtrResult the new object is returned in this out-param - * @param aContent the table object to map - * @param aParent the parent of the new frame + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame * * @return NS_OK if the frame was properly allocated, otherwise an error code */ - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + friend nsresult + NS_NewTableFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); // nsISupports NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); diff --git a/mozilla/layout/tables/nsTableOuterFrame.cpp b/mozilla/layout/tables/nsTableOuterFrame.cpp index ac39911bb94..7ce83d1e2ff 100644 --- a/mozilla/layout/tables/nsTableOuterFrame.cpp +++ b/mozilla/layout/tables/nsTableOuterFrame.cpp @@ -17,8 +17,6 @@ */ #include "nsTableOuterFrame.h" #include "nsTableFrame.h" -#include "nsITableContent.h" -#include "nsTableContent.h" #include "nsBodyFrame.h" #include "nsIReflowCommand.h" #include "nsIStyleContext.h" @@ -45,8 +43,6 @@ static const PRBool gsDebug = PR_FALSE; static const PRBool gsTiming = PR_FALSE; #endif -static NS_DEFINE_IID(kITableContentIID, NS_ITABLECONTENT_IID); - NS_DEF_PTR(nsIStyleContext); NS_DEF_PTR(nsIContent); @@ -623,13 +619,13 @@ nsresult nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) if (NS_STYLE_DISPLAY_TABLE_CAPTION == childDisplay->mDisplay) { // Create the caption frame. - // XXX In general (e.g. in an XML document) there's no reason to assume - // that the content object is of type nsIHTMLContent - result = ((nsIHTMLContent*)(nsIContent*)caption)->CreateFrame(aPresContext, - this, captionSC, - mCaptionFrame); - if (NS_OK != result) { - return result; + nsIContentDelegate* kidDel = nsnull; + kidDel = caption->GetDelegate(aPresContext); + nsresult rv = kidDel->CreateFrame(aPresContext, caption, this, captionSC, + mCaptionFrame); + NS_RELEASE(kidDel); + if (NS_OK != rv) { + return rv; } // Determine if the caption is a top or bottom caption @@ -849,21 +845,18 @@ nsresult nsTableOuterFrame::CreateInnerTableFrame(nsIPresContext* aPresContext, return NS_OK; } -/* ----- static methods ----- */ +/* ----- global methods ----- */ -nsresult nsTableOuterFrame::NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +nsresult +NS_NewTableOuterFrame( nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableOuterFrame(aContent, aParent); + nsIFrame* it = new nsTableOuterFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } diff --git a/mozilla/layout/tables/nsTableOuterFrame.h b/mozilla/layout/tables/nsTableOuterFrame.h index 43a22d09721..5e13f6bcd70 100644 --- a/mozilla/layout/tables/nsTableOuterFrame.h +++ b/mozilla/layout/tables/nsTableOuterFrame.h @@ -38,16 +38,17 @@ class nsTableOuterFrame : public nsContainerFrame { public: - /** instantiate a new instance of nsTableFrame. - * @param aInstancePtrResult the new object is returned in this out-param - * @param aContent the table object to map - * @param aParent the parent of the new frame + /** instantiate a new instance of nsTableOuterFrame. + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame * * @return NS_OK if the frame was properly allocated, otherwise an error code */ - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + friend nsresult + NS_NewTableOuterFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); /** @see nsIFrame::Paint */ NS_IMETHOD Paint(nsIPresContext& aPresContext, diff --git a/mozilla/layout/tables/nsTableRowFrame.cpp b/mozilla/layout/tables/nsTableRowFrame.cpp index fb24bde0f68..659720e9929 100644 --- a/mozilla/layout/tables/nsTableRowFrame.cpp +++ b/mozilla/layout/tables/nsTableRowFrame.cpp @@ -32,9 +32,8 @@ #include "nsIReflowCommand.h" #include "nsCSSRendering.h" // the following header files are required for style optimizations that work only when the child content is really a cell -#include "nsITableContent.h" -#include "nsTableCell.h" -static NS_DEFINE_IID(kITableContentIID, NS_ITABLECONTENT_IID); +#include "nsIHTMLTableCellElement.h" +static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID); // end includes for style optimizations that require real content knowledge NS_DEF_PTR(nsIStyleContext); @@ -553,18 +552,14 @@ nsTableRowFrame::InitialReflow(nsIPresContext& aPresContext, * other tags mapped to table cell display won't benefit from this optimization * see nsHTMLStyleSheet::RulesMatching */ - nsITableContent *tableContentInterface = nsnull; - nsresult rv = cell->QueryInterface(kITableContentIID, - (void **)&tableContentInterface); // tableContentInterface: REFCNT++ + nsIHTMLTableCellElement *cellContent = nsnull; + nsresult rv = cell->QueryInterface(kIHTMLTableCellElementIID, + (void **)&cellContent); // cellContent: REFCNT++ if (NS_SUCCEEDED(rv)) - { // we know it's a table part of some sort, is it a cell? - const int contentType = ((nsTableContent *)tableContentInterface)->GetType(); - if (contentType == nsITableContent::kTableCellType) - { - ((nsTableCell *)tableContentInterface)->SetColIndex(colIndex); - if (gsDebug) printf("%p : set cell content %p to col index = %d\n", this, tableContentInterface, colIndex); - } - NS_RELEASE(tableContentInterface); + { // we know it's a table cell + cellContent->SetColIndex(colIndex); + if (gsDebug) printf("%p : set cell content %p to col index = %d\n", this, cellContent, colIndex); + NS_RELEASE(cellContent); } // part of the style optimization is to ensure that the column frame for the cell exists // we used to do this post-pass1, now we do it incrementally for the optimization @@ -587,7 +582,7 @@ nsTableRowFrame::InitialReflow(nsIPresContext& aPresContext, break; } // this sets the frame's notion of it's column index - ((nsTableCellFrame *)kidFrame)->SetColIndex(colIndex); + ((nsTableCellFrame *)kidFrame)->InitCellFrame(colIndex); if (gsDebug) printf("%p : set cell frame %p to col index = %d\n", this, kidFrame, colIndex); // add the cell frame to the table's cell map aState.tableFrame->AddCellToTable(this, (nsTableCellFrame *)kidFrame, isFirst); @@ -1005,19 +1000,18 @@ nsTableRowFrame::CreateContinuingFrame(nsIPresContext& aPresContext, return NS_ERROR_NOT_IMPLEMENTED; } -nsresult nsTableRowFrame::NewFrame( nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +/* ----- global methods ----- */ + +nsresult +NS_NewTableRowFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableRowFrame(aContent, aParent); + nsIFrame* it = new nsTableRowFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } diff --git a/mozilla/layout/tables/nsTableRowFrame.h b/mozilla/layout/tables/nsTableRowFrame.h index db8e4adf89c..395d852b083 100644 --- a/mozilla/layout/tables/nsTableRowFrame.h +++ b/mozilla/layout/tables/nsTableRowFrame.h @@ -42,15 +42,16 @@ public: void Init(PRInt32 aRowIndex); /** instantiate a new instance of nsTableRowFrame. - * @param aInstancePtrResult the new object is returned in this out-param - * @param aContent the table object to map - * @param aParent the parent of the new frame + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame * * @return NS_OK if the frame was properly allocated, otherwise an error code */ - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + friend nsresult + NS_NewTableRowFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); /** @see nsIFrame::Paint */ NS_IMETHOD Paint(nsIPresContext& aPresContext, diff --git a/mozilla/layout/tables/nsTableRowGroupFrame.cpp b/mozilla/layout/tables/nsTableRowGroupFrame.cpp index 1765b56cdf0..11615126d4d 100644 --- a/mozilla/layout/tables/nsTableRowGroupFrame.cpp +++ b/mozilla/layout/tables/nsTableRowGroupFrame.cpp @@ -1195,21 +1195,18 @@ nsTableRowGroupFrame::CreateContinuingFrame(nsIPresContext& aPresContext, return NS_OK; } -/* ----- static methods ----- */ +/* ----- global methods ----- */ -nsresult nsTableRowGroupFrame::NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent) +nsresult +NS_NewTableRowGroupFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult) { - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIFrame* it = new nsTableRowGroupFrame(aContent, aParent); + nsIFrame* it = new nsTableRowGroupFrame(aContent, aParentFrame); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - *aInstancePtrResult = it; + aResult = it; return NS_OK; } diff --git a/mozilla/layout/tables/nsTableRowGroupFrame.h b/mozilla/layout/tables/nsTableRowGroupFrame.h index 996cc89ecfb..5c3dc08f293 100644 --- a/mozilla/layout/tables/nsTableRowGroupFrame.h +++ b/mozilla/layout/tables/nsTableRowGroupFrame.h @@ -40,15 +40,16 @@ class nsTableRowGroupFrame : public nsContainerFrame public: /** instantiate a new instance of nsTableRowGroupFrame. - * @param aInstancePtrResult the new object is returned in this out-param - * @param aContent the table object to map - * @param aParent the parent of the new frame + * @param aResult the new object is returned in this out-param + * @param aContent the table object to map + * @param aParent the parent of the new frame * * @return NS_OK if the frame was properly allocated, otherwise an error code */ - static nsresult NewFrame(nsIFrame** aInstancePtrResult, - nsIContent* aContent, - nsIFrame* aParent); + friend nsresult + NS_NewTableRowGroupFrame(nsIContent* aContent, + nsIFrame* aParentFrame, + nsIFrame*& aResult); /** @see nsIFrame::Paint */ NS_IMETHOD Paint(nsIPresContext& aPresContext,