michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ 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 michael@0: #include "AtkSocketAccessible.h" michael@0: michael@0: #include "InterfaceInitFuncs.h" michael@0: #include "nsMai.h" michael@0: #include "mozilla/Likely.h" michael@0: michael@0: using namespace mozilla::a11y; michael@0: michael@0: AtkSocketEmbedType AtkSocketAccessible::g_atk_socket_embed = nullptr; michael@0: GType AtkSocketAccessible::g_atk_socket_type = G_TYPE_INVALID; michael@0: const char* AtkSocketAccessible::sATKSocketEmbedSymbol = "atk_socket_embed"; michael@0: const char* AtkSocketAccessible::sATKSocketGetTypeSymbol = "atk_socket_get_type"; michael@0: michael@0: bool AtkSocketAccessible::gCanEmbed = FALSE; michael@0: michael@0: extern "C" void mai_atk_component_iface_init(AtkComponentIface* aIface); michael@0: extern "C" GType mai_atk_socket_get_type(void); michael@0: michael@0: /* MaiAtkSocket */ michael@0: michael@0: #define MAI_TYPE_ATK_SOCKET (mai_atk_socket_get_type ()) michael@0: #define MAI_ATK_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\ michael@0: MAI_TYPE_ATK_SOCKET, MaiAtkSocket)) michael@0: #define MAI_IS_ATK_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\ michael@0: MAI_TYPE_ATK_SOCKET)) michael@0: #define MAI_ATK_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\ michael@0: MAI_TYPE_ATK_SOCKET,\ michael@0: MaiAtkSocketClass)) michael@0: #define MAI_IS_ATK_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\ michael@0: MAI_TYPE_ATK_SOCKET)) michael@0: #define MAI_ATK_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\ michael@0: MAI_TYPE_ATK_SOCKET,\ michael@0: MaiAtkSocketClass)) michael@0: michael@0: typedef struct _MaiAtkSocket michael@0: { michael@0: AtkSocket parent; michael@0: michael@0: AccessibleWrap* accWrap; michael@0: } MaiAtkSocket; michael@0: michael@0: typedef struct _MaiAtkSocketClass michael@0: { michael@0: AtkSocketClass parent_class; michael@0: } MaiAtkSocketClass; michael@0: michael@0: G_DEFINE_TYPE_EXTENDED(MaiAtkSocket, mai_atk_socket, michael@0: AtkSocketAccessible::g_atk_socket_type, 0, michael@0: G_IMPLEMENT_INTERFACE(ATK_TYPE_COMPONENT, michael@0: mai_atk_component_iface_init)) michael@0: michael@0: void michael@0: mai_atk_socket_class_init(MaiAtkSocketClass* aAcc) michael@0: { michael@0: } michael@0: michael@0: void michael@0: mai_atk_socket_init(MaiAtkSocket* aAcc) michael@0: { michael@0: } michael@0: michael@0: static AtkObject* michael@0: mai_atk_socket_new(AccessibleWrap* aAccWrap) michael@0: { michael@0: NS_ENSURE_TRUE(aAccWrap, nullptr); michael@0: michael@0: MaiAtkSocket* acc = nullptr; michael@0: acc = static_cast(g_object_new(MAI_TYPE_ATK_SOCKET, nullptr)); michael@0: NS_ENSURE_TRUE(acc, nullptr); michael@0: michael@0: acc->accWrap = aAccWrap; michael@0: return ATK_OBJECT(acc); michael@0: } michael@0: michael@0: extern "C" { michael@0: static AtkObject* michael@0: RefAccessibleAtPoint(AtkComponent* aComponent, gint aX, gint aY, michael@0: AtkCoordType aCoordType) michael@0: { michael@0: NS_ENSURE_TRUE(MAI_IS_ATK_SOCKET(aComponent), nullptr); michael@0: michael@0: return refAccessibleAtPointHelper(MAI_ATK_SOCKET(aComponent)->accWrap, michael@0: aX, aY, aCoordType); michael@0: } michael@0: michael@0: static void michael@0: GetExtents(AtkComponent* aComponent, gint* aX, gint* aY, gint* aWidth, michael@0: gint* aHeight, AtkCoordType aCoordType) michael@0: { michael@0: *aX = *aY = *aWidth = *aHeight = 0; michael@0: michael@0: if (!MAI_IS_ATK_SOCKET(aComponent)) michael@0: return; michael@0: michael@0: getExtentsHelper(MAI_ATK_SOCKET(aComponent)->accWrap, michael@0: aX, aY, aWidth, aHeight, aCoordType); michael@0: } michael@0: } michael@0: michael@0: void michael@0: mai_atk_component_iface_init(AtkComponentIface* aIface) michael@0: { michael@0: NS_ASSERTION(aIface, "Invalid Interface"); michael@0: if (MOZ_UNLIKELY(!aIface)) michael@0: return; michael@0: michael@0: aIface->ref_accessible_at_point = RefAccessibleAtPoint; michael@0: aIface->get_extents = GetExtents; michael@0: } michael@0: michael@0: AtkSocketAccessible::AtkSocketAccessible(nsIContent* aContent, michael@0: DocAccessible* aDoc, michael@0: const nsCString& aPlugId) : michael@0: AccessibleWrap(aContent, aDoc) michael@0: { michael@0: mAtkObject = mai_atk_socket_new(this); michael@0: if (!mAtkObject) michael@0: return; michael@0: michael@0: // Embeds the children of an AtkPlug, specified by plugId, as the children of michael@0: // this socket. michael@0: // Using G_TYPE macros instead of ATK_SOCKET macros to avoid undefined michael@0: // symbols. michael@0: if (gCanEmbed && G_TYPE_CHECK_INSTANCE_TYPE(mAtkObject, g_atk_socket_type) && michael@0: !aPlugId.IsVoid()) { michael@0: AtkSocket* accSocket = michael@0: G_TYPE_CHECK_INSTANCE_CAST(mAtkObject, g_atk_socket_type, AtkSocket); michael@0: g_atk_socket_embed(accSocket, (gchar*)aPlugId.get()); michael@0: } michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: AtkSocketAccessible::GetNativeInterface(void** aOutAccessible) michael@0: { michael@0: *aOutAccessible = mAtkObject; michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: AtkSocketAccessible::Shutdown() michael@0: { michael@0: if (mAtkObject) { michael@0: if (MAI_IS_ATK_SOCKET(mAtkObject)) michael@0: MAI_ATK_SOCKET(mAtkObject)->accWrap = nullptr; michael@0: g_object_unref(mAtkObject); michael@0: mAtkObject = nullptr; michael@0: } michael@0: AccessibleWrap::Shutdown(); michael@0: }