PRUint32 index;
PRInt32 index;
nsTypedSelection::addTableCellRange(nsIDOMRange *aRange, PRBool *aDidAddRange){  if (!aDidAddRange)    return NS_ERROR_NULL_POINTER;  *aDidAddRange = PR_FALSE;  if (!mFrameSelection)    return NS_OK;  if (!aRange)    return NS_ERROR_NULL_POINTER;  if (!mRangeArray)    return NS_ERROR_FAILURE;  nsresult result;  nsCOMPtr<nsISupports> isupp = do_QueryInterface(aRange, &result);  if (NS_FAILED(result)) return result;  // Get if we are adding a cell selection and the row, col of cell if we are  PRInt32 newRow, newCol, tableMode;  result = getTableCellLocationFromRange(aRange, &tableMode, &newRow, &newCol);  if (NS_FAILED(result)) return result;    // If not adding a cell range, we are done here  if (tableMode != nsISelectionPrivate::TABLESELECTION_CELL)  {    mFrameSelection->mSelectingTableCellMode = tableMode;    // Don't fail if range isn't a selected cell, aDidAddRange tells caller if we didn't proceed    return NS_OK;  }    // Set frame selection mode only if not already set to a table mode  //  so we don't loose the select row and column flags (not detected by getTableCellLocation)  if (mFrameSelection->mSelectingTableCellMode == TABLESELECTION_NONE)    mFrameSelection->mSelectingTableCellMode = tableMode;  PRUint32 count;  result = mRangeArray->Count(&count);  if (NS_FAILED(result)) return result;  if (count > 0)  {    // Adding a cell range to existing list of cell ranges    PRUint32 index;    PRInt32 row, col;    // Insert range at appropriate location    for (index = 0; index < count; index++)    {      nsCOMPtr<nsISupports> element = dont_AddRef(mRangeArray->ElementAt(index));	    nsCOMPtr<nsIDOMRange> range = do_QueryInterface(element);      if (!range) return NS_ERROR_FAILURE;      PRInt32 selectionMode;      result = getTableCellLocationFromRange(range, &selectionMode, &row, &col);      if (NS_FAILED(result)) return result;      // Don't proceed if range not a table cell      if (selectionMode != nsISelectionPrivate::TABLESELECTION_CELL)        return NS_OK;      if (row > newRow ||          (row == newRow && col > newCol))      {        // Existing selected cell is after cell to add,        //  so insert at this index        result = mRangeArray->InsertElementAt(isupp, index);        *aDidAddRange = NS_SUCCEEDED(result);        return result;      }    }            }  // If here, we are adding a selected cell range   //   to end of range array or it's the first selected range   result = mRangeArray->AppendElement(isupp);  *aDidAddRange = NS_SUCCEEDED(result);  return result;}