Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
TableBackgroundPainter Class Reference

#include <nsTablePainter.h>

Collaboration diagram for TableBackgroundPainter:
Collaboration graph
[legend]

List of all members.

Classes

struct  ColData
struct  TableBackgroundData

Public Types

enum  Origin { eOrigin_Table, eOrigin_TableRowGroup, eOrigin_TableRow }

Public Member Functions

 TableBackgroundPainter (nsTableFrame *aTableFrame, Origin aOrigin, nsPresContext *aPresContext, nsIRenderingContext &aRenderingContext, const nsRect &aDirtyRect)
 Public constructor.
 ~TableBackgroundPainter ()
 Destructor.
nsresult PaintTable (nsTableFrame *aTableFrame, nsMargin *aDeflate)
 Paint background for the table frame and its children down through cells (Cells themselves will only be painted in border collapse) Table must do a flagged TABLE_BG_PAINT ::Paint call on its children afterwards.
nsresult PaintRowGroup (nsTableRowGroupFrame *aFrame)
 Paint background for the row group and its children down through cells (Cells themselves will only be painted in border collapse) Standards mode only Table Row Group must do a flagged TABLE_BG_PAINT ::Paint call on its children afterwards.
nsresult PaintRow (nsTableRowFrame *aFrame)
 Paint background for the row and its children down through cells (Cells themselves will only be painted in border collapse) Standards mode only Table Row must do a flagged TABLE_BG_PAINT ::Paint call on its children afterwards.

Private Member Functions

nsresult PaintTableFrame (nsTableFrame *aTableFrame, nsTableRowGroupFrame *aFirstRowGroup, nsTableRowGroupFrame *aLastRowGroup, nsMargin *aDeflate=nsnull)
 Paint table frame's background.
nsresult PaintRowGroup (nsTableRowGroupFrame *aFrame, PRBool aPassThrough)
nsresult PaintRow (nsTableRowFrame *aFrame, PRBool aPassThrough)
nsresult PaintCell (nsTableCellFrame *aFrame, PRBool aPassSelf)
 Paint table background layers for this cell space Also paints cell's own background in border-collapse mode.
void TranslateContext (nscoord aDX, nscoord aDY)
 Translate mRenderingContext, mDirtyRect, and mCols' column and colgroup coords.

Private Attributes

nsPresContextmPresContext
nsIRenderingContextmRenderingContext
nsRect mDirtyRect
PRBool mIsBorderCollapse
Origin mOrigin
ColDatamCols
PRUint32 mNumCols
TableBackgroundData mRowGroup
TableBackgroundData mRow
nsRect mCellRect
nsStyleBorder mZeroBorder
nsStylePadding mZeroPadding
float mP2t

Friends

struct TableBackgroundData
struct ColData

Detailed Description

Definition at line 55 of file nsTablePainter.h.


Member Enumeration Documentation

Enumerator:
eOrigin_Table 
eOrigin_TableRowGroup 
eOrigin_TableRow 

Definition at line 64 of file nsTablePainter.h.


Constructor & Destructor Documentation

TableBackgroundPainter::TableBackgroundPainter ( nsTableFrame aTableFrame,
Origin  aOrigin,
nsPresContext aPresContext,
nsIRenderingContext aRenderingContext,
const nsRect aDirtyRect 
)

Public constructor.

Parameters:
aTableFrame- the table's table frame
aOrigin- what type of table frame is creating this instance
aPresContext- the presentation context
aRenderingContext- the rendering context
aDirtyRect- the area that needs to be painted

Definition at line 223 of file nsTablePainter.cpp.

  : mPresContext(aPresContext),
    mRenderingContext(aRenderingContext),
    mDirtyRect(aDirtyRect),
    mOrigin(aOrigin),
    mCols(nsnull),
    mZeroBorder(aPresContext)
{
  MOZ_COUNT_CTOR(TableBackgroundPainter);

  NS_FOR_CSS_SIDES(side) {
    mZeroBorder.SetBorderStyle(side, NS_STYLE_BORDER_STYLE_SOLID);
    mZeroBorder.SetBorderWidth(side, 0);
  }

  mZeroPadding.RecalcData();

  mP2t = mPresContext->ScaledPixelsToTwips();
  mIsBorderCollapse = aTableFrame->IsBorderCollapse();
#ifdef DEBUG
  mCompatMode = mPresContext->CompatibilityMode();
#endif
  mNumCols = aTableFrame->GetColCount();
}

Here is the call graph for this function:

Destructor.

Definition at line 252 of file nsTablePainter.cpp.

{
  if (mCols) {
    TableBackgroundData* lastColGroup = nsnull;
    for (PRUint32 i = 0; i < mNumCols; i++) {
      if (mCols[i].mColGroup != lastColGroup) {
        lastColGroup = mCols[i].mColGroup;
        NS_ASSERTION(mCols[i].mColGroup, "colgroup data should not be null - bug 237421");
        // we need to wallpaper a over zero pointer deref, bug 237421 will have the real fix
        if(lastColGroup)
          lastColGroup->Destroy(mPresContext);
        delete lastColGroup;
      }
      mCols[i].mColGroup = nsnull;
      mCols[i].mCol.Destroy(mPresContext);
    }
    delete [] mCols;
  }
  mRowGroup.Destroy(mPresContext);
  mRow.Destroy(mPresContext);
  MOZ_COUNT_DTOR(TableBackgroundPainter);
}

Here is the call graph for this function:


Member Function Documentation

nsresult TableBackgroundPainter::PaintCell ( nsTableCellFrame aFrame,
PRBool  aPassSelf 
) [private]

Paint table background layers for this cell space Also paints cell's own background in border-collapse mode.

Parameters:
aFrame- the cell
aPassSelf- pass this cell; i.e. paint only underlying layers

Definition at line 575 of file nsTablePainter.cpp.

{
  NS_PRECONDITION(aCell, "null frame");

  const nsStyleTableBorder* cellTableStyle;
  cellTableStyle = aCell->GetStyleTableBorder();
  if (!(NS_STYLE_TABLE_EMPTY_CELLS_SHOW == cellTableStyle->mEmptyCells ||
        NS_STYLE_TABLE_EMPTY_CELLS_SHOW_BACKGROUND == cellTableStyle->mEmptyCells)
      && aCell->GetContentEmpty()) {
    return NS_OK;
  }

  PRInt32 colIndex;
  aCell->GetColIndex(colIndex);
  NS_ASSERTION(colIndex < mNumCols, "prevent array boundary violation");
  if (mNumCols <= colIndex)
    return NS_OK;

  //Paint column group background
  if (mCols && mCols[colIndex].mColGroup && mCols[colIndex].mColGroup->IsVisible()) {
    nsCSSRendering::PaintBackgroundWithSC(mPresContext, mRenderingContext,
                                          mCols[colIndex].mColGroup->mFrame, mDirtyRect,
                                          mCols[colIndex].mColGroup->mRect,
                                          *mCols[colIndex].mColGroup->mBackground,
                                          *mCols[colIndex].mColGroup->mBorder,
                                          mZeroPadding, PR_TRUE, &mCellRect);
  }

  //Paint column background
  if (mCols && mCols[colIndex].mCol.IsVisible()) {
    nsCSSRendering::PaintBackgroundWithSC(mPresContext, mRenderingContext,
                                          mCols[colIndex].mCol.mFrame, mDirtyRect,
                                          mCols[colIndex].mCol.mRect,
                                          *mCols[colIndex].mCol.mBackground,
                                          *mCols[colIndex].mCol.mBorder,
                                          mZeroPadding, PR_TRUE, &mCellRect);
  }

  //Paint row group background
  if (mRowGroup.IsVisible()) {
    nsCSSRendering::PaintBackgroundWithSC(mPresContext, mRenderingContext,
                                          mRowGroup.mFrame, mDirtyRect, mRowGroup.mRect,
                                          *mRowGroup.mBackground, *mRowGroup.mBorder,
                                          mZeroPadding, PR_TRUE, &mCellRect);
  }

  //Paint row background
  if (mRow.IsVisible()) {
    nsCSSRendering::PaintBackgroundWithSC(mPresContext, mRenderingContext,
                                          mRow.mFrame, mDirtyRect, mRow.mRect,
                                          *mRow.mBackground, *mRow.mBorder,
                                          mZeroPadding, PR_TRUE, &mCellRect);
  }

  //Paint cell background in border-collapse unless we're just passing
  if (mIsBorderCollapse && !aPassSelf) {
    mRenderingContext.PushState();
    mRenderingContext.Translate(mCellRect.x, mCellRect.y);
    mDirtyRect.MoveBy(-mCellRect.x, -mCellRect.y);
    aCell->Paint(mPresContext, mRenderingContext, mDirtyRect,
                 NS_FRAME_PAINT_LAYER_BACKGROUND,
                 NS_PAINT_FLAG_TABLE_BG_PAINT | NS_PAINT_FLAG_TABLE_CELL_BG_PASS);
    mDirtyRect.MoveBy(mCellRect.x, mCellRect.y);
    mRenderingContext.PopState();
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Paint background for the row and its children down through cells (Cells themselves will only be painted in border collapse) Standards mode only Table Row must do a flagged TABLE_BG_PAINT ::Paint call on its children afterwards.

Parameters:
aFrame- the table row frame

Definition at line 129 of file nsTablePainter.h.

    { return PaintRow(aFrame, PR_FALSE); }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult TableBackgroundPainter::PaintRow ( nsTableRowFrame aFrame,
PRBool  aPassThrough 
) [private]

Definition at line 519 of file nsTablePainter.cpp.

{
  NS_PRECONDITION(aFrame, "null frame");

  if (!mRow.mFrame) {
    mRow.SetFrame(aFrame);
  }

  /* Load row data */
  if (!aPassThrough) {
    mRow.SetData(mPresContext, mRenderingContext);
    if (mIsBorderCollapse && mRow.ShouldSetBCBorder()) {
      nsMargin border;
      nsTableRowFrame* nextRow = aFrame->GetNextRow();
      if (nextRow) { //outer top below us is inner bottom for us
        border.bottom = nextRow->GetOuterTopContBCBorderWidth(mP2t);
      }
      else { //acquire rg's bottom border
        nsTableRowGroupFrame* rowGroup = NS_STATIC_CAST(nsTableRowGroupFrame*, aFrame->GetParent());
        rowGroup->GetContinuousBCBorderWidth(mP2t, border);
      }
      //get the rest of the borders; will overwrite all but bottom
      aFrame->GetContinuousBCBorderWidth(mP2t, border);

      nsresult res = mRow.SetBCBorder(border, this);
      if (!NS_SUCCEEDED(res)) {
        return res;
      }
    }
    aPassThrough = !mRow.IsVisible();
  }

  /* Translate */
  if (eOrigin_TableRow == mOrigin) {
    /* If we originate from the row, then make the row the origin. */
    mRow.mRect.MoveTo(0, 0);
  }
  //else: Use row group's coord system -> no translation necessary

  for (nsTableCellFrame* cell = aFrame->GetFirstCell(); cell; cell = cell->GetNextCell()) {
    mCellRect = cell->GetRect();
    //Translate to use the same coord system as mRow.
    mCellRect.MoveBy(mRow.mRect.x, mRow.mRect.y);
    if (mCellRect.Intersects(mDirtyRect)) {
      nsresult rv = PaintCell(cell, aPassThrough || cell->HasView());
      if (NS_FAILED(rv)) return rv;
    }
  }

  /* Unload row data */
  mRow.Clear();
  return NS_OK;
}

Here is the call graph for this function:

Paint background for the row group and its children down through cells (Cells themselves will only be painted in border collapse) Standards mode only Table Row Group must do a flagged TABLE_BG_PAINT ::Paint call on its children afterwards.

Parameters:
aFrame- the table row group frame

Definition at line 119 of file nsTablePainter.h.

    { return PaintRowGroup(aFrame, PR_FALSE); }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult TableBackgroundPainter::PaintRowGroup ( nsTableRowGroupFrame aFrame,
PRBool  aPassThrough 
) [private]

Definition at line 460 of file nsTablePainter.cpp.

{
  NS_PRECONDITION(aFrame, "null frame");

  if (!mRowGroup.mFrame) {
    mRowGroup.SetFrame(aFrame);
  }

  nsTableRowFrame* firstRow = aFrame->GetFirstRow();

  /* Load row group data */
  if (!aPassThrough) {
    mRowGroup.SetData(mPresContext, mRenderingContext);
    if (mIsBorderCollapse && mRowGroup.ShouldSetBCBorder()) {
      nsMargin border;
      if (firstRow) {
        //pick up first row's top border (= rg top border)
        firstRow->GetContinuousBCBorderWidth(mP2t, border);
        /* (row group doesn't store its top border) */
      }
      //overwrite sides+bottom borders with rg's own
      aFrame->GetContinuousBCBorderWidth(mP2t, border);
      nsresult res = mRowGroup.SetBCBorder(border, this);
      if (!NS_SUCCEEDED(res)) {
        return res;
      }
    }
    aPassThrough = !mRowGroup.IsVisible();
  }

  /* translate everything into row group coord system*/
  if (eOrigin_TableRowGroup != mOrigin) {
    TranslateContext(mRowGroup.mRect.x, mRowGroup.mRect.y);
  }
  nsRect rgRect = mRowGroup.mRect;
  mRowGroup.mRect.MoveTo(0, 0);

  /* paint */
  for (nsTableRowFrame* row = firstRow; row; row = row->GetNextRow()) {
    mRow.SetFrame(row);
    if (mDirtyRect.YMost() >= mRow.mRect.y) { //Intersect wouldn't handle rowspans
      nsresult rv = PaintRow(row, aPassThrough || row->HasView());
      if (NS_FAILED(rv)) return rv;
    }
  }

  /* translate back into table coord system */
  if (eOrigin_TableRowGroup != mOrigin) {
    TranslateContext(-rgRect.x, -rgRect.y);
  }
  
  /* unload rg data */
  mRowGroup.Clear();

  return NS_OK;
}

Here is the call graph for this function:

Paint background for the table frame and its children down through cells (Cells themselves will only be painted in border collapse) Table must do a flagged TABLE_BG_PAINT ::Paint call on its children afterwards.

Parameters:
aTableFrame- the table frame
aDeflate- deflation needed to bring table's mRect to the outer grid lines in border-collapse

Definition at line 352 of file nsTablePainter.cpp.

{
  NS_PRECONDITION(aTableFrame, "null table frame");

  nsVoidArray rowGroups;
  PRUint32 numRowGroups;
  aTableFrame->OrderRowGroups(rowGroups, numRowGroups);

  if (numRowGroups < 1) { //degenerate case
    PaintTableFrame(aTableFrame,nsnull, nsnull, nsnull);
    /* No cells; nothing else to paint */
    return NS_OK;
  }

  PaintTableFrame(aTableFrame,
                  aTableFrame->GetRowGroupFrame(NS_STATIC_CAST(nsIFrame*, rowGroups.ElementAt(0))),
                  aTableFrame->GetRowGroupFrame(NS_STATIC_CAST(nsIFrame*, rowGroups.ElementAt(numRowGroups - 1))),
                  aDeflate);

  /*Set up column background/border data*/
  if (mNumCols > 0) {
    nsFrameList& colGroupList = aTableFrame->GetColGroups();
    NS_ASSERTION(colGroupList.FirstChild(), "table should have at least one colgroup");

    mCols = new ColData[mNumCols];
    if (!mCols) return NS_ERROR_OUT_OF_MEMORY;

    TableBackgroundData* cgData = nsnull;
    nsMargin border;
    /* BC left borders aren't stored on cols, but the previous column's
       right border is the next one's left border.*/
    //Start with table's left border.
    nscoord lastLeftBorder = aTableFrame->GetContinuousLeftBCBorderWidth(mP2t);
    for (nsTableColGroupFrame* cgFrame = NS_STATIC_CAST(nsTableColGroupFrame*, colGroupList.FirstChild());
         cgFrame; cgFrame = NS_STATIC_CAST(nsTableColGroupFrame*, cgFrame->GetNextSibling())) {

      if (cgFrame->GetColCount() < 1) {
        //No columns, no cells, so no need for data
        continue;
      }

      /*Create data struct for column group*/
      cgData = new TableBackgroundData;
      if (!cgData) return NS_ERROR_OUT_OF_MEMORY;
      cgData->SetFull(mPresContext, mRenderingContext, cgFrame);
      if (mIsBorderCollapse && cgData->ShouldSetBCBorder()) {
        border.left = lastLeftBorder;
        cgFrame->GetContinuousBCBorderWidth(mP2t, border);
        nsresult rv = cgData->SetBCBorder(border, this);
        if (NS_FAILED(rv)) {
          cgData->Destroy(mPresContext);
          delete cgData;
          return rv;
        }
      }

      // Boolean that indicates whether mCols took ownership of cgData
      PRBool cgDataOwnershipTaken = PR_FALSE;
      
      /*Loop over columns in this colgroup*/
      if (cgData->IsVisible()) {
        for (nsTableColFrame* col = cgFrame->GetFirstColumn(); col;
             col = NS_STATIC_CAST(nsTableColFrame*, col->GetNextSibling())) {
          /*Create data struct for column*/
          PRUint32 colIndex = col->GetColIndex();
          NS_ASSERTION(colIndex < mNumCols, "prevent array boundary violation");
          if (mNumCols <= colIndex)
            break;
          mCols[colIndex].mCol.SetFull(mPresContext, mRenderingContext, col);
          //Bring column mRect into table's coord system
          mCols[colIndex].mCol.mRect.MoveBy(cgData->mRect.x, cgData->mRect.y);
          //link to parent colgroup's data
          mCols[colIndex].mColGroup = cgData;
          cgDataOwnershipTaken = PR_TRUE;
          if (mIsBorderCollapse) {
            border.left = lastLeftBorder;
            lastLeftBorder = col->GetContinuousBCBorderWidth(mP2t, border);
            if (mCols[colIndex].mCol.ShouldSetBCBorder()) {
              nsresult rv = mCols[colIndex].mCol.SetBCBorder(border, this);
              if (NS_FAILED(rv)) return rv;
            }
          }
        }
      }

      if (!cgDataOwnershipTaken) {
        cgData->Destroy(mPresContext);
        delete cgData;
      }
    }
  }

  for (PRUint32 i = 0; i < numRowGroups; i++) {
    nsTableRowGroupFrame* rg = nsTableFrame::GetRowGroupFrame(NS_STATIC_CAST(nsIFrame*, rowGroups.ElementAt(i)));
    mRowGroup.SetFrame(rg);
    // Need to compute the right rect via GetOffsetTo, since the row
    // group may not be a child of the table.
    mRowGroup.mRect.MoveTo(rg->GetOffsetTo(aTableFrame));
    if (mRowGroup.mRect.Intersects(mDirtyRect)) {
      nsresult rv = PaintRowGroup(rg, rg->HasView());
      if (NS_FAILED(rv)) return rv;
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult TableBackgroundPainter::PaintTableFrame ( nsTableFrame aTableFrame,
nsTableRowGroupFrame aFirstRowGroup,
nsTableRowGroupFrame aLastRowGroup,
nsMargin aDeflate = nsnull 
) [private]

Paint table frame's background.

Parameters:
aTableFrame- the table frame
aFirstRowGroup- the first (in layout order) row group may be null
aLastRowGroup- the last (in layout order) row group may be null
aDeflate- adjustment to frame's rect (used for quirks BC) may be null

Definition at line 276 of file nsTablePainter.cpp.

{
  NS_PRECONDITION(aTableFrame, "null frame");
  TableBackgroundData tableData;
  tableData.SetFull(mPresContext, mRenderingContext, aTableFrame);
  tableData.mRect.MoveTo(0,0); //using table's coords
  if (aDeflate) {
    tableData.mRect.Deflate(*aDeflate);
  }
  if (mIsBorderCollapse && tableData.ShouldSetBCBorder()) {
    if (aFirstRowGroup && aLastRowGroup && mNumCols > 0) {
      //only handle non-degenerate tables; we need a more robust BC model
      //to make degenerate tables' borders reasonable to deal with
      nsMargin border, tempBorder;
      nsTableColFrame* colFrame = aTableFrame->GetColFrame(mNumCols - 1);
      if (colFrame) {
        colFrame->GetContinuousBCBorderWidth(mP2t, tempBorder);
      }
      border.right = tempBorder.right;

      aLastRowGroup->GetContinuousBCBorderWidth(mP2t, tempBorder);
      border.bottom = tempBorder.bottom;

      nsTableRowFrame* rowFrame = aFirstRowGroup->GetFirstRow();
      if (rowFrame) {
        rowFrame->GetContinuousBCBorderWidth(mP2t, tempBorder);
        border.top = tempBorder.top;
      }

      border.left = aTableFrame->GetContinuousLeftBCBorderWidth(mP2t);

      nsresult rv = tableData.SetBCBorder(border, this);
      if (NS_FAILED(rv)) {
        tableData.Destroy(mPresContext);
        return rv;
      }
    }
  }
  if (tableData.IsVisible()) {
    nsCSSRendering::PaintBackgroundWithSC(mPresContext, mRenderingContext,
                                          tableData.mFrame, mDirtyRect,
                                          tableData.mRect,
                                          *tableData.mBackground,
                                          *tableData.mBorder,
                                          mZeroPadding, PR_TRUE);
  }
  tableData.Destroy(mPresContext);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Translate mRenderingContext, mDirtyRect, and mCols' column and colgroup coords.

Parameters:
aDX- origin's x-coord change
aDY- origin's y-coord change

Definition at line 330 of file nsTablePainter.cpp.

{
  mRenderingContext.Translate(aDX, aDY);
  mDirtyRect.MoveBy(-aDX, -aDY);
  if (mCols) {
    TableBackgroundData* lastColGroup = nsnull;
    for (PRUint32 i = 0; i < mNumCols; i++) {
      mCols[i].mCol.mRect.MoveBy(-aDX, -aDY);
      if (lastColGroup != mCols[i].mColGroup) {
        NS_ASSERTION(mCols[i].mColGroup, "colgroup data should not be null - bug 237421");
        // we need to wallpaper a over zero pointer deref, bug 237421 will have the real fix
        if (!mCols[i].mColGroup)
          return;
        mCols[i].mColGroup->mRect.MoveBy(-aDX, -aDY);
        lastColGroup = mCols[i].mColGroup;
      }
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend struct ColData [friend]

Definition at line 222 of file nsTablePainter.h.

friend struct TableBackgroundData [friend]

Definition at line 173 of file nsTablePainter.h.


Member Data Documentation

Definition at line 245 of file nsTablePainter.h.

Definition at line 241 of file nsTablePainter.h.

Definition at line 234 of file nsTablePainter.h.

Definition at line 238 of file nsTablePainter.h.

Definition at line 242 of file nsTablePainter.h.

Definition at line 239 of file nsTablePainter.h.

Definition at line 250 of file nsTablePainter.h.

Definition at line 232 of file nsTablePainter.h.

Definition at line 233 of file nsTablePainter.h.

Definition at line 244 of file nsTablePainter.h.

Definition at line 243 of file nsTablePainter.h.

Definition at line 248 of file nsTablePainter.h.

Definition at line 249 of file nsTablePainter.h.


The documentation for this class was generated from the following files: