result = iter->First(); while (NS_SUCCEEDED(result) && NS_COMFALSE == iter->IsDone()) { result = iter->CurrentNode(getter_AddRefs(content)); if (NS_FAILED(result) || !content) return result; selectFrames(inneriter, content, aRange, aFlags); result = iter->Next(); }  if (FetchEndParent(aRange) != FetchStartParent(aRange)) { content = do_QueryInterface(FetchEndParent(aRange), &result); if (NS_FAILED(result) || !content) return result; canContainChildren = PR_FALSE; result = content->CanContainChildren(canContainChildren); if (NS_SUCCEEDED(result) && !canContainChildren) { result = mRangeList->GetTracker()->GetPrimaryFrameFor(content, &frame); if (NS_SUCCEEDED(result) && frame) frame->SetSelected(aRange,aFlags,eSpreadDown); } }
nsDOMSelection::selectFrames(nsIDOMRange *aRange, PRBool aFlags){  if (!aRange)     return NS_ERROR_NULL_POINTER;  nsCOMPtr<nsIContentIterator> iter;  nsCOMPtr<nsIContentIterator> inneriter;  nsresult result = nsComponentManager::CreateInstance(kCSubtreeIteratorCID, nsnull,                                              nsIContentIterator::GetIID(),                                               getter_AddRefs(iter));  if (NS_FAILED(result))    return result;  result = nsComponentManager::CreateInstance(kCContentIteratorCID, nsnull,                                              nsIContentIterator::GetIID(),                                               getter_AddRefs(inneriter));  if ((NS_SUCCEEDED(result)) && iter && inneriter)  {    iter->Init(aRange);    // loop through the content iterator for each content node    // for each text node:    // get the frame for the content, and from it the style context    // ask the style context about the property    nsCOMPtr<nsIContent> content;    nsIFrame *frame;//we must call first one explicitly    content = do_QueryInterface(FetchStartParent(aRange), &result);    if (NS_FAILED(result) || !content)      return result;    PRBool canContainChildren = PR_FALSE;    result = content->CanContainChildren(canContainChildren);    if (NS_SUCCEEDED(result) && !canContainChildren)    {      result = mRangeList->GetTracker()->GetPrimaryFrameFor(content, &frame);      if (NS_SUCCEEDED(result) && frame)        frame->SetSelected(aRange,aFlags,eSpreadDown);//spread from here to hit all frames in flow    }//end start content    result = iter->First();    while (NS_SUCCEEDED(result) && NS_COMFALSE == iter->IsDone())    {      result = iter->CurrentNode(getter_AddRefs(content));      if (NS_FAILED(result) || !content)        return result;      selectFrames(inneriter, content, aRange, aFlags);      result = iter->Next();    }//we must now do the last one  if it is not the same as the first    if (FetchEndParent(aRange) != FetchStartParent(aRange))    {      content = do_QueryInterface(FetchEndParent(aRange), &result);      if (NS_FAILED(result) || !content)        return result;      canContainChildren = PR_FALSE;      result = content->CanContainChildren(canContainChildren);      if (NS_SUCCEEDED(result) && !canContainChildren)      {        result = mRangeList->GetTracker()->GetPrimaryFrameFor(content, &frame);        if (NS_SUCCEEDED(result) && frame)           frame->SetSelected(aRange,aFlags,eSpreadDown);//spread from here to hit all frames in flow      }    }//end end parent  }  return result;}