Bug 381312 - implement IAccessibleRelation, r=aaronlev, sr=neil

This commit is contained in:
surkov.alexander@gmail.com 2007-05-24 06:26:54 -07:00
parent 76bae7baad
commit 472eb065f9
12 changed files with 535 additions and 11 deletions

View File

@ -99,6 +99,7 @@ EXPORTS = \
nsHyperTextAccessibleWrap.h \
nsHTMLImageAccessibleWrap.h \
nsHTMLTableAccessibleWrap.h \
nsAccessibleRelationWrap.h \
$(NULL)
# we want to force the creation of a static lib.

View File

@ -0,0 +1,49 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:expandtab:shiftwidth=2:tabstop=2:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Alexander Surkov <surkov.alexander@gmail.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _NS_ACCESSIBLE_RELATION_WRAP_H
#define _NS_ACCESSIBLE_RELATION_WRAP_H
#include "nsAccessibleRelation.h"
typedef class nsAccessibleRelation nsAccessibleRelationWrap;
#endif

View File

@ -2893,7 +2893,7 @@ nsAccessible::GetRelations(nsIArray **aRelations)
if (accessible) {
nsCOMPtr<nsIAccessibleRelation> relation =
new nsAccessibleRelation(relType, accessible);
new nsAccessibleRelationWrap(relType, accessible);
NS_ENSURE_TRUE(relation, NS_ERROR_OUT_OF_MEMORY);
relations->AppendElement(relation, PR_FALSE);

View File

@ -49,7 +49,7 @@
#include "nsIAccessibleValue.h"
#include "nsIAccessibleRole.h"
#include "nsIAccessibleStates.h"
#include "nsIAccessibleRelation.h"
#include "nsAccessibleRelationWrap.h"
#include "nsIDOMNodeList.h"
#include "nsINameSpaceManager.h"

View File

@ -84,6 +84,7 @@ EXPORTS = \
nsHyperTextAccessibleWrap.h \
nsHTMLImageAccessibleWrap.h \
nsHTMLTableAccessibleWrap.h \
nsAccessibleRelationWrap.h \
mozDocAccessible.h \
mozAccessible.h \
mozAccessibleWrapper.h \

View File

@ -0,0 +1,49 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:expandtab:shiftwidth=2:tabstop=2:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Alexander Surkov <surkov.alexander@gmail.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _NS_ACCESSIBLE_RELATION_WRAP_H
#define _NS_ACCESSIBLE_RELATION_WRAP_H
#include "nsAccessibleRelation.h"
typedef class nsAccessibleRelation nsAccessibleRelationWrap;
#endif

View File

@ -78,6 +78,7 @@ CPPSRCS = \
nsHyperTextAccessibleWrap.cpp \
nsHTMLImageAccessibleWrap.cpp \
nsHTMLTableAccessibleWrap.cpp \
nsAccessibleRelationWrap.cpp \
CAccessibleAction.cpp \
CAccessibleImage.cpp \
CAccessibleComponent.cpp \
@ -101,6 +102,7 @@ EXPORTS = \
nsHyperTextAccessibleWrap.h \
nsHTMLImageAccessibleWrap.h \
nsHTMLTableAccessibleWrap.h \
nsAccessibleRelationWrap.h \
CAccessibleAction.h \
CAccessibleImage.h \
CAccessibleComponent.h \

View File

@ -0,0 +1,226 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:expandtab:shiftwidth=2:tabstop=2:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Alexander Surkov <surkov.alexander@gmail.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsAccessibleRelationWrap.h"
#include "AccessibleRelation_i.c"
#include "nsArrayUtils.h"
nsAccessibleRelationWrap::
nsAccessibleRelationWrap(PRUint32 aType, nsIAccessible *aTarget) :
nsAccessibleRelation(aType, aTarget)
{
}
// ISupports
NS_IMPL_ISUPPORTS_INHERITED1(nsAccessibleRelationWrap, nsAccessibleRelation,
nsIWinAccessNode)
// nsIWinAccessNode
NS_IMETHODIMP
nsAccessibleRelationWrap::QueryNativeInterface(REFIID aIID, void** aInstancePtr)
{
return QueryInterface(aIID, aInstancePtr);
}
// IUnknown
STDMETHODIMP
nsAccessibleRelationWrap::QueryInterface(REFIID iid, void** ppv)
{
*ppv = NULL;
if (IID_IAccessibleRelation == iid || IID_IUnknown == iid) {
*ppv = NS_STATIC_CAST(IAccessibleRelation*, this);
(NS_REINTERPRET_CAST(IUnknown*, *ppv))->AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
// IAccessibleRelation
STDMETHODIMP
nsAccessibleRelationWrap::get_relationType(BSTR *aRelationType)
{
*aRelationType = NULL;
PRUint32 type = 0;
nsresult rv = GetRelationType(&type);
if (NS_FAILED(rv))
return E_FAIL;
switch (type) {
case RELATION_CONTROLLED_BY:
*aRelationType = ::SysAllocString(IA2_RELATION_CONTROLLED_BY);
break;
case RELATION_CONTROLLER_FOR:
*aRelationType = ::SysAllocString(IA2_RELATION_CONTROLLER_FOR);
break;
case RELATION_DESCRIBED_BY:
*aRelationType = ::SysAllocString(IA2_RELATION_DESCRIBED_BY);
break;
case RELATION_DESCRIPTION_FOR:
*aRelationType = ::SysAllocString(IA2_RELATION_DESCRIPTION_FOR);
break;
case RELATION_EMBEDDED_BY:
*aRelationType = ::SysAllocString(IA2_RELATION_EMBEDDED_BY);
break;
case RELATION_EMBEDS:
*aRelationType = ::SysAllocString(IA2_RELATION_EMBEDS);
break;
case RELATION_FLOWS_FROM:
*aRelationType = ::SysAllocString(IA2_RELATION_FLOWS_FROM);
break;
case RELATION_FLOWS_TO:
*aRelationType = ::SysAllocString(IA2_RELATION_FLOWS_TO);
break;
case RELATION_LABEL_FOR:
*aRelationType = ::SysAllocString(IA2_RELATION_LABEL_FOR);
break;
case RELATION_LABELLED_BY:
*aRelationType = ::SysAllocString(IA2_RELATION_LABELED_BY);
break;
case RELATION_MEMBER_OF:
*aRelationType = ::SysAllocString(IA2_RELATION_MEMBER_OF);
break;
case RELATION_NODE_CHILD_OF:
*aRelationType = ::SysAllocString(IA2_RELATION_NODE_CHILD_OF);
break;
case RELATION_PARENT_WINDOW_OF:
*aRelationType = ::SysAllocString(IA2_RELATION_PARENT_WINDOW_OF);
break;
case RELATION_POPUP_FOR:
*aRelationType = ::SysAllocString(IA2_RELATION_POPUP_FOR);
break;
case RELATION_SUBWINDOW_OF:
*aRelationType = ::SysAllocString(IA2_RELATION_SUBWINDOW_OF);
break;
default:
return E_FAIL;
}
return !aRelationType ? E_OUTOFMEMORY : S_OK;
}
STDMETHODIMP
nsAccessibleRelationWrap::get_localizedRelationType(BSTR *aLocalizedRelationType)
{
return E_NOTIMPL;
}
STDMETHODIMP
nsAccessibleRelationWrap::get_nTargets(long *aNTargets)
{
PRUint32 count = 0;
nsresult rv = GetTargetsCount(&count);
*aNTargets = count;
return NS_FAILED(rv) ? E_FAIL : S_OK;
}
STDMETHODIMP
nsAccessibleRelationWrap::get_target(long aTargetIndex, IUnknown **aTarget)
{
nsCOMPtr<nsIAccessible> accessible;
nsresult rv = GetTarget(aTargetIndex, getter_AddRefs(accessible));
nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryInterface(accessible));
if (!winAccessNode)
return E_FAIL;
void *instancePtr = NULL;
rv = winAccessNode->QueryNativeInterface(IID_IUnknown, &instancePtr);
if (NS_FAILED(rv))
return E_FAIL;
*aTarget = NS_STATIC_CAST(IUnknown*, instancePtr);
return S_OK;
}
STDMETHODIMP
nsAccessibleRelationWrap::get_targets(long aMaxTargets, IUnknown **aTarget,
long *aNTargets)
{
*aNTargets = 0;
nsCOMPtr<nsIArray> targets;
nsresult rv = GetTargets(getter_AddRefs(targets));
if (NS_FAILED(rv))
return E_FAIL;
PRUint32 length = 0;
rv = targets->GetLength(&length);
if (NS_FAILED(rv))
return E_FAIL;
PRUint32 count = length < PRUint32(aMaxTargets) ? length : aMaxTargets;
PRUint32 index = 0;
for (; index < count; index++) {
nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryElementAt(targets, index, &rv));
if (NS_FAILED(rv) || !winAccessNode)
break;
void *instancePtr = NULL;
nsresult rv = winAccessNode->QueryNativeInterface(IID_IUnknown,
&instancePtr);
if (NS_FAILED(rv))
break;
aTarget[index] = NS_STATIC_CAST(IUnknown*, instancePtr);
}
if (NS_FAILED(rv)) {
for (PRUint32 index2 = 0; index2 < index; index2++) {
aTarget[index2]->Release();
aTarget[index2] = NULL;
}
return E_FAIL;
}
*aNTargets = count;
return S_OK;
}

View File

@ -0,0 +1,88 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:expandtab:shiftwidth=2:tabstop=2:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Alexander Surkov <surkov.alexander@gmail.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _NS_ACCESSIBLE_RELATION_WRAP_H
#define _NS_ACCESSIBLE_RELATION_WRAP_H
#include "nsAccessibleRelation.h"
#include "AccessibleRelation.h"
#include "nsIWinAccessNode.h"
#include "nsISupports.h"
class nsAccessibleRelationWrap: public nsAccessibleRelation,
public nsIWinAccessNode,
public IAccessibleRelation
{
public:
nsAccessibleRelationWrap(PRUint32 aType, nsIAccessible *aTarget);
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsIWinAccessNode
NS_DECL_NSIWINACCESSNODE
// IUnknown
STDMETHODIMP QueryInterface(REFIID, void**);
// IAccessibleRelation
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_relationType(
/* [retval][out] */ BSTR *relationType);
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_localizedRelationType(
/* [retval][out] */ BSTR *localizedRelationType);
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_nTargets(
/* [retval][out] */ long *nTargets);
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_target(
/* [in] */ long targetIndex,
/* [retval][out] */ IUnknown **target);
virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_targets(
/* [in] */ long maxTargets,
/* [length_is][size_is][out] */ IUnknown **target,
/* [retval][out] */ long *nTargets);
};
#endif

View File

@ -1093,24 +1093,82 @@ nsAccessibleWrap::Reset(void)
// IAccessible2
STDMETHODIMP
nsAccessibleWrap::get_nRelations(long *nRelations)
nsAccessibleWrap::get_nRelations(long *aNRelations)
{
return E_NOTIMPL;
PRUint32 count = 0;
nsresult rv = GetRelationsCount(&count);
*aNRelations = count;
return NS_FAILED(rv) ? E_FAIL : S_OK;
}
STDMETHODIMP
nsAccessibleWrap::get_relation(long relationIndex,
IAccessibleRelation **relation)
nsAccessibleWrap::get_relation(long aRelationIndex,
IAccessibleRelation **aRelation)
{
return E_NOTIMPL;
nsCOMPtr<nsIAccessibleRelation> relation;
nsresult rv = GetRelation(aRelationIndex, getter_AddRefs(relation));
if (NS_FAILED(rv))
return E_FAIL;
nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryInterface(relation));
if (!winAccessNode)
return E_FAIL;
void *instancePtr = NULL;
rv = winAccessNode->QueryNativeInterface(IID_IAccessibleRelation,
&instancePtr);
if (NS_FAILED(rv))
return E_FAIL;
*aRelation = NS_STATIC_CAST(IAccessibleRelation*, instancePtr);
return S_OK;
}
STDMETHODIMP
nsAccessibleWrap::get_relations(long maxRelations,
IAccessibleRelation **relation,
long *nRelations)
nsAccessibleWrap::get_relations(long aMaxRelations,
IAccessibleRelation **aRelation,
long *aNRelations)
{
return E_NOTIMPL;
*aNRelations = 0;
nsCOMPtr<nsIArray> relations;
nsresult rv = GetRelations(getter_AddRefs(relations));
if (NS_FAILED(rv))
return E_FAIL;
PRUint32 length = 0;
rv = relations->GetLength(&length);
if (NS_FAILED(rv))
return E_FAIL;
PRUint32 count = length < (PRUint32)aMaxRelations ? length : aMaxRelations;
PRUint32 index = 0;
for (; index < count; index++) {
nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryElementAt(relations, index, &rv));
if (NS_FAILED(rv) || !winAccessNode)
break;
void *instancePtr = NULL;
nsresult rv = winAccessNode->QueryNativeInterface(IID_IAccessibleRelation,
&instancePtr);
if (NS_FAILED(rv))
break;
aRelation[index] = NS_STATIC_CAST(IAccessibleRelation*, instancePtr);
}
if (NS_FAILED(rv)) {
for (PRUint32 index2 = 0; index2 < index; index2++) {
aRelation[index2]->Release();
aRelation[index2] = NULL;
}
return E_FAIL;
}
*aNRelations = count;
return S_OK;
}
STDMETHODIMP

View File

@ -84,6 +84,7 @@ EXPORTS = \
nsHyperTextAccessibleWrap.h \
nsHTMLImageAccessibleWrap.h \
nsHTMLTableAccessibleWrap.h \
nsAccessibleRelationWrap.h \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.

View File

@ -0,0 +1,49 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:expandtab:shiftwidth=2:tabstop=2:
*/
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Alexander Surkov <surkov.alexander@gmail.com> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _NS_ACCESSIBLE_RELATION_WRAP_H
#define _NS_ACCESSIBLE_RELATION_WRAP_H
#include "nsAccessibleRelation.h"
typedef class nsAccessibleRelation nsAccessibleRelationWrap;
#endif