2011-04-27 06:42:27 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-05-27 15:37:24 -07:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
#include "InterfaceInitFuncs.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-20 19:16:44 -08:00
|
|
|
#include "Accessible-inl.h"
|
2012-05-28 18:18:45 -07:00
|
|
|
#include "AccessibleWrap.h"
|
2012-03-19 21:02:50 -07:00
|
|
|
#include "nsMai.h"
|
2015-03-25 07:19:12 -07:00
|
|
|
#include "ProxyAccessible.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
2012-03-19 21:02:50 -07:00
|
|
|
|
|
|
|
#include <atk/atk.h>
|
|
|
|
|
2012-11-17 18:01:44 -08:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
extern "C" {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
addSelectionCB(AtkSelection *aSelection, gint i)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 07:19:12 -07:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->AddItemToSelection(i);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-25 07:19:12 -07:00
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->AddItemToSelection(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
clearSelectionCB(AtkSelection *aSelection)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 07:19:12 -07:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->UnselectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->UnselectAll();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-25 07:19:12 -07:00
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static AtkObject*
|
2007-03-22 10:30:00 -07:00
|
|
|
refSelectionCB(AtkSelection *aSelection, gint i)
|
|
|
|
{
|
2015-03-25 07:19:12 -07:00
|
|
|
AtkObject* atkObj = nullptr;
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 07:19:12 -07: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-28 18:18:45 -07:00
|
|
|
g_object_ref(atkObj);
|
2015-03-25 07:19:12 -07:00
|
|
|
}
|
2012-05-28 18:18:45 -07:00
|
|
|
|
|
|
|
return atkObj;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gint
|
2007-03-22 10:30:00 -07:00
|
|
|
getSelectionCountCB(AtkSelection *aSelection)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 07:19:12 -07:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->SelectedItemCount();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-25 07:19:12 -07:00
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->SelectedItemCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
isChildSelectedCB(AtkSelection *aSelection, gint i)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 07:19:12 -07:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->IsItemSelected(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->IsItemSelected(i);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-25 07:19:12 -07:00
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
removeSelectionCB(AtkSelection *aSelection, gint i)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 07:19:12 -07:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->RemoveItemFromSelection(i);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-25 07:19:12 -07:00
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->RemoveItemFromSelection(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-19 21:02:50 -07:00
|
|
|
static gboolean
|
2007-03-22 10:30:00 -07:00
|
|
|
selectAllSelectionCB(AtkSelection *aSelection)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
|
2015-03-25 07:19:12 -07:00
|
|
|
if (accWrap && accWrap->IsSelect()) {
|
|
|
|
return accWrap->SelectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aSelection))) {
|
|
|
|
return proxy->SelectAll();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-25 07:19:12 -07:00
|
|
|
return FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-03-19 21:02:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
selectionInterfaceInitCB(AtkSelectionIface* aIface)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aIface, "Invalid aIface");
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(!aIface))
|
2012-03-19 21:02:50 -07: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;
|
|
|
|
}
|