From 829a802103783383d7e586448a9c330f0c0941ec Mon Sep 17 00:00:00 2001 From: "aaronleventhal@moonset.net" Date: Wed, 5 Sep 2007 06:35:35 -0700 Subject: [PATCH] Bug 394387. Only cells with expanders should have STATE_EXPANDABLE and expand/collapse actions. r=evan.yan, a=dsicore --- accessible/src/xul/nsXULTreeAccessible.cpp | 72 +++++++++++----------- accessible/src/xul/nsXULTreeAccessible.h | 1 + 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/accessible/src/xul/nsXULTreeAccessible.cpp b/accessible/src/xul/nsXULTreeAccessible.cpp index 09df9c98e85e..b20af1d31968 100644 --- a/accessible/src/xul/nsXULTreeAccessible.cpp +++ b/accessible/src/xul/nsXULTreeAccessible.cpp @@ -634,18 +634,11 @@ nsXULTreeitemAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) nsIAccessibleStates::STATE_SELECTABLE; // get expanded/collapsed state - PRBool isContainer, isContainerOpen, isContainerEmpty; - mTreeView->IsContainer(mRow, &isContainer); - if (isContainer) { - mTreeView->IsContainerEmpty(mRow, &isContainerEmpty); - if (!isContainerEmpty) { - if (aExtraState) - *aExtraState |= nsIAccessibleStates::EXT_STATE_EXPANDABLE; - - mTreeView->IsContainerOpen(mRow, &isContainerOpen); - *aState |= isContainerOpen? PRUint32(nsIAccessibleStates::STATE_EXPANDED): - PRUint32(nsIAccessibleStates::STATE_COLLAPSED); - } + if (IsExpandable()) { + PRBool isContainerOpen; + mTreeView->IsContainerOpen(mRow, &isContainerOpen); + *aState |= isContainerOpen? PRUint32(nsIAccessibleStates::STATE_EXPANDED): + PRUint32(nsIAccessibleStates::STATE_COLLAPSED); } // get selected state @@ -689,17 +682,31 @@ nsXULTreeitemAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState) return NS_OK; } -// "activate" (xor "cycle") action is available for all treeitems -// "expand/collapse" action is avaible for treeitem which is container -NS_IMETHODIMP nsXULTreeitemAccessible::GetNumActions(PRUint8 *_retval) +PRBool nsXULTreeitemAccessible::IsExpandable() { - NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(mTree && mTreeView && mColumn, NS_ERROR_FAILURE); PRBool isContainer; mTreeView->IsContainer(mRow, &isContainer); - if (isContainer) - *_retval = 2; - else - *_retval = 1; + if (isContainer) { + PRBool isEmpty; + mTreeView->IsContainerEmpty(mRow, &isEmpty); + if (!isEmpty) { + PRBool isPrimary; + mColumn->GetPrimary(&isPrimary); + if (isPrimary) { + return PR_TRUE; + } + } + } + return PR_FALSE; +} + +// "activate" (xor "cycle") action is available for all treeitems +// "expand/collapse" action is avaible for treeitem which is container +NS_IMETHODIMP nsXULTreeitemAccessible::GetNumActions(PRUint8 *aNumActions) +{ + NS_ENSURE_TRUE(mTree && mTreeView && mColumn, NS_ERROR_FAILURE); + *aNumActions = IsExpandable() ? 2 : 1; return NS_OK; } @@ -720,17 +727,13 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetActionName(PRUint8 aIndex, nsAString& } return NS_OK; } - else if (aIndex == eAction_Expand) { - PRBool isContainer, isContainerOpen; - mTreeView->IsContainer(mRow, &isContainer); - if (isContainer) { - mTreeView->IsContainerOpen(mRow, &isContainerOpen); - if (isContainerOpen) - aName.AssignLiteral("collapse"); - else - aName.AssignLiteral("expand"); - } - + else if (aIndex == eAction_Expand && IsExpandable()) { + PRBool isContainerOpen; + mTreeView->IsContainerOpen(mRow, &isContainerOpen); + if (isContainerOpen) + aName.AssignLiteral("collapse"); + else + aName.AssignLiteral("expand"); return NS_OK; } @@ -920,11 +923,8 @@ NS_IMETHODIMP nsXULTreeitemAccessible::DoAction(PRUint8 index) } return rv; } - else if (index == eAction_Expand) { - PRBool isContainer; - mTreeView->IsContainer(mRow, &isContainer); - if (isContainer) - return mTreeView->ToggleOpenState(mRow); + else if (index == eAction_Expand && IsExpandable()) { + return mTreeView->ToggleOpenState(mRow); } return NS_ERROR_INVALID_ARG; diff --git a/accessible/src/xul/nsXULTreeAccessible.h b/accessible/src/xul/nsXULTreeAccessible.h index f5102288aae6..a0e39f88fd91 100644 --- a/accessible/src/xul/nsXULTreeAccessible.h +++ b/accessible/src/xul/nsXULTreeAccessible.h @@ -128,6 +128,7 @@ public: NS_IMETHOD GetUniqueID(void **aUniqueID); protected: + PRBool IsExpandable(); nsCOMPtr mTree; nsCOMPtr mTreeView; PRInt32 mRow;