tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ia2AccessibleRelation.cpp (2540B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:expandtab:shiftwidth=2:tabstop=2:
      3 */
      4 /* This Source Code Form is subject to the terms of the Mozilla Public
      5 * License, v. 2.0. If a copy of the MPL was not distributed with this
      6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      7 
      8 #include "ia2AccessibleRelation.h"
      9 
     10 #include "Relation.h"
     11 #include "nsID.h"
     12 
     13 #include "AccessibleRelation_i.c"
     14 
     15 using namespace mozilla::a11y;
     16 
     17 ia2AccessibleRelation::ia2AccessibleRelation(RelationType aType, Relation* aRel)
     18    : mType(aType) {
     19  Accessible* target = nullptr;
     20  while ((target = aRel->Next())) {
     21    mTargets.AppendElement(
     22        already_AddRefed(MsaaAccessible::NativeAccessible(target)));
     23  }
     24 }
     25 
     26 // IUnknown
     27 
     28 IMPL_IUNKNOWN_QUERY_HEAD(ia2AccessibleRelation)
     29 IMPL_IUNKNOWN_QUERY_IFACE(IAccessibleRelation)
     30 IMPL_IUNKNOWN_QUERY_IFACE(IUnknown)
     31 IMPL_IUNKNOWN_QUERY_TAIL
     32 
     33 // IAccessibleRelation
     34 
     35 STDMETHODIMP
     36 ia2AccessibleRelation::get_relationType(BSTR* aRelationType) {
     37  if (!aRelationType) return E_INVALIDARG;
     38 
     39  *aRelationType = nullptr;
     40 
     41 #define RELATIONTYPE(geckoType, geckoTypeName, atkType, msaaType, ia2Type) \
     42  case RelationType::geckoType:                                            \
     43    *aRelationType = ::SysAllocString(ia2Type);                            \
     44    break;
     45 
     46  switch (mType) {
     47 #include "RelationTypeMap.h"
     48  }
     49 
     50  return *aRelationType ? S_OK : E_OUTOFMEMORY;
     51 }
     52 
     53 STDMETHODIMP
     54 ia2AccessibleRelation::get_localizedRelationType(BSTR* aLocalizedRelationType) {
     55  if (!aLocalizedRelationType) return E_INVALIDARG;
     56 
     57  *aLocalizedRelationType = nullptr;
     58  return E_NOTIMPL;
     59 }
     60 
     61 STDMETHODIMP
     62 ia2AccessibleRelation::get_nTargets(long* aNTargets) {
     63  if (!aNTargets) return E_INVALIDARG;
     64 
     65  *aNTargets = mTargets.Length();
     66  return S_OK;
     67 }
     68 
     69 STDMETHODIMP
     70 ia2AccessibleRelation::get_target(long aTargetIndex, IUnknown** aTarget) {
     71  if (aTargetIndex < 0 || (uint32_t)aTargetIndex >= mTargets.Length() ||
     72      !aTarget)
     73    return E_INVALIDARG;
     74 
     75  RefPtr<IUnknown> target = mTargets[aTargetIndex];
     76  target.forget(aTarget);
     77 
     78  return S_OK;
     79 }
     80 
     81 STDMETHODIMP
     82 ia2AccessibleRelation::get_targets(long aMaxTargets, IUnknown** aTargets,
     83                                   long* aNTargets) {
     84  if (!aNTargets || !aTargets) return E_INVALIDARG;
     85 
     86  *aNTargets = 0;
     87  long maxTargets = mTargets.Length();
     88  if (maxTargets > aMaxTargets) maxTargets = aMaxTargets;
     89 
     90  for (long idx = 0; idx < maxTargets; idx++) get_target(idx, aTargets + idx);
     91 
     92  *aNTargets = maxTargets;
     93  return S_OK;
     94 }