accessible/src/atk/nsMaiInterfaceSelection.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/atk/nsMaiInterfaceSelection.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,113 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "InterfaceInitFuncs.h"
    1.11 +
    1.12 +#include "Accessible-inl.h"
    1.13 +#include "AccessibleWrap.h"
    1.14 +#include "nsMai.h"
    1.15 +#include "mozilla/Likely.h"
    1.16 +
    1.17 +#include <atk/atk.h>
    1.18 +
    1.19 +using namespace mozilla::a11y;
    1.20 +
    1.21 +extern "C" {
    1.22 +
    1.23 +static gboolean
    1.24 +addSelectionCB(AtkSelection *aSelection, gint i)
    1.25 +{
    1.26 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    1.27 +  if (!accWrap || !accWrap->IsSelect())
    1.28 +    return FALSE;
    1.29 +
    1.30 +  return accWrap->AddItemToSelection(i);
    1.31 +}
    1.32 +
    1.33 +static gboolean
    1.34 +clearSelectionCB(AtkSelection *aSelection)
    1.35 +{
    1.36 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    1.37 +  if (!accWrap || !accWrap->IsSelect())
    1.38 +    return FALSE;
    1.39 +
    1.40 +  return accWrap->UnselectAll();
    1.41 +}
    1.42 +
    1.43 +static AtkObject*
    1.44 +refSelectionCB(AtkSelection *aSelection, gint i)
    1.45 +{
    1.46 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    1.47 +  if (!accWrap || !accWrap->IsSelect())
    1.48 +    return nullptr;
    1.49 +
    1.50 +  Accessible* selectedItem = accWrap->GetSelectedItem(i);
    1.51 +  if (!selectedItem)
    1.52 +    return nullptr;
    1.53 +
    1.54 +  AtkObject* atkObj = AccessibleWrap::GetAtkObject(selectedItem);
    1.55 +  if (atkObj)
    1.56 +    g_object_ref(atkObj);
    1.57 +
    1.58 +  return atkObj;
    1.59 +}
    1.60 +
    1.61 +static gint
    1.62 +getSelectionCountCB(AtkSelection *aSelection)
    1.63 +{
    1.64 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    1.65 +  if (!accWrap || !accWrap->IsSelect())
    1.66 +    return -1;
    1.67 +
    1.68 +  return accWrap->SelectedItemCount();
    1.69 +}
    1.70 +
    1.71 +static gboolean
    1.72 +isChildSelectedCB(AtkSelection *aSelection, gint i)
    1.73 +{
    1.74 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    1.75 +  if (!accWrap || !accWrap->IsSelect())
    1.76 +    return FALSE;
    1.77 +
    1.78 +  return accWrap->IsItemSelected(i);
    1.79 +}
    1.80 +
    1.81 +static gboolean
    1.82 +removeSelectionCB(AtkSelection *aSelection, gint i)
    1.83 +{
    1.84 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    1.85 +  if (!accWrap || !accWrap->IsSelect())
    1.86 +    return FALSE;
    1.87 +
    1.88 +  return accWrap->RemoveItemFromSelection(i);
    1.89 +}
    1.90 +
    1.91 +static gboolean
    1.92 +selectAllSelectionCB(AtkSelection *aSelection)
    1.93 +{
    1.94 +  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aSelection));
    1.95 +  if (!accWrap || !accWrap->IsSelect())
    1.96 +    return FALSE;
    1.97 +
    1.98 +  return accWrap->SelectAll();
    1.99 +}
   1.100 +}
   1.101 +
   1.102 +void
   1.103 +selectionInterfaceInitCB(AtkSelectionIface* aIface)
   1.104 +{
   1.105 +  NS_ASSERTION(aIface, "Invalid aIface");
   1.106 +  if (MOZ_UNLIKELY(!aIface))
   1.107 +    return;
   1.108 +
   1.109 +  aIface->add_selection = addSelectionCB;
   1.110 +  aIface->clear_selection = clearSelectionCB;
   1.111 +  aIface->ref_selection = refSelectionCB;
   1.112 +  aIface->get_selection_count = getSelectionCountCB;
   1.113 +  aIface->is_child_selected = isChildSelectedCB;
   1.114 +  aIface->remove_selection = removeSelectionCB;
   1.115 +  aIface->select_all_selection = selectAllSelectionCB;
   1.116 +}

mercurial