зеркало из https://github.com/mozilla/gecko-dev.git
Bug 630001, part3 - rewrite GetText, r=davidb, a=betaN
This commit is contained in:
Родитель
d895529e1f
Коммит
5310cfe475
|
@ -474,12 +474,62 @@ nsHyperTextAccessible::GetPosAndText(PRInt32& aStartOffset, PRInt32& aEndOffset,
|
|||
return startFrame;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHyperTextAccessible::GetText(PRInt32 aStartOffset, PRInt32 aEndOffset, nsAString &aText)
|
||||
NS_IMETHODIMP
|
||||
nsHyperTextAccessible::GetText(PRInt32 aStartOffset, PRInt32 aEndOffset,
|
||||
nsAString &aText)
|
||||
{
|
||||
aText.Truncate();
|
||||
|
||||
if (IsDefunct())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return GetPosAndText(aStartOffset, aEndOffset, &aText) ? NS_OK : NS_ERROR_FAILURE;
|
||||
if (aStartOffset == nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT)
|
||||
aStartOffset = CharacterCount();
|
||||
else if (aStartOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
||||
GetCaretOffset(&aStartOffset);
|
||||
|
||||
if (aEndOffset == nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT)
|
||||
aEndOffset = CharacterCount();
|
||||
else if (aEndOffset == nsIAccessibleText::TEXT_OFFSET_CARET)
|
||||
GetCaretOffset(&aEndOffset);
|
||||
|
||||
PRInt32 startChildIdx = GetChildIndexAtOffset(aStartOffset);
|
||||
if (startChildIdx == -1)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
PRInt32 endChildIdx = GetChildIndexAtOffset(aEndOffset);
|
||||
if (endChildIdx == -1)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (startChildIdx == endChildIdx) {
|
||||
PRInt32 childOffset = GetChildOffset(startChildIdx);
|
||||
NS_ENSURE_STATE(childOffset != -1);
|
||||
|
||||
nsAccessible* child = GetChildAt(startChildIdx);
|
||||
child->AppendTextTo(aText, aStartOffset - childOffset,
|
||||
aEndOffset - aStartOffset);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32 startChildOffset = GetChildOffset(startChildIdx);
|
||||
NS_ENSURE_STATE(startChildOffset != -1);
|
||||
|
||||
nsAccessible* startChild = GetChildAt(startChildIdx);
|
||||
startChild->AppendTextTo(aText, aStartOffset - startChildOffset);
|
||||
|
||||
for (PRInt32 childIdx = startChildIdx + 1; childIdx < endChildIdx; childIdx++) {
|
||||
nsAccessible* child = GetChildAt(childIdx);
|
||||
child->AppendTextTo(aText);
|
||||
}
|
||||
|
||||
PRInt32 endChildOffset = GetChildOffset(endChildIdx);
|
||||
NS_ENSURE_STATE(endChildOffset != -1);
|
||||
|
||||
nsAccessible* endChild = GetChildAt(endChildIdx);
|
||||
endChild->AppendTextTo(aText, 0, aEndOffset - endChildOffset);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -19,7 +19,7 @@ const kOk = 2;
|
|||
*/
|
||||
function testCharacterCount(aIDs, aCount)
|
||||
{
|
||||
for (var i = 1; i < aIDs.length; i++) {
|
||||
for (var i = 0; i < aIDs.length; i++) {
|
||||
var textacc = getAccessible(aIDs[i], [nsIAccessibleText]);
|
||||
is(textacc.characterCount, aCount,
|
||||
"Wrong character count for " + prettyName(aIDs[i]));
|
||||
|
|
|
@ -48,6 +48,7 @@ include $(topsrcdir)/config/rules.mk
|
|||
_TEST_FILES = \
|
||||
doc.html \
|
||||
test_doc.html \
|
||||
test_hypertext.html \
|
||||
test_singleline.html \
|
||||
test_whitespaces.html \
|
||||
test_words.html \
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>nsIAccessibleText getText related function tests for rich text</title>
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="../common.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="../text.js"></script>
|
||||
|
||||
<script type="application/javascript">
|
||||
function doTest()
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// hypertext
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ! - embedded object char
|
||||
// @ - imaginary object char, space is used
|
||||
// __h__e__l__l__o__ __!__ __s__e__e__ __@__
|
||||
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13
|
||||
|
||||
var IDs = [ "hypertext" ];
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// characterCount
|
||||
|
||||
testCharacterCount(IDs, 13);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// getText
|
||||
|
||||
testText(IDs, 0, 1, "h");
|
||||
testText(IDs, 5, 7, " " + kEmbedChar);
|
||||
testText(IDs, 10, 13, "e ");
|
||||
testText(IDs, 0, 13, "hello " + kEmbedChar + " see ");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// list
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IDs = [ "list" ];
|
||||
testCharacterCount(IDs, 1);
|
||||
testText(IDs, 0, 1, kEmbedChar);
|
||||
|
||||
IDs = [ "listitem" ];
|
||||
testCharacterCount(IDs, 5);
|
||||
testText(IDs, 0, 5, "1.foo");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addA11yLoadEvent(doTest);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<a target="_blank"
|
||||
title="Fix getText"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=630001">Mozilla Bug 630001, part3</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
|
||||
<div id="hypertext">hello <a>friend</a> see <img></div>
|
||||
<ol id="list"><li id="listitem">foo</li></ol>
|
||||
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче