res = iter->CurrentNode(getter_AddRefs(content)); if (NS_FAILED(res)) return res; node = do_QueryInterface(content); if (!node) return NS_ERROR_FAILURE; isupports = do_QueryInterface(node); arrayOfNodes->AppendElement(isupports); res = iter->Next(); if (NS_FAILED(res)) return res;
while (NS_ENUMERATOR_FALSE == iter->IsDone()) { res = iter->CurrentNode(getter_AddRefs(content)); if (NS_FAILED(res)) return res; node = do_QueryInterface(content); if (!node) return NS_ERROR_FAILURE; if (IsEditable(node)) { isupports = do_QueryInterface(node); arrayOfNodes->AppendElement(isupports); } iter->Next(); }      PRUint32 listCount; PRUint32 j; arrayOfNodes->Count(&listCount); for (j = 0; j < listCount; j++) { isupports = (dont_AddRef)(arrayOfNodes->ElementAt(0)); node = do_QueryInterface(isupports); res = RelativeFontChangeOnNode(aSizeChange, node); if (NS_FAILED(res)) return res; arrayOfNodes->RemoveElementAt(0); }
nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange){  // Can only change font size by + or - 1  if ( !( (aSizeChange==1) || (aSizeChange==-1) ) )    return NS_ERROR_ILLEGAL_VALUE;    ForceCompositionEnd();  // wrap with txn batching, rules sniffing, and selection preservation code  nsAutoEditBatch batchIt(this);  nsAutoRules beginRulesSniffing(this, kOpSetTextProperty, nsIEditor::eNext, PR_TRUE);  // Get the selection   nsCOMPtr<nsIDOMSelection>selection;  nsresult res = GetSelection(getter_AddRefs(selection));  if (NS_FAILED(res)) return res;  if (!selection) return NS_ERROR_FAILURE;    // Is the selection collapsed?  PRBool bCollapsed;  res = selection->GetIsCollapsed(&bCollapsed);  if (NS_FAILED(res)) return res;    // if it's collapsed dont do anything.    // MOOSE: We should probably have typing state for this like  // we do for other things.  if (bCollapsed)  {    return NS_OK;  }    // get selection range enumerator  nsCOMPtr<nsIEnumerator> enumerator;  res = selection->GetEnumerator(getter_AddRefs(enumerator));  if (NS_FAILED(res)) return res;  if (!enumerator)    return NS_ERROR_FAILURE;  // loop thru the ranges in the selection  enumerator->First();   nsCOMPtr<nsISupports> currentItem;  while ((NS_ENUMERATOR_FALSE == enumerator->IsDone()))  {    res = enumerator->CurrentItem(getter_AddRefs(currentItem));    if (NS_FAILED(res)) return res;    if (!currentItem)   return NS_ERROR_FAILURE;        nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );    // check for easy case: both range endpoints in same text node    nsCOMPtr<nsIDOMNode> startNode, endNode;    res = range->GetStartParent(getter_AddRefs(startNode));    if (NS_FAILED(res)) return res;    res = range->GetEndParent(getter_AddRefs(endNode));    if (NS_FAILED(res)) return res;    if ((startNode == endNode) && IsTextNode(startNode))    {      PRInt32 startOffset, endOffset;      range->GetStartOffset(&startOffset);      range->GetEndOffset(&endOffset);      nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(startNode);      res = RelativeFontChangeOnTextNode(aSizeChange, nodeAsText, startOffset, endOffset);      if (NS_FAILED(res)) return res;    }    else    {      // not the easy case.  range not contained in single text node.       // there are up to three phases here.  There are all the nodes      // reported by the subtree iterator to be processed.  And there      // are potentially a starting textnode and an ending textnode      // which are only partially contained by the range.            // lets handle the nodes reported by the iterator.  These nodes      // are entirely contained in the selection range.  We build up      // a list of them (since doing operations on the document during      // iteration would perturb the iterator).      nsCOMPtr<nsIContentIterator> iter;      res = nsComponentManager::CreateInstance(kSubtreeIteratorCID, nsnull,                                                NS_GET_IID(nsIContentIterator),                                                 getter_AddRefs(iter));      if (NS_FAILED(res)) return res;      if (!iter)          return NS_ERROR_FAILURE;      nsCOMPtr<nsISupportsArray> arrayOfNodes;      nsCOMPtr<nsIContent> content;      nsCOMPtr<nsIDOMNode> node;      nsCOMPtr<nsISupports> isupports;            // make a array      res = NS_NewISupportsArray(getter_AddRefs(arrayOfNodes));      if (NS_FAILED(res)) return res;            // iterate range and build up array      iter->Init(range);      while (NS_ENUMERATOR_FALSE == iter->IsDone())      {        res = iter->CurrentNode(getter_AddRefs(content));        if (NS_FAILED(res)) return res;        node = do_QueryInterface(content);        if (!node) return NS_ERROR_FAILURE;        isupports = do_QueryInterface(node);        arrayOfNodes->AppendElement(isupports);        res = iter->Next();        if (NS_FAILED(res)) return res;      }            // now that we have the list, do the font size change on each node      PRUint32 listCount;      PRUint32 j;      arrayOfNodes->Count(&listCount);      for (j = 0; j < listCount; j++)      {        isupports = (dont_AddRef)(arrayOfNodes->ElementAt(0));        node = do_QueryInterface(isupports);        res = RelativeFontChangeOnNode(aSizeChange, node);        if (NS_FAILED(res)) return res;        arrayOfNodes->RemoveElementAt(0);      }            // now check the start and end parents of the range to see if they need to       // be seperately handled (they do if they are text nodes, due to how the      // subtree iterator works - it will not have reported them).      if (IsTextNode(startNode))      {        nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(startNode);        PRInt32 startOffset;        PRUint32 textLen;        range->GetStartOffset(&startOffset);        nodeAsText->GetLength(&textLen);        res = RelativeFontChangeOnTextNode(aSizeChange, nodeAsText, startOffset, textLen);        if (NS_FAILED(res)) return res;      }      if (IsTextNode(endNode))      {        nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(endNode);        PRInt32 endOffset;        range->GetEndOffset(&endOffset);        res = RelativeFontChangeOnTextNode(aSizeChange, nodeAsText, 0, endOffset);        if (NS_FAILED(res)) return res;      }    }    enumerator->Next();  }    return res;  }