nsLineLayout::FindNextText(nsIPresContext* aPresContext, nsIFrame* aFrame)
nsLineLayout::FindNextText(nsPresContext* aPresContext, nsIFrame* aFrame)
nsLineLayout::FindNextText(nsIPresContext* aPresContext, nsIFrame* aFrame){  // Grovel through the frame hierarchy to find a text frame that is  // "adjacent" to aFrame.  // So this is kind of funky. During reflow, overflow frames will  // have their parent pointers set up lazily. We assume that, on  // entry, aFrame has it's parent pointer set correctly (as do all of  // its ancestors). Starting from that, we need to make sure that as  // we traverse through frames trying to find the next text frame, we  // leave the frames with their parent pointers set correctly, so the  // *next* time we come through here, we're good to go.  // Build a path from the enclosing block frame down to aFrame. We'll  // use this to walk the frame tree. (XXXwaterson if I was clever, I  // wouldn't need to build this up before hand, and could incorporate  // this logic into the walking code directly.)  nsAutoVoidArray stack;  for (;;) {    stack.InsertElementAt(aFrame, 0);    aFrame = aFrame->GetParent();    NS_ASSERTION(aFrame, "wow, no block frame found");    if (! aFrame)      break;    if (NS_STYLE_DISPLAY_INLINE != aFrame->GetStyleDisplay()->mDisplay)      break;  }  // Using the path we've built up, walk the frame tree looking for  // the text frame that follows aFrame.  PRInt32 count;  while ((count = stack.Count()) != 0) {    PRInt32 lastIndex = count - 1;    nsIFrame* top = NS_STATIC_CAST(nsIFrame*, stack.ElementAt(lastIndex));    // If this is a frame that'll break a word, then bail.    PRBool canContinue;    top->CanContinueTextRun(canContinue);    if (! canContinue)      return nsnull;    // Advance to top's next sibling    nsIFrame* next = top->GetNextSibling();    if (! next) {      // No more siblings. Pop the top element to walk back up the      // frame tree.      stack.RemoveElementAt(lastIndex);      continue;    }    // We know top's parent is good, but next's might not be. So let's    // set it to be sure.    next->SetParent(top->GetParent());    // Save next at the top of the stack...    stack.ReplaceElementAt(next, lastIndex);    // ...and prowl down to next's deepest child. We'll need to check    // for potential run-busters "on the way down", too.    for (;;) {      next->CanContinueTextRun(canContinue);      if (! canContinue)        return nsnull;      nsIFrame* child = next->GetFirstChild(nsnull);      if (! child)        break;      stack.AppendElement(child);      next = child;    }    // Ignore continuing frames    if (HasPrevInFlow(next))      continue;    // If this is a text frame, return it.    if (nsLayoutAtoms::textFrame == next->GetType())      return next;  }  // If we get here, then there are no more text frames in this block.  return nsnull;}