diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 6456e0782e9..4219da1e960 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -3436,11 +3436,7 @@ PresShell::CompleteMove(PRBool aForward, PRBool aExtend) nsPeekOffsetStruct pos = frame->GetExtremeCaretPosition(!aForward); - // we 'prefer left' (i.e. prefer the beginning of the next line) - // iff we're moving to the end of the content - pos.mPreferLeft = aForward; - - mSelection->HandleClick(pos.mResultContent ,pos.mContentOffset ,pos.mContentOffset/*End*/ ,aExtend, PR_FALSE, pos.mPreferLeft); + mSelection->HandleClick(pos.mResultContent ,pos.mContentOffset ,pos.mContentOffset/*End*/ ,aExtend, PR_FALSE, aForward); return ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION, PR_TRUE); } diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index c2bff58d4e2..307c5f7bbab 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -1992,8 +1992,7 @@ nsFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack, nsresult rv = GetSelectionController(aPresContext, getter_AddRefs(selcon)); if (NS_FAILED(rv)) return rv; - nsIPresShell *shell = aPresContext->GetPresShell(); - if (!shell || !selcon) + if (!selcon) return NS_ERROR_NOT_INITIALIZED; // Use peek offset one way then the other: @@ -2002,13 +2001,10 @@ nsFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack, nsCOMPtr endContent; nsCOMPtr endNode; nsPeekOffsetStruct startpos; - startpos.SetData(shell, - 0, - aAmountBack, + startpos.SetData(aAmountBack, eDirPrevious, - aStartPos, - PR_FALSE, - PR_TRUE, + aStartPos, + 0, aJumpLines, PR_TRUE, //limit on scrolled views PR_FALSE, @@ -2017,13 +2013,10 @@ nsFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack, if (NS_FAILED(rv)) return rv; nsPeekOffsetStruct endpos; - endpos.SetData(shell, - 0, - aAmountForward, + endpos.SetData(aAmountForward, eDirNext, - aStartPos, - PR_FALSE, - PR_FALSE, + aStartPos, + 0, aJumpLines, PR_TRUE, //limit on scrolled views PR_FALSE, @@ -3823,7 +3816,7 @@ nsFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext, aPos->mResultFrame = nsnull; aPos->mResultContent = nsnull; - aPos->mPreferLeft = (aPos->mDirection == eDirNext); + aPos->mAttachForward = (aPos->mDirection == eDirNext); nsresult result; nsCOMPtr it; @@ -3951,13 +3944,12 @@ nsFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext, { aPos->mResultContent = parent; aPos->mContentOffset = parent->IndexOf(content); - aPos->mPreferLeft = PR_FALSE; + aPos->mAttachForward = PR_FALSE; if ((point.x - offset.x+ tempRect.x)>tempRect.width) { aPos->mContentOffset++;//go to end of this frame - aPos->mPreferLeft = PR_TRUE; + aPos->mAttachForward = PR_TRUE; } - aPos->mContentOffsetEnd = aPos->mContentOffset; //result frame is the result frames parent. aPos->mResultFrame = resultFrame->GetParent(); return NS_POSITION_BEFORE_TABLE; @@ -3976,7 +3968,7 @@ nsFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext, resultFrame->GetContentOffsetsFromPoint(point - offset); aPos->mResultContent = offsets.content; aPos->mContentOffset = offsets.offset; - aPos->mPreferLeft = offsets.associateWithNext; + aPos->mAttachForward = offsets.associateWithNext; if (offsets.content) { PRBool selectable; @@ -4018,7 +4010,7 @@ nsFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext, resultFrame->GetContentOffsetsFromPoint(point - offset); aPos->mResultContent = offsets.content; aPos->mContentOffset = offsets.offset; - aPos->mPreferLeft = offsets.associateWithNext; + aPos->mAttachForward = offsets.associateWithNext; if (offsets.content) { PRBool selectable; @@ -4027,9 +4019,9 @@ nsFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext, { found = PR_TRUE; if (resultFrame == farStoppingFrame) - aPos->mPreferLeft = PR_FALSE; + aPos->mAttachForward = PR_FALSE; else - aPos->mPreferLeft = PR_TRUE; + aPos->mAttachForward = PR_TRUE; break; } } @@ -4054,7 +4046,7 @@ nsFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext, aPos->mAmount = eSelectLine; aPos->mStartOffset = 0; aPos->mEatingWS = PR_FALSE; - aPos->mPreferLeft = !(aPos->mDirection == eDirNext); + aPos->mAttachForward = !(aPos->mDirection == eDirNext); if (aPos->mDirection == eDirPrevious) aPos->mStartOffset = -1;//start from end return aBlockFrame->PeekOffset(aPresContext, aPos); @@ -4071,7 +4063,7 @@ nsPeekOffsetStruct nsIFrame::GetExtremeCaretPosition(PRBool aStart) FrameContentRange range = GetRangeForFrame(targetFrame.frame); result.mResultContent = range.content; result.mContentOffset = aStart ? range.start : range.end; - result.mPreferLeft = (result.mContentOffset == range.start); + result.mAttachForward = (result.mContentOffset == range.start); return result; } @@ -4208,9 +4200,9 @@ nsFrame::PeekOffsetParagraph(nsPresContext* aPresContext, NS_IMETHODIMP nsFrame::PeekOffset(nsPresContext* aPresContext, nsPeekOffsetStruct *aPos) { - if (!aPos || !aPos->mShell) + if (!aPos) return NS_ERROR_NULL_POINTER; - nsresult result = NS_ERROR_FAILURE; + nsresult result = NS_ERROR_FAILURE; nsPoint point; point.x = aPos->mDesiredX; point.y = 0; @@ -4260,16 +4252,13 @@ nsFrame::PeekOffset(nsPresContext* aPresContext, nsPeekOffsetStruct *aPos) }//drop into no amount case eSelectNoAmount: { - nsPresContext *context = aPos->mShell->GetPresContext(); - if (!context) - return NS_OK; nsIView* view; nsPoint offset; GetOffsetFromView(offset, &view); ContentOffsets offsets = GetContentOffsetsFromPoint(point - offset); aPos->mResultContent = offsets.content; aPos->mContentOffset = offsets.offset; - aPos->mPreferLeft = offsets.associateWithNext; + aPos->mAttachForward = offsets.associateWithNext; result = offsets.content ? NS_OK : NS_ERROR_FAILURE; }break; case eSelectLine : @@ -4401,7 +4390,7 @@ nsFrame::PeekOffset(nsPresContext* aPresContext, nsPeekOffsetStruct *aPos) FrameContentRange range = GetRangeForFrame(targetFrame.frame); aPos->mResultContent = range.content; aPos->mContentOffset = endOfLine ? range.end : range.start; - aPos->mPreferLeft = (aPos->mContentOffset == range.start); + aPos->mAttachForward = (aPos->mContentOffset == range.start); if (!range.content) return NS_ERROR_FAILURE; return NS_OK; diff --git a/mozilla/layout/generic/nsFrameSelection.h b/mozilla/layout/generic/nsFrameSelection.h index 76241a0904f..942c59d30bc 100644 --- a/mozilla/layout/generic/nsFrameSelection.h +++ b/mozilla/layout/generic/nsFrameSelection.h @@ -61,68 +61,105 @@ class nsIPresShell; enum EWordMovementType { eStartWord, eEndWord, eDefaultBehavior }; -/*PeekOffsetStruct - * @param mShell is used to get the PresContext useful for measuring text etc. - * @param mDesiredX is the "desired" location of the new caret - * @param mAmount eWord, eCharacter, eLine - * @param mDirection enum defined in this file to be eForward or eBackward - * @param mStartOffset start offset to start the peek. 0 == beginning -1 = end - * @param mResultContent content that actually is the next/previous - * @param mResultOffset offset for result content - * @param mResultFrame resulting frame for peeking - * @param mEatingWS boolean to tell us the state of our search for Next/Prev - * @param mPreferLeft true = prev line end, false = next line begin - * @param mJumpLines if this is true then it's ok to cross lines while peeking - * @param mScrollViewStop if this is true then stop peeking across scroll view boundary - * @param mWordMovementType an enum that determines whether to prefer the start or end of a word - * or to use the default beahvior, which is a combination of - * direction and the platform-based pref - * "layout.word_select.eat_space_to_next_word" -*/ +/** PeekOffsetStruct is used to group various arguments (both input and output) + * that are passed to nsFrame::PeekOffset(). See below for the description of + * individual arguments. + */ struct nsPeekOffsetStruct { - void SetData(nsIPresShell *aShell, - nscoord aDesiredX, - nsSelectionAmount aAmount, + void SetData(nsSelectionAmount aAmount, nsDirection aDirection, - PRInt32 aStartOffset, - PRBool aEatingWS, - PRBool aPreferLeft, + PRInt32 aStartOffset, + nscoord aDesiredX, PRBool aJumpLines, PRBool aScrollViewStop, PRBool aIsKeyboardSelect, PRBool aVisual, - EWordMovementType aWordMovementType = eDefaultBehavior ) - { - mShell=aShell; - mDesiredX=aDesiredX; - mAmount=aAmount; - mDirection=aDirection; - mStartOffset=aStartOffset; - mEatingWS=aEatingWS; - mPreferLeft=aPreferLeft; - mJumpLines = aJumpLines; - mScrollViewStop = aScrollViewStop; - mIsKeyboardSelect = aIsKeyboardSelect; - mVisual = aVisual; - mWordMovementType = aWordMovementType; - } - nsIPresShell *mShell; - nscoord mDesiredX; + EWordMovementType aWordMovementType = eDefaultBehavior) + + { + mAmount = aAmount; + mDirection = aDirection; + mStartOffset = aStartOffset; + mDesiredX = aDesiredX; + mJumpLines = aJumpLines; + mScrollViewStop = aScrollViewStop; + mIsKeyboardSelect = aIsKeyboardSelect; + mVisual = aVisual; + mWordMovementType = aWordMovementType; + mEatingWS = PR_FALSE; + } + + // Note: Most arguments (input and output) are only used with certain values + // of mAmount. These values are indicated for each argument below. + // Arguments with no such indication are used with all values of mAmount. + + /*** Input arguments ***/ + // Note: The value of some of the input arguments may be changed upon exit. + + // mAmount: The type of movement requested (by character, word, line, etc.) nsSelectionAmount mAmount; + + // mDirection: eDirPrevious or eDirNext. + // Used with: eSelectCharacter, eSelectWord, eSelectLine, eSelectParagraph. nsDirection mDirection; + + // mStartOffset: Offset into the content of the current frame where the peek starts. + // Used with: eSelectCharacter, eSelectWord PRInt32 mStartOffset; - nsCOMPtr mResultContent; - PRInt32 mContentOffset; - PRInt32 mContentOffsetEnd; - nsIFrame *mResultFrame; - PRBool mEatingWS; - PRBool mPreferLeft; + + // mDesiredX: The desired x coordinate for the caret. + // Used with: eSelectLine. + nscoord mDesiredX; + + // mJumpLines: Whether to allow jumping across line boundaries. + // Used with: eSelectCharacter, eSelectWord. PRBool mJumpLines; + + // mScrollViewStop: Whether to stop when reaching a scroll view boundary. + // Used with: eSelectCharacter, eSelectWord, eSelectLine. PRBool mScrollViewStop; + + // mIsKeyboardSelect: Whether the peeking is done in response to a keyboard action. + // Used with: eSelectWord. PRBool mIsKeyboardSelect; + + // mVisual: Whether bidi caret behavior is visual (PR_TRUE) or logical (PR_FALSE). + // Used with: eSelectCharacter, eSelectWord. PRBool mVisual; + + // mWordMovementType: An enum that determines whether to prefer the start or end of a word + // or to use the default beahvior, which is a combination of + // direction and the platform-based pref + // "layout.word_select.eat_space_to_next_word" EWordMovementType mWordMovementType; + + /*** Output arguments ***/ + + // mResultContent: Content reached as a result of the peek. + nsCOMPtr mResultContent; + + // mContentOffset: Offset into content reached as a result of the peek. + PRInt32 mContentOffset; + + // mResultFrame: Frame reached as a result of the peek. + // Used with: eSelectCharacter, eSelectWord. + nsIFrame *mResultFrame; + + // mAttachForward: When the result position is between two frames, + // indicates which of the two frames the caret should be painted in. + // PR_FALSE means "the end of the frame logically before the caret", + // PR_TRUE means "the beginning of the frame logically after the caret". + // Used with: eSelectLine, eSelectBeginLine, eSelectEndLine. + PRBool mAttachForward; + + /*** Arguments only used internally ***/ + + // mEatingWS: Used only internally, for recursive calls into PeekOffset. + // Shold be PR_FALSE upon initial call to PeekOffset. + // Used with: eSelectWord. + PRBool mEatingWS; + }; struct nsPrevNextBidiLevels diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index 389b31888d6..ceee87f904d 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -1208,8 +1208,8 @@ nsFrameSelection::MoveCaret(PRUint32 aKeycode, //set data using mLimiter to stop on scroll views. If we have a limiter then we stop peeking //when we hit scrollable views. If no limiter then just let it go ahead - pos.SetData(mShell, desiredX, aAmount, eDirPrevious, offsetused, PR_FALSE, - PR_TRUE, PR_TRUE, mLimiter != nsnull, PR_TRUE, visualMovement); + pos.SetData(aAmount, eDirPrevious, offsetused, desiredX, + PR_TRUE, mLimiter != nsnull, PR_TRUE, visualMovement); nsBidiLevel baseLevel = nsBidiPresUtils::GetFrameBaseLevel(frame); @@ -1218,37 +1218,29 @@ nsFrameSelection::MoveCaret(PRUint32 aKeycode, case nsIDOMKeyEvent::DOM_VK_RIGHT : InvalidateDesiredX(); pos.mDirection = (baseLevel & 1) ? eDirPrevious : eDirNext; - PostReason(nsISelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_LEFT : //no break InvalidateDesiredX(); pos.mDirection = (baseLevel & 1) ? eDirNext : eDirPrevious; - PostReason(nsISelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_DOWN : pos.mAmount = eSelectLine; pos.mDirection = eDirNext;//no break here - PostReason(nsISelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_UP : pos.mAmount = eSelectLine; - PostReason(nsISelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_HOME : InvalidateDesiredX(); pos.mAmount = eSelectBeginLine; - tHint = HINTRIGHT;//stick to opposite of movement - PostReason(nsISelectionListener::KEYPRESS_REASON); break; case nsIDOMKeyEvent::DOM_VK_END : InvalidateDesiredX(); pos.mAmount = eSelectEndLine; - tHint = HINTLEFT;//stick to this line - PostReason(nsISelectionListener::KEYPRESS_REASON); break; default :return NS_ERROR_FAILURE; } - pos.mPreferLeft = tHint; + PostReason(nsISelectionListener::KEYPRESS_REASON); if (NS_SUCCEEDED(result = frame->PeekOffset(context, &pos)) && pos.mResultContent) { nsIFrame *theFrame; @@ -1257,7 +1249,7 @@ nsFrameSelection::MoveCaret(PRUint32 aKeycode, if (aKeycode == nsIDOMKeyEvent::DOM_VK_RIGHT || aKeycode == nsIDOMKeyEvent::DOM_VK_LEFT) { - // For left/right, PeekOffset() sets pos.mResultFrame correctly, but does not set pos.mPreferLeft, + // For left/right, PeekOffset() sets pos.mResultFrame correctly, but does not set pos.mAttachForward, // so determine the hint here based on the result frame and offset: // If we're at the end of a text frame, set the hint to HINTLEFT to indicate that we // want the caret displayed at the end of this frame, not at the beginning of the next one. @@ -1271,7 +1263,7 @@ nsFrameSelection::MoveCaret(PRUint32 aKeycode, } else { // For up/down and home/end, pos.mResultFrame might not be set correctly, or not at all. // In these cases, get the frame based on the content and hint returned by PeekOffset(). - tHint = (HINT)pos.mPreferLeft; + tHint = (HINT)pos.mAttachForward; theFrame = GetFrameForNodeOffset(pos.mResultContent, pos.mContentOffset, tHint, ¤tOffset); if (!theFrame) @@ -2286,8 +2278,8 @@ nsFrameSelection::HandleDrag(nsIFrame *aFrame, nsPoint aPoint) amount = eSelectEndLine; nsPeekOffsetStruct pos; - pos.SetData(mShell, 0, amount, direction, offsets.offset, PR_FALSE, - PR_TRUE, PR_FALSE, mLimiter != nsnull, PR_TRUE, PR_FALSE); + pos.SetData(amount, direction, offsets.offset, 0, + PR_FALSE, mLimiter != nsnull, PR_FALSE, PR_FALSE); nsIFrame* frame = mShell->GetPrimaryFrameFor(offsets.content); if (NS_SUCCEEDED(result = frame->PeekOffset(mShell->GetPresContext(), &pos)) && pos.mResultContent) { @@ -2303,8 +2295,8 @@ nsFrameSelection::HandleDrag(nsIFrame *aFrame, nsPoint aPoint) nsPeekOffsetStruct pos; //set data using mLimiter to stop on scroll views. If we have a limiter then we stop peeking //when we hit scrollable views. If no limiter then just let it go ahead - pos.SetData(mShell, 0, eSelectDir, eDirNext, startPos, PR_FALSE, - PR_TRUE, PR_TRUE, mLimiter != nsnull, PR_FALSE); + pos.SetData(eSelectDir, eDirNext, startPos, 0, + PR_TRUE, mLimiter != nsnull, PR_FALSE, PR_TRUE); mHint = HINT(beginOfContent); HINT saveHint = mHint; if (NS_GET_EMBEDDING_LEVEL(newFrame) & 1) diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index b2a5911cb92..054485d45ba 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -4979,8 +4979,6 @@ TryNextFrame: result = NS_ERROR_FAILURE; break; } - aPos->mContentOffsetEnd = aPos->mContentOffset; - if (NS_FAILED(result)){ aPos->mResultContent = mContent; //aPos->mContentOffset = aPos->mStartOffset;