ApplicationAccessibleWrap.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* vim:expandtab:shiftwidth=4:tabstop=4:
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  7. #include "ApplicationAccessibleWrap.h"
  8. #include "AccessibleApplication_i.c"
  9. #include "IUnknownImpl.h"
  10. #include "nsIGfxInfo.h"
  11. #include "nsIPersistentProperties2.h"
  12. #include "nsServiceManagerUtils.h"
  13. #include "mozilla/Services.h"
  14. using namespace mozilla;
  15. using namespace mozilla::a11y;
  16. ////////////////////////////////////////////////////////////////////////////////
  17. // nsISupports
  18. NS_IMPL_ISUPPORTS_INHERITED0(ApplicationAccessibleWrap,
  19. ApplicationAccessible)
  20. already_AddRefed<nsIPersistentProperties>
  21. ApplicationAccessibleWrap::NativeAttributes()
  22. {
  23. nsCOMPtr<nsIPersistentProperties> attributes =
  24. do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
  25. nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
  26. if (gfxInfo) {
  27. bool isD2DEnabled = false;
  28. gfxInfo->GetD2DEnabled(&isD2DEnabled);
  29. nsAutoString unused;
  30. attributes->SetStringProperty(
  31. NS_LITERAL_CSTRING("D2D"),
  32. isD2DEnabled ? NS_LITERAL_STRING("true") : NS_LITERAL_STRING("false"),
  33. unused);
  34. }
  35. return attributes.forget();
  36. }
  37. ////////////////////////////////////////////////////////////////////////////////
  38. // IUnknown
  39. STDMETHODIMP
  40. ApplicationAccessibleWrap::QueryInterface(REFIID iid, void** ppv)
  41. {
  42. if (!ppv)
  43. return E_INVALIDARG;
  44. *ppv = nullptr;
  45. if (IID_IAccessibleApplication == iid) {
  46. *ppv = static_cast<IAccessibleApplication*>(this);
  47. (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
  48. return S_OK;
  49. }
  50. return AccessibleWrap::QueryInterface(iid, ppv);
  51. }
  52. ////////////////////////////////////////////////////////////////////////////////
  53. // IAccessibleApplication
  54. STDMETHODIMP
  55. ApplicationAccessibleWrap::get_appName(BSTR* aName)
  56. {
  57. if (!aName)
  58. return E_INVALIDARG;
  59. *aName = nullptr;
  60. if (IsDefunct())
  61. return CO_E_OBJNOTCONNECTED;
  62. nsAutoString name;
  63. AppName(name);
  64. if (name.IsEmpty())
  65. return S_FALSE;
  66. *aName = ::SysAllocStringLen(name.get(), name.Length());
  67. return *aName ? S_OK : E_OUTOFMEMORY;
  68. }
  69. STDMETHODIMP
  70. ApplicationAccessibleWrap::get_appVersion(BSTR* aVersion)
  71. {
  72. if (!aVersion)
  73. return E_INVALIDARG;
  74. *aVersion = nullptr;
  75. if (IsDefunct())
  76. return CO_E_OBJNOTCONNECTED;
  77. nsAutoString version;
  78. AppVersion(version);
  79. if (version.IsEmpty())
  80. return S_FALSE;
  81. *aVersion = ::SysAllocStringLen(version.get(), version.Length());
  82. return *aVersion ? S_OK : E_OUTOFMEMORY;
  83. }
  84. STDMETHODIMP
  85. ApplicationAccessibleWrap::get_toolkitName(BSTR* aName)
  86. {
  87. if (!aName)
  88. return E_INVALIDARG;
  89. if (IsDefunct())
  90. return CO_E_OBJNOTCONNECTED;
  91. nsAutoString name;
  92. PlatformName(name);
  93. if (name.IsEmpty())
  94. return S_FALSE;
  95. *aName = ::SysAllocStringLen(name.get(), name.Length());
  96. return *aName ? S_OK : E_OUTOFMEMORY;
  97. }
  98. STDMETHODIMP
  99. ApplicationAccessibleWrap::get_toolkitVersion(BSTR* aVersion)
  100. {
  101. if (!aVersion)
  102. return E_INVALIDARG;
  103. *aVersion = nullptr;
  104. if (IsDefunct())
  105. return CO_E_OBJNOTCONNECTED;
  106. nsAutoString version;
  107. PlatformVersion(version);
  108. if (version.IsEmpty())
  109. return S_FALSE;
  110. *aVersion = ::SysAllocStringLen(version.get(), version.Length());
  111. return *aVersion ? S_OK : E_OUTOFMEMORY;
  112. }