nsAccessibleRelation.cpp (1660B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "nsAccessibleRelation.h" 7 8 #include "Relation.h" 9 #include "xpcAccessibleDocument.h" 10 11 #include "nsArrayUtils.h" 12 #include "nsComponentManagerUtils.h" 13 14 using namespace mozilla::a11y; 15 16 nsAccessibleRelation::nsAccessibleRelation(uint32_t aType, Relation* aRel) 17 : mType(aType) { 18 mTargets = do_CreateInstance(NS_ARRAY_CONTRACTID); 19 Accessible* targetAcc = nullptr; 20 while ((targetAcc = aRel->Next())) { 21 mTargets->AppendElement(static_cast<nsIAccessible*>(ToXPC(targetAcc))); 22 } 23 } 24 25 nsAccessibleRelation::~nsAccessibleRelation() {} 26 27 // nsISupports 28 NS_IMPL_ISUPPORTS(nsAccessibleRelation, nsIAccessibleRelation) 29 30 // nsIAccessibleRelation 31 NS_IMETHODIMP 32 nsAccessibleRelation::GetRelationType(uint32_t* aType) { 33 NS_ENSURE_ARG_POINTER(aType); 34 *aType = mType; 35 return NS_OK; 36 } 37 38 NS_IMETHODIMP 39 nsAccessibleRelation::GetTargetsCount(uint32_t* aCount) { 40 NS_ENSURE_ARG_POINTER(aCount); 41 *aCount = 0; 42 return mTargets->GetLength(aCount); 43 } 44 45 NS_IMETHODIMP 46 nsAccessibleRelation::GetTarget(uint32_t aIndex, nsIAccessible** aTarget) { 47 NS_ENSURE_ARG_POINTER(aTarget); 48 nsresult rv = NS_OK; 49 nsCOMPtr<nsIAccessible> target = do_QueryElementAt(mTargets, aIndex, &rv); 50 target.forget(aTarget); 51 return rv; 52 } 53 54 NS_IMETHODIMP 55 nsAccessibleRelation::GetTargets(nsIArray** aTargets) { 56 NS_ENSURE_ARG_POINTER(aTargets); 57 NS_ADDREF(*aTargets = mTargets); 58 return NS_OK; 59 }