Bug 1730096 part 5: Push text attributes to the cache. r=eeejay

Differential Revision: https://phabricator.services.mozilla.com/D129471
This commit is contained in:
James Teh 2021-11-01 23:27:38 +00:00
parent 5cb3312f64
commit e2a75ff2ce

View File

@ -3165,26 +3165,36 @@ already_AddRefed<AccAttributes> LocalAccessible::BundleFieldsForCache(
} }
} }
// We only cache text on leaf Accessibles. if (aCacheDomain & CacheDomain::Text) {
if ((aCacheDomain & CacheDomain::Text) && !HasChildren()) { if (!HasChildren()) {
// Only text Accessibles can have actual text. // We only cache text and line offsets on leaf Accessibles.
if (IsText()) { // Only text Accessibles can have actual text.
nsString text; if (IsText()) {
AppendTextTo(text); nsString text;
fields->SetAttribute(nsGkAtoms::text, std::move(text)); AppendTextTo(text);
fields->SetAttribute(nsGkAtoms::text, std::move(text));
TextLeafPoint point(this, 0);
RefPtr<AccAttributes> attrs = point.GetTextAttributesLocalAcc(
/* aIncludeDefaults */ false);
fields->SetAttribute(nsGkAtoms::style, std::move(attrs));
}
// We cache line start offsets for both text and non-text leaf Accessibles
// because non-text leaf Accessibles can still start a line.
nsTArray<int32_t> lineStarts;
for (TextLeafPoint lineStart =
TextLeafPoint(this, 0).FindNextLineStartSameLocalAcc(
/* aIncludeOrigin */ true);
lineStart;
lineStart = lineStart.FindNextLineStartSameLocalAcc(false)) {
lineStarts.AppendElement(lineStart.mOffset);
}
if (!lineStarts.IsEmpty()) {
fields->SetAttribute(nsGkAtoms::line, std::move(lineStarts));
}
} }
// We cache line start offsets for both text and non-text leaf Accessibles if (HyperTextAccessible* ht = AsHyperText()) {
// because non-text leaf Accessibles can still start a line. RefPtr<AccAttributes> attrs = ht->DefaultTextAttributes();
nsTArray<int32_t> lineStarts; fields->SetAttribute(nsGkAtoms::style, std::move(attrs));
for (TextLeafPoint lineStart =
TextLeafPoint(this, 0).FindNextLineStartSameLocalAcc(
/* aIncludeOrigin */ true);
lineStart;
lineStart = lineStart.FindNextLineStartSameLocalAcc(false)) {
lineStarts.AppendElement(lineStart.mOffset);
}
if (!lineStarts.IsEmpty()) {
fields->SetAttribute(nsGkAtoms::line, std::move(lineStarts));
} }
} }