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 "InterfaceInitFuncs.h" michael@0: michael@0: #include "AccessibleWrap.h" michael@0: #include "nsAccUtils.h" michael@0: #include "nsCoreUtils.h" michael@0: #include "nsMai.h" michael@0: #include "mozilla/Likely.h" michael@0: michael@0: using namespace mozilla::a11y; michael@0: michael@0: extern "C" { michael@0: michael@0: static AtkObject* michael@0: refAccessibleAtPointCB(AtkComponent* aComponent, gint aAccX, gint aAccY, michael@0: AtkCoordType aCoordType) michael@0: { michael@0: return refAccessibleAtPointHelper(GetAccessibleWrap(ATK_OBJECT(aComponent)), michael@0: aAccX, aAccY, aCoordType); michael@0: } michael@0: michael@0: static void michael@0: getExtentsCB(AtkComponent* aComponent, gint* aX, gint* aY, michael@0: gint* aWidth, gint* aHeight, AtkCoordType aCoordType) michael@0: { michael@0: getExtentsHelper(GetAccessibleWrap(ATK_OBJECT(aComponent)), michael@0: aX, aY, aWidth, aHeight, aCoordType); michael@0: } michael@0: michael@0: static gboolean michael@0: grabFocusCB(AtkComponent* aComponent) michael@0: { michael@0: AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent)); michael@0: if (!accWrap) michael@0: return FALSE; michael@0: michael@0: nsresult rv = accWrap->TakeFocus(); michael@0: return (NS_FAILED(rv)) ? FALSE : TRUE; michael@0: } michael@0: } michael@0: michael@0: AtkObject* michael@0: refAccessibleAtPointHelper(AccessibleWrap* aAccWrap, gint aX, gint aY, michael@0: AtkCoordType aCoordType) michael@0: { michael@0: if (!aAccWrap || aAccWrap->IsDefunct() || nsAccUtils::MustPrune(aAccWrap)) michael@0: return nullptr; michael@0: michael@0: // Accessible::ChildAtPoint(x,y) is in screen pixels. michael@0: if (aCoordType == ATK_XY_WINDOW) { michael@0: nsIntPoint winCoords = michael@0: nsCoreUtils::GetScreenCoordsForWindow(aAccWrap->GetNode()); michael@0: aX += winCoords.x; michael@0: aY += winCoords.y; michael@0: } michael@0: michael@0: Accessible* accAtPoint = aAccWrap->ChildAtPoint(aX, aY, michael@0: Accessible::eDirectChild); michael@0: if (!accAtPoint) michael@0: return nullptr; michael@0: michael@0: AtkObject* atkObj = AccessibleWrap::GetAtkObject(accAtPoint); michael@0: if (atkObj) michael@0: g_object_ref(atkObj); michael@0: return atkObj; michael@0: } michael@0: michael@0: void michael@0: getExtentsHelper(AccessibleWrap* aAccWrap, michael@0: gint* aX, gint* aY, gint* aWidth, gint* aHeight, michael@0: AtkCoordType aCoordType) michael@0: { michael@0: *aX = *aY = *aWidth = *aHeight = 0; michael@0: michael@0: if (!aAccWrap || aAccWrap->IsDefunct()) michael@0: return; michael@0: michael@0: int32_t x = 0, y = 0, width = 0, height = 0; michael@0: // Returned in screen coordinates michael@0: nsresult rv = aAccWrap->GetBounds(&x, &y, &width, &height); michael@0: if (NS_FAILED(rv)) michael@0: return; michael@0: michael@0: if (aCoordType == ATK_XY_WINDOW) { michael@0: nsIntPoint winCoords = michael@0: nsCoreUtils::GetScreenCoordsForWindow(aAccWrap->GetNode()); michael@0: x -= winCoords.x; michael@0: y -= winCoords.y; michael@0: } michael@0: michael@0: *aX = x; michael@0: *aY = y; michael@0: *aWidth = width; michael@0: *aHeight = height; michael@0: } michael@0: michael@0: void michael@0: componentInterfaceInitCB(AtkComponentIface* aIface) michael@0: { michael@0: NS_ASSERTION(aIface, "Invalid Interface"); michael@0: if(MOZ_UNLIKELY(!aIface)) michael@0: return; michael@0: michael@0: /* michael@0: * Use default implementation in atk for contains, get_position, michael@0: * and get_size michael@0: */ michael@0: aIface->ref_accessible_at_point = refAccessibleAtPointCB; michael@0: aIface->get_extents = getExtentsCB; michael@0: aIface->grab_focus = grabFocusCB; michael@0: }