michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsAccessibleRelation.h" michael@0: michael@0: #include "Relation.h" michael@0: #include "Accessible.h" michael@0: michael@0: #include "nsArrayUtils.h" michael@0: #include "nsComponentManagerUtils.h" michael@0: michael@0: using namespace mozilla::a11y; michael@0: michael@0: nsAccessibleRelation::nsAccessibleRelation(uint32_t aType, michael@0: Relation* aRel) : michael@0: mType(aType) michael@0: { michael@0: mTargets = do_CreateInstance(NS_ARRAY_CONTRACTID); michael@0: nsIAccessible* targetAcc = nullptr; michael@0: while ((targetAcc = aRel->Next())) michael@0: mTargets->AppendElement(targetAcc, false); michael@0: } michael@0: michael@0: // nsISupports michael@0: NS_IMPL_ISUPPORTS(nsAccessibleRelation, nsIAccessibleRelation) michael@0: michael@0: // nsIAccessibleRelation michael@0: NS_IMETHODIMP michael@0: nsAccessibleRelation::GetRelationType(uint32_t *aType) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aType); michael@0: *aType = mType; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAccessibleRelation::GetTargetsCount(uint32_t *aCount) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aCount); michael@0: *aCount = 0; michael@0: return mTargets->GetLength(aCount); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAccessibleRelation::GetTarget(uint32_t aIndex, nsIAccessible **aTarget) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aTarget); michael@0: nsresult rv = NS_OK; michael@0: nsCOMPtr target = do_QueryElementAt(mTargets, aIndex, &rv); michael@0: target.forget(aTarget); michael@0: return rv; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsAccessibleRelation::GetTargets(nsIArray **aTargets) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aTargets); michael@0: NS_ADDREF(*aTargets = mTargets); michael@0: return NS_OK; michael@0: }