Bug 961737 - getTextAtOffset is broken w.r.t. embedded object characters, part1, r=tbsaunde

This commit is contained in:
Alexander Surkov 2014-01-22 18:14:06 -05:00
parent 6ceffa63c0
commit 0e7832396a
2 changed files with 23 additions and 12 deletions

View File

@ -331,18 +331,16 @@ HyperTextAccessible::DOMPointToHypertextOffset(nsINode* aNode,
break;
}
// This offset no longer applies because the passed-in text object is not a child
// of the hypertext. This happens when there are nested hypertexts, e.g.
// <div>abc<h1>def</h1>ghi</div>
// If the passed-in DOM point was not on a direct child of the hypertext, we will
// return the offset for that entire hypertext
if (aIsEndOffset) {
// Not inclusive, the indicated char comes at index before this offset
// If the end offset is after the first character of the passed in object, use 1 for
// addTextOffset, to put us after the embedded object char. We'll only treat the offset as
// before the embedded object char if we end at the very beginning of the child.
addTextOffset = addTextOffset > 0;
} else
// This offset no longer applies because the passed-in text object is not
// a child of the hypertext. This happens when there are nested hypertexts,
// e.g. <div>abc<h1>def</h1>ghi</div>. Thus we need to adjust the offset
// to make it relative the hypertext.
// If the end offset is not supposed to be inclusive and the original point
// is not at 0 offset then the returned offset should be after an embedded
// character the original point belongs to.
if (aIsEndOffset)
addTextOffset = (addTextOffset > 0 || descendantAcc->IndexInParent() > 0) ? 1 : 0;
else
addTextOffset = 0;
descendantAcc = parentAcc;

View File

@ -120,6 +120,12 @@
testTextAtOffset([ "li1" ], BOUNDARY_LINE_START,
[ [ 0, 5, kDiscBulletChar + "Item", 0, 5 ] ]);
//////////////////////////////////////////////////////////////////////////
// Nested hypertexts
testTextAtOffset(["ht_5" ], BOUNDARY_LINE_START,
[ [ 0, 0, kEmbedChar, 0, 1 ] ]);
SimpleTest.finish();
}
@ -190,5 +196,12 @@ two words
<ul>
<li id="li1">Item</li>
</ul>
<div id="ht_5">
<div>
<p>sectiounus</p>
<p>seciofarus</p>
</div>
</div>
</body>
</html>