Bug 1816536 - Fix document edge issues in FindBounary. r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D169726
This commit is contained in:
Eitan Isaacson 2023-02-21 16:37:24 +00:00
Родитель a8c6dc0db1
Коммит 4cdf1e6cc0
3 изменённых файлов: 48 добавлений и 23 удалений

Просмотреть файл

@ -602,6 +602,15 @@ bool TextLeafPoint::operator<=(const TextLeafPoint& aPoint) const {
return *this == aPoint || *this < aPoint;
}
bool TextLeafPoint::IsDocEdge(nsDirection aDirection) const {
if (aDirection == eDirPrevious) {
return mOffset == 0 && !PrevLeaf(mAcc);
}
return mOffset == static_cast<int32_t>(nsAccUtils::TextLength(mAcc)) &&
!NextLeaf(mAcc);
}
bool TextLeafPoint::IsEmptyLastLine() const {
if (mAcc->IsHTMLBr() && mOffset == 1) {
return true;
@ -1103,10 +1112,10 @@ TextLeafPoint TextLeafPoint::FindWordEnd(nsDirection aDirection,
return *this; // Can't go any further.
}
prevIsSpace = prev.IsSpace();
if ((aFlags & BoundaryFlags::eIncludeOrigin) && origIsSpace &&
!prevIsSpace) {
// The origin is space, but the previous character is not. This means
// we're at the end of a word.
if ((aFlags & BoundaryFlags::eIncludeOrigin) &&
(origIsSpace || IsDocEdge(eDirNext)) && !prevIsSpace) {
// The origin is space or end of document, but the previous
// character is not. This means we're at the end of a word.
return *this;
}
}
@ -1129,8 +1138,15 @@ TextLeafPoint TextLeafPoint::FindWordEnd(nsDirection aDirection,
}
}
if (aDirection == eDirNext) {
BoundaryFlags flags = aFlags;
if (IsDocEdge(eDirPrevious)) {
// If this is the start of the doc don't be inclusive in the word-start
// search because there is no preceding block where this could be a
// word-end for.
flags &= ~BoundaryFlags::eIncludeOrigin;
}
boundary = boundary.FindBoundary(nsIAccessibleText::BOUNDARY_WORD_START,
eDirNext, aFlags);
eDirNext, flags);
}
// At this point, boundary is either the start of a word or at a space. A
// word ends at the beginning of consecutive space. Therefore, skip back to
@ -1152,6 +1168,11 @@ TextLeafPoint TextLeafPoint::FindWordEnd(nsDirection aDirection,
TextLeafPoint TextLeafPoint::FindParagraphSameAcc(nsDirection aDirection,
bool aIncludeOrigin) const {
if (aIncludeOrigin && IsDocEdge(eDirPrevious)) {
// The top of the document is a paragraph boundary.
return *this;
}
if (mAcc->IsTextLeaf() &&
// We don't want to copy strings unnecessarily. See below for the context
// of these individual conditions.

Просмотреть файл

@ -194,6 +194,8 @@ class TextLeafPoint final {
private:
bool IsEmptyLastLine() const;
bool IsDocEdge(nsDirection aDirection) const;
char16_t GetChar() const;
TextLeafPoint FindLineStartSameRemoteAcc(nsDirection aDirection,

Просмотреть файл

@ -117,11 +117,7 @@ the <strong>big</strong> rug.</p>
BOUNDARY_WORD_END,
DIRECTION_NEXT,
expectedWordEndSequence,
"Forward BOUNDARY_WORD_END sequence is correct",
{
// XXX: Includes first point in doc which is not a word end
todo: true,
}
"Forward BOUNDARY_WORD_END sequence is correct"
);
testBoundarySequence(
@ -129,11 +125,7 @@ the <strong>big</strong> rug.</p>
BOUNDARY_WORD_END,
DIRECTION_PREVIOUS,
[readablePoint(firstPoint), ...expectedWordEndSequence].reverse(),
"Backward BOUNDARY_WORD_END sequence is correct",
{
// XXX: Doesn't include last point in doc which is a word end
todo: true,
}
"Backward BOUNDARY_WORD_END sequence is correct"
);
const expectedLineStartSequence = [
@ -265,9 +257,8 @@ on a <span style="display: block;">rug</span></p>
<li>Three</li>
</ul>`,
function(browser, docAcc) {
const container = findAccessibleChildByID(docAcc, "p");
const firstPoint = createTextLeafPoint(container, 0);
const lastPoint = createTextLeafPoint(container, kTextEndOffset);
const firstPoint = createTextLeafPoint(docAcc, 0);
const lastPoint = createTextLeafPoint(docAcc, kTextEndOffset);
const expectedParagraphStart = [
["A bug\non a ", 0],
@ -283,11 +274,22 @@ on a <span style="display: block;">rug</span></p>
BOUNDARY_PARAGRAPH,
DIRECTION_NEXT,
[...expectedParagraphStart, readablePoint(lastPoint)],
"Forward BOUNDARY_PARAGRAPH sequence is correct",
{
// XXX: Missing the first paragraph start.
todo: true,
}
"Forward BOUNDARY_PARAGRAPH sequence is correct"
);
const paragraphStart = createTextLeafPoint(
findAccessibleChildByID(docAcc, "p2").firstChild,
0
);
const wordEnd = paragraphStart.findBoundary(
BOUNDARY_WORD_END,
DIRECTION_NEXT,
BOUNDARY_FLAG_INCLUDE_ORIGIN
);
testPointEqual(
wordEnd,
paragraphStart,
"The word end from the previous block is the first point in this block"
);
},
{ chrome: true, topLevel: isCacheEnabled, iframe: false, remoteIframe: false }