Bug 879130 - getTextBeforeOffset line end boundary is on new rails, r=tbsaunde

This commit is contained in:
Alexander Surkov 2013-07-12 13:34:13 -04:00
parent 538d6c1103
commit 9e12a2556a
5 changed files with 71 additions and 84 deletions

View File

@ -1035,14 +1035,10 @@ HyperTextAccessible::GetTextBeforeOffset(int32_t aOffset,
// If we are at last empty then home key and get the text (last empty line // If we are at last empty then home key and get the text (last empty line
// doesn't have own frame). // doesn't have own frame).
if (offset == CharacterCount()) { if (IsEmptyLastLineOffset(offset)) {
nsAutoString lastChar; *aStartOffset = FindLineBoundary(offset, eDirPrevious, eSelectBeginLine);
GetText(offset -1, -1, lastChar); *aEndOffset = offset;
if (lastChar.EqualsLiteral("\n")) { return GetText(*aStartOffset, *aEndOffset, aText);
*aStartOffset = FindLineBoundary(offset, eDirPrevious, eSelectBeginLine);
*aEndOffset = offset;
return GetText(*aStartOffset, *aEndOffset, aText);
}
} }
// Home key, up arrow, home key. // Home key, up arrow, home key.
@ -1053,7 +1049,35 @@ HyperTextAccessible::GetTextBeforeOffset(int32_t aOffset,
return GetText(*aStartOffset, *aEndOffset, aText); return GetText(*aStartOffset, *aEndOffset, aText);
} }
case BOUNDARY_LINE_END: case BOUNDARY_LINE_END: {
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
offset = AdjustCaretOffset(offset);
// Nothing if we are at first line.
int32_t tmpOffset = FindLineBoundary(offset, eDirPrevious, eSelectBeginLine);
if (tmpOffset == 0) {
*aStartOffset = *aEndOffset = 0;
return NS_OK;
}
// Up arrow, end key to find previous line endings.
if (IsEmptyLastLineOffset(offset)) { // no own frame for a last line
tmpOffset = FindLineBoundary(offset, eDirPrevious, eSelectLine);
*aStartOffset = FindLineBoundary(tmpOffset, eDirNext, eSelectEndLine);
*aEndOffset = offset - 1;
return GetText(*aStartOffset, *aEndOffset, aText);
}
tmpOffset = FindLineBoundary(offset, eDirPrevious, eSelectLine);
*aEndOffset = FindLineBoundary(tmpOffset, eDirNext, eSelectEndLine);
tmpOffset = FindLineBoundary(*aEndOffset, eDirPrevious, eSelectLine);
*aStartOffset = FindLineBoundary(tmpOffset, eDirNext, eSelectEndLine);
if (*aStartOffset == *aEndOffset) // we are at second line
*aStartOffset = 0;
return GetText(*aStartOffset, *aEndOffset, aText);
}
case BOUNDARY_ATTRIBUTE_RANGE: case BOUNDARY_ATTRIBUTE_RANGE:
return GetTextHelper(eGetBefore, aBoundaryType, aOffset, return GetTextHelper(eGetBefore, aBoundaryType, aOffset,
aStartOffset, aEndOffset, aText); aStartOffset, aEndOffset, aText);
@ -1098,13 +1122,9 @@ HyperTextAccessible::GetTextAtOffset(int32_t aOffset,
// Empty last line doesn't have own frame (a previous line contains '\n' // Empty last line doesn't have own frame (a previous line contains '\n'
// character instead) thus we can't operate on last line separately // character instead) thus we can't operate on last line separately
// from previous line. // from previous line.
if (offset == CharacterCount()) { if (IsEmptyLastLineOffset(offset)) {
nsAutoString lastChar; *aStartOffset = *aEndOffset = offset;
GetText(offset -1, -1, lastChar); return NS_OK;
if (lastChar.EqualsLiteral("\n")) {
*aStartOffset = *aEndOffset = offset;
return NS_OK;
}
} }
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
@ -1124,15 +1144,11 @@ HyperTextAccessible::GetTextAtOffset(int32_t aOffset,
// Empty last line doesn't have own frame (a previous line contains '\n' // Empty last line doesn't have own frame (a previous line contains '\n'
// character instead) thus we can't operate on last line separately // character instead) thus we can't operate on last line separately
// from the previous line. // from the previous line.
if (offset == CharacterCount()) { if (IsEmptyLastLineOffset(offset)) {
nsAutoString lastChar; *aStartOffset = offset - 1;
GetText(offset -1, -1, lastChar); *aEndOffset = offset;
if (lastChar.EqualsLiteral("\n")) { aText.AssignLiteral("\n");
*aStartOffset = offset - 1; return NS_OK;
*aEndOffset = offset;
aText = lastChar;
return NS_OK;
}
} }
if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET) if (aOffset == nsIAccessibleText::TEXT_OFFSET_CARET)

View File

@ -283,6 +283,19 @@ protected:
return aOffset; return aOffset;
} }
/**
* Return true if the given offset points to terminal empty line if any.
*/
bool IsEmptyLastLineOffset(int32_t aOffset)
{
if (aOffset != static_cast<int32_t>(CharacterCount()))
return false;
nsAutoString lastChar;
GetText(aOffset -1, -1, lastChar);
return lastChar.EqualsLiteral("\n");
}
/** /**
* Return an offset of the found word boundary. * Return an offset of the found word boundary.
*/ */

View File

@ -56,7 +56,7 @@
[ "textarea" ]); [ "textarea" ]);
testTextBeforeOffset(kCaretOffset, BOUNDARY_LINE_END, "\ntwo ", 5, 10, testTextBeforeOffset(kCaretOffset, BOUNDARY_LINE_END, "\ntwo ", 5, 10,
"textarea", kTodo, kTodo, kTodo); "textarea", kTodo, kTodo, kOk);
} }
this.getID = function moveToLastLineEnd_getID() this.getID = function moveToLastLineEnd_getID()
@ -119,7 +119,7 @@
[ "textarea" ]); [ "textarea" ]);
testTextBeforeOffset(kCaretOffset, BOUNDARY_LINE_END, "aword", 0, 5, testTextBeforeOffset(kCaretOffset, BOUNDARY_LINE_END, "aword", 0, 5,
"textarea", kTodo, kTodo, kTodo); [ "textarea" ]);
} }
this.getID = function moveToMiddleLineStart_getID() this.getID = function moveToMiddleLineStart_getID()
@ -150,7 +150,7 @@
[ "textarea" ]); [ "textarea" ]);
testTextBeforeOffset(kCaretOffset, BOUNDARY_LINE_END, "aword", 0, 5, testTextBeforeOffset(kCaretOffset, BOUNDARY_LINE_END, "aword", 0, 5,
"textarea", kTodo, kTodo, kTodo); [ "textarea" ]);
} }
this.getID = function moveToMiddleLineEnd_getID() this.getID = function moveToMiddleLineEnd_getID()
@ -212,7 +212,7 @@
[ "textarea" ]); [ "textarea" ]);
testTextBeforeOffset(kCaretOffset, BOUNDARY_LINE_END, "", 0, 0, testTextBeforeOffset(kCaretOffset, BOUNDARY_LINE_END, "", 0, 0,
"textarea", kTodo, kOk, kTodo); [ "textarea" ]);
} }
this.getID = function moveToFirstLineEnd_getID() this.getID = function moveToFirstLineEnd_getID()
@ -224,7 +224,7 @@
var gQueue = null; var gQueue = null;
function doTest() function doTest()
{ {
SimpleTest.expectAssertions(3); SimpleTest.expectAssertions(1);
gQueue = new eventQueue(); gQueue = new eventQueue();
gQueue.push(new moveToLastLineEnd()); gQueue.push(new moveToLastLineEnd());

View File

@ -16,7 +16,7 @@
function doTest() function doTest()
{ {
SimpleTest.expectAssertions(20); SimpleTest.expectAssertions(5);
// __o__n__e__w__o__r__d__\n // __o__n__e__w__o__r__d__\n
// 0 1 2 3 4 5 6 7 // 0 1 2 3 4 5 6 7
@ -114,42 +114,12 @@
testTextBeforeOffset(19, BOUNDARY_LINE_START, "two words\n", 9, 19, IDs); testTextBeforeOffset(19, BOUNDARY_LINE_START, "two words\n", 9, 19, IDs);
// BOUNDARY_LINE_END // BOUNDARY_LINE_END
testTextBeforeOffset(0, BOUNDARY_LINE_END, "", 0, 0, testTextBeforeOffset(0, BOUNDARY_LINE_END, "", 0, 0, IDs);
"div", kOk, kOk, kOk, testTextBeforeOffset(7, BOUNDARY_LINE_END, "", 0, 0, IDs);
"divbr", kOk, kOk, kOk, testTextBeforeOffset(8, BOUNDARY_LINE_END, "oneword", 0, 7, IDs);
"editable", kOk, kOk, kOk, testTextBeforeOffset(9, BOUNDARY_LINE_END, "\n", 7, 8, IDs);
"editablebr", kOk, kOk, kOk, testTextBeforeOffset(18, BOUNDARY_LINE_END, "\n", 7, 8, IDs);
"textarea", kOk, kOk, kOk); testTextBeforeOffset(19, BOUNDARY_LINE_END, "\ntwo words", 8, 18, IDs);
testTextBeforeOffset(7, BOUNDARY_LINE_END, "", 0, 0,
"div", kOk, kTodo, kTodo,
"divbr", kOk, kTodo, kTodo,
"editable", kOk, kTodo, kTodo,
"editablebr", kOk, kTodo, kTodo,
"textarea", kOk, kTodo, kTodo);
testTextBeforeOffset(8, BOUNDARY_LINE_END, "oneword", 0, 7,
"div", kTodo, kTodo, kTodo,
"divbr", kTodo, kTodo, kTodo,
"editable", kTodo, kTodo, kTodo,
"editablebr", kTodo, kTodo, kTodo,
"textarea", kTodo, kTodo, kTodo);
testTextBeforeOffset(9, BOUNDARY_LINE_END, "\n", 7, 8,
"div", kOk, kTodo, kTodo,
"divbr", kOk, kTodo, kTodo,
"editable", kOk, kTodo, kTodo,
"editablebr", kOk, kTodo, kTodo,
"textarea", kOk, kTodo, kTodo);
testTextBeforeOffset(18, BOUNDARY_LINE_END, "\n", 7, 8,
"div", kTodo, kTodo, kTodo,
"divbr", kTodo, kTodo, kTodo,
"editable", kTodo, kTodo, kTodo,
"editablebr", kTodo, kTodo, kTodo,
"textarea", kTodo, kTodo, kTodo);
testTextBeforeOffset(19, BOUNDARY_LINE_END, "\ntwo words", 8, 18,
"div", kTodo, kTodo, kTodo,
"divbr", kTodo, kTodo, kTodo,
"editable", kTodo, kTodo, kTodo,
"editablebr", kTodo, kTodo, kTodo,
"textarea", kTodo, kTodo, kTodo);
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// getTextAtOffset // getTextAtOffset

View File

@ -12,9 +12,9 @@
src="../text.js"></script> src="../text.js"></script>
<script type="application/javascript"> <script type="application/javascript">
if (navigator.platform.startsWith("Mac")) { if (navigator.platform.startsWith("Mac")) {
SimpleTest.expectAssertions(0, 8); SimpleTest.expectAssertions(0, 4);
} else { } else {
SimpleTest.expectAssertions(8); SimpleTest.expectAssertions(4);
} }
function doTest() function doTest()
@ -84,21 +84,9 @@
testTextBeforeOffset(15, BOUNDARY_LINE_START, "", 0, 0, IDs); testTextBeforeOffset(15, BOUNDARY_LINE_START, "", 0, 0, IDs);
// BOUNDARY_LINE_END // BOUNDARY_LINE_END
testTextBeforeOffset(0, BOUNDARY_LINE_END, "", 0, 0, testTextBeforeOffset(0, BOUNDARY_LINE_END, "", 0, 0, IDs);
"input", kOk, kOk, kOk, testTextBeforeOffset(1, BOUNDARY_LINE_END, "", 0, 0, IDs);
"div", kOk, kOk, kOk, testTextBeforeOffset(14, BOUNDARY_LINE_END, "", 0, 0, IDs);
"editable", kOk, kOk, kOk,
"textarea", kOk, kOk, kOk);
testTextBeforeOffset(1, BOUNDARY_LINE_END, "", 0, 0,
"input", kTodo, kOk, kTodo,
"div", kTodo, kOk, kTodo,
"editable", kTodo, kOk, kTodo,
"textarea", kTodo, kOk, kTodo);
testTextBeforeOffset(14, BOUNDARY_LINE_END, "", 0, 0,
"input", kTodo, kOk, kTodo,
"div", kTodo, kOk, kTodo,
"editable", kTodo, kOk, kTodo,
"textarea", kTodo, kOk, kTodo);
testTextBeforeOffset(15, BOUNDARY_LINE_END, "", 0, 0, IDs); testTextBeforeOffset(15, BOUNDARY_LINE_END, "", 0, 0, IDs);
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////