|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* vim:expandtab:shiftwidth=4:tabstop=4: |
|
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 "ApplicationAccessibleWrap.h" |
|
9 |
|
10 #include "AccessibleApplication_i.c" |
|
11 #include "IUnknownImpl.h" |
|
12 |
|
13 #include "nsIGfxInfo.h" |
|
14 #include "nsIPersistentProperties2.h" |
|
15 #include "nsServiceManagerUtils.h" |
|
16 |
|
17 using namespace mozilla; |
|
18 using namespace mozilla::a11y; |
|
19 |
|
20 //////////////////////////////////////////////////////////////////////////////// |
|
21 // nsISupports |
|
22 NS_IMPL_ISUPPORTS_INHERITED0(ApplicationAccessibleWrap, |
|
23 ApplicationAccessible) |
|
24 |
|
25 already_AddRefed<nsIPersistentProperties> |
|
26 ApplicationAccessibleWrap::NativeAttributes() |
|
27 { |
|
28 nsCOMPtr<nsIPersistentProperties> attributes = |
|
29 do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID); |
|
30 |
|
31 nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1"); |
|
32 if (gfxInfo) { |
|
33 bool isD2DEnabled = false; |
|
34 gfxInfo->GetD2DEnabled(&isD2DEnabled); |
|
35 nsAutoString unused; |
|
36 attributes->SetStringProperty( |
|
37 NS_LITERAL_CSTRING("D2D"), |
|
38 isD2DEnabled ? NS_LITERAL_STRING("true") : NS_LITERAL_STRING("false"), |
|
39 unused); |
|
40 } |
|
41 |
|
42 return attributes.forget(); |
|
43 } |
|
44 |
|
45 //////////////////////////////////////////////////////////////////////////////// |
|
46 // IUnknown |
|
47 |
|
48 STDMETHODIMP |
|
49 ApplicationAccessibleWrap::QueryInterface(REFIID iid, void** ppv) |
|
50 { |
|
51 if (!ppv) |
|
52 return E_INVALIDARG; |
|
53 |
|
54 *ppv = nullptr; |
|
55 |
|
56 if (IID_IAccessibleApplication == iid) { |
|
57 *ppv = static_cast<IAccessibleApplication*>(this); |
|
58 (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); |
|
59 return S_OK; |
|
60 } |
|
61 |
|
62 return AccessibleWrap::QueryInterface(iid, ppv); |
|
63 } |
|
64 |
|
65 //////////////////////////////////////////////////////////////////////////////// |
|
66 // IAccessibleApplication |
|
67 |
|
68 STDMETHODIMP |
|
69 ApplicationAccessibleWrap::get_appName(BSTR* aName) |
|
70 { |
|
71 A11Y_TRYBLOCK_BEGIN |
|
72 |
|
73 if (!aName) |
|
74 return E_INVALIDARG; |
|
75 |
|
76 *aName = nullptr; |
|
77 |
|
78 if (IsDefunct()) |
|
79 return CO_E_OBJNOTCONNECTED; |
|
80 |
|
81 nsAutoString name; |
|
82 nsresult rv = GetAppName(name); |
|
83 if (NS_FAILED(rv)) |
|
84 return GetHRESULT(rv); |
|
85 |
|
86 if (name.IsEmpty()) |
|
87 return S_FALSE; |
|
88 |
|
89 *aName = ::SysAllocStringLen(name.get(), name.Length()); |
|
90 return *aName ? S_OK : E_OUTOFMEMORY; |
|
91 |
|
92 A11Y_TRYBLOCK_END |
|
93 } |
|
94 |
|
95 STDMETHODIMP |
|
96 ApplicationAccessibleWrap::get_appVersion(BSTR* aVersion) |
|
97 { |
|
98 A11Y_TRYBLOCK_BEGIN |
|
99 |
|
100 if (!aVersion) |
|
101 return E_INVALIDARG; |
|
102 |
|
103 *aVersion = nullptr; |
|
104 |
|
105 if (IsDefunct()) |
|
106 return CO_E_OBJNOTCONNECTED; |
|
107 |
|
108 nsAutoString version; |
|
109 nsresult rv = GetAppVersion(version); |
|
110 if (NS_FAILED(rv)) |
|
111 return GetHRESULT(rv); |
|
112 |
|
113 if (version.IsEmpty()) |
|
114 return S_FALSE; |
|
115 |
|
116 *aVersion = ::SysAllocStringLen(version.get(), version.Length()); |
|
117 return *aVersion ? S_OK : E_OUTOFMEMORY; |
|
118 |
|
119 A11Y_TRYBLOCK_END |
|
120 } |
|
121 |
|
122 STDMETHODIMP |
|
123 ApplicationAccessibleWrap::get_toolkitName(BSTR* aName) |
|
124 { |
|
125 A11Y_TRYBLOCK_BEGIN |
|
126 |
|
127 if (!aName) |
|
128 return E_INVALIDARG; |
|
129 |
|
130 if (IsDefunct()) |
|
131 return CO_E_OBJNOTCONNECTED; |
|
132 |
|
133 nsAutoString name; |
|
134 nsresult rv = GetPlatformName(name); |
|
135 if (NS_FAILED(rv)) |
|
136 return GetHRESULT(rv); |
|
137 |
|
138 if (name.IsEmpty()) |
|
139 return S_FALSE; |
|
140 |
|
141 *aName = ::SysAllocStringLen(name.get(), name.Length()); |
|
142 return *aName ? S_OK : E_OUTOFMEMORY; |
|
143 |
|
144 A11Y_TRYBLOCK_END |
|
145 } |
|
146 |
|
147 STDMETHODIMP |
|
148 ApplicationAccessibleWrap::get_toolkitVersion(BSTR* aVersion) |
|
149 { |
|
150 A11Y_TRYBLOCK_BEGIN |
|
151 |
|
152 if (!aVersion) |
|
153 return E_INVALIDARG; |
|
154 |
|
155 *aVersion = nullptr; |
|
156 |
|
157 if (IsDefunct()) |
|
158 return CO_E_OBJNOTCONNECTED; |
|
159 |
|
160 nsAutoString version; |
|
161 nsresult rv = GetPlatformVersion(version); |
|
162 if (NS_FAILED(rv)) |
|
163 return GetHRESULT(rv); |
|
164 |
|
165 if (version.IsEmpty()) |
|
166 return S_FALSE; |
|
167 |
|
168 *aVersion = ::SysAllocStringLen(version.get(), version.Length()); |
|
169 return *aVersion ? S_OK : E_OUTOFMEMORY; |
|
170 |
|
171 A11Y_TRYBLOCK_END |
|
172 } |
|
173 |