1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/atk/nsMaiInterfaceComponent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,116 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "InterfaceInitFuncs.h" 1.11 + 1.12 +#include "AccessibleWrap.h" 1.13 +#include "nsAccUtils.h" 1.14 +#include "nsCoreUtils.h" 1.15 +#include "nsMai.h" 1.16 +#include "mozilla/Likely.h" 1.17 + 1.18 +using namespace mozilla::a11y; 1.19 + 1.20 +extern "C" { 1.21 + 1.22 +static AtkObject* 1.23 +refAccessibleAtPointCB(AtkComponent* aComponent, gint aAccX, gint aAccY, 1.24 + AtkCoordType aCoordType) 1.25 +{ 1.26 + return refAccessibleAtPointHelper(GetAccessibleWrap(ATK_OBJECT(aComponent)), 1.27 + aAccX, aAccY, aCoordType); 1.28 +} 1.29 + 1.30 +static void 1.31 +getExtentsCB(AtkComponent* aComponent, gint* aX, gint* aY, 1.32 + gint* aWidth, gint* aHeight, AtkCoordType aCoordType) 1.33 +{ 1.34 + getExtentsHelper(GetAccessibleWrap(ATK_OBJECT(aComponent)), 1.35 + aX, aY, aWidth, aHeight, aCoordType); 1.36 +} 1.37 + 1.38 +static gboolean 1.39 +grabFocusCB(AtkComponent* aComponent) 1.40 +{ 1.41 + AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent)); 1.42 + if (!accWrap) 1.43 + return FALSE; 1.44 + 1.45 + nsresult rv = accWrap->TakeFocus(); 1.46 + return (NS_FAILED(rv)) ? FALSE : TRUE; 1.47 +} 1.48 +} 1.49 + 1.50 +AtkObject* 1.51 +refAccessibleAtPointHelper(AccessibleWrap* aAccWrap, gint aX, gint aY, 1.52 + AtkCoordType aCoordType) 1.53 +{ 1.54 + if (!aAccWrap || aAccWrap->IsDefunct() || nsAccUtils::MustPrune(aAccWrap)) 1.55 + return nullptr; 1.56 + 1.57 + // Accessible::ChildAtPoint(x,y) is in screen pixels. 1.58 + if (aCoordType == ATK_XY_WINDOW) { 1.59 + nsIntPoint winCoords = 1.60 + nsCoreUtils::GetScreenCoordsForWindow(aAccWrap->GetNode()); 1.61 + aX += winCoords.x; 1.62 + aY += winCoords.y; 1.63 + } 1.64 + 1.65 + Accessible* accAtPoint = aAccWrap->ChildAtPoint(aX, aY, 1.66 + Accessible::eDirectChild); 1.67 + if (!accAtPoint) 1.68 + return nullptr; 1.69 + 1.70 + AtkObject* atkObj = AccessibleWrap::GetAtkObject(accAtPoint); 1.71 + if (atkObj) 1.72 + g_object_ref(atkObj); 1.73 + return atkObj; 1.74 +} 1.75 + 1.76 +void 1.77 +getExtentsHelper(AccessibleWrap* aAccWrap, 1.78 + gint* aX, gint* aY, gint* aWidth, gint* aHeight, 1.79 + AtkCoordType aCoordType) 1.80 +{ 1.81 + *aX = *aY = *aWidth = *aHeight = 0; 1.82 + 1.83 + if (!aAccWrap || aAccWrap->IsDefunct()) 1.84 + return; 1.85 + 1.86 + int32_t x = 0, y = 0, width = 0, height = 0; 1.87 + // Returned in screen coordinates 1.88 + nsresult rv = aAccWrap->GetBounds(&x, &y, &width, &height); 1.89 + if (NS_FAILED(rv)) 1.90 + return; 1.91 + 1.92 + if (aCoordType == ATK_XY_WINDOW) { 1.93 + nsIntPoint winCoords = 1.94 + nsCoreUtils::GetScreenCoordsForWindow(aAccWrap->GetNode()); 1.95 + x -= winCoords.x; 1.96 + y -= winCoords.y; 1.97 + } 1.98 + 1.99 + *aX = x; 1.100 + *aY = y; 1.101 + *aWidth = width; 1.102 + *aHeight = height; 1.103 +} 1.104 + 1.105 +void 1.106 +componentInterfaceInitCB(AtkComponentIface* aIface) 1.107 +{ 1.108 + NS_ASSERTION(aIface, "Invalid Interface"); 1.109 + if(MOZ_UNLIKELY(!aIface)) 1.110 + return; 1.111 + 1.112 + /* 1.113 + * Use default implementation in atk for contains, get_position, 1.114 + * and get_size 1.115 + */ 1.116 + aIface->ref_accessible_at_point = refAccessibleAtPointCB; 1.117 + aIface->get_extents = getExtentsCB; 1.118 + aIface->grab_focus = grabFocusCB; 1.119 +}