Bug 1661760 - Part 3: Add line boundary support in mac. r=morgan

The left and right line getters don't seem to be used often by voiceover,
so I am not sure if they always return the expected result.

Differential Revision: https://phabricator.services.mozilla.com/D90938
This commit is contained in:
Eitan Isaacson 2020-09-24 16:04:56 +00:00
parent f770fa368b
commit 1080fb58d3
9 changed files with 1275 additions and 306 deletions

View File

@ -79,7 +79,7 @@ template <>
struct ParamTraits<mozilla::a11y::EWhichRange>
: public ContiguousEnumSerializerInclusive<
mozilla::a11y::EWhichRange, mozilla::a11y::EWhichRange::eLeftWord,
mozilla::a11y::EWhichRange::eRightWord> {};
mozilla::a11y::EWhichRange::eRightLine> {};
} // namespace IPC

View File

@ -69,6 +69,10 @@ class HyperTextAccessibleWrap : public HyperTextAccessible {
void RightWordAt(int32_t aOffset, HyperTextAccessible** aStartContainer,
int32_t* aStartOffset, HyperTextAccessible** aEndContainer,
int32_t* aEndOffset);
void LineAt(int32_t aOffset, bool aNextLine,
HyperTextAccessible** aStartContainer, int32_t* aStartOffset,
HyperTextAccessible** aEndContainer, int32_t* aEndOffset);
};
} // namespace a11y

View File

@ -261,6 +261,15 @@ void HyperTextAccessibleWrap::RangeAt(int32_t aOffset, EWhichRange aRangeType,
RightWordAt(aOffset, aStartContainer, aStartOffset, aEndContainer,
aEndOffset);
break;
case EWhichRange::eLine:
case EWhichRange::eLeftLine:
LineAt(aOffset, false, aStartContainer, aStartOffset, aEndContainer,
aEndOffset);
break;
case EWhichRange::eRightLine:
LineAt(aOffset, true, aStartContainer, aStartOffset, aEndContainer,
aEndOffset);
break;
default:
break;
}
@ -341,6 +350,42 @@ void HyperTextAccessibleWrap::RightWordAt(int32_t aOffset,
}
}
void HyperTextAccessibleWrap::LineAt(int32_t aOffset, bool aNextLine,
HyperTextAccessible** aStartContainer,
int32_t* aStartOffset,
HyperTextAccessible** aEndContainer,
int32_t* aEndOffset) {
TextPoint here(this, aOffset);
TextPoint end =
FindTextPoint(aOffset, eDirNext, eSelectEndLine, eDefaultBehavior);
if (!end.mContainer || end < here) {
// If we didn't find a word end, or if we wrapped around (bug 1652833),
// return with no result.
return;
}
TextPoint start = static_cast<HyperTextAccessibleWrap*>(end.mContainer)
->FindTextPoint(end.mOffset, eDirPrevious,
eSelectBeginLine, eDefaultBehavior);
if (!aNextLine && here < start) {
start = FindTextPoint(aOffset, eDirPrevious, eSelectBeginLine,
eDefaultBehavior);
if (!start.mContainer) {
return;
}
end = static_cast<HyperTextAccessibleWrap*>(start.mContainer)
->FindTextPoint(start.mOffset, eDirNext, eSelectEndLine,
eDefaultBehavior);
}
*aStartContainer = start.mContainer;
*aEndContainer = end.mContainer;
*aStartOffset = start.mOffset;
*aEndOffset = end.mOffset;
}
void HyperTextAccessibleWrap::NextClusterAt(
int32_t aOffset, HyperTextAccessible** aNextContainer,
int32_t* aNextOffset) {

View File

@ -410,6 +410,16 @@
// AXTextMarkerRangeForUIElement
- (id _Nullable)moxTextMarkerRangeForUIElement:(id _Nonnull)element;
// AXLineTextMarkerRangeForTextMarker
- (id _Nullable)moxLineTextMarkerRangeForTextMarker:(id _Nonnull)textMarker;
// AXLeftLineTextMarkerRangeForTextMarker
- (id _Nullable)moxLeftLineTextMarkerRangeForTextMarker:(id _Nonnull)textMarker;
// AXRightLineTextMarkerRangeForTextMarker
- (id _Nullable)moxRightLineTextMarkerRangeForTextMarker:
(id _Nonnull)textMarker;
#pragma mark - TextAttributeSetters
// AXSelectedTextMarkerRange

View File

@ -61,6 +61,15 @@
// override
- (id)moxRightWordTextMarkerRangeForTextMarker:(id)textMarker;
// override
- (id)moxLineTextMarkerRangeForTextMarker:(id)textMarker;
// override
- (id)moxLeftLineTextMarkerRangeForTextMarker:(id)textMarker;
// override
- (id)moxRightLineTextMarkerRangeForTextMarker:(id)textMarker;
// override
- (id)moxNextTextMarkerForTextMarker:(id)textMarker;

View File

@ -180,6 +180,35 @@ static nsDataHashtable<nsUint64HashKey, MOXTextMarkerDelegate*> sDelegates;
.CreateAXTextMarkerRange();
}
- (id)moxLineTextMarkerRangeForTextMarker:(id)textMarker {
GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker);
if (!geckoTextMarker.IsValid()) {
return nil;
}
return geckoTextMarker.Range(EWhichRange::eLine).CreateAXTextMarkerRange();
}
- (id)moxLeftLineTextMarkerRangeForTextMarker:(id)textMarker {
GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker);
if (!geckoTextMarker.IsValid()) {
return nil;
}
return geckoTextMarker.Range(EWhichRange::eLeftLine)
.CreateAXTextMarkerRange();
}
- (id)moxRightLineTextMarkerRangeForTextMarker:(id)textMarker {
GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker);
if (!geckoTextMarker.IsValid()) {
return nil;
}
return geckoTextMarker.Range(EWhichRange::eRightLine)
.CreateAXTextMarkerRange();
}
- (id)moxNextTextMarkerForTextMarker:(id)textMarker {
GeckoTextMarker geckoTextMarker(mGeckoDocAccessible, textMarker);
if (!geckoTextMarker.IsValid()) {

View File

@ -11,7 +11,10 @@ namespace a11y {
enum class EWhichRange {
eLeftWord,
eRightWord
eRightWord,
eLine,
eLeftLine,
eRightLine
};
} // namespace a11y

View File

@ -50,6 +50,39 @@ function testWords(macDoc, marker, msg, expectedLeft, expectedRight) {
);
}
function testLines(
macDoc,
marker,
msg,
expectedLine,
expectedLeft,
expectedRight
) {
testRangeAtMarker(
macDoc,
marker,
"AXLineTextMarkerRangeForTextMarker",
expectedLine,
`${msg}: line matches`
);
testRangeAtMarker(
macDoc,
marker,
"AXLeftLineTextMarkerRangeForTextMarker",
expectedLeft,
`${msg}: left line matches`
);
testRangeAtMarker(
macDoc,
marker,
"AXRightLineTextMarkerRangeForTextMarker",
expectedRight,
`${msg}: right line matches`
);
}
// Tests consistency in text markers between:
// 1. "Linked list" forward navagation
// 2. Getting markers by index
@ -81,6 +114,12 @@ function testMarkerIntegrity(accDoc, expectedMarkerValues) {
`At index ${count}`,
...expectedMarkerValues[count].words
);
testLines(
macDoc,
marker,
`At index ${count}`,
...expectedMarkerValues[count].lines
);
testUIElement(
macDoc,
marker,

File diff suppressed because it is too large Load Diff