|
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 "ia2AccessibleComponent.h" |
|
9 |
|
10 #include "AccessibleComponent_i.c" |
|
11 |
|
12 #include "AccessibleWrap.h" |
|
13 #include "States.h" |
|
14 #include "IUnknownImpl.h" |
|
15 |
|
16 #include "nsIFrame.h" |
|
17 |
|
18 using namespace mozilla::a11y; |
|
19 |
|
20 // IUnknown |
|
21 |
|
22 STDMETHODIMP |
|
23 ia2AccessibleComponent::QueryInterface(REFIID iid, void** ppv) |
|
24 { |
|
25 if (!ppv) |
|
26 return E_INVALIDARG; |
|
27 |
|
28 *ppv = nullptr; |
|
29 |
|
30 if (IID_IAccessibleComponent == iid) { |
|
31 *ppv = static_cast<IAccessibleComponent*>(this); |
|
32 (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); |
|
33 return S_OK; |
|
34 } |
|
35 |
|
36 return E_NOINTERFACE; |
|
37 } |
|
38 |
|
39 // IAccessibleComponent |
|
40 |
|
41 STDMETHODIMP |
|
42 ia2AccessibleComponent::get_locationInParent(long* aX, long* aY) |
|
43 { |
|
44 A11Y_TRYBLOCK_BEGIN |
|
45 |
|
46 if (!aX || !aY) |
|
47 return E_INVALIDARG; |
|
48 |
|
49 *aX = 0; |
|
50 *aY = 0; |
|
51 |
|
52 AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); |
|
53 if (acc->IsDefunct()) |
|
54 return CO_E_OBJNOTCONNECTED; |
|
55 |
|
56 // If the object is not on any screen the returned position is (0,0). |
|
57 uint64_t state = acc->State(); |
|
58 if (state & states::INVISIBLE) |
|
59 return S_OK; |
|
60 |
|
61 int32_t x = 0, y = 0, width = 0, height = 0; |
|
62 nsresult rv = acc->GetBounds(&x, &y, &width, &height); |
|
63 if (NS_FAILED(rv)) |
|
64 return GetHRESULT(rv); |
|
65 |
|
66 Accessible* parentAcc = acc->Parent(); |
|
67 |
|
68 // The coordinates of the returned position are relative to this object's |
|
69 // parent or relative to the screen on which this object is rendered if it |
|
70 // has no parent. |
|
71 if (!parentAcc) { |
|
72 *aX = x; |
|
73 *aY = y; |
|
74 return S_OK; |
|
75 } |
|
76 |
|
77 // The coordinates of the bounding box are given relative to the parent's |
|
78 // coordinate system. |
|
79 int32_t parentx = 0, parenty = 0; |
|
80 rv = acc->GetBounds(&parentx, &parenty, &width, &height); |
|
81 if (NS_FAILED(rv)) |
|
82 return GetHRESULT(rv); |
|
83 |
|
84 *aX = x - parentx; |
|
85 *aY = y - parenty; |
|
86 return S_OK; |
|
87 |
|
88 A11Y_TRYBLOCK_END |
|
89 } |
|
90 |
|
91 STDMETHODIMP |
|
92 ia2AccessibleComponent::get_foreground(IA2Color* aForeground) |
|
93 { |
|
94 A11Y_TRYBLOCK_BEGIN |
|
95 |
|
96 if (!aForeground) |
|
97 return E_INVALIDARG; |
|
98 |
|
99 *aForeground = 0; |
|
100 |
|
101 AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); |
|
102 if (acc->IsDefunct()) |
|
103 return CO_E_OBJNOTCONNECTED; |
|
104 |
|
105 nsIFrame* frame = acc->GetFrame(); |
|
106 if (frame) |
|
107 *aForeground = frame->StyleColor()->mColor; |
|
108 |
|
109 return S_OK; |
|
110 |
|
111 A11Y_TRYBLOCK_END |
|
112 } |
|
113 |
|
114 STDMETHODIMP |
|
115 ia2AccessibleComponent::get_background(IA2Color* aBackground) |
|
116 { |
|
117 A11Y_TRYBLOCK_BEGIN |
|
118 |
|
119 if (!aBackground) |
|
120 return E_INVALIDARG; |
|
121 |
|
122 *aBackground = 0; |
|
123 |
|
124 AccessibleWrap* acc = static_cast<AccessibleWrap*>(this); |
|
125 if (acc->IsDefunct()) |
|
126 return CO_E_OBJNOTCONNECTED; |
|
127 |
|
128 nsIFrame* frame = acc->GetFrame(); |
|
129 if (frame) |
|
130 *aBackground = frame->StyleBackground()->mBackgroundColor; |
|
131 |
|
132 return S_OK; |
|
133 |
|
134 A11Y_TRYBLOCK_END |
|
135 } |
|
136 |