Bug 1687263: part 4) Defer and in some cases avoid removing spellchecking-ranges...
[gecko.git] / accessible / base / AccessibleOrProxy.cpp
blobf9ab7e6a253de5be314e7acbf7aeee01ec286753
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 "AccessibleOrProxy.h"
8 #include "mozilla/a11y/DocAccessibleParent.h"
9 #include "mozilla/a11y/OuterDocAccessible.h"
11 namespace mozilla {
12 namespace a11y {
14 int32_t AccessibleOrProxy::IndexInParent() const {
15 if (IsAccessible()) {
16 return AsAccessible()->IndexInParent();
19 RemoteAccessible* proxy = AsProxy();
20 if (!proxy) {
21 return -1;
24 if (proxy->RemoteParent()) {
25 return proxy->IndexInParent();
28 if (proxy->OuterDocOfRemoteBrowser()) {
29 return 0;
32 MOZ_ASSERT_UNREACHABLE("Proxy should have parent or outer doc.");
33 return -1;
36 AccessibleOrProxy AccessibleOrProxy::Parent() const {
37 if (IsAccessible()) {
38 return AsAccessible()->LocalParent();
41 RemoteAccessible* proxy = AsProxy();
42 if (!proxy) {
43 return nullptr;
46 if (RemoteAccessible* parent = proxy->RemoteParent()) {
47 return parent;
50 // Otherwise this should be the proxy for the tab's top level document.
51 return proxy->OuterDocOfRemoteBrowser();
54 AccessibleOrProxy AccessibleOrProxy::ChildAtPoint(
55 int32_t aX, int32_t aY, Accessible::EWhichChildAtPoint aWhichChild) {
56 // XXX: This implementation is silly now, but it will go away with AoP...
57 Accessible* result = IsProxy()
58 ? AsProxy()->ChildAtPoint(aX, aY, aWhichChild)
59 : AsAccessible()->ChildAtPoint(aX, aY, aWhichChild);
60 if (!result) {
61 return nullptr;
64 if (result->IsLocal()) {
65 return result->AsLocal();
68 if (result->IsRemote()) {
69 return result->AsRemote();
72 return nullptr;
75 RemoteAccessible* AccessibleOrProxy::RemoteChildDoc() const {
76 MOZ_ASSERT(!IsNull());
77 if (IsProxy()) {
78 return nullptr;
80 OuterDocAccessible* outerDoc = AsAccessible()->AsOuterDoc();
81 if (!outerDoc) {
82 return nullptr;
84 return outerDoc->RemoteChildDoc();
87 } // namespace a11y
88 } // namespace mozilla