accessible/src/xpcom/nsAccessibleRelation.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/xpcom/nsAccessibleRelation.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsAccessibleRelation.h"
    1.10 +
    1.11 +#include "Relation.h"
    1.12 +#include "Accessible.h"
    1.13 +
    1.14 +#include "nsArrayUtils.h"
    1.15 +#include "nsComponentManagerUtils.h"
    1.16 +
    1.17 +using namespace mozilla::a11y;
    1.18 +
    1.19 +nsAccessibleRelation::nsAccessibleRelation(uint32_t aType,
    1.20 +                                           Relation* aRel) :
    1.21 +  mType(aType)
    1.22 +{
    1.23 +  mTargets = do_CreateInstance(NS_ARRAY_CONTRACTID);
    1.24 +  nsIAccessible* targetAcc = nullptr;
    1.25 +  while ((targetAcc = aRel->Next()))
    1.26 +    mTargets->AppendElement(targetAcc, false);
    1.27 +}
    1.28 +
    1.29 +// nsISupports
    1.30 +NS_IMPL_ISUPPORTS(nsAccessibleRelation, nsIAccessibleRelation)
    1.31 +
    1.32 +// nsIAccessibleRelation
    1.33 +NS_IMETHODIMP
    1.34 +nsAccessibleRelation::GetRelationType(uint32_t *aType)
    1.35 +{
    1.36 +  NS_ENSURE_ARG_POINTER(aType);
    1.37 +  *aType = mType;
    1.38 +  return NS_OK;
    1.39 +}
    1.40 +
    1.41 +NS_IMETHODIMP
    1.42 +nsAccessibleRelation::GetTargetsCount(uint32_t *aCount)
    1.43 +{
    1.44 +  NS_ENSURE_ARG_POINTER(aCount);
    1.45 +  *aCount = 0;
    1.46 +  return mTargets->GetLength(aCount);
    1.47 +}
    1.48 +
    1.49 +NS_IMETHODIMP
    1.50 +nsAccessibleRelation::GetTarget(uint32_t aIndex, nsIAccessible **aTarget)
    1.51 +{
    1.52 +  NS_ENSURE_ARG_POINTER(aTarget);
    1.53 +  nsresult rv = NS_OK;
    1.54 +  nsCOMPtr<nsIAccessible> target = do_QueryElementAt(mTargets, aIndex, &rv);
    1.55 +  target.forget(aTarget);
    1.56 +  return rv;
    1.57 +}
    1.58 +
    1.59 +NS_IMETHODIMP
    1.60 +nsAccessibleRelation::GetTargets(nsIArray **aTargets)
    1.61 +{
    1.62 +  NS_ENSURE_ARG_POINTER(aTargets);
    1.63 +  NS_ADDREF(*aTargets = mTargets);
    1.64 +  return NS_OK;
    1.65 +}

mercurial