Bug 660153 - comb next/prev accessible methods, r=tbsaunde

This commit is contained in:
Alexander Surkov 2011-06-07 11:23:13 +09:00
parent a7a6e77911
commit ab9effc9a6
10 changed files with 39 additions and 82 deletions

View File

@ -313,8 +313,8 @@ AccHideEvent::
AccMutationEvent(::nsIAccessibleEvent::EVENT_HIDE, aTarget, aTargetNode)
{
mParent = mAccessible->GetParent();
mNextSibling = mAccessible->GetCachedNextSibling();
mPrevSibling = mAccessible->GetCachedPrevSibling();
mNextSibling = mAccessible->NextSibling();
mPrevSibling = mAccessible->PrevSibling();
}

View File

@ -152,7 +152,7 @@ AccGroupInfo::AccGroupInfo(nsAccessible* aItem, PRUint32 aRole) :
return;
}
nsAccessible* parentPrevSibling = parent->GetSiblingAtOffset(-1);
nsAccessible* parentPrevSibling = parent->PrevSibling();
if (!parentPrevSibling)
return;
@ -162,7 +162,7 @@ AccGroupInfo::AccGroupInfo(nsAccessible* aItem, PRUint32 aRole) :
// although the text does not appear to be rendered, GetRenderedText()
// says that it is so we need to skip past it to find the true
// previous sibling.
parentPrevSibling = parentPrevSibling->GetSiblingAtOffset(-1);
parentPrevSibling = parentPrevSibling->PrevSibling();
if (parentPrevSibling)
parentPrevSiblingRole = parentPrevSibling->Role();
}

View File

@ -450,6 +450,10 @@ NS_IMETHODIMP
nsAccessible::GetNextSibling(nsIAccessible **aNextSibling)
{
NS_ENSURE_ARG_POINTER(aNextSibling);
*aNextSibling = nsnull;
if (IsDefunct())
return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
NS_IF_ADDREF(*aNextSibling = GetSiblingAtOffset(1, &rv));
@ -461,6 +465,10 @@ NS_IMETHODIMP
nsAccessible::GetPreviousSibling(nsIAccessible * *aPreviousSibling)
{
NS_ENSURE_ARG_POINTER(aPreviousSibling);
*aPreviousSibling = nsnull;
if (IsDefunct())
return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
NS_IF_ADDREF(*aPreviousSibling = GetSiblingAtOffset(-1, &rv));
@ -3166,39 +3174,21 @@ nsAccessible::EnsureChildren()
}
nsAccessible*
nsAccessible::GetSiblingAtOffset(PRInt32 aOffset, nsresult* aError)
nsAccessible::GetSiblingAtOffset(PRInt32 aOffset, nsresult* aError) const
{
if (IsDefunct()) {
if (aError)
*aError = NS_ERROR_FAILURE;
return nsnull;
}
nsAccessible *parent = GetParent();
if (!parent) {
if (!mParent || mIndexInParent == -1) {
if (aError)
*aError = NS_ERROR_UNEXPECTED;
return nsnull;
}
if (mIndexInParent == -1) {
if (aError)
*aError = NS_ERROR_UNEXPECTED;
if (aError && mIndexInParent + aOffset >= mParent->GetChildCount()) {
*aError = NS_OK; // fail peacefully
return nsnull;
}
if (aError) {
PRInt32 childCount = parent->GetChildCount();
if (mIndexInParent + aOffset >= childCount) {
*aError = NS_OK; // fail peacefully
return nsnull;
}
}
nsAccessible* child = parent->GetChildAt(mIndexInParent + aOffset);
nsAccessible* child = mParent->GetChildAt(mIndexInParent + aOffset);
if (aError && !child)
*aError = NS_ERROR_UNEXPECTED;

View File

@ -304,6 +304,14 @@ public:
*/
PRBool HasChildren() { return !!GetChildAt(0); }
/**
* Return next/previous sibling of the accessible.
*/
inline nsAccessible* NextSibling() const
{ return GetSiblingAtOffset(1); }
inline nsAccessible* PrevSibling() const
{ return GetSiblingAtOffset(-1); }
/**
* Return embedded accessible children count.
*/
@ -319,19 +327,6 @@ public:
*/
PRInt32 GetIndexOfEmbeddedChild(nsAccessible* aChild);
/**
* Return cached accessible of parent-child relatives.
*/
nsAccessible* GetCachedNextSibling() const
{
return mParent ?
mParent->mChildren.SafeElementAt(mIndexInParent + 1, nsnull).get() : nsnull;
}
nsAccessible* GetCachedPrevSibling() const
{
return mParent ?
mParent->mChildren.SafeElementAt(mIndexInParent - 1, nsnull).get() : nsnull;
}
PRUint32 GetCachedChildCount() const { return mChildren.Length(); }
nsAccessible* GetCachedChildAt(PRUint32 aIndex) const { return mChildren.ElementAt(aIndex); }
inline bool AreChildrenCached() const
@ -503,7 +498,7 @@ protected:
* Return sibling accessible at the given offset.
*/
virtual nsAccessible* GetSiblingAtOffset(PRInt32 aOffset,
nsresult *aError = nsnull);
nsresult *aError = nsnull) const;
/**
* Flags used to describe the state and type of children.

View File

@ -428,15 +428,9 @@ nsApplicationAccessible::CacheChildren()
}
nsAccessible*
nsApplicationAccessible::GetSiblingAtOffset(PRInt32 aOffset, nsresult* aError)
nsApplicationAccessible::GetSiblingAtOffset(PRInt32 aOffset,
nsresult* aError) const
{
if (IsDefunct()) {
if (aError)
*aError = NS_ERROR_FAILURE;
return nsnull;
}
if (aError)
*aError = NS_OK; // fail peacefully

View File

@ -136,7 +136,7 @@ protected:
// nsAccessible
virtual void CacheChildren();
virtual nsAccessible* GetSiblingAtOffset(PRInt32 aOffset,
nsresult *aError = nsnull);
nsresult *aError = nsnull) const;
private:
nsCOMPtr<nsIXULAppInfo> mAppInfo;

View File

@ -1008,15 +1008,8 @@ nsXULTreeItemAccessibleBase::DispatchClickEvent(nsIContent *aContent,
nsAccessible*
nsXULTreeItemAccessibleBase::GetSiblingAtOffset(PRInt32 aOffset,
nsresult* aError)
nsresult* aError) const
{
if (IsDefunct()) {
if (aError)
*aError = NS_ERROR_FAILURE;
return nsnull;
}
if (aError)
*aError = NS_OK; // fail peacefully
@ -1172,20 +1165,13 @@ nsXULTreeColumnsAccessible::
nsAccessible*
nsXULTreeColumnsAccessible::GetSiblingAtOffset(PRInt32 aOffset,
nsresult* aError)
nsresult* aError) const
{
if (aOffset < 0)
return nsXULColumnsAccessible::GetSiblingAtOffset(aOffset, aError);
if (IsDefunct()) {
if (aError)
*aError = NS_ERROR_FAILURE;
return nsnull;
}
if (aError)
*aError = NS_OK; // fail peacefully
*aError = NS_OK; // fail peacefully
nsCOMPtr<nsITreeBoxObject> tree = nsCoreUtils::GetTreeBoxObject(mContent);
if (tree) {
@ -1195,7 +1181,7 @@ nsXULTreeColumnsAccessible::GetSiblingAtOffset(PRInt32 aOffset,
PRInt32 rowCount = 0;
treeView->GetRowCount(&rowCount);
if (rowCount > 0 && aOffset <= rowCount) {
nsRefPtr<nsXULTreeAccessible> treeAcc = do_QueryObject(mParent);
nsRefPtr<nsXULTreeAccessible> treeAcc = do_QueryObject(GetParent());
if (treeAcc)
return treeAcc->GetTreeItemAccessible(aOffset - 1);

View File

@ -235,7 +235,7 @@ protected:
// nsAccessible
virtual void DispatchClickEvent(nsIContent *aContent, PRUint32 aActionIndex);
virtual nsAccessible* GetSiblingAtOffset(PRInt32 aOffset,
nsresult *aError = nsnull);
nsresult *aError = nsnull) const;
// nsXULTreeItemAccessibleBase
@ -299,7 +299,7 @@ protected:
// nsAccessible
virtual nsAccessible* GetSiblingAtOffset(PRInt32 aOffset,
nsresult *aError = nsnull);
nsresult *aError = nsnull) const;
};
#endif

View File

@ -1244,17 +1244,10 @@ nsXULTreeGridCellAccessible::CellInvalidated()
nsAccessible*
nsXULTreeGridCellAccessible::GetSiblingAtOffset(PRInt32 aOffset,
nsresult* aError)
nsresult* aError) const
{
if (IsDefunct()) {
if (aError)
*aError = NS_ERROR_FAILURE;
return nsnull;
}
if (aError)
*aError = NS_OK; // fail peacefully
*aError = NS_OK; // fail peacefully
nsCOMPtr<nsITreeColumn> columnAtOffset(mColumn), column;
if (aOffset < 0) {
@ -1272,8 +1265,7 @@ nsXULTreeGridCellAccessible::GetSiblingAtOffset(PRInt32 aOffset,
if (!columnAtOffset)
return nsnull;
nsRefPtr<nsXULTreeItemAccessibleBase> rowAcc = do_QueryObject(mParent);
nsRefPtr<nsXULTreeItemAccessibleBase> rowAcc = do_QueryObject(GetParent());
return rowAcc->GetCellAccessible(columnAtOffset);
}

View File

@ -182,7 +182,7 @@ public:
protected:
// nsAccessible
virtual nsAccessible* GetSiblingAtOffset(PRInt32 aOffset,
nsresult *aError = nsnull);
nsresult *aError = nsnull) const;
virtual void DispatchClickEvent(nsIContent *aContent, PRUint32 aActionIndex);
// nsXULTreeGridCellAccessible