printf("SelectBlockOfCells -- NO START CELL!\n");
PRINTF("SelectBlockOfCells -- NO START CELL!\n");
nsSelection::SelectBlockOfCells(nsIContent *aEndCell){  if (!aEndCell) return NS_ERROR_NULL_POINTER;  mEndSelectedCell = aEndCell;  nsCOMPtr<nsIContent> startCell;  nsresult result = NS_OK;  if (mAppendStartSelectedCell)  {    // We are appending a new block#ifdef DEBUG_TABLE_SELECTIONprintf("SelectBlockOfCells -- using mAppendStartSelectedCell\n");#endif    startCell = mAppendStartSelectedCell;  }  else if (mStartSelectedCell)  {    startCell = mStartSelectedCell;#ifdef DEBUG_TABLE_SELECTIONprintf("SelectBlockOfCells -- using mStartSelectedCell\n");#endif  }  if (!startCell)  {#ifdef DEBUG_TABLE_SELECTIONprintf("SelectBlockOfCells -- NO START CELL!\n");#endif    return NS_OK;  }  // If new end cell is in a different table, do nothing  nsCOMPtr<nsIContent> table;  if (!IsInSameTable(startCell, aEndCell, getter_AddRefs(table)))    return NS_OK;  // Get starting and ending cells' location in the cellmap  PRInt32 startRowIndex, startColIndex, endRowIndex, endColIndex;  result = GetCellIndexes(startCell, startRowIndex, startColIndex);  if(NS_FAILED(result)) return result;  result = GetCellIndexes(aEndCell, endRowIndex, endColIndex);  if(NS_FAILED(result)) return result;  // Get TableLayout interface to access cell data based on cellmap location  // frames are not ref counted, so don't use an nsCOMPtr  nsITableLayout *tableLayoutObject = GetTableLayout(table);  if (!tableLayoutObject) return NS_ERROR_FAILURE;  PRInt32 curRowIndex, curColIndex;  if (!mAppendStartSelectedCell)  {    // Not appending - remove selected cells outside of new block limits    PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);    nsCOMPtr<nsIDOMNode> cellNode;    nsCOMPtr<nsIDOMRange> range;    result = GetFirstSelectedCellAndRange(getter_AddRefs(cellNode), getter_AddRefs(range));    if (NS_FAILED(result)) return result;    PRInt32 minRowIndex = PR_MIN(startRowIndex, endRowIndex);    PRInt32 maxRowIndex = PR_MAX(startRowIndex, endRowIndex);    PRInt32 minColIndex = PR_MIN(startColIndex, endColIndex);    PRInt32 maxColIndex = PR_MAX(startColIndex, endColIndex);    while (cellNode)    {      nsCOMPtr<nsIContent> childContent = do_QueryInterface(cellNode);      result = GetCellIndexes(childContent, curRowIndex, curColIndex);      if (NS_FAILED(result)) return result;#ifdef DEBUG_TABLE_SELECTIONif (!range)printf("SelectBlockOfCells -- range is null\n");#endif      if (range &&          (curRowIndex < minRowIndex || curRowIndex > maxRowIndex ||            curColIndex < minColIndex || curColIndex > maxColIndex))      {        mDomSelections[index]->RemoveRange(range);        // Since we've removed the range, decrement pointer to next range        mSelectedCellIndex--;      }          result = GetNextSelectedCellAndRange(getter_AddRefs(cellNode), getter_AddRefs(range));      if (NS_FAILED(result)) return result;    }  }  nsCOMPtr<nsIDOMElement> cellElement;  PRInt32 rowSpan, colSpan, actualRowSpan, actualColSpan;  PRBool  isSelected;  // Note that we select block in the direction of user's mouse dragging,  //  which means start cell may be after the end cell in either row or column  PRInt32 row = startRowIndex;  while(PR_TRUE)  {    PRInt32 col = startColIndex;    while(PR_TRUE)    {      result = tableLayoutObject->GetCellDataAt(row, col, *getter_AddRefs(cellElement),                                                curRowIndex, curColIndex, rowSpan, colSpan,                                                 actualRowSpan, actualColSpan, isSelected);      if (NS_FAILED(result)) return result;      NS_ASSERTION(actualColSpan, "!actualColSpan is 0!");      // Skip cells that are spanned from previous locations or are already selected      if (!isSelected && cellElement && row == curRowIndex && col == curColIndex)      {        result = SelectCellElement(cellElement);        if (NS_FAILED(result)) return result;      }      // Done when we reach end column      if (col == endColIndex) break;      if (startColIndex < endColIndex)        col ++;      else        col--;    };    if (row == endRowIndex) break;    if (startRowIndex < endRowIndex)      row++;    else      row--;  };  return result;}