From daf8cc32db79aa4decf62b721f0b1ece2a1020df Mon Sep 17 00:00:00 2001 From: "buster%netscape.com" Date: Wed, 11 Nov 1998 19:56:02 +0000 Subject: [PATCH] support for frame and rules attribute --- .../html/content/src/nsHTMLTableElement.cpp | 134 ++++++++++++++---- .../html/content/src/nsHTMLTableElement.cpp | 134 ++++++++++++++---- layout/html/table/src/nsTableCellFrame.cpp | 60 ++++++-- layout/html/table/src/nsTableCellFrame.h | 12 +- layout/html/table/src/nsTableFrame.cpp | 8 +- .../html/table/src/nsTableRowGroupFrame.cpp | 1 + layout/tables/nsTableCellFrame.cpp | 60 ++++++-- layout/tables/nsTableCellFrame.h | 12 +- layout/tables/nsTableFrame.cpp | 8 +- layout/tables/nsTableRowGroupFrame.cpp | 1 + 10 files changed, 342 insertions(+), 88 deletions(-) diff --git a/content/html/content/src/nsHTMLTableElement.cpp b/content/html/content/src/nsHTMLTableElement.cpp index 1b17382fd0d..f02bcf8b345 100644 --- a/content/html/content/src/nsHTMLTableElement.cpp +++ b/content/html/content/src/nsHTMLTableElement.cpp @@ -423,8 +423,79 @@ nsHTMLTableElement::AttributeToString(nsIAtom* aAttribute, 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 +MapTableFrameInto(nsIHTMLAttributes* aAttributes, + nsIStyleContext* aContext, + nsIPresContext* aPresContext, + nsStyleSpacing* aSpacing) +{ + // set up defaults + if (aSpacing->mBorderStyle[0] == NS_STYLE_BORDER_STYLE_NONE) { + aSpacing->mBorderStyle[0] = NS_STYLE_BORDER_STYLE_OUTSET; + } + if (aSpacing->mBorderStyle[1] == NS_STYLE_BORDER_STYLE_NONE) { + aSpacing->mBorderStyle[1] = NS_STYLE_BORDER_STYLE_OUTSET; + } + if (aSpacing->mBorderStyle[2] == NS_STYLE_BORDER_STYLE_NONE) { + aSpacing->mBorderStyle[2] = NS_STYLE_BORDER_STYLE_OUTSET; + } + if (aSpacing->mBorderStyle[3] == NS_STYLE_BORDER_STYLE_NONE) { + aSpacing->mBorderStyle[3] = NS_STYLE_BORDER_STYLE_OUTSET; + } + + nsHTMLValue frameValue; + // 0 out the sides that we want to hide based on the frame attribute + aAttributes->GetAttribute(nsHTMLAtoms::frame, frameValue); + if (frameValue.GetUnit() == eHTMLUnit_Enumerated) + { + // store the value of frame + nsStyleTable *tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + tableStyle->mFrame = frameValue.GetIntValue(); + tableStyle->mRules=NS_STYLE_TABLE_RULES_ALL; // most values of frame imply default rules=all + // adjust the border style based on the value of frame + switch (frameValue.GetIntValue()) + { + case NS_STYLE_TABLE_FRAME_NONE: + aSpacing->mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + tableStyle->mRules=NS_STYLE_TABLE_RULES_NONE; + break; + case NS_STYLE_TABLE_FRAME_ABOVE: + aSpacing->mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_FRAME_BELOW: + aSpacing->mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_FRAME_HSIDES: + aSpacing->mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_FRAME_LEFT: + aSpacing->mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_FRAME_RIGHT: + aSpacing->mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_FRAME_VSIDES: + aSpacing->mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + break; + // BOX and BORDER are ignored, the caller has already set all the border sides + // any illegal value is also ignored + } + } +} + static void MapTableBorderInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, @@ -433,45 +504,50 @@ MapTableBorderInto(nsIHTMLAttributes* aAttributes, NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); - nsHTMLValue value; + nsHTMLValue borderValue; - aAttributes->GetAttribute(nsHTMLAtoms::border, value); - if (value.GetUnit() == eHTMLUnit_String) + aAttributes->GetAttribute(nsHTMLAtoms::border, borderValue); + if (borderValue.GetUnit() == eHTMLUnit_String) { nsAutoString borderAsString; - value.GetStringValue(borderAsString); - nsGenericHTMLElement::ParseValue(borderAsString, 0, value, eHTMLUnit_Pixel); + borderValue.GetStringValue(borderAsString); + nsGenericHTMLElement::ParseValue(borderAsString, 0, borderValue, eHTMLUnit_Pixel); } - if ((value.GetUnit() == eHTMLUnit_Pixel) || - (value.GetUnit() == eHTMLUnit_Empty)) { + else if (borderValue.GetUnit() == eHTMLUnit_Null) + { // the absence of "border" with the presence of "frame" implies border = 1 pixel + nsHTMLValue frameValue; + aAttributes->GetAttribute(nsHTMLAtoms::frame, frameValue); + if (frameValue.GetUnit() != eHTMLUnit_Null) + borderValue.SetPixelValue(1); + } + if ((borderValue.GetUnit() == eHTMLUnit_Pixel) || + (borderValue.GetUnit() == eHTMLUnit_Empty)) { nsStyleSpacing* spacing = (nsStyleSpacing*) aContext->GetMutableStyleData(eStyleStruct_Spacing); + nsStyleTable *tableStyle = (nsStyleTable*) + aContext->GetMutableStyleData(eStyleStruct_Table); float p2t = aPresContext->GetPixelsToTwips(); nsStyleCoord twips; - if (value.GetUnit() == eHTMLUnit_Empty) { + if (borderValue.GetUnit() == eHTMLUnit_Empty) { + tableStyle->mRules=NS_STYLE_TABLE_RULES_ALL; // non-0 values of border imply default rules=all twips.SetCoordValue(NSIntPixelsToTwips(1, p2t)); } else { - twips.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + PRInt32 borderThickness = borderValue.GetPixelValue(); + twips.SetCoordValue(NSIntPixelsToTwips(borderThickness, p2t)); + if (0!=borderThickness) + tableStyle->mRules=NS_STYLE_TABLE_RULES_ALL; // non-0 values of border imply default rules=all + else + tableStyle->mRules=NS_STYLE_TABLE_RULES_NONE; // 0 value of border imply default rules=none } + // by default, set all border sides to the specified width 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_OUTSET; - } - if (spacing->mBorderStyle[1] == NS_STYLE_BORDER_STYLE_NONE) { - spacing->mBorderStyle[1] = NS_STYLE_BORDER_STYLE_OUTSET; - } - if (spacing->mBorderStyle[2] == NS_STYLE_BORDER_STYLE_NONE) { - spacing->mBorderStyle[2] = NS_STYLE_BORDER_STYLE_OUTSET; - } - if (spacing->mBorderStyle[3] == NS_STYLE_BORDER_STYLE_NONE) { - spacing->mBorderStyle[3] = NS_STYLE_BORDER_STYLE_OUTSET; - } + // then account for the frame attribute + MapTableFrameInto(aAttributes, aContext, aPresContext, spacing); } } @@ -503,7 +579,7 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, break; } } - // border + // border and frame MapTableBorderInto(aAttributes, aContext, aPresContext); // align @@ -562,6 +638,14 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, tableStyle->mCols = NS_STYLE_TABLE_COLS_ALL; } + // rules, must come after handling of border which set the default + aAttributes->GetAttribute(nsHTMLAtoms::rules, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) { + if (nsnull==tableStyle) + tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + tableStyle->mRules = value.GetIntValue(); + } + //background: color nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); diff --git a/layout/html/content/src/nsHTMLTableElement.cpp b/layout/html/content/src/nsHTMLTableElement.cpp index 1b17382fd0d..f02bcf8b345 100644 --- a/layout/html/content/src/nsHTMLTableElement.cpp +++ b/layout/html/content/src/nsHTMLTableElement.cpp @@ -423,8 +423,79 @@ nsHTMLTableElement::AttributeToString(nsIAtom* aAttribute, 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 +MapTableFrameInto(nsIHTMLAttributes* aAttributes, + nsIStyleContext* aContext, + nsIPresContext* aPresContext, + nsStyleSpacing* aSpacing) +{ + // set up defaults + if (aSpacing->mBorderStyle[0] == NS_STYLE_BORDER_STYLE_NONE) { + aSpacing->mBorderStyle[0] = NS_STYLE_BORDER_STYLE_OUTSET; + } + if (aSpacing->mBorderStyle[1] == NS_STYLE_BORDER_STYLE_NONE) { + aSpacing->mBorderStyle[1] = NS_STYLE_BORDER_STYLE_OUTSET; + } + if (aSpacing->mBorderStyle[2] == NS_STYLE_BORDER_STYLE_NONE) { + aSpacing->mBorderStyle[2] = NS_STYLE_BORDER_STYLE_OUTSET; + } + if (aSpacing->mBorderStyle[3] == NS_STYLE_BORDER_STYLE_NONE) { + aSpacing->mBorderStyle[3] = NS_STYLE_BORDER_STYLE_OUTSET; + } + + nsHTMLValue frameValue; + // 0 out the sides that we want to hide based on the frame attribute + aAttributes->GetAttribute(nsHTMLAtoms::frame, frameValue); + if (frameValue.GetUnit() == eHTMLUnit_Enumerated) + { + // store the value of frame + nsStyleTable *tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + tableStyle->mFrame = frameValue.GetIntValue(); + tableStyle->mRules=NS_STYLE_TABLE_RULES_ALL; // most values of frame imply default rules=all + // adjust the border style based on the value of frame + switch (frameValue.GetIntValue()) + { + case NS_STYLE_TABLE_FRAME_NONE: + aSpacing->mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + tableStyle->mRules=NS_STYLE_TABLE_RULES_NONE; + break; + case NS_STYLE_TABLE_FRAME_ABOVE: + aSpacing->mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_FRAME_BELOW: + aSpacing->mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_FRAME_HSIDES: + aSpacing->mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_FRAME_LEFT: + aSpacing->mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_FRAME_RIGHT: + aSpacing->mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_FRAME_VSIDES: + aSpacing->mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacing->mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + break; + // BOX and BORDER are ignored, the caller has already set all the border sides + // any illegal value is also ignored + } + } +} + static void MapTableBorderInto(nsIHTMLAttributes* aAttributes, nsIStyleContext* aContext, @@ -433,45 +504,50 @@ MapTableBorderInto(nsIHTMLAttributes* aAttributes, NS_PRECONDITION(nsnull!=aContext, "bad style context arg"); NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg"); - nsHTMLValue value; + nsHTMLValue borderValue; - aAttributes->GetAttribute(nsHTMLAtoms::border, value); - if (value.GetUnit() == eHTMLUnit_String) + aAttributes->GetAttribute(nsHTMLAtoms::border, borderValue); + if (borderValue.GetUnit() == eHTMLUnit_String) { nsAutoString borderAsString; - value.GetStringValue(borderAsString); - nsGenericHTMLElement::ParseValue(borderAsString, 0, value, eHTMLUnit_Pixel); + borderValue.GetStringValue(borderAsString); + nsGenericHTMLElement::ParseValue(borderAsString, 0, borderValue, eHTMLUnit_Pixel); } - if ((value.GetUnit() == eHTMLUnit_Pixel) || - (value.GetUnit() == eHTMLUnit_Empty)) { + else if (borderValue.GetUnit() == eHTMLUnit_Null) + { // the absence of "border" with the presence of "frame" implies border = 1 pixel + nsHTMLValue frameValue; + aAttributes->GetAttribute(nsHTMLAtoms::frame, frameValue); + if (frameValue.GetUnit() != eHTMLUnit_Null) + borderValue.SetPixelValue(1); + } + if ((borderValue.GetUnit() == eHTMLUnit_Pixel) || + (borderValue.GetUnit() == eHTMLUnit_Empty)) { nsStyleSpacing* spacing = (nsStyleSpacing*) aContext->GetMutableStyleData(eStyleStruct_Spacing); + nsStyleTable *tableStyle = (nsStyleTable*) + aContext->GetMutableStyleData(eStyleStruct_Table); float p2t = aPresContext->GetPixelsToTwips(); nsStyleCoord twips; - if (value.GetUnit() == eHTMLUnit_Empty) { + if (borderValue.GetUnit() == eHTMLUnit_Empty) { + tableStyle->mRules=NS_STYLE_TABLE_RULES_ALL; // non-0 values of border imply default rules=all twips.SetCoordValue(NSIntPixelsToTwips(1, p2t)); } else { - twips.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t)); + PRInt32 borderThickness = borderValue.GetPixelValue(); + twips.SetCoordValue(NSIntPixelsToTwips(borderThickness, p2t)); + if (0!=borderThickness) + tableStyle->mRules=NS_STYLE_TABLE_RULES_ALL; // non-0 values of border imply default rules=all + else + tableStyle->mRules=NS_STYLE_TABLE_RULES_NONE; // 0 value of border imply default rules=none } + // by default, set all border sides to the specified width 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_OUTSET; - } - if (spacing->mBorderStyle[1] == NS_STYLE_BORDER_STYLE_NONE) { - spacing->mBorderStyle[1] = NS_STYLE_BORDER_STYLE_OUTSET; - } - if (spacing->mBorderStyle[2] == NS_STYLE_BORDER_STYLE_NONE) { - spacing->mBorderStyle[2] = NS_STYLE_BORDER_STYLE_OUTSET; - } - if (spacing->mBorderStyle[3] == NS_STYLE_BORDER_STYLE_NONE) { - spacing->mBorderStyle[3] = NS_STYLE_BORDER_STYLE_OUTSET; - } + // then account for the frame attribute + MapTableFrameInto(aAttributes, aContext, aPresContext, spacing); } } @@ -503,7 +579,7 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, break; } } - // border + // border and frame MapTableBorderInto(aAttributes, aContext, aPresContext); // align @@ -562,6 +638,14 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes, tableStyle->mCols = NS_STYLE_TABLE_COLS_ALL; } + // rules, must come after handling of border which set the default + aAttributes->GetAttribute(nsHTMLAtoms::rules, value); + if (value.GetUnit() == eHTMLUnit_Enumerated) { + if (nsnull==tableStyle) + tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table); + tableStyle->mRules = value.GetIntValue(); + } + //background: color nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext, aPresContext); nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext); diff --git a/layout/html/table/src/nsTableCellFrame.cpp b/layout/html/table/src/nsTableCellFrame.cpp index d81bbb49e1b..b8ec2585934 100644 --- a/layout/html/table/src/nsTableCellFrame.cpp +++ b/layout/html/table/src/nsTableCellFrame.cpp @@ -16,6 +16,7 @@ * Reserved. */ #include "nsTableCellFrame.h" +#include "nsTableFrame.h" #include "nsIReflowCommand.h" #include "nsIStyleContext.h" #include "nsStyleConsts.h" @@ -115,6 +116,7 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext& aPresContext, //XXX: this could be calculated once and remembered // get border padding values + //XXX: also check style for rule on rendering empty cells nsMargin borderPadding; const nsStyleSpacing* cellSpacing; GetStyleData(eStyleStruct_Spacing , ((nsStyleStruct *&)cellSpacing)); @@ -500,7 +502,10 @@ nsTableCellFrame::CreateContinuingFrame(nsIPresContext& aPresContext, * Update the border style to map to the HTML border style * */ -void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext, nsStyleSpacing& aSpacingStyle, nscoord aBorderWidth) +void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext, + nsStyleSpacing& aSpacingStyle, + nscoord aBorderWidth, + nsTableFrame *aTableFrame) { nsStyleCoord width; width.SetCoordValue(aBorderWidth); @@ -538,11 +543,44 @@ void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext, nsStyleS if (borderColor == 0xFFFFFFFF) borderColor = 0xFFC0C0C0; - aSpacingStyle.mBorderColor[NS_SIDE_TOP] = aSpacingStyle.mBorderColor[NS_SIDE_LEFT] = aSpacingStyle.mBorderColor[NS_SIDE_BOTTOM] = aSpacingStyle.mBorderColor[NS_SIDE_RIGHT] = borderColor; + + //adjust the border style based on the table rules attribute + const nsStyleTable* tableStyle; + tableFrame->GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle); + + switch (tableStyle->mRules) + { + case NS_STYLE_TABLE_RULES_NONE: + aSpacingStyle.mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_RULES_GROUPS: + // XXX: it depends on which cell this is! + /* + aSpacingStyle.mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + */ + break; + case NS_STYLE_TABLE_RULES_COLS: + aSpacingStyle.mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + break; + + case NS_STYLE_TABLE_RULES_ROWS: + aSpacingStyle.mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + + // do nothing for "ALL" or for any illegal value + } } @@ -582,8 +620,8 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) return; // get the table frame style context, and from it get cellpadding, cellspacing, and border info - nsStyleTable* tableStyle; - tableFrame->GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle); + const nsStyleTable* tableStyle; + tableFrame->GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle); nsStyleSpacing* tableSpacingStyle; tableFrame->GetStyleData(eStyleStruct_Spacing,(nsStyleStruct *&)tableSpacingStyle); nsStyleSpacing* spacingData = (nsStyleSpacing*)mStyleContext->GetMutableStyleData(eStyleStruct_Spacing); @@ -603,16 +641,12 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) } // get border information from the table - if (tableSpacingStyle->mBorder.GetTopUnit() == eStyleUnit_Coord) + if (tableStyle->mRules!= NS_STYLE_TABLE_RULES_NONE) { - nsStyleCoord borderWidth; - tableSpacingStyle->mBorder.GetTop(borderWidth); - if (0!=borderWidth.GetCoordValue()) - { - // in HTML, cell borders are always 1 pixel by default - border = NSIntPixelsToTwips(1, aPresContext->GetPixelsToTwips()); - MapHTMLBorderStyle(aPresContext, *spacingData, border); - } + // XXX: need to get border width here + // in HTML, cell borders are always 1 pixel by default + border = NSIntPixelsToTwips(1, aPresContext->GetPixelsToTwips()); + MapHTMLBorderStyle(aPresContext, *spacingData, border, tableFrame); } } diff --git a/layout/html/table/src/nsTableCellFrame.h b/layout/html/table/src/nsTableCellFrame.h index d5165901e6b..f89d0ba2c57 100644 --- a/layout/html/table/src/nsTableCellFrame.h +++ b/layout/html/table/src/nsTableCellFrame.h @@ -20,11 +20,11 @@ #include "nscore.h" #include "nsHTMLContainerFrame.h" -#include "nsTableFrame.h" #include "nsTableRowFrame.h" // need to actually include this here to inline GetRowIndex struct nsStyleSpacing; - +class nsTableFrame; +class nsHTMLValue; /** * nsTableCellFrame @@ -192,8 +192,14 @@ protected: // Subclass hook for style post processing NS_IMETHOD DidSetStyleContext(nsIPresContext* aPresContext); + void MapBorderMarginPadding(nsIPresContext* aPresContext); - void MapHTMLBorderStyle(nsIPresContext* aPresContext,nsStyleSpacing& aSpacingStyle, nscoord aBorderWidth); + + void MapHTMLBorderStyle(nsIPresContext* aPresContext, + nsStyleSpacing& aSpacingStyle, + nscoord aBorderWidth, + nsTableFrame *aTableFrame); + PRBool ConvertToPixelValue(nsHTMLValue& aValue, PRInt32 aDefault, PRInt32& aResult); NS_IMETHOD IR_StyleChanged(nsIPresContext& aPresContext, diff --git a/layout/html/table/src/nsTableFrame.cpp b/layout/html/table/src/nsTableFrame.cpp index ad343f0daf5..d7358b1eba1 100644 --- a/layout/html/table/src/nsTableFrame.cpp +++ b/layout/html/table/src/nsTableFrame.cpp @@ -1360,9 +1360,9 @@ NS_METHOD nsTableFrame::Paint(nsIPresContext& aPresContext, nsRect rect(0, 0, mRect.width, mRect.height); nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, rect, *color, 0, 0); - // XXX: use GetSkipSides? + PRIntn skipSides = GetSkipSides(); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, rect, *spacing, 0); + aDirtyRect, rect, *spacing, skipSides); } // for debug... @@ -1379,6 +1379,8 @@ PRIntn nsTableFrame::GetSkipSides() const { PRIntn skip = 0; + // frame attribute was accounted for in nsHTMLTableElement::MapTableBorderInto + // account for pagination if (nsnull != mPrevInFlow) { skip |= 1 << NS_SIDE_TOP; } @@ -3777,7 +3779,7 @@ nscoord nsTableFrame::GetMinTableWidth() return result; } -/** return the maximum width of the table caption. Return 0 if the max width is unknown. */ +/** return the maximum width of the table. Return 0 if the max width is unknown. */ nscoord nsTableFrame::GetMaxTableWidth() { nscoord result = 0; diff --git a/layout/html/table/src/nsTableRowGroupFrame.cpp b/layout/html/table/src/nsTableRowGroupFrame.cpp index 470ab0bcb09..8a0bc9b503f 100644 --- a/layout/html/table/src/nsTableRowGroupFrame.cpp +++ b/layout/html/table/src/nsTableRowGroupFrame.cpp @@ -17,6 +17,7 @@ */ #include "nsTableRowGroupFrame.h" #include "nsTableRowFrame.h" +#include "nsTableFrame.h" #include "nsTableCellFrame.h" #include "nsIRenderingContext.h" #include "nsIPresContext.h" diff --git a/layout/tables/nsTableCellFrame.cpp b/layout/tables/nsTableCellFrame.cpp index d81bbb49e1b..b8ec2585934 100644 --- a/layout/tables/nsTableCellFrame.cpp +++ b/layout/tables/nsTableCellFrame.cpp @@ -16,6 +16,7 @@ * Reserved. */ #include "nsTableCellFrame.h" +#include "nsTableFrame.h" #include "nsIReflowCommand.h" #include "nsIStyleContext.h" #include "nsStyleConsts.h" @@ -115,6 +116,7 @@ NS_METHOD nsTableCellFrame::Paint(nsIPresContext& aPresContext, //XXX: this could be calculated once and remembered // get border padding values + //XXX: also check style for rule on rendering empty cells nsMargin borderPadding; const nsStyleSpacing* cellSpacing; GetStyleData(eStyleStruct_Spacing , ((nsStyleStruct *&)cellSpacing)); @@ -500,7 +502,10 @@ nsTableCellFrame::CreateContinuingFrame(nsIPresContext& aPresContext, * Update the border style to map to the HTML border style * */ -void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext, nsStyleSpacing& aSpacingStyle, nscoord aBorderWidth) +void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext, + nsStyleSpacing& aSpacingStyle, + nscoord aBorderWidth, + nsTableFrame *aTableFrame) { nsStyleCoord width; width.SetCoordValue(aBorderWidth); @@ -538,11 +543,44 @@ void nsTableCellFrame::MapHTMLBorderStyle(nsIPresContext* aPresContext, nsStyleS if (borderColor == 0xFFFFFFFF) borderColor = 0xFFC0C0C0; - aSpacingStyle.mBorderColor[NS_SIDE_TOP] = aSpacingStyle.mBorderColor[NS_SIDE_LEFT] = aSpacingStyle.mBorderColor[NS_SIDE_BOTTOM] = aSpacingStyle.mBorderColor[NS_SIDE_RIGHT] = borderColor; + + //adjust the border style based on the table rules attribute + const nsStyleTable* tableStyle; + tableFrame->GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle); + + switch (tableStyle->mRules) + { + case NS_STYLE_TABLE_RULES_NONE: + aSpacingStyle.mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + case NS_STYLE_TABLE_RULES_GROUPS: + // XXX: it depends on which cell this is! + /* + aSpacingStyle.mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + */ + break; + case NS_STYLE_TABLE_RULES_COLS: + aSpacingStyle.mBorderStyle[NS_SIDE_TOP] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_BOTTOM] = NS_STYLE_BORDER_STYLE_NONE; + break; + + case NS_STYLE_TABLE_RULES_ROWS: + aSpacingStyle.mBorderStyle[NS_SIDE_RIGHT] = NS_STYLE_BORDER_STYLE_NONE; + aSpacingStyle.mBorderStyle[NS_SIDE_LEFT] = NS_STYLE_BORDER_STYLE_NONE; + break; + + // do nothing for "ALL" or for any illegal value + } } @@ -582,8 +620,8 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) return; // get the table frame style context, and from it get cellpadding, cellspacing, and border info - nsStyleTable* tableStyle; - tableFrame->GetStyleData(eStyleStruct_Table, (nsStyleStruct *&)tableStyle); + const nsStyleTable* tableStyle; + tableFrame->GetStyleData(eStyleStruct_Table, (const nsStyleStruct *&)tableStyle); nsStyleSpacing* tableSpacingStyle; tableFrame->GetStyleData(eStyleStruct_Spacing,(nsStyleStruct *&)tableSpacingStyle); nsStyleSpacing* spacingData = (nsStyleSpacing*)mStyleContext->GetMutableStyleData(eStyleStruct_Spacing); @@ -603,16 +641,12 @@ void nsTableCellFrame::MapBorderMarginPadding(nsIPresContext* aPresContext) } // get border information from the table - if (tableSpacingStyle->mBorder.GetTopUnit() == eStyleUnit_Coord) + if (tableStyle->mRules!= NS_STYLE_TABLE_RULES_NONE) { - nsStyleCoord borderWidth; - tableSpacingStyle->mBorder.GetTop(borderWidth); - if (0!=borderWidth.GetCoordValue()) - { - // in HTML, cell borders are always 1 pixel by default - border = NSIntPixelsToTwips(1, aPresContext->GetPixelsToTwips()); - MapHTMLBorderStyle(aPresContext, *spacingData, border); - } + // XXX: need to get border width here + // in HTML, cell borders are always 1 pixel by default + border = NSIntPixelsToTwips(1, aPresContext->GetPixelsToTwips()); + MapHTMLBorderStyle(aPresContext, *spacingData, border, tableFrame); } } diff --git a/layout/tables/nsTableCellFrame.h b/layout/tables/nsTableCellFrame.h index d5165901e6b..f89d0ba2c57 100644 --- a/layout/tables/nsTableCellFrame.h +++ b/layout/tables/nsTableCellFrame.h @@ -20,11 +20,11 @@ #include "nscore.h" #include "nsHTMLContainerFrame.h" -#include "nsTableFrame.h" #include "nsTableRowFrame.h" // need to actually include this here to inline GetRowIndex struct nsStyleSpacing; - +class nsTableFrame; +class nsHTMLValue; /** * nsTableCellFrame @@ -192,8 +192,14 @@ protected: // Subclass hook for style post processing NS_IMETHOD DidSetStyleContext(nsIPresContext* aPresContext); + void MapBorderMarginPadding(nsIPresContext* aPresContext); - void MapHTMLBorderStyle(nsIPresContext* aPresContext,nsStyleSpacing& aSpacingStyle, nscoord aBorderWidth); + + void MapHTMLBorderStyle(nsIPresContext* aPresContext, + nsStyleSpacing& aSpacingStyle, + nscoord aBorderWidth, + nsTableFrame *aTableFrame); + PRBool ConvertToPixelValue(nsHTMLValue& aValue, PRInt32 aDefault, PRInt32& aResult); NS_IMETHOD IR_StyleChanged(nsIPresContext& aPresContext, diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index ad343f0daf5..d7358b1eba1 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -1360,9 +1360,9 @@ NS_METHOD nsTableFrame::Paint(nsIPresContext& aPresContext, nsRect rect(0, 0, mRect.width, mRect.height); nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this, aDirtyRect, rect, *color, 0, 0); - // XXX: use GetSkipSides? + PRIntn skipSides = GetSkipSides(); nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, - aDirtyRect, rect, *spacing, 0); + aDirtyRect, rect, *spacing, skipSides); } // for debug... @@ -1379,6 +1379,8 @@ PRIntn nsTableFrame::GetSkipSides() const { PRIntn skip = 0; + // frame attribute was accounted for in nsHTMLTableElement::MapTableBorderInto + // account for pagination if (nsnull != mPrevInFlow) { skip |= 1 << NS_SIDE_TOP; } @@ -3777,7 +3779,7 @@ nscoord nsTableFrame::GetMinTableWidth() return result; } -/** return the maximum width of the table caption. Return 0 if the max width is unknown. */ +/** return the maximum width of the table. Return 0 if the max width is unknown. */ nscoord nsTableFrame::GetMaxTableWidth() { nscoord result = 0; diff --git a/layout/tables/nsTableRowGroupFrame.cpp b/layout/tables/nsTableRowGroupFrame.cpp index 470ab0bcb09..8a0bc9b503f 100644 --- a/layout/tables/nsTableRowGroupFrame.cpp +++ b/layout/tables/nsTableRowGroupFrame.cpp @@ -17,6 +17,7 @@ */ #include "nsTableRowGroupFrame.h" #include "nsTableRowFrame.h" +#include "nsTableFrame.h" #include "nsTableCellFrame.h" #include "nsIRenderingContext.h" #include "nsIPresContext.h"