ApplicationAccessible.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:expandtab:shiftwidth=2:tabstop=2:
  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. #ifndef mozilla_a11y_ApplicationAccessible_h__
  8. #define mozilla_a11y_ApplicationAccessible_h__
  9. #include "AccessibleWrap.h"
  10. #include "nsIMutableArray.h"
  11. #include "nsIXULAppInfo.h"
  12. namespace mozilla {
  13. namespace a11y {
  14. /**
  15. * ApplicationAccessible is for the whole application of Mozilla.
  16. * Only one instance of ApplicationAccessible exists for one Mozilla instance.
  17. * And this one should be created when Mozilla Startup (if accessibility
  18. * feature has been enabled) and destroyed when Mozilla Shutdown.
  19. *
  20. * All the accessibility objects for toplevel windows are direct children of
  21. * the ApplicationAccessible instance.
  22. */
  23. class ApplicationAccessible : public AccessibleWrap
  24. {
  25. public:
  26. ApplicationAccessible();
  27. NS_DECL_ISUPPORTS_INHERITED
  28. // Accessible
  29. virtual void Shutdown() override;
  30. virtual nsIntRect Bounds() const override;
  31. virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() override;
  32. virtual GroupPos GroupPosition() override;
  33. virtual ENameValueFlag Name(nsString& aName) override;
  34. virtual void ApplyARIAState(uint64_t* aState) const override;
  35. virtual void Description(nsString& aDescription) override;
  36. virtual void Value(nsString& aValue) override;
  37. virtual mozilla::a11y::role NativeRole() override;
  38. virtual uint64_t State() override;
  39. virtual uint64_t NativeState() override;
  40. virtual Relation RelationByType(RelationType aType) override;
  41. virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY,
  42. EWhichChildAtPoint aWhichChild) override;
  43. virtual Accessible* FocusedChild() override;
  44. // ActionAccessible
  45. virtual KeyBinding AccessKey() const override;
  46. // ApplicationAccessible
  47. void Init();
  48. void AppName(nsAString& aName) const
  49. {
  50. MOZ_ASSERT(mAppInfo, "no application info");
  51. if (mAppInfo) {
  52. nsAutoCString cname;
  53. mAppInfo->GetName(cname);
  54. AppendUTF8toUTF16(cname, aName);
  55. }
  56. }
  57. void AppVersion(nsAString& aVersion) const
  58. {
  59. MOZ_ASSERT(mAppInfo, "no application info");
  60. if (mAppInfo) {
  61. nsAutoCString cversion;
  62. mAppInfo->GetVersion(cversion);
  63. AppendUTF8toUTF16(cversion, aVersion);
  64. }
  65. }
  66. void PlatformName(nsAString& aName) const
  67. {
  68. aName.AssignLiteral("Gecko");
  69. }
  70. void PlatformVersion(nsAString& aVersion) const
  71. {
  72. MOZ_ASSERT(mAppInfo, "no application info");
  73. if (mAppInfo) {
  74. nsAutoCString cversion;
  75. mAppInfo->GetPlatformVersion(cversion);
  76. AppendUTF8toUTF16(cversion, aVersion);
  77. }
  78. }
  79. protected:
  80. virtual ~ApplicationAccessible() {}
  81. // Accessible
  82. virtual Accessible* GetSiblingAtOffset(int32_t aOffset,
  83. nsresult *aError = nullptr) const override;
  84. private:
  85. nsCOMPtr<nsIXULAppInfo> mAppInfo;
  86. };
  87. inline ApplicationAccessible*
  88. Accessible::AsApplication()
  89. {
  90. return IsApplication() ? static_cast<ApplicationAccessible*>(this) : nullptr;
  91. }
  92. } // namespace a11y
  93. } // namespace mozilla
  94. #endif