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 "ApplicationAccessibleWrap.h" michael@0: michael@0: #include "AccessibleApplication_i.c" michael@0: #include "IUnknownImpl.h" michael@0: michael@0: #include "nsIGfxInfo.h" michael@0: #include "nsIPersistentProperties2.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::a11y; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // nsISupports michael@0: NS_IMPL_ISUPPORTS_INHERITED0(ApplicationAccessibleWrap, michael@0: ApplicationAccessible) michael@0: michael@0: already_AddRefed michael@0: ApplicationAccessibleWrap::NativeAttributes() michael@0: { michael@0: nsCOMPtr attributes = michael@0: do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID); michael@0: michael@0: nsCOMPtr gfxInfo = do_GetService("@mozilla.org/gfx/info;1"); michael@0: if (gfxInfo) { michael@0: bool isD2DEnabled = false; michael@0: gfxInfo->GetD2DEnabled(&isD2DEnabled); michael@0: nsAutoString unused; michael@0: attributes->SetStringProperty( michael@0: NS_LITERAL_CSTRING("D2D"), michael@0: isD2DEnabled ? NS_LITERAL_STRING("true") : NS_LITERAL_STRING("false"), michael@0: unused); michael@0: } michael@0: michael@0: return attributes.forget(); michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // IUnknown michael@0: michael@0: STDMETHODIMP michael@0: ApplicationAccessibleWrap::QueryInterface(REFIID iid, void** ppv) michael@0: { michael@0: if (!ppv) michael@0: return E_INVALIDARG; michael@0: michael@0: *ppv = nullptr; michael@0: michael@0: if (IID_IAccessibleApplication == iid) { michael@0: *ppv = static_cast(this); michael@0: (reinterpret_cast(*ppv))->AddRef(); michael@0: return S_OK; michael@0: } michael@0: michael@0: return AccessibleWrap::QueryInterface(iid, ppv); michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // IAccessibleApplication michael@0: michael@0: STDMETHODIMP michael@0: ApplicationAccessibleWrap::get_appName(BSTR* aName) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aName) michael@0: return E_INVALIDARG; michael@0: michael@0: *aName = nullptr; michael@0: michael@0: if (IsDefunct()) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: nsAutoString name; michael@0: nsresult rv = GetAppName(name); michael@0: if (NS_FAILED(rv)) michael@0: return GetHRESULT(rv); michael@0: michael@0: if (name.IsEmpty()) michael@0: return S_FALSE; michael@0: michael@0: *aName = ::SysAllocStringLen(name.get(), name.Length()); michael@0: return *aName ? S_OK : E_OUTOFMEMORY; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ApplicationAccessibleWrap::get_appVersion(BSTR* aVersion) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aVersion) michael@0: return E_INVALIDARG; michael@0: michael@0: *aVersion = nullptr; michael@0: michael@0: if (IsDefunct()) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: nsAutoString version; michael@0: nsresult rv = GetAppVersion(version); michael@0: if (NS_FAILED(rv)) michael@0: return GetHRESULT(rv); michael@0: michael@0: if (version.IsEmpty()) michael@0: return S_FALSE; michael@0: michael@0: *aVersion = ::SysAllocStringLen(version.get(), version.Length()); michael@0: return *aVersion ? S_OK : E_OUTOFMEMORY; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ApplicationAccessibleWrap::get_toolkitName(BSTR* aName) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aName) michael@0: return E_INVALIDARG; michael@0: michael@0: if (IsDefunct()) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: nsAutoString name; michael@0: nsresult rv = GetPlatformName(name); michael@0: if (NS_FAILED(rv)) michael@0: return GetHRESULT(rv); michael@0: michael@0: if (name.IsEmpty()) michael@0: return S_FALSE; michael@0: michael@0: *aName = ::SysAllocStringLen(name.get(), name.Length()); michael@0: return *aName ? S_OK : E_OUTOFMEMORY; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ApplicationAccessibleWrap::get_toolkitVersion(BSTR* aVersion) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aVersion) michael@0: return E_INVALIDARG; michael@0: michael@0: *aVersion = nullptr; michael@0: michael@0: if (IsDefunct()) michael@0: return CO_E_OBJNOTCONNECTED; michael@0: michael@0: nsAutoString version; michael@0: nsresult rv = GetPlatformVersion(version); michael@0: if (NS_FAILED(rv)) michael@0: return GetHRESULT(rv); michael@0: michael@0: if (version.IsEmpty()) michael@0: return S_FALSE; michael@0: michael@0: *aVersion = ::SysAllocStringLen(version.get(), version.Length()); michael@0: return *aVersion ? S_OK : E_OUTOFMEMORY; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: