From 21c364c6f045b1acecb5abaee24ac0dbd3f65740 Mon Sep 17 00:00:00 2001 From: "alfred.peng%sun.com" Date: Fri, 8 Dec 2006 09:57:25 +0000 Subject: [PATCH] Bug 356347. Invisible column headers of xul tree-table are not exposed. Patch by Evan.Yan@sun.com. r=aaronleventhal. --- .../src/atk/nsXULTreeAccessibleWrap.cpp | 3 +- accessible/src/base/nsAccessibilityAtomList.h | 1 + accessible/src/xul/nsXULTreeAccessible.cpp | 63 ++++++++++++++++--- accessible/src/xul/nsXULTreeAccessible.h | 5 ++ 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/accessible/src/atk/nsXULTreeAccessibleWrap.cpp b/accessible/src/atk/nsXULTreeAccessibleWrap.cpp index b58feed0996..669cab11e43 100644 --- a/accessible/src/atk/nsXULTreeAccessibleWrap.cpp +++ b/accessible/src/atk/nsXULTreeAccessibleWrap.cpp @@ -68,7 +68,8 @@ NS_IMETHODIMP nsXULTreeAccessibleWrap::GetChildCount(PRInt32 *aAccChildCount) // created and appended by XUL tree accessible implementation PRInt32 rowCount, colCount = 1; mTreeView->GetRowCount(&rowCount); - GetColumnCount(mTree, &colCount); + mFirstChild->GetChildCount(&colCount); + *aAccChildCount += rowCount * colCount; return NS_OK; diff --git a/accessible/src/base/nsAccessibilityAtomList.h b/accessible/src/base/nsAccessibilityAtomList.h index 3a20a252b68..7e1363d5ca3 100755 --- a/accessible/src/base/nsAccessibilityAtomList.h +++ b/accessible/src/base/nsAccessibilityAtomList.h @@ -168,3 +168,4 @@ ACCESSIBILITY_ATOM(selected, "selected") ACCESSIBILITY_ATOM(valuenow, "valuenow") // For DHTML widget values ACCESSIBILITY_ATOM(valuemin, "valuemin") ACCESSIBILITY_ATOM(valuemax, "valuemax") +ACCESSIBILITY_ATOM(hidden, "hidden") diff --git a/accessible/src/xul/nsXULTreeAccessible.cpp b/accessible/src/xul/nsXULTreeAccessible.cpp index 324bdc434d7..ff2a9bf8bf9 100644 --- a/accessible/src/xul/nsXULTreeAccessible.cpp +++ b/accessible/src/xul/nsXULTreeAccessible.cpp @@ -51,7 +51,35 @@ #define kMaxTreeColumns 100 -inline already_AddRefed GetFirstColumn(nsITreeBoxObject *aTree) +/* static */ +PRBool nsXULTreeAccessible::IsColumnHidden(nsITreeColumn *aColumn) +{ + nsCOMPtr element; + aColumn->GetElement(getter_AddRefs(element)); + nsCOMPtr content = do_QueryInterface(element); + return content->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::hidden, + nsAccessibilityAtoms::_true, eCaseMatters); +} + +/* static */ +already_AddRefed nsXULTreeAccessible::GetNextVisibleColumn(nsITreeColumn *aColumn) +{ + // Skip hidden columns. + nsCOMPtr nextColumn; + aColumn->GetNext(getter_AddRefs(nextColumn)); + while (nextColumn && IsColumnHidden(nextColumn)) { + nsCOMPtr tempColumn; + nextColumn->GetNext(getter_AddRefs(tempColumn)); + nextColumn.swap(tempColumn); + } + + nsITreeColumn *retCol = nsnull; + nextColumn.swap(retCol); + return retCol; +} + +/* static */ +already_AddRefed nsXULTreeAccessible::GetFirstVisibleColumn(nsITreeBoxObject *aTree) { nsCOMPtr cols; nsCOMPtr column; @@ -59,12 +87,19 @@ inline already_AddRefed GetFirstColumn(nsITreeBoxObject *aTree) if (cols) { cols->GetFirstColumn(getter_AddRefs(column)); } + + if (column && IsColumnHidden(column)) { + column = GetNextVisibleColumn(column); + } + NS_ENSURE_TRUE(column, nsnull); + nsITreeColumn *retCol = nsnull; column.swap(retCol); return retCol; } -inline already_AddRefed GetLastColumn(nsITreeBoxObject *aTree) +/* static */ +already_AddRefed nsXULTreeAccessible::GetLastVisibleColumn(nsITreeBoxObject *aTree) { nsCOMPtr cols; nsCOMPtr column; @@ -72,6 +107,15 @@ inline already_AddRefed GetLastColumn(nsITreeBoxObject *aTree) if (cols) { cols->GetLastColumn(getter_AddRefs(column)); } + + // Skip hidden columns. + while (column && IsColumnHidden(column)) { + nsCOMPtr tempColumn; + column->GetPrevious(getter_AddRefs(tempColumn)); + column.swap(tempColumn); + } + NS_ENSURE_TRUE(column, nsnull); + nsITreeColumn *retCol = nsnull; column.swap(retCol); return retCol; @@ -211,7 +255,7 @@ NS_IMETHODIMP nsXULTreeAccessible::GetFirstChild(nsIAccessible **aFirstChild) PRInt32 rowCount; mTreeView->GetRowCount(&rowCount); if (rowCount > 0) { - nsCOMPtr column = GetFirstColumn(mTree); + nsCOMPtr column = GetFirstVisibleColumn(mTree); return GetCachedTreeitemAccessible(0, column, aFirstChild); } } @@ -226,7 +270,7 @@ NS_IMETHODIMP nsXULTreeAccessible::GetLastChild(nsIAccessible **aLastChild) PRInt32 rowCount; mTreeView->GetRowCount(&rowCount); if (rowCount > 0) { - nsCOMPtr column = GetLastColumn(mTree); + nsCOMPtr column = GetLastVisibleColumn(mTree); return GetCachedTreeitemAccessible(rowCount - 1, column, aLastChild); } else // if there is not any rows, use treecols as tree's last child @@ -647,13 +691,12 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetNextSibling(nsIAccessible **aNextSibli PRInt32 row = mRow; nsCOMPtr column; #ifdef MOZ_ACCESSIBILITY_ATK - rv = mColumn->GetNext(getter_AddRefs(column)); - NS_ENSURE_SUCCESS(rv, rv); - + column = nsXULTreeAccessible::GetNextVisibleColumn(mColumn); + if (!column) { if (mRow < rowCount -1) { row++; - column = GetFirstColumn(mTree); + column = nsXULTreeAccessible::GetFirstVisibleColumn(mTree); } else { // the next sibling of the last treeitem is null return NS_OK; @@ -695,7 +738,7 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetPreviousSibling(nsIAccessible **aPrevi if (!column && mRow > 0) { row--; - column = GetLastColumn(mTree); + column = nsXULTreeAccessible::GetLastVisibleColumn(mTree); } #else if (--row < 0) { @@ -893,7 +936,7 @@ NS_IMETHODIMP nsXULTreeColumnsAccessible::GetNextSibling(nsIAccessible **aNextSi PRInt32 rowCount; treeView->GetRowCount(&rowCount); if (rowCount > 0) { - nsCOMPtr column = GetFirstColumn(tree); + nsCOMPtr column = nsXULTreeAccessible::GetFirstVisibleColumn(tree); nsCOMPtr treeCache(do_QueryInterface(mParent)); NS_ENSURE_TRUE(treeCache, NS_ERROR_FAILURE); ret = treeCache->GetCachedTreeitemAccessible(0, column, aNextSibling); diff --git a/accessible/src/xul/nsXULTreeAccessible.h b/accessible/src/xul/nsXULTreeAccessible.h index 43c45da68d3..2e5810e7fdd 100644 --- a/accessible/src/xul/nsXULTreeAccessible.h +++ b/accessible/src/xul/nsXULTreeAccessible.h @@ -76,6 +76,11 @@ public: static void GetTreeBoxObject(nsIDOMNode* aDOMNode, nsITreeBoxObject** aBoxObject); static nsresult GetColumnCount(nsITreeBoxObject* aBoxObject, PRInt32 *aCount); + static PRBool IsColumnHidden(nsITreeColumn *aColumn); + static already_AddRefed GetNextVisibleColumn(nsITreeColumn *aColumn); + static already_AddRefed GetFirstVisibleColumn(nsITreeBoxObject *aTree); + static already_AddRefed GetLastVisibleColumn(nsITreeBoxObject *aTree); + protected: nsCOMPtr mTree; nsCOMPtr mTreeView;