diff --git a/accessible/src/generic/HyperTextAccessible.cpp b/accessible/src/generic/HyperTextAccessible.cpp index 5d56f6c0e992..3770733b8e00 100644 --- a/accessible/src/generic/HyperTextAccessible.cpp +++ b/accessible/src/generic/HyperTextAccessible.cpp @@ -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(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; } diff --git a/accessible/src/generic/HyperTextAccessible.h b/accessible/src/generic/HyperTextAccessible.h index 1565f77c9345..b7b33fa378d1 100644 --- a/accessible/src/generic/HyperTextAccessible.h +++ b/accessible/src/generic/HyperTextAccessible.h @@ -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 diff --git a/accessible/src/html/HTMLListAccessible.cpp b/accessible/src/html/HTMLListAccessible.cpp index 7b21a719b8df..ef14543e433d 100644 --- a/accessible/src/html/HTMLListAccessible.cpp +++ b/accessible/src/html/HTMLListAccessible.cpp @@ -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 diff --git a/accessible/src/html/HTMLListAccessible.h b/accessible/src/html/HTMLListAccessible.h index 8b7aa1e1ebb1..b02ba1df1ee8 100644 --- a/accessible/src/html/HTMLListAccessible.h +++ b/accessible/src/html/HTMLListAccessible.h @@ -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: diff --git a/accessible/tests/mochitest/common.js b/accessible/tests/mochitest/common.js index b7c450bbdcc6..6d5ee871b673 100644 --- a/accessible/tests/mochitest/common.js +++ b/accessible/tests/mochitest/common.js @@ -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) + " "; diff --git a/accessible/tests/mochitest/text/test_lineboundary.html b/accessible/tests/mochitest/text/test_lineboundary.html index 8f9bb0ca5a02..d2886fb31a56 100644 --- a/accessible/tests/mochitest/text/test_lineboundary.html +++ b/accessible/tests/mochitest/text/test_lineboundary.html @@ -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 + +