Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "xpcAccessibleSelectable.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "Accessible-inl.h" |
michael@0 | 10 | |
michael@0 | 11 | using namespace mozilla::a11y; |
michael@0 | 12 | |
michael@0 | 13 | NS_IMETHODIMP |
michael@0 | 14 | xpcAccessibleSelectable::GetSelectedItems(nsIArray** aSelectedItems) |
michael@0 | 15 | { |
michael@0 | 16 | NS_ENSURE_ARG_POINTER(aSelectedItems); |
michael@0 | 17 | *aSelectedItems = nullptr; |
michael@0 | 18 | |
michael@0 | 19 | Accessible* acc = static_cast<Accessible*>(this); |
michael@0 | 20 | if (acc->IsDefunct()) |
michael@0 | 21 | return NS_ERROR_FAILURE; |
michael@0 | 22 | NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
michael@0 | 23 | |
michael@0 | 24 | nsCOMPtr<nsIArray> items = acc->SelectedItems(); |
michael@0 | 25 | if (items) { |
michael@0 | 26 | uint32_t length = 0; |
michael@0 | 27 | items->GetLength(&length); |
michael@0 | 28 | if (length) |
michael@0 | 29 | items.swap(*aSelectedItems); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | return NS_OK; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | NS_IMETHODIMP |
michael@0 | 36 | xpcAccessibleSelectable::GetSelectedItemCount(uint32_t* aSelectionCount) |
michael@0 | 37 | { |
michael@0 | 38 | NS_ENSURE_ARG_POINTER(aSelectionCount); |
michael@0 | 39 | *aSelectionCount = 0; |
michael@0 | 40 | |
michael@0 | 41 | Accessible* acc = static_cast<Accessible*>(this); |
michael@0 | 42 | if (acc->IsDefunct()) |
michael@0 | 43 | return NS_ERROR_FAILURE; |
michael@0 | 44 | NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
michael@0 | 45 | |
michael@0 | 46 | *aSelectionCount = acc->SelectedItemCount(); |
michael@0 | 47 | return NS_OK; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | NS_IMETHODIMP |
michael@0 | 51 | xpcAccessibleSelectable::GetSelectedItemAt(uint32_t aIndex, |
michael@0 | 52 | nsIAccessible** aSelected) |
michael@0 | 53 | { |
michael@0 | 54 | NS_ENSURE_ARG_POINTER(aSelected); |
michael@0 | 55 | *aSelected = nullptr; |
michael@0 | 56 | |
michael@0 | 57 | Accessible* acc = static_cast<Accessible*>(this); |
michael@0 | 58 | if (acc->IsDefunct()) |
michael@0 | 59 | return NS_ERROR_FAILURE; |
michael@0 | 60 | NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
michael@0 | 61 | |
michael@0 | 62 | *aSelected = acc->GetSelectedItem(aIndex); |
michael@0 | 63 | if (*aSelected) { |
michael@0 | 64 | NS_ADDREF(*aSelected); |
michael@0 | 65 | return NS_OK; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | return NS_ERROR_INVALID_ARG; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | NS_IMETHODIMP |
michael@0 | 72 | xpcAccessibleSelectable::ScriptableIsItemSelected(uint32_t aIndex, |
michael@0 | 73 | bool* aIsSelected) |
michael@0 | 74 | { |
michael@0 | 75 | NS_ENSURE_ARG_POINTER(aIsSelected); |
michael@0 | 76 | *aIsSelected = false; |
michael@0 | 77 | |
michael@0 | 78 | Accessible* acc = static_cast<Accessible*>(this); |
michael@0 | 79 | if (acc->IsDefunct()) |
michael@0 | 80 | return NS_ERROR_FAILURE; |
michael@0 | 81 | NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
michael@0 | 82 | |
michael@0 | 83 | *aIsSelected = acc->IsItemSelected(aIndex); |
michael@0 | 84 | return NS_OK; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | NS_IMETHODIMP |
michael@0 | 88 | xpcAccessibleSelectable::ScriptableAddItemToSelection(uint32_t aIndex) |
michael@0 | 89 | { |
michael@0 | 90 | Accessible* acc = static_cast<Accessible*>(this); |
michael@0 | 91 | if (acc->IsDefunct()) |
michael@0 | 92 | return NS_ERROR_FAILURE; |
michael@0 | 93 | NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
michael@0 | 94 | |
michael@0 | 95 | return acc->AddItemToSelection(aIndex) ? NS_OK : NS_ERROR_INVALID_ARG; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | NS_IMETHODIMP |
michael@0 | 99 | xpcAccessibleSelectable::ScriptableRemoveItemFromSelection(uint32_t aIndex) |
michael@0 | 100 | { |
michael@0 | 101 | Accessible* acc = static_cast<Accessible*>(this); |
michael@0 | 102 | if (acc->IsDefunct()) |
michael@0 | 103 | return NS_ERROR_FAILURE; |
michael@0 | 104 | NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
michael@0 | 105 | |
michael@0 | 106 | return acc->RemoveItemFromSelection(aIndex) ? NS_OK : NS_ERROR_INVALID_ARG; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | NS_IMETHODIMP |
michael@0 | 110 | xpcAccessibleSelectable::ScriptableSelectAll(bool* aIsMultiSelect) |
michael@0 | 111 | { |
michael@0 | 112 | NS_ENSURE_ARG_POINTER(aIsMultiSelect); |
michael@0 | 113 | *aIsMultiSelect = false; |
michael@0 | 114 | |
michael@0 | 115 | Accessible* acc = static_cast<Accessible*>(this); |
michael@0 | 116 | if (acc->IsDefunct()) |
michael@0 | 117 | return NS_ERROR_FAILURE; |
michael@0 | 118 | NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
michael@0 | 119 | |
michael@0 | 120 | *aIsMultiSelect = acc->SelectAll(); |
michael@0 | 121 | return NS_OK; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | NS_IMETHODIMP |
michael@0 | 125 | xpcAccessibleSelectable::ScriptableUnselectAll() |
michael@0 | 126 | { |
michael@0 | 127 | Accessible* acc = static_cast<Accessible*>(this); |
michael@0 | 128 | if (acc->IsDefunct()) |
michael@0 | 129 | return NS_ERROR_FAILURE; |
michael@0 | 130 | NS_PRECONDITION(acc->IsSelect(), "Called on non selectable widget!"); |
michael@0 | 131 | |
michael@0 | 132 | acc->UnselectAll(); |
michael@0 | 133 | return NS_OK; |
michael@0 | 134 | } |