AtkSocketAccessible.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include <atk/atk.h>
  6. #include "AtkSocketAccessible.h"
  7. #include "InterfaceInitFuncs.h"
  8. #include "nsMai.h"
  9. #include "mozilla/Likely.h"
  10. using namespace mozilla::a11y;
  11. AtkSocketEmbedType AtkSocketAccessible::g_atk_socket_embed = nullptr;
  12. GType AtkSocketAccessible::g_atk_socket_type = G_TYPE_INVALID;
  13. const char* AtkSocketAccessible::sATKSocketEmbedSymbol = "atk_socket_embed";
  14. const char* AtkSocketAccessible::sATKSocketGetTypeSymbol = "atk_socket_get_type";
  15. bool AtkSocketAccessible::gCanEmbed = FALSE;
  16. extern "C" void mai_atk_component_iface_init(AtkComponentIface* aIface);
  17. G_DEFINE_TYPE_EXTENDED(MaiAtkSocket, mai_atk_socket,
  18. AtkSocketAccessible::g_atk_socket_type, 0,
  19. G_IMPLEMENT_INTERFACE(ATK_TYPE_COMPONENT,
  20. mai_atk_component_iface_init))
  21. void
  22. mai_atk_socket_class_init(MaiAtkSocketClass* aAcc)
  23. {
  24. }
  25. void
  26. mai_atk_socket_init(MaiAtkSocket* aAcc)
  27. {
  28. }
  29. static AtkObject*
  30. mai_atk_socket_new(AccessibleWrap* aAccWrap)
  31. {
  32. NS_ENSURE_TRUE(aAccWrap, nullptr);
  33. MaiAtkSocket* acc = nullptr;
  34. acc = static_cast<MaiAtkSocket*>(g_object_new(MAI_TYPE_ATK_SOCKET, nullptr));
  35. NS_ENSURE_TRUE(acc, nullptr);
  36. acc->accWrap = aAccWrap;
  37. return ATK_OBJECT(acc);
  38. }
  39. extern "C" {
  40. static AtkObject*
  41. RefAccessibleAtPoint(AtkComponent* aComponent, gint aX, gint aY,
  42. AtkCoordType aCoordType)
  43. {
  44. NS_ENSURE_TRUE(MAI_IS_ATK_SOCKET(aComponent), nullptr);
  45. return refAccessibleAtPointHelper(ATK_OBJECT(MAI_ATK_SOCKET(aComponent)),
  46. aX, aY, aCoordType);
  47. }
  48. static void
  49. GetExtents(AtkComponent* aComponent, gint* aX, gint* aY, gint* aWidth,
  50. gint* aHeight, AtkCoordType aCoordType)
  51. {
  52. *aX = *aY = *aWidth = *aHeight = 0;
  53. if (!MAI_IS_ATK_SOCKET(aComponent))
  54. return;
  55. getExtentsHelper(ATK_OBJECT(MAI_ATK_SOCKET(aComponent)),
  56. aX, aY, aWidth, aHeight, aCoordType);
  57. }
  58. }
  59. void
  60. mai_atk_component_iface_init(AtkComponentIface* aIface)
  61. {
  62. NS_ASSERTION(aIface, "Invalid Interface");
  63. if (MOZ_UNLIKELY(!aIface))
  64. return;
  65. aIface->ref_accessible_at_point = RefAccessibleAtPoint;
  66. aIface->get_extents = GetExtents;
  67. }
  68. AtkSocketAccessible::AtkSocketAccessible(nsIContent* aContent,
  69. DocAccessible* aDoc,
  70. const nsCString& aPlugId) :
  71. AccessibleWrap(aContent, aDoc)
  72. {
  73. mAtkObject = mai_atk_socket_new(this);
  74. if (!mAtkObject)
  75. return;
  76. // Embeds the children of an AtkPlug, specified by plugId, as the children of
  77. // this socket.
  78. // Using G_TYPE macros instead of ATK_SOCKET macros to avoid undefined
  79. // symbols.
  80. if (gCanEmbed && G_TYPE_CHECK_INSTANCE_TYPE(mAtkObject, g_atk_socket_type) &&
  81. !aPlugId.IsVoid()) {
  82. AtkSocket* accSocket =
  83. G_TYPE_CHECK_INSTANCE_CAST(mAtkObject, g_atk_socket_type, AtkSocket);
  84. g_atk_socket_embed(accSocket, (gchar*)aPlugId.get());
  85. }
  86. }
  87. void
  88. AtkSocketAccessible::GetNativeInterface(void** aOutAccessible)
  89. {
  90. *aOutAccessible = mAtkObject;
  91. }
  92. void
  93. AtkSocketAccessible::Shutdown()
  94. {
  95. if (mAtkObject) {
  96. if (MAI_IS_ATK_SOCKET(mAtkObject))
  97. MAI_ATK_SOCKET(mAtkObject)->accWrap = nullptr;
  98. g_object_unref(mAtkObject);
  99. mAtkObject = nullptr;
  100. }
  101. AccessibleWrap::Shutdown();
  102. }