Bug 935254 - getTextAt broken for list items, r=tbsaunde

This commit is contained in:
Alexander Surkov 2013-12-10 07:40:54 -05:00
parent e04ac8799a
commit 9ac1ccac2d
6 changed files with 54 additions and 25 deletions

View File

@ -658,30 +658,15 @@ HyperTextAccessible::FindOffset(int32_t aOffset, nsDirection aDirection,
// Turn the resulting node and offset into a hyperTextOffset
// If finalAccessible is nullptr, then DOMPointToHypertextOffset() searched
// through the hypertext children without finding the node/offset position.
int32_t hyperTextOffset;
int32_t hyperTextOffset = 0;
Accessible* finalAccessible =
DOMPointToHypertextOffset(pos.mResultContent, pos.mContentOffset,
&hyperTextOffset, aDirection == eDirNext);
if (!finalAccessible && aDirection == eDirPrevious) {
// If we reached the end during search, this means we didn't find the DOM point
// and we're actually at the start of the paragraph
hyperTextOffset = 0;
}
else if (aAmount == eSelectBeginLine) {
Accessible* firstChild = mChildren.SafeElementAt(0, nullptr);
// For line selection with needsStart, set start of line exactly to line break
if (pos.mContentOffset == 0 && firstChild &&
firstChild->Role() == roles::STATICTEXT &&
static_cast<int32_t>(nsAccUtils::TextLength(firstChild)) == hyperTextOffset) {
// XXX Bullet hack -- we should remove this once list bullets use anonymous content
hyperTextOffset = 0;
}
if (aWordMovementType != eStartWord && aAmount != eSelectBeginLine &&
hyperTextOffset > 0) {
-- hyperTextOffset;
}
}
// If we reached the end during search, this means we didn't find the DOM point
// and we're actually at the start of the paragraph
if (!finalAccessible && aDirection == eDirPrevious)
return 0;
return hyperTextOffset;
}

View File

@ -432,9 +432,9 @@ protected:
* Return an offset corresponding to the given direction and selection amount
* relative the given offset. A helper used to find word or line boundaries.
*/
int32_t FindOffset(int32_t aOffset, nsDirection aDirection,
nsSelectionAmount aAmount,
EWordMovementType aWordMovementType = eDefaultBehavior);
virtual int32_t FindOffset(int32_t aOffset, nsDirection aDirection,
nsSelectionAmount aAmount,
EWordMovementType aWordMovementType = eDefaultBehavior);
/**
* Provides information for substring that is defined by the given start

View File

@ -7,6 +7,7 @@
#include "HTMLListAccessible.h"
#include "DocAccessible.h"
#include "nsAccUtils.h"
#include "Role.h"
#include "States.h"
@ -97,6 +98,33 @@ HTMLLIAccessible::GetBounds(int32_t* aX, int32_t* aY,
return NS_OK;
}
int32_t
HTMLLIAccessible::FindOffset(int32_t aOffset, nsDirection aDirection,
nsSelectionAmount aAmount,
EWordMovementType aWordMovementType)
{
Accessible* child = GetChildAtOffset(aOffset);
if (!child)
return -1;
if (child != mBullet) {
if (aDirection == eDirPrevious &&
(aAmount == eSelectBeginLine || aAmount == eSelectLine))
return 0;
return HyperTextAccessible::FindOffset(aOffset, aDirection,
aAmount, aWordMovementType);
}
if (aDirection == eDirPrevious)
return 0;
if (aAmount == eSelectEndLine || aAmount == eSelectLine)
return CharacterCount();
return nsAccUtils::TextLength(child);
}
////////////////////////////////////////////////////////////////////////////////
// HTMLLIAccessible: public

View File

@ -55,7 +55,12 @@ public:
virtual a11y::role NativeRole();
virtual uint64_t NativeState();
// nsHTMLLIAccessible
// HyperTextAccessible
virtual int32_t FindOffset(int32_t aOffset, nsDirection aDirection,
nsSelectionAmount aAmount,
EWordMovementType aWordMovementType) MOZ_OVERRIDE;
// HTMLLIAccessible
void UpdateBullet(bool aHasBullet);
protected:

View File

@ -79,7 +79,8 @@ const COORDTYPE_PARENT_RELATIVE = nsIAccessibleCoordinateType.COORDTYPE_PARENT_R
const kEmbedChar = String.fromCharCode(0xfffc);
const kDiscBulletText = String.fromCharCode(0x2022) + " ";
const kDiscBulletChar = String.fromCharCode(0x2022);
const kDiscBulletText = kDiscBulletChar + " ";
const kCircleBulletText = String.fromCharCode(0x25e6) + " ";
const kSquareBulletText = String.fromCharCode(0x25aa) + " ";

View File

@ -108,6 +108,12 @@
BOUNDARY_LINE_START,
[ [ 0, 3, "foo\n", 0, 4 ], [ 4, 4, "", 4, 4 ] ]);
//////////////////////////////////////////////////////////////////////////
// list items
testTextAtOffset([ "li1" ], BOUNDARY_LINE_START,
[ [ 0, 5, kDiscBulletChar + "Item", 0, 5 ] ]);
SimpleTest.finish();
}
@ -166,5 +172,9 @@ two words
<iframe id="ht_2" src="data:text/html,<div contentEditable='true'>foo<br/></div>"></iframe>
<iframe id="ht_3" src="data:text/html,<div contentEditable='true'>foo<br/><br/></div>"></iframe>
<ul>
<li id="li1">Item</li>
</ul>
</body>
</html>