Bug 1740853 - part 2: Make HyperTextAccessible::GetSpellTextAttr take uint32_t for offset in a text node r=Jamie

It takes text node's offset that is never larger than `INT32_T` because
`nsTextFragment` limits max text length of a text node is
`<= NS_MAX_TEXT_FRAGMENT_LENGTH`, that means equals or less than `0x1FFFFFFF`.
So that it must be safe to convert the offset to `uint32_t` from `int32_t`.

Differential Revision: https://phabricator.services.mozilla.com/D131111
This commit is contained in:
Masayuki Nakano 2021-12-09 08:01:31 +00:00
parent c20aaa3bd9
commit 67dfbee062
2 changed files with 12 additions and 9 deletions

View File

@ -1216,8 +1216,13 @@ already_AddRefed<AccAttributes> HyperTextAccessible::TextAttributes(
RenderedToContentOffset(offsetFrame, offsetInAcc, &nodeOffset);
// Set 'misspelled' text attribute.
GetSpellTextAttr(accAtOffset->GetNode(), nodeOffset, &startOffset,
&endOffset, attributes);
// FYI: Max length of text in a text node is less than INT32_MAX (see
// NS_MAX_TEXT_FRAGMENT_LENGTH) so that nodeOffset should always
// be 0 or greater.
MOZ_DIAGNOSTIC_ASSERT(accAtOffset->GetNode()->IsText());
MOZ_DIAGNOSTIC_ASSERT(nodeOffset >= 0);
GetSpellTextAttr(accAtOffset->GetNode(), static_cast<uint32_t>(nodeOffset),
&startOffset, &endOffset, attributes);
}
*aStartOffset = startOffset;
@ -2310,7 +2315,7 @@ nsresult HyperTextAccessible::GetDOMPointByFrameOffset(
}
// HyperTextAccessible
void HyperTextAccessible::GetSpellTextAttr(nsINode* aNode, int32_t aNodeOffset,
void HyperTextAccessible::GetSpellTextAttr(nsINode* aNode, uint32_t aNodeOffset,
uint32_t* aStartOffset,
uint32_t* aEndOffset,
AccAttributes* aAttributes) {
@ -2336,8 +2341,7 @@ void HyperTextAccessible::GetSpellTextAttr(nsINode* aNode, int32_t aNodeOffset,
// case there is another range after this one.
nsINode* endNode = range->GetEndContainer();
uint32_t endNodeOffset = range->EndOffset();
// FYI: Fixed by the following patch.
Maybe<int32_t> order = nsContentUtils::ComparePoints_FixOffset1(
Maybe<int32_t> order = nsContentUtils::ComparePoints(
aNode, aNodeOffset, endNode, endNodeOffset);
if (NS_WARN_IF(!order)) {
continue;
@ -2353,9 +2357,8 @@ void HyperTextAccessible::GetSpellTextAttr(nsINode* aNode, int32_t aNodeOffset,
// must be before the range and after the previous one if any.
nsINode* startNode = range->GetStartContainer();
int32_t startNodeOffset = range->StartOffset();
// FYI: Fixed by the following patch.
order = nsContentUtils::ComparePoints_FixOffset2(startNode, startNodeOffset,
aNode, aNodeOffset);
order = nsContentUtils::ComparePoints(startNode, startNodeOffset, aNode,
aNodeOffset);
if (!order) {
// As (`aNode`, `aNodeOffset`) is comparable to the end of the range, it
// should also be comparable to the range's start. Returning here

View File

@ -436,7 +436,7 @@ class HyperTextAccessible : public AccessibleWrap,
* @param aEndOffset [in, out] the end offset
* @param aAttributes [out, optional] result attributes
*/
void GetSpellTextAttr(nsINode* aNode, int32_t aNodeOffset,
void GetSpellTextAttr(nsINode* aNode, uint32_t aNodeOffset,
uint32_t* aStartOffset, uint32_t* aEndOffset,
AccAttributes* aAttributes);