|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:expandtab:shiftwidth=2:tabstop=2: |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #include "ia2AccessibleRelation.h" |
|
9 |
|
10 #include "Relation.h" |
|
11 #include "nsIAccessibleRelation.h" |
|
12 #include "nsID.h" |
|
13 |
|
14 #include "AccessibleRelation_i.c" |
|
15 |
|
16 using namespace mozilla::a11y; |
|
17 |
|
18 ia2AccessibleRelation::ia2AccessibleRelation(RelationType aType, Relation* aRel) : |
|
19 mType(aType) |
|
20 { |
|
21 Accessible* target = nullptr; |
|
22 while ((target = aRel->Next())) |
|
23 mTargets.AppendElement(target); |
|
24 } |
|
25 |
|
26 // IUnknown |
|
27 |
|
28 IMPL_IUNKNOWN_QUERY_HEAD(ia2AccessibleRelation) |
|
29 IMPL_IUNKNOWN_QUERY_IFACE(IAccessibleRelation) |
|
30 IMPL_IUNKNOWN_QUERY_IFACE(IUnknown) |
|
31 IMPL_IUNKNOWN_QUERY_TAIL |
|
32 |
|
33 // IAccessibleRelation |
|
34 |
|
35 STDMETHODIMP |
|
36 ia2AccessibleRelation::get_relationType(BSTR* aRelationType) |
|
37 { |
|
38 A11Y_TRYBLOCK_BEGIN |
|
39 |
|
40 if (!aRelationType) |
|
41 return E_INVALIDARG; |
|
42 |
|
43 *aRelationType = nullptr; |
|
44 |
|
45 #define RELATIONTYPE(geckoType, geckoTypeName, atkType, msaaType, ia2Type) \ |
|
46 case RelationType::geckoType: \ |
|
47 *aRelationType = ::SysAllocString(ia2Type); \ |
|
48 break; |
|
49 |
|
50 switch (mType) { |
|
51 #include "RelationTypeMap.h" |
|
52 } |
|
53 |
|
54 return *aRelationType ? S_OK : E_OUTOFMEMORY; |
|
55 |
|
56 A11Y_TRYBLOCK_END |
|
57 } |
|
58 |
|
59 STDMETHODIMP |
|
60 ia2AccessibleRelation::get_localizedRelationType(BSTR *aLocalizedRelationType) |
|
61 { |
|
62 A11Y_TRYBLOCK_BEGIN |
|
63 |
|
64 if (!aLocalizedRelationType) |
|
65 return E_INVALIDARG; |
|
66 |
|
67 *aLocalizedRelationType = nullptr; |
|
68 return E_NOTIMPL; |
|
69 |
|
70 A11Y_TRYBLOCK_END |
|
71 } |
|
72 |
|
73 STDMETHODIMP |
|
74 ia2AccessibleRelation::get_nTargets(long *aNTargets) |
|
75 { |
|
76 A11Y_TRYBLOCK_BEGIN |
|
77 |
|
78 if (!aNTargets) |
|
79 return E_INVALIDARG; |
|
80 |
|
81 *aNTargets = mTargets.Length(); |
|
82 return S_OK; |
|
83 |
|
84 A11Y_TRYBLOCK_END |
|
85 } |
|
86 |
|
87 STDMETHODIMP |
|
88 ia2AccessibleRelation::get_target(long aTargetIndex, IUnknown **aTarget) |
|
89 { |
|
90 A11Y_TRYBLOCK_BEGIN |
|
91 |
|
92 if (aTargetIndex < 0 || (uint32_t)aTargetIndex >= mTargets.Length() || !aTarget) |
|
93 return E_INVALIDARG; |
|
94 |
|
95 AccessibleWrap* target = |
|
96 static_cast<AccessibleWrap*>(mTargets[aTargetIndex].get()); |
|
97 *aTarget = static_cast<IAccessible*>(target); |
|
98 (*aTarget)->AddRef(); |
|
99 |
|
100 return S_OK; |
|
101 |
|
102 A11Y_TRYBLOCK_END |
|
103 } |
|
104 |
|
105 STDMETHODIMP |
|
106 ia2AccessibleRelation::get_targets(long aMaxTargets, IUnknown **aTargets, |
|
107 long *aNTargets) |
|
108 { |
|
109 A11Y_TRYBLOCK_BEGIN |
|
110 |
|
111 if (!aNTargets || !aTargets) |
|
112 return E_INVALIDARG; |
|
113 |
|
114 *aNTargets = 0; |
|
115 long maxTargets = mTargets.Length(); |
|
116 if (maxTargets > aMaxTargets) |
|
117 maxTargets = aMaxTargets; |
|
118 |
|
119 for (long idx = 0; idx < maxTargets; idx++) |
|
120 get_target(idx, aTargets + idx); |
|
121 |
|
122 *aNTargets = maxTargets; |
|
123 return S_OK; |
|
124 |
|
125 A11Y_TRYBLOCK_END |
|
126 } |