michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "InterfaceInitFuncs.h" michael@0: michael@0: #include "Accessible-inl.h" michael@0: #include "AccessibleWrap.h" michael@0: #include "nsMai.h" michael@0: #include "mozilla/Likely.h" michael@0: michael@0: #include michael@0: michael@0: using namespace mozilla::a11y; michael@0: michael@0: extern "C" { michael@0: michael@0: static gboolean michael@0: addSelectionCB(AtkSelection *aSelection, gint i) michael@0: { michael@0: AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection)); michael@0: if (!accWrap || !accWrap->IsSelect()) michael@0: return FALSE; michael@0: michael@0: return accWrap->AddItemToSelection(i); michael@0: } michael@0: michael@0: static gboolean michael@0: clearSelectionCB(AtkSelection *aSelection) michael@0: { michael@0: AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection)); michael@0: if (!accWrap || !accWrap->IsSelect()) michael@0: return FALSE; michael@0: michael@0: return accWrap->UnselectAll(); michael@0: } michael@0: michael@0: static AtkObject* michael@0: refSelectionCB(AtkSelection *aSelection, gint i) michael@0: { michael@0: AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection)); michael@0: if (!accWrap || !accWrap->IsSelect()) michael@0: return nullptr; michael@0: michael@0: Accessible* selectedItem = accWrap->GetSelectedItem(i); michael@0: if (!selectedItem) michael@0: return nullptr; michael@0: michael@0: AtkObject* atkObj = AccessibleWrap::GetAtkObject(selectedItem); michael@0: if (atkObj) michael@0: g_object_ref(atkObj); michael@0: michael@0: return atkObj; michael@0: } michael@0: michael@0: static gint michael@0: getSelectionCountCB(AtkSelection *aSelection) michael@0: { michael@0: AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection)); michael@0: if (!accWrap || !accWrap->IsSelect()) michael@0: return -1; michael@0: michael@0: return accWrap->SelectedItemCount(); michael@0: } michael@0: michael@0: static gboolean michael@0: isChildSelectedCB(AtkSelection *aSelection, gint i) michael@0: { michael@0: AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection)); michael@0: if (!accWrap || !accWrap->IsSelect()) michael@0: return FALSE; michael@0: michael@0: return accWrap->IsItemSelected(i); michael@0: } michael@0: michael@0: static gboolean michael@0: removeSelectionCB(AtkSelection *aSelection, gint i) michael@0: { michael@0: AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection)); michael@0: if (!accWrap || !accWrap->IsSelect()) michael@0: return FALSE; michael@0: michael@0: return accWrap->RemoveItemFromSelection(i); michael@0: } michael@0: michael@0: static gboolean michael@0: selectAllSelectionCB(AtkSelection *aSelection) michael@0: { michael@0: AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection)); michael@0: if (!accWrap || !accWrap->IsSelect()) michael@0: return FALSE; michael@0: michael@0: return accWrap->SelectAll(); michael@0: } michael@0: } michael@0: michael@0: void michael@0: selectionInterfaceInitCB(AtkSelectionIface* aIface) michael@0: { michael@0: NS_ASSERTION(aIface, "Invalid aIface"); michael@0: if (MOZ_UNLIKELY(!aIface)) michael@0: return; michael@0: michael@0: aIface->add_selection = addSelectionCB; michael@0: aIface->clear_selection = clearSelectionCB; michael@0: aIface->ref_selection = refSelectionCB; michael@0: aIface->get_selection_count = getSelectionCountCB; michael@0: aIface->is_child_selected = isChildSelectedCB; michael@0: aIface->remove_selection = removeSelectionCB; michael@0: aIface->select_all_selection = selectAllSelectionCB; michael@0: }