Bug 716408 - Make nsTableFrame::GetTableFrame abort if the given frame isn't a table frame descendant, thus guaranteeing a non-null result. r=bernd

This commit is contained in:
Mats Palmgren
2012-01-17 00:38:10 +01:00
parent 702081ffc5
commit e0018d2b82
6 changed files with 66 additions and 141 deletions

View File

@@ -236,9 +236,7 @@ nsTableCellFrame::AttributeChanged(PRInt32 aNameSpaceID,
}
// let the table frame decide what to do
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame) {
tableFrame->AttributeChangedFor(this, mContent, aAttribute);
}
return NS_OK;
}
@@ -249,7 +247,6 @@ nsTableCellFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
return;
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame->IsBorderCollapse() &&
tableFrame->BCRecalcNeeded(aOldStyleContext, GetStyleContext())) {
PRInt32 colIndex, rowIndex;
@@ -443,7 +440,6 @@ nsTableCellFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
DO_GLOBAL_REFLOW_COUNT_DSP("nsTableCellFrame");
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
PRInt32 emptyCellStyle = GetContentEmpty() && !tableFrame->IsBorderCollapse() ?
GetStyleTableBorder()->mEmptyCells
: NS_STYLE_TABLE_EMPTY_CELLS_SHOW;
@@ -824,11 +820,6 @@ NS_METHOD nsTableCellFrame::Reflow(nsPresContext* aPresContext,
aStatus = NS_FRAME_COMPLETE;
nsSize availSize(aReflowState.availableWidth, aReflowState.availableHeight);
/* It's the 'border-collapse' on the table that matters */
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame)
ABORT1(NS_ERROR_NULL_POINTER);
nsMargin borderPadding = aReflowState.mComputedPadding;
nsMargin border;
GetBorderWidth(border);
@@ -854,6 +845,7 @@ NS_METHOD nsTableCellFrame::Reflow(nsPresContext* aPresContext,
SetPriorAvailWidth(aReflowState.availableWidth);
nsIFrame* firstKid = mFrames.FirstChild();
NS_ASSERTION(firstKid, "Frame construction error, a table cell always has an inner cell frame");
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (aReflowState.mFlags.mSpecialHeightReflow) {
const_cast<nsHTMLReflowState&>(aReflowState).SetComputedHeight(mRect.height - topInset - bottomInset);

View File

@@ -90,13 +90,11 @@ nsTableColFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
return;
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame->IsBorderCollapse() &&
tableFrame->BCRecalcNeeded(aOldStyleContext, GetStyleContext())) {
nsRect damageArea = nsRect(GetColIndex(), 0, 1, tableFrame->GetRowCount());
tableFrame->AddBCDamageArea(damageArea);
}
return;
}
void nsTableColFrame::SetContinuousBCBorderWidth(PRUint8 aForSide,
@@ -130,10 +128,8 @@ NS_METHOD nsTableColFrame::Reflow(nsPresContext* aPresContext,
bool collapseCol = (NS_STYLE_VISIBILITY_COLLAPSE == colVis->mVisible);
if (collapseCol) {
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame) {
tableFrame->SetNeedToCollapse(true);
}
}
aStatus = NS_FRAME_COMPLETE;
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
return NS_OK;

View File

@@ -102,10 +102,7 @@ nsTableColGroupFrame::AddColsToTable(PRInt32 aFirstColIndex,
bool aResetSubsequentColIndices,
const nsFrameList::Slice& aCols)
{
nsresult rv = NS_OK;
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame)
return NS_ERROR_NULL_POINTER;
// set the col indices of the col frames and and add col info to the table
PRInt32 colIndex = aFirstColIndex;
@@ -132,7 +129,7 @@ nsTableColGroupFrame::AddColsToTable(PRInt32 aFirstColIndex,
ResetColIndices(GetNextSibling(), colIndex);
}
return rv;
return NS_OK;
}
@@ -177,9 +174,6 @@ nsTableColGroupFrame::SetInitialChildList(ChildListID aListID,
return NS_ERROR_INVALID_ARG;
}
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame)
return NS_ERROR_NULL_POINTER;
if (aChildList.IsEmpty()) {
tableFrame->AppendAnonymousColFrames(this, GetSpan(), eColAnonymousColGroup,
false);
@@ -197,7 +191,6 @@ nsTableColGroupFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
return;
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame->IsBorderCollapse() &&
tableFrame->BCRecalcNeeded(aOldStyleContext, GetStyleContext())) {
PRInt32 colCount = GetColCount();
@@ -207,7 +200,6 @@ nsTableColGroupFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
tableFrame->GetRowCount());
tableFrame->AddBCDamageArea(damageArea);
}
return;
}
NS_IMETHODIMP
@@ -359,9 +351,6 @@ nsTableColGroupFrame::RemoveFrame(ChildListID aListID,
RemoveChild(*colFrame, true);
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame)
return NS_ERROR_NULL_POINTER;
tableFrame->RemoveCol(this, colIndex, true, true);
if (mFrames.IsEmpty() && contentRemoval &&
GetColType() == eColGroupContent) {
@@ -403,9 +392,7 @@ NS_METHOD nsTableColGroupFrame::Reflow(nsPresContext* aPresContext,
bool collapseGroup = (NS_STYLE_VISIBILITY_COLLAPSE == groupVis->mVisible);
if (collapseGroup) {
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame) {
tableFrame->SetNeedToCollapse(true);;
}
tableFrame->SetNeedToCollapse(true);
}
// for every content child that (is a column thingy and does not already have a frame)
// create a frame and adjust it's style
@@ -487,7 +474,6 @@ void nsTableColGroupFrame::GetContinuousBCBorderWidth(nsMargin& aBorder)
mTopContBorderWidth);
aBorder.bottom = BC_BORDER_TOP_HALF_COORD(aPixelsToTwips,
mBottomContBorderWidth);
return;
}
/* ----- global methods ----- */

View File

@@ -3364,18 +3364,15 @@ NS_NewTableFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
NS_IMPL_FRAMEARENA_HELPERS(nsTableFrame)
nsTableFrame*
nsTableFrame::GetTableFrame(nsIFrame* aSourceFrame)
nsTableFrame::GetTableFrame(nsIFrame* aFrame)
{
if (aSourceFrame) {
// "result" is the result of intermediate calls, not the result we return from this method
for (nsIFrame* parentFrame = aSourceFrame->GetParent(); parentFrame;
parentFrame = parentFrame->GetParent()) {
if (nsGkAtoms::tableFrame == parentFrame->GetType()) {
return (nsTableFrame*)parentFrame;
for (nsIFrame* ancestor = aFrame->GetParent(); ancestor;
ancestor = ancestor->GetParent()) {
if (nsGkAtoms::tableFrame == ancestor->GetType()) {
return static_cast<nsTableFrame*>(ancestor);
}
}
}
NS_NOTREACHED("unable to find table parent");
NS_RUNTIMEABORT("unable to find table parent");
return nsnull;
}
@@ -3581,14 +3578,8 @@ void nsTableIterator::Init(nsIFrame* aFirstChild)
}
nsTableFrame* table = nsTableFrame::GetTableFrame(mFirstChild);
if (table) {
mLeftToRight = (NS_STYLE_DIRECTION_LTR ==
table->GetStyleVisibility()->mDirection);
}
else {
NS_NOTREACHED("source of table iterator is not part of a table");
return;
}
if (!mLeftToRight) {
mCount = 0;

View File

@@ -196,7 +196,6 @@ nsTableRowFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
nsRect damageArea(0, GetRowIndex(), tableFrame->GetColCount(), 1);
tableFrame->AddBCDamageArea(damageArea);
}
return;
}
NS_IMETHODIMP
@@ -265,7 +264,6 @@ nsTableRowFrame::RemoveFrame(ChildListID aListID,
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list");
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame) {
nsTableCellFrame *cellFrame = do_QueryFrame(aOldFrame);
if (cellFrame) {
PRInt32 colIndex;
@@ -285,7 +283,6 @@ nsTableRowFrame::RemoveFrame(ChildListID aListID,
NS_ERROR("unexpected frame type");
return NS_ERROR_INVALID_ARG;
}
}
return NS_OK;
}
@@ -350,9 +347,6 @@ nsTableRowFrame::DidResize()
{
// Resize and re-align the cell frames based on our row height
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame)
return;
nsTableIterator iter(*this);
nsIFrame* childFrame = iter.First();
@@ -519,9 +513,6 @@ nscoord
nsTableRowFrame::CalcHeight(const nsHTMLReflowState& aReflowState)
{
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame)
return 0;
nscoord computedHeight = (NS_UNCONSTRAINEDSIZE == aReflowState.ComputedHeight())
? 0 : aReflowState.ComputedHeight();
ResetHeight(computedHeight);
@@ -582,9 +573,9 @@ public:
void
nsDisplayTableRowBackground::Paint(nsDisplayListBuilder* aBuilder,
nsRenderingContext* aCtx) {
nsRenderingContext* aCtx)
{
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(mFrame);
TableBackgroundPainter painter(tableFrame,
TableBackgroundPainter::eOrigin_TableRow,
mFrame->PresContext(), *aCtx,
@@ -644,9 +635,6 @@ nsTableRowFrame::CalculateCellActualHeight(nsTableCellFrame* aCellFrame,
const nsStylePosition* position = aCellFrame->GetStylePosition();
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame)
return NS_ERROR_NULL_POINTER;
PRInt32 rowSpan = tableFrame->GetEffectiveRowSpan(*aCellFrame);
switch (position->mHeight.GetUnit()) {
@@ -1027,9 +1015,6 @@ nsTableRowFrame::Reflow(nsPresContext* aPresContext,
nsresult rv = NS_OK;
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame)
return NS_ERROR_NULL_POINTER;
const nsStyleVisibility* rowVis = GetStyleVisibility();
bool collapseRow = (NS_STYLE_VISIBILITY_COLLAPSE == rowVis->mVisible);
if (collapseRow) {
@@ -1071,15 +1056,12 @@ nsTableRowFrame::ReflowCellFrame(nsPresContext* aPresContext,
nscoord aAvailableHeight,
nsReflowStatus& aStatus)
{
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame)
ABORT1(NS_ERROR_NULL_POINTER);
// Reflow the cell frame with the specified height. Use the existing width
nsRect cellRect = aCellFrame->GetRect();
nsRect cellVisualOverflow = aCellFrame->GetVisualOverflowRect();
nsSize availSize(cellRect.width, aAvailableHeight);
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
bool borderCollapse = tableFrame->IsBorderCollapse();
nsTableCellReflowState cellReflowState(aPresContext, aReflowState,
aCellFrame, availSize, false);

View File

@@ -96,10 +96,8 @@ PRInt32 nsTableRowGroupFrame::GetStartRowIndex()
// if the row group doesn't have any children, get it the hard way
if (-1 == result) {
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame) {
return tableFrame->GetStartRowIndex(this);
}
}
return result;
}
@@ -178,9 +176,9 @@ public:
void
nsDisplayTableRowGroupBackground::Paint(nsDisplayListBuilder* aBuilder,
nsRenderingContext* aCtx) {
nsRenderingContext* aCtx)
{
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(mFrame);
TableBackgroundPainter painter(tableFrame,
TableBackgroundPainter::eOrigin_TableRowGroup,
mFrame->PresContext(), *aCtx,
@@ -350,13 +348,8 @@ nsTableRowGroupFrame::ReflowChildren(nsPresContext* aPresContext,
*aPageBreakBeforeEnd = false;
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame)
ABORT1(NS_ERROR_NULL_POINTER);
nsresult rv = NS_OK;
bool borderCollapse = tableFrame->IsBorderCollapse();
const bool borderCollapse = tableFrame->IsBorderCollapse();
nscoord cellSpacingY = tableFrame->GetCellSpacingY();
// XXXldb Should we really be checking this rather than available height?
@@ -564,9 +557,7 @@ nsTableRowGroupFrame::CalculateRowHeights(nsPresContext* aPresContext,
const nsHTMLReflowState& aReflowState)
{
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame) return;
bool isPaginated = aPresContext->IsPaginated();
const bool isPaginated = aPresContext->IsPaginated();
// all table cells have the same top and bottom margins, namely cellSpacingY
nscoord cellSpacingY = tableFrame->GetCellSpacingY();
@@ -844,7 +835,6 @@ nsTableRowGroupFrame::CollapseRowGroupIfNecessary(nscoord aYTotalOffset,
nscoord aWidth)
{
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
const nsStyleVisibility* groupVis = GetStyleVisibility();
bool collapseGroup = (NS_STYLE_VISIBILITY_COLLAPSE == groupVis->mVisible);
if (collapseGroup) {
@@ -1317,15 +1307,13 @@ nsTableRowGroupFrame::Reflow(nsPresContext* aPresContext,
nsresult rv = NS_OK;
aStatus = NS_FRAME_COMPLETE;
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame) return NS_ERROR_NULL_POINTER;
// Row geometry may be going to change so we need to invalidate any row cursor.
ClearRowCursor();
// see if a special height reflow needs to occur due to having a pct height
nsTableFrame::CheckRequestSpecialHeightReflow(aReflowState);
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
nsRowGroupReflowState state(aReflowState, tableFrame);
const nsStyleVisibility* groupVis = GetStyleVisibility();
bool collapseGroup = (NS_STYLE_VISIBILITY_COLLAPSE == groupVis->mVisible);
@@ -1388,14 +1376,12 @@ nsTableRowGroupFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
return;
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame->IsBorderCollapse() &&
tableFrame->BCRecalcNeeded(aOldStyleContext, GetStyleContext())) {
nsRect damageArea(0, GetStartRowIndex(), tableFrame->GetColCount(),
GetRowCount());
tableFrame->AddBCDamageArea(damageArea);
}
return;
}
NS_IMETHODIMP
@@ -1426,14 +1412,12 @@ nsTableRowGroupFrame::AppendFrames(ChildListID aListID,
if (rows.Length() > 0) {
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame) {
tableFrame->AppendRows(this, rowIndex, rows);
PresContext()->PresShell()->
FrameNeedsReflow(this, nsIPresShell::eTreeChange,
NS_FRAME_HAS_DIRTY_CHILDREN);
tableFrame->SetGeometryDirty();
}
}
return NS_OK;
}
@@ -1449,12 +1433,9 @@ nsTableRowGroupFrame::InsertFrames(ChildListID aListID,
ClearRowCursor();
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (!tableFrame)
return NS_ERROR_NULL_POINTER;
// collect the new row frames in an array
// XXXbz why are we doing the QI stuff? There shouldn't be any non-rows here.
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
nsTArray<nsTableRowFrame*> rows;
bool gotFirstRow = false;
for (nsFrameList::Enumerator e(aFrameList); !e.AtEnd(); e.Next()) {
@@ -1500,7 +1481,7 @@ nsTableRowGroupFrame::RemoveFrame(ChildListID aListID,
ClearRowCursor();
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame) {
// XXX why are we doing the QI stuff? There shouldn't be any non-rows here.
nsTableRowFrame* rowFrame = do_QueryFrame(aOldFrame);
if (rowFrame) {
// remove the rows from the table (and flag a rebalance)
@@ -1511,7 +1492,6 @@ nsTableRowGroupFrame::RemoveFrame(ChildListID aListID,
NS_FRAME_HAS_DIRTY_CHILDREN);
tableFrame->SetGeometryDirty();
}
}
mFrames.DestroyFrame(aOldFrame);
return NS_OK;
@@ -1540,7 +1520,6 @@ nsTableRowGroupFrame::GetHeightBasis(const nsHTMLReflowState& aReflowState)
{
nscoord result = 0;
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
if (tableFrame) {
if ((aReflowState.ComputedHeight() > 0) && (aReflowState.ComputedHeight() < NS_UNCONSTRAINEDSIZE)) {
nscoord cellSpacing = NS_MAX(0, GetRowCount() - 1) * tableFrame->GetCellSpacingY();
result = aReflowState.ComputedHeight() - cellSpacing;
@@ -1556,7 +1535,6 @@ nsTableRowGroupFrame::GetHeightBasis(const nsHTMLReflowState& aReflowState)
result = parentRS->ComputedHeight() - cellSpacing;
}
}
}
return result;
}