accessible/src/xpcom/nsAccessibleRelation.cpp

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:be2b640938f5
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 "Accessible.h"
10
11 #include "nsArrayUtils.h"
12 #include "nsComponentManagerUtils.h"
13
14 using namespace mozilla::a11y;
15
16 nsAccessibleRelation::nsAccessibleRelation(uint32_t aType,
17 Relation* aRel) :
18 mType(aType)
19 {
20 mTargets = do_CreateInstance(NS_ARRAY_CONTRACTID);
21 nsIAccessible* targetAcc = nullptr;
22 while ((targetAcc = aRel->Next()))
23 mTargets->AppendElement(targetAcc, false);
24 }
25
26 // nsISupports
27 NS_IMPL_ISUPPORTS(nsAccessibleRelation, nsIAccessibleRelation)
28
29 // nsIAccessibleRelation
30 NS_IMETHODIMP
31 nsAccessibleRelation::GetRelationType(uint32_t *aType)
32 {
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 {
41 NS_ENSURE_ARG_POINTER(aCount);
42 *aCount = 0;
43 return mTargets->GetLength(aCount);
44 }
45
46 NS_IMETHODIMP
47 nsAccessibleRelation::GetTarget(uint32_t aIndex, nsIAccessible **aTarget)
48 {
49 NS_ENSURE_ARG_POINTER(aTarget);
50 nsresult rv = NS_OK;
51 nsCOMPtr<nsIAccessible> target = do_QueryElementAt(mTargets, aIndex, &rv);
52 target.forget(aTarget);
53 return rv;
54 }
55
56 NS_IMETHODIMP
57 nsAccessibleRelation::GetTargets(nsIArray **aTargets)
58 {
59 NS_ENSURE_ARG_POINTER(aTargets);
60 NS_ADDREF(*aTargets = mTargets);
61 return NS_OK;
62 }

mercurial