Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 5b1b8e0

Browse files
committed
Bug 1901464 part 1: TextLeafRange::WalkLineRects: Pass the TextLeafRange for each line to the callback. r=nlapre
This will be used in a subsequent patch to fetch the sub-ranges for visible lines. Differential Revision: https://phabricator.services.mozilla.com/D236088
1 parent 10e2477 commit 5b1b8e0

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

accessible/base/TextLeafRange.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,8 +2058,8 @@ bool TextLeafRange::Crop(Accessible* aContainer) {
20582058
LayoutDeviceIntRect TextLeafRange::Bounds() const {
20592059
// Walk all the lines and union them into the result rectangle.
20602060
LayoutDeviceIntRect result = TextLeafPoint{mStart}.CharBounds();
2061-
const bool succeeded =
2062-
WalkLineRects([&result](LayoutDeviceIntRect aLineRect) {
2061+
const bool succeeded = WalkLineRects(
2062+
[&result](TextLeafRange aLine, LayoutDeviceIntRect aLineRect) {
20632063
result.UnionRect(result, aLineRect);
20642064
});
20652065

@@ -2078,7 +2078,8 @@ nsTArray<LayoutDeviceIntRect> TextLeafRange::LineRects() const {
20782078
}
20792079

20802080
nsTArray<LayoutDeviceIntRect> lineRects;
2081-
WalkLineRects([&lineRects, &contentBounds](LayoutDeviceIntRect aLineRect) {
2081+
WalkLineRects([&lineRects, &contentBounds](TextLeafRange aLine,
2082+
LayoutDeviceIntRect aLineRect) {
20822083
// Clip the bounds to the bounds of the content area.
20832084
bool boundsVisible = true;
20842085
if (contentBounds.isSome()) {
@@ -2253,22 +2254,25 @@ bool TextLeafRange::WalkLineRects(LineRectCallback aCallback) const {
22532254
// start of the next line and going back one char. We don't
22542255
// use BOUNDARY_LINE_END here because it is equivalent to LINE_START when
22552256
// the line doesn't end with a line feed character.
2256-
TextLeafPoint lineStartPoint = currPoint.FindBoundary(
2257+
TextLeafPoint nextLineStartPoint = currPoint.FindBoundary(
22572258
nsIAccessibleText::BOUNDARY_LINE_START, eDirNext);
2258-
TextLeafPoint lastPointInLine = lineStartPoint.FindBoundary(
2259+
TextLeafPoint lastPointInLine = nextLineStartPoint.FindBoundary(
22592260
nsIAccessibleText::BOUNDARY_CHAR, eDirPrevious);
2260-
// If currPoint is the end of the document, lineStartPoint will be equal
2261+
// If currPoint is the end of the document, nextLineStartPoint will be equal
22612262
// to currPoint and we would be in an endless loop.
2262-
if (lineStartPoint == currPoint || mEnd <= lastPointInLine) {
2263+
if (nextLineStartPoint == currPoint || mEnd <= lastPointInLine) {
22632264
lastPointInLine = mEnd;
22642265
locatedFinalLine = true;
22652266
}
22662267

2267-
LayoutDeviceIntRect currLine = currPoint.CharBounds();
2268-
currLine.UnionRect(currLine, lastPointInLine.CharBounds());
2269-
aCallback(currLine);
2268+
LayoutDeviceIntRect currLineRect = currPoint.CharBounds();
2269+
currLineRect.UnionRect(currLineRect, lastPointInLine.CharBounds());
2270+
// The range we pass must include the last character and range ends are
2271+
// exclusive, hence the use of nextLineStartPoint.
2272+
TextLeafRange currLine = TextLeafRange(currPoint, nextLineStartPoint);
2273+
aCallback(currLine, currLineRect);
22702274

2271-
currPoint = lineStartPoint;
2275+
currPoint = nextLineStartPoint;
22722276
}
22732277
return true;
22742278
}

accessible/base/TextLeafRange.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,14 @@ class TextLeafRange final {
335335

336336
/*
337337
* Walk all of the lines within the TextLeafRange. This function invokes the
338-
* given callback with each line-bounding rectangle. The bounds are inclusive
339-
* of all characters in each line. Each rectangle is screen-relative. The
340-
* function returns true if it walks any lines, and false if it could not walk
341-
* any rects, which could happen if the start and end points are improperly
342-
* positioned.
338+
* given callback with the sub-range for each line and the line's bounding
339+
* rectangle. The bounds are inclusive of all characters in each line. Each
340+
* rectangle is screen-relative. The function returns true if it walks any
341+
* lines, and false if it could not walk any rects, which could happen if the
342+
* start and end points are improperly positioned.
343343
*/
344-
using LineRectCallback = FunctionRef<void(LayoutDeviceIntRect)>;
344+
using LineRectCallback =
345+
FunctionRef<void(TextLeafRange, LayoutDeviceIntRect)>;
345346
bool WalkLineRects(LineRectCallback aCallback) const;
346347

347348
public:

0 commit comments

Comments
 (0)