if (parent.get() == parentNode && offset == aContentOffset)
if (parent == parentNode && offset == aContentOffset)
nsRangeList::HandleTableSelection(nsIContent *aParentContent, PRInt32 aContentOffset, PRUint32 aTarget){  if (!aParentContent) return NS_ERROR_NULL_POINTER;  if (mSelectingTableCells && (aTarget & TABLESELECTION_TABLE))  {    // We were selecting cells and user drags mouse in table border or inbetween cells,    //  just do nothing      return NS_OK;  }  nsCOMPtr<nsIDOMNode> parentNode = do_QueryInterface(aParentContent);  if (!parentNode)  return NS_ERROR_FAILURE;  nsCOMPtr<nsIContent> childContent;  nsresult result = aParentContent->ChildAt(aContentOffset, *getter_AddRefs(childContent));  if (NS_FAILED(result)) return result;  if (!childContent)  return NS_ERROR_FAILURE;  nsCOMPtr<nsIDOMNode> childNode = do_QueryInterface(childContent);  if (!childNode)  return NS_ERROR_FAILURE;  // Stack-class to wrap all table selection changes in   //  BeginBatchChanges() / EndBatchChanges()  nsSelectionBatcher selectionBatcher(mDomSelections[SELECTION_NORMAL]);  if (mSelectingTableCells)  {#ifdef DEBUG_TABLE    printf("HandleTableSelection: dragging mouse\n");#endif    if (aTarget == TABLESELECTION_CELL)    {      // If dragging in the same cell as last event, do nothing      if (mEndSelectedCell == childContent)        return NS_OK;#ifdef DEBUG_TABLE      printf("HandleTableSelection: Dragged into a new cell\n");#endif      // Reselect block of cells to new end location      mEndSelectedCell = childContent;      return SelectBlockOfCells(mStartSelectedCell, mEndSelectedCell);    }  }  else   {    // Not dragging  -- mouse event is a click#ifdef DEBUG_TABLE      printf("HandleTableSelection: CLICK event\n");#endif    if (aTarget == TABLESELECTION_TABLE)    {      //TODO: Currently selects when clicked between cells,      //  should we restrict to only around border?      //  *** How do we get location data for cell and click?      mSelectingTableCells = PR_FALSE;      mStartSelectedCell = nsnull;      mEndSelectedCell = nsnull;#ifdef DEBUG_TABLE      printf("HandleTableSelection: Selecting Table\n");#endif      // Select the table            mDomSelections[SELECTION_NORMAL]->ClearSelection();      return CreateAndAddRange(parentNode, aContentOffset);    }    // We are already selecting cells    // Check if cell clicked on is already selected      PRInt32 rangeCount;    result = mDomSelections[SELECTION_NORMAL]->GetRangeCount(&rangeCount);    if (NS_FAILED(result)) return result;    nsCOMPtr<nsIDOMNode> parent;    nsCOMPtr<nsIDOMRange> range;    PRInt32 offset;    for( PRInt32 i = 0; i < rangeCount; i++)    {      result = mDomSelections[SELECTION_NORMAL]->GetRangeAt(i, getter_AddRefs(range));      if (NS_FAILED(result)) return result;      if (!range) return NS_ERROR_NULL_POINTER;      result = range->GetStartParent(getter_AddRefs(parent));      if (NS_FAILED(result)) return result;      if (!parent) return NS_ERROR_NULL_POINTER;      range->GetStartOffset(&offset);      if (parent.get() == parentNode && offset == aContentOffset)      {        // Cell is already selected        if (rangeCount == 1)        {#ifdef DEBUG_TABLE          printf("HandleTableSelection: Unselecting single selected cell\n");#endif          // This was the only cell selected.          // Collapse to "normal" selection inside the cell          mSelectingTableCells = PR_FALSE;          mStartSelectedCell = nsnull;          mEndSelectedCell = nsnull;          //TODO: We need a "Collapse to just before deepest child" routine          // Even better, should we collapse to just after the LAST deepest child          //  (i.e., at the end of the cell's contents)?          return mDomSelections[SELECTION_NORMAL]->Collapse(childNode, 0);        }#ifdef DEBUG_TABLE        printf("HandleTableSelection: Removing cell from multi-cell selection\n");#endif        //TODO: Should we try to reassign to a different existing cell?        //mStartSelectedCell = nsnull;        //mEndSelectedCell = nsnull;        // Other cells are selected:        // Deselect cell by removing its range from selection        return mDomSelections[SELECTION_NORMAL]->RemoveRange(range);      }    }    // If new cell in a different table is selected, clear existing selection    // Content of the last selection range's start parent    nsCOMPtr<nsIContent> lastRangeContent = do_QueryInterface(parent);    if (!lastRangeContent) return NS_ERROR_FAILURE;    if (!IsInSameTable(lastRangeContent, childContent, nsnull))      mDomSelections[SELECTION_NORMAL]->ClearSelection();#ifdef DEBUG_TABLE    printf("HandleTableSelection: Adding new selected cell range\n");#endif    // Append a new selection range that surrounds the cell    // It would be nice to make the order of ranges     //  map to the order of cells in table,    //  but AddRange doesn't allow that    result = CreateAndAddRange(parentNode, aContentOffset);    if (NS_SUCCEEDED(result))    {      mSelectingTableCells = PR_TRUE;      mStartSelectedCell = childContent;      mEndSelectedCell = childContent;    }  }  return result;}