1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
4 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is mozilla.org code.
19 * The Initial Developer of the Original Code is
21 * Portions created by the Initial Developer are Copyright (C) 2007
22 * the Initial Developer. All Rights Reserved.
25 * Alexander Surkov <surkov.alexander@gmail.com> (original author)
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #include "nsAccessibleRelationWrap.h"
43 #include "AccessibleRelation_i.c"
44 #include "nsAccessNodeWrap.h"
46 #include "nsArrayUtils.h"
48 nsAccessibleRelationWrap::
49 nsAccessibleRelationWrap(PRUint32 aType
, nsIAccessible
*aTarget
) :
50 nsAccessibleRelation(aType
, aTarget
)
56 NS_IMPL_ISUPPORTS_INHERITED1(nsAccessibleRelationWrap
, nsAccessibleRelation
,
62 nsAccessibleRelationWrap::QueryNativeInterface(REFIID aIID
, void** aInstancePtr
)
64 return QueryInterface(aIID
, aInstancePtr
);
70 nsAccessibleRelationWrap::QueryInterface(REFIID iid
, void** ppv
)
74 if (IID_IAccessibleRelation
== iid
|| IID_IUnknown
== iid
) {
75 *ppv
= static_cast<IAccessibleRelation
*>(this);
76 (reinterpret_cast<IUnknown
*>(*ppv
))->AddRef();
83 // IAccessibleRelation
86 nsAccessibleRelationWrap::get_relationType(BSTR
*aRelationType
)
89 *aRelationType
= NULL
;
92 nsresult rv
= GetRelationType(&type
);
94 return GetHRESULT(rv
);
97 case RELATION_CONTROLLED_BY
:
98 *aRelationType
= ::SysAllocString(IA2_RELATION_CONTROLLED_BY
);
100 case RELATION_CONTROLLER_FOR
:
101 *aRelationType
= ::SysAllocString(IA2_RELATION_CONTROLLER_FOR
);
103 case RELATION_DESCRIBED_BY
:
104 *aRelationType
= ::SysAllocString(IA2_RELATION_DESCRIBED_BY
);
106 case RELATION_DESCRIPTION_FOR
:
107 *aRelationType
= ::SysAllocString(IA2_RELATION_DESCRIPTION_FOR
);
109 case RELATION_EMBEDDED_BY
:
110 *aRelationType
= ::SysAllocString(IA2_RELATION_EMBEDDED_BY
);
112 case RELATION_EMBEDS
:
113 *aRelationType
= ::SysAllocString(IA2_RELATION_EMBEDS
);
115 case RELATION_FLOWS_FROM
:
116 *aRelationType
= ::SysAllocString(IA2_RELATION_FLOWS_FROM
);
118 case RELATION_FLOWS_TO
:
119 *aRelationType
= ::SysAllocString(IA2_RELATION_FLOWS_TO
);
121 case RELATION_LABEL_FOR
:
122 *aRelationType
= ::SysAllocString(IA2_RELATION_LABEL_FOR
);
124 case RELATION_LABELLED_BY
:
125 *aRelationType
= ::SysAllocString(IA2_RELATION_LABELED_BY
);
127 case RELATION_MEMBER_OF
:
128 *aRelationType
= ::SysAllocString(IA2_RELATION_MEMBER_OF
);
130 case RELATION_NODE_CHILD_OF
:
131 *aRelationType
= ::SysAllocString(IA2_RELATION_NODE_CHILD_OF
);
133 case RELATION_PARENT_WINDOW_OF
:
134 *aRelationType
= ::SysAllocString(IA2_RELATION_PARENT_WINDOW_OF
);
136 case RELATION_POPUP_FOR
:
137 *aRelationType
= ::SysAllocString(IA2_RELATION_POPUP_FOR
);
139 case RELATION_SUBWINDOW_OF
:
140 *aRelationType
= ::SysAllocString(IA2_RELATION_SUBWINDOW_OF
);
146 return *aRelationType
? S_OK
: E_OUTOFMEMORY
;
148 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
153 nsAccessibleRelationWrap::get_localizedRelationType(BSTR
*aLocalizedRelationType
)
156 *aLocalizedRelationType
= NULL
;
158 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
163 nsAccessibleRelationWrap::get_nTargets(long *aNTargets
)
169 nsresult rv
= GetTargetsCount(&count
);
171 return GetHRESULT(rv
);
176 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
181 nsAccessibleRelationWrap::get_target(long aTargetIndex
, IUnknown
**aTarget
)
184 nsCOMPtr
<nsIAccessible
> accessible
;
185 nsresult rv
= GetTarget(aTargetIndex
, getter_AddRefs(accessible
));
187 return GetHRESULT(rv
);
189 nsCOMPtr
<nsIWinAccessNode
> winAccessNode(do_QueryInterface(accessible
));
193 void *instancePtr
= NULL
;
194 rv
= winAccessNode
->QueryNativeInterface(IID_IUnknown
, &instancePtr
);
196 return GetHRESULT(rv
);
198 *aTarget
= static_cast<IUnknown
*>(instancePtr
);
201 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
206 nsAccessibleRelationWrap::get_targets(long aMaxTargets
, IUnknown
**aTarget
,
212 nsCOMPtr
<nsIArray
> targets
;
213 nsresult rv
= GetTargets(getter_AddRefs(targets
));
215 return GetHRESULT(rv
);
218 rv
= targets
->GetLength(&length
);
220 return GetHRESULT(rv
);
225 PRUint32 count
= length
< PRUint32(aMaxTargets
) ? length
: aMaxTargets
;
228 for (; index
< count
; index
++) {
229 nsCOMPtr
<nsIWinAccessNode
> winAccessNode
=
230 do_QueryElementAt(targets
, index
, &rv
);
234 void *instancePtr
= NULL
;
235 nsresult rv
= winAccessNode
->QueryNativeInterface(IID_IUnknown
,
240 aTarget
[index
] = static_cast<IUnknown
*>(instancePtr
);
244 for (PRUint32 index2
= 0; index2
< index
; index2
++) {
245 aTarget
[index2
]->Release();
246 aTarget
[index2
] = NULL
;
248 return GetHRESULT(rv
);
254 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }