accessible/src/windows/ia2/ia2AccessibleRelation.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial