Bug 407155. Backing out 392809 to fix regressions. a=schrep

This commit is contained in:
roc+%cs.cmu.edu 2007-12-07 09:35:45 +00:00
Родитель 162c6d9db4
Коммит f1a169291c
5 изменённых файлов: 25 добавлений и 82 удалений

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

@ -4947,7 +4947,7 @@ nsFrame::PeekOffsetWord(PRBool aForward, PRBool aWordSelectEatSpace, PRBool aIsK
if (!aState->mAtStart) {
if (aState->mLastCharWasPunctuation) {
// We're not punctuation, so this is a punctuation boundary.
if (BreakWordBetweenPunctuation(aState, PR_FALSE, PR_FALSE, aIsKeyboardSelect))
if (BreakWordBetweenPunctuation(aForward, aIsKeyboardSelect))
return PR_TRUE;
} else {
// This is not a punctuation boundary.
@ -4957,9 +4957,7 @@ nsFrame::PeekOffsetWord(PRBool aForward, PRBool aWordSelectEatSpace, PRBool aIsK
}
// Otherwise skip to the other side and note that we encountered non-whitespace.
*aOffset = 1 - startOffset;
aState->Update(PR_FALSE, // not punctuation
PR_FALSE // not whitespace
);
aState->Update(PR_FALSE);
if (!aWordSelectEatSpace)
aState->SetSawBeforeType();
}
@ -4967,32 +4965,18 @@ nsFrame::PeekOffsetWord(PRBool aForward, PRBool aWordSelectEatSpace, PRBool aIsK
}
PRBool
nsFrame::BreakWordBetweenPunctuation(const PeekWordState* aState,
PRBool aPunctAfter, PRBool aWhitespaceAfter,
PRBool aIsKeyboardSelect)
nsFrame::BreakWordBetweenPunctuation(PRBool aAfterPunct, PRBool aIsKeyboardSelect)
{
NS_ASSERTION(aPunctAfter != aState->mLastCharWasPunctuation,
"Call this only at punctuation boundaries");
if (aState->mLastCharWasWhitespace) {
// We always stop between whitespace and punctuation
return PR_TRUE;
}
if (!nsContentUtils::GetBoolPref("layout.word_select.stop_at_punctuation")) {
// When this pref is false, we never stop at a punctuation boundary unless
// it's after whitespace
// When this pref is false, we never stop at a punctuation boundary.
return PR_FALSE;
}
if (!aIsKeyboardSelect) {
// mouse caret movement (e.g. word selection) always stops at every punctuation boundary
return PR_TRUE;
}
if (!aState->mLastCharWasPunctuation) {
// keyboard caret movement stops after punctuation, not before it
return PR_FALSE;
}
// Stop only if we've seen some non-punctuation since the last whitespace;
// don't stop after punctuation that follows whitespace.
return aState->mSeenNonPunctuationSinceWhitespace;
// keyboard caret movement stops after punctuation, not before it
return aAfterPunct;
}
NS_IMETHODIMP

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

@ -251,14 +251,11 @@ public:
PRInt32* aOffset, PeekWordState *aState);
/**
* Check whether we should break at a boundary between punctuation and
* non-punctuation. Only call it at a punctuation boundary
* (i.e. exactly one of the previous and next characters are punctuation).
* @param aPunctAfter true if the next character is punctuation
* non-punctuation.
* @param aAfterPunct true when this point is logically *after* punctuation.
*/
PRBool BreakWordBetweenPunctuation(const PeekWordState* aState,
PRBool aPunctAfter, PRBool aWhitespaceAfter,
PRBool aIsKeyboardSelect);
PRBool BreakWordBetweenPunctuation(PRBool aAfterPunct, PRBool aIsKeyboardSelect);
NS_IMETHOD CheckVisibility(nsPresContext* aContext, PRInt32 aStartIndex, PRInt32 aEndIndex, PRBool aRecurse, PRBool *aFinished, PRBool *_retval);
NS_IMETHOD GetOffsets(PRInt32 &aStart, PRInt32 &aEnd) const;

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

@ -2168,27 +2168,15 @@ protected:
PRPackedBool mSawBeforeType;
// true when the last character encountered was punctuation
PRPackedBool mLastCharWasPunctuation;
// true when the last character encountered was whitespace
PRPackedBool mLastCharWasWhitespace;
// true when we've seen non-punctuation since the last whitespace
PRPackedBool mSeenNonPunctuationSinceWhitespace;
// text that's *before* the current frame when aForward is true, *after*
// the current frame when aForward is false. Only includes the text
// on the current line.
// the current frame when aForward is false.
nsAutoString mContext;
PeekWordState() : mAtStart(PR_TRUE), mSawBeforeType(PR_FALSE),
mLastCharWasPunctuation(PR_FALSE), mLastCharWasWhitespace(PR_FALSE),
mSeenNonPunctuationSinceWhitespace(PR_FALSE) {}
mLastCharWasPunctuation(PR_FALSE) {}
void SetSawBeforeType() { mSawBeforeType = PR_TRUE; }
void Update(PRBool aAfterPunctuation, PRBool aAfterWhitespace) {
void Update(PRBool aAfterPunctuation) {
mLastCharWasPunctuation = aAfterPunctuation;
mLastCharWasWhitespace = aAfterWhitespace;
if (aAfterWhitespace) {
mSeenNonPunctuationSinceWhitespace = PR_FALSE;
} else if (!aAfterPunctuation) {
mSeenNonPunctuationSinceWhitespace = PR_TRUE;
}
mAtStart = PR_FALSE;
}
};

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

@ -4723,23 +4723,23 @@ nsTextFrame::PeekOffsetWord(PRBool aForward, PRBool aWordSelectEatSpace, PRBool
do {
PRBool isPunctuation = cIter.IsPunctuation();
PRBool isWhitespace = cIter.IsWhitespace();
if (aWordSelectEatSpace == isWhitespace && !aState->mSawBeforeType) {
if (aWordSelectEatSpace == cIter.IsWhitespace() && !aState->mSawBeforeType) {
aState->SetSawBeforeType();
aState->Update(isPunctuation, isWhitespace);
aState->Update(isPunctuation);
continue;
}
// See if we can break before the current cluster
if (!aState->mAtStart) {
PRBool canBreak = isPunctuation != aState->mLastCharWasPunctuation
? BreakWordBetweenPunctuation(aState, isPunctuation, isWhitespace, aIsKeyboardSelect)
? BreakWordBetweenPunctuation(aForward ? aState->mLastCharWasPunctuation : isPunctuation,
aIsKeyboardSelect)
: cIter.HaveWordBreakBefore() && aState->mSawBeforeType;
if (canBreak) {
*aOffset = cIter.GetBeforeOffset() - mContentOffset;
return PR_TRUE;
}
}
aState->Update(isPunctuation, isWhitespace);
aState->Update(isPunctuation);
} while (cIter.NextCluster());
*aOffset = cIter.GetAfterOffset() - mContentOffset;

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

@ -31,19 +31,15 @@ function getPrefs() {
.getBranch("layout.word_select.");
}
function setPrefs(eat_space, stop_at_punctuation) {
getPrefs().setBoolPref("eat_space_to_next_word", eat_space);
getPrefs().setBoolPref("stop_at_punctuation", stop_at_punctuation);
eatSpace = eat_space;
function setEatSpace(newValue) {
getPrefs().setBoolPref("eat_space_to_next_word", newValue);
eatSpace = newValue;
}
function restorePrefs() {
function restoreEatSpace() {
try {
getPrefs().clearUserPref("eat_space_to_next_word");
} catch(ex) {}
try {
getPrefs().clearUserPref("stop_at_punctuation");
} catch(ex) {}
}
function test() {
@ -73,7 +69,7 @@ function test() {
var afterEditorNode = document.getElementById("catch").firstChild;
setPrefs(false, true);
setEatSpace(false);
editor.innerHTML = "Hello Kitty";
sel.collapse(editor.firstChild, 0);
@ -107,18 +103,7 @@ function test() {
testLeft(editor.firstChild.firstChild, 4);
testLeft(editor.firstChild.firstChild, 0);
editor.innerHTML = "Set .rc to <b>'</b>quiz'";
sel.collapse(editor.firstChild, 0);
testRight(editor.firstChild, 3);
testRight(editor.firstChild, 7);
testRight(editor.firstChild, 10);
testRight(editor.firstChild.nextSibling.nextSibling, 5);
testLeft(editor.firstChild, 11);
testLeft(editor.firstChild, 8);
testLeft(editor.firstChild, 4);
testLeft(editor.firstChild, 0);
setPrefs(true, true);
setEatSpace(true);
// test basic word movement with eat_space_next_to_word true.
@ -152,18 +137,7 @@ function test() {
testLeft(editor.firstChild.firstChild, 4);
testLeft(editor.firstChild.firstChild, 0);
editor.innerHTML = "Set .rc to <b>'</b>quiz'";
sel.collapse(editor.firstChild, 0);
testRight(editor.firstChild, 4);
testRight(editor.firstChild, 8);
testRight(editor.firstChild.nextSibling.firstChild, 0);
testRight(afterEditorNode, 0);
testLeft(editor.firstChild, 11);
testLeft(editor.firstChild, 8);
testLeft(editor.firstChild, 4);
testLeft(editor.firstChild, 0);
restorePrefs();
restoreEatSpace();
SimpleTest.finish();
}