Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* vim:expandtab:shiftwidth=4:tabstop=4: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "ApplicationAccessible.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "nsAccessibilityService.h" |
michael@0 | 11 | #include "nsAccUtils.h" |
michael@0 | 12 | #include "Relation.h" |
michael@0 | 13 | #include "Role.h" |
michael@0 | 14 | #include "States.h" |
michael@0 | 15 | |
michael@0 | 16 | #include "nsIComponentManager.h" |
michael@0 | 17 | #include "nsIDOMDocument.h" |
michael@0 | 18 | #include "nsIDOMWindow.h" |
michael@0 | 19 | #include "nsIWindowMediator.h" |
michael@0 | 20 | #include "nsServiceManagerUtils.h" |
michael@0 | 21 | #include "mozilla/Services.h" |
michael@0 | 22 | #include "nsIStringBundle.h" |
michael@0 | 23 | |
michael@0 | 24 | using namespace mozilla::a11y; |
michael@0 | 25 | |
michael@0 | 26 | ApplicationAccessible::ApplicationAccessible() : |
michael@0 | 27 | AccessibleWrap(nullptr, nullptr) |
michael@0 | 28 | { |
michael@0 | 29 | mType = eApplicationType; |
michael@0 | 30 | mAppInfo = do_GetService("@mozilla.org/xre/app-info;1"); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 34 | // nsISupports |
michael@0 | 35 | |
michael@0 | 36 | NS_IMPL_ISUPPORTS_INHERITED(ApplicationAccessible, Accessible, |
michael@0 | 37 | nsIAccessibleApplication) |
michael@0 | 38 | |
michael@0 | 39 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 40 | // nsIAccessible |
michael@0 | 41 | |
michael@0 | 42 | NS_IMETHODIMP |
michael@0 | 43 | ApplicationAccessible::GetParent(nsIAccessible** aAccessible) |
michael@0 | 44 | { |
michael@0 | 45 | NS_ENSURE_ARG_POINTER(aAccessible); |
michael@0 | 46 | *aAccessible = nullptr; |
michael@0 | 47 | return NS_OK; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | NS_IMETHODIMP |
michael@0 | 51 | ApplicationAccessible::GetNextSibling(nsIAccessible** aNextSibling) |
michael@0 | 52 | { |
michael@0 | 53 | NS_ENSURE_ARG_POINTER(aNextSibling); |
michael@0 | 54 | *aNextSibling = nullptr; |
michael@0 | 55 | return NS_OK; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | NS_IMETHODIMP |
michael@0 | 59 | ApplicationAccessible::GetPreviousSibling(nsIAccessible** aPreviousSibling) |
michael@0 | 60 | { |
michael@0 | 61 | NS_ENSURE_ARG_POINTER(aPreviousSibling); |
michael@0 | 62 | *aPreviousSibling = nullptr; |
michael@0 | 63 | return NS_OK; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | ENameValueFlag |
michael@0 | 67 | ApplicationAccessible::Name(nsString& aName) |
michael@0 | 68 | { |
michael@0 | 69 | aName.Truncate(); |
michael@0 | 70 | |
michael@0 | 71 | nsCOMPtr<nsIStringBundleService> bundleService = |
michael@0 | 72 | mozilla::services::GetStringBundleService(); |
michael@0 | 73 | |
michael@0 | 74 | NS_ASSERTION(bundleService, "String bundle service must be present!"); |
michael@0 | 75 | if (!bundleService) |
michael@0 | 76 | return eNameOK; |
michael@0 | 77 | |
michael@0 | 78 | nsCOMPtr<nsIStringBundle> bundle; |
michael@0 | 79 | nsresult rv = bundleService->CreateBundle("chrome://branding/locale/brand.properties", |
michael@0 | 80 | getter_AddRefs(bundle)); |
michael@0 | 81 | if (NS_FAILED(rv)) |
michael@0 | 82 | return eNameOK; |
michael@0 | 83 | |
michael@0 | 84 | nsXPIDLString appName; |
michael@0 | 85 | rv = bundle->GetStringFromName(MOZ_UTF16("brandShortName"), |
michael@0 | 86 | getter_Copies(appName)); |
michael@0 | 87 | if (NS_FAILED(rv) || appName.IsEmpty()) { |
michael@0 | 88 | NS_WARNING("brandShortName not found, using default app name"); |
michael@0 | 89 | appName.AssignLiteral("Gecko based application"); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | aName.Assign(appName); |
michael@0 | 93 | return eNameOK; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | void |
michael@0 | 97 | ApplicationAccessible::Description(nsString& aDescription) |
michael@0 | 98 | { |
michael@0 | 99 | aDescription.Truncate(); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | void |
michael@0 | 103 | ApplicationAccessible::Value(nsString& aValue) |
michael@0 | 104 | { |
michael@0 | 105 | aValue.Truncate(); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | uint64_t |
michael@0 | 109 | ApplicationAccessible::State() |
michael@0 | 110 | { |
michael@0 | 111 | return IsDefunct() ? states::DEFUNCT : 0; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | already_AddRefed<nsIPersistentProperties> |
michael@0 | 115 | ApplicationAccessible::NativeAttributes() |
michael@0 | 116 | { |
michael@0 | 117 | return nullptr; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | GroupPos |
michael@0 | 121 | ApplicationAccessible::GroupPosition() |
michael@0 | 122 | { |
michael@0 | 123 | return GroupPos(); |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | Accessible* |
michael@0 | 127 | ApplicationAccessible::ChildAtPoint(int32_t aX, int32_t aY, |
michael@0 | 128 | EWhichChildAtPoint aWhichChild) |
michael@0 | 129 | { |
michael@0 | 130 | return nullptr; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | Accessible* |
michael@0 | 134 | ApplicationAccessible::FocusedChild() |
michael@0 | 135 | { |
michael@0 | 136 | Accessible* focus = FocusMgr()->FocusedAccessible(); |
michael@0 | 137 | if (focus && focus->Parent() == this) |
michael@0 | 138 | return focus; |
michael@0 | 139 | |
michael@0 | 140 | return nullptr; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | Relation |
michael@0 | 144 | ApplicationAccessible::RelationByType(RelationType aRelationType) |
michael@0 | 145 | { |
michael@0 | 146 | return Relation(); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | NS_IMETHODIMP |
michael@0 | 150 | ApplicationAccessible::GetBounds(int32_t* aX, int32_t* aY, |
michael@0 | 151 | int32_t* aWidth, int32_t* aHeight) |
michael@0 | 152 | { |
michael@0 | 153 | NS_ENSURE_ARG_POINTER(aX); |
michael@0 | 154 | *aX = 0; |
michael@0 | 155 | NS_ENSURE_ARG_POINTER(aY); |
michael@0 | 156 | *aY = 0; |
michael@0 | 157 | NS_ENSURE_ARG_POINTER(aWidth); |
michael@0 | 158 | *aWidth = 0; |
michael@0 | 159 | NS_ENSURE_ARG_POINTER(aHeight); |
michael@0 | 160 | *aHeight = 0; |
michael@0 | 161 | return NS_OK; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | NS_IMETHODIMP |
michael@0 | 165 | ApplicationAccessible::SetSelected(bool aIsSelected) |
michael@0 | 166 | { |
michael@0 | 167 | return NS_OK; |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | NS_IMETHODIMP |
michael@0 | 171 | ApplicationAccessible::TakeSelection() |
michael@0 | 172 | { |
michael@0 | 173 | return NS_OK; |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | NS_IMETHODIMP |
michael@0 | 177 | ApplicationAccessible::TakeFocus() |
michael@0 | 178 | { |
michael@0 | 179 | return NS_OK; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | uint8_t |
michael@0 | 183 | ApplicationAccessible::ActionCount() |
michael@0 | 184 | { |
michael@0 | 185 | return 0; |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | NS_IMETHODIMP |
michael@0 | 189 | ApplicationAccessible::GetActionName(uint8_t aIndex, nsAString& aName) |
michael@0 | 190 | { |
michael@0 | 191 | aName.Truncate(); |
michael@0 | 192 | return NS_ERROR_INVALID_ARG; |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | NS_IMETHODIMP |
michael@0 | 196 | ApplicationAccessible::GetActionDescription(uint8_t aIndex, |
michael@0 | 197 | nsAString& aDescription) |
michael@0 | 198 | { |
michael@0 | 199 | aDescription.Truncate(); |
michael@0 | 200 | return NS_ERROR_INVALID_ARG; |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | NS_IMETHODIMP |
michael@0 | 204 | ApplicationAccessible::DoAction(uint8_t aIndex) |
michael@0 | 205 | { |
michael@0 | 206 | return NS_OK; |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 210 | // nsIAccessibleApplication |
michael@0 | 211 | |
michael@0 | 212 | NS_IMETHODIMP |
michael@0 | 213 | ApplicationAccessible::GetAppName(nsAString& aName) |
michael@0 | 214 | { |
michael@0 | 215 | aName.Truncate(); |
michael@0 | 216 | |
michael@0 | 217 | if (!mAppInfo) |
michael@0 | 218 | return NS_ERROR_FAILURE; |
michael@0 | 219 | |
michael@0 | 220 | nsAutoCString cname; |
michael@0 | 221 | nsresult rv = mAppInfo->GetName(cname); |
michael@0 | 222 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 223 | |
michael@0 | 224 | AppendUTF8toUTF16(cname, aName); |
michael@0 | 225 | return NS_OK; |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | NS_IMETHODIMP |
michael@0 | 229 | ApplicationAccessible::GetAppVersion(nsAString& aVersion) |
michael@0 | 230 | { |
michael@0 | 231 | aVersion.Truncate(); |
michael@0 | 232 | |
michael@0 | 233 | if (!mAppInfo) |
michael@0 | 234 | return NS_ERROR_FAILURE; |
michael@0 | 235 | |
michael@0 | 236 | nsAutoCString cversion; |
michael@0 | 237 | nsresult rv = mAppInfo->GetVersion(cversion); |
michael@0 | 238 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 239 | |
michael@0 | 240 | AppendUTF8toUTF16(cversion, aVersion); |
michael@0 | 241 | return NS_OK; |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | NS_IMETHODIMP |
michael@0 | 245 | ApplicationAccessible::GetPlatformName(nsAString& aName) |
michael@0 | 246 | { |
michael@0 | 247 | aName.AssignLiteral("Gecko"); |
michael@0 | 248 | return NS_OK; |
michael@0 | 249 | } |
michael@0 | 250 | |
michael@0 | 251 | NS_IMETHODIMP |
michael@0 | 252 | ApplicationAccessible::GetPlatformVersion(nsAString& aVersion) |
michael@0 | 253 | { |
michael@0 | 254 | aVersion.Truncate(); |
michael@0 | 255 | |
michael@0 | 256 | if (!mAppInfo) |
michael@0 | 257 | return NS_ERROR_FAILURE; |
michael@0 | 258 | |
michael@0 | 259 | nsAutoCString cversion; |
michael@0 | 260 | nsresult rv = mAppInfo->GetPlatformVersion(cversion); |
michael@0 | 261 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 262 | |
michael@0 | 263 | AppendUTF8toUTF16(cversion, aVersion); |
michael@0 | 264 | return NS_OK; |
michael@0 | 265 | } |
michael@0 | 266 | |
michael@0 | 267 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 268 | // Accessible public methods |
michael@0 | 269 | |
michael@0 | 270 | void |
michael@0 | 271 | ApplicationAccessible::Shutdown() |
michael@0 | 272 | { |
michael@0 | 273 | mAppInfo = nullptr; |
michael@0 | 274 | } |
michael@0 | 275 | |
michael@0 | 276 | void |
michael@0 | 277 | ApplicationAccessible::ApplyARIAState(uint64_t* aState) const |
michael@0 | 278 | { |
michael@0 | 279 | } |
michael@0 | 280 | |
michael@0 | 281 | role |
michael@0 | 282 | ApplicationAccessible::NativeRole() |
michael@0 | 283 | { |
michael@0 | 284 | return roles::APP_ROOT; |
michael@0 | 285 | } |
michael@0 | 286 | |
michael@0 | 287 | uint64_t |
michael@0 | 288 | ApplicationAccessible::NativeState() |
michael@0 | 289 | { |
michael@0 | 290 | return 0; |
michael@0 | 291 | } |
michael@0 | 292 | |
michael@0 | 293 | void |
michael@0 | 294 | ApplicationAccessible::InvalidateChildren() |
michael@0 | 295 | { |
michael@0 | 296 | // Do nothing because application children are kept updated by AppendChild() |
michael@0 | 297 | // and RemoveChild() method calls. |
michael@0 | 298 | } |
michael@0 | 299 | |
michael@0 | 300 | KeyBinding |
michael@0 | 301 | ApplicationAccessible::AccessKey() const |
michael@0 | 302 | { |
michael@0 | 303 | return KeyBinding(); |
michael@0 | 304 | } |
michael@0 | 305 | |
michael@0 | 306 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 307 | // Accessible protected methods |
michael@0 | 308 | |
michael@0 | 309 | void |
michael@0 | 310 | ApplicationAccessible::CacheChildren() |
michael@0 | 311 | { |
michael@0 | 312 | // CacheChildren is called only once for application accessible when its |
michael@0 | 313 | // children are requested because empty InvalidateChldren() prevents its |
michael@0 | 314 | // repeated calls. |
michael@0 | 315 | |
michael@0 | 316 | // Basically children are kept updated by Append/RemoveChild method calls. |
michael@0 | 317 | // However if there are open windows before accessibility was started |
michael@0 | 318 | // then we need to make sure root accessibles for open windows are created so |
michael@0 | 319 | // that all root accessibles are stored in application accessible children |
michael@0 | 320 | // array. |
michael@0 | 321 | |
michael@0 | 322 | nsCOMPtr<nsIWindowMediator> windowMediator = |
michael@0 | 323 | do_GetService(NS_WINDOWMEDIATOR_CONTRACTID); |
michael@0 | 324 | |
michael@0 | 325 | nsCOMPtr<nsISimpleEnumerator> windowEnumerator; |
michael@0 | 326 | nsresult rv = windowMediator->GetEnumerator(nullptr, |
michael@0 | 327 | getter_AddRefs(windowEnumerator)); |
michael@0 | 328 | if (NS_FAILED(rv)) |
michael@0 | 329 | return; |
michael@0 | 330 | |
michael@0 | 331 | bool hasMore = false; |
michael@0 | 332 | windowEnumerator->HasMoreElements(&hasMore); |
michael@0 | 333 | while (hasMore) { |
michael@0 | 334 | nsCOMPtr<nsISupports> window; |
michael@0 | 335 | windowEnumerator->GetNext(getter_AddRefs(window)); |
michael@0 | 336 | nsCOMPtr<nsIDOMWindow> DOMWindow = do_QueryInterface(window); |
michael@0 | 337 | if (DOMWindow) { |
michael@0 | 338 | nsCOMPtr<nsIDOMDocument> DOMDocument; |
michael@0 | 339 | DOMWindow->GetDocument(getter_AddRefs(DOMDocument)); |
michael@0 | 340 | if (DOMDocument) { |
michael@0 | 341 | nsCOMPtr<nsIDocument> docNode(do_QueryInterface(DOMDocument)); |
michael@0 | 342 | GetAccService()->GetDocAccessible(docNode); // ensure creation |
michael@0 | 343 | } |
michael@0 | 344 | } |
michael@0 | 345 | windowEnumerator->HasMoreElements(&hasMore); |
michael@0 | 346 | } |
michael@0 | 347 | } |
michael@0 | 348 | |
michael@0 | 349 | Accessible* |
michael@0 | 350 | ApplicationAccessible::GetSiblingAtOffset(int32_t aOffset, |
michael@0 | 351 | nsresult* aError) const |
michael@0 | 352 | { |
michael@0 | 353 | if (aError) |
michael@0 | 354 | *aError = NS_OK; // fail peacefully |
michael@0 | 355 | |
michael@0 | 356 | return nullptr; |
michael@0 | 357 | } |
michael@0 | 358 | |
michael@0 | 359 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 360 | // nsIAccessible |
michael@0 | 361 | |
michael@0 | 362 | NS_IMETHODIMP |
michael@0 | 363 | ApplicationAccessible::GetRootDocument(nsIAccessibleDocument** aRootDocument) |
michael@0 | 364 | { |
michael@0 | 365 | NS_ENSURE_ARG_POINTER(aRootDocument); |
michael@0 | 366 | *aRootDocument = nullptr; |
michael@0 | 367 | return NS_OK; |
michael@0 | 368 | } |
michael@0 | 369 | |
michael@0 | 370 | NS_IMETHODIMP |
michael@0 | 371 | ApplicationAccessible::ScrollTo(uint32_t aScrollType) |
michael@0 | 372 | { |
michael@0 | 373 | return NS_OK; |
michael@0 | 374 | } |
michael@0 | 375 | |
michael@0 | 376 | NS_IMETHODIMP |
michael@0 | 377 | ApplicationAccessible::ScrollToPoint(uint32_t aCoordinateType, |
michael@0 | 378 | int32_t aX, int32_t aY) |
michael@0 | 379 | { |
michael@0 | 380 | return NS_OK; |
michael@0 | 381 | } |
michael@0 | 382 | |
michael@0 | 383 | NS_IMETHODIMP |
michael@0 | 384 | ApplicationAccessible::GetLanguage(nsAString& aLanguage) |
michael@0 | 385 | { |
michael@0 | 386 | aLanguage.Truncate(); |
michael@0 | 387 | return NS_OK; |
michael@0 | 388 | } |
michael@0 | 389 |