result = genericiter->Init(aPresShell,aContent);
nsCOMPtr<nsIPresShell> presShell; result = aPresContext->GetShell(getter_AddRefs(presShell)); if (NS_FAILED(result) && presShell) presShell = 0; #ifdef USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE nsCOMPtr<nsIGeneratedContentIterator> genericiter = do_QueryInterface(iter); if (genericiter && presShell) result = genericiter->Init(presShell,aRange); else #endif result = iter->Init(aRange);      nsCOMPtr<nsIContent> content; nsIFrame *frame;  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 = mFrameSelection->GetTracker()->GetPrimaryFrameFor(content, &frame); if (NS_SUCCEEDED(result) && frame) frame->SetSelected(aPresContext, aRange,aFlags,eSpreadDown); }  result = iter->First(); while (NS_SUCCEEDED(result) && NS_ENUMERATOR_FALSE == iter->IsDone()) { result = iter->CurrentNode(getter_AddRefs(content)); if (NS_FAILED(result) || !content) return result; selectFrames(aPresContext, inneriter, content, aRange, presShell,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 = mFrameSelection->GetTracker()->GetPrimaryFrameFor(content, &frame); if (NS_SUCCEEDED(result) && frame) frame->SetSelected(aPresContext, aRange,aFlags,eSpreadDown); } }
nsDOMSelection::selectFrames(nsIPresContext* aPresContext,                             nsIContentIterator *aInnerIter,                             nsIContent *aContent,                             nsIDOMRange *aRange,                             nsIPresShell *aPresShell,                             PRBool aFlags){  if (!mFrameSelection)    return NS_OK;//nothing to do  nsresult result;  if (!aInnerIter)    return NS_ERROR_NULL_POINTER;#ifdef USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE  nsCOMPtr<nsIGeneratedContentIterator> genericiter = do_QueryInterface(aInnerIter);  if (genericiter && aPresShell)  {    result = genericiter->Init(aPresShell,aContent);  }  else#endif // USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE    result = aInnerIter->Init(aContent);  nsIFrame *frame;  if (NS_SUCCEEDED(result))  {    // First select frame of content passed in    result = mFrameSelection->GetTracker()->GetPrimaryFrameFor(aContent, &frame);    if (NS_SUCCEEDED(result) && frame)      //NOTE: aRange and eSpreadDown are now IGNORED. Selected state is set only for given frame      frame->SetSelected(aPresContext, aRange, aFlags, eSpreadDown);        // Now iterated through the child frames and set them    nsCOMPtr<nsIContent> innercontent;    while (NS_ENUMERATOR_FALSE == aInnerIter->IsDone())    {      result = aInnerIter->CurrentNode(getter_AddRefs(innercontent));      if (NS_SUCCEEDED(result) && innercontent)      {        result = mFrameSelection->GetTracker()->GetPrimaryFrameFor(innercontent, &frame);        if (NS_SUCCEEDED(result) && frame)          //NOTE: aRange and eSpreadDown are now IGNORED. Selected state is set only for given frame          frame->SetSelected(aPresContext, aRange,aFlags,eSpreadDown);//spread from here to hit all frames in flow      }      result = aInnerIter->Next();      if (NS_FAILED(result))        return result;    }#if 0    result = mFrameSelection->GetTracker()->GetPrimaryFrameFor(content, &frame);    if (NS_SUCCEEDED(result) && frame)      frame->SetSelected(aRange,aFlags,eSpreadDown);//spread from here to hit all frames in flow#endif    return NS_OK;  }  return NS_ERROR_FAILURE;}