accessible/src/windows/ia2/ia2AccessibleRelation.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/windows/ia2/ia2AccessibleRelation.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:expandtab:shiftwidth=2:tabstop=2:
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#include "ia2AccessibleRelation.h"
    1.12 +
    1.13 +#include "Relation.h"
    1.14 +#include "nsIAccessibleRelation.h"
    1.15 +#include "nsID.h"
    1.16 +
    1.17 +#include "AccessibleRelation_i.c"
    1.18 +
    1.19 +using namespace mozilla::a11y;
    1.20 +
    1.21 +ia2AccessibleRelation::ia2AccessibleRelation(RelationType aType, Relation* aRel) :
    1.22 +  mType(aType)
    1.23 +{
    1.24 +  Accessible* target = nullptr;
    1.25 +  while ((target = aRel->Next()))
    1.26 +    mTargets.AppendElement(target);
    1.27 +}
    1.28 +
    1.29 +// IUnknown
    1.30 +
    1.31 +IMPL_IUNKNOWN_QUERY_HEAD(ia2AccessibleRelation)
    1.32 +  IMPL_IUNKNOWN_QUERY_IFACE(IAccessibleRelation)
    1.33 +  IMPL_IUNKNOWN_QUERY_IFACE(IUnknown)
    1.34 +IMPL_IUNKNOWN_QUERY_TAIL
    1.35 +
    1.36 +// IAccessibleRelation
    1.37 +
    1.38 +STDMETHODIMP
    1.39 +ia2AccessibleRelation::get_relationType(BSTR* aRelationType)
    1.40 +{
    1.41 +  A11Y_TRYBLOCK_BEGIN
    1.42 +
    1.43 +  if (!aRelationType)
    1.44 +    return E_INVALIDARG;
    1.45 +
    1.46 +  *aRelationType = nullptr;
    1.47 +
    1.48 +#define RELATIONTYPE(geckoType, geckoTypeName, atkType, msaaType, ia2Type) \
    1.49 +  case RelationType::geckoType: \
    1.50 +    *aRelationType = ::SysAllocString(ia2Type); \
    1.51 +    break;
    1.52 +
    1.53 +  switch (mType) {
    1.54 +#include "RelationTypeMap.h"
    1.55 +  }
    1.56 +
    1.57 +  return *aRelationType ? S_OK : E_OUTOFMEMORY;
    1.58 +
    1.59 +  A11Y_TRYBLOCK_END
    1.60 +}
    1.61 +
    1.62 +STDMETHODIMP
    1.63 +ia2AccessibleRelation::get_localizedRelationType(BSTR *aLocalizedRelationType)
    1.64 +{
    1.65 +  A11Y_TRYBLOCK_BEGIN
    1.66 +
    1.67 +  if (!aLocalizedRelationType)
    1.68 +    return E_INVALIDARG;
    1.69 +
    1.70 +  *aLocalizedRelationType = nullptr;
    1.71 +  return E_NOTIMPL;
    1.72 +
    1.73 +  A11Y_TRYBLOCK_END
    1.74 +}
    1.75 +
    1.76 +STDMETHODIMP
    1.77 +ia2AccessibleRelation::get_nTargets(long *aNTargets)
    1.78 +{
    1.79 +  A11Y_TRYBLOCK_BEGIN
    1.80 +
    1.81 + if (!aNTargets)
    1.82 +   return E_INVALIDARG;
    1.83 +
    1.84 + *aNTargets = mTargets.Length();
    1.85 +  return S_OK;
    1.86 +
    1.87 +  A11Y_TRYBLOCK_END
    1.88 +}
    1.89 +
    1.90 +STDMETHODIMP
    1.91 +ia2AccessibleRelation::get_target(long aTargetIndex, IUnknown **aTarget)
    1.92 +{
    1.93 +  A11Y_TRYBLOCK_BEGIN
    1.94 +
    1.95 +  if (aTargetIndex < 0 || (uint32_t)aTargetIndex >= mTargets.Length() || !aTarget)
    1.96 +    return E_INVALIDARG;
    1.97 +
    1.98 +  AccessibleWrap* target =
    1.99 +    static_cast<AccessibleWrap*>(mTargets[aTargetIndex].get());
   1.100 +  *aTarget = static_cast<IAccessible*>(target);
   1.101 +  (*aTarget)->AddRef();
   1.102 +
   1.103 +  return S_OK;
   1.104 +
   1.105 +  A11Y_TRYBLOCK_END
   1.106 +}
   1.107 +
   1.108 +STDMETHODIMP
   1.109 +ia2AccessibleRelation::get_targets(long aMaxTargets, IUnknown **aTargets,
   1.110 +                                   long *aNTargets)
   1.111 +{
   1.112 +  A11Y_TRYBLOCK_BEGIN
   1.113 +
   1.114 +  if (!aNTargets || !aTargets)
   1.115 +    return E_INVALIDARG;
   1.116 +
   1.117 +  *aNTargets = 0;
   1.118 +  long maxTargets = mTargets.Length();
   1.119 +  if (maxTargets > aMaxTargets)
   1.120 +    maxTargets = aMaxTargets;
   1.121 +
   1.122 +  for (long idx = 0; idx < maxTargets; idx++)
   1.123 +    get_target(idx, aTargets + idx);
   1.124 +
   1.125 +  *aNTargets = maxTargets;
   1.126 +  return S_OK;
   1.127 +
   1.128 +  A11Y_TRYBLOCK_END
   1.129 +}

mercurial