NS_ASSERTION(aPresContext, "Pointer is null!"); NS_ASSERTION(aParentFrame, "Pointer is null!");
static nsresult FindSelectionBounds(nsIPresContext* aPresContext,                                    nsIRenderingContext& aRC,                                    nsIFrame *      aParentFrame,                                    nsRect&         aRect,                                    nsIFrame *&     aStartFrame,                                    nsRect&         aStartRect,                                    nsIFrame *&     aEndFrame,                                    nsRect&         aEndRect){  nsIFrame * child;  aParentFrame->FirstChild(aPresContext, nsnull, &child);  nsRect rect;  aParentFrame->GetRect(rect);  aRect.x += rect.x;  aRect.y += rect.y;  while (child != nsnull) {    nsFrameState state;    child->GetFrameState(&state);    // only leaf frames have this bit flipped    // then check the hard way    PRBool isSelected = (state & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT;    if (isSelected) {      if (NS_FAILED(child->IsVisibleForPainting(aPresContext, aRC, PR_TRUE, &isSelected))) {        return NS_ERROR_FAILURE;      }    }    if (isSelected) {      nsRect r;      child->GetRect(r);      if (aStartFrame == nsnull) {        aStartFrame = child;        aStartRect.SetRect(aRect.x + r.x, aRect.y + r.y, r.width, r.height);      } else {        child->GetRect(r);        aEndFrame = child;        aEndRect.SetRect(aRect.x + r.x, aRect.y + r.y, r.width, r.height);      }    }    FindSelectionBounds(aPresContext, aRC, child, aRect, aStartFrame, aStartRect, aEndFrame, aEndRect);    child->GetNextSibling(&child);  }  aRect.x -= rect.x;  aRect.y -= rect.y;  return NS_OK;}