aPos->mContentOffsetEnd = aPos->mContentOffset;
nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos) {  if (!aPos || !mContent)    return NS_ERROR_NULL_POINTER;  if (aPos->mStartOffset < 0 )    aPos->mStartOffset = mContentLength + mContentOffset;  if (aPos->mStartOffset < mContentOffset){    aPos->mStartOffset = mContentOffset;  }  if (aPos->mStartOffset > (mContentOffset + mContentLength)){    nsIFrame *nextInFlow;    nextInFlow = GetNextInFlow();    if (!nextInFlow){      NS_ASSERTION(PR_FALSE,"nsTextFrame::PeekOffset no more flow \n");      return NS_ERROR_INVALID_ARG;    }    return nextInFlow->PeekOffset(aPos);  }   if (aPos->mAmount == eSelectLine || aPos->mAmount == eSelectBeginLine       || aPos->mAmount == eSelectEndLine)  {      return nsFrame::PeekOffset(aPos);  }  nsAutoTextBuffer paintBuffer;  nsAutoIndexBuffer indexBuffer;  nsresult rv = indexBuffer.GrowTo(mContentLength + 1);  if (NS_FAILED(rv)) {    return rv;  }  PRInt32* ip = indexBuffer.mBuffer;  PRInt32 textLength;  nsresult result(NS_ERROR_FAILURE);  aPos->mResultContent = mContent;//do this right off  switch (aPos->mAmount){    case eSelectNoAmount:    {      // Transform text from content into renderable form      nsIDocument* doc;      result = mContent->GetDocument(doc);      if (NS_FAILED(result) || !doc) {        return result;      }      nsCOMPtr<nsILineBreaker> lb;      doc->GetLineBreaker(getter_AddRefs(lb));      NS_RELEASE(doc);      nsTextTransformer tx(lb, nsnull);      PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength);      if (textLength)//if no renderable length, you cant park here.      {        aPos->mContentOffset = aPos->mStartOffset;        result = NS_OK;      }      else      {        aPos->mAmount = eSelectDir;//go to "next" or previous frame based on direction not THIS frame        result = nsFrame::PeekOffset(aPos);      }    }    break;    case eSelectCharacter:    {      // Transform text from content into renderable form      nsIDocument* doc;      result = mContent->GetDocument(doc);      if (NS_FAILED(result) || !doc) {        return result;      }      nsCOMPtr<nsILineBreaker> lb;      doc->GetLineBreaker(getter_AddRefs(lb));      NS_RELEASE(doc);      nsTextTransformer tx(lb, nsnull);      PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength);      nsIFrame *frameUsed = nsnull;      PRInt32 start;      PRBool found = PR_TRUE;      if (aPos->mDirection == eDirPrevious){        aPos->mContentOffset = 0;        PRInt32 i;        for (i = aPos->mStartOffset -1 - mContentOffset; i >=0;  i--){          if (ip[i] < ip[aPos->mStartOffset - mContentOffset]){            aPos->mContentOffset = i + mContentOffset;            break;          }        }        if (i <0){          found = PR_FALSE;          frameUsed = GetPrevInFlow();          start = mContentOffset;        }      }      else if (aPos->mDirection == eDirNext){        PRInt32 i;        aPos->mContentOffset = mContentLength;        for (i = aPos->mStartOffset +1 - mContentOffset; i <= mContentLength;  i++){          if (ip[i] > ip[aPos->mStartOffset - mContentOffset]){            aPos->mContentOffset = i + mContentOffset;            break;          }        }/*      if (aStartOffset == 0 && (mState & TEXT_SKIP_LEADING_WS))        i--; //back up because we just skipped over some white space. why skip over the char also?*/        if (i > mContentLength){          found = PR_FALSE;          frameUsed = GetNextInFlow();          start = mContentOffset + mContentLength;        }      }      if (!found)        result = nsFrame::PeekOffset(aPos);      else         aPos->mResultContent = mContent;    }    break;    case eSelectWord:    {      // Transform text from content into renderable form      nsIDocument* doc;      result = mContent->GetDocument(doc);      if (NS_FAILED(result) || !doc) {        return result;      }      nsCOMPtr<nsILineBreaker> lb;      doc->GetLineBreaker(getter_AddRefs(lb));      nsCOMPtr<nsIWordBreaker> wb;      doc->GetWordBreaker(getter_AddRefs(wb));      NS_RELEASE(doc);      nsTextTransformer tx(lb, wb);      PrepareUnicodeText(tx, &indexBuffer, &paintBuffer, &textLength);      nsIFrame *frameUsed = nsnull;      PRBool keepSearching; //if you run out of chars before you hit the end of word, maybe next frame has more text to select?      PRInt32 start;      PRBool found = PR_FALSE;      PRBool isWhitespace;      PRInt32 wordLen, contentLen;      if (aPos->mDirection == eDirPrevious){        keepSearching = PR_TRUE;        tx.Init(this, mContent, aPos->mStartOffset);        if (tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace, PR_FALSE) &&          (aPos->mStartOffset - contentLen >= mContentOffset) ){          if ((aPos->mEatingWS && !isWhitespace) || !aPos->mEatingWS){            aPos->mContentOffset = aPos->mStartOffset - contentLen;            //check for whitespace next.            if (isWhitespace && aPos->mContentOffset <= mContentOffset)            {              keepSearching = PR_FALSE;//reached the beginning of a word              aPos->mEatingWS = PR_FALSE;//if no real word then            }            else{              while (isWhitespace && tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace, PR_FALSE)){                aPos->mContentOffset -= contentLen;                aPos->mEatingWS = PR_TRUE;              }              aPos->mEatingWS = !isWhitespace;//nowhite space, just eat chars.              keepSearching = aPos->mContentOffset <= mContentOffset;              if (!isWhitespace){                if (!keepSearching)                  found = PR_TRUE;              else                aPos->mEatingWS = PR_TRUE;              }            }          }          else {            aPos->mContentOffset = mContentLength + mContentOffset;            found = PR_TRUE;          }        }      }      else if (aPos->mDirection == eDirNext) {        tx.Init(this, mContent, aPos->mStartOffset );#ifdef DEBUGWORDJUMP        printf("Next- Start=%d aPos->mEatingWS=%s\n", aPos->mStartOffset, aPos->mEatingWS ? "TRUE" : "FALSE");#endif        if (tx.GetNextWord(PR_FALSE, wordLen, contentLen, isWhitespace, PR_FALSE) &&          (aPos->mStartOffset + contentLen <= (mContentLength + mContentOffset))){#ifdef DEBUGWORDJUMP          printf("GetNextWord return non null, wordLen%d, contentLen%d isWhitespace=%s\n",                  wordLen, contentLen, isWhitespace ? "WS" : "NOT WS");#endif          if ((aPos->mEatingWS && isWhitespace) || !aPos->mEatingWS){            aPos->mContentOffset = aPos->mStartOffset + contentLen;            //check for whitespace next.            keepSearching = PR_TRUE;            aPos->mEatingWS = PR_TRUE;            while (!isWhitespace && tx.GetNextWord(PR_FALSE, wordLen, contentLen, isWhitespace, PR_FALSE)){#ifdef DEBUGWORDJUMP              printf("2-GetNextWord return non null, wordLen%d, contentLen%d isWhitespace=%s\n",                      wordLen, contentLen, isWhitespace ? "WS" : "NOT WS");#endif              aPos->mContentOffset += contentLen;              keepSearching = PR_FALSE;            }          }          else if (aPos->mEatingWS)            aPos->mContentOffset = mContentOffset;          found = isWhitespace;          if (!isWhitespace){            aPos->mEatingWS = PR_FALSE;          }          else if (!keepSearching) //we have found the "whole" word so just looking for WS            aPos->mEatingWS = PR_TRUE;        }        frameUsed = GetNextInFlow();        start = 0;      }#ifdef DEBUGWORDJUMP      printf("aEatingWS = %s\n" , aPos->mEatingWS ? "TRUE" : "FALSE");#endif      if (!found || (aPos->mContentOffset > (mContentOffset + mContentLength)) || (aPos->mContentOffset < mContentOffset))      {        aPos->mContentOffset = PR_MIN(aPos->mContentOffset, mContentOffset + mContentLength);        aPos->mContentOffset = PR_MAX(aPos->mContentOffset, mContentOffset);        result = nsFrame::PeekOffset(aPos);      }      else         aPos->mResultContent = mContent;    }    break;    default:      result = NS_ERROR_FAILURE; break;  }  if (NS_FAILED(result)){    aPos->mResultContent = mContent;    //aPos->mContentOffset = aPos->mStartOffset;    result = NS_OK;  }  aPos->mResultFrame = this;  return result;}