Bug 1521243 - Show a warning for invalid declarations and filter icon for overridden...
[gecko.git] / accessible / android / ProxyAccessibleWrap.h
blob3eff3860b8f042f58212833b61b2d6b5f052720d
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/. *
6 */
8 #ifndef MOZILLA_A11Y_ProxyAccessibleWrap_h
9 #define MOZILLA_A11Y_ProxyAccessibleWrap_h
11 #include "AccessibleWrap.h"
12 #include "DocAccessibleParent.h"
14 namespace mozilla {
15 namespace a11y {
17 /**
18 * A wrapper for Accessible proxies. The public methods here should be overriden
19 * from AccessibleWrap or its super classes.
20 * This gives us an abstraction layer so SessionAccessibility doesn't have
21 * to distinguish between a local or remote accessibles.
22 * NOTE: This shouldn't be regarded as a full Accessible implementation.
24 class ProxyAccessibleWrap : public AccessibleWrap {
25 public:
26 explicit ProxyAccessibleWrap(ProxyAccessible* aProxy);
28 virtual void Shutdown() override;
30 // Accessible
32 virtual already_AddRefed<nsIPersistentProperties> Attributes() override;
34 virtual uint32_t ChildCount() const override;
36 virtual Accessible* GetChildAt(uint32_t aIndex) const override;
38 virtual ENameValueFlag Name(nsString& aName) const override;
40 virtual void Value(nsString& aValue) const override;
42 virtual uint64_t State() override;
44 virtual nsIntRect Bounds() const override;
46 virtual void ScrollTo(uint32_t aHow) const override;
48 virtual uint8_t ActionCount() const override;
50 virtual bool DoAction(uint8_t aIndex) const override;
52 // AccessibleWrap
54 virtual void SetTextContents(const nsAString& aText) override;
56 virtual void GetTextContents(nsAString& aText) override;
58 virtual bool GetSelectionBounds(int32_t* aStartOffset,
59 int32_t* aEndOffset) override;
61 virtual void WrapperDOMNodeID(nsString& aDOMNodeID) override;
63 private:
64 virtual role WrapperRole() override;
66 virtual AccessibleWrap* WrapperParent() override;
68 virtual bool WrapperRangeInfo(double* aCurVal, double* aMinVal,
69 double* aMaxVal, double* aStep) override;
72 class DocProxyAccessibleWrap : public ProxyAccessibleWrap {
73 public:
74 explicit DocProxyAccessibleWrap(DocAccessibleParent* aProxy)
75 : ProxyAccessibleWrap(aProxy) {
76 mGenericTypes |= eDocument;
78 if (auto parent = ParentDocument()) {
79 mID = AcquireID();
80 parent->AddID(mID, this);
81 } else {
82 // top level
83 mID = kNoID;
87 virtual void Shutdown() override {
88 if (mID) {
89 auto parent = ParentDocument();
90 if (parent) {
91 MOZ_ASSERT(mID != kNoID, "A non root accessible always has a parent");
92 parent->RemoveID(mID);
93 ReleaseID(mID);
96 mID = 0;
97 mBits.proxy = nullptr;
98 mStateFlags |= eIsDefunct;
101 DocProxyAccessibleWrap* ParentDocument() {
102 DocAccessibleParent* proxy = static_cast<DocAccessibleParent*>(Proxy());
103 MOZ_ASSERT(proxy);
104 if (DocAccessibleParent* parent = proxy->ParentDoc()) {
105 return reinterpret_cast<DocProxyAccessibleWrap*>(parent->GetWrapper());
108 return nullptr;
111 DocProxyAccessibleWrap* GetChildDocumentAt(uint32_t aIndex) {
112 auto doc = Proxy()->AsDoc();
113 if (doc && doc->ChildDocCount() > aIndex) {
114 return reinterpret_cast<DocProxyAccessibleWrap*>(
115 doc->ChildDocAt(aIndex)->GetWrapper());
118 return nullptr;
121 void AddID(uint32_t aID, AccessibleWrap* aAcc) {
122 mIDToAccessibleMap.Put(aID, aAcc);
124 void RemoveID(uint32_t aID) { mIDToAccessibleMap.Remove(aID); }
125 AccessibleWrap* GetAccessibleByID(uint32_t aID) const {
126 return mIDToAccessibleMap.Get(aID);
129 private:
131 * This provides a mapping from 32 bit id to accessible objects.
133 nsDataHashtable<nsUint32HashKey, AccessibleWrap*> mIDToAccessibleMap;
135 } // namespace a11y
136 } // namespace mozilla
138 #endif