nsMaiInterfaceSelection.cpp (2696B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "InterfaceInitFuncs.h" 8 9 #include "LocalAccessible-inl.h" 10 #include "AccessibleWrap.h" 11 #include "nsMai.h" 12 #include "mozilla/Likely.h" 13 14 #include <atk/atkobject.h> 15 #include <atk/atkselection.h> 16 17 using namespace mozilla::a11y; 18 19 extern "C" { 20 21 static gboolean addSelectionCB(AtkSelection* aSelection, gint i) { 22 Accessible* acc = GetInternalObj(ATK_OBJECT(aSelection)); 23 if (acc && acc->IsSelect()) { 24 return acc->AddItemToSelection(i); 25 } 26 27 return FALSE; 28 } 29 30 static gboolean clearSelectionCB(AtkSelection* aSelection) { 31 Accessible* acc = GetInternalObj(ATK_OBJECT(aSelection)); 32 if (acc && acc->IsSelect()) { 33 return acc->UnselectAll(); 34 } 35 36 return FALSE; 37 } 38 39 static AtkObject* refSelectionCB(AtkSelection* aSelection, gint i) { 40 AtkObject* atkObj = nullptr; 41 Accessible* acc = GetInternalObj(ATK_OBJECT(aSelection)); 42 Accessible* selectedItem = acc->GetSelectedItem(i); 43 if (selectedItem) { 44 atkObj = GetWrapperFor(selectedItem); 45 } 46 47 if (atkObj) { 48 g_object_ref(atkObj); 49 } 50 51 return atkObj; 52 } 53 54 static gint getSelectionCountCB(AtkSelection* aSelection) { 55 Accessible* acc = GetInternalObj(ATK_OBJECT(aSelection)); 56 if (acc && acc->IsSelect()) { 57 return acc->SelectedItemCount(); 58 } 59 60 return -1; 61 } 62 63 static gboolean isChildSelectedCB(AtkSelection* aSelection, gint i) { 64 Accessible* acc = GetInternalObj(ATK_OBJECT(aSelection)); 65 if (acc && acc->IsSelect()) { 66 return acc->IsItemSelected(i); 67 } 68 69 return FALSE; 70 } 71 72 static gboolean removeSelectionCB(AtkSelection* aSelection, gint i) { 73 Accessible* acc = GetInternalObj(ATK_OBJECT(aSelection)); 74 if (acc && acc->IsSelect()) { 75 return acc->RemoveItemFromSelection(i); 76 } 77 78 return FALSE; 79 } 80 81 static gboolean selectAllSelectionCB(AtkSelection* aSelection) { 82 Accessible* acc = GetInternalObj(ATK_OBJECT(aSelection)); 83 if (acc && acc->IsSelect()) { 84 return acc->SelectAll(); 85 } 86 87 return FALSE; 88 } 89 } 90 91 void selectionInterfaceInitCB(AtkSelectionIface* aIface) { 92 NS_ASSERTION(aIface, "Invalid aIface"); 93 if (MOZ_UNLIKELY(!aIface)) return; 94 95 aIface->add_selection = addSelectionCB; 96 aIface->clear_selection = clearSelectionCB; 97 aIface->ref_selection = refSelectionCB; 98 aIface->get_selection_count = getSelectionCountCB; 99 aIface->is_child_selected = isChildSelectedCB; 100 aIface->remove_selection = removeSelectionCB; 101 aIface->select_all_selection = selectAllSelectionCB; 102 }