Bug 461923 - remove nsIAccessibleTreeCache and nsPIAccessibleTreeItem, r=marcoz, davidb

This commit is contained in:
Alexander Surkov 2009-06-29 23:38:17 +08:00
Родитель 780a4ffe51
Коммит 02064170df
9 изменённых файлов: 285 добавлений и 274 удалений

Просмотреть файл

@ -73,11 +73,5 @@ XPIDLSRCS = \
nsIXBLAccessible.idl \
$(NULL)
ifdef MOZ_XUL
XPIDLSRCS += \
nsIAccessibleTreeCache.idl \
$(NULL)
endif
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -1,101 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Louie Zhao <Louie.Zhao@sun.com> (original author)
* Alexander Surkov <surkov.alexander@gmail.com>
*
* 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 "nsISupports.idl"
#include "nsITreeColumns.idl"
interface nsIAccessible;
/**
* A private interface to operate with tree accessible.
*
* @status UNDER_REVIEW
*/
[uuid(1dde5c3b-bede-43d1-aabf-dabc461113bd)]
interface nsIAccessibleTreeCache : nsISupports
{
/**
* Get tree item from cache according to row and column, create if doesn't
* exist in cache.
*
* @param aRow the given row index
* @param aColumn the given column object. If is is nsnull then primary
* column is used. It makes sense for ATK only.
*/
nsIAccessible getCachedTreeitemAccessible(in long aRow,
in nsITreeColumn aColumn);
/**
* Invalidates the number of cached treeitem accessibles.
*
* @param aRow row index the invalidation starts from
* @param aCount the number of treeitem accessibles to invalidate,
* the number sign specifies whether rows have been
* inserted (plus) or removed (minus)
*/
void invalidateCache(in long aRow, in long aCount);
/**
* Fires name change events for invalidated area of tree.
*
* @param aStartRow row index invalidation starts from
* @param aEndRow row index invalidation ends, -1 means last row index
* @param aStartCol column index invalidation starts from
* @param aEndCol column index invalidation ends, -1 mens last column
* index
*/
void treeViewInvalidated(in long aStartRow, in long aEndRow,
in long aStartCol, in long aEndCol);
/**
* Invalidates children created for previous tree view.
*/
void treeViewChanged();
};
[uuid(b71532f9-53b2-4647-a5b2-1c5f57e9aed6)]
interface nsPIAccessibleTreeItem : nsISupports
{
/**
* Get/set cached name.
*/
attribute AString cachedName;
};

Просмотреть файл

@ -50,6 +50,7 @@
#include "nsAccessibleTreeWalker.h"
#include "nsAccessible.h"
#include "nsARIAMap.h"
#include "nsXULTreeAccessible.h"
#include "nsIDOMXULContainerElement.h"
#include "nsIDOMXULSelectCntrlEl.h"
@ -768,6 +769,28 @@ nsAccUtils::QueryAccessibleDocument(nsIAccessibleDocument *aAccessibleDocument)
return accessible;
}
#ifdef MOZ_XUL
already_AddRefed<nsXULTreeAccessible>
nsAccUtils::QueryAccessibleTree(nsIAccessible *aAccessible)
{
nsXULTreeAccessible* accessible = nsnull;
if (aAccessible)
CallQueryInterface(aAccessible, &accessible);
return accessible;
}
already_AddRefed<nsXULTreeitemAccessible>
nsAccUtils::QueryAccessibleTreeitem(nsIAccessNode *aAccessNode)
{
nsXULTreeitemAccessible* accessible = nsnull;
if (aAccessNode)
CallQueryInterface(aAccessNode, &accessible);
return accessible;
}
#endif
#ifdef DEBUG_A11Y
PRBool

Просмотреть файл

@ -56,6 +56,10 @@ class nsAccessNode;
class nsAccessible;
class nsHTMLTableAccessible;
class nsDocAccessible;
#ifdef MOZ_XUL
class nsXULTreeAccessible;
class nsXULTreeitemAccessible;
#endif
class nsAccUtils
{
@ -354,6 +358,20 @@ public:
static already_AddRefed<nsDocAccessible>
QueryAccessibleDocument(nsIAccessibleDocument *aAccessibleDocument);
#ifdef MOZ_XUL
/**
* Query nsXULTreeAccessible from the given nsIAccessible.
*/
static already_AddRefed<nsXULTreeAccessible>
QueryAccessibleTree(nsIAccessible *aAccessible);
/**
* Query nsXULTreeitemAccessible from the given nsIAccessNode.
*/
static already_AddRefed<nsXULTreeitemAccessible>
QueryAccessibleTreeitem(nsIAccessNode *aAccessNode);
#endif
#ifdef DEBUG_A11Y
/**
* Detect whether the given accessible object implements nsIAccessibleText,

Просмотреть файл

@ -268,6 +268,7 @@ nsAccEvent::GetAccessibleByNode()
nsIAccessible *accessible = nsnull;
accService->GetAccessibleFor(mDOMNode, &accessible);
#ifdef MOZ_XUL
// hack for xul tree table. We need a better way for firing delayed event
// against xul tree table. see bug 386821.
@ -282,18 +283,12 @@ nsAccEvent::GetAccessibleByNode()
PRInt32 treeIndex = -1;
multiSelect->GetCurrentIndex(&treeIndex);
if (treeIndex >= 0) {
nsCOMPtr<nsIAccessibleTreeCache> treeCache(do_QueryInterface(accessible));
NS_IF_RELEASE(accessible);
nsCOMPtr<nsIAccessible> treeItemAccessible;
if (!treeCache ||
NS_FAILED(treeCache->GetCachedTreeitemAccessible(
treeIndex,
nsnull,
getter_AddRefs(treeItemAccessible))) ||
!treeItemAccessible) {
return nsnull;
nsRefPtr<nsXULTreeAccessible> treeCache =
nsAccUtils::QueryAccessibleTree(accessible);
if (treeCache) {
treeCache->GetCachedTreeitemAccessible(treeIndex, nsnull,
&accessible);
}
NS_IF_ADDREF(accessible = treeItemAccessible);
}
}
}

Просмотреть файл

@ -669,13 +669,16 @@ nsresult nsRootAccessible::HandleEventWithTarget(nsIDOMEvent* aEvent,
#ifdef MOZ_XUL
if (isTree) {
nsCOMPtr<nsIAccessibleTreeCache> treeAcc(do_QueryInterface(accessible));
nsRefPtr<nsXULTreeAccessible> treeAcc =
nsAccUtils::QueryAccessibleTree(accessible);
NS_ASSERTION(treeAcc,
"Accessible for xul:tree doesn't implement nsIAccessibleTreeCache interface.");
"Accessible for xul:tree isn't nsXULTreeAccessible.");
if (treeAcc) {
if (eventType.EqualsLiteral("TreeViewChanged"))
return treeAcc->TreeViewChanged();
if (eventType.EqualsLiteral("TreeViewChanged")) {
treeAcc->TreeViewChanged();
return NS_OK;
}
if (eventType.EqualsLiteral("TreeRowCountChanged"))
return HandleTreeRowCountChangedEvent(aEvent, treeAcc);
@ -730,16 +733,14 @@ nsresult nsRootAccessible::HandleEventWithTarget(nsIDOMEvent* aEvent,
PRInt32 treeIndex = -1;
multiSelect->GetCurrentIndex(&treeIndex);
if (treeIndex >= 0) {
nsCOMPtr<nsIAccessibleTreeCache> treeCache(do_QueryInterface(accessible));
if (!treeCache ||
NS_FAILED(treeCache->GetCachedTreeitemAccessible(
treeIndex,
nsnull,
getter_AddRefs(treeItemAccessible))) ||
!treeItemAccessible) {
return NS_ERROR_OUT_OF_MEMORY;
nsRefPtr<nsXULTreeAccessible> treeCache =
nsAccUtils::QueryAccessibleTree(accessible);
if (treeCache) {
treeCache->GetCachedTreeitemAccessible(treeIndex, nsnull,
getter_AddRefs(treeItemAccessible));
if (treeItemAccessible)
accessible = treeItemAccessible;
}
accessible = treeItemAccessible;
}
}
}
@ -1181,7 +1182,7 @@ nsRootAccessible::HandlePopupHidingEvent(nsIDOMNode *aNode,
#ifdef MOZ_XUL
nsresult
nsRootAccessible::HandleTreeRowCountChangedEvent(nsIDOMEvent *aEvent,
nsIAccessibleTreeCache *aAccessible)
nsXULTreeAccessible *aAccessible)
{
nsCOMPtr<nsIDOMDataContainerEvent> dataEvent(do_QueryInterface(aEvent));
if (!dataEvent)
@ -1203,12 +1204,13 @@ nsRootAccessible::HandleTreeRowCountChangedEvent(nsIDOMEvent *aEvent,
indexVariant->GetAsInt32(&index);
countVariant->GetAsInt32(&count);
return aAccessible->InvalidateCache(index, count);
aAccessible->InvalidateCache(index, count);
return NS_OK;
}
nsresult
nsRootAccessible::HandleTreeInvalidatedEvent(nsIDOMEvent *aEvent,
nsIAccessibleTreeCache *aAccessible)
nsXULTreeAccessible *aAccessible)
{
nsCOMPtr<nsIDOMDataContainerEvent> dataEvent(do_QueryInterface(aEvent));
if (!dataEvent)
@ -1240,7 +1242,8 @@ nsRootAccessible::HandleTreeInvalidatedEvent(nsIDOMEvent *aEvent,
if (endColVariant)
endColVariant->GetAsInt32(&endCol);
return aAccessible->TreeViewInvalidated(startRow, endRow, startCol, endCol);
aAccessible->TreeViewInvalidated(startRow, endRow, startCol, endCol);
return NS_OK;
}
#endif

Просмотреть файл

@ -43,7 +43,7 @@
#include "nsIAccessibleDocument.h"
#ifdef MOZ_XUL
#include "nsIAccessibleTreeCache.h"
#include "nsXULTreeAccessible.h"
#endif
#include "nsHashtable.h"
@ -140,9 +140,9 @@ public:
#ifdef MOZ_XUL
nsresult HandleTreeRowCountChangedEvent(nsIDOMEvent *aEvent,
nsIAccessibleTreeCache *aAccessible);
nsXULTreeAccessible *aAccessible);
nsresult HandleTreeInvalidatedEvent(nsIDOMEvent *aEvent,
nsIAccessibleTreeCache *aAccessible);
nsXULTreeAccessible *aAccessible);
PRUint32 GetChromeFlags();
#endif

Просмотреть файл

@ -133,7 +133,9 @@ mAccessNodeCache(nsnull)
mAccessNodeCache->Init(kDefaultTreeCacheSize);
}
NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeAccessible, nsXULSelectableAccessible, nsIAccessibleTreeCache)
NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeAccessible,
nsXULSelectableAccessible,
nsXULTreeAccessible)
@ -220,6 +222,12 @@ NS_IMETHODIMP nsXULTreeAccessible::GetValue(nsAString& _retval)
return NS_OK;
}
PRBool
nsXULTreeAccessible::IsDefunct()
{
return nsXULSelectableAccessible::IsDefunct() || !mTree || !mTreeView;
}
nsresult
nsXULTreeAccessible::Shutdown()
{
@ -262,7 +270,7 @@ NS_IMETHODIMP nsXULTreeAccessible::GetFirstChild(nsIAccessible **aFirstChild)
mTreeView->GetRowCount(&rowCount);
if (rowCount > 0) {
nsCOMPtr<nsITreeColumn> column = GetFirstVisibleColumn(mTree);
return GetCachedTreeitemAccessible(0, column, aFirstChild);
GetCachedTreeitemAccessible(0, column, aFirstChild);
}
}
@ -281,12 +289,11 @@ nsXULTreeAccessible::GetLastChild(nsIAccessible **aLastChild)
mTreeView->GetRowCount(&rowCount);
if (rowCount > 0) {
nsCOMPtr<nsITreeColumn> column = GetLastVisibleColumn(mTree);
nsresult rv = GetCachedTreeitemAccessible(rowCount - 1, column, aLastChild);
NS_ENSURE_SUCCESS(rv, rv);
}
GetCachedTreeitemAccessible(rowCount - 1, column, aLastChild);
if (*aLastChild)
return NS_OK;
if (*aLastChild)
return NS_OK;
}
// If there is not any rows, use treecols as tree's last child.
return nsAccessible::GetLastChild(aLastChild);
@ -316,9 +323,8 @@ NS_IMETHODIMP nsXULTreeAccessible::GetFocusedChild(nsIAccessible **aFocusedChild
multiSelect->GetCurrentIndex(&row);
if (row >= 0) {
GetCachedTreeitemAccessible(row, nsnull, aFocusedChild);
if (*aFocusedChild) {
return NS_OK; // Already addref'd by getter
}
if (*aFocusedChild)
return NS_OK;
}
}
NS_ADDREF(*aFocusedChild = this);
@ -360,13 +366,7 @@ nsXULTreeAccessible::GetChildAtPoint(PRInt32 aX, PRInt32 aY,
return nsXULSelectableAccessible::
GetChildAtPoint(aX, aY, aDeepestChild, aChild);
nsCOMPtr<nsIAccessible> treeitemAcc;
nsresult rv = GetCachedTreeitemAccessible(row, column,
getter_AddRefs(treeitemAcc));
NS_ENSURE_SUCCESS(rv, rv);
NS_IF_ADDREF(*aChild = treeitemAcc);
GetCachedTreeitemAccessible(row, column, aChild);
return NS_OK;
}
@ -392,9 +392,10 @@ NS_IMETHODIMP nsXULTreeAccessible::GetSelectedChildren(nsIArray **_retval)
selection->IsSelected(rowIndex, &isSelected);
if (isSelected) {
nsCOMPtr<nsIAccessible> tempAccess;
if (NS_FAILED(GetCachedTreeitemAccessible(rowIndex, nsnull, getter_AddRefs(tempAccess))) || !tempAccess)
GetCachedTreeitemAccessible(rowIndex, nsnull,
getter_AddRefs(tempAccess));
NS_ENSURE_STATE(tempAccess);
return NS_ERROR_OUT_OF_MEMORY;
selectedAccessibles->AppendElement(tempAccess, PR_FALSE);
}
}
@ -468,9 +469,11 @@ NS_IMETHODIMP nsXULTreeAccessible::ClearSelection()
return NS_OK;
}
NS_IMETHODIMP nsXULTreeAccessible::RefSelection(PRInt32 aIndex, nsIAccessible **_retval)
NS_IMETHODIMP
nsXULTreeAccessible::RefSelection(PRInt32 aIndex, nsIAccessible **aAccessible)
{
*_retval = nsnull;
NS_ENSURE_ARG_POINTER(aAccessible);
*aAccessible = nsnull;
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
@ -487,7 +490,8 @@ NS_IMETHODIMP nsXULTreeAccessible::RefSelection(PRInt32 aIndex, nsIAccessible **
selection->IsSelected(rowIndex, &isSelected);
if (isSelected) {
if (selCount == aIndex) {
return GetCachedTreeitemAccessible(rowIndex, nsnull, _retval);
GetCachedTreeitemAccessible(rowIndex, nsnull, aAccessible);
return NS_OK;
}
selCount++;
}
@ -519,14 +523,13 @@ NS_IMETHODIMP nsXULTreeAccessible::SelectAllSelection(PRBool *_retval)
return NS_OK;
}
// nsIAccessible nsIAccessibleTreeCache::
// GetCachedTreeitemAccessible(in long aRow, nsITreeColumn* aColumn)
NS_IMETHODIMP
// nsXULTreeAccessible
void
nsXULTreeAccessible::GetCachedTreeitemAccessible(PRInt32 aRow,
nsITreeColumn* aColumn,
nsIAccessible** aAccessible)
{
NS_ENSURE_ARG_POINTER(aAccessible);
*aAccessible = nsnull;
NS_ASSERTION(mAccessNodeCache, "No accessibility cache for tree");
@ -548,59 +551,61 @@ nsXULTreeAccessible::GetCachedTreeitemAccessible(PRInt32 aRow,
// Do not create accessible for treeitem if there is no column in the tree
// because it doesn't render treeitems properly.
if (!col)
return NS_OK;
return;
col->GetIndex(&columnIndex);
nsCOMPtr<nsIAccessNode> accessNode;
GetCacheEntry(*mAccessNodeCache, (void*)(aRow * kMaxTreeColumns + columnIndex), getter_AddRefs(accessNode));
if (!accessNode)
{
nsXULTreeitemAccessibleWrap* treeItemAcc =
if (!accessNode) {
nsRefPtr<nsAccessNode> treeItemAcc =
new nsXULTreeitemAccessibleWrap(this, mDOMNode, mWeakShell, aRow, col);
NS_ENSURE_TRUE(treeItemAcc, NS_ERROR_OUT_OF_MEMORY);
if (!treeItemAcc)
return;
nsresult rv = treeItemAcc->Init();
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv))
return;
accessNode = treeItemAcc;
PutCacheEntry(*mAccessNodeCache, (void*)(aRow * kMaxTreeColumns + columnIndex), accessNode);
}
nsCOMPtr<nsIAccessible> accessible(do_QueryInterface(accessNode));
NS_IF_ADDREF(*aAccessible = accessible);
return NS_OK;
CallQueryInterface(accessNode, aAccessible);
}
// void nsIAccessibleTreeCache::
// invalidateCache(in PRInt32 aRow, in PRInt32 aCount)
NS_IMETHODIMP
void
nsXULTreeAccessible::InvalidateCache(PRInt32 aRow, PRInt32 aCount)
{
if (IsDefunct())
return;
// Do not invalidate the cache if rows have been inserted.
if (aCount > 0)
return NS_OK;
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
return;
nsCOMPtr<nsITreeColumns> cols;
nsresult rv = mTree->GetColumns(getter_AddRefs(cols));
NS_ENSURE_STATE(cols);
mTree->GetColumns(getter_AddRefs(cols));
if (!cols)
return;
#ifdef MOZ_ACCESSIBILITY_ATK
PRInt32 colsCount = 0;
rv = cols->GetCount(&colsCount);
NS_ENSURE_SUCCESS(rv, rv);
nsresult rv = cols->GetCount(&colsCount);
if (NS_FAILED(rv))
return;
#else
nsCOMPtr<nsITreeColumn> col;
rv = cols->GetKeyColumn(getter_AddRefs(col));
NS_ENSURE_SUCCESS(rv, rv);
cols->GetKeyColumn(getter_AddRefs(col));
if (!col)
return NS_OK;
return;
PRInt32 colIdx = 0;
rv = col->GetIndex(&colIdx);
NS_ENSURE_SUCCESS(rv, rv);
nsresult rv = col->GetIndex(&colIdx);
if (NS_FAILED(rv))
return;
#endif
for (PRInt32 rowIdx = aRow; rowIdx < aRow - aCount; rowIdx++) {
@ -629,7 +634,8 @@ nsXULTreeAccessible::InvalidateCache(PRInt32 aRow, PRInt32 aCount)
PRInt32 newRowCount = 0;
rv = mTreeView->GetRowCount(&newRowCount);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv))
return;
PRInt32 oldRowCount = newRowCount - aCount;
@ -643,18 +649,14 @@ nsXULTreeAccessible::InvalidateCache(PRInt32 aRow, PRInt32 aCount)
mAccessNodeCache->Remove(key);
}
}
return NS_OK;
}
// void nsIAccessibleTreeCache::
// treeViewInvalidated(in long aStartRow, in long aEndRow,
// in long aStartCol, in long aEndCol);
NS_IMETHODIMP
void
nsXULTreeAccessible::TreeViewInvalidated(PRInt32 aStartRow, PRInt32 aEndRow,
PRInt32 aStartCol, PRInt32 aEndCol)
{
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
if (IsDefunct())
return;
PRInt32 endRow = aEndRow;
@ -662,14 +664,16 @@ nsXULTreeAccessible::TreeViewInvalidated(PRInt32 aStartRow, PRInt32 aEndRow,
if (endRow == -1) {
PRInt32 rowCount = 0;
rv = mTreeView->GetRowCount(&rowCount);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv))
return;
endRow = rowCount - 1;
}
nsCOMPtr<nsITreeColumns> treeColumns;
mTree->GetColumns(getter_AddRefs(treeColumns));
NS_ENSURE_STATE(treeColumns);
if (!treeColumns)
return;
#ifdef MOZ_ACCESSIBILITY_ATK
PRInt32 endCol = aEndCol;
@ -677,21 +681,22 @@ nsXULTreeAccessible::TreeViewInvalidated(PRInt32 aStartRow, PRInt32 aEndRow,
if (endCol == -1) {
PRInt32 colCount = 0;
rv = treeColumns->GetCount(&colCount);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv))
return;
endCol = colCount - 1;
}
#else
nsCOMPtr<nsITreeColumn> col;
rv = treeColumns->GetKeyColumn(getter_AddRefs(col));
NS_ENSURE_SUCCESS(rv, rv);
if (!col)
return NS_OK;
return;
PRInt32 colIdx = 0;
rv = col->GetIndex(&colIdx);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv))
return;
#endif
for (PRInt32 rowIdx = aStartRow; rowIdx <= endRow; ++rowIdx) {
@ -705,37 +710,29 @@ nsXULTreeAccessible::TreeViewInvalidated(PRInt32 aStartRow, PRInt32 aEndRow,
GetCacheEntry(*mAccessNodeCache, key, getter_AddRefs(accessNode));
if (accessNode) {
nsCOMPtr<nsIAccessible> acc(do_QueryInterface(accessNode));
NS_ENSURE_STATE(acc);
nsCOMPtr<nsPIAccessibleTreeItem> treeItemAcc(
do_QueryInterface(accessNode));
NS_ENSURE_STATE(treeItemAcc);
nsRefPtr<nsXULTreeitemAccessible> treeitemAcc(
nsAccUtils::QueryAccessibleTreeitem(accessNode));
NS_ASSERTION(treeitemAcc, "Wrong accessible at the given key!");
nsAutoString name, cachedName;
rv = acc->GetName(name);
NS_ENSURE_SUCCESS(rv, rv);
rv = treeItemAcc->GetCachedName(cachedName);
NS_ENSURE_SUCCESS(rv, rv);
treeitemAcc->GetName(name);
treeitemAcc->GetCachedName(cachedName);
if (name != cachedName) {
nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_NAME_CHANGE, acc);
treeItemAcc->SetCachedName(name);
nsAccUtils::FireAccEvent(nsIAccessibleEvent::EVENT_NAME_CHANGE,
treeitemAcc);
treeitemAcc->SetCachedName(name);
}
}
}
}
return NS_OK;
}
// void nsIAccessibleTreeCache::treeViewChanged();
NS_IMETHODIMP
void
nsXULTreeAccessible::TreeViewChanged()
{
if (!mTree)
return NS_ERROR_FAILURE;
if (IsDefunct())
return;
// Fire only notification destroy/create events on accessible tree to lie to
// AT because it should be expensive to fire destroy events for each tree item
@ -743,22 +740,22 @@ nsXULTreeAccessible::TreeViewChanged()
nsCOMPtr<nsIAccessibleEvent> eventDestroy =
new nsAccEvent(nsIAccessibleEvent::EVENT_DOM_DESTROY,
this, PR_FALSE);
NS_ENSURE_TRUE(eventDestroy, NS_ERROR_OUT_OF_MEMORY);
if (!eventDestroy)
return;
nsresult rv = FirePlatformEvent(eventDestroy);
FirePlatformEvent(eventDestroy);
ClearCache(*mAccessNodeCache);
mTree->GetView(getter_AddRefs(mTreeView));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAccessibleEvent> eventCreate =
new nsAccEvent(nsIAccessibleEvent::EVENT_DOM_CREATE,
this, PR_FALSE);
NS_ENSURE_TRUE(eventCreate, NS_ERROR_OUT_OF_MEMORY);
if (!eventCreate)
return;
return FirePlatformEvent(eventCreate);
FirePlatformEvent(eventCreate);
}
nsresult nsXULTreeAccessible::GetColumnCount(nsITreeBoxObject* aBoxObject, PRInt32* aCount)
@ -795,9 +792,12 @@ nsXULTreeitemAccessible::nsXULTreeitemAccessible(nsIAccessible *aParent, nsIDOMN
}
}
NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeitemAccessible, nsLeafAccessible,
nsPIAccessibleTreeItem)
NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeitemAccessible,
nsLeafAccessible,
nsXULTreeitemAccessible)
// nsAccessNode
nsresult
nsXULTreeitemAccessible::Shutdown()
{
@ -807,6 +807,8 @@ nsXULTreeitemAccessible::Shutdown()
return nsLeafAccessible::Shutdown();
}
// nsIAccessible
NS_IMETHODIMP
nsXULTreeitemAccessible::GetName(nsAString& aName)
{
@ -1102,7 +1104,8 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetNextSibling(nsIAccessible **aNextSibli
if (IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIAccessibleTreeCache> treeCache(do_QueryInterface(mParent));
nsRefPtr<nsXULTreeAccessible> treeCache =
nsAccUtils::QueryAccessibleTree(mParent);
NS_ENSURE_TRUE(treeCache, NS_ERROR_FAILURE);
PRInt32 rowCount;
@ -1110,12 +1113,11 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetNextSibling(nsIAccessible **aNextSibli
if (!mColumn) {
if (mRow < rowCount - 1)
return treeCache->GetCachedTreeitemAccessible(mRow + 1, nsnull, aNextSibling);
else
return NS_OK;
treeCache->GetCachedTreeitemAccessible(mRow + 1, nsnull, aNextSibling);
return NS_OK;
}
nsresult rv = NS_OK;
PRInt32 row = mRow;
nsCOMPtr<nsITreeColumn> column;
#ifdef MOZ_ACCESSIBILITY_ATK
@ -1136,9 +1138,8 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetNextSibling(nsIAccessible **aNextSibli
}
#endif //MOZ_ACCESSIBILITY_ATK
rv = treeCache->GetCachedTreeitemAccessible(row, column, aNextSibling);
return rv;
treeCache->GetCachedTreeitemAccessible(row, column, aNextSibling);
return NS_OK;
}
// Return the previous row of tree if mColumn (if any),
@ -1151,12 +1152,13 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetPreviousSibling(nsIAccessible **aPrevi
if (IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIAccessibleTreeCache> treeCache(do_QueryInterface(mParent));
nsRefPtr<nsXULTreeAccessible> treeCache =
nsAccUtils::QueryAccessibleTree(mParent);
NS_ENSURE_TRUE(treeCache, NS_ERROR_FAILURE);
if (!mColumn && mRow > 0)
return treeCache->GetCachedTreeitemAccessible(mRow - 1, nsnull, aPreviousSibling);
treeCache->GetCachedTreeitemAccessible(mRow - 1, nsnull, aPreviousSibling);
nsresult rv = NS_OK;
@ -1176,9 +1178,8 @@ NS_IMETHODIMP nsXULTreeitemAccessible::GetPreviousSibling(nsIAccessible **aPrevi
}
#endif
rv = treeCache->GetCachedTreeitemAccessible(row, column, aPreviousSibling);
return rv;
treeCache->GetCachedTreeitemAccessible(row, column, aPreviousSibling);
return NS_OK;
}
NS_IMETHODIMP nsXULTreeitemAccessible::DoAction(PRUint8 index)
@ -1294,13 +1295,12 @@ nsXULTreeitemAccessible::GetRelationByType(PRUint32 aRelationType,
if (parentIndex == -1)
return nsRelUtils::AddTarget(aRelationType, aRelation, mParent);
nsCOMPtr<nsIAccessibleTreeCache> cache =
do_QueryInterface(mParent);
nsRefPtr<nsXULTreeAccessible> treeCache =
nsAccUtils::QueryAccessibleTree(mParent);
nsCOMPtr<nsIAccessible> accParent;
nsresult rv = cache->
GetCachedTreeitemAccessible(parentIndex, mColumn,
getter_AddRefs(accParent));
NS_ENSURE_SUCCESS(rv, rv);
treeCache->GetCachedTreeitemAccessible(parentIndex, mColumn,
getter_AddRefs(accParent));
return nsRelUtils::AddTarget(aRelationType, aRelation, accParent);
}
@ -1312,20 +1312,17 @@ nsXULTreeitemAccessible::GetRelationByType(PRUint32 aRelationType,
return nsAccessible::GetRelationByType(aRelationType, aRelation);
}
// attribute AString nsIAccessibleTreeItem::cachedName
NS_IMETHODIMP
// nsXULTreeitemAccessible
void
nsXULTreeitemAccessible::GetCachedName(nsAString &aName)
{
aName = mCachedName;
return NS_OK;
}
// attribute AString nsIAccessibleTreeItem::cachedName
NS_IMETHODIMP
void
nsXULTreeitemAccessible::SetCachedName(const nsAString &aName)
{
mCachedName = aName;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
@ -1355,10 +1352,11 @@ nsXULTreeColumnsAccessible::GetNextSibling(nsIAccessible **aNextSibling)
nsCOMPtr<nsITreeColumn> column =
nsXULTreeAccessible::GetFirstVisibleColumn(tree);
nsCOMPtr<nsIAccessibleTreeCache> treeCache(do_QueryInterface(mParent));
nsRefPtr<nsXULTreeAccessible> treeCache =
nsAccUtils::QueryAccessibleTree(mParent);
NS_ENSURE_TRUE(treeCache, NS_ERROR_FAILURE);
return treeCache->GetCachedTreeitemAccessible(0, column, aNextSibling);
treeCache->GetCachedTreeitemAccessible(0, column, aNextSibling);
}
}
}

Просмотреть файл

@ -42,7 +42,6 @@
#include "nsITreeView.h"
#include "nsITreeColumns.h"
#include "nsXULSelectAccessible.h"
#include "nsIAccessibleTreeCache.h"
/*
* A class the represents the XUL Tree widget.
@ -50,17 +49,30 @@
const PRUint32 kMaxTreeColumns = 100;
const PRUint32 kDefaultTreeCacheSize = 256;
class nsXULTreeAccessible : public nsXULSelectableAccessible,
public nsIAccessibleTreeCache
/**
* Accessible class for XUL tree element.
*/
#define NS_XULTREEACCESSIBLE_IMPL_CID \
{ /* 2692e149-6176-42ee-b8e1-2c44b04185e3 */ \
0x2692e149, \
0x6176, \
0x42ee, \
{ 0xb8, 0xe1, 0x2c, 0x44, 0xb0, 0x41, 0x85, 0xe3 } \
}
class nsXULTreeAccessible : public nsXULSelectableAccessible
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIACCESSIBLESELECTABLE
NS_DECL_NSIACCESSIBLETREECACHE
nsXULTreeAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
virtual ~nsXULTreeAccessible() {}
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsIAccessibleSelectable
NS_DECL_NSIACCESSIBLESELECTABLE
// nsIAccessible
NS_IMETHOD GetValue(nsAString& _retval);
@ -70,6 +82,7 @@ public:
NS_IMETHOD GetFocusedChild(nsIAccessible **aFocusedChild);
// nsAccessNode
virtual PRBool IsDefunct();
virtual nsresult Shutdown();
// nsAccessible
@ -80,6 +93,48 @@ public:
nsIAccessible **aChild);
// nsXULTreeAccessible
NS_DECLARE_STATIC_IID_ACCESSOR(NS_XULTREEACCESSIBLE_IMPL_CID)
/**
* Return tree item accessible at the givem row and column. If accessible
* doesn't exist in the cache then create it.
*
* @param aRow [in] the given row index
* @param aColumn [in] the given column object. If is is nsnull then
* primary column is used
* @param aAccessible [out] tree item accessible
*/
void GetCachedTreeitemAccessible(PRInt32 aRow, nsITreeColumn *aColumn,
nsIAccessible **aAccessible);
/**
* Invalidates the number of cached treeitem accessibles.
*
* @param aRow [in] row index the invalidation starts from
* @param aCount [in] the number of treeitem accessibles to invalidate,
* the number sign specifies whether rows have been
* inserted (plus) or removed (minus)
*/
void InvalidateCache(PRInt32 aRow, PRInt32 aCount);
/**
* Fires name change events for invalidated area of tree.
*
* @param aStartRow [in] row index invalidation starts from
* @param aEndRow [in] row index invalidation ends, -1 means last row index
* @param aStartCol [in] column index invalidation starts from
* @param aEndCol [in] column index invalidation ends, -1 mens last column
* index
*/
void TreeViewInvalidated(PRInt32 aStartRow, PRInt32 aEndRow,
PRInt32 aStartCol, PRInt32 aEndCol);
/**
* Invalidates children created for previous tree view.
*/
void TreeViewChanged();
static void GetTreeBoxObject(nsIDOMNode* aDOMNode, nsITreeBoxObject** aBoxObject);
static nsresult GetColumnCount(nsITreeBoxObject* aBoxObject, PRInt32 *aCount);
@ -96,26 +151,36 @@ protected:
NS_IMETHOD ChangeSelection(PRInt32 aIndex, PRUint8 aMethod, PRBool *aSelState);
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsXULTreeAccessible,
NS_XULTREEACCESSIBLE_IMPL_CID)
/**
* Treeitems -- used in Trees
*/
class nsXULTreeitemAccessible : public nsLeafAccessible,
public nsPIAccessibleTreeItem
* Accessible class for items for XUL tree.
*/
#define NS_XULTREEITEMACCESSIBLE_IMPL_CID \
{ /* 7b1aa039-7270-4523-aeb3-61063a13ac3f */ \
0x7b1aa039, \
0x7270, \
0x4523, \
{ 0xae, 0xb3, 0x61, 0x06, 0x3a, 0x13, 0xac, 0x3f } \
}
class nsXULTreeitemAccessible : public nsLeafAccessible
{
public:
enum { eAction_Click = 0, eAction_Expand = 1 };
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSPIACCESSIBLETREEITEM
nsXULTreeitemAccessible(nsIAccessible *aParent, nsIDOMNode *aDOMNode, nsIWeakReference *aShell, PRInt32 aRow, nsITreeColumn* aColumn = nsnull);
virtual ~nsXULTreeitemAccessible() {}
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsIAccessible
NS_IMETHOD GetName(nsAString& aName);
NS_IMETHOD GetNumActions(PRUint8 *_retval);
NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
NS_IMETHOD GetParent(nsIAccessible **_retval);
NS_IMETHOD GetNextSibling(nsIAccessible **_retval);
@ -138,9 +203,19 @@ public:
virtual nsresult Shutdown();
// nsAccessible
virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
virtual nsresult GetRoleInternal(PRUint32 *aRole);
virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
// nsXULTreeitemAccessible
NS_DECLARE_STATIC_IID_ACCESSOR(NS_XULTREEITEMACCESSIBLE_IMPL_CID)
/**
* Get/set cached name.
*/
void GetCachedName(nsAString& aName);
void SetCachedName(const nsAString& aName);
protected:
PRBool IsExpandable();
nsCOMPtr<nsITreeBoxObject> mTree;
@ -150,6 +225,12 @@ protected:
nsString mCachedName;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsXULTreeitemAccessible,
NS_XULTREEITEMACCESSIBLE_IMPL_CID)
/**
* Accessible class for columns element of XUL tree.
*/
class nsXULTreeColumnsAccessible : public nsXULColumnsAccessible
{
public: