1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/generic/ApplicationAccessible.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,389 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim:expandtab:shiftwidth=4:tabstop=4: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "ApplicationAccessible.h" 1.12 + 1.13 +#include "nsAccessibilityService.h" 1.14 +#include "nsAccUtils.h" 1.15 +#include "Relation.h" 1.16 +#include "Role.h" 1.17 +#include "States.h" 1.18 + 1.19 +#include "nsIComponentManager.h" 1.20 +#include "nsIDOMDocument.h" 1.21 +#include "nsIDOMWindow.h" 1.22 +#include "nsIWindowMediator.h" 1.23 +#include "nsServiceManagerUtils.h" 1.24 +#include "mozilla/Services.h" 1.25 +#include "nsIStringBundle.h" 1.26 + 1.27 +using namespace mozilla::a11y; 1.28 + 1.29 +ApplicationAccessible::ApplicationAccessible() : 1.30 + AccessibleWrap(nullptr, nullptr) 1.31 +{ 1.32 + mType = eApplicationType; 1.33 + mAppInfo = do_GetService("@mozilla.org/xre/app-info;1"); 1.34 +} 1.35 + 1.36 +//////////////////////////////////////////////////////////////////////////////// 1.37 +// nsISupports 1.38 + 1.39 +NS_IMPL_ISUPPORTS_INHERITED(ApplicationAccessible, Accessible, 1.40 + nsIAccessibleApplication) 1.41 + 1.42 +//////////////////////////////////////////////////////////////////////////////// 1.43 +// nsIAccessible 1.44 + 1.45 +NS_IMETHODIMP 1.46 +ApplicationAccessible::GetParent(nsIAccessible** aAccessible) 1.47 +{ 1.48 + NS_ENSURE_ARG_POINTER(aAccessible); 1.49 + *aAccessible = nullptr; 1.50 + return NS_OK; 1.51 +} 1.52 + 1.53 +NS_IMETHODIMP 1.54 +ApplicationAccessible::GetNextSibling(nsIAccessible** aNextSibling) 1.55 +{ 1.56 + NS_ENSURE_ARG_POINTER(aNextSibling); 1.57 + *aNextSibling = nullptr; 1.58 + return NS_OK; 1.59 +} 1.60 + 1.61 +NS_IMETHODIMP 1.62 +ApplicationAccessible::GetPreviousSibling(nsIAccessible** aPreviousSibling) 1.63 +{ 1.64 + NS_ENSURE_ARG_POINTER(aPreviousSibling); 1.65 + *aPreviousSibling = nullptr; 1.66 + return NS_OK; 1.67 +} 1.68 + 1.69 +ENameValueFlag 1.70 +ApplicationAccessible::Name(nsString& aName) 1.71 +{ 1.72 + aName.Truncate(); 1.73 + 1.74 + nsCOMPtr<nsIStringBundleService> bundleService = 1.75 + mozilla::services::GetStringBundleService(); 1.76 + 1.77 + NS_ASSERTION(bundleService, "String bundle service must be present!"); 1.78 + if (!bundleService) 1.79 + return eNameOK; 1.80 + 1.81 + nsCOMPtr<nsIStringBundle> bundle; 1.82 + nsresult rv = bundleService->CreateBundle("chrome://branding/locale/brand.properties", 1.83 + getter_AddRefs(bundle)); 1.84 + if (NS_FAILED(rv)) 1.85 + return eNameOK; 1.86 + 1.87 + nsXPIDLString appName; 1.88 + rv = bundle->GetStringFromName(MOZ_UTF16("brandShortName"), 1.89 + getter_Copies(appName)); 1.90 + if (NS_FAILED(rv) || appName.IsEmpty()) { 1.91 + NS_WARNING("brandShortName not found, using default app name"); 1.92 + appName.AssignLiteral("Gecko based application"); 1.93 + } 1.94 + 1.95 + aName.Assign(appName); 1.96 + return eNameOK; 1.97 +} 1.98 + 1.99 +void 1.100 +ApplicationAccessible::Description(nsString& aDescription) 1.101 +{ 1.102 + aDescription.Truncate(); 1.103 +} 1.104 + 1.105 +void 1.106 +ApplicationAccessible::Value(nsString& aValue) 1.107 +{ 1.108 + aValue.Truncate(); 1.109 +} 1.110 + 1.111 +uint64_t 1.112 +ApplicationAccessible::State() 1.113 +{ 1.114 + return IsDefunct() ? states::DEFUNCT : 0; 1.115 +} 1.116 + 1.117 +already_AddRefed<nsIPersistentProperties> 1.118 +ApplicationAccessible::NativeAttributes() 1.119 +{ 1.120 + return nullptr; 1.121 +} 1.122 + 1.123 +GroupPos 1.124 +ApplicationAccessible::GroupPosition() 1.125 +{ 1.126 + return GroupPos(); 1.127 +} 1.128 + 1.129 +Accessible* 1.130 +ApplicationAccessible::ChildAtPoint(int32_t aX, int32_t aY, 1.131 + EWhichChildAtPoint aWhichChild) 1.132 +{ 1.133 + return nullptr; 1.134 +} 1.135 + 1.136 +Accessible* 1.137 +ApplicationAccessible::FocusedChild() 1.138 +{ 1.139 + Accessible* focus = FocusMgr()->FocusedAccessible(); 1.140 + if (focus && focus->Parent() == this) 1.141 + return focus; 1.142 + 1.143 + return nullptr; 1.144 +} 1.145 + 1.146 +Relation 1.147 +ApplicationAccessible::RelationByType(RelationType aRelationType) 1.148 +{ 1.149 + return Relation(); 1.150 +} 1.151 + 1.152 +NS_IMETHODIMP 1.153 +ApplicationAccessible::GetBounds(int32_t* aX, int32_t* aY, 1.154 + int32_t* aWidth, int32_t* aHeight) 1.155 +{ 1.156 + NS_ENSURE_ARG_POINTER(aX); 1.157 + *aX = 0; 1.158 + NS_ENSURE_ARG_POINTER(aY); 1.159 + *aY = 0; 1.160 + NS_ENSURE_ARG_POINTER(aWidth); 1.161 + *aWidth = 0; 1.162 + NS_ENSURE_ARG_POINTER(aHeight); 1.163 + *aHeight = 0; 1.164 + return NS_OK; 1.165 +} 1.166 + 1.167 +NS_IMETHODIMP 1.168 +ApplicationAccessible::SetSelected(bool aIsSelected) 1.169 +{ 1.170 + return NS_OK; 1.171 +} 1.172 + 1.173 +NS_IMETHODIMP 1.174 +ApplicationAccessible::TakeSelection() 1.175 +{ 1.176 + return NS_OK; 1.177 +} 1.178 + 1.179 +NS_IMETHODIMP 1.180 +ApplicationAccessible::TakeFocus() 1.181 +{ 1.182 + return NS_OK; 1.183 +} 1.184 + 1.185 +uint8_t 1.186 +ApplicationAccessible::ActionCount() 1.187 +{ 1.188 + return 0; 1.189 +} 1.190 + 1.191 +NS_IMETHODIMP 1.192 +ApplicationAccessible::GetActionName(uint8_t aIndex, nsAString& aName) 1.193 +{ 1.194 + aName.Truncate(); 1.195 + return NS_ERROR_INVALID_ARG; 1.196 +} 1.197 + 1.198 +NS_IMETHODIMP 1.199 +ApplicationAccessible::GetActionDescription(uint8_t aIndex, 1.200 + nsAString& aDescription) 1.201 +{ 1.202 + aDescription.Truncate(); 1.203 + return NS_ERROR_INVALID_ARG; 1.204 +} 1.205 + 1.206 +NS_IMETHODIMP 1.207 +ApplicationAccessible::DoAction(uint8_t aIndex) 1.208 +{ 1.209 + return NS_OK; 1.210 +} 1.211 + 1.212 +//////////////////////////////////////////////////////////////////////////////// 1.213 +// nsIAccessibleApplication 1.214 + 1.215 +NS_IMETHODIMP 1.216 +ApplicationAccessible::GetAppName(nsAString& aName) 1.217 +{ 1.218 + aName.Truncate(); 1.219 + 1.220 + if (!mAppInfo) 1.221 + return NS_ERROR_FAILURE; 1.222 + 1.223 + nsAutoCString cname; 1.224 + nsresult rv = mAppInfo->GetName(cname); 1.225 + NS_ENSURE_SUCCESS(rv, rv); 1.226 + 1.227 + AppendUTF8toUTF16(cname, aName); 1.228 + return NS_OK; 1.229 +} 1.230 + 1.231 +NS_IMETHODIMP 1.232 +ApplicationAccessible::GetAppVersion(nsAString& aVersion) 1.233 +{ 1.234 + aVersion.Truncate(); 1.235 + 1.236 + if (!mAppInfo) 1.237 + return NS_ERROR_FAILURE; 1.238 + 1.239 + nsAutoCString cversion; 1.240 + nsresult rv = mAppInfo->GetVersion(cversion); 1.241 + NS_ENSURE_SUCCESS(rv, rv); 1.242 + 1.243 + AppendUTF8toUTF16(cversion, aVersion); 1.244 + return NS_OK; 1.245 +} 1.246 + 1.247 +NS_IMETHODIMP 1.248 +ApplicationAccessible::GetPlatformName(nsAString& aName) 1.249 +{ 1.250 + aName.AssignLiteral("Gecko"); 1.251 + return NS_OK; 1.252 +} 1.253 + 1.254 +NS_IMETHODIMP 1.255 +ApplicationAccessible::GetPlatformVersion(nsAString& aVersion) 1.256 +{ 1.257 + aVersion.Truncate(); 1.258 + 1.259 + if (!mAppInfo) 1.260 + return NS_ERROR_FAILURE; 1.261 + 1.262 + nsAutoCString cversion; 1.263 + nsresult rv = mAppInfo->GetPlatformVersion(cversion); 1.264 + NS_ENSURE_SUCCESS(rv, rv); 1.265 + 1.266 + AppendUTF8toUTF16(cversion, aVersion); 1.267 + return NS_OK; 1.268 +} 1.269 + 1.270 +//////////////////////////////////////////////////////////////////////////////// 1.271 +// Accessible public methods 1.272 + 1.273 +void 1.274 +ApplicationAccessible::Shutdown() 1.275 +{ 1.276 + mAppInfo = nullptr; 1.277 +} 1.278 + 1.279 +void 1.280 +ApplicationAccessible::ApplyARIAState(uint64_t* aState) const 1.281 +{ 1.282 +} 1.283 + 1.284 +role 1.285 +ApplicationAccessible::NativeRole() 1.286 +{ 1.287 + return roles::APP_ROOT; 1.288 +} 1.289 + 1.290 +uint64_t 1.291 +ApplicationAccessible::NativeState() 1.292 +{ 1.293 + return 0; 1.294 +} 1.295 + 1.296 +void 1.297 +ApplicationAccessible::InvalidateChildren() 1.298 +{ 1.299 + // Do nothing because application children are kept updated by AppendChild() 1.300 + // and RemoveChild() method calls. 1.301 +} 1.302 + 1.303 +KeyBinding 1.304 +ApplicationAccessible::AccessKey() const 1.305 +{ 1.306 + return KeyBinding(); 1.307 +} 1.308 + 1.309 +//////////////////////////////////////////////////////////////////////////////// 1.310 +// Accessible protected methods 1.311 + 1.312 +void 1.313 +ApplicationAccessible::CacheChildren() 1.314 +{ 1.315 + // CacheChildren is called only once for application accessible when its 1.316 + // children are requested because empty InvalidateChldren() prevents its 1.317 + // repeated calls. 1.318 + 1.319 + // Basically children are kept updated by Append/RemoveChild method calls. 1.320 + // However if there are open windows before accessibility was started 1.321 + // then we need to make sure root accessibles for open windows are created so 1.322 + // that all root accessibles are stored in application accessible children 1.323 + // array. 1.324 + 1.325 + nsCOMPtr<nsIWindowMediator> windowMediator = 1.326 + do_GetService(NS_WINDOWMEDIATOR_CONTRACTID); 1.327 + 1.328 + nsCOMPtr<nsISimpleEnumerator> windowEnumerator; 1.329 + nsresult rv = windowMediator->GetEnumerator(nullptr, 1.330 + getter_AddRefs(windowEnumerator)); 1.331 + if (NS_FAILED(rv)) 1.332 + return; 1.333 + 1.334 + bool hasMore = false; 1.335 + windowEnumerator->HasMoreElements(&hasMore); 1.336 + while (hasMore) { 1.337 + nsCOMPtr<nsISupports> window; 1.338 + windowEnumerator->GetNext(getter_AddRefs(window)); 1.339 + nsCOMPtr<nsIDOMWindow> DOMWindow = do_QueryInterface(window); 1.340 + if (DOMWindow) { 1.341 + nsCOMPtr<nsIDOMDocument> DOMDocument; 1.342 + DOMWindow->GetDocument(getter_AddRefs(DOMDocument)); 1.343 + if (DOMDocument) { 1.344 + nsCOMPtr<nsIDocument> docNode(do_QueryInterface(DOMDocument)); 1.345 + GetAccService()->GetDocAccessible(docNode); // ensure creation 1.346 + } 1.347 + } 1.348 + windowEnumerator->HasMoreElements(&hasMore); 1.349 + } 1.350 +} 1.351 + 1.352 +Accessible* 1.353 +ApplicationAccessible::GetSiblingAtOffset(int32_t aOffset, 1.354 + nsresult* aError) const 1.355 +{ 1.356 + if (aError) 1.357 + *aError = NS_OK; // fail peacefully 1.358 + 1.359 + return nullptr; 1.360 +} 1.361 + 1.362 +//////////////////////////////////////////////////////////////////////////////// 1.363 +// nsIAccessible 1.364 + 1.365 +NS_IMETHODIMP 1.366 +ApplicationAccessible::GetRootDocument(nsIAccessibleDocument** aRootDocument) 1.367 +{ 1.368 + NS_ENSURE_ARG_POINTER(aRootDocument); 1.369 + *aRootDocument = nullptr; 1.370 + return NS_OK; 1.371 +} 1.372 + 1.373 +NS_IMETHODIMP 1.374 +ApplicationAccessible::ScrollTo(uint32_t aScrollType) 1.375 +{ 1.376 + return NS_OK; 1.377 +} 1.378 + 1.379 +NS_IMETHODIMP 1.380 +ApplicationAccessible::ScrollToPoint(uint32_t aCoordinateType, 1.381 + int32_t aX, int32_t aY) 1.382 +{ 1.383 + return NS_OK; 1.384 +} 1.385 + 1.386 +NS_IMETHODIMP 1.387 +ApplicationAccessible::GetLanguage(nsAString& aLanguage) 1.388 +{ 1.389 + aLanguage.Truncate(); 1.390 + return NS_OK; 1.391 +} 1.392 +