Bug 1856976 [wpt PR 42335] - Update mutation event suppression for <details name...
[gecko.git] / accessible / ipc / RemoteAccessible.cpp
blob6fa97bd284604b044a0de8fc3c111ec5292325e7
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "ARIAMap.h"
8 #include "CachedTableAccessible.h"
9 #include "RemoteAccessible.h"
10 #include "mozilla/a11y/DocAccessibleParent.h"
11 #include "mozilla/a11y/DocManager.h"
12 #include "mozilla/a11y/Platform.h"
13 #include "mozilla/a11y/TableAccessible.h"
14 #include "mozilla/a11y/TableCellAccessible.h"
15 #include "mozilla/dom/Element.h"
16 #include "mozilla/dom/BrowserParent.h"
17 #include "mozilla/dom/CanonicalBrowsingContext.h"
18 #include "mozilla/gfx/Matrix.h"
19 #include "nsAccessibilityService.h"
20 #include "mozilla/Unused.h"
21 #include "nsAccUtils.h"
22 #include "nsTextEquivUtils.h"
23 #include "Pivot.h"
24 #include "Relation.h"
25 #include "RelationType.h"
26 #include "xpcAccessibleDocument.h"
28 #ifdef A11Y_LOG
29 # include "Logging.h"
30 # define VERIFY_CACHE(domain) \
31 if (logging::IsEnabled(logging::eCache)) { \
32 Unused << mDoc->SendVerifyCache(mID, domain, mCachedFields); \
34 #else
35 # define VERIFY_CACHE(domain) \
36 do { \
37 } while (0)
39 #endif
41 namespace mozilla {
42 namespace a11y {
44 void RemoteAccessible::Shutdown() {
45 MOZ_DIAGNOSTIC_ASSERT(!IsDoc());
46 xpcAccessibleDocument* xpcDoc =
47 GetAccService()->GetCachedXPCDocument(Document());
48 if (xpcDoc) {
49 xpcDoc->NotifyOfShutdown(static_cast<RemoteAccessible*>(this));
52 if (IsTable() || IsTableCell()) {
53 CachedTableAccessible::Invalidate(this);
56 // Remove this acc's relation map from the doc's map of
57 // reverse relations. Prune forward relations associated with this
58 // acc's reverse relations. This also removes the acc's map of reverse
59 // rels from the mDoc's mReverseRelations.
60 PruneRelationsOnShutdown();
62 // XXX Ideally this wouldn't be necessary, but it seems OuterDoc
63 // accessibles can be destroyed before the doc they own.
64 uint32_t childCount = mChildren.Length();
65 if (!IsOuterDoc()) {
66 for (uint32_t idx = 0; idx < childCount; idx++) mChildren[idx]->Shutdown();
67 } else {
68 if (childCount > 1) {
69 MOZ_CRASH("outer doc has too many documents!");
70 } else if (childCount == 1) {
71 mChildren[0]->AsDoc()->Unbind();
75 mChildren.Clear();
76 ProxyDestroyed(static_cast<RemoteAccessible*>(this));
77 mDoc->RemoveAccessible(static_cast<RemoteAccessible*>(this));
80 void RemoteAccessible::SetChildDoc(DocAccessibleParent* aChildDoc) {
81 MOZ_ASSERT(aChildDoc);
82 MOZ_ASSERT(mChildren.Length() == 0);
83 mChildren.AppendElement(aChildDoc);
86 void RemoteAccessible::ClearChildDoc(DocAccessibleParent* aChildDoc) {
87 MOZ_ASSERT(aChildDoc);
88 // This is possible if we're replacing one document with another: Doc 1
89 // has not had a chance to remove itself, but was already replaced by Doc 2
90 // in SetChildDoc(). This could result in two subsequent calls to
91 // ClearChildDoc() even though mChildren.Length() == 1.
92 MOZ_ASSERT(mChildren.Length() <= 1);
93 mChildren.RemoveElement(aChildDoc);
96 uint32_t RemoteAccessible::EmbeddedChildCount() {
97 size_t count = 0, kids = mChildren.Length();
98 for (size_t i = 0; i < kids; i++) {
99 if (mChildren[i]->IsEmbeddedObject()) {
100 count++;
104 return count;
107 int32_t RemoteAccessible::IndexOfEmbeddedChild(Accessible* aChild) {
108 size_t index = 0, kids = mChildren.Length();
109 for (size_t i = 0; i < kids; i++) {
110 if (mChildren[i]->IsEmbeddedObject()) {
111 if (mChildren[i] == aChild) {
112 return index;
115 index++;
119 return -1;
122 Accessible* RemoteAccessible::EmbeddedChildAt(uint32_t aChildIdx) {
123 size_t index = 0, kids = mChildren.Length();
124 for (size_t i = 0; i < kids; i++) {
125 if (!mChildren[i]->IsEmbeddedObject()) {
126 continue;
129 if (index == aChildIdx) {
130 return mChildren[i];
133 index++;
136 return nullptr;
139 LocalAccessible* RemoteAccessible::OuterDocOfRemoteBrowser() const {
140 auto tab = static_cast<dom::BrowserParent*>(mDoc->Manager());
141 dom::Element* frame = tab->GetOwnerElement();
142 NS_ASSERTION(frame, "why isn't the tab in a frame!");
143 if (!frame) return nullptr;
145 DocAccessible* chromeDoc = GetExistingDocAccessible(frame->OwnerDoc());
147 return chromeDoc ? chromeDoc->GetAccessible(frame) : nullptr;
150 void RemoteAccessible::SetParent(RemoteAccessible* aParent) {
151 if (!aParent) {
152 mParent = kNoParent;
153 } else {
154 MOZ_ASSERT(!IsDoc() || !aParent->IsDoc());
155 mParent = aParent->ID();
159 RemoteAccessible* RemoteAccessible::RemoteParent() const {
160 if (mParent == kNoParent) {
161 return nullptr;
164 // if we are not a document then are parent is another proxy in the same
165 // document. That means we can just ask our document for the proxy with our
166 // parent id.
167 if (!IsDoc()) {
168 return Document()->GetAccessible(mParent);
171 // If we are a top level document then our parent is not a proxy.
172 if (AsDoc()->IsTopLevel()) {
173 return nullptr;
176 // Finally if we are a non top level document then our parent id is for a
177 // proxy in our parent document so get the proxy from there.
178 DocAccessibleParent* parentDoc = AsDoc()->ParentDoc();
179 MOZ_ASSERT(parentDoc);
180 MOZ_ASSERT(mParent);
181 return parentDoc->GetAccessible(mParent);
184 void RemoteAccessible::ApplyCache(CacheUpdateType aUpdateType,
185 AccAttributes* aFields) {
186 if (!aFields) {
187 MOZ_ASSERT_UNREACHABLE("ApplyCache called with aFields == null");
188 return;
191 const nsTArray<bool> relUpdatesNeeded = PreProcessRelations(aFields);
192 if (auto maybeViewportCache =
193 aFields->GetAttribute<nsTArray<uint64_t>>(CacheKey::Viewport)) {
194 // Updating the viewport cache means the offscreen state of this
195 // document's accessibles has changed. Update the HashSet we use for
196 // checking offscreen state here.
197 MOZ_ASSERT(IsDoc(),
198 "Fetched the viewport cache from a non-doc accessible?");
199 AsDoc()->mOnScreenAccessibles.Clear();
200 for (auto id : *maybeViewportCache) {
201 AsDoc()->mOnScreenAccessibles.Insert(id);
205 if (aUpdateType == CacheUpdateType::Initial) {
206 mCachedFields = aFields;
207 } else {
208 if (!mCachedFields) {
209 // The fields cache can be uninitialized if there were no cache-worthy
210 // fields in the initial cache push.
211 // We don't do a simple assign because we don't want to store the
212 // DeleteEntry entries.
213 mCachedFields = new AccAttributes();
215 mCachedFields->Update(aFields);
218 if (IsTextLeaf()) {
219 RemoteAccessible* parent = RemoteParent();
220 if (parent && parent->IsHyperText()) {
221 parent->InvalidateCachedHyperTextOffsets();
225 PostProcessRelations(relUpdatesNeeded);
228 ENameValueFlag RemoteAccessible::Name(nsString& aName) const {
229 ENameValueFlag nameFlag = eNameOK;
230 if (mCachedFields) {
231 if (IsText()) {
232 mCachedFields->GetAttribute(CacheKey::Text, aName);
233 return eNameOK;
235 auto cachedNameFlag =
236 mCachedFields->GetAttribute<int32_t>(CacheKey::NameValueFlag);
237 if (cachedNameFlag) {
238 nameFlag = static_cast<ENameValueFlag>(*cachedNameFlag);
240 if (mCachedFields->GetAttribute(CacheKey::Name, aName)) {
241 VERIFY_CACHE(CacheDomain::NameAndDescription);
242 return nameFlag;
246 MOZ_ASSERT(aName.IsEmpty());
247 aName.SetIsVoid(true);
248 return nameFlag;
251 void RemoteAccessible::Description(nsString& aDescription) const {
252 if (mCachedFields) {
253 mCachedFields->GetAttribute(CacheKey::Description, aDescription);
254 VERIFY_CACHE(CacheDomain::NameAndDescription);
258 void RemoteAccessible::Value(nsString& aValue) const {
259 if (mCachedFields) {
260 if (mCachedFields->HasAttribute(CacheKey::TextValue)) {
261 mCachedFields->GetAttribute(CacheKey::TextValue, aValue);
262 VERIFY_CACHE(CacheDomain::Value);
263 return;
266 if (HasNumericValue()) {
267 double checkValue = CurValue();
268 if (!std::isnan(checkValue)) {
269 aValue.AppendFloat(checkValue);
271 return;
274 const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
275 // Value of textbox is a textified subtree.
276 if (roleMapEntry && roleMapEntry->Is(nsGkAtoms::textbox)) {
277 nsTextEquivUtils::GetTextEquivFromSubtree(this, aValue);
278 return;
281 if (IsCombobox()) {
282 // For combo boxes, rely on selection state to determine the value.
283 const Accessible* option =
284 const_cast<RemoteAccessible*>(this)->GetSelectedItem(0);
285 if (option) {
286 option->Name(aValue);
287 } else {
288 // If no selected item, determine the value from descendant elements.
289 nsTextEquivUtils::GetTextEquivFromSubtree(this, aValue);
291 return;
294 if (IsTextLeaf() || IsImage()) {
295 if (const Accessible* actionAcc = ActionAncestor()) {
296 if (const_cast<Accessible*>(actionAcc)->State() & states::LINKED) {
297 // Text and image descendants of links expose the link URL as the
298 // value.
299 return actionAcc->Value(aValue);
306 double RemoteAccessible::CurValue() const {
307 if (mCachedFields) {
308 if (auto value =
309 mCachedFields->GetAttribute<double>(CacheKey::NumericValue)) {
310 VERIFY_CACHE(CacheDomain::Value);
311 return *value;
315 return UnspecifiedNaN<double>();
318 double RemoteAccessible::MinValue() const {
319 if (mCachedFields) {
320 if (auto min = mCachedFields->GetAttribute<double>(CacheKey::MinValue)) {
321 VERIFY_CACHE(CacheDomain::Value);
322 return *min;
326 return UnspecifiedNaN<double>();
329 double RemoteAccessible::MaxValue() const {
330 if (mCachedFields) {
331 if (auto max = mCachedFields->GetAttribute<double>(CacheKey::MaxValue)) {
332 VERIFY_CACHE(CacheDomain::Value);
333 return *max;
337 return UnspecifiedNaN<double>();
340 double RemoteAccessible::Step() const {
341 if (mCachedFields) {
342 if (auto step = mCachedFields->GetAttribute<double>(CacheKey::Step)) {
343 VERIFY_CACHE(CacheDomain::Value);
344 return *step;
348 return UnspecifiedNaN<double>();
351 bool RemoteAccessible::SetCurValue(double aValue) {
352 if (!HasNumericValue() || IsProgress()) {
353 return false;
356 const uint32_t kValueCannotChange = states::READONLY | states::UNAVAILABLE;
357 if (State() & kValueCannotChange) {
358 return false;
361 double checkValue = MinValue();
362 if (!std::isnan(checkValue) && aValue < checkValue) {
363 return false;
366 checkValue = MaxValue();
367 if (!std::isnan(checkValue) && aValue > checkValue) {
368 return false;
371 Unused << mDoc->SendSetCurValue(mID, aValue);
372 return true;
375 bool RemoteAccessible::ContainsPoint(int32_t aX, int32_t aY) {
376 if (!BoundsWithOffset(Nothing(), true).Contains(aX, aY)) {
377 return false;
379 if (!IsTextLeaf()) {
380 return true;
382 // This is a text leaf. The text might wrap across lines, which means our
383 // rect might cover a wider area than the actual text. For example, if the
384 // text begins in the middle of the first line and wraps on to the second,
385 // the rect will cover the start of the first line and the end of the second.
386 auto lines = GetCachedTextLines();
387 if (!lines) {
388 // This means the text is empty or occupies a single line (but does not
389 // begin the line). In that case, the Bounds check above is sufficient,
390 // since there's only one rect.
391 return true;
393 uint32_t length = lines->Length();
394 MOZ_ASSERT(length > 0,
395 "Line starts shouldn't be in cache if there aren't any");
396 if (length == 0 || (length == 1 && (*lines)[0] == 0)) {
397 // This means the text begins and occupies a single line. Again, the Bounds
398 // check above is sufficient.
399 return true;
401 // Walk the lines of the text. Even if this text doesn't start at the
402 // beginning of a line (i.e. lines[0] > 0), we always want to consider its
403 // first line.
404 int32_t lineStart = 0;
405 for (uint32_t index = 0; index <= length; ++index) {
406 int32_t lineEnd;
407 if (index < length) {
408 int32_t nextLineStart = (*lines)[index];
409 if (nextLineStart == 0) {
410 // This Accessible starts at the beginning of a line. Here, we always
411 // treat 0 as the first line start anyway.
412 MOZ_ASSERT(index == 0);
413 continue;
415 lineEnd = nextLineStart - 1;
416 } else {
417 // This is the last line.
418 lineEnd = static_cast<int32_t>(nsAccUtils::TextLength(this)) - 1;
420 MOZ_ASSERT(lineEnd >= lineStart);
421 nsRect lineRect = GetCachedCharRect(lineStart);
422 if (lineEnd > lineStart) {
423 lineRect.UnionRect(lineRect, GetCachedCharRect(lineEnd));
425 if (BoundsWithOffset(Some(lineRect), true).Contains(aX, aY)) {
426 return true;
428 lineStart = lineEnd + 1;
430 return false;
433 RemoteAccessible* RemoteAccessible::DoFuzzyHittesting() {
434 uint32_t childCount = ChildCount();
435 if (!childCount) {
436 return nullptr;
438 // Check if this match has a clipped child.
439 // This usually indicates invisible text, and we're
440 // interested in returning the inner text content
441 // even if it doesn't contain the point we're hittesting.
442 RemoteAccessible* clippedContainer = nullptr;
443 for (uint32_t i = 0; i < childCount; i++) {
444 RemoteAccessible* child = RemoteChildAt(i);
445 if (child->Role() == roles::TEXT_CONTAINER) {
446 if (child->IsClipped()) {
447 clippedContainer = child;
448 break;
452 // If we found a clipped container, descend it in search of
453 // meaningful text leaves. Ignore non-text-leaf/text-container
454 // siblings.
455 RemoteAccessible* container = clippedContainer;
456 while (container) {
457 RemoteAccessible* textLeaf = nullptr;
458 bool continueSearch = false;
459 childCount = container->ChildCount();
460 for (uint32_t i = 0; i < childCount; i++) {
461 RemoteAccessible* child = container->RemoteChildAt(i);
462 if (child->Role() == roles::TEXT_CONTAINER) {
463 container = child;
464 continueSearch = true;
465 break;
467 if (child->IsTextLeaf()) {
468 textLeaf = child;
469 // Don't break here -- it's possible a text container
470 // exists as another sibling, and we should descend as
471 // deep as possible.
474 if (textLeaf) {
475 return textLeaf;
477 if (!continueSearch) {
478 // We didn't find anything useful in this set of siblings.
479 // Don't keep searching
480 break;
483 return nullptr;
486 Accessible* RemoteAccessible::ChildAtPoint(
487 int32_t aX, int32_t aY, LocalAccessible::EWhichChildAtPoint aWhichChild) {
488 // Elements that are partially on-screen should have their bounds masked by
489 // their containing scroll area so hittesting yields results that are
490 // consistent with the content's visual representation. Pass this value to
491 // bounds calculation functions to indicate that we're hittesting.
492 const bool hitTesting = true;
494 if (IsOuterDoc() && aWhichChild == EWhichChildAtPoint::DirectChild) {
495 // This is an iframe, which is as deep as the viewport cache goes. The
496 // caller wants a direct child, which can only be the embedded document.
497 if (BoundsWithOffset(Nothing(), hitTesting).Contains(aX, aY)) {
498 return RemoteFirstChild();
500 return nullptr;
503 RemoteAccessible* lastMatch = nullptr;
504 // If `this` is a document, use its viewport cache instead of
505 // the cache of its parent document.
506 if (DocAccessibleParent* doc = IsDoc() ? AsDoc() : mDoc) {
507 if (!doc->mCachedFields) {
508 // A client call might arrive after we've constructed doc but before we
509 // get a cache push for it.
510 return nullptr;
512 if (auto maybeViewportCache =
513 doc->mCachedFields->GetAttribute<nsTArray<uint64_t>>(
514 CacheKey::Viewport)) {
515 // The retrieved viewport cache contains acc IDs in hittesting order.
516 // That is, items earlier in the list have z-indexes that are larger than
517 // those later in the list. If you were to build a tree by z-index, where
518 // chilren have larger z indices than their parents, iterating this list
519 // is essentially a postorder tree traversal.
520 const nsTArray<uint64_t>& viewportCache = *maybeViewportCache;
522 for (auto id : viewportCache) {
523 RemoteAccessible* acc = doc->GetAccessible(id);
524 if (!acc) {
525 // This can happen if the acc died in between
526 // pushing the viewport cache and doing this hittest
527 continue;
530 if (acc->IsOuterDoc() &&
531 aWhichChild == EWhichChildAtPoint::DeepestChild &&
532 acc->BoundsWithOffset(Nothing(), hitTesting).Contains(aX, aY)) {
533 // acc is an iframe, which is as deep as the viewport cache goes. This
534 // iframe contains the requested point.
535 RemoteAccessible* innerDoc = acc->RemoteFirstChild();
536 if (innerDoc) {
537 MOZ_ASSERT(innerDoc->IsDoc());
538 // Search the embedded document's viewport cache so we return the
539 // deepest descendant in that embedded document.
540 Accessible* deepestAcc = innerDoc->ChildAtPoint(
541 aX, aY, EWhichChildAtPoint::DeepestChild);
542 MOZ_ASSERT(!deepestAcc || deepestAcc->IsRemote());
543 lastMatch = deepestAcc ? deepestAcc->AsRemote() : nullptr;
544 break;
546 // If there is no embedded document, the iframe itself is the deepest
547 // descendant.
548 lastMatch = acc;
549 break;
552 if (acc == this) {
553 MOZ_ASSERT(!acc->IsOuterDoc());
554 // Even though we're searching from the doc's cache
555 // this call shouldn't pass the boundary defined by
556 // the acc this call originated on. If we hit `this`,
557 // return our most recent match.
558 if (!lastMatch &&
559 BoundsWithOffset(Nothing(), hitTesting).Contains(aX, aY)) {
560 // If we haven't found a match, but `this` contains the point we're
561 // looking for, set it as our temp last match so we can
562 // (potentially) do fuzzy hittesting on it below.
563 lastMatch = acc;
565 break;
568 if (acc->ContainsPoint(aX, aY)) {
569 // Because our rects are in hittesting order, the
570 // first match we encounter is guaranteed to be the
571 // deepest match.
572 lastMatch = acc;
573 break;
576 if (lastMatch) {
577 RemoteAccessible* fuzzyMatch = lastMatch->DoFuzzyHittesting();
578 lastMatch = fuzzyMatch ? fuzzyMatch : lastMatch;
583 if (aWhichChild == EWhichChildAtPoint::DirectChild && lastMatch) {
584 // lastMatch is the deepest match. Walk up to the direct child of this.
585 RemoteAccessible* parent = lastMatch->RemoteParent();
586 for (;;) {
587 if (parent == this) {
588 break;
590 if (!parent || parent->IsDoc()) {
591 // `this` is not an ancestor of lastMatch. Ignore lastMatch.
592 lastMatch = nullptr;
593 break;
595 lastMatch = parent;
596 parent = parent->RemoteParent();
598 } else if (aWhichChild == EWhichChildAtPoint::DeepestChild && lastMatch &&
599 !IsDoc() && !IsAncestorOf(lastMatch)) {
600 // If we end up with a match that is not in the ancestor chain
601 // of the accessible this call originated on, we should ignore it.
602 // This can happen when the aX, aY given are outside `this`.
603 lastMatch = nullptr;
606 if (!lastMatch && BoundsWithOffset(Nothing(), hitTesting).Contains(aX, aY)) {
607 // Even though the hit target isn't inside `this`, the point is still
608 // within our bounds, so fall back to `this`.
609 return this;
612 return lastMatch;
615 Maybe<nsRect> RemoteAccessible::RetrieveCachedBounds() const {
616 if (!mCachedFields) {
617 return Nothing();
620 Maybe<const nsTArray<int32_t>&> maybeArray =
621 mCachedFields->GetAttribute<nsTArray<int32_t>>(
622 CacheKey::ParentRelativeBounds);
623 if (maybeArray) {
624 const nsTArray<int32_t>& relativeBoundsArr = *maybeArray;
625 MOZ_ASSERT(relativeBoundsArr.Length() == 4,
626 "Incorrectly sized bounds array");
627 nsRect relativeBoundsRect(relativeBoundsArr[0], relativeBoundsArr[1],
628 relativeBoundsArr[2], relativeBoundsArr[3]);
629 return Some(relativeBoundsRect);
632 return Nothing();
635 void RemoteAccessible::ApplyCrossDocOffset(nsRect& aBounds) const {
636 if (!IsDoc()) {
637 // We should only apply cross-doc offsets to documents. If we're anything
638 // else, return early here.
639 return;
642 RemoteAccessible* parentAcc = RemoteParent();
643 if (!parentAcc || !parentAcc->IsOuterDoc()) {
644 return;
647 Maybe<const nsTArray<int32_t>&> maybeOffset =
648 parentAcc->mCachedFields->GetAttribute<nsTArray<int32_t>>(
649 CacheKey::CrossDocOffset);
650 if (!maybeOffset) {
651 return;
654 MOZ_ASSERT(maybeOffset->Length() == 2);
655 const nsTArray<int32_t>& offset = *maybeOffset;
656 // Our retrieved value is in app units, so we don't need to do any
657 // unit conversion here.
658 aBounds.MoveBy(offset[0], offset[1]);
661 bool RemoteAccessible::ApplyTransform(nsRect& aCumulativeBounds) const {
662 // First, attempt to retrieve the transform from the cache.
663 Maybe<const UniquePtr<gfx::Matrix4x4>&> maybeTransform =
664 mCachedFields->GetAttribute<UniquePtr<gfx::Matrix4x4>>(
665 CacheKey::TransformMatrix);
666 if (!maybeTransform) {
667 return false;
670 auto mtxInPixels = gfx::Matrix4x4Typed<CSSPixel, CSSPixel>::FromUnknownMatrix(
671 *(*maybeTransform));
673 // Our matrix is in CSS Pixels, so we need our rect to be in CSS
674 // Pixels too. Convert before applying.
675 auto boundsInPixels = CSSRect::FromAppUnits(aCumulativeBounds);
676 boundsInPixels = mtxInPixels.TransformBounds(boundsInPixels);
677 aCumulativeBounds = CSSRect::ToAppUnits(boundsInPixels);
679 return true;
682 bool RemoteAccessible::ApplyScrollOffset(nsRect& aBounds) const {
683 Maybe<const nsTArray<int32_t>&> maybeScrollPosition =
684 mCachedFields->GetAttribute<nsTArray<int32_t>>(CacheKey::ScrollPosition);
686 if (!maybeScrollPosition || maybeScrollPosition->Length() != 2) {
687 return false;
689 // Our retrieved value is in app units, so we don't need to do any
690 // unit conversion here.
691 const nsTArray<int32_t>& scrollPosition = *maybeScrollPosition;
693 // Scroll position is an inverse representation of scroll offset (since the
694 // further the scroll bar moves down the page, the further the page content
695 // moves up/closer to the origin).
696 nsPoint scrollOffset(-scrollPosition[0], -scrollPosition[1]);
698 aBounds.MoveBy(scrollOffset.x, scrollOffset.y);
700 // Return true here even if the scroll offset was 0,0 because the RV is used
701 // as a scroll container indicator. Non-scroll containers won't have cached
702 // scroll position.
703 return true;
706 nsRect RemoteAccessible::BoundsInAppUnits() const {
707 if (dom::CanonicalBrowsingContext* cbc = mDoc->GetBrowsingContext()->Top()) {
708 if (dom::BrowserParent* bp = cbc->GetBrowserParent()) {
709 DocAccessibleParent* topDoc = bp->GetTopLevelDocAccessible();
710 if (topDoc && topDoc->mCachedFields) {
711 auto appUnitsPerDevPixel = topDoc->mCachedFields->GetAttribute<int32_t>(
712 CacheKey::AppUnitsPerDevPixel);
713 MOZ_ASSERT(appUnitsPerDevPixel);
714 return LayoutDeviceIntRect::ToAppUnits(Bounds(), *appUnitsPerDevPixel);
718 return LayoutDeviceIntRect::ToAppUnits(Bounds(), AppUnitsPerCSSPixel());
721 bool RemoteAccessible::IsFixedPos() const {
722 MOZ_ASSERT(mCachedFields);
723 if (auto maybePosition =
724 mCachedFields->GetAttribute<RefPtr<nsAtom>>(CacheKey::CssPosition)) {
725 return *maybePosition == nsGkAtoms::fixed;
728 return false;
731 bool RemoteAccessible::IsOverflowHidden() const {
732 MOZ_ASSERT(mCachedFields);
733 if (auto maybeOverflow =
734 mCachedFields->GetAttribute<RefPtr<nsAtom>>(CacheKey::CSSOverflow)) {
735 return *maybeOverflow == nsGkAtoms::hidden;
738 return false;
741 bool RemoteAccessible::IsClipped() const {
742 MOZ_ASSERT(mCachedFields);
743 if (mCachedFields->GetAttribute<bool>(CacheKey::IsClipped)) {
744 return true;
747 return false;
750 LayoutDeviceIntRect RemoteAccessible::BoundsWithOffset(
751 Maybe<nsRect> aOffset, bool aBoundsAreForHittesting) const {
752 Maybe<nsRect> maybeBounds = RetrieveCachedBounds();
753 if (maybeBounds) {
754 nsRect bounds = *maybeBounds;
755 // maybeBounds is parent-relative. However, the transform matrix we cache
756 // (if any) is meant to operate on self-relative rects. Therefore, make
757 // bounds self-relative until after we transform.
758 bounds.MoveTo(0, 0);
759 const DocAccessibleParent* topDoc = IsDoc() ? AsDoc() : nullptr;
761 if (aOffset.isSome()) {
762 // The rect we've passed in is in app units, so no conversion needed.
763 nsRect internalRect = *aOffset;
764 bounds.SetRectX(bounds.x + internalRect.x, internalRect.width);
765 bounds.SetRectY(bounds.y + internalRect.y, internalRect.height);
768 Unused << ApplyTransform(bounds);
769 // Now apply the parent-relative offset.
770 bounds.MoveBy(maybeBounds->TopLeft());
772 ApplyCrossDocOffset(bounds);
774 LayoutDeviceIntRect devPxBounds;
775 const Accessible* acc = Parent();
776 bool encounteredFixedContainer = IsFixedPos();
777 while (acc && acc->IsRemote()) {
778 // Return early if we're hit testing and our cumulative bounds are empty,
779 // since walking the ancestor chain won't produce any hits.
780 if (aBoundsAreForHittesting && bounds.IsEmpty()) {
781 return LayoutDeviceIntRect{};
784 RemoteAccessible* remoteAcc = const_cast<Accessible*>(acc)->AsRemote();
786 if (Maybe<nsRect> maybeRemoteBounds = remoteAcc->RetrieveCachedBounds()) {
787 nsRect remoteBounds = *maybeRemoteBounds;
788 // We need to take into account a non-1 resolution set on the
789 // presshell. This happens with async pinch zooming, among other
790 // things. We can't reliably query this value in the parent process,
791 // so we retrieve it from the document's cache.
792 if (remoteAcc->IsDoc()) {
793 // Apply the document's resolution to the bounds we've gathered
794 // thus far. We do this before applying the document's offset
795 // because document accs should not have their bounds scaled by
796 // their own resolution. They should be scaled by the resolution
797 // of their containing document (if any).
798 Maybe<float> res =
799 remoteAcc->AsDoc()->mCachedFields->GetAttribute<float>(
800 CacheKey::Resolution);
801 MOZ_ASSERT(res, "No cached document resolution found.");
802 bounds.ScaleRoundOut(res.valueOr(1.0f));
804 topDoc = remoteAcc->AsDoc();
807 // We don't account for the document offset of iframes when
808 // computing parent-relative bounds. Instead, we store this value
809 // separately on all iframes and apply it here. See the comments in
810 // LocalAccessible::BundleFieldsForCache where we set the
811 // nsGkAtoms::crossorigin attribute.
812 remoteAcc->ApplyCrossDocOffset(remoteBounds);
813 if (!encounteredFixedContainer) {
814 // Apply scroll offset, if applicable. Only the contents of an
815 // element are affected by its scroll offset, which is why this call
816 // happens in this loop instead of both inside and outside of
817 // the loop (like ApplyTransform).
818 // Never apply scroll offsets past a fixed container.
819 const bool hasScrollArea = remoteAcc->ApplyScrollOffset(bounds);
821 // If we are hit testing and the Accessible has a scroll area, ensure
822 // that the bounds we've calculated so far are constrained to the
823 // bounds of the scroll area. Without this, we'll "hit" the off-screen
824 // portions of accs that are are partially (but not fully) within the
825 // scroll area. This is also a problem for accs with overflow:hidden;
826 if (aBoundsAreForHittesting &&
827 (hasScrollArea || remoteAcc->IsOverflowHidden())) {
828 nsRect selfRelativeVisibleBounds(0, 0, remoteBounds.width,
829 remoteBounds.height);
830 bounds = bounds.SafeIntersect(selfRelativeVisibleBounds);
833 if (remoteAcc->IsDoc()) {
834 // Fixed elements are document relative, so if we've hit a
835 // document we're now subject to that document's styling
836 // (including scroll offsets that operate on it).
837 // This ordering is important, we don't want to apply scroll
838 // offsets on this doc's content.
839 encounteredFixedContainer = false;
841 if (!encounteredFixedContainer) {
842 // The transform matrix we cache (if any) is meant to operate on
843 // self-relative rects. Therefore, we must apply the transform before
844 // we make bounds parent-relative.
845 Unused << remoteAcc->ApplyTransform(bounds);
846 // Regardless of whether this is a doc, we should offset `bounds`
847 // by the bounds retrieved here. This is how we build screen
848 // coordinates from relative coordinates.
849 bounds.MoveBy(remoteBounds.X(), remoteBounds.Y());
852 if (remoteAcc->IsFixedPos()) {
853 encounteredFixedContainer = true;
855 // we can't just break here if we're scroll suppressed because we still
856 // need to find the top doc.
858 acc = acc->Parent();
861 MOZ_ASSERT(topDoc);
862 if (topDoc) {
863 // We use the top documents app-units-per-dev-pixel even though
864 // theoretically nested docs can have different values. Practically,
865 // that isn't likely since we only offer zoom controls for the top
866 // document and all subdocuments inherit from it.
867 auto appUnitsPerDevPixel = topDoc->mCachedFields->GetAttribute<int32_t>(
868 CacheKey::AppUnitsPerDevPixel);
869 MOZ_ASSERT(appUnitsPerDevPixel);
870 if (appUnitsPerDevPixel) {
871 // Convert our existing `bounds` rect from app units to dev pixels
872 devPxBounds = LayoutDeviceIntRect::FromAppUnitsToNearest(
873 bounds, *appUnitsPerDevPixel);
877 #if !defined(ANDROID)
878 // This block is not thread safe because it queries a LocalAccessible.
879 // It is also not needed in Android since the only local accessible is
880 // the outer doc browser that has an offset of 0.
881 // acc could be null if the OuterDocAccessible died before the top level
882 // DocAccessibleParent.
883 if (LocalAccessible* localAcc =
884 acc ? const_cast<Accessible*>(acc)->AsLocal() : nullptr) {
885 // LocalAccessible::Bounds returns screen-relative bounds in
886 // dev pixels.
887 LayoutDeviceIntRect localBounds = localAcc->Bounds();
889 // The root document will always have an APZ resolution of 1,
890 // so we don't factor in its scale here. We also don't scale
891 // by GetFullZoom because LocalAccessible::Bounds already does
892 // that.
893 devPxBounds.MoveBy(localBounds.X(), localBounds.Y());
895 #endif
897 return devPxBounds;
900 return LayoutDeviceIntRect();
903 LayoutDeviceIntRect RemoteAccessible::Bounds() const {
904 return BoundsWithOffset(Nothing());
907 Relation RemoteAccessible::RelationByType(RelationType aType) const {
908 // We are able to handle some relations completely in the
909 // parent process, without the help of the cache. Those
910 // relations are enumerated here. Other relations, whose
911 // types are stored in kRelationTypeAtoms, are processed
912 // below using the cache.
913 if (aType == RelationType::CONTAINING_TAB_PANE) {
914 if (dom::CanonicalBrowsingContext* cbc = mDoc->GetBrowsingContext()) {
915 if (dom::CanonicalBrowsingContext* topCbc = cbc->Top()) {
916 if (dom::BrowserParent* bp = topCbc->GetBrowserParent()) {
917 return Relation(bp->GetTopLevelDocAccessible());
921 return Relation();
924 if (aType == RelationType::LINKS_TO && Role() == roles::LINK) {
925 Pivot p = Pivot(mDoc);
926 nsString href;
927 Value(href);
928 int32_t i = href.FindChar('#');
929 int32_t len = static_cast<int32_t>(href.Length());
930 if (i != -1 && i < (len - 1)) {
931 nsDependentSubstring anchorName = Substring(href, i + 1, len);
932 MustPruneSameDocRule rule;
933 Accessible* nameMatch = nullptr;
934 for (Accessible* match = p.Next(mDoc, rule); match;
935 match = p.Next(match, rule)) {
936 nsString currID;
937 match->DOMNodeID(currID);
938 MOZ_ASSERT(match->IsRemote());
939 if (anchorName.Equals(currID)) {
940 return Relation(match->AsRemote());
942 if (!nameMatch) {
943 nsString currName = match->AsRemote()->GetCachedHTMLNameAttribute();
944 if (match->TagName() == nsGkAtoms::a && anchorName.Equals(currName)) {
945 // If we find an element with a matching ID, we should return
946 // that, but if we don't we should return the first anchor with
947 // a matching name. To avoid doing two traversals, store the first
948 // name match here.
949 nameMatch = match;
953 return nameMatch ? Relation(nameMatch->AsRemote()) : Relation();
956 return Relation();
959 // Handle ARIA tree, treegrid parent/child relations. Each of these cases
960 // relies on cached group info. To find the parent of an accessible, use the
961 // unified conceptual parent.
962 if (aType == RelationType::NODE_CHILD_OF) {
963 const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
964 if (roleMapEntry && (roleMapEntry->role == roles::OUTLINEITEM ||
965 roleMapEntry->role == roles::LISTITEM ||
966 roleMapEntry->role == roles::ROW)) {
967 if (const AccGroupInfo* groupInfo =
968 const_cast<RemoteAccessible*>(this)->GetOrCreateGroupInfo()) {
969 return Relation(groupInfo->ConceptualParent());
972 return Relation();
975 // To find the children of a parent, provide an iterator through its items.
976 if (aType == RelationType::NODE_PARENT_OF) {
977 const nsRoleMapEntry* roleMapEntry = ARIARoleMap();
978 if (roleMapEntry && (roleMapEntry->role == roles::OUTLINEITEM ||
979 roleMapEntry->role == roles::LISTITEM ||
980 roleMapEntry->role == roles::ROW ||
981 roleMapEntry->role == roles::OUTLINE ||
982 roleMapEntry->role == roles::LIST ||
983 roleMapEntry->role == roles::TREE_TABLE)) {
984 return Relation(new ItemIterator(this));
986 return Relation();
989 if (aType == RelationType::MEMBER_OF) {
990 Relation rel = Relation();
991 // HTML radio buttons with cached names should be grouped.
992 if (IsHTMLRadioButton()) {
993 nsString name = GetCachedHTMLNameAttribute();
994 if (name.IsEmpty()) {
995 return rel;
998 RemoteAccessible* ancestor = RemoteParent();
999 while (ancestor && ancestor->Role() != roles::FORM && ancestor != mDoc) {
1000 ancestor = ancestor->RemoteParent();
1002 if (ancestor) {
1003 // Sometimes we end up with an unparented acc here, potentially
1004 // because the acc is being moved. See bug 1807639.
1005 // Pivot expects to be created with a non-null mRoot.
1006 Pivot p = Pivot(ancestor);
1007 PivotRadioNameRule rule(name);
1008 Accessible* match = p.Next(ancestor, rule);
1009 while (match) {
1010 rel.AppendTarget(match->AsRemote());
1011 match = p.Next(match, rule);
1014 return rel;
1017 if (IsARIARole(nsGkAtoms::radio)) {
1018 // ARIA radio buttons should be grouped by their radio group
1019 // parent, if one exists.
1020 RemoteAccessible* currParent = RemoteParent();
1021 while (currParent && currParent->Role() != roles::RADIO_GROUP) {
1022 currParent = currParent->RemoteParent();
1025 if (currParent && currParent->Role() == roles::RADIO_GROUP) {
1026 // If we found a radiogroup parent, search for all
1027 // roles::RADIOBUTTON children and add them to our relation.
1028 // This search will include the radio button this method
1029 // was called from, which is expected.
1030 Pivot p = Pivot(currParent);
1031 PivotRoleRule rule(roles::RADIOBUTTON);
1032 Accessible* match = p.Next(currParent, rule);
1033 while (match) {
1034 MOZ_ASSERT(match->IsRemote(),
1035 "We should only be traversing the remote tree.");
1036 rel.AppendTarget(match->AsRemote());
1037 match = p.Next(match, rule);
1041 // By webkit's standard, aria radio buttons do not get grouped
1042 // if they lack a group parent, so we return an empty
1043 // relation here if the above check fails.
1044 return rel;
1047 Relation rel;
1048 if (!mCachedFields) {
1049 return rel;
1052 for (const auto& data : kRelationTypeAtoms) {
1053 if (data.mType != aType ||
1054 (data.mValidTag && TagName() != data.mValidTag)) {
1055 continue;
1058 if (auto maybeIds =
1059 mCachedFields->GetAttribute<nsTArray<uint64_t>>(data.mAtom)) {
1060 rel.AppendIter(new RemoteAccIterator(*maybeIds, Document()));
1062 // Each relation type has only one relevant cached attribute,
1063 // so break after we've handled the attr for this type,
1064 // even if we didn't find any targets.
1065 break;
1068 if (auto accRelMapEntry = mDoc->mReverseRelations.Lookup(ID())) {
1069 if (auto reverseIdsEntry = accRelMapEntry.Data().Lookup(aType)) {
1070 rel.AppendIter(new RemoteAccIterator(reverseIdsEntry.Data(), Document()));
1074 // We handle these relations here rather than before cached relations because
1075 // the cached relations need to take precedence. For example, a <figure> with
1076 // both aria-labelledby and a <figcaption> must return two LABELLED_BY
1077 // targets: the aria-labelledby and then the <figcaption>.
1078 if (aType == RelationType::LABELLED_BY && TagName() == nsGkAtoms::figure) {
1079 uint32_t count = ChildCount();
1080 for (uint32_t c = 0; c < count; ++c) {
1081 RemoteAccessible* child = RemoteChildAt(c);
1082 MOZ_ASSERT(child);
1083 if (child->TagName() == nsGkAtoms::figcaption) {
1084 rel.AppendTarget(child);
1087 } else if (aType == RelationType::LABEL_FOR &&
1088 TagName() == nsGkAtoms::figcaption) {
1089 if (RemoteAccessible* parent = RemoteParent()) {
1090 if (parent->TagName() == nsGkAtoms::figure) {
1091 rel.AppendTarget(parent);
1096 return rel;
1099 void RemoteAccessible::AppendTextTo(nsAString& aText, uint32_t aStartOffset,
1100 uint32_t aLength) {
1101 if (IsText()) {
1102 if (mCachedFields) {
1103 if (auto text = mCachedFields->GetAttribute<nsString>(CacheKey::Text)) {
1104 aText.Append(Substring(*text, aStartOffset, aLength));
1106 VERIFY_CACHE(CacheDomain::Text);
1108 return;
1111 if (aStartOffset != 0 || aLength == 0) {
1112 return;
1115 if (IsHTMLBr()) {
1116 aText += kForcedNewLineChar;
1117 } else if (RemoteParent() && nsAccUtils::MustPrune(RemoteParent())) {
1118 // Expose the embedded object accessible as imaginary embedded object
1119 // character if its parent hypertext accessible doesn't expose children to
1120 // AT.
1121 aText += kImaginaryEmbeddedObjectChar;
1122 } else {
1123 aText += kEmbeddedObjectChar;
1127 nsTArray<bool> RemoteAccessible::PreProcessRelations(AccAttributes* aFields) {
1128 nsTArray<bool> updateTracker(ArrayLength(kRelationTypeAtoms));
1129 for (auto const& data : kRelationTypeAtoms) {
1130 if (data.mValidTag) {
1131 // The relation we're currently processing only applies to particular
1132 // elements. Check to see if we're one of them.
1133 nsAtom* tag = TagName();
1134 if (!tag) {
1135 // TagName() returns null on an initial cache push -- check aFields
1136 // for a tag name instead.
1137 if (auto maybeTag =
1138 aFields->GetAttribute<RefPtr<nsAtom>>(CacheKey::TagName)) {
1139 tag = *maybeTag;
1142 MOZ_ASSERT(
1143 tag || IsTextLeaf() || IsDoc(),
1144 "Could not fetch tag via TagName() or from initial cache push!");
1145 if (tag != data.mValidTag) {
1146 // If this rel doesn't apply to us, do no pre-processing. Also,
1147 // note in our updateTracker that we should do no post-processing.
1148 updateTracker.AppendElement(false);
1149 continue;
1153 nsStaticAtom* const relAtom = data.mAtom;
1154 auto newRelationTargets =
1155 aFields->GetAttribute<nsTArray<uint64_t>>(relAtom);
1156 bool shouldAddNewImplicitRels =
1157 newRelationTargets && newRelationTargets->Length();
1159 // Remove existing implicit relations if we need to perform an update, or
1160 // if we've recieved a DeleteEntry(). Only do this if mCachedFields is
1161 // initialized. If mCachedFields is not initialized, we still need to
1162 // construct the update array so we correctly handle reverse rels in
1163 // PostProcessRelations.
1164 if ((shouldAddNewImplicitRels ||
1165 aFields->GetAttribute<DeleteEntry>(relAtom)) &&
1166 mCachedFields) {
1167 if (auto maybeOldIDs =
1168 mCachedFields->GetAttribute<nsTArray<uint64_t>>(relAtom)) {
1169 for (uint64_t id : *maybeOldIDs) {
1170 // For each target, fetch its reverse relation map
1171 // We need to call `Lookup` here instead of `LookupOrInsert` because
1172 // it's possible the ID we're querying is from an acc that has since
1173 // been Shutdown(), and so has intentionally removed its reverse rels
1174 // from the doc's reverse rel cache.
1175 if (auto reverseRels = Document()->mReverseRelations.Lookup(id)) {
1176 // Then fetch its reverse relation's ID list. This should be safe
1177 // to do via LookupOrInsert because by the time we've gotten here,
1178 // we know the acc and `this` are still alive in the doc. If we hit
1179 // the following assert, we don't have parity on implicit/explicit
1180 // rels and something is wrong.
1181 nsTArray<uint64_t>& reverseRelIDs =
1182 reverseRels->LookupOrInsert(data.mReverseType);
1183 // There might be other reverse relations stored for this acc, so
1184 // remove our ID instead of deleting the array entirely.
1185 DebugOnly<bool> removed = reverseRelIDs.RemoveElement(ID());
1186 MOZ_ASSERT(removed, "Can't find old reverse relation");
1192 updateTracker.AppendElement(shouldAddNewImplicitRels);
1195 return updateTracker;
1198 void RemoteAccessible::PostProcessRelations(const nsTArray<bool>& aToUpdate) {
1199 size_t updateCount = aToUpdate.Length();
1200 MOZ_ASSERT(updateCount == ArrayLength(kRelationTypeAtoms),
1201 "Did not note update status for every relation type!");
1202 for (size_t i = 0; i < updateCount; i++) {
1203 if (aToUpdate.ElementAt(i)) {
1204 // Since kRelationTypeAtoms was used to generate aToUpdate, we
1205 // know the ith entry of aToUpdate corresponds to the relation type in
1206 // the ith entry of kRelationTypeAtoms. Fetch the related data here.
1207 auto const& data = kRelationTypeAtoms[i];
1209 const nsTArray<uint64_t>& newIDs =
1210 *mCachedFields->GetAttribute<nsTArray<uint64_t>>(data.mAtom);
1211 for (uint64_t id : newIDs) {
1212 nsTHashMap<RelationType, nsTArray<uint64_t>>& relations =
1213 Document()->mReverseRelations.LookupOrInsert(id);
1214 nsTArray<uint64_t>& ids = relations.LookupOrInsert(data.mReverseType);
1215 ids.AppendElement(ID());
1221 void RemoteAccessible::PruneRelationsOnShutdown() {
1222 auto reverseRels = mDoc->mReverseRelations.Lookup(ID());
1223 if (!reverseRels) {
1224 return;
1226 for (auto const& data : kRelationTypeAtoms) {
1227 // Fetch the list of targets for this reverse relation
1228 auto reverseTargetList = reverseRels->Lookup(data.mReverseType);
1229 if (!reverseTargetList) {
1230 continue;
1232 for (uint64_t id : *reverseTargetList) {
1233 // For each target, retrieve its corresponding forward relation target
1234 // list
1235 RemoteAccessible* affectedAcc = mDoc->GetAccessible(id);
1236 if (!affectedAcc) {
1237 // It's possible the affect acc also shut down, in which case
1238 // we don't have anything to update.
1239 continue;
1241 if (auto forwardTargetList =
1242 affectedAcc->mCachedFields
1243 ->GetMutableAttribute<nsTArray<uint64_t>>(data.mAtom)) {
1244 forwardTargetList->RemoveElement(ID());
1245 if (!forwardTargetList->Length()) {
1246 // The ID we removed was the only thing in the list, so remove the
1247 // entry from the cache entirely -- don't leave an empty array.
1248 affectedAcc->mCachedFields->Remove(data.mAtom);
1253 // Remove this ID from the document's map of reverse relations.
1254 reverseRels.Remove();
1257 uint32_t RemoteAccessible::GetCachedTextLength() {
1258 MOZ_ASSERT(!HasChildren());
1259 if (!mCachedFields) {
1260 return 0;
1262 VERIFY_CACHE(CacheDomain::Text);
1263 auto text = mCachedFields->GetAttribute<nsString>(CacheKey::Text);
1264 if (!text) {
1265 return 0;
1267 return text->Length();
1270 Maybe<const nsTArray<int32_t>&> RemoteAccessible::GetCachedTextLines() {
1271 MOZ_ASSERT(!HasChildren());
1272 if (!mCachedFields) {
1273 return Nothing();
1275 VERIFY_CACHE(CacheDomain::Text);
1276 return mCachedFields->GetAttribute<nsTArray<int32_t>>(
1277 CacheKey::TextLineStarts);
1280 nsRect RemoteAccessible::GetCachedCharRect(int32_t aOffset) {
1281 MOZ_ASSERT(IsText());
1282 if (!mCachedFields) {
1283 return nsRect();
1286 if (Maybe<const nsTArray<int32_t>&> maybeCharData =
1287 mCachedFields->GetAttribute<nsTArray<int32_t>>(
1288 CacheKey::TextBounds)) {
1289 const nsTArray<int32_t>& charData = *maybeCharData;
1290 const int32_t index = aOffset * kNumbersInRect;
1291 if (index < static_cast<int32_t>(charData.Length())) {
1292 return nsRect(charData[index], charData[index + 1], charData[index + 2],
1293 charData[index + 3]);
1295 // It is valid for a client to call this with an offset 1 after the last
1296 // character because of the insertion point at the end of text boxes.
1297 MOZ_ASSERT(index == static_cast<int32_t>(charData.Length()));
1300 return nsRect();
1303 void RemoteAccessible::DOMNodeID(nsString& aID) const {
1304 if (mCachedFields) {
1305 mCachedFields->GetAttribute(CacheKey::DOMNodeID, aID);
1306 VERIFY_CACHE(CacheDomain::DOMNodeIDAndClass);
1310 void RemoteAccessible::ScrollToPoint(uint32_t aScrollType, int32_t aX,
1311 int32_t aY) {
1312 Unused << mDoc->SendScrollToPoint(mID, aScrollType, aX, aY);
1315 #if !defined(XP_WIN)
1316 void RemoteAccessible::Announce(const nsString& aAnnouncement,
1317 uint16_t aPriority) {
1318 Unused << mDoc->SendAnnounce(mID, aAnnouncement, aPriority);
1320 #endif // !defined(XP_WIN)
1322 void RemoteAccessible::ScrollSubstringToPoint(int32_t aStartOffset,
1323 int32_t aEndOffset,
1324 uint32_t aCoordinateType,
1325 int32_t aX, int32_t aY) {
1326 Unused << mDoc->SendScrollSubstringToPoint(mID, aStartOffset, aEndOffset,
1327 aCoordinateType, aX, aY);
1330 RefPtr<const AccAttributes> RemoteAccessible::GetCachedTextAttributes() {
1331 MOZ_ASSERT(IsText() || IsHyperText());
1332 if (mCachedFields) {
1333 auto attrs = mCachedFields->GetAttributeRefPtr<AccAttributes>(
1334 CacheKey::TextAttributes);
1335 VERIFY_CACHE(CacheDomain::Text);
1336 return attrs;
1338 return nullptr;
1341 already_AddRefed<AccAttributes> RemoteAccessible::DefaultTextAttributes() {
1342 RefPtr<const AccAttributes> attrs = GetCachedTextAttributes();
1343 RefPtr<AccAttributes> result = new AccAttributes();
1344 if (attrs) {
1345 attrs->CopyTo(result);
1347 return result.forget();
1350 RefPtr<const AccAttributes> RemoteAccessible::GetCachedARIAAttributes() const {
1351 if (mCachedFields) {
1352 auto attrs = mCachedFields->GetAttributeRefPtr<AccAttributes>(
1353 CacheKey::ARIAAttributes);
1354 VERIFY_CACHE(CacheDomain::ARIA);
1355 return attrs;
1357 return nullptr;
1360 nsString RemoteAccessible::GetCachedHTMLNameAttribute() const {
1361 if (mCachedFields) {
1362 if (auto maybeName =
1363 mCachedFields->GetAttribute<nsString>(CacheKey::DOMName)) {
1364 return *maybeName;
1367 return nsString();
1370 uint64_t RemoteAccessible::State() {
1371 uint64_t state = 0;
1372 if (mCachedFields) {
1373 if (auto rawState =
1374 mCachedFields->GetAttribute<uint64_t>(CacheKey::State)) {
1375 VERIFY_CACHE(CacheDomain::State);
1376 state = *rawState;
1377 // Handle states that are derived from other states.
1378 if (!(state & states::UNAVAILABLE)) {
1379 state |= states::ENABLED | states::SENSITIVE;
1381 if (state & states::EXPANDABLE && !(state & states::EXPANDED)) {
1382 state |= states::COLLAPSED;
1386 ApplyImplicitState(state);
1388 auto* cbc = mDoc->GetBrowsingContext();
1389 if (cbc && !cbc->IsActive()) {
1390 // If our browsing context is _not_ active, we're in a background tab
1391 // and inherently offscreen.
1392 state |= states::OFFSCREEN;
1393 } else {
1394 // If we're in an active browsing context, there are a few scenarios we
1395 // need to address:
1396 // - We are an iframe document in the visual viewport
1397 // - We are an iframe document out of the visual viewport
1398 // - We are non-iframe content in the visual viewport
1399 // - We are non-iframe content out of the visual viewport
1400 // We assume top level tab docs are on screen if their BC is active, so
1401 // we don't need additional handling for them here.
1402 if (!mDoc->IsTopLevel()) {
1403 // Here we handle iframes and iframe content.
1404 // We use an iframe's outer doc's position in the embedding document's
1405 // viewport to determine if the iframe has been scrolled offscreen.
1406 Accessible* docParent = mDoc->Parent();
1407 // In rare cases, we might not have an outer doc yet. Return if that's
1408 // the case.
1409 if (NS_WARN_IF(!docParent || !docParent->IsRemote())) {
1410 return state;
1413 RemoteAccessible* outerDoc = docParent->AsRemote();
1414 DocAccessibleParent* embeddingDocument = outerDoc->Document();
1415 if (embeddingDocument &&
1416 !embeddingDocument->mOnScreenAccessibles.Contains(outerDoc->ID())) {
1417 // Our embedding document's viewport cache doesn't contain the ID of
1418 // our outer doc, so this iframe (and any of its content) is
1419 // offscreen.
1420 state |= states::OFFSCREEN;
1421 } else if (this != mDoc && !mDoc->mOnScreenAccessibles.Contains(ID())) {
1422 // Our embedding document's viewport cache contains the ID of our
1423 // outer doc, but the iframe's viewport cache doesn't contain our ID.
1424 // We are offscreen.
1425 state |= states::OFFSCREEN;
1427 } else if (this != mDoc && !mDoc->mOnScreenAccessibles.Contains(ID())) {
1428 // We are top level tab content (but not a top level tab doc).
1429 // If our tab doc's viewport cache doesn't contain our ID, we're
1430 // offscreen.
1431 state |= states::OFFSCREEN;
1436 return state;
1439 already_AddRefed<AccAttributes> RemoteAccessible::Attributes() {
1440 RefPtr<AccAttributes> attributes = new AccAttributes();
1441 nsAccessibilityService* accService = GetAccService();
1442 if (!accService) {
1443 // The service can be shut down before RemoteAccessibles. If it is shut
1444 // down, we can't calculate some attributes. We're about to die anyway.
1445 return attributes.forget();
1448 if (mCachedFields) {
1449 // We use GetAttribute instead of GetAttributeRefPtr because we need
1450 // nsAtom, not const nsAtom.
1451 if (auto tag =
1452 mCachedFields->GetAttribute<RefPtr<nsAtom>>(CacheKey::TagName)) {
1453 attributes->SetAttribute(nsGkAtoms::tag, *tag);
1456 GroupPos groupPos = GroupPosition();
1457 nsAccUtils::SetAccGroupAttrs(attributes, groupPos.level, groupPos.setSize,
1458 groupPos.posInSet);
1460 bool hierarchical = false;
1461 uint32_t itemCount = AccGroupInfo::TotalItemCount(this, &hierarchical);
1462 if (itemCount) {
1463 attributes->SetAttribute(nsGkAtoms::child_item_count,
1464 static_cast<int32_t>(itemCount));
1467 if (hierarchical) {
1468 attributes->SetAttribute(nsGkAtoms::tree, true);
1471 if (auto inputType =
1472 mCachedFields->GetAttribute<RefPtr<nsAtom>>(CacheKey::InputType)) {
1473 attributes->SetAttribute(nsGkAtoms::textInputType, *inputType);
1476 if (RefPtr<nsAtom> display = DisplayStyle()) {
1477 attributes->SetAttribute(nsGkAtoms::display, display);
1480 if (TableCellAccessible* cell = AsTableCell()) {
1481 TableAccessible* table = cell->Table();
1482 uint32_t row = cell->RowIdx();
1483 uint32_t col = cell->ColIdx();
1484 int32_t cellIdx = table->CellIndexAt(row, col);
1485 if (cellIdx != -1) {
1486 attributes->SetAttribute(nsGkAtoms::tableCellIndex, cellIdx);
1490 if (bool layoutGuess = TableIsProbablyForLayout()) {
1491 attributes->SetAttribute(nsGkAtoms::layout_guess, layoutGuess);
1494 accService->MarkupAttributes(this, attributes);
1496 const nsRoleMapEntry* roleMap = ARIARoleMap();
1497 nsAutoString role;
1498 mCachedFields->GetAttribute(CacheKey::ARIARole, role);
1499 if (role.IsEmpty()) {
1500 if (roleMap && roleMap->roleAtom != nsGkAtoms::_empty) {
1501 // Single, known role.
1502 attributes->SetAttribute(nsGkAtoms::xmlroles, roleMap->roleAtom);
1503 } else if (nsAtom* landmark = LandmarkRole()) {
1504 // Landmark role from markup; e.g. HTML <main>.
1505 attributes->SetAttribute(nsGkAtoms::xmlroles, landmark);
1507 } else {
1508 // Unknown role or multiple roles.
1509 attributes->SetAttribute(nsGkAtoms::xmlroles, std::move(role));
1512 if (roleMap) {
1513 nsAutoString live;
1514 if (nsAccUtils::GetLiveAttrValue(roleMap->liveAttRule, live)) {
1515 attributes->SetAttribute(nsGkAtoms::aria_live, std::move(live));
1519 if (auto ariaAttrs = GetCachedARIAAttributes()) {
1520 ariaAttrs->CopyTo(attributes);
1523 nsAccUtils::SetLiveContainerAttributes(attributes, this);
1525 nsString id;
1526 DOMNodeID(id);
1527 if (!id.IsEmpty()) {
1528 attributes->SetAttribute(nsGkAtoms::id, std::move(id));
1531 nsString className;
1532 mCachedFields->GetAttribute(CacheKey::DOMNodeClass, className);
1533 if (!className.IsEmpty()) {
1534 attributes->SetAttribute(nsGkAtoms::_class, std::move(className));
1537 if (IsImage()) {
1538 nsString src;
1539 mCachedFields->GetAttribute(CacheKey::SrcURL, src);
1540 if (!src.IsEmpty()) {
1541 attributes->SetAttribute(nsGkAtoms::src, std::move(src));
1545 if (IsTextField()) {
1546 nsString placeholder;
1547 mCachedFields->GetAttribute(CacheKey::HTMLPlaceholder, placeholder);
1548 if (!placeholder.IsEmpty()) {
1549 attributes->SetAttribute(nsGkAtoms::placeholder,
1550 std::move(placeholder));
1551 attributes->Remove(nsGkAtoms::aria_placeholder);
1556 nsAutoString name;
1557 if (Name(name) != eNameFromSubtree && !name.IsVoid()) {
1558 attributes->SetAttribute(nsGkAtoms::explicit_name, true);
1561 // Expose the string value via the valuetext attribute. We test for the value
1562 // interface because we don't want to expose traditional Value() information
1563 // such as URLs on links and documents, or text in an input.
1564 // XXX This is only needed for ATK, since other APIs have native ways to
1565 // retrieve value text. We should probably move this into ATK specific code.
1566 // For now, we do this because LocalAccessible does it.
1567 if (HasNumericValue()) {
1568 nsString valuetext;
1569 Value(valuetext);
1570 attributes->SetAttribute(nsGkAtoms::aria_valuetext, std::move(valuetext));
1573 return attributes.forget();
1576 nsAtom* RemoteAccessible::TagName() const {
1577 if (mCachedFields) {
1578 if (auto tag =
1579 mCachedFields->GetAttribute<RefPtr<nsAtom>>(CacheKey::TagName)) {
1580 return *tag;
1584 return nullptr;
1587 already_AddRefed<nsAtom> RemoteAccessible::InputType() const {
1588 if (mCachedFields) {
1589 if (auto inputType =
1590 mCachedFields->GetAttribute<RefPtr<nsAtom>>(CacheKey::InputType)) {
1591 RefPtr<nsAtom> result = *inputType;
1592 return result.forget();
1596 return nullptr;
1599 already_AddRefed<nsAtom> RemoteAccessible::DisplayStyle() const {
1600 if (mCachedFields) {
1601 if (auto display =
1602 mCachedFields->GetAttribute<RefPtr<nsAtom>>(CacheKey::CSSDisplay)) {
1603 RefPtr<nsAtom> result = *display;
1604 return result.forget();
1607 return nullptr;
1610 float RemoteAccessible::Opacity() const {
1611 if (mCachedFields) {
1612 if (auto opacity = mCachedFields->GetAttribute<float>(CacheKey::Opacity)) {
1613 return *opacity;
1617 return 1.0f;
1620 void RemoteAccessible::LiveRegionAttributes(nsAString* aLive,
1621 nsAString* aRelevant,
1622 Maybe<bool>* aAtomic,
1623 nsAString* aBusy) const {
1624 if (!mCachedFields) {
1625 return;
1627 RefPtr<const AccAttributes> attrs = GetCachedARIAAttributes();
1628 if (!attrs) {
1629 return;
1631 if (aLive) {
1632 attrs->GetAttribute(nsGkAtoms::aria_live, *aLive);
1634 if (aRelevant) {
1635 attrs->GetAttribute(nsGkAtoms::aria_relevant, *aRelevant);
1637 if (aAtomic) {
1638 if (auto value =
1639 attrs->GetAttribute<RefPtr<nsAtom>>(nsGkAtoms::aria_atomic)) {
1640 *aAtomic = Some(*value == nsGkAtoms::_true);
1643 if (aBusy) {
1644 attrs->GetAttribute(nsGkAtoms::aria_busy, *aBusy);
1648 Maybe<bool> RemoteAccessible::ARIASelected() const {
1649 if (mCachedFields) {
1650 return mCachedFields->GetAttribute<bool>(CacheKey::ARIASelected);
1652 return Nothing();
1655 nsAtom* RemoteAccessible::GetPrimaryAction() const {
1656 if (mCachedFields) {
1657 if (auto action = mCachedFields->GetAttribute<RefPtr<nsAtom>>(
1658 CacheKey::PrimaryAction)) {
1659 return *action;
1663 return nullptr;
1666 uint8_t RemoteAccessible::ActionCount() const {
1667 uint8_t actionCount = 0;
1668 if (mCachedFields) {
1669 if (HasPrimaryAction() || ActionAncestor()) {
1670 actionCount++;
1673 if (mCachedFields->HasAttribute(CacheKey::HasLongdesc)) {
1674 actionCount++;
1676 VERIFY_CACHE(CacheDomain::Actions);
1679 return actionCount;
1682 void RemoteAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) {
1683 if (mCachedFields) {
1684 aName.Truncate();
1685 nsAtom* action = GetPrimaryAction();
1686 bool hasActionAncestor = !action && ActionAncestor();
1688 switch (aIndex) {
1689 case 0:
1690 if (action) {
1691 action->ToString(aName);
1692 } else if (hasActionAncestor) {
1693 aName.AssignLiteral("click ancestor");
1694 } else if (mCachedFields->HasAttribute(CacheKey::HasLongdesc)) {
1695 aName.AssignLiteral("showlongdesc");
1697 break;
1698 case 1:
1699 if ((action || hasActionAncestor) &&
1700 mCachedFields->HasAttribute(CacheKey::HasLongdesc)) {
1701 aName.AssignLiteral("showlongdesc");
1703 break;
1704 default:
1705 break;
1708 VERIFY_CACHE(CacheDomain::Actions);
1711 bool RemoteAccessible::DoAction(uint8_t aIndex) const {
1712 if (ActionCount() < aIndex + 1) {
1713 return false;
1716 Unused << mDoc->SendDoActionAsync(mID, aIndex);
1717 return true;
1720 KeyBinding RemoteAccessible::AccessKey() const {
1721 if (mCachedFields) {
1722 if (auto value =
1723 mCachedFields->GetAttribute<uint64_t>(CacheKey::AccessKey)) {
1724 return KeyBinding(*value);
1727 return KeyBinding();
1730 void RemoteAccessible::SelectionRanges(nsTArray<TextRange>* aRanges) const {
1731 Document()->SelectionRanges(aRanges);
1734 bool RemoteAccessible::RemoveFromSelection(int32_t aSelectionNum) {
1735 MOZ_ASSERT(IsHyperText());
1736 if (SelectionCount() <= aSelectionNum) {
1737 return false;
1740 Unused << mDoc->SendRemoveTextSelection(mID, aSelectionNum);
1742 return true;
1745 void RemoteAccessible::ARIAGroupPosition(int32_t* aLevel, int32_t* aSetSize,
1746 int32_t* aPosInSet) const {
1747 if (!mCachedFields) {
1748 return;
1751 if (aLevel) {
1752 if (auto level =
1753 mCachedFields->GetAttribute<int32_t>(nsGkAtoms::aria_level)) {
1754 *aLevel = *level;
1757 if (aSetSize) {
1758 if (auto setsize =
1759 mCachedFields->GetAttribute<int32_t>(nsGkAtoms::aria_setsize)) {
1760 *aSetSize = *setsize;
1763 if (aPosInSet) {
1764 if (auto posinset =
1765 mCachedFields->GetAttribute<int32_t>(nsGkAtoms::aria_posinset)) {
1766 *aPosInSet = *posinset;
1771 AccGroupInfo* RemoteAccessible::GetGroupInfo() const {
1772 if (!mCachedFields) {
1773 return nullptr;
1776 if (auto groupInfo = mCachedFields->GetAttribute<UniquePtr<AccGroupInfo>>(
1777 CacheKey::GroupInfo)) {
1778 return groupInfo->get();
1781 return nullptr;
1784 AccGroupInfo* RemoteAccessible::GetOrCreateGroupInfo() {
1785 AccGroupInfo* groupInfo = GetGroupInfo();
1786 if (groupInfo) {
1787 return groupInfo;
1790 groupInfo = AccGroupInfo::CreateGroupInfo(this);
1791 if (groupInfo) {
1792 if (!mCachedFields) {
1793 mCachedFields = new AccAttributes();
1796 mCachedFields->SetAttribute(CacheKey::GroupInfo, groupInfo);
1799 return groupInfo;
1802 void RemoteAccessible::InvalidateGroupInfo() {
1803 if (mCachedFields) {
1804 mCachedFields->Remove(CacheKey::GroupInfo);
1808 void RemoteAccessible::GetPositionAndSetSize(int32_t* aPosInSet,
1809 int32_t* aSetSize) {
1810 if (IsHTMLRadioButton()) {
1811 *aSetSize = 0;
1812 Relation rel = RelationByType(RelationType::MEMBER_OF);
1813 while (Accessible* radio = rel.Next()) {
1814 ++*aSetSize;
1815 if (radio == this) {
1816 *aPosInSet = *aSetSize;
1819 return;
1822 Accessible::GetPositionAndSetSize(aPosInSet, aSetSize);
1825 bool RemoteAccessible::HasPrimaryAction() const {
1826 return mCachedFields && mCachedFields->HasAttribute(CacheKey::PrimaryAction);
1829 void RemoteAccessible::TakeFocus() const { Unused << mDoc->SendTakeFocus(mID); }
1831 void RemoteAccessible::ScrollTo(uint32_t aHow) const {
1832 Unused << mDoc->SendScrollTo(mID, aHow);
1835 ////////////////////////////////////////////////////////////////////////////////
1836 // SelectAccessible
1838 void RemoteAccessible::SelectedItems(nsTArray<Accessible*>* aItems) {
1839 Pivot p = Pivot(this);
1840 PivotStateRule rule(states::SELECTED);
1841 for (Accessible* selected = p.First(rule); selected;
1842 selected = p.Next(selected, rule)) {
1843 aItems->AppendElement(selected);
1847 uint32_t RemoteAccessible::SelectedItemCount() {
1848 uint32_t count = 0;
1849 Pivot p = Pivot(this);
1850 PivotStateRule rule(states::SELECTED);
1851 for (Accessible* selected = p.First(rule); selected;
1852 selected = p.Next(selected, rule)) {
1853 count++;
1856 return count;
1859 Accessible* RemoteAccessible::GetSelectedItem(uint32_t aIndex) {
1860 uint32_t index = 0;
1861 Accessible* selected = nullptr;
1862 Pivot p = Pivot(this);
1863 PivotStateRule rule(states::SELECTED);
1864 for (selected = p.First(rule); selected && index < aIndex;
1865 selected = p.Next(selected, rule)) {
1866 index++;
1869 return selected;
1872 bool RemoteAccessible::IsItemSelected(uint32_t aIndex) {
1873 uint32_t index = 0;
1874 Accessible* selectable = nullptr;
1875 Pivot p = Pivot(this);
1876 PivotStateRule rule(states::SELECTABLE);
1877 for (selectable = p.First(rule); selectable && index < aIndex;
1878 selectable = p.Next(selectable, rule)) {
1879 index++;
1882 return selectable && selectable->State() & states::SELECTED;
1885 bool RemoteAccessible::AddItemToSelection(uint32_t aIndex) {
1886 uint32_t index = 0;
1887 Accessible* selectable = nullptr;
1888 Pivot p = Pivot(this);
1889 PivotStateRule rule(states::SELECTABLE);
1890 for (selectable = p.First(rule); selectable && index < aIndex;
1891 selectable = p.Next(selectable, rule)) {
1892 index++;
1895 if (selectable) selectable->SetSelected(true);
1897 return static_cast<bool>(selectable);
1900 bool RemoteAccessible::RemoveItemFromSelection(uint32_t aIndex) {
1901 uint32_t index = 0;
1902 Accessible* selectable = nullptr;
1903 Pivot p = Pivot(this);
1904 PivotStateRule rule(states::SELECTABLE);
1905 for (selectable = p.First(rule); selectable && index < aIndex;
1906 selectable = p.Next(selectable, rule)) {
1907 index++;
1910 if (selectable) selectable->SetSelected(false);
1912 return static_cast<bool>(selectable);
1915 bool RemoteAccessible::SelectAll() {
1916 if ((State() & states::MULTISELECTABLE) == 0) {
1917 return false;
1920 bool success = false;
1921 Accessible* selectable = nullptr;
1922 Pivot p = Pivot(this);
1923 PivotStateRule rule(states::SELECTABLE);
1924 for (selectable = p.First(rule); selectable;
1925 selectable = p.Next(selectable, rule)) {
1926 success = true;
1927 selectable->SetSelected(true);
1929 return success;
1932 bool RemoteAccessible::UnselectAll() {
1933 if ((State() & states::MULTISELECTABLE) == 0) {
1934 return false;
1937 bool success = false;
1938 Accessible* selectable = nullptr;
1939 Pivot p = Pivot(this);
1940 PivotStateRule rule(states::SELECTABLE);
1941 for (selectable = p.First(rule); selectable;
1942 selectable = p.Next(selectable, rule)) {
1943 success = true;
1944 selectable->SetSelected(false);
1946 return success;
1949 void RemoteAccessible::TakeSelection() {
1950 Unused << mDoc->SendTakeSelection(mID);
1953 void RemoteAccessible::SetSelected(bool aSelect) {
1954 Unused << mDoc->SendSetSelected(mID, aSelect);
1957 TableAccessible* RemoteAccessible::AsTable() {
1958 if (IsTable()) {
1959 return CachedTableAccessible::GetFrom(this);
1961 return nullptr;
1964 TableCellAccessible* RemoteAccessible::AsTableCell() {
1965 if (IsTableCell()) {
1966 return CachedTableCellAccessible::GetFrom(this);
1968 return nullptr;
1971 bool RemoteAccessible::TableIsProbablyForLayout() {
1972 if (mCachedFields) {
1973 if (auto layoutGuess =
1974 mCachedFields->GetAttribute<bool>(CacheKey::TableLayoutGuess)) {
1975 return *layoutGuess;
1978 return false;
1981 nsTArray<int32_t>& RemoteAccessible::GetCachedHyperTextOffsets() {
1982 if (mCachedFields) {
1983 if (auto offsets = mCachedFields->GetMutableAttribute<nsTArray<int32_t>>(
1984 CacheKey::HyperTextOffsets)) {
1985 return *offsets;
1988 nsTArray<int32_t> newOffsets;
1989 if (!mCachedFields) {
1990 mCachedFields = new AccAttributes();
1992 mCachedFields->SetAttribute(CacheKey::HyperTextOffsets,
1993 std::move(newOffsets));
1994 return *mCachedFields->GetMutableAttribute<nsTArray<int32_t>>(
1995 CacheKey::HyperTextOffsets);
1998 void RemoteAccessible::SetCaretOffset(int32_t aOffset) {
1999 Unused << mDoc->SendSetCaretOffset(mID, aOffset);
2002 Maybe<int32_t> RemoteAccessible::GetIntARIAAttr(nsAtom* aAttrName) const {
2003 if (RefPtr<const AccAttributes> attrs = GetCachedARIAAttributes()) {
2004 if (auto val = attrs->GetAttribute<int32_t>(aAttrName)) {
2005 return val;
2008 return Nothing();
2011 void RemoteAccessible::Language(nsAString& aLocale) {
2012 if (!IsHyperText()) {
2013 return;
2015 if (auto attrs = GetCachedTextAttributes()) {
2016 attrs->GetAttribute(nsGkAtoms::language, aLocale);
2020 void RemoteAccessible::ReplaceText(const nsAString& aText) {
2021 Unused << mDoc->SendReplaceText(mID, aText);
2024 void RemoteAccessible::InsertText(const nsAString& aText, int32_t aPosition) {
2025 Unused << mDoc->SendInsertText(mID, aText, aPosition);
2028 void RemoteAccessible::CopyText(int32_t aStartPos, int32_t aEndPos) {
2029 Unused << mDoc->SendCopyText(mID, aStartPos, aEndPos);
2032 void RemoteAccessible::CutText(int32_t aStartPos, int32_t aEndPos) {
2033 Unused << mDoc->SendCutText(mID, aStartPos, aEndPos);
2036 void RemoteAccessible::DeleteText(int32_t aStartPos, int32_t aEndPos) {
2037 Unused << mDoc->SendDeleteText(mID, aStartPos, aEndPos);
2040 void RemoteAccessible::PasteText(int32_t aPosition) {
2041 Unused << mDoc->SendPasteText(mID, aPosition);
2044 size_t RemoteAccessible::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) {
2045 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
2048 size_t RemoteAccessible::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) {
2049 size_t size = 0;
2051 // Count attributes.
2052 if (mCachedFields) {
2053 size += mCachedFields->SizeOfIncludingThis(aMallocSizeOf);
2056 // We don't recurse into mChildren because they're already counted in their
2057 // document's mAccessibles.
2058 size += mChildren.ShallowSizeOfExcludingThis(aMallocSizeOf);
2060 return size;
2063 } // namespace a11y
2064 } // namespace mozilla