Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
BasicTableLayoutStrategy.cpp File Reference
#include "plarena.h"
#include "BasicTableLayoutStrategy.h"
#include "nsPresContext.h"
#include "nsTableFrame.h"
#include "nsTableColFrame.h"
#include "nsTableCellFrame.h"
#include "nsStyleConsts.h"
#include "nsVoidArray.h"
#include "nsQuickSort.h"

Go to the source code of this file.

Classes

struct  CellInfo
struct  ColInfo

Defines

#define PL_ARENA_CONST_ALIGN_MASK   (sizeof(void*)-1)
#define ARENA_ALLOCATE(var, pool, num, type)
#define FINISHED   99
#define LIMIT_PCT   0
#define LIMIT_FIX   1
#define LIMIT_DES   2
#define LIMIT_NONE   3

Functions

PRBool CanAllocate (PRInt32 aType, PRInt32 aPrevType, nsTableColFrame *aColFrame)
PRBool HasPctValue (const nsIFrame *aFrame)
PRBool BCW_Wrapup (const nsHTMLReflowState &aReflowState, BasicTableLayoutStrategy *aStrategy, nsTableFrame *aTableFrame, PRInt32 *aAllocTypes)
void ResetPctValues (nsTableFrame *aTableFrame, PRInt32 aNumCols)
nscoord GetColWidth (nsTableColFrame *aColFrame, PRInt32 aWidthType)
nscoord GetConstrainedWidth (nsTableColFrame *colFrame, PRBool aConsiderPct)
static int RowSortCB (const void *a, const void *b, void *)
static PRInt32 GetSortedFrames (nsTableFrame *TableFrame, PRInt32 colX, PRInt32 numRows, CellInfo *cellInfo)
 This function finds all the rows which have a colspan greater than 1, and places those rows into the cellInfo array.
nscoord WrapupAssignPctColumnWidths (nsTableFrame *aTableFrame, const nsHTMLReflowState &aReflowState, nscoord aValue)
void AC_Wrapup (nsTableFrame *aTableFrame, PRInt32 aNumItems, ColInfo **aColInfo, PRBool aAbort=PR_FALSE)
void AC_Increase (PRInt32 aNumAutoCols, ColInfo **aColInfo, PRInt32 aDivisor, PRInt32 &aAvailWidth, float aPixelToTwips)
void AC_Decrease (PRInt32 aNumAutoCols, ColInfo **aColInfo, PRInt32 aDivisor, PRInt32 &aExcess, float aPixelToTwips)
void AC_Sort (ColInfo **aColInfo, PRInt32 aNumCols)

Class Documentation

struct CellInfo

Definition at line 364 of file btree.c.

Collaboration diagram for CellInfo:
Class Members
nsTableCellFrame * cellFrame
PRInt32 colSpan
u16 iOverflow
u32 nData
u16 nHeader
i64 nKey
u16 nLocal
u16 nSize
u8 * pCell

Define Documentation

#define ARENA_ALLOCATE (   var,
  pool,
  num,
  type 
)
Value:
{void *_tmp_; PL_ARENA_ALLOCATE(_tmp_, pool, (num*sizeof(type))); \
    var = NS_REINTERPRET_CAST(type*, _tmp_); }

Definition at line 51 of file BasicTableLayoutStrategy.cpp.

#define FINISHED   99

Definition at line 446 of file BasicTableLayoutStrategy.cpp.

#define LIMIT_DES   2

Definition at line 538 of file BasicTableLayoutStrategy.cpp.

#define LIMIT_FIX   1

Definition at line 537 of file BasicTableLayoutStrategy.cpp.

#define LIMIT_NONE   3

Definition at line 539 of file BasicTableLayoutStrategy.cpp.

#define LIMIT_PCT   0

Definition at line 536 of file BasicTableLayoutStrategy.cpp.

Definition at line 38 of file BasicTableLayoutStrategy.cpp.


Function Documentation

void AC_Decrease ( PRInt32  aNumAutoCols,
ColInfo **  aColInfo,
PRInt32  aDivisor,
PRInt32 aExcess,
float  aPixelToTwips 
)

Definition at line 1786 of file BasicTableLayoutStrategy.cpp.

{
  for (PRInt32 i = 0; i < aNumAutoCols; i++) {
    if ((aExcess <= 0) || (aDivisor <= 0)) {
      break;
    }
    float percent = ((float)aColInfo[i]->mMaxWidth) / (float)aDivisor;
    aDivisor -= aColInfo[i]->mMaxWidth;
    nscoord reduction = nsTableFrame::RoundToPixel(NSToCoordRound(((float)(aExcess)) * percent), aPixelToTwips);
    // if its the last col, try to remove the remaining excess from it
    if ((i == aNumAutoCols - 1) && (reduction < aExcess)) {
      reduction = aExcess;
    }
    // don't let the reduction exceed what is available to reduce
    reduction = PR_MIN(reduction, aExcess);
    // don't go under the col min
    reduction = PR_MIN(reduction, aColInfo[i]->mWidth - aColInfo[i]->mMinWidth);
    aColInfo[i]->mWidth -= reduction;
    aExcess -= reduction;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void AC_Increase ( PRInt32  aNumAutoCols,
ColInfo **  aColInfo,
PRInt32  aDivisor,
PRInt32 aAvailWidth,
float  aPixelToTwips 
)

Definition at line 1757 of file BasicTableLayoutStrategy.cpp.

{
  for (PRInt32 i = 0; i < aNumAutoCols; i++) {
    if ((aAvailWidth <= 0) || (aDivisor <= 0)) {
      break;
    }
    // aDivisor represents the sum of unallocated space (diff between max and min values)
    float percent = ((float)aColInfo[i]->mMaxWidth - (float)aColInfo[i]->mMinWidth) / (float)aDivisor;
    aDivisor -= aColInfo[i]->mMaxWidth - aColInfo[i]->mMinWidth;

    nscoord addition = nsTableFrame::RoundToPixel(NSToCoordRound(((float)(aAvailWidth)) * percent), aPixelToTwips);
    // if its the last col, try to give what's left to it
    if ((i == aNumAutoCols - 1) && (addition < aAvailWidth)) {
      addition = aAvailWidth;
    }
    // don't let the addition exceed what is available to add
    addition = PR_MIN(addition, aAvailWidth);
    // don't go over the col max
    addition = PR_MIN(addition, aColInfo[i]->mMaxWidth - aColInfo[i]->mWidth);
    aColInfo[i]->mWidth += addition;
    aAvailWidth -= addition;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void AC_Sort ( ColInfo **  aColInfo,
PRInt32  aNumCols 
)

Definition at line 1813 of file BasicTableLayoutStrategy.cpp.

{
  // sort the cols based on the Weight 
  for (PRInt32 j = aNumCols - 1; j > 0; j--) {
    for (PRInt32 i = 0; i < j; i++) { 
      if (aColInfo[i]->mWeight < aColInfo[i+1]->mWeight) { // swap them
        ColInfo* save = aColInfo[i];
        aColInfo[i]   = aColInfo[i+1];
        aColInfo[i+1] = save;
      }
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void AC_Wrapup ( nsTableFrame aTableFrame,
PRInt32  aNumItems,
ColInfo **  aColInfo,
PRBool  aAbort = PR_FALSE 
)

Definition at line 1738 of file BasicTableLayoutStrategy.cpp.

{
  if (aColInfo) {
    for (PRInt32 i = 0; i < aNumItems; i++) {
      if (aColInfo[i]) {
        if (!aAbort) {
          aTableFrame->SetColumnWidth(aColInfo[i]->mIndex, aColInfo[i]->mWidth);
        }
        delete aColInfo[i];
      }
    }
    delete [] aColInfo;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool BCW_Wrapup ( const nsHTMLReflowState aReflowState,
BasicTableLayoutStrategy aStrategy,
nsTableFrame aTableFrame,
PRInt32 aAllocTypes 
)

Definition at line 177 of file BasicTableLayoutStrategy.cpp.

{
  if (aAllocTypes)
    delete [] aAllocTypes;
#ifdef DEBUG_TABLE_STRATEGY
  printf("BalanceColumnWidths ex \n"); aTableFrame->Dump(PR_FALSE, PR_TRUE, PR_FALSE);
#endif
#ifdef DEBUG_TABLE_REFLOW_TIMING
  nsTableFrame::DebugTimeMethod(nsTableFrame::eBalanceCols, *aTableFrame, (nsHTMLReflowState&)aReflowState, PR_FALSE);
#endif
  return PR_TRUE;
}

Here is the caller graph for this function:

PRBool CanAllocate ( PRInt32  aType,
PRInt32  aPrevType,
nsTableColFrame aColFrame 
)

Definition at line 76 of file BasicTableLayoutStrategy.cpp.

{
  switch(aType) {
  case PCT:
  case FIX:
  case DES_CON:
    return (WIDTH_NOT_SET == aPrevType);
  case FIX_ADJ:
    return (WIDTH_NOT_SET == aPrevType) || (FIX == aPrevType);
  default:
    NS_ASSERTION(PR_FALSE, "invalid call");
  }
  return PR_FALSE;
}

Here is the caller graph for this function:

nscoord GetColWidth ( nsTableColFrame aColFrame,
PRInt32  aWidthType 
)

Definition at line 393 of file BasicTableLayoutStrategy.cpp.

{
  switch(aWidthType) {
  case DES_CON:
    return aColFrame->GetDesWidth();
  case FIX:
  case FIX_ADJ:
    return aColFrame->GetWidth(aWidthType);
  case PCT:
    return aColFrame->GetPctWidth();
  default:
    NS_ASSERTION(PR_FALSE, "invalid call");
    return WIDTH_NOT_SET;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nscoord GetConstrainedWidth ( nsTableColFrame colFrame,
PRBool  aConsiderPct 
)

Definition at line 522 of file BasicTableLayoutStrategy.cpp.

{
  nscoord conWidth = WIDTH_NOT_SET;
  if (aConsiderPct) {
    conWidth = colFrame->GetPctWidth();
  }
  if (conWidth <= 0 ) {
    conWidth = colFrame->GetFixWidth();
  }
  return conWidth;
}

Here is the call graph for this function:

static PRInt32 GetSortedFrames ( nsTableFrame TableFrame,
PRInt32  colX,
PRInt32  numRows,
CellInfo cellInfo 
) [static]

This function finds all the rows which have a colspan greater than 1, and places those rows into the cellInfo array.

This array is then sorted so that the rows with the largest colspan are last.

Parameters:
TableFrame- The table we are working on
colX- The column in the table we are considering
numRows- The number of rows in the table
cellInfo- The array to store the result in.
Returns:
- The number of entries stored in the array

Definition at line 561 of file BasicTableLayoutStrategy.cpp.

{
  PRInt32 rowX, index = 0;
  for (rowX = 0; rowX < numRows; rowX++) {
    CellInfo *inf = &cellInfo[index];
    PRBool orig;
    inf->cellFrame =
      TableFrame->GetCellInfoAt(rowX, colX, &orig, &inf->colSpan);

    // If the cell is good we keep it.
    if(inf->cellFrame && orig && 1 != inf->colSpan) {
      index++;
    }
  }

  if(index>1) {
    NS_QuickSort(cellInfo, index, sizeof(cellInfo[0]), RowSortCB, 0);
  }

  return index;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 95 of file BasicTableLayoutStrategy.cpp.

{
  const nsStylePosition* position = aFrame->GetStylePosition();
  if (eStyleUnit_Percent == position->mWidth.GetUnit()) {
    float percent = position->mWidth.GetPercentValue();
    if (percent > 0.0f) {
      return PR_TRUE;
    }
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ResetPctValues ( nsTableFrame aTableFrame,
PRInt32  aNumCols 
)

Definition at line 194 of file BasicTableLayoutStrategy.cpp.

{
  // initialize the col percent and cell percent values to 0.
  PRInt32 colX;
  for (colX = 0; colX < aNumCols; colX++) { 
    nsTableColFrame* colFrame = aTableFrame->GetColFrame(colX); 
    if (colFrame) {
      colFrame->SetWidth(PCT, WIDTH_NOT_SET);
      colFrame->SetWidth(PCT_ADJ, WIDTH_NOT_SET);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int RowSortCB ( const void a,
const void b,
void  
) [static]

Definition at line 542 of file BasicTableLayoutStrategy.cpp.

{
  const CellInfo *aa = NS_STATIC_CAST(const CellInfo*,a);
  const CellInfo *bb = NS_STATIC_CAST(const CellInfo*,b);

  return aa->colSpan - bb->colSpan;
}

Here is the caller graph for this function:

nscoord WrapupAssignPctColumnWidths ( nsTableFrame aTableFrame,
const nsHTMLReflowState aReflowState,
nscoord  aValue 
) [inline]

Definition at line 1223 of file BasicTableLayoutStrategy.cpp.

{
  return aValue;
}

Here is the caller graph for this function: