mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1730096 part 7: Support cached remote text attributes in TextLeafPoint. r=eeejay
Differential Revision: https://phabricator.services.mozilla.com/D129473
This commit is contained in:
parent
7f79cc0400
commit
6bd5ccff7d
@ -762,7 +762,19 @@ already_AddRefed<AccAttributes> TextLeafPoint::GetTextAttributes(
|
||||
if (mAcc->IsLocal()) {
|
||||
return GetTextAttributesLocalAcc(aIncludeDefaults);
|
||||
}
|
||||
return nullptr;
|
||||
RefPtr<AccAttributes> attrs = new AccAttributes();
|
||||
if (aIncludeDefaults) {
|
||||
Accessible* parent = mAcc->Parent();
|
||||
if (parent && parent->IsRemote() && parent->IsHyperText()) {
|
||||
if (auto defAttrs = parent->AsRemote()->GetCachedTextAttributes()) {
|
||||
defAttrs->CopyTo(attrs);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (auto thisAttrs = mAcc->AsRemote()->GetCachedTextAttributes()) {
|
||||
thisAttrs->CopyTo(attrs);
|
||||
}
|
||||
return attrs.forget();
|
||||
}
|
||||
|
||||
TextLeafPoint TextLeafPoint::FindTextAttrsStart(
|
||||
@ -770,10 +782,26 @@ TextLeafPoint TextLeafPoint::FindTextAttrsStart(
|
||||
const AccAttributes* aOriginAttrs, bool aIncludeDefaults) const {
|
||||
// XXX Add support for spelling errors.
|
||||
RefPtr<const AccAttributes> lastAttrs;
|
||||
if (aOriginAttrs) {
|
||||
lastAttrs = aOriginAttrs;
|
||||
const bool isRemote = mAcc->IsRemote();
|
||||
if (isRemote) {
|
||||
// For RemoteAccessible, leaf attrs and default attrs are cached
|
||||
// separately. To combine them, we have to copy. Since we're not walking
|
||||
// outside the container, we don't care about defaults. Therefore, we
|
||||
// always just fetch the leaf attrs.
|
||||
// We ignore aOriginAttrs because it might include defaults. Fetching leaf
|
||||
// attrs is very cheap anyway.
|
||||
lastAttrs = mAcc->AsRemote()->GetCachedTextAttributes();
|
||||
} else {
|
||||
lastAttrs = GetTextAttributesLocalAcc(aIncludeDefaults);
|
||||
// For LocalAccessible, we want to avoid calculating attrs more than
|
||||
// necessary, so we want to use aOriginAttrs if provided.
|
||||
if (aOriginAttrs) {
|
||||
lastAttrs = aOriginAttrs;
|
||||
// Whether we include defaults henceforth must match aOriginAttrs, which
|
||||
// depends on aIncludeDefaults. Defaults are always calculated even if
|
||||
// they aren't returned, so calculation cost isn't a concern.
|
||||
} else {
|
||||
lastAttrs = GetTextAttributesLocalAcc(aIncludeDefaults);
|
||||
}
|
||||
}
|
||||
if (aIncludeOrigin && aDirection == eDirNext && mOffset == 0) {
|
||||
// Even when searching forward, the only way to know whether the origin is
|
||||
@ -784,8 +812,11 @@ TextLeafPoint TextLeafPoint::FindTextAttrsStart(
|
||||
if (!point.mAcc || !point.mAcc->IsText()) {
|
||||
return *this;
|
||||
}
|
||||
// For RemoteAccessible, we can get attributes from the cache without any
|
||||
// calculation or copying.
|
||||
RefPtr<const AccAttributes> attrs =
|
||||
point.GetTextAttributesLocalAcc(aIncludeDefaults);
|
||||
isRemote ? point.mAcc->AsRemote()->GetCachedTextAttributes()
|
||||
: point.GetTextAttributesLocalAcc(aIncludeDefaults);
|
||||
if (!attrs->Equal(lastAttrs)) {
|
||||
return *this;
|
||||
}
|
||||
@ -799,7 +830,8 @@ TextLeafPoint TextLeafPoint::FindTextAttrsStart(
|
||||
break;
|
||||
}
|
||||
RefPtr<const AccAttributes> attrs =
|
||||
point.GetTextAttributesLocalAcc(aIncludeDefaults);
|
||||
isRemote ? point.mAcc->AsRemote()->GetCachedTextAttributes()
|
||||
: point.GetTextAttributesLocalAcc(aIncludeDefaults);
|
||||
if (!attrs->Equal(lastAttrs)) {
|
||||
// The attributes change here. If we're moving forward, we want to
|
||||
// return this point. If we're moving backward, we've now moved before
|
||||
|
@ -417,6 +417,19 @@ void RemoteAccessibleBase<Derived>::DOMNodeID(nsString& aID) const {
|
||||
}
|
||||
}
|
||||
|
||||
template <class Derived>
|
||||
RefPtr<const AccAttributes>
|
||||
RemoteAccessibleBase<Derived>::GetCachedTextAttributes() {
|
||||
MOZ_ASSERT(IsText() || IsHyperText());
|
||||
if (mCachedFields) {
|
||||
auto attrs =
|
||||
mCachedFields->GetAttributeRefPtr<AccAttributes>(nsGkAtoms::style);
|
||||
VERIFY_CACHE(CacheDomain::Text);
|
||||
return attrs;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template class RemoteAccessibleBase<RemoteAccessible>;
|
||||
|
||||
} // namespace a11y
|
||||
|
@ -217,6 +217,7 @@ class RemoteAccessibleBase : public Accessible, public HyperTextAccessibleBase {
|
||||
|
||||
uint32_t GetCachedTextLength();
|
||||
Maybe<const nsTArray<int32_t>&> GetCachedTextLines();
|
||||
RefPtr<const AccAttributes> GetCachedTextAttributes();
|
||||
|
||||
virtual HyperTextAccessibleBase* AsHyperTextBase() override {
|
||||
return IsHyperText() ? static_cast<HyperTextAccessibleBase*>(this)
|
||||
|
Loading…
Reference in New Issue
Block a user