fixes for line/frame traversal. now we use more common code inside nsFrame rather than nsTextFrame specific code all the time.

This commit is contained in:
mjudge%netscape.com 1999-09-22 04:12:23 +00:00
Родитель bfe297f681
Коммит 375e6fb76f
4 изменённых файлов: 114 добавлений и 52 удалений

Просмотреть файл

@ -1010,7 +1010,7 @@ NS_IMETHODIMP nsFrame::GetPosition(nsIPresContext& aCX,
aContentOffset, aContentOffsetEnd);
}
}
result = mContent->GetParent(*aNewContent);
if (*aNewContent){
result = (*aNewContent)->IndexOf(mContent, aContentOffset);
@ -1018,6 +1018,7 @@ NS_IMETHODIMP nsFrame::GetPosition(nsIPresContext& aCX,
{
return result;
}
#if 0
nsRect rect;
GetRect(rect);
nsPoint offsetPoint; //used for offset of result frame
@ -1025,6 +1026,7 @@ NS_IMETHODIMP nsFrame::GetPosition(nsIPresContext& aCX,
GetOffsetFromView(offsetPoint, &view);
if (aXCoord > (rect.width + rect.x))
aContentOffset++;
#endif
aContentOffsetEnd = aContentOffset;
}
return result;
@ -2125,7 +2127,54 @@ nsFrame::PeekOffset(nsPeekOffsetStruct *aPos)
{
//this will use the nsFrameTraversal as the default peek method.
//this should change to use geometry and also look to ALL the child lists
//we need to set up line information to make sure we dont jump across line boundaries
nsIFrame *blockFrame = this;
nsIFrame *thisBlock;
PRInt32 thisLine;
nsCOMPtr<nsILineIterator> it;
while (NS_FAILED(result) && blockFrame)
{
thisBlock = blockFrame;
result = blockFrame->GetParent(&blockFrame);
if (NS_SUCCEEDED(result) && blockFrame){
result = blockFrame->QueryInterface(nsILineIterator::GetIID(),getter_AddRefs(it));
}
else
blockFrame = nsnull;
}
if (!blockFrame || !it)
return NS_ERROR_FAILURE;
result = it->FindLineContaining(thisBlock, &thisLine);
if (NS_FAILED(result))
return result;
nsIFrame *firstFrame;
nsIFrame *lastFrame;
nsRect nonUsedRect;
PRInt32 lineFrameCount;
result = it->GetLine(thisLine, &firstFrame, &lineFrameCount,nonUsedRect);
if (NS_FAILED(result))
return result;
lastFrame = firstFrame;
for (;lineFrameCount > 1;lineFrameCount --){
result = lastFrame->GetNextSibling(&lastFrame);
if (NS_FAILED(result)){
NS_ASSERTION(0,"should not be reached nsFrame\n");
return NS_ERROR_FAILURE;
}
}
//END LINE DATA CODE
if ((aPos->mDirection == eDirNext && lastFrame == this)
||(aPos->mDirection == eDirPrevious && firstFrame == this))
{
aPos->mPreferLeft = (PRBool)!(aPos->mPreferLeft);//drift to other side
aPos->mAmount = eSelectNoAmount;
}
nsCOMPtr<nsIBidirectionalEnumerator> frameTraversal;
result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal),LEAF,this);
if (NS_FAILED(result))

Просмотреть файл

@ -2083,7 +2083,7 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos)
PRInt32* ip = indexBuffer.mBuffer;
PRInt32 textLength;
nsresult result(NS_OK);
nsresult result(NS_ERROR_FAILURE);
aPos->mResultContent = mContent;//do this right off
switch (aPos->mAmount){
case eSelectNoAmount:
@ -2143,17 +2143,10 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos)
start = mContentOffset + mContentLength;
}
}
if (!found){
if (frameUsed){
result = frameUsed->PeekOffset(aPos);
}
else {//reached end ask the frame for help
result = nsFrame::PeekOffset(aPos);
}
}
else {
if (!found)
result = nsFrame::PeekOffset(aPos);
else
aPos->mResultContent = mContent;
}
}
break;
@ -2208,8 +2201,6 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos)
found = PR_TRUE;
}
}
frameUsed = GetPrevInFlow();
start = -1; //start at end
}
else if (aPos->mDirection == eDirNext) {
tx.Init(this, mContent, aPos->mStartOffset );
@ -2256,21 +2247,12 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos)
#ifdef DEBUGWORDJUMP
printf("aEatingWS = %s\n" , aPos->mEatingWS ? "TRUE" : "FALSE");
#endif
if (!found || (aPos->mContentOffset > (mContentOffset + mContentLength)) || (aPos->mContentOffset < mContentOffset)){ //gone too far
if (frameUsed){
aPos->mStartOffset = start;
result = frameUsed->PeekOffset(aPos);
}
else {//reached end ask the frame for help
result = nsFrame::PeekOffset(aPos);
}
}
else {
if (!found || (aPos->mContentOffset > (mContentOffset + mContentLength)) || (aPos->mContentOffset < mContentOffset))
result = nsFrame::PeekOffset(aPos);
else
aPos->mResultContent = mContent;
}
}
break;
default:
result = NS_ERROR_FAILURE; break;
}

Просмотреть файл

@ -1010,7 +1010,7 @@ NS_IMETHODIMP nsFrame::GetPosition(nsIPresContext& aCX,
aContentOffset, aContentOffsetEnd);
}
}
result = mContent->GetParent(*aNewContent);
if (*aNewContent){
result = (*aNewContent)->IndexOf(mContent, aContentOffset);
@ -1018,6 +1018,7 @@ NS_IMETHODIMP nsFrame::GetPosition(nsIPresContext& aCX,
{
return result;
}
#if 0
nsRect rect;
GetRect(rect);
nsPoint offsetPoint; //used for offset of result frame
@ -1025,6 +1026,7 @@ NS_IMETHODIMP nsFrame::GetPosition(nsIPresContext& aCX,
GetOffsetFromView(offsetPoint, &view);
if (aXCoord > (rect.width + rect.x))
aContentOffset++;
#endif
aContentOffsetEnd = aContentOffset;
}
return result;
@ -2125,7 +2127,54 @@ nsFrame::PeekOffset(nsPeekOffsetStruct *aPos)
{
//this will use the nsFrameTraversal as the default peek method.
//this should change to use geometry and also look to ALL the child lists
//we need to set up line information to make sure we dont jump across line boundaries
nsIFrame *blockFrame = this;
nsIFrame *thisBlock;
PRInt32 thisLine;
nsCOMPtr<nsILineIterator> it;
while (NS_FAILED(result) && blockFrame)
{
thisBlock = blockFrame;
result = blockFrame->GetParent(&blockFrame);
if (NS_SUCCEEDED(result) && blockFrame){
result = blockFrame->QueryInterface(nsILineIterator::GetIID(),getter_AddRefs(it));
}
else
blockFrame = nsnull;
}
if (!blockFrame || !it)
return NS_ERROR_FAILURE;
result = it->FindLineContaining(thisBlock, &thisLine);
if (NS_FAILED(result))
return result;
nsIFrame *firstFrame;
nsIFrame *lastFrame;
nsRect nonUsedRect;
PRInt32 lineFrameCount;
result = it->GetLine(thisLine, &firstFrame, &lineFrameCount,nonUsedRect);
if (NS_FAILED(result))
return result;
lastFrame = firstFrame;
for (;lineFrameCount > 1;lineFrameCount --){
result = lastFrame->GetNextSibling(&lastFrame);
if (NS_FAILED(result)){
NS_ASSERTION(0,"should not be reached nsFrame\n");
return NS_ERROR_FAILURE;
}
}
//END LINE DATA CODE
if ((aPos->mDirection == eDirNext && lastFrame == this)
||(aPos->mDirection == eDirPrevious && firstFrame == this))
{
aPos->mPreferLeft = (PRBool)!(aPos->mPreferLeft);//drift to other side
aPos->mAmount = eSelectNoAmount;
}
nsCOMPtr<nsIBidirectionalEnumerator> frameTraversal;
result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal),LEAF,this);
if (NS_FAILED(result))

Просмотреть файл

@ -2083,7 +2083,7 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos)
PRInt32* ip = indexBuffer.mBuffer;
PRInt32 textLength;
nsresult result(NS_OK);
nsresult result(NS_ERROR_FAILURE);
aPos->mResultContent = mContent;//do this right off
switch (aPos->mAmount){
case eSelectNoAmount:
@ -2143,17 +2143,10 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos)
start = mContentOffset + mContentLength;
}
}
if (!found){
if (frameUsed){
result = frameUsed->PeekOffset(aPos);
}
else {//reached end ask the frame for help
result = nsFrame::PeekOffset(aPos);
}
}
else {
if (!found)
result = nsFrame::PeekOffset(aPos);
else
aPos->mResultContent = mContent;
}
}
break;
@ -2208,8 +2201,6 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos)
found = PR_TRUE;
}
}
frameUsed = GetPrevInFlow();
start = -1; //start at end
}
else if (aPos->mDirection == eDirNext) {
tx.Init(this, mContent, aPos->mStartOffset );
@ -2256,21 +2247,12 @@ nsTextFrame::PeekOffset(nsPeekOffsetStruct *aPos)
#ifdef DEBUGWORDJUMP
printf("aEatingWS = %s\n" , aPos->mEatingWS ? "TRUE" : "FALSE");
#endif
if (!found || (aPos->mContentOffset > (mContentOffset + mContentLength)) || (aPos->mContentOffset < mContentOffset)){ //gone too far
if (frameUsed){
aPos->mStartOffset = start;
result = frameUsed->PeekOffset(aPos);
}
else {//reached end ask the frame for help
result = nsFrame::PeekOffset(aPos);
}
}
else {
if (!found || (aPos->mContentOffset > (mContentOffset + mContentLength)) || (aPos->mContentOffset < mContentOffset))
result = nsFrame::PeekOffset(aPos);
else
aPos->mResultContent = mContent;
}
}
break;
default:
result = NS_ERROR_FAILURE; break;
}