From f7fdeca918eda9d9c9bbd75e816ce0f55d49ccde Mon Sep 17 00:00:00 2001 From: "uriber%gmail.com" Date: Sat, 8 Apr 2006 14:45:48 +0000 Subject: [PATCH] Implemented bidi.edit.caret_movement_style pref, default is "visual, but logical during selection". bug=330175 r=smontagu sr=roc git-svn-id: svn://10.0.0.236/trunk@193942 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsIFrameSelection.h | 5 ++++- mozilla/layout/generic/nsFrame.cpp | 20 +++++++++++++------- mozilla/layout/generic/nsSelection.cpp | 8 +++++++- mozilla/layout/generic/nsTextFrame.cpp | 5 +++-- mozilla/modules/libpref/src/init/all.js | 5 +++++ 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/mozilla/layout/base/nsIFrameSelection.h b/mozilla/layout/base/nsIFrameSelection.h index c478fec1810..4000e3d155d 100644 --- a/mozilla/layout/base/nsIFrameSelection.h +++ b/mozilla/layout/base/nsIFrameSelection.h @@ -97,7 +97,8 @@ struct nsPeekOffsetStruct PRBool aPreferLeft, PRBool aJumpLines, PRBool aScrollViewStop, - PRBool aIsKeyboardSelect) + PRBool aIsKeyboardSelect, + PRBool aVisual) { mShell=aShell; mDesiredX=aDesiredX; @@ -109,6 +110,7 @@ struct nsPeekOffsetStruct mJumpLines = aJumpLines; mScrollViewStop = aScrollViewStop; mIsKeyboardSelect = aIsKeyboardSelect; + mVisual = aVisual; } nsIPresShell *mShell; nscoord mDesiredX; @@ -124,6 +126,7 @@ struct nsPeekOffsetStruct PRBool mJumpLines; PRBool mScrollViewStop; PRBool mIsKeyboardSelect; + PRBool mVisual; }; class nsIScrollableView; diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 3cd73fd29f0..dc3a66e1bfc 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -2055,6 +2055,7 @@ nsFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack, PR_TRUE, aJumpLines, PR_TRUE, //limit on scrolled views + PR_FALSE, PR_FALSE); rv = PeekOffset(aPresContext, &startpos); if (NS_FAILED(rv)) @@ -2069,6 +2070,7 @@ nsFrame::PeekBackwardAndForward(nsSelectionAmount aAmountBack, PR_FALSE, aJumpLines, PR_TRUE, //limit on scrolled views + PR_FALSE, PR_FALSE); rv = PeekOffset(aPresContext, &endpos); if (NS_FAILED(rv)) @@ -4496,9 +4498,11 @@ nsFrame::GetFrameFromDirection(nsPresContext* aPresContext, nsPeekOffsetStruct * nsIFrame *firstVisual; nsIFrame *lastVisual; - result = it->CheckLineOrder(thisLine, &lineIsReordered, &firstVisual, &lastVisual); - if (NS_FAILED(result)) - return result; + if (aPos->mVisual) { + result = it->CheckLineOrder(thisLine, &lineIsReordered, &firstVisual, &lastVisual); + if (NS_FAILED(result)) + return result; + } if (lineIsReordered) { firstFrame = firstVisual; @@ -4575,10 +4579,12 @@ nsFrame::GetFrameFromDirection(nsPresContext* aPresContext, nsPeekOffsetStruct * else aPos->mStartOffset = -1; #ifdef IBMBIDI - PRUint8 newLevel = NS_GET_EMBEDDING_LEVEL(traversedFrame); - PRUint8 newBaseLevel = NS_GET_BASE_LEVEL(traversedFrame); - if ((newLevel & 1) != (newBaseLevel & 1)) // The new frame is reverse-direction, go to the other end - aPos->mStartOffset = -1 - aPos->mStartOffset; + if (aPos->mVisual) { + PRUint8 newLevel = NS_GET_EMBEDDING_LEVEL(traversedFrame); + PRUint8 newBaseLevel = NS_GET_BASE_LEVEL(traversedFrame); + if ((newLevel & 1) != (newBaseLevel & 1)) // The new frame is reverse-direction, go to the other end + aPos->mStartOffset = -1 - aPos->mStartOffset; + } #endif aPos->mResultFrame = traversedFrame; return NS_OK; diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index 2a7c231a4f7..c7186c7b37a 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -522,6 +522,8 @@ private: PRPackedBool mMouseDownState; //for drag purposes PRPackedBool mMouseDoubleDownState; //has the doubleclick down happened PRPackedBool mDesiredXSet; + + PRInt8 mCaretMovementStyle; }; class nsSelectionIterator : public nsIBidirectionalEnumerator @@ -1260,6 +1262,7 @@ nsSelection::Init(nsIPresShell *aShell, nsIContent *aLimiter) mDesiredXSet = PR_FALSE; mLimiter = aLimiter; mScrollView = nsnull; + mCaretMovementStyle = nsContentUtils::GetIntPref("bidi.edit.caret_movement_style", 2); return NS_OK; } @@ -1376,10 +1379,13 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinueSelection, nsSelection nsCOMPtr parentNode; nsPeekOffsetStruct pos; + PRBool visualMovement = mCaretMovementStyle == 1 || + (mCaretMovementStyle == 2 && !aContinueSelection); + //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); + PR_TRUE, PR_TRUE, mLimiter != nsnull, PR_TRUE, visualMovement); nsBidiLevel baseLevel = nsBidiPresUtils::GetFrameBaseLevel(frame); diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 4a14978645d..d354192edfe 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -4515,7 +4515,7 @@ nsTextFrame::PeekOffset(nsPresContext* aPresContext, nsPeekOffsetStruct *aPos) // one "on the left" - the first frame on the next // line. // - // Note: + // Note (for visual caret movement): // eDirPrevious means 'left-then-up' if the containing block is LTR, // 'right-then-up' if it is RTL. // eDirNext means 'right-then-down' if the containing block is LTR, @@ -4524,7 +4524,8 @@ nsTextFrame::PeekOffset(nsPresContext* aPresContext, nsPeekOffsetStruct *aPos) // previous paragraph", and eDirNext means "go to the visual beginning of // the next paragraph" - PRBool isReverseDirection = (NS_GET_EMBEDDING_LEVEL(this) & 1) != (NS_GET_BASE_LEVEL(this) & 1); + PRBool isReverseDirection = aPos->mVisual ? + (NS_GET_EMBEDDING_LEVEL(this) & 1) != (NS_GET_BASE_LEVEL(this) & 1) : PR_FALSE; PRBool movementIsInFrameDirection = ((aPos->mDirection == eDirNext) && !isReverseDirection) || ((aPos->mDirection == eDirPrevious) && isReverseDirection); diff --git a/mozilla/modules/libpref/src/init/all.js b/mozilla/modules/libpref/src/init/all.js index 42f8ecc5ead..ed1f8b97c31 100644 --- a/mozilla/modules/libpref/src/init/all.js +++ b/mozilla/modules/libpref/src/init/all.js @@ -932,6 +932,11 @@ pref("bidi.characterset", 1); // on the first keypress and delete the character on a second keypress pref("bidi.edit.delete_immediately", false); +// Bidi caret movement style: +// 0 = logical +// 1 = visual +// 2 = visual, but logical during selection +pref("bidi.edit.caret_movement_style", 2); // used for double-click word selection behavior. Win will override. pref("layout.word_select.eat_space_to_next_word", false);