diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 53c14df4e19..834acd00d63 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -1600,7 +1600,8 @@ nsFrame::GetChildFrameContainingOffset(PRInt32 inContentOffset, PRInt32* outFram NS_IMETHODIMP nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset) + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, + PRBool aEatingWS) { //this will use the nsFrameTraversal as the default peek method. //this should change to use geometry and also look to ALL the child lists @@ -1625,7 +1626,7 @@ nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 a //for speed reasons nsIFrame *newFrame = (nsIFrame *)isupports; return newFrame->PeekOffset(aAmount, aDirection, aStartOffset, aResultFrame, - aFrameOffset, aContentOffset); + aFrameOffset, aContentOffset, aEatingWS); } //----------------------------------------------------------------------------------- diff --git a/mozilla/layout/generic/nsFrame.h b/mozilla/layout/generic/nsFrame.h index 47d39f2f96b..40565315d41 100644 --- a/mozilla/layout/generic/nsFrame.h +++ b/mozilla/layout/generic/nsFrame.h @@ -217,7 +217,8 @@ public: nsIFrame **aActualSelected); NS_IMETHOD GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOffset, PRInt32 *aBeginContentOffset); NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset); + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, + PRBool aEatingWS); NS_IMETHOD GetOffsets(PRInt32 &aStart, PRInt32 &aEnd) const; diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 6919fc35238..bea1f42f92b 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -131,7 +131,8 @@ public: nsIFrame **aActualSelected); NS_IMETHOD GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOffset, PRInt32 *aBeginContentOffset); NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset); + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, + PRBool aEatingWS); NS_IMETHOD GetOffsets(PRInt32 &start, PRInt32 &end)const; @@ -1769,7 +1770,7 @@ TextFrame::GetChildFrameContainingOffset(PRInt32 inContentOffset, PRInt32* outFr NS_IMETHODIMP TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, nsIFrame **aResultFrame, - PRInt32 *aFrameOffset, PRInt32 *aContentOffset) + PRInt32 *aFrameOffset, PRInt32 *aContentOffset, PRBool aEatingWS) { //default, no matter what grab next/ previous sibling. if (!aResultFrame || !aFrameOffset || !aContentOffset) @@ -1840,11 +1841,11 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 if (!found){ if (frameUsed){ return frameUsed->PeekOffset(eSelectCharacter, aDirection, start, aResultFrame, - aFrameOffset, aContentOffset); + aFrameOffset, aContentOffset, aEatingWS); } else {//reached end ask the frame for help return nsFrame::PeekOffset(eSelectCharacter, aDirection, start, aResultFrame, - aFrameOffset, aContentOffset); + aFrameOffset, aContentOffset, aEatingWS); } } *aContentOffset = mContentOffset; @@ -1853,7 +1854,7 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 case eSelectWord : { nsIFrame *frameUsed = nsnull; PRInt32 start; - PRBool found = PR_TRUE; + PRBool found = PR_FALSE; PRBool isWhitespace; PRInt32 wordLen, contentLen; if (aDirection == eDirPrevious){ @@ -1861,9 +1862,10 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 if (tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace)){ *aFrameOffset = aStartOffset - contentLen; //check for whitespace next. - if (isWhitespace && tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace)) + while (isWhitespace && tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace)) *aFrameOffset -= contentLen; - found = PR_TRUE; + if (!isWhitespace) + found = PR_TRUE; } frameUsed = GetPrevInFlow(); start = -1; //start at end @@ -1871,23 +1873,33 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 else if (aDirection == eDirNext){ tx.Init(this, mContentOffset + aStartOffset ); if (tx.GetNextWord(PR_FALSE, wordLen, contentLen, isWhitespace)){ - *aFrameOffset = aStartOffset + contentLen; - //check for whitespace next. - if (tx.GetNextWord(PR_FALSE, wordLen, contentLen, isWhitespace) && isWhitespace) - *aFrameOffset += contentLen; - found = PR_TRUE; + if ((aEatingWS && isWhitespace) || !aEatingWS){ + *aFrameOffset = aStartOffset + contentLen; + //check for whitespace next. + while (tx.GetNextWord(PR_FALSE, wordLen, contentLen, isWhitespace) && isWhitespace) + *aFrameOffset += contentLen; + } + else if (aEatingWS) + *aFrameOffset = mContentOffset; + + if (!isWhitespace){ + found = PR_TRUE; + aEatingWS = PR_FALSE; + } + else + aEatingWS = PR_TRUE; } frameUsed = GetNextInFlow(); start = 0; } - if (!found || (*aFrameOffset > mContentLength) || (*aFrameOffset < mContentOffset)){ //gone too far + if (!found || (*aFrameOffset > mContentLength) || (*aFrameOffset < 0)){ //gone too far if (frameUsed){ return frameUsed->PeekOffset(aAmount, aDirection, start, aResultFrame, - aFrameOffset, aContentOffset); + aFrameOffset, aContentOffset, aEatingWS); } else {//reached end ask the frame for help return nsFrame::PeekOffset(aAmount, aDirection, start, aResultFrame, - aFrameOffset, aContentOffset); + aFrameOffset, aContentOffset, aEatingWS); } } *aContentOffset = mContentOffset; diff --git a/mozilla/layout/generic/nsTextTransformer.cpp b/mozilla/layout/generic/nsTextTransformer.cpp index e8c1fbb0044..6ffab73d298 100644 --- a/mozilla/layout/generic/nsTextTransformer.cpp +++ b/mozilla/layout/generic/nsTextTransformer.cpp @@ -95,6 +95,10 @@ nsTextTransformer::Init(/*nsTextRun& aTextRun, XXX*/ } offset += frag->GetLength(); } + if (mNumFrags && aStartingOffset == mContentLength){ + mCurrentFrag = mFrags + (mNumFrags -1); + mCurrentFragOffset = mCurrentFrag->GetLength(); + } // Get the frames style and choose a transform proc const nsStyleText* styleText; @@ -492,7 +496,7 @@ nsTextTransformer::GetPrevWord(PRBool aInWord, contentLen += numChars; } else { - while (cp > end) { + while (cp >= end) { PRUnichar ch = *cp; if (!XP_IS_SPACE(ch)) { if (CH_NBSP == ch) ch = ' '; @@ -556,7 +560,7 @@ nsTextTransformer::GetPrevWord(PRBool aInWord, contentLen += numChars; } else { - while (cp > end) { + while (cp >= end) { PRUnichar ch = PRUnichar(*cp); if (!XP_IS_SPACE(ch)) { if (CH_NBSP == ch) ch = ' '; diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index 53c14df4e19..834acd00d63 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -1600,7 +1600,8 @@ nsFrame::GetChildFrameContainingOffset(PRInt32 inContentOffset, PRInt32* outFram NS_IMETHODIMP nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset) + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, + PRBool aEatingWS) { //this will use the nsFrameTraversal as the default peek method. //this should change to use geometry and also look to ALL the child lists @@ -1625,7 +1626,7 @@ nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 a //for speed reasons nsIFrame *newFrame = (nsIFrame *)isupports; return newFrame->PeekOffset(aAmount, aDirection, aStartOffset, aResultFrame, - aFrameOffset, aContentOffset); + aFrameOffset, aContentOffset, aEatingWS); } //----------------------------------------------------------------------------------- diff --git a/mozilla/layout/html/base/src/nsFrame.h b/mozilla/layout/html/base/src/nsFrame.h index 47d39f2f96b..40565315d41 100644 --- a/mozilla/layout/html/base/src/nsFrame.h +++ b/mozilla/layout/html/base/src/nsFrame.h @@ -217,7 +217,8 @@ public: nsIFrame **aActualSelected); NS_IMETHOD GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOffset, PRInt32 *aBeginContentOffset); NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset); + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, + PRBool aEatingWS); NS_IMETHOD GetOffsets(PRInt32 &aStart, PRInt32 &aEnd) const; diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 6919fc35238..bea1f42f92b 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -131,7 +131,8 @@ public: nsIFrame **aActualSelected); NS_IMETHOD GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOffset, PRInt32 *aBeginContentOffset); NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, - nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset); + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset, + PRBool aEatingWS); NS_IMETHOD GetOffsets(PRInt32 &start, PRInt32 &end)const; @@ -1769,7 +1770,7 @@ TextFrame::GetChildFrameContainingOffset(PRInt32 inContentOffset, PRInt32* outFr NS_IMETHODIMP TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, nsIFrame **aResultFrame, - PRInt32 *aFrameOffset, PRInt32 *aContentOffset) + PRInt32 *aFrameOffset, PRInt32 *aContentOffset, PRBool aEatingWS) { //default, no matter what grab next/ previous sibling. if (!aResultFrame || !aFrameOffset || !aContentOffset) @@ -1840,11 +1841,11 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 if (!found){ if (frameUsed){ return frameUsed->PeekOffset(eSelectCharacter, aDirection, start, aResultFrame, - aFrameOffset, aContentOffset); + aFrameOffset, aContentOffset, aEatingWS); } else {//reached end ask the frame for help return nsFrame::PeekOffset(eSelectCharacter, aDirection, start, aResultFrame, - aFrameOffset, aContentOffset); + aFrameOffset, aContentOffset, aEatingWS); } } *aContentOffset = mContentOffset; @@ -1853,7 +1854,7 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 case eSelectWord : { nsIFrame *frameUsed = nsnull; PRInt32 start; - PRBool found = PR_TRUE; + PRBool found = PR_FALSE; PRBool isWhitespace; PRInt32 wordLen, contentLen; if (aDirection == eDirPrevious){ @@ -1861,9 +1862,10 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 if (tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace)){ *aFrameOffset = aStartOffset - contentLen; //check for whitespace next. - if (isWhitespace && tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace)) + while (isWhitespace && tx.GetPrevWord(PR_FALSE, wordLen, contentLen, isWhitespace)) *aFrameOffset -= contentLen; - found = PR_TRUE; + if (!isWhitespace) + found = PR_TRUE; } frameUsed = GetPrevInFlow(); start = -1; //start at end @@ -1871,23 +1873,33 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 else if (aDirection == eDirNext){ tx.Init(this, mContentOffset + aStartOffset ); if (tx.GetNextWord(PR_FALSE, wordLen, contentLen, isWhitespace)){ - *aFrameOffset = aStartOffset + contentLen; - //check for whitespace next. - if (tx.GetNextWord(PR_FALSE, wordLen, contentLen, isWhitespace) && isWhitespace) - *aFrameOffset += contentLen; - found = PR_TRUE; + if ((aEatingWS && isWhitespace) || !aEatingWS){ + *aFrameOffset = aStartOffset + contentLen; + //check for whitespace next. + while (tx.GetNextWord(PR_FALSE, wordLen, contentLen, isWhitespace) && isWhitespace) + *aFrameOffset += contentLen; + } + else if (aEatingWS) + *aFrameOffset = mContentOffset; + + if (!isWhitespace){ + found = PR_TRUE; + aEatingWS = PR_FALSE; + } + else + aEatingWS = PR_TRUE; } frameUsed = GetNextInFlow(); start = 0; } - if (!found || (*aFrameOffset > mContentLength) || (*aFrameOffset < mContentOffset)){ //gone too far + if (!found || (*aFrameOffset > mContentLength) || (*aFrameOffset < 0)){ //gone too far if (frameUsed){ return frameUsed->PeekOffset(aAmount, aDirection, start, aResultFrame, - aFrameOffset, aContentOffset); + aFrameOffset, aContentOffset, aEatingWS); } else {//reached end ask the frame for help return nsFrame::PeekOffset(aAmount, aDirection, start, aResultFrame, - aFrameOffset, aContentOffset); + aFrameOffset, aContentOffset, aEatingWS); } } *aContentOffset = mContentOffset; diff --git a/mozilla/layout/html/base/src/nsTextTransformer.cpp b/mozilla/layout/html/base/src/nsTextTransformer.cpp index e8c1fbb0044..6ffab73d298 100644 --- a/mozilla/layout/html/base/src/nsTextTransformer.cpp +++ b/mozilla/layout/html/base/src/nsTextTransformer.cpp @@ -95,6 +95,10 @@ nsTextTransformer::Init(/*nsTextRun& aTextRun, XXX*/ } offset += frag->GetLength(); } + if (mNumFrags && aStartingOffset == mContentLength){ + mCurrentFrag = mFrags + (mNumFrags -1); + mCurrentFragOffset = mCurrentFrag->GetLength(); + } // Get the frames style and choose a transform proc const nsStyleText* styleText; @@ -492,7 +496,7 @@ nsTextTransformer::GetPrevWord(PRBool aInWord, contentLen += numChars; } else { - while (cp > end) { + while (cp >= end) { PRUnichar ch = *cp; if (!XP_IS_SPACE(ch)) { if (CH_NBSP == ch) ch = ' '; @@ -556,7 +560,7 @@ nsTextTransformer::GetPrevWord(PRBool aInWord, contentLen += numChars; } else { - while (cp > end) { + while (cp >= end) { PRUnichar ch = PRUnichar(*cp); if (!XP_IS_SPACE(ch)) { if (CH_NBSP == ch) ch = ' ';