From 36357f1dc03663966d7b32e195b56bc0e2ef0574 Mon Sep 17 00:00:00 2001 From: kostello Date: Fri, 1 May 1998 20:44:55 +0000 Subject: [PATCH] Made SetStyleContext take the presentation context as a parameter Made DidSetStyleContext virtual, since we need to override the behavior in subclasses Moved attribute setting logic from nsTableCell to nsTableCellFrame Table Borders are being drawn again : ) Table Padding is being displayed git-svn-id: svn://10.0.0.236/trunk@1027 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/table/src/nsTableCaptionFrame.cpp | 2 +- mozilla/layout/html/table/src/nsTableCell.cpp | 95 +------------ mozilla/layout/html/table/src/nsTableCell.h | 3 - .../html/table/src/nsTableCellFrame.cpp | 128 +++++++++++++++++- .../layout/html/table/src/nsTableCellFrame.h | 11 ++ .../layout/html/table/src/nsTableFrame.cpp | 15 +- mozilla/layout/html/table/src/nsTableFrame.h | 3 + .../html/table/src/nsTableOuterFrame.cpp | 17 +-- mozilla/layout/html/table/src/nsTablePart.cpp | 9 +- .../layout/html/table/src/nsTableRowFrame.cpp | 2 +- .../html/table/src/nsTableRowGroupFrame.cpp | 2 +- mozilla/layout/tables/nsTableCellFrame.cpp | 128 +++++++++++++++++- mozilla/layout/tables/nsTableCellFrame.h | 11 ++ mozilla/layout/tables/nsTableFrame.cpp | 15 +- mozilla/layout/tables/nsTableFrame.h | 3 + mozilla/layout/tables/nsTableOuterFrame.cpp | 17 +-- mozilla/layout/tables/nsTableRowFrame.cpp | 2 +- .../layout/tables/nsTableRowGroupFrame.cpp | 2 +- 18 files changed, 337 insertions(+), 128 deletions(-) diff --git a/mozilla/layout/html/table/src/nsTableCaptionFrame.cpp b/mozilla/layout/html/table/src/nsTableCaptionFrame.cpp index 0a2abc5e839..ad4f16d8c1f 100644 --- a/mozilla/layout/html/table/src/nsTableCaptionFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableCaptionFrame.cpp @@ -82,7 +82,7 @@ void nsTableCaptionFrame::CreatePsuedoFrame(nsIPresContext* aPresContext) // Resolve style and set the style context nsIStyleContext* styleContext = aPresContext->ResolveStyleContextFor(mContent, this); // styleContext: ADDREF++ - mFirstChild->SetStyleContext(styleContext); + mFirstChild->SetStyleContext(aPresContext,styleContext); NS_RELEASE(styleContext); // styleContext: ADDREF-- } else { nsTableCaptionFrame* prevFrame = (nsTableCaptionFrame *)mPrevInFlow; diff --git a/mozilla/layout/html/table/src/nsTableCell.cpp b/mozilla/layout/html/table/src/nsTableCell.cpp index 36d91bf0a12..91b1bd685ab 100644 --- a/mozilla/layout/html/table/src/nsTableCell.cpp +++ b/mozilla/layout/html/table/src/nsTableCell.cpp @@ -191,95 +191,6 @@ void nsTableCell::SetAttribute(nsIAtom* aAttribute, const nsString& aValue) } -void nsTableCell::MapHTMLBorderStyle(nsStyleBorder& aBorderStyle, nscoord aBorderWidth) -{ - for (PRInt32 index = 0; index < 4; index++) - aBorderStyle.mSizeFlag[index] = NS_STYLE_BORDER_WIDTH_LENGTH_VALUE; - - aBorderStyle.mSize.top = - aBorderStyle.mSize.left = - aBorderStyle.mSize.bottom = - aBorderStyle.mSize.right = aBorderWidth; - - - aBorderStyle.mStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_INSET; - aBorderStyle.mStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_INSET; - aBorderStyle.mStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_OUTSET; - aBorderStyle.mStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_OUTSET; - - NS_ColorNameToRGB("white",&aBorderStyle.mColor[NS_SIDE_TOP]); - NS_ColorNameToRGB("white",&aBorderStyle.mColor[NS_SIDE_LEFT]); - - // This should be the background color of the tables - // container - NS_ColorNameToRGB("gray",&aBorderStyle.mColor[NS_SIDE_BOTTOM]); - NS_ColorNameToRGB("gray",&aBorderStyle.mColor[NS_SIDE_RIGHT]); -} - - -void nsTableCell::MapBorderMarginPaddingInto(nsIStyleContext* aContext, - nsIPresContext* aPresContext) -{ - // 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 - // padding information in the cell. If these attributes - // are not defined, the the cells attributes are used - - nsHTMLValue padding_value; - nsHTMLValue spacing_value; - nsHTMLValue border_value; - - nsContentAttr padding_result; - nsContentAttr spacing_result; - nsContentAttr border_result; - - NS_ASSERTION(mTable,"Table Must not be null"); - if (!mTable) - return; - - padding_result = mTable->GetAttribute(nsHTMLAtoms::cellpadding,padding_value); - spacing_result = mTable->GetAttribute(nsHTMLAtoms::cellspacing,spacing_value); - border_result = mTable->GetAttribute(nsHTMLAtoms::border,border_value); - - // check to see if cellpadding or cellspacing is defined - if (spacing_result == eContentAttr_HasValue || padding_result == eContentAttr_HasValue) - { - nscoord padding = 0; - nscoord spacing = 0; - nscoord border = 0; - - float p2t = aPresContext->GetPixelsToTwips(); - if (padding_result == eContentAttr_HasValue) - padding = p2t*(float)padding_value.GetPixelValue(); - - if (spacing_result == eContentAttr_HasValue) - spacing = p2t*(float)spacing_value.GetPixelValue(); - - nsStyleSpacing* spacingData = (nsStyleSpacing*)aContext->GetData(kStyleSpacingSID); - spacingData->mMargin.SizeTo(spacing,spacing,spacing,spacing); - spacingData->mPadding.top = - spacingData->mPadding.left = - spacingData->mPadding.bottom = - spacingData->mPadding.right = padding; - - nsStyleBorder& borderData = *(nsStyleBorder*)aContext->GetData(kStyleBorderSID); - if (border_result == eContentAttr_HasValue) - { - // The HTML rule is that if the table's border style is - // zero, then the cell's border width is also zero, - // otherwise the cell's border width is one - - PRInt32 intValue = border_value.GetPixelValue(); - if (intValue > 0) - intValue = 1; - border = p2t*(float)intValue; - MapHTMLBorderStyle(borderData,border); - } - } -} - - void nsTableCell::MapAttributesInto(nsIStyleContext* aContext, nsIPresContext* aPresContext) @@ -291,15 +202,13 @@ void nsTableCell::MapAttributesInto(nsIStyleContext* aContext, // align: enum GetAttribute(nsHTMLAtoms::align, value); - if (value.GetUnit() == eHTMLUnit_Enumerated) { + if (value.GetUnit() == eHTMLUnit_Enumerated) + { nsStyleText* text = (nsStyleText*)aContext->GetData(kStyleTextSID); text->mTextAlign = value.GetIntValue(); } - - MapBorderMarginPaddingInto(aContext,aPresContext); MapBackgroundAttributesInto(aContext, aPresContext); - } void nsTableCell::SetRowSpan(int aRowSpan) diff --git a/mozilla/layout/html/table/src/nsTableCell.h b/mozilla/layout/html/table/src/nsTableCell.h index 71b45ab316d..7a04bc00468 100644 --- a/mozilla/layout/html/table/src/nsTableCell.h +++ b/mozilla/layout/html/table/src/nsTableCell.h @@ -96,9 +96,6 @@ public: nsIPresContext* aPresContext); - virtual void MapHTMLBorderStyle(nsStyleBorder& aBorderStyle, nscoord aBorderWidth); - virtual void MapBorderMarginPaddingInto(nsIStyleContext* aContext, - nsIPresContext* aPresContext); /** @return the number of rows spanned by this cell. Always >= 1 */ virtual int GetRowSpan (); diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.cpp b/mozilla/layout/html/table/src/nsTableCellFrame.cpp index 4925281e2ca..e199421502b 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableCellFrame.cpp @@ -26,10 +26,11 @@ #include "nsIContent.h" #include "nsIContentDelegate.h" #include "nsCSSLayout.h" +#include "nsHTMLAtoms.h" #ifdef NS_DEBUG static PRBool gsDebug = PR_FALSE; -//#define NOISY +#define NOISY_STYLE //#define NOISY_FLOW #else static const PRBool gsDebug = PR_FALSE; @@ -185,7 +186,7 @@ void nsTableCellFrame::CreatePsuedoFrame(nsIPresContext* aPresContext) // Resolve style and set the style context nsIStyleContext* styleContext = aPresContext->ResolveStyleContextFor(mContent, this); // styleContext: ADDREF++ - mFirstChild->SetStyleContext(styleContext); + mFirstChild->SetStyleContext(aPresContext,styleContext); NS_RELEASE(styleContext); // styleContext: ADDREF-- } else { nsTableCellFrame* prevFrame = (nsTableCellFrame *)mPrevInFlow; @@ -345,6 +346,129 @@ NS_METHOD nsTableCellFrame::CreateContinuingFrame(nsIPresContext* aPresContext, } +/** + * + * Update the border style to map to the HTML border style + * + */ +void nsTableCellFrame::MapHTMLBorderStyle(nsStyleBorder& aBorderStyle, nscoord aBorderWidth) +{ + for (PRInt32 index = 0; index < 4; index++) + aBorderStyle.mSizeFlag[index] = NS_STYLE_BORDER_WIDTH_LENGTH_VALUE; + + aBorderStyle.mSize.top = + aBorderStyle.mSize.left = + aBorderStyle.mSize.bottom = + aBorderStyle.mSize.right = aBorderWidth; + + + aBorderStyle.mStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_INSET; + aBorderStyle.mStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_INSET; + aBorderStyle.mStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_OUTSET; + aBorderStyle.mStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_OUTSET; + + NS_ColorNameToRGB("white",&aBorderStyle.mColor[NS_SIDE_TOP]); + NS_ColorNameToRGB("white",&aBorderStyle.mColor[NS_SIDE_LEFT]); + + // This should be the background color of the tables + // container + NS_ColorNameToRGB("gray",&aBorderStyle.mColor[NS_SIDE_BOTTOM]); + NS_ColorNameToRGB("gray",&aBorderStyle.mColor[NS_SIDE_RIGHT]); +} + + + +void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) +{ + // 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 + // padding information in the cell. If these attributes + // are not defined, the the cells attributes are used + + nsHTMLValue padding_value; + nsHTMLValue spacing_value; + nsHTMLValue border_value; + + nsContentAttr padding_result; + nsContentAttr spacing_result; + nsContentAttr border_result; + + nscoord padding = 0; + nscoord spacing = 0; + nscoord border = 1; + + float p2t = aPresContext->GetPixelsToTwips(); + + nsTablePart* table = ((nsTableContent*)mContent)->GetTable(); + + NS_ASSERTION(table,"Table Must not be null"); + if (!table) + return; + + padding_result = table->GetAttribute(nsHTMLAtoms::cellpadding,padding_value); + spacing_result = table->GetAttribute(nsHTMLAtoms::cellspacing,spacing_value); + border_result = table->GetAttribute(nsHTMLAtoms::border,border_value); + + // check to see if cellpadding or cellspacing is defined + if (spacing_result == eContentAttr_HasValue || padding_result == eContentAttr_HasValue) + { + + if (padding_result == eContentAttr_HasValue) + padding = (nscoord)(p2t*(float)padding_value.GetPixelValue()); + + if (spacing_result == eContentAttr_HasValue) + spacing = (nscoord)(p2t*(float)spacing_value.GetPixelValue()); + + nsStyleSpacing* spacingData = (nsStyleSpacing*)mStyleContext->GetData(kStyleSpacingSID); + spacingData->mMargin.SizeTo(spacing,spacing,spacing,spacing); + spacingData->mPadding.top = + spacingData->mPadding.left = + spacingData->mPadding.bottom = + spacingData->mPadding.right = padding; + + } + if (border_result == eContentAttr_HasValue) + { + PRInt32 intValue = border_value.GetPixelValue(); + if (intValue > 0) + intValue = 1; + border = nscoord(p2t*(float)intValue); + } + + + nsStyleBorder& borderData = *(nsStyleBorder*)mStyleContext->GetData(kStyleBorderSID); + MapHTMLBorderStyle(borderData,border); +} + +void nsTableCellFrame::MapTextAttributes(nsIPresContext* aPresContext) +{ + nsHTMLValue value; + + ((nsTableCell*)mContent)->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + nsStyleText* text = (nsStyleText*)mStyleContext->GetData(kStyleTextSID); + text->mTextAlign = value.GetIntValue(); + } +} + + + +// Subclass hook for style post processing +NS_METHOD nsTableCellFrame::DidSetStyleContext(nsIPresContext* aPresContext) +{ +#ifdef NOISY_STYLE + printf("nsTableCellFrame::DidSetStyleContext \n"); +#endif + + MapTextAttributes(aPresContext); + MapBorderMarginPadding(aPresContext); + mStyleContext->RecalcAutomaticData(); + return NS_OK; +} + + /* ----- static methods ----- */ nsresult nsTableCellFrame::NewFrame(nsIFrame** aInstancePtrResult, diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.h b/mozilla/layout/html/table/src/nsTableCellFrame.h index c41849660b4..ce0d9b56073 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.h +++ b/mozilla/layout/html/table/src/nsTableCellFrame.h @@ -72,6 +72,7 @@ public: virtual ~nsTableCellFrame(); + protected: /** protected constructor. @@ -85,6 +86,16 @@ protected: */ virtual void CreatePsuedoFrame(nsIPresContext* aPresContext); + // Subclass hook for style post processing + NS_METHOD DidSetStyleContext(nsIPresContext* aPresContext); + void MapTextAttributes(nsIPresContext* aPresContext); + void MapBorderMarginPadding(nsIPresContext* aPresContext); + void MapHTMLBorderStyle(nsStyleBorder& aBorderStyle, nscoord aBorderWidth); + + + + + }; diff --git a/mozilla/layout/html/table/src/nsTableFrame.cpp b/mozilla/layout/html/table/src/nsTableFrame.cpp index 2fdbf3e09b6..1b7886f2522 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableFrame.cpp @@ -48,6 +48,7 @@ static PRBool gsTiming = PR_FALSE; static PRBool gsDebugMBP = PR_FALSE; //#define NOISY //#define NOISY_FLOW +//#ifdef NOISY_STYLE #else static const PRBool gsDebug = PR_FALSE; static const PRBool gsDebugCLD = PR_FALSE; @@ -640,7 +641,7 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont kidDel = kid->GetDelegate(aPresContext); kidFrame = kidDel->CreateFrame(aPresContext, kid, contentOffset, this); NS_RELEASE(kidDel); - kidFrame->SetStyleContext(kidStyleContext); + kidFrame->SetStyleContext(aPresContext,kidStyleContext); } nsSize maxKidElementSize; @@ -1415,7 +1416,7 @@ nsTableFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, kidDel = kid->GetDelegate(aPresContext); kidFrame = kidDel->CreateFrame(aPresContext, kid, kidIndex, this); NS_RELEASE(kidDel); - kidFrame->SetStyleContext(kidStyleContext); + kidFrame->SetStyleContext(aPresContext, kidStyleContext); } else { kidPrevInFlow->CreateContinuingFrame(aPresContext, this, kidFrame); } @@ -2077,7 +2078,7 @@ NS_METHOD nsTableFrame::CreateContinuingFrame(nsIPresContext* aPresContext, kidDel = content->GetDelegate(aPresContext); // kidDel: REFCNT++ nsIFrame * duplicateFrame = kidDel->CreateFrame(aPresContext, content, index, cf); NS_RELEASE(kidDel); // kidDel: REFCNT-- - duplicateFrame->SetStyleContext(kidStyleContext); + duplicateFrame->SetStyleContext(aPresContext,kidStyleContext); NS_RELEASE(kidStyleContext); // kidStyleContenxt: REFCNT-- if (nsnull==lastSib) @@ -2147,6 +2148,14 @@ void nsTableFrame::SetColumnWidth(PRInt32 aColIndex, PRInt32 aWidth) } } +// Subclass hook for style post processing +NS_METHOD nsTableFrame::DidSetStyleContext(nsIPresContext* aPresContext) +{ +#ifdef NOISY_STYLE + printf("nsTableFrame::DidSetStyleContext \n"); +#endif + return NS_OK; +} /* ---------- static methods ---------- */ diff --git a/mozilla/layout/html/table/src/nsTableFrame.h b/mozilla/layout/html/table/src/nsTableFrame.h index f9ac82bc475..c89d89425a8 100644 --- a/mozilla/layout/html/table/src/nsTableFrame.h +++ b/mozilla/layout/html/table/src/nsTableFrame.h @@ -297,6 +297,9 @@ protected: /** returns PR_TRUE if the cached pass 1 data is still valid */ virtual PRBool IsFirstPassValid() const; + /** do post processing to setting up style information for the frame */ + virtual NS_METHOD DidSetStyleContext(nsIPresContext* aPresContext); + private: void nsTableFrame::DebugPrintCount() const; // Debugging routine diff --git a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp index ce00afbce76..2cc16d27807 100644 --- a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp @@ -227,16 +227,17 @@ NS_METHOD nsTableOuterFrame::ResizeReflow(nsIPresContext* aPresContext, aStatus = mInnerTableFrame->ResizeReflowPass1(aPresContext, aDesiredSize, aMaxSize, &innerTableMaxElementSize); + nsIContentPtr content; + mInnerTableFrame->GetContent(content.AssignRef()); + nsTablePart *table = (nsTablePart*)(nsIContent*)content; #ifdef NOISY_MARGINS - nsIContent* content = nsnull; - mInnerTableFrame->GetContent(content); - nsTablePart *table = (nsTablePart*)content; if (table != nsnull) table->DumpCellMap(); +#endif mInnerTableFrame->RecalcLayoutData(); +#ifdef NOISY_MARGINS mInnerTableFrame->ListColumnLayoutData(stdout,1); #endif - } mInnerTableFrame->SetReflowPass(nsTableFrame::kPASS_SECOND); // assign table width info only if the inner table frame is a first-in-flow @@ -945,7 +946,7 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(mContent, this); NS_ASSERTION(kidStyleContext.IsNotNull(), "bad style context for kid."); - mInnerTableFrame->SetStyleContext(kidStyleContext); + mInnerTableFrame->SetStyleContext(aPresContext,kidStyleContext); mChildCount++; // Link child frame into the list of children mFirstChild = mInnerTableFrame; @@ -974,7 +975,7 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) NS_ASSERTION(captionStyleContext.IsNotNull(), "bad style context for caption."); nsStyleText* captionStyle = (nsStyleText*)captionStyleContext->GetData(kStyleTextSID); - captionFrame->SetStyleContext(captionStyleContext); + captionFrame->SetStyleContext(aPresContext,captionStyleContext); mChildCount++; // Link child frame into the list of children if ((eStyleUnit_Enumerated == captionStyle->mVerticalAlign.GetUnit()) && @@ -1244,7 +1245,7 @@ void nsTableOuterFrame::PrepareContinuingFrame(nsIPresContext* aPresContext, // XXX presumptive nsIStyleContextPtr styleContext = aPresContext->ResolveStyleContextFor(mContent, aParent); - aContFrame->SetStyleContext(styleContext); + aContFrame->SetStyleContext(aPresContext,styleContext); } NS_METHOD nsTableOuterFrame::VerifyTree() const @@ -1363,7 +1364,7 @@ void nsTableOuterFrame::CreateInnerTableFrame(nsIPresContext* aPresContext) // Resolve style and set the style context nsIStyleContextPtr styleContext = aPresContext->ResolveStyleContextFor(mContent, this); - mInnerTableFrame->SetStyleContext(styleContext); + mInnerTableFrame->SetStyleContext(aPresContext,styleContext); } else { nsTableOuterFrame* prevOuterTable = (nsTableOuterFrame*)mPrevInFlow; diff --git a/mozilla/layout/html/table/src/nsTablePart.cpp b/mozilla/layout/html/table/src/nsTablePart.cpp index 2a6f1e04b60..966a7a8d592 100644 --- a/mozilla/layout/html/table/src/nsTablePart.cpp +++ b/mozilla/layout/html/table/src/nsTablePart.cpp @@ -153,6 +153,14 @@ nsTablePart::~nsTablePart() } } +/** + */ +/* +nsTablePart::void compact() { + compact(); +} +*/ + // for debugging only nsrefcnt nsTablePart::AddRef(void) { @@ -1064,7 +1072,6 @@ void nsTablePart::MapAttributesInto(nsIStyleContext* aContext, break; } } - // border GetTableBorder(this, aContext, aPresContext, PR_FALSE); } diff --git a/mozilla/layout/html/table/src/nsTableRowFrame.cpp b/mozilla/layout/html/table/src/nsTableRowFrame.cpp index 9fc165ca65b..4c885604ae0 100644 --- a/mozilla/layout/html/table/src/nsTableRowFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableRowFrame.cpp @@ -811,7 +811,7 @@ nsTableRowFrame::ReflowUnmappedChildren( nsIPresContext* aPresContext, kidDel = cell->GetDelegate(aPresContext); kidFrame = kidDel->CreateFrame(aPresContext, cell, kidIndex, this); NS_RELEASE(kidDel); - kidFrame->SetStyleContext(kidStyleContext); + kidFrame->SetStyleContext(aPresContext,kidStyleContext); } else { kidPrevInFlow->CreateContinuingFrame(aPresContext, this, kidFrame); } diff --git a/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp b/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp index 3cbc1e206de..4188aed3730 100644 --- a/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableRowGroupFrame.cpp @@ -743,7 +743,7 @@ nsTableRowGroupFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, kidDel = kid->GetDelegate(aPresContext); kidFrame = kidDel->CreateFrame(aPresContext, kid, kidIndex, this); NS_RELEASE(kidDel); - kidFrame->SetStyleContext(kidSC); + kidFrame->SetStyleContext(aPresContext,kidSC); } else { kidPrevInFlow->CreateContinuingFrame(aPresContext, this, kidFrame); } diff --git a/mozilla/layout/tables/nsTableCellFrame.cpp b/mozilla/layout/tables/nsTableCellFrame.cpp index 4925281e2ca..e199421502b 100644 --- a/mozilla/layout/tables/nsTableCellFrame.cpp +++ b/mozilla/layout/tables/nsTableCellFrame.cpp @@ -26,10 +26,11 @@ #include "nsIContent.h" #include "nsIContentDelegate.h" #include "nsCSSLayout.h" +#include "nsHTMLAtoms.h" #ifdef NS_DEBUG static PRBool gsDebug = PR_FALSE; -//#define NOISY +#define NOISY_STYLE //#define NOISY_FLOW #else static const PRBool gsDebug = PR_FALSE; @@ -185,7 +186,7 @@ void nsTableCellFrame::CreatePsuedoFrame(nsIPresContext* aPresContext) // Resolve style and set the style context nsIStyleContext* styleContext = aPresContext->ResolveStyleContextFor(mContent, this); // styleContext: ADDREF++ - mFirstChild->SetStyleContext(styleContext); + mFirstChild->SetStyleContext(aPresContext,styleContext); NS_RELEASE(styleContext); // styleContext: ADDREF-- } else { nsTableCellFrame* prevFrame = (nsTableCellFrame *)mPrevInFlow; @@ -345,6 +346,129 @@ NS_METHOD nsTableCellFrame::CreateContinuingFrame(nsIPresContext* aPresContext, } +/** + * + * Update the border style to map to the HTML border style + * + */ +void nsTableCellFrame::MapHTMLBorderStyle(nsStyleBorder& aBorderStyle, nscoord aBorderWidth) +{ + for (PRInt32 index = 0; index < 4; index++) + aBorderStyle.mSizeFlag[index] = NS_STYLE_BORDER_WIDTH_LENGTH_VALUE; + + aBorderStyle.mSize.top = + aBorderStyle.mSize.left = + aBorderStyle.mSize.bottom = + aBorderStyle.mSize.right = aBorderWidth; + + + aBorderStyle.mStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_INSET; + aBorderStyle.mStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_INSET; + aBorderStyle.mStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_OUTSET; + aBorderStyle.mStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_OUTSET; + + NS_ColorNameToRGB("white",&aBorderStyle.mColor[NS_SIDE_TOP]); + NS_ColorNameToRGB("white",&aBorderStyle.mColor[NS_SIDE_LEFT]); + + // This should be the background color of the tables + // container + NS_ColorNameToRGB("gray",&aBorderStyle.mColor[NS_SIDE_BOTTOM]); + NS_ColorNameToRGB("gray",&aBorderStyle.mColor[NS_SIDE_RIGHT]); +} + + + +void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) +{ + // 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 + // padding information in the cell. If these attributes + // are not defined, the the cells attributes are used + + nsHTMLValue padding_value; + nsHTMLValue spacing_value; + nsHTMLValue border_value; + + nsContentAttr padding_result; + nsContentAttr spacing_result; + nsContentAttr border_result; + + nscoord padding = 0; + nscoord spacing = 0; + nscoord border = 1; + + float p2t = aPresContext->GetPixelsToTwips(); + + nsTablePart* table = ((nsTableContent*)mContent)->GetTable(); + + NS_ASSERTION(table,"Table Must not be null"); + if (!table) + return; + + padding_result = table->GetAttribute(nsHTMLAtoms::cellpadding,padding_value); + spacing_result = table->GetAttribute(nsHTMLAtoms::cellspacing,spacing_value); + border_result = table->GetAttribute(nsHTMLAtoms::border,border_value); + + // check to see if cellpadding or cellspacing is defined + if (spacing_result == eContentAttr_HasValue || padding_result == eContentAttr_HasValue) + { + + if (padding_result == eContentAttr_HasValue) + padding = (nscoord)(p2t*(float)padding_value.GetPixelValue()); + + if (spacing_result == eContentAttr_HasValue) + spacing = (nscoord)(p2t*(float)spacing_value.GetPixelValue()); + + nsStyleSpacing* spacingData = (nsStyleSpacing*)mStyleContext->GetData(kStyleSpacingSID); + spacingData->mMargin.SizeTo(spacing,spacing,spacing,spacing); + spacingData->mPadding.top = + spacingData->mPadding.left = + spacingData->mPadding.bottom = + spacingData->mPadding.right = padding; + + } + if (border_result == eContentAttr_HasValue) + { + PRInt32 intValue = border_value.GetPixelValue(); + if (intValue > 0) + intValue = 1; + border = nscoord(p2t*(float)intValue); + } + + + nsStyleBorder& borderData = *(nsStyleBorder*)mStyleContext->GetData(kStyleBorderSID); + MapHTMLBorderStyle(borderData,border); +} + +void nsTableCellFrame::MapTextAttributes(nsIPresContext* aPresContext) +{ + nsHTMLValue value; + + ((nsTableCell*)mContent)->GetAttribute(nsHTMLAtoms::align, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) + { + nsStyleText* text = (nsStyleText*)mStyleContext->GetData(kStyleTextSID); + text->mTextAlign = value.GetIntValue(); + } +} + + + +// Subclass hook for style post processing +NS_METHOD nsTableCellFrame::DidSetStyleContext(nsIPresContext* aPresContext) +{ +#ifdef NOISY_STYLE + printf("nsTableCellFrame::DidSetStyleContext \n"); +#endif + + MapTextAttributes(aPresContext); + MapBorderMarginPadding(aPresContext); + mStyleContext->RecalcAutomaticData(); + return NS_OK; +} + + /* ----- static methods ----- */ nsresult nsTableCellFrame::NewFrame(nsIFrame** aInstancePtrResult, diff --git a/mozilla/layout/tables/nsTableCellFrame.h b/mozilla/layout/tables/nsTableCellFrame.h index c41849660b4..ce0d9b56073 100644 --- a/mozilla/layout/tables/nsTableCellFrame.h +++ b/mozilla/layout/tables/nsTableCellFrame.h @@ -72,6 +72,7 @@ public: virtual ~nsTableCellFrame(); + protected: /** protected constructor. @@ -85,6 +86,16 @@ protected: */ virtual void CreatePsuedoFrame(nsIPresContext* aPresContext); + // Subclass hook for style post processing + NS_METHOD DidSetStyleContext(nsIPresContext* aPresContext); + void MapTextAttributes(nsIPresContext* aPresContext); + void MapBorderMarginPadding(nsIPresContext* aPresContext); + void MapHTMLBorderStyle(nsStyleBorder& aBorderStyle, nscoord aBorderWidth); + + + + + }; diff --git a/mozilla/layout/tables/nsTableFrame.cpp b/mozilla/layout/tables/nsTableFrame.cpp index 2fdbf3e09b6..1b7886f2522 100644 --- a/mozilla/layout/tables/nsTableFrame.cpp +++ b/mozilla/layout/tables/nsTableFrame.cpp @@ -48,6 +48,7 @@ static PRBool gsTiming = PR_FALSE; static PRBool gsDebugMBP = PR_FALSE; //#define NOISY //#define NOISY_FLOW +//#ifdef NOISY_STYLE #else static const PRBool gsDebug = PR_FALSE; static const PRBool gsDebugCLD = PR_FALSE; @@ -640,7 +641,7 @@ nsIFrame::ReflowStatus nsTableFrame::ResizeReflowPass1(nsIPresContext* aPresCont kidDel = kid->GetDelegate(aPresContext); kidFrame = kidDel->CreateFrame(aPresContext, kid, contentOffset, this); NS_RELEASE(kidDel); - kidFrame->SetStyleContext(kidStyleContext); + kidFrame->SetStyleContext(aPresContext,kidStyleContext); } nsSize maxKidElementSize; @@ -1415,7 +1416,7 @@ nsTableFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, kidDel = kid->GetDelegate(aPresContext); kidFrame = kidDel->CreateFrame(aPresContext, kid, kidIndex, this); NS_RELEASE(kidDel); - kidFrame->SetStyleContext(kidStyleContext); + kidFrame->SetStyleContext(aPresContext, kidStyleContext); } else { kidPrevInFlow->CreateContinuingFrame(aPresContext, this, kidFrame); } @@ -2077,7 +2078,7 @@ NS_METHOD nsTableFrame::CreateContinuingFrame(nsIPresContext* aPresContext, kidDel = content->GetDelegate(aPresContext); // kidDel: REFCNT++ nsIFrame * duplicateFrame = kidDel->CreateFrame(aPresContext, content, index, cf); NS_RELEASE(kidDel); // kidDel: REFCNT-- - duplicateFrame->SetStyleContext(kidStyleContext); + duplicateFrame->SetStyleContext(aPresContext,kidStyleContext); NS_RELEASE(kidStyleContext); // kidStyleContenxt: REFCNT-- if (nsnull==lastSib) @@ -2147,6 +2148,14 @@ void nsTableFrame::SetColumnWidth(PRInt32 aColIndex, PRInt32 aWidth) } } +// Subclass hook for style post processing +NS_METHOD nsTableFrame::DidSetStyleContext(nsIPresContext* aPresContext) +{ +#ifdef NOISY_STYLE + printf("nsTableFrame::DidSetStyleContext \n"); +#endif + return NS_OK; +} /* ---------- static methods ---------- */ diff --git a/mozilla/layout/tables/nsTableFrame.h b/mozilla/layout/tables/nsTableFrame.h index f9ac82bc475..c89d89425a8 100644 --- a/mozilla/layout/tables/nsTableFrame.h +++ b/mozilla/layout/tables/nsTableFrame.h @@ -297,6 +297,9 @@ protected: /** returns PR_TRUE if the cached pass 1 data is still valid */ virtual PRBool IsFirstPassValid() const; + /** do post processing to setting up style information for the frame */ + virtual NS_METHOD DidSetStyleContext(nsIPresContext* aPresContext); + private: void nsTableFrame::DebugPrintCount() const; // Debugging routine diff --git a/mozilla/layout/tables/nsTableOuterFrame.cpp b/mozilla/layout/tables/nsTableOuterFrame.cpp index ce00afbce76..2cc16d27807 100644 --- a/mozilla/layout/tables/nsTableOuterFrame.cpp +++ b/mozilla/layout/tables/nsTableOuterFrame.cpp @@ -227,16 +227,17 @@ NS_METHOD nsTableOuterFrame::ResizeReflow(nsIPresContext* aPresContext, aStatus = mInnerTableFrame->ResizeReflowPass1(aPresContext, aDesiredSize, aMaxSize, &innerTableMaxElementSize); + nsIContentPtr content; + mInnerTableFrame->GetContent(content.AssignRef()); + nsTablePart *table = (nsTablePart*)(nsIContent*)content; #ifdef NOISY_MARGINS - nsIContent* content = nsnull; - mInnerTableFrame->GetContent(content); - nsTablePart *table = (nsTablePart*)content; if (table != nsnull) table->DumpCellMap(); +#endif mInnerTableFrame->RecalcLayoutData(); +#ifdef NOISY_MARGINS mInnerTableFrame->ListColumnLayoutData(stdout,1); #endif - } mInnerTableFrame->SetReflowPass(nsTableFrame::kPASS_SECOND); // assign table width info only if the inner table frame is a first-in-flow @@ -945,7 +946,7 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) nsIStyleContextPtr kidStyleContext = aPresContext->ResolveStyleContextFor(mContent, this); NS_ASSERTION(kidStyleContext.IsNotNull(), "bad style context for kid."); - mInnerTableFrame->SetStyleContext(kidStyleContext); + mInnerTableFrame->SetStyleContext(aPresContext,kidStyleContext); mChildCount++; // Link child frame into the list of children mFirstChild = mInnerTableFrame; @@ -974,7 +975,7 @@ void nsTableOuterFrame::CreateChildFrames(nsIPresContext* aPresContext) NS_ASSERTION(captionStyleContext.IsNotNull(), "bad style context for caption."); nsStyleText* captionStyle = (nsStyleText*)captionStyleContext->GetData(kStyleTextSID); - captionFrame->SetStyleContext(captionStyleContext); + captionFrame->SetStyleContext(aPresContext,captionStyleContext); mChildCount++; // Link child frame into the list of children if ((eStyleUnit_Enumerated == captionStyle->mVerticalAlign.GetUnit()) && @@ -1244,7 +1245,7 @@ void nsTableOuterFrame::PrepareContinuingFrame(nsIPresContext* aPresContext, // XXX presumptive nsIStyleContextPtr styleContext = aPresContext->ResolveStyleContextFor(mContent, aParent); - aContFrame->SetStyleContext(styleContext); + aContFrame->SetStyleContext(aPresContext,styleContext); } NS_METHOD nsTableOuterFrame::VerifyTree() const @@ -1363,7 +1364,7 @@ void nsTableOuterFrame::CreateInnerTableFrame(nsIPresContext* aPresContext) // Resolve style and set the style context nsIStyleContextPtr styleContext = aPresContext->ResolveStyleContextFor(mContent, this); - mInnerTableFrame->SetStyleContext(styleContext); + mInnerTableFrame->SetStyleContext(aPresContext,styleContext); } else { nsTableOuterFrame* prevOuterTable = (nsTableOuterFrame*)mPrevInFlow; diff --git a/mozilla/layout/tables/nsTableRowFrame.cpp b/mozilla/layout/tables/nsTableRowFrame.cpp index 9fc165ca65b..4c885604ae0 100644 --- a/mozilla/layout/tables/nsTableRowFrame.cpp +++ b/mozilla/layout/tables/nsTableRowFrame.cpp @@ -811,7 +811,7 @@ nsTableRowFrame::ReflowUnmappedChildren( nsIPresContext* aPresContext, kidDel = cell->GetDelegate(aPresContext); kidFrame = kidDel->CreateFrame(aPresContext, cell, kidIndex, this); NS_RELEASE(kidDel); - kidFrame->SetStyleContext(kidStyleContext); + kidFrame->SetStyleContext(aPresContext,kidStyleContext); } else { kidPrevInFlow->CreateContinuingFrame(aPresContext, this, kidFrame); } diff --git a/mozilla/layout/tables/nsTableRowGroupFrame.cpp b/mozilla/layout/tables/nsTableRowGroupFrame.cpp index 3cbc1e206de..4188aed3730 100644 --- a/mozilla/layout/tables/nsTableRowGroupFrame.cpp +++ b/mozilla/layout/tables/nsTableRowGroupFrame.cpp @@ -743,7 +743,7 @@ nsTableRowGroupFrame::ReflowUnmappedChildren(nsIPresContext* aPresContext, kidDel = kid->GetDelegate(aPresContext); kidFrame = kidDel->CreateFrame(aPresContext, kid, kidIndex, this); NS_RELEASE(kidDel); - kidFrame->SetStyleContext(kidSC); + kidFrame->SetStyleContext(aPresContext,kidSC); } else { kidPrevInFlow->CreateContinuingFrame(aPresContext, this, kidFrame); }