2011-04-27 17:42:27 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-05-28 02:37:24 +04:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "InterfaceInitFuncs.h"
|
2009-03-11 04:59:25 +03:00
|
|
|
|
2012-04-17 13:56:02 +04:00
|
|
|
#include "Accessible-inl.h"
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "nsMai.h"
|
2012-01-12 07:07:35 +04:00
|
|
|
#include "Role.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "nsString.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
extern "C" {
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gboolean
|
2003-05-06 06:23:50 +04:00
|
|
|
doActionCB(AtkAction *aAction, gint aActionIndex)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
|
2014-09-16 21:30:23 +04:00
|
|
|
return accWrap && accWrap->DoAction(aActionIndex);
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static gint
|
2003-05-06 06:23:50 +04:00
|
|
|
getActionCountCB(AtkAction *aAction)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
|
2011-06-05 23:35:43 +04:00
|
|
|
return accWrap ? accWrap->ActionCount() : 0;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static const gchar*
|
2006-05-29 09:46:38 +04:00
|
|
|
getActionDescriptionCB(AtkAction *aAction, gint aActionIndex)
|
2003-05-06 06:23:50 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
|
|
|
|
if (!accWrap)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2007-02-25 06:43:20 +03:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
nsAutoString description;
|
2014-10-22 04:49:28 +04:00
|
|
|
accWrap->ActionDescriptionAt(aActionIndex, description);
|
2012-05-29 05:18:45 +04:00
|
|
|
return AccessibleWrap::ReturnString(description);
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static const gchar*
|
2006-05-29 09:46:38 +04:00
|
|
|
getActionNameCB(AtkAction *aAction, gint aActionIndex)
|
2003-05-06 06:23:50 +04:00
|
|
|
{
|
2014-09-16 21:30:23 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
|
|
|
|
if (!accWrap)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
nsAutoString autoStr;
|
|
|
|
accWrap->ActionNameAt(aActionIndex, autoStr);
|
|
|
|
return AccessibleWrap::ReturnString(autoStr);
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static const gchar*
|
2003-07-31 12:09:39 +04:00
|
|
|
getKeyBindingCB(AtkAction *aAction, gint aActionIndex)
|
2003-05-06 06:23:50 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* acc = GetAccessibleWrap(ATK_OBJECT(aAction));
|
2011-07-19 12:30:24 +04:00
|
|
|
if (!acc)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-07-19 12:30:24 +04:00
|
|
|
|
|
|
|
// Return all key bindings including access key and keyboard shortcut.
|
|
|
|
nsAutoString keyBindingsStr;
|
|
|
|
|
|
|
|
// Get access key.
|
|
|
|
KeyBinding keyBinding = acc->AccessKey();
|
|
|
|
if (!keyBinding.IsEmpty()) {
|
|
|
|
keyBinding.AppendToString(keyBindingsStr, KeyBinding::eAtkFormat);
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* parent = acc->Parent();
|
2012-01-12 07:07:35 +04:00
|
|
|
roles::Role role = parent ? parent->Role() : roles::NOTHING;
|
|
|
|
if (role == roles::PARENT_MENUITEM || role == roles::MENUITEM ||
|
|
|
|
role == roles::RADIO_MENU_ITEM || role == roles::CHECK_MENU_ITEM) {
|
2011-07-19 12:30:24 +04:00
|
|
|
// It is submenu, expose keyboard shortcuts from menu hierarchy like
|
|
|
|
// "s;<Alt>f:s"
|
|
|
|
nsAutoString keysInHierarchyStr = keyBindingsStr;
|
|
|
|
do {
|
|
|
|
KeyBinding parentKeyBinding = parent->AccessKey();
|
|
|
|
if (!parentKeyBinding.IsEmpty()) {
|
|
|
|
nsAutoString str;
|
|
|
|
parentKeyBinding.ToString(str, KeyBinding::eAtkFormat);
|
|
|
|
str.Append(':');
|
|
|
|
|
|
|
|
keysInHierarchyStr.Insert(str, 0);
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
2012-01-12 07:07:35 +04:00
|
|
|
} while ((parent = parent->Parent()) && parent->Role() != roles::MENUBAR);
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2011-07-19 12:30:24 +04:00
|
|
|
keyBindingsStr.Append(';');
|
|
|
|
keyBindingsStr.Append(keysInHierarchyStr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No access key, add ';' to point this.
|
|
|
|
keyBindingsStr.Append(';');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get keyboard shortcut.
|
|
|
|
keyBindingsStr.Append(';');
|
|
|
|
keyBinding = acc->KeyboardShortcut();
|
|
|
|
if (!keyBinding.IsEmpty()) {
|
|
|
|
keyBinding.AppendToString(keyBindingsStr, KeyBinding::eAtkFormat);
|
|
|
|
}
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
return AccessibleWrap::ReturnString(keyBindingsStr);
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
2012-03-20 08:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
actionInterfaceInitCB(AtkActionIface* aIface)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aIface, "Invalid aIface");
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(!aIface))
|
2012-03-20 08:02:50 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
aIface->do_action = doActionCB;
|
|
|
|
aIface->get_n_actions = getActionCountCB;
|
|
|
|
aIface->get_description = getActionDescriptionCB;
|
|
|
|
aIface->get_keybinding = getKeyBindingCB;
|
|
|
|
aIface->get_name = getActionNameCB;
|
|
|
|
}
|