1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "InterfaceInitFuncs.h"
#include "LocalAccessible-inl.h"
#include "nsMai.h"
#include "mozilla/Likely.h"
#include "nsAccessibilityService.h"
#include "Relation.h"
#include "RemoteAccessible.h"
#include "nsString.h"
using namespace mozilla;
using namespace mozilla::a11y;
extern "C" {
static gboolean doActionCB(AtkAction* aAction, gint aActionIndex) {
AtkObject* atkObject = ATK_OBJECT(aAction);
Accessible* acc = GetInternalObj(atkObject);
if (!acc) {
// If we don't have an Accessible, we can't have any actions.
return false;
}
if (aActionIndex < acc->ActionCount()) {
acc->DoAction(aActionIndex);
return true;
}
// Check for custom actions.
Relation customActions(acc->RelationByType(RelationType::ACTION));
gint actionIndex = acc->ActionCount();
while (Accessible* target = customActions.Next()) {
if (target->HasPrimaryAction()) {
MOZ_ASSERT(target->ActionCount() > 0);
if (actionIndex == aActionIndex) {
target->DoAction(0);
return true;
}
actionIndex++;
}
}
return false;
}
static gint getActionCountCB(AtkAction* aAction) {
AtkObject* atkObject = ATK_OBJECT(aAction);
Accessible* acc = GetInternalObj(atkObject);
if (!acc) {
// If we don't have an Accessible, we can't have any actions.
return 0;
}
gint actionCount = acc->ActionCount();
Relation customActions(acc->RelationByType(RelationType::ACTION));
while (Accessible* target = customActions.Next()) {
if (target->HasPrimaryAction()) {
actionCount++;
}
}
return actionCount;
}
static const gchar* getActionDescriptionCB(AtkAction* aAction,
gint aActionIndex) {
AtkObject* atkObject = ATK_OBJECT(aAction);
nsAutoString description;
Accessible* acc = GetInternalObj(atkObject);
if (!acc) {
// If we don't have an Accessible, we can't have any actions.
return 0;
}
if (aActionIndex < acc->ActionCount()) {
acc->ActionDescriptionAt(aActionIndex, description);
} else {
// Check for custom actions.
Relation customActions(acc->RelationByType(RelationType::ACTION));
gint actionIndex = acc->ActionCount();
while (Accessible* target = customActions.Next()) {
if (target->HasPrimaryAction()) {
MOZ_ASSERT(target->ActionCount() > 0);
if (actionIndex == aActionIndex) {
// Use target's name as action description.
target->Name(description);
break;
}
actionIndex++;
}
}
}
if (!description.IsEmpty()) {
return AccessibleWrap::ReturnString(description);
}
return nullptr;
}
static const gchar* getActionNameCB(AtkAction* aAction, gint aActionIndex) {
AtkObject* atkObject = ATK_OBJECT(aAction);
nsAutoString name;
Accessible* acc = GetInternalObj(atkObject);
if (!acc) {
// If we don't have an Accessible, we can't have any actions.
return 0;
}
if (aActionIndex < acc->ActionCount()) {
acc->ActionNameAt(aActionIndex, name);
} else {
// Check for custom actions.
Relation customActions(acc->RelationByType(RelationType::ACTION));
gint actionIndex = acc->ActionCount();
while (Accessible* target = customActions.Next()) {
if (target->HasPrimaryAction()) {
MOZ_ASSERT(target->ActionCount() > 0);
if (actionIndex == aActionIndex) {
name.AssignLiteral("custom");
nsAutoString domNodeId;
target->DOMNodeID(domNodeId);
if (!domNodeId.IsEmpty()) {
name.AppendPrintf("_%s", NS_ConvertUTF16toUTF8(domNodeId).get());
}
break;
}
actionIndex++;
}
}
}
if (!name.IsEmpty()) {
return AccessibleWrap::ReturnString(name);
}
return nullptr;
}
static const gchar* getActionLocalizedNameCB(AtkAction* aAction,
gint aActionIndex) {
// Mirror action description into localized name.
return getActionDescriptionCB(aAction, aActionIndex);
}
static const gchar* getKeyBindingCB(AtkAction* aAction, gint aActionIndex) {
Accessible* acc = GetInternalObj(ATK_OBJECT(aAction));
if (!acc) {
return nullptr;
}
nsAutoString keyBindingsStr;
AccessibleWrap::GetKeyBinding(acc, keyBindingsStr);
return AccessibleWrap::ReturnString(keyBindingsStr);
}
}
void actionInterfaceInitCB(AtkActionIface* aIface) {
NS_ASSERTION(aIface, "Invalid aIface");
if (MOZ_UNLIKELY(!aIface)) return;
aIface->do_action = doActionCB;
aIface->get_n_actions = getActionCountCB;
aIface->get_description = getActionDescriptionCB;
aIface->get_keybinding = getKeyBindingCB;
aIface->get_name = getActionNameCB;
aIface->get_localized_name = getActionLocalizedNameCB;
}
|