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"
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2012-12-21 07:16:44 +04:00
|
|
|
#include "Accessible-inl.h"
|
2012-05-29 05:18:45 +04:00
|
|
|
#include "AccessibleWrap.h"
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "nsMai.h"
|
2015-03-25 17:19:12 +03:00
|
|
|
#include "ProxyAccessible.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2012-03-20 08:02:50 +04:00
|
|
|
|
|
|
|
#include <atk/atk.h>
|
|
|
|
|
2012-11-18 06:01:44 +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
|
|
|
addSelectionCB(AtkSelection *aSelection, gint i)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 17:19:12 +03:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->AddItemToSelection(i);
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-25 17:19:12 +03:00
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->AddItemToSelection(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
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
|
|
|
clearSelectionCB(AtkSelection *aSelection)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 17:19:12 +03:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->UnselectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->UnselectAll();
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-25 17:19:12 +03:00
|
|
|
return FALSE;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
static AtkObject*
|
2003-05-06 06:23:50 +04:00
|
|
|
refSelectionCB(AtkSelection *aSelection, gint i)
|
|
|
|
{
|
2015-03-25 17:19:12 +03:00
|
|
|
AtkObject* atkObj = nullptr;
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 17:19:12 +03:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
Accessible* selectedItem = accWrap->GetSelectedItem(i);
|
|
|
|
if (!selectedItem) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
atkObj = AccessibleWrap::GetAtkObject(selectedItem);
|
|
|
|
} else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
ProxyAccessible* selectedItem = proxy->GetSelectedItem(i);
|
|
|
|
if (selectedItem) {
|
|
|
|
atkObj = GetWrapperFor(selectedItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atkObj) {
|
2012-05-29 05:18:45 +04:00
|
|
|
g_object_ref(atkObj);
|
2015-03-25 17:19:12 +03:00
|
|
|
}
|
2012-05-29 05:18:45 +04:00
|
|
|
|
|
|
|
return atkObj;
|
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
|
|
|
getSelectionCountCB(AtkSelection *aSelection)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 17:19:12 +03:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->SelectedItemCount();
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-25 17:19:12 +03:00
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->SelectedItemCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
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
|
|
|
isChildSelectedCB(AtkSelection *aSelection, gint i)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 17:19:12 +03:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->IsItemSelected(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->IsItemSelected(i);
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-25 17:19:12 +03:00
|
|
|
return FALSE;
|
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
|
|
|
removeSelectionCB(AtkSelection *aSelection, gint i)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 17:19:12 +03:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->RemoveItemFromSelection(i);
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-25 17:19:12 +03:00
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->RemoveItemFromSelection(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
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
|
|
|
selectAllSelectionCB(AtkSelection *aSelection)
|
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 17:19:12 +03:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->SelectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->SelectAll();
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-03-25 17:19:12 +03:00
|
|
|
return FALSE;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
2012-03-20 08:02:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
selectionInterfaceInitCB(AtkSelectionIface* 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->add_selection = addSelectionCB;
|
|
|
|
aIface->clear_selection = clearSelectionCB;
|
|
|
|
aIface->ref_selection = refSelectionCB;
|
|
|
|
aIface->get_selection_count = getSelectionCountCB;
|
|
|
|
aIface->is_child_selected = isChildSelectedCB;
|
|
|
|
aIface->remove_selection = removeSelectionCB;
|
|
|
|
aIface->select_all_selection = selectAllSelectionCB;
|
|
|
|
}
|