accessible/src/windows/msaa/ApplicationAccessibleWrap.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/windows/msaa/ApplicationAccessibleWrap.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,173 @@
     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 "ApplicationAccessibleWrap.h"
    1.12 +
    1.13 +#include "AccessibleApplication_i.c"
    1.14 +#include "IUnknownImpl.h"
    1.15 +
    1.16 +#include "nsIGfxInfo.h"
    1.17 +#include "nsIPersistentProperties2.h"
    1.18 +#include "nsServiceManagerUtils.h"
    1.19 +
    1.20 +using namespace mozilla;
    1.21 +using namespace mozilla::a11y;
    1.22 +
    1.23 +////////////////////////////////////////////////////////////////////////////////
    1.24 +// nsISupports
    1.25 +NS_IMPL_ISUPPORTS_INHERITED0(ApplicationAccessibleWrap,
    1.26 +                             ApplicationAccessible)
    1.27 +
    1.28 +already_AddRefed<nsIPersistentProperties>
    1.29 +ApplicationAccessibleWrap::NativeAttributes()
    1.30 +{
    1.31 +  nsCOMPtr<nsIPersistentProperties> attributes =
    1.32 +    do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
    1.33 +
    1.34 +  nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
    1.35 +  if (gfxInfo) {
    1.36 +    bool isD2DEnabled = false;
    1.37 +    gfxInfo->GetD2DEnabled(&isD2DEnabled);
    1.38 +    nsAutoString unused;
    1.39 +    attributes->SetStringProperty(
    1.40 +      NS_LITERAL_CSTRING("D2D"),
    1.41 +      isD2DEnabled ? NS_LITERAL_STRING("true") : NS_LITERAL_STRING("false"),
    1.42 +        unused);
    1.43 +  }
    1.44 +
    1.45 +  return attributes.forget();
    1.46 +}
    1.47 +
    1.48 +////////////////////////////////////////////////////////////////////////////////
    1.49 +// IUnknown
    1.50 +
    1.51 +STDMETHODIMP
    1.52 +ApplicationAccessibleWrap::QueryInterface(REFIID iid, void** ppv)
    1.53 +{
    1.54 +  if (!ppv)
    1.55 +    return E_INVALIDARG;
    1.56 +
    1.57 +  *ppv = nullptr;
    1.58 +
    1.59 +  if (IID_IAccessibleApplication == iid) {
    1.60 +    *ppv = static_cast<IAccessibleApplication*>(this);
    1.61 +    (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
    1.62 +    return S_OK;
    1.63 +  }
    1.64 +
    1.65 +  return AccessibleWrap::QueryInterface(iid, ppv);
    1.66 +}
    1.67 +
    1.68 +////////////////////////////////////////////////////////////////////////////////
    1.69 +// IAccessibleApplication
    1.70 +
    1.71 +STDMETHODIMP
    1.72 +ApplicationAccessibleWrap::get_appName(BSTR* aName)
    1.73 +{
    1.74 +  A11Y_TRYBLOCK_BEGIN
    1.75 +
    1.76 +  if (!aName)
    1.77 +    return E_INVALIDARG;
    1.78 +
    1.79 +  *aName = nullptr;
    1.80 +
    1.81 +  if (IsDefunct())
    1.82 +    return CO_E_OBJNOTCONNECTED;
    1.83 +
    1.84 +  nsAutoString name;
    1.85 +  nsresult rv = GetAppName(name);
    1.86 +  if (NS_FAILED(rv))
    1.87 +    return GetHRESULT(rv);
    1.88 +
    1.89 +  if (name.IsEmpty())
    1.90 +    return S_FALSE;
    1.91 +
    1.92 +  *aName = ::SysAllocStringLen(name.get(), name.Length());
    1.93 +  return *aName ? S_OK : E_OUTOFMEMORY;
    1.94 +
    1.95 +  A11Y_TRYBLOCK_END
    1.96 +}
    1.97 +
    1.98 +STDMETHODIMP
    1.99 +ApplicationAccessibleWrap::get_appVersion(BSTR* aVersion)
   1.100 +{
   1.101 +  A11Y_TRYBLOCK_BEGIN
   1.102 +
   1.103 +  if (!aVersion)
   1.104 +    return E_INVALIDARG;
   1.105 +
   1.106 +  *aVersion = nullptr;
   1.107 +
   1.108 +  if (IsDefunct())
   1.109 +    return CO_E_OBJNOTCONNECTED;
   1.110 +
   1.111 +  nsAutoString version;
   1.112 +  nsresult rv = GetAppVersion(version);
   1.113 +  if (NS_FAILED(rv))
   1.114 +    return GetHRESULT(rv);
   1.115 +
   1.116 +  if (version.IsEmpty())
   1.117 +    return S_FALSE;
   1.118 +
   1.119 +  *aVersion = ::SysAllocStringLen(version.get(), version.Length());
   1.120 +  return *aVersion ? S_OK : E_OUTOFMEMORY;
   1.121 +
   1.122 +  A11Y_TRYBLOCK_END
   1.123 +}
   1.124 +
   1.125 +STDMETHODIMP
   1.126 +ApplicationAccessibleWrap::get_toolkitName(BSTR* aName)
   1.127 +{
   1.128 +  A11Y_TRYBLOCK_BEGIN
   1.129 +
   1.130 +  if (!aName)
   1.131 +    return E_INVALIDARG;
   1.132 +
   1.133 +  if (IsDefunct())
   1.134 +    return CO_E_OBJNOTCONNECTED;
   1.135 +
   1.136 +  nsAutoString name;
   1.137 +  nsresult rv = GetPlatformName(name);
   1.138 +  if (NS_FAILED(rv))
   1.139 +    return GetHRESULT(rv);
   1.140 +
   1.141 +  if (name.IsEmpty())
   1.142 +    return S_FALSE;
   1.143 +
   1.144 +  *aName = ::SysAllocStringLen(name.get(), name.Length());
   1.145 +  return *aName ? S_OK : E_OUTOFMEMORY;
   1.146 +
   1.147 +  A11Y_TRYBLOCK_END
   1.148 +}
   1.149 +
   1.150 +STDMETHODIMP
   1.151 +ApplicationAccessibleWrap::get_toolkitVersion(BSTR* aVersion)
   1.152 +{
   1.153 +  A11Y_TRYBLOCK_BEGIN
   1.154 +
   1.155 +  if (!aVersion)
   1.156 +    return E_INVALIDARG;
   1.157 +
   1.158 +  *aVersion = nullptr;
   1.159 +
   1.160 +  if (IsDefunct())
   1.161 +    return CO_E_OBJNOTCONNECTED;
   1.162 +
   1.163 +  nsAutoString version;
   1.164 +  nsresult rv = GetPlatformVersion(version);
   1.165 +  if (NS_FAILED(rv))
   1.166 +    return GetHRESULT(rv);
   1.167 +
   1.168 +  if (version.IsEmpty())
   1.169 +    return S_FALSE;
   1.170 +
   1.171 +  *aVersion = ::SysAllocStringLen(version.get(), version.Length());
   1.172 +  return *aVersion ? S_OK : E_OUTOFMEMORY;
   1.173 +
   1.174 +  A11Y_TRYBLOCK_END
   1.175 +}
   1.176 +

mercurial