accessible/src/xpcom/xpcAccessibleSelectable.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/xpcom/xpcAccessibleSelectable.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,134 @@
     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 file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "xpcAccessibleSelectable.h"
    1.11 +
    1.12 +#include "Accessible-inl.h"
    1.13 +
    1.14 +using namespace mozilla::a11y;
    1.15 +
    1.16 +NS_IMETHODIMP
    1.17 +xpcAccessibleSelectable::GetSelectedItems(nsIArray** aSelectedItems)
    1.18 +{
    1.19 +  NS_ENSURE_ARG_POINTER(aSelectedItems);
    1.20 +  *aSelectedItems = nullptr;
    1.21 +
    1.22 +  Accessible* acc = static_cast<Accessible*>(this);
    1.23 +  if (acc->IsDefunct())
    1.24 +    return NS_ERROR_FAILURE;
    1.25 +  NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!");
    1.26 +
    1.27 +  nsCOMPtr<nsIArray> items = acc->SelectedItems();
    1.28 +  if (items) {
    1.29 +    uint32_t length = 0;
    1.30 +    items->GetLength(&length);
    1.31 +    if (length)
    1.32 +      items.swap(*aSelectedItems);
    1.33 +  }
    1.34 +
    1.35 +  return NS_OK;
    1.36 +}
    1.37 +
    1.38 +NS_IMETHODIMP
    1.39 +xpcAccessibleSelectable::GetSelectedItemCount(uint32_t* aSelectionCount)
    1.40 +{
    1.41 +  NS_ENSURE_ARG_POINTER(aSelectionCount);
    1.42 +  *aSelectionCount = 0;
    1.43 +
    1.44 +  Accessible* acc = static_cast<Accessible*>(this);
    1.45 +  if (acc->IsDefunct())
    1.46 +    return NS_ERROR_FAILURE;
    1.47 +  NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!");
    1.48 +
    1.49 +  *aSelectionCount = acc->SelectedItemCount();
    1.50 +  return NS_OK;
    1.51 +}
    1.52 +
    1.53 +NS_IMETHODIMP
    1.54 +xpcAccessibleSelectable::GetSelectedItemAt(uint32_t aIndex,
    1.55 +                                           nsIAccessible** aSelected)
    1.56 +{
    1.57 +  NS_ENSURE_ARG_POINTER(aSelected);
    1.58 +  *aSelected = nullptr;
    1.59 +
    1.60 +  Accessible* acc = static_cast<Accessible*>(this);
    1.61 +  if (acc->IsDefunct())
    1.62 +    return NS_ERROR_FAILURE;
    1.63 +  NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!");
    1.64 +
    1.65 +  *aSelected = acc->GetSelectedItem(aIndex);
    1.66 +  if (*aSelected) {
    1.67 +    NS_ADDREF(*aSelected);
    1.68 +    return NS_OK;
    1.69 +  }
    1.70 +
    1.71 +  return NS_ERROR_INVALID_ARG;
    1.72 +}
    1.73 +
    1.74 +NS_IMETHODIMP
    1.75 +xpcAccessibleSelectable::ScriptableIsItemSelected(uint32_t aIndex,
    1.76 +                                                  bool* aIsSelected)
    1.77 +{
    1.78 +  NS_ENSURE_ARG_POINTER(aIsSelected);
    1.79 +  *aIsSelected = false;
    1.80 +
    1.81 +  Accessible* acc = static_cast<Accessible*>(this);
    1.82 +  if (acc->IsDefunct())
    1.83 +    return NS_ERROR_FAILURE;
    1.84 +  NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!");
    1.85 +
    1.86 +  *aIsSelected = acc->IsItemSelected(aIndex);
    1.87 +  return NS_OK;
    1.88 +}
    1.89 +
    1.90 +NS_IMETHODIMP
    1.91 +xpcAccessibleSelectable::ScriptableAddItemToSelection(uint32_t aIndex)
    1.92 +{
    1.93 +  Accessible* acc = static_cast<Accessible*>(this);
    1.94 +  if (acc->IsDefunct())
    1.95 +    return NS_ERROR_FAILURE;
    1.96 +  NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!");
    1.97 +
    1.98 +  return acc->AddItemToSelection(aIndex) ? NS_OK : NS_ERROR_INVALID_ARG;
    1.99 +}
   1.100 +
   1.101 +NS_IMETHODIMP
   1.102 +xpcAccessibleSelectable::ScriptableRemoveItemFromSelection(uint32_t aIndex)
   1.103 +{
   1.104 +  Accessible* acc = static_cast<Accessible*>(this);
   1.105 +  if (acc->IsDefunct())
   1.106 +    return NS_ERROR_FAILURE;
   1.107 +  NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!");
   1.108 +
   1.109 +  return acc->RemoveItemFromSelection(aIndex) ? NS_OK : NS_ERROR_INVALID_ARG;
   1.110 +}
   1.111 +
   1.112 +NS_IMETHODIMP
   1.113 +xpcAccessibleSelectable::ScriptableSelectAll(bool* aIsMultiSelect)
   1.114 +{
   1.115 +  NS_ENSURE_ARG_POINTER(aIsMultiSelect);
   1.116 +  *aIsMultiSelect = false;
   1.117 +
   1.118 +  Accessible* acc = static_cast<Accessible*>(this);
   1.119 +  if (acc->IsDefunct())
   1.120 +    return NS_ERROR_FAILURE;
   1.121 +  NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!");
   1.122 +
   1.123 +  *aIsMultiSelect = acc->SelectAll();
   1.124 +  return NS_OK;
   1.125 +}
   1.126 +
   1.127 +NS_IMETHODIMP
   1.128 +xpcAccessibleSelectable::ScriptableUnselectAll()
   1.129 +{
   1.130 +  Accessible* acc = static_cast<Accessible*>(this);
   1.131 +  if (acc->IsDefunct())
   1.132 +    return NS_ERROR_FAILURE;
   1.133 +  NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!");
   1.134 +
   1.135 +  acc->UnselectAll();
   1.136 +  return NS_OK;
   1.137 +}

mercurial