Added, jump to prev word, modified INIT of nsTextTransformer to better prepare for a start offset at the end of the mFrags list. added implementation of extra parameter to nsIFrame::PeekOffset to keep state for the next word problem of eating ws. nsTextFrame should be all set on implementation of jumping words.

This commit is contained in:
mjudge%netscape.com 1999-02-22 04:59:52 +00:00
parent 7df9af9d91
commit b13e4da265
8 changed files with 76 additions and 40 deletions

View File

@ -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);
}
//-----------------------------------------------------------------------------------

View File

@ -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;

View File

@ -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;

View File

@ -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 = ' ';

View File

@ -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);
}
//-----------------------------------------------------------------------------------

View File

@ -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;

View File

@ -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;

View File

@ -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 = ' ';