if (!parent) return res; nsCOMPtr<nsIDOMNode> selNode = GetChildAt(parent, selOffset); if (!selNode) selNode = parent;
if (!iter) return NS_ERROR_NULL_POINTER; nsCOMPtr<nsIContent> cTbl = do_QueryInterface(tbl); nsCOMPtr<nsIContent> cBlock = do_QueryInterface(cellElement); res = iter->Init(cTbl); if (NS_FAILED(res)) return res;  res = iter->PositionAt(cBlock); if (NS_FAILED(res)) return res; nsCOMPtr<nsIDOMNode> node; nsCOMPtr<nsIContent> cNode; do { if (inIsShift) res = iter->Prev(); else res = iter->Next(); if (NS_FAILED(res)) break; res = iter->CurrentNode(getter_AddRefs(cNode)); if (NS_FAILED(res)) break; node = do_QueryInterface(cNode); if (nsHTMLEditUtils::IsTableCell(node) && (GetEnclosingTable(node) == tbl)) { res = CollapseSelectionToDeepestNonTableFirstChild(nsnull, node); if (NS_FAILED(res)) return res; *outHandled = PR_TRUE; return NS_OK; } } while (iter->IsDone() == NS_ENUMERATOR_FALSE);
NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled){  if (!outHandled) return NS_ERROR_NULL_POINTER;  *outHandled = PR_FALSE;  // find selection start  nsCOMPtr<nsIDOMSelection> selection;  nsresult res = GetSelection(getter_AddRefs(selection));  if (NS_FAILED(res)) return res;  nsCOMPtr<nsIDOMNode> parent;  PRInt32 selOffset;  res = GetStartNodeAndOffset(selection, &parent, &selOffset);  if (NS_FAILED(res)) return res;  if (!parent) return res;  nsCOMPtr<nsIDOMNode> selNode = GetChildAt(parent, selOffset);  if (!selNode) selNode = parent;    // is it in a table block of some kind?  nsCOMPtr<nsIDOMNode> block;  if (IsBlockNode(selNode)) block = selNode;  else block = GetBlockNodeParent(selNode);  if (!block) return res;    if (IsTableElement(block))  {    // find enclosing table    nsCOMPtr<nsIDOMNode> tbl;    if (IsTable(block)) tbl = block;    else tbl = GetEnclosingTable(block);    if (!tbl) return res;    // advance to next cell    // first create an iterator over the table    nsCOMPtr<nsIContentIterator> iter;    res = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,                                                NS_GET_IID(nsIContentIterator),                                                 getter_AddRefs(iter));    if (NS_FAILED(res)) return res;    if (!iter) return NS_ERROR_NULL_POINTER;    nsCOMPtr<nsIContent> cTbl = do_QueryInterface(tbl);    nsCOMPtr<nsIContent> cBlock = do_QueryInterface(block);    res = iter->Init(cTbl);    if (NS_FAILED(res)) return res;    // position iter at block    res = iter->PositionAt(cBlock);    if (NS_FAILED(res)) return res;    nsCOMPtr<nsIDOMNode> node;    nsCOMPtr<nsIContent> cNode;    do    {      if (inIsShift) res = iter->Prev();      else res = iter->Next();      if (NS_FAILED(res)) return res;      res = iter->CurrentNode(getter_AddRefs(cNode));      if (NS_FAILED(res)) return res;      node = do_QueryInterface(cNode);      if (IsTableCell(node) && (GetEnclosingTable(node) == tbl))      {        selection->Collapse(node, 0);        *outHandled = PR_TRUE;        return NS_OK;      }    } while (iter->IsDone() == NS_ENUMERATOR_FALSE);  }  return NS_OK;}