nsCOMPtr<nsIDOMSelection>selection;
nsCOMPtr<nsISelection>selection;
nsHTMLEditor::GetParentBlockTags(nsStringArray *aTagList, PRBool aGetLists){  if (!aTagList) { return NS_ERROR_NULL_POINTER; }  nsresult res;  nsCOMPtr<nsIDOMSelection>selection;  res = GetSelection(getter_AddRefs(selection));  if (NS_FAILED(res)) return res;  if (!selection) return NS_ERROR_NULL_POINTER;  // Find out if the selection is collapsed:  PRBool isCollapsed;  res = selection->GetIsCollapsed(&isCollapsed);  if (NS_FAILED(res)) return res;  if (isCollapsed)  {    nsCOMPtr<nsIDOMNode> node, blockParent;    PRInt32 offset;      res = GetStartNodeAndOffset(selection, &node, &offset);    if (!node) res = NS_ERROR_FAILURE;    if (NS_FAILED(res)) return res;      nsCOMPtr<nsIDOMElement> blockParentElem;    if (aGetLists)    {      // Get the "ol", "ul", or "dl" parent element      res = GetElementOrParentByTagName("list", node, getter_AddRefs(blockParentElem));      if (NS_FAILED(res)) return res;    }     else     {      if (IsBlockNode(node)) blockParent = node;      else blockParent = GetBlockNodeParent(node);      blockParentElem = do_QueryInterface(blockParent);    }    if (blockParentElem)    {      nsAutoString blockParentTag;      blockParentElem->GetTagName(blockParentTag);      aTagList->AppendString(blockParentTag);    }        return res;  }  // else non-collapsed selection  nsCOMPtr<nsIEnumerator> enumerator;  res = selection->GetEnumerator(getter_AddRefs(enumerator));  if (NS_FAILED(res)) return res;  if (!enumerator) return NS_ERROR_NULL_POINTER;  enumerator->First();   nsCOMPtr<nsISupports> currentItem;  res = enumerator->CurrentItem(getter_AddRefs(currentItem));  if (NS_FAILED(res)) return res;  //XXX: should be while loop?  if (currentItem)  {    nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );    // scan the range for all the independent block content blockSections    // and get the block parent of each    nsISupportsArray *blockSections;    res = NS_NewISupportsArray(&blockSections);    if (NS_FAILED(res)) return res;    if (!blockSections) return NS_ERROR_NULL_POINTER;    res = GetBlockSectionsForRange(range, blockSections);    if (NS_SUCCEEDED(res))    {      nsIDOMRange *subRange;      subRange = (nsIDOMRange *)(blockSections->ElementAt(0));      while (subRange)      {        nsCOMPtr<nsIDOMNode>startParent;        res = subRange->GetStartParent(getter_AddRefs(startParent));        if (NS_SUCCEEDED(res) && startParent)         {          nsCOMPtr<nsIDOMElement> blockParent;          if (aGetLists)          {            // Get the "ol", "ul", or "dl" parent element            res = GetElementOrParentByTagName("list", startParent, getter_AddRefs(blockParent));          } else {            res = GetBlockParent(startParent, getter_AddRefs(blockParent));          }          if (NS_SUCCEEDED(res) && blockParent)          {            nsAutoString blockParentTag;            blockParent->GetTagName(blockParentTag);            PRBool isRoot;            IsRootTag(blockParentTag, isRoot);            if ((PR_FALSE==isRoot) && (-1==aTagList->IndexOf(blockParentTag))) {              aTagList->AppendString(blockParentTag);            }          }        }        NS_RELEASE(subRange);        if (NS_FAILED(res))          break;  // don't return here, need to release blockSections        blockSections->RemoveElementAt(0);        subRange = (nsIDOMRange *)(blockSections->ElementAt(0));      }    }    NS_RELEASE(blockSections);  }  return res;}