michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:expandtab:shiftwidth=2:tabstop=2: michael@0: */ 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 "ia2AccessibleRelation.h" michael@0: michael@0: #include "Relation.h" michael@0: #include "nsIAccessibleRelation.h" michael@0: #include "nsID.h" michael@0: michael@0: #include "AccessibleRelation_i.c" michael@0: michael@0: using namespace mozilla::a11y; michael@0: michael@0: ia2AccessibleRelation::ia2AccessibleRelation(RelationType aType, Relation* aRel) : michael@0: mType(aType) michael@0: { michael@0: Accessible* target = nullptr; michael@0: while ((target = aRel->Next())) michael@0: mTargets.AppendElement(target); michael@0: } michael@0: michael@0: // IUnknown michael@0: michael@0: IMPL_IUNKNOWN_QUERY_HEAD(ia2AccessibleRelation) michael@0: IMPL_IUNKNOWN_QUERY_IFACE(IAccessibleRelation) michael@0: IMPL_IUNKNOWN_QUERY_IFACE(IUnknown) michael@0: IMPL_IUNKNOWN_QUERY_TAIL michael@0: michael@0: // IAccessibleRelation michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleRelation::get_relationType(BSTR* aRelationType) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aRelationType) michael@0: return E_INVALIDARG; michael@0: michael@0: *aRelationType = nullptr; michael@0: michael@0: #define RELATIONTYPE(geckoType, geckoTypeName, atkType, msaaType, ia2Type) \ michael@0: case RelationType::geckoType: \ michael@0: *aRelationType = ::SysAllocString(ia2Type); \ michael@0: break; michael@0: michael@0: switch (mType) { michael@0: #include "RelationTypeMap.h" michael@0: } michael@0: michael@0: return *aRelationType ? S_OK : E_OUTOFMEMORY; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleRelation::get_localizedRelationType(BSTR *aLocalizedRelationType) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aLocalizedRelationType) michael@0: return E_INVALIDARG; michael@0: michael@0: *aLocalizedRelationType = nullptr; michael@0: return E_NOTIMPL; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleRelation::get_nTargets(long *aNTargets) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aNTargets) michael@0: return E_INVALIDARG; michael@0: michael@0: *aNTargets = mTargets.Length(); michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleRelation::get_target(long aTargetIndex, IUnknown **aTarget) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (aTargetIndex < 0 || (uint32_t)aTargetIndex >= mTargets.Length() || !aTarget) michael@0: return E_INVALIDARG; michael@0: michael@0: AccessibleWrap* target = michael@0: static_cast(mTargets[aTargetIndex].get()); michael@0: *aTarget = static_cast(target); michael@0: (*aTarget)->AddRef(); michael@0: michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: } michael@0: michael@0: STDMETHODIMP michael@0: ia2AccessibleRelation::get_targets(long aMaxTargets, IUnknown **aTargets, michael@0: long *aNTargets) michael@0: { michael@0: A11Y_TRYBLOCK_BEGIN michael@0: michael@0: if (!aNTargets || !aTargets) michael@0: return E_INVALIDARG; michael@0: michael@0: *aNTargets = 0; michael@0: long maxTargets = mTargets.Length(); michael@0: if (maxTargets > aMaxTargets) michael@0: maxTargets = aMaxTargets; michael@0: michael@0: for (long idx = 0; idx < maxTargets; idx++) michael@0: get_target(idx, aTargets + idx); michael@0: michael@0: *aNTargets = maxTargets; michael@0: return S_OK; michael@0: michael@0: A11Y_TRYBLOCK_END michael@0: }