NS_ASSERTION(aFrame, "No frame to search!"); if (!aFrame) return nsnull;
FindFrameWithContent(nsIFrame* aFrame, nsIContent* aContent){  nsIContent* frameContent;  PRBool      hasSameContent;     // See if the frame points to the same content object  aFrame->GetContent(&frameContent);  hasSameContent = (frameContent == aContent);  NS_IF_RELEASE(frameContent);  if (hasSameContent) {    nsIAtom*  frameType;    PRBool    isPlaceholder;    // See if it's a placeholder frame    aFrame->GetFrameType(&frameType);    isPlaceholder = (nsLayoutAtoms::placeholderFrame == frameType);    NS_IF_RELEASE(frameType);    if (isPlaceholder) {      // Ignore the placeholder and return the out-of-flow frame instead      return ((nsPlaceholderFrame*)aFrame)->GetOutOfFlowFrame();    }    // Also ignore frames associated with generated content    nsFrameState  frameState;        aFrame->GetFrameState(&frameState);    if ((frameState & NS_FRAME_GENERATED_CONTENT) == 0) {      return aFrame;    }  }  // Search for the frame in each child list that aFrame supports  nsIAtom* listName = nsnull;  PRInt32 listIndex = 0;  do {    nsIFrame* kid;    aFrame->FirstChild(listName, &kid);    while (nsnull != kid) {      nsIFrame* result = FindFrameWithContent(kid, aContent);      if (nsnull != result) {        NS_IF_RELEASE(listName);        return result;      }      kid->GetNextSibling(&kid);    }    NS_IF_RELEASE(listName);    aFrame->GetAdditionalChildListName(listIndex++, &listName);  } while(nsnull != listName);  return nsnull;}