From 4a089a3fffbe1e2dad4fb301d4cddc62f4df8ce2 Mon Sep 17 00:00:00 2001 From: "roc+%cs.cmu.edu" Date: Mon, 22 Aug 2005 01:32:03 +0000 Subject: [PATCH] Bug 305239. Fix regression in text entry. r+sr=roc, patch by Uri Bernstein git-svn-id: svn://10.0.0.236/trunk@178581 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/generic/nsFrame.cpp | 10 +++++++++- mozilla/layout/generic/nsSelection.cpp | 17 +++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index fa982fec480..59f8492ae8a 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -3602,16 +3602,24 @@ DrillDownToEndOfLine(nsIFrame* aFrame, PRInt32 aLineFrameCount, if (!aFrame) return NS_ERROR_UNEXPECTED; + nsIFrame *prevFrame = aFrame; nsIFrame *currentFrame = aFrame; PRInt32 i; for (i = 1; i < aLineFrameCount; i++) //already have 1st frame { + prevFrame = currentFrame; currentFrame = currentFrame->GetNextSibling(); NS_ASSERTION(currentFrame, "lineFrame Count lied to us from nsILineIterator!\n"); } + if (!currentFrame->GetRect().width) //this can happen with BR frames and or empty placeholder frames. + { + //if we do hit an empty frame then back up the current frame to the frame before it if there is one. + currentFrame = prevFrame; + } + nsFrame::GetLastLeaf(aFrame->GetPresContext(), ¤tFrame); - + aPos->mResultContent = currentFrame->GetContent(); PRInt32 startOffset, endOffset; nsresult rv = currentFrame->GetOffsets(startOffset, endOffset); diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index f07160692cd..88bba4cd8aa 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -2736,14 +2736,8 @@ nsSelection::GetFrameForNodeOffset(nsIContent *aNode, PRInt32 aOffset, HINT aHin if (aNode->IsContentOfType(nsIContent::eELEMENT)) { PRInt32 childIndex = 0; - PRInt32 numChildren = theNode->GetChildCount(); + PRInt32 numChildren = 0; - if (numChildren == 0) - { - *aReturnOffset = 0; - return mShell->GetPrimaryFrameFor(theNode, aReturnFrame); - } - if (aHint == HINTLEFT) { if (aOffset > 0) @@ -2753,8 +2747,15 @@ nsSelection::GetFrameForNodeOffset(nsIContent *aNode, PRInt32 aOffset, HINT aHin } else // HINTRIGHT { + numChildren = theNode->GetChildCount(); + if (aOffset >= numChildren) - childIndex = numChildren - 1; + { + if (numChildren > 0) + childIndex = numChildren - 1; + else + childIndex = 0; + } else childIndex = aOffset; }