nsresult res = NS_OK; nsCOMPtr<nsIContent> content = do_QueryInterface(aElement); if (content)
res = NS_OK; nsAutoString tagName; aElement->GetNodeName(tagName); tagName.ToLowerCase(); if (tagName == "td" || tagName == "tr" || tagName == "th" || tagName == "td" || tagName == "caption")
nsHTMLEditor::SetCaretInTableCell(nsIDOMElement* aElement){  PRBool caretIsSet = PR_FALSE;  if (aElement && IsElementInBody(aElement))  {    nsresult res = NS_OK;    nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);    if (content)    {      nsCOMPtr<nsIAtom> atom;      content->GetTag(*getter_AddRefs(atom));      if (atom.get() == nsIEditProperty::table ||          atom.get() == nsIEditProperty::tbody ||          atom.get() == nsIEditProperty::thead ||          atom.get() == nsIEditProperty::tfoot ||          atom.get() == nsIEditProperty::caption ||          atom.get() == nsIEditProperty::tr ||          atom.get() == nsIEditProperty::td )      {        nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement);        nsCOMPtr<nsIDOMNode> parent;        // This MUST succeed if IsElementInBody was TRUE        node->GetParentNode(getter_AddRefs(parent));        nsCOMPtr<nsIDOMNode>firstChild;        // Find deepest child        PRBool hasChild;        while (NS_SUCCEEDED(node->HasChildNodes(&hasChild)) && hasChild)        {          if (NS_SUCCEEDED(node->GetFirstChild(getter_AddRefs(firstChild))))          {            parent = node;            node = firstChild;          }        }# if 0 // I've ifdef'd this out because it isn't finished and I'm not sure what the intent is.        PRInt32 offset = 0;        nsCOMPtr<nsIDOMNode>lastChild;        res = parent->GetLastChild(getter_AddRefs(lastChild));        if (NS_SUCCEEDED(res) && lastChild && node != lastChild)        {          if (node == lastChild)          {            // Check if node is text and has more than just a &nbsp            nsCOMPtr<nsIDOMCharacterData>textNode = do_QueryInterface(node);            nsAutoString text;            PRUnichar nbspStr[2] = {nbsp, 0};            if (textNode && textNode->GetData(text))            {              // Set selection relative to the text node              parent = node;              PRInt32 len = text.Length();              if (len > 1 || text != nbspStr)              {                offset = len;              }            }          } else {            // We have > 1 node, so set to end of content          }        }#endif        // Set selection at beginning of deepest node        nsCOMPtr<nsIDOMSelection> selection;        res = GetSelection(getter_AddRefs(selection));        if (NS_SUCCEEDED(res) && selection && firstChild)        {          res = selection->Collapse(firstChild, 0);          if (NS_SUCCEEDED(res))            caretIsSet = PR_TRUE;        }      }    }  }  return caretIsSet;}            