michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim:expandtab:shiftwidth=4:tabstop=4: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "ApplicationAccessible.h" michael@0: michael@0: #include "nsAccessibilityService.h" michael@0: #include "nsAccUtils.h" michael@0: #include "Relation.h" michael@0: #include "Role.h" michael@0: #include "States.h" michael@0: michael@0: #include "nsIComponentManager.h" michael@0: #include "nsIDOMDocument.h" michael@0: #include "nsIDOMWindow.h" michael@0: #include "nsIWindowMediator.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "mozilla/Services.h" michael@0: #include "nsIStringBundle.h" michael@0: michael@0: using namespace mozilla::a11y; michael@0: michael@0: ApplicationAccessible::ApplicationAccessible() : michael@0: AccessibleWrap(nullptr, nullptr) michael@0: { michael@0: mType = eApplicationType; michael@0: mAppInfo = do_GetService("@mozilla.org/xre/app-info;1"); michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // nsISupports michael@0: michael@0: NS_IMPL_ISUPPORTS_INHERITED(ApplicationAccessible, Accessible, michael@0: nsIAccessibleApplication) michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // nsIAccessible michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetParent(nsIAccessible** aAccessible) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aAccessible); michael@0: *aAccessible = nullptr; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetNextSibling(nsIAccessible** aNextSibling) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aNextSibling); michael@0: *aNextSibling = nullptr; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetPreviousSibling(nsIAccessible** aPreviousSibling) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aPreviousSibling); michael@0: *aPreviousSibling = nullptr; michael@0: return NS_OK; michael@0: } michael@0: michael@0: ENameValueFlag michael@0: ApplicationAccessible::Name(nsString& aName) michael@0: { michael@0: aName.Truncate(); michael@0: michael@0: nsCOMPtr bundleService = michael@0: mozilla::services::GetStringBundleService(); michael@0: michael@0: NS_ASSERTION(bundleService, "String bundle service must be present!"); michael@0: if (!bundleService) michael@0: return eNameOK; michael@0: michael@0: nsCOMPtr bundle; michael@0: nsresult rv = bundleService->CreateBundle("chrome://branding/locale/brand.properties", michael@0: getter_AddRefs(bundle)); michael@0: if (NS_FAILED(rv)) michael@0: return eNameOK; michael@0: michael@0: nsXPIDLString appName; michael@0: rv = bundle->GetStringFromName(MOZ_UTF16("brandShortName"), michael@0: getter_Copies(appName)); michael@0: if (NS_FAILED(rv) || appName.IsEmpty()) { michael@0: NS_WARNING("brandShortName not found, using default app name"); michael@0: appName.AssignLiteral("Gecko based application"); michael@0: } michael@0: michael@0: aName.Assign(appName); michael@0: return eNameOK; michael@0: } michael@0: michael@0: void michael@0: ApplicationAccessible::Description(nsString& aDescription) michael@0: { michael@0: aDescription.Truncate(); michael@0: } michael@0: michael@0: void michael@0: ApplicationAccessible::Value(nsString& aValue) michael@0: { michael@0: aValue.Truncate(); michael@0: } michael@0: michael@0: uint64_t michael@0: ApplicationAccessible::State() michael@0: { michael@0: return IsDefunct() ? states::DEFUNCT : 0; michael@0: } michael@0: michael@0: already_AddRefed michael@0: ApplicationAccessible::NativeAttributes() michael@0: { michael@0: return nullptr; michael@0: } michael@0: michael@0: GroupPos michael@0: ApplicationAccessible::GroupPosition() michael@0: { michael@0: return GroupPos(); michael@0: } michael@0: michael@0: Accessible* michael@0: ApplicationAccessible::ChildAtPoint(int32_t aX, int32_t aY, michael@0: EWhichChildAtPoint aWhichChild) michael@0: { michael@0: return nullptr; michael@0: } michael@0: michael@0: Accessible* michael@0: ApplicationAccessible::FocusedChild() michael@0: { michael@0: Accessible* focus = FocusMgr()->FocusedAccessible(); michael@0: if (focus && focus->Parent() == this) michael@0: return focus; michael@0: michael@0: return nullptr; michael@0: } michael@0: michael@0: Relation michael@0: ApplicationAccessible::RelationByType(RelationType aRelationType) michael@0: { michael@0: return Relation(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetBounds(int32_t* aX, int32_t* aY, michael@0: int32_t* aWidth, int32_t* aHeight) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aX); michael@0: *aX = 0; michael@0: NS_ENSURE_ARG_POINTER(aY); michael@0: *aY = 0; michael@0: NS_ENSURE_ARG_POINTER(aWidth); michael@0: *aWidth = 0; michael@0: NS_ENSURE_ARG_POINTER(aHeight); michael@0: *aHeight = 0; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::SetSelected(bool aIsSelected) michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::TakeSelection() michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::TakeFocus() michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: uint8_t michael@0: ApplicationAccessible::ActionCount() michael@0: { michael@0: return 0; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetActionName(uint8_t aIndex, nsAString& aName) michael@0: { michael@0: aName.Truncate(); michael@0: return NS_ERROR_INVALID_ARG; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetActionDescription(uint8_t aIndex, michael@0: nsAString& aDescription) michael@0: { michael@0: aDescription.Truncate(); michael@0: return NS_ERROR_INVALID_ARG; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::DoAction(uint8_t aIndex) michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // nsIAccessibleApplication michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetAppName(nsAString& aName) michael@0: { michael@0: aName.Truncate(); michael@0: michael@0: if (!mAppInfo) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: nsAutoCString cname; michael@0: nsresult rv = mAppInfo->GetName(cname); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: AppendUTF8toUTF16(cname, aName); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetAppVersion(nsAString& aVersion) michael@0: { michael@0: aVersion.Truncate(); michael@0: michael@0: if (!mAppInfo) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: nsAutoCString cversion; michael@0: nsresult rv = mAppInfo->GetVersion(cversion); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: AppendUTF8toUTF16(cversion, aVersion); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetPlatformName(nsAString& aName) michael@0: { michael@0: aName.AssignLiteral("Gecko"); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetPlatformVersion(nsAString& aVersion) michael@0: { michael@0: aVersion.Truncate(); michael@0: michael@0: if (!mAppInfo) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: nsAutoCString cversion; michael@0: nsresult rv = mAppInfo->GetPlatformVersion(cversion); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: AppendUTF8toUTF16(cversion, aVersion); michael@0: return NS_OK; michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Accessible public methods michael@0: michael@0: void michael@0: ApplicationAccessible::Shutdown() michael@0: { michael@0: mAppInfo = nullptr; michael@0: } michael@0: michael@0: void michael@0: ApplicationAccessible::ApplyARIAState(uint64_t* aState) const michael@0: { michael@0: } michael@0: michael@0: role michael@0: ApplicationAccessible::NativeRole() michael@0: { michael@0: return roles::APP_ROOT; michael@0: } michael@0: michael@0: uint64_t michael@0: ApplicationAccessible::NativeState() michael@0: { michael@0: return 0; michael@0: } michael@0: michael@0: void michael@0: ApplicationAccessible::InvalidateChildren() michael@0: { michael@0: // Do nothing because application children are kept updated by AppendChild() michael@0: // and RemoveChild() method calls. michael@0: } michael@0: michael@0: KeyBinding michael@0: ApplicationAccessible::AccessKey() const michael@0: { michael@0: return KeyBinding(); michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Accessible protected methods michael@0: michael@0: void michael@0: ApplicationAccessible::CacheChildren() michael@0: { michael@0: // CacheChildren is called only once for application accessible when its michael@0: // children are requested because empty InvalidateChldren() prevents its michael@0: // repeated calls. michael@0: michael@0: // Basically children are kept updated by Append/RemoveChild method calls. michael@0: // However if there are open windows before accessibility was started michael@0: // then we need to make sure root accessibles for open windows are created so michael@0: // that all root accessibles are stored in application accessible children michael@0: // array. michael@0: michael@0: nsCOMPtr windowMediator = michael@0: do_GetService(NS_WINDOWMEDIATOR_CONTRACTID); michael@0: michael@0: nsCOMPtr windowEnumerator; michael@0: nsresult rv = windowMediator->GetEnumerator(nullptr, michael@0: getter_AddRefs(windowEnumerator)); michael@0: if (NS_FAILED(rv)) michael@0: return; michael@0: michael@0: bool hasMore = false; michael@0: windowEnumerator->HasMoreElements(&hasMore); michael@0: while (hasMore) { michael@0: nsCOMPtr window; michael@0: windowEnumerator->GetNext(getter_AddRefs(window)); michael@0: nsCOMPtr DOMWindow = do_QueryInterface(window); michael@0: if (DOMWindow) { michael@0: nsCOMPtr DOMDocument; michael@0: DOMWindow->GetDocument(getter_AddRefs(DOMDocument)); michael@0: if (DOMDocument) { michael@0: nsCOMPtr docNode(do_QueryInterface(DOMDocument)); michael@0: GetAccService()->GetDocAccessible(docNode); // ensure creation michael@0: } michael@0: } michael@0: windowEnumerator->HasMoreElements(&hasMore); michael@0: } michael@0: } michael@0: michael@0: Accessible* michael@0: ApplicationAccessible::GetSiblingAtOffset(int32_t aOffset, michael@0: nsresult* aError) const michael@0: { michael@0: if (aError) michael@0: *aError = NS_OK; // fail peacefully michael@0: michael@0: return nullptr; michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // nsIAccessible michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetRootDocument(nsIAccessibleDocument** aRootDocument) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aRootDocument); michael@0: *aRootDocument = nullptr; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::ScrollTo(uint32_t aScrollType) michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::ScrollToPoint(uint32_t aCoordinateType, michael@0: int32_t aX, int32_t aY) michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ApplicationAccessible::GetLanguage(nsAString& aLanguage) michael@0: { michael@0: aLanguage.Truncate(); michael@0: return NS_OK; michael@0: } michael@0: