2007-03-22 10:30:00 -07:00
|
|
|
/* -*- 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) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Author: Kyle Yuan (kyle.yuan@sun.com)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of 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 ***** */
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
#include "nsXULTreeAccessible.h"
|
|
|
|
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsAccCache.h"
|
|
|
|
#include "nsAccUtils.h"
|
|
|
|
#include "nsCoreUtils.h"
|
2009-08-19 23:45:19 -07:00
|
|
|
#include "nsDocAccessible.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsRelUtils.h"
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#include "nsIDOMXULMultSelectCntrlEl.h"
|
2007-03-27 05:17:11 -07:00
|
|
|
#include "nsIDOMXULTreeElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsITreeSelection.h"
|
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
nsXULTreeAccessible::
|
2010-06-11 01:23:18 -07:00
|
|
|
nsXULTreeAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
2010-09-01 17:46:59 -07:00
|
|
|
nsAccessibleWrap(aContent, aShell)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
mTree = nsCoreUtils::GetTreeBoxObject(aContent);
|
2009-08-19 23:45:19 -07:00
|
|
|
if (mTree)
|
|
|
|
mTree->GetView(getter_AddRefs(mTreeView));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_ASSERTION(mTree && mTreeView, "Can't get mTree or mTreeView!\n");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
mAccessibleCache.Init(kDefaultTreeCacheSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: nsISupports and cycle collection implementation
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULTreeAccessible)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULTreeAccessible,
|
|
|
|
nsAccessible)
|
2010-03-10 02:26:11 -08:00
|
|
|
CycleCollectorTraverseCache(tmp->mAccessibleCache, &cb);
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsXULTreeAccessible,
|
|
|
|
nsAccessible)
|
2010-03-10 02:26:11 -08:00
|
|
|
ClearCache(tmp->mAccessibleCache);
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsXULTreeAccessible)
|
|
|
|
NS_INTERFACE_MAP_STATIC_AMBIGUOUS(nsXULTreeAccessible)
|
2010-09-01 17:46:59 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsAccessible)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsXULTreeAccessible, nsAccessible)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsXULTreeAccessible, nsAccessible)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: nsAccessible implementation
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-11-03 19:37:46 -08:00
|
|
|
nsresult
|
|
|
|
nsXULTreeAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
// Get focus status from base class.
|
2008-11-03 19:37:46 -08:00
|
|
|
nsresult rv = nsAccessible::GetStateInternal(aState, aExtraState);
|
2008-11-26 20:04:05 -08:00
|
|
|
NS_ENSURE_A11Y_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// readonly state
|
|
|
|
*aState |= nsIAccessibleStates::STATE_READONLY;
|
|
|
|
|
|
|
|
// remove focusable and focused states since tree items are focusable for AT
|
|
|
|
*aState &= ~nsIAccessibleStates::STATE_FOCUSABLE;
|
|
|
|
*aState &= ~nsIAccessibleStates::STATE_FOCUSED;
|
|
|
|
|
|
|
|
// multiselectable state.
|
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
NS_ENSURE_STATE(selection);
|
|
|
|
|
|
|
|
PRBool isSingle = PR_FALSE;
|
|
|
|
rv = selection->GetSingle(&isSingle);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!isSingle)
|
|
|
|
*aState |= nsIAccessibleStates::STATE_MULTISELECTABLE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeAccessible::GetValue(nsAString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
// Return the value is the first selected child.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
aValue.Truncate();
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
2009-08-19 23:45:19 -07:00
|
|
|
if (!selection)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRInt32 currentIndex;
|
|
|
|
nsCOMPtr<nsIDOMElement> selectItem;
|
|
|
|
selection->GetCurrentIndex(¤tIndex);
|
|
|
|
if (currentIndex >= 0) {
|
|
|
|
nsCOMPtr<nsITreeColumn> keyCol;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITreeColumns> cols;
|
|
|
|
mTree->GetColumns(getter_AddRefs(cols));
|
|
|
|
if (cols)
|
|
|
|
cols->GetKeyColumn(getter_AddRefs(keyCol));
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
return mTreeView->GetCellText(currentIndex, keyCol, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: nsAccessNode implementation
|
|
|
|
|
2009-06-29 08:38:17 -07:00
|
|
|
PRBool
|
|
|
|
nsXULTreeAccessible::IsDefunct()
|
|
|
|
{
|
2010-09-01 17:46:59 -07:00
|
|
|
return nsAccessibleWrap::IsDefunct() || !mTree || !mTreeView;
|
2009-06-29 08:38:17 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
void
|
2008-10-31 20:58:07 -07:00
|
|
|
nsXULTreeAccessible::Shutdown()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
// XXX: we don't remove accessible from document cache if shutdown wasn't
|
|
|
|
// initiated by document destroying. Note, we can't remove accessible from
|
|
|
|
// document cache here while document is going to be shutdown. Note, this is
|
|
|
|
// not unique place where we have similar problem.
|
2010-03-10 02:26:11 -08:00
|
|
|
ClearCache(mAccessibleCache);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2007-05-20 01:05:28 -07:00
|
|
|
mTree = nsnull;
|
|
|
|
mTreeView = nsnull;
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
nsAccessibleWrap::Shutdown();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: nsAccessible implementation (put methods here)
|
|
|
|
|
2010-09-04 19:14:01 -07:00
|
|
|
PRUint32
|
|
|
|
nsXULTreeAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
// No primary column means we're in a list. In fact, history and mail turn off
|
|
|
|
// the primary flag when switching to a flat view.
|
|
|
|
|
|
|
|
nsCOMPtr<nsITreeColumns> cols;
|
|
|
|
mTree->GetColumns(getter_AddRefs(cols));
|
|
|
|
nsCOMPtr<nsITreeColumn> primaryCol;
|
|
|
|
if (cols)
|
|
|
|
cols->GetPrimaryColumn(getter_AddRefs(primaryCol));
|
|
|
|
|
2010-09-04 19:14:01 -07:00
|
|
|
return primaryCol ?
|
2010-08-18 19:14:50 -07:00
|
|
|
static_cast<PRUint32>(nsIAccessibleRole::ROLE_OUTLINE) :
|
|
|
|
static_cast<PRUint32>(nsIAccessibleRole::ROLE_LIST);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: nsIAccessible implementation
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeAccessible::GetFocusedChild(nsIAccessible **aFocusedChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aFocusedChild);
|
|
|
|
*aFocusedChild = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
if (gLastFocusedNode != mContent)
|
2009-08-19 23:45:19 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
|
2010-06-11 01:23:18 -07:00
|
|
|
do_QueryInterface(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (multiSelect) {
|
2009-08-19 23:45:19 -07:00
|
|
|
PRInt32 row = -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
multiSelect->GetCurrentIndex(&row);
|
2009-08-19 23:45:19 -07:00
|
|
|
if (row >= 0)
|
2010-03-10 02:26:11 -08:00
|
|
|
NS_IF_ADDREF(*aFocusedChild = GetTreeItemAccessible(row));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: nsAccessible implementation (DON'T put methods here)
|
|
|
|
|
2009-05-11 03:57:28 -07:00
|
|
|
nsresult
|
|
|
|
nsXULTreeAccessible::GetChildAtPoint(PRInt32 aX, PRInt32 aY,
|
|
|
|
PRBool aDeepestChild,
|
|
|
|
nsIAccessible **aChild)
|
2007-09-05 01:00:40 -07:00
|
|
|
{
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (!frame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsPresContext *presContext = frame->PresContext();
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = presContext->PresShell();
|
|
|
|
|
|
|
|
nsIFrame *rootFrame = presShell->GetRootFrame();
|
|
|
|
NS_ENSURE_STATE(rootFrame);
|
|
|
|
|
|
|
|
nsIntRect rootRect = rootFrame->GetScreenRectExternal();
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
PRInt32 clientX = presContext->DevPixelsToIntCSSPixels(aX - rootRect.x);
|
|
|
|
PRInt32 clientY = presContext->DevPixelsToIntCSSPixels(aY - rootRect.y);
|
2007-09-05 01:00:40 -07:00
|
|
|
|
|
|
|
PRInt32 row = -1;
|
|
|
|
nsCOMPtr<nsITreeColumn> column;
|
|
|
|
nsCAutoString childEltUnused;
|
|
|
|
mTree->GetCellAt(clientX, clientY, &row, getter_AddRefs(column),
|
|
|
|
childEltUnused);
|
|
|
|
|
|
|
|
// If we failed to find tree cell for the given point then it might be
|
|
|
|
// tree columns.
|
|
|
|
if (row == -1 || !column)
|
2010-09-01 17:46:59 -07:00
|
|
|
return nsAccessibleWrap::GetChildAtPoint(aX, aY, aDeepestChild, aChild);
|
2009-05-11 03:57:28 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible *child = GetTreeItemAccessible(row);
|
|
|
|
if (aDeepestChild && child) {
|
2009-08-19 23:45:19 -07:00
|
|
|
// Look for accessible cell for the found item accessible.
|
2010-05-11 02:48:10 -07:00
|
|
|
nsRefPtr<nsXULTreeItemAccessibleBase> treeitem = do_QueryObject(child);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible *cell = treeitem->GetCellAccessible(column);
|
|
|
|
if (cell)
|
|
|
|
child = cell;
|
2009-08-19 23:45:19 -07:00
|
|
|
}
|
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
NS_IF_ADDREF(*aChild = child);
|
2009-05-11 03:57:28 -07:00
|
|
|
return NS_OK;
|
2007-09-05 01:00:40 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-09-01 17:46:59 -07:00
|
|
|
// nsXULTreeAccessible: SelectAccessible
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
bool
|
|
|
|
nsXULTreeAccessible::IsSelect()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-01 17:46:59 -07:00
|
|
|
return true;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
already_AddRefed<nsIArray>
|
|
|
|
nsXULTreeAccessible::SelectedItems()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (!selection)
|
2010-09-01 17:46:59 -07:00
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMutableArray> selectedItems =
|
2007-03-22 10:30:00 -07:00
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID);
|
2010-09-01 17:46:59 -07:00
|
|
|
if (!selectedItems)
|
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRInt32 rowIndex, rowCount;
|
|
|
|
PRBool isSelected;
|
|
|
|
mTreeView->GetRowCount(&rowCount);
|
|
|
|
for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
|
|
|
selection->IsSelected(rowIndex, &isSelected);
|
|
|
|
if (isSelected) {
|
2010-09-01 17:46:59 -07:00
|
|
|
nsIAccessible* item = GetTreeItemAccessible(rowIndex);
|
|
|
|
if (item)
|
|
|
|
selectedItems->AppendElement(item, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
nsIMutableArray* items = nsnull;
|
|
|
|
selectedItems.forget(&items);
|
|
|
|
return items;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
PRUint32
|
|
|
|
nsXULTreeAccessible::SelectedItemCount()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
2010-09-01 17:46:59 -07:00
|
|
|
if (selection) {
|
|
|
|
PRInt32 count = 0;
|
|
|
|
selection->GetCount(&count);
|
|
|
|
return count;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
bool
|
|
|
|
nsXULTreeAccessible::AddItemToSelection(PRUint32 aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
2010-09-01 17:46:59 -07:00
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
selection->IsSelected(aIndex, &isSelected);
|
|
|
|
if (!isSelected)
|
|
|
|
selection->ToggleSelect(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
bool
|
|
|
|
nsXULTreeAccessible::RemoveItemFromSelection(PRUint32 aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-01 17:46:59 -07:00
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
selection->IsSelected(aIndex, &isSelected);
|
|
|
|
if (isSelected)
|
|
|
|
selection->ToggleSelect(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
bool
|
|
|
|
nsXULTreeAccessible::IsItemSelected(PRUint32 aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-01 17:46:59 -07:00
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
selection->IsSelected(aIndex, &isSelected);
|
|
|
|
return isSelected;
|
|
|
|
}
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
bool
|
|
|
|
nsXULTreeAccessible::UnselectAll()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
2010-09-01 17:46:59 -07:00
|
|
|
if (!selection)
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
selection->ClearSelection();
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
nsAccessible*
|
|
|
|
nsXULTreeAccessible::GetSelectedItem(PRUint32 aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (!selection)
|
2010-09-01 17:46:59 -07:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRInt32 rowIndex, rowCount;
|
|
|
|
PRInt32 selCount = 0;
|
|
|
|
PRBool isSelected;
|
|
|
|
mTreeView->GetRowCount(&rowCount);
|
|
|
|
for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
|
|
|
selection->IsSelected(rowIndex, &isSelected);
|
|
|
|
if (isSelected) {
|
2010-09-01 17:46:59 -07:00
|
|
|
if (selCount == aIndex)
|
|
|
|
return GetTreeItemAccessible(rowIndex);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
selCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
bool
|
|
|
|
nsXULTreeAccessible::SelectAll()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// see if we are multiple select if so set ourselves as such
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
|
|
|
PRBool single = PR_FALSE;
|
|
|
|
selection->GetSingle(&single);
|
|
|
|
if (!single) {
|
|
|
|
selection->SelectAll();
|
2010-09-01 17:46:59 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: nsAccessible implementation
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible*
|
2009-12-10 11:12:19 -08:00
|
|
|
nsXULTreeAccessible::GetChildAt(PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
PRInt32 childCount = nsAccessible::GetChildCount();
|
|
|
|
if (childCount == -1)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
if (static_cast<PRInt32>(aIndex) < childCount)
|
|
|
|
return nsAccessible::GetChildAt(aIndex);
|
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
return GetTreeItemAccessible(aIndex - childCount);
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsXULTreeAccessible::GetChildCount()
|
|
|
|
{
|
|
|
|
// tree's children count is row count + treecols count.
|
|
|
|
PRInt32 childCount = nsAccessible::GetChildCount();
|
|
|
|
if (childCount == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
mTreeView->GetRowCount(&rowCount);
|
|
|
|
childCount += rowCount;
|
|
|
|
|
|
|
|
return childCount;
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: public implementation
|
2009-06-29 08:38:17 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible*
|
|
|
|
nsXULTreeAccessible::GetTreeItemAccessible(PRInt32 aRow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-11-29 21:59:09 -08:00
|
|
|
if (aRow < 0 || IsDefunct())
|
2010-03-10 02:26:11 -08:00
|
|
|
return nsnull;
|
2007-09-18 19:54:44 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
nsresult rv = mTreeView->GetRowCount(&rowCount);
|
|
|
|
if (NS_FAILED(rv) || aRow >= rowCount)
|
2010-03-10 02:26:11 -08:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
void *key = reinterpret_cast<void*>(aRow);
|
2010-03-10 02:26:11 -08:00
|
|
|
nsRefPtr<nsAccessible> accessible = mAccessibleCache.GetWeak(key);
|
2009-06-29 08:38:17 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
if (!accessible) {
|
|
|
|
accessible = CreateTreeItemAccessible(aRow);
|
|
|
|
if (!accessible)
|
|
|
|
return nsnull;
|
2008-10-31 20:58:07 -07:00
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
if (!accessible->Init()) {
|
2010-03-10 02:26:11 -08:00
|
|
|
accessible->Shutdown();
|
|
|
|
return nsnull;
|
|
|
|
}
|
2008-10-31 20:58:07 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
if (!mAccessibleCache.Put(key, accessible))
|
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-06-29 08:38:17 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
return accessible;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-06-29 08:38:17 -07:00
|
|
|
void
|
2007-12-11 00:18:04 -08:00
|
|
|
nsXULTreeAccessible::InvalidateCache(PRInt32 aRow, PRInt32 aCount)
|
|
|
|
{
|
2009-06-29 08:38:17 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return;
|
|
|
|
|
2007-12-11 00:18:04 -08:00
|
|
|
// Do not invalidate the cache if rows have been inserted.
|
|
|
|
if (aCount > 0)
|
2009-06-29 08:38:17 -07:00
|
|
|
return;
|
2008-01-18 11:55:37 -08:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// Fire destroy event for removed tree items and delete them from caches.
|
2007-12-11 00:18:04 -08:00
|
|
|
for (PRInt32 rowIdx = aRow; rowIdx < aRow - aCount; rowIdx++) {
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-02-11 05:58:35 -08:00
|
|
|
void* key = reinterpret_cast<void*>(rowIdx);
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible *accessible = mAccessibleCache.GetWeak(key);
|
2007-12-11 00:18:04 -08:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
if (accessible) {
|
2010-08-24 19:08:28 -07:00
|
|
|
nsRefPtr<AccEvent> event =
|
2010-10-20 21:16:10 -07:00
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_HIDE, accessible);
|
2010-01-18 08:17:01 -08:00
|
|
|
nsEventShell::FireEvent(event);
|
2007-12-11 00:18:04 -08:00
|
|
|
|
2010-10-20 21:16:10 -07:00
|
|
|
// Shutdown and remove accessible from document cache and tree cache.
|
2010-06-11 21:04:50 -07:00
|
|
|
nsDocAccessible *docAccessible = GetDocAccessible();
|
|
|
|
if (docAccessible)
|
2010-10-20 21:16:10 -07:00
|
|
|
docAccessible->ShutdownAccessible(accessible);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
mAccessibleCache.Remove(key);
|
2007-12-11 00:18:04 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// We dealt with removed tree items already however we may keep tree items
|
|
|
|
// having row indexes greater than row count. We should remove these dead tree
|
|
|
|
// items silently from caches.
|
2007-12-11 00:18:04 -08:00
|
|
|
PRInt32 newRowCount = 0;
|
2009-08-19 23:45:19 -07:00
|
|
|
nsresult rv = mTreeView->GetRowCount(&newRowCount);
|
2009-06-29 08:38:17 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
2007-12-11 00:18:04 -08:00
|
|
|
|
|
|
|
PRInt32 oldRowCount = newRowCount - aCount;
|
|
|
|
|
|
|
|
for (PRInt32 rowIdx = newRowCount; rowIdx < oldRowCount; ++rowIdx) {
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-02-11 05:58:35 -08:00
|
|
|
void *key = reinterpret_cast<void*>(rowIdx);
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible *accessible = mAccessibleCache.GetWeak(key);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
if (accessible) {
|
2010-10-20 21:16:10 -07:00
|
|
|
// Shutdown and remove accessible from document cache and tree cache.
|
2010-06-11 21:04:50 -07:00
|
|
|
nsDocAccessible *docAccessible = GetDocAccessible();
|
|
|
|
if (docAccessible)
|
2010-10-20 21:16:10 -07:00
|
|
|
docAccessible->ShutdownAccessible(accessible);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
mAccessibleCache.Remove(key);
|
2007-12-11 00:18:04 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-29 08:38:17 -07:00
|
|
|
void
|
2008-02-08 04:55:57 -08:00
|
|
|
nsXULTreeAccessible::TreeViewInvalidated(PRInt32 aStartRow, PRInt32 aEndRow,
|
|
|
|
PRInt32 aStartCol, PRInt32 aEndCol)
|
|
|
|
{
|
2009-06-29 08:38:17 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return;
|
2008-02-08 04:55:57 -08:00
|
|
|
|
2008-06-15 23:16:18 -07:00
|
|
|
PRInt32 endRow = aEndRow;
|
2008-02-08 04:55:57 -08:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if (endRow == -1) {
|
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
rv = mTreeView->GetRowCount(&rowCount);
|
2009-06-29 08:38:17 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
2008-02-08 04:55:57 -08:00
|
|
|
|
|
|
|
endRow = rowCount - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsITreeColumns> treeColumns;
|
|
|
|
mTree->GetColumns(getter_AddRefs(treeColumns));
|
2009-06-29 08:38:17 -07:00
|
|
|
if (!treeColumns)
|
|
|
|
return;
|
2008-02-08 04:55:57 -08:00
|
|
|
|
2008-06-15 23:16:18 -07:00
|
|
|
PRInt32 endCol = aEndCol;
|
|
|
|
|
2008-02-08 04:55:57 -08:00
|
|
|
if (endCol == -1) {
|
|
|
|
PRInt32 colCount = 0;
|
|
|
|
rv = treeColumns->GetCount(&colCount);
|
2009-06-29 08:38:17 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
2008-02-08 04:55:57 -08:00
|
|
|
|
|
|
|
endCol = colCount - 1;
|
|
|
|
}
|
2009-05-12 22:21:21 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
for (PRInt32 rowIdx = aStartRow; rowIdx <= endRow; ++rowIdx) {
|
2009-06-29 08:38:17 -07:00
|
|
|
|
2010-02-11 05:58:35 -08:00
|
|
|
void *key = reinterpret_cast<void*>(rowIdx);
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible *accessible = mAccessibleCache.GetWeak(key);
|
2008-02-08 04:55:57 -08:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
if (accessible) {
|
2010-05-11 02:48:10 -07:00
|
|
|
nsRefPtr<nsXULTreeItemAccessibleBase> treeitemAcc = do_QueryObject(accessible);
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_ASSERTION(treeitemAcc, "Wrong accessible at the given key!");
|
|
|
|
|
|
|
|
treeitemAcc->RowInvalidated(aStartCol, endCol);
|
2008-02-08 04:55:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-29 08:38:17 -07:00
|
|
|
void
|
2008-06-15 23:16:18 -07:00
|
|
|
nsXULTreeAccessible::TreeViewChanged()
|
|
|
|
{
|
2009-06-29 08:38:17 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return;
|
2008-06-15 23:16:18 -07:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// in cache.
|
2010-08-24 19:08:28 -07:00
|
|
|
nsRefPtr<AccEvent> eventDestroy =
|
2010-10-20 21:16:10 -07:00
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_HIDE, this);
|
2009-06-29 08:38:17 -07:00
|
|
|
if (!eventDestroy)
|
|
|
|
return;
|
2008-06-15 23:16:18 -07:00
|
|
|
|
2009-06-29 08:38:17 -07:00
|
|
|
FirePlatformEvent(eventDestroy);
|
2008-06-15 23:16:18 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
ClearCache(mAccessibleCache);
|
2008-06-15 23:16:18 -07:00
|
|
|
|
|
|
|
mTree->GetView(getter_AddRefs(mTreeView));
|
|
|
|
|
2010-08-24 19:08:28 -07:00
|
|
|
nsRefPtr<AccEvent> eventCreate =
|
2010-10-20 21:16:10 -07:00
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_SHOW, this);
|
2009-06-29 08:38:17 -07:00
|
|
|
if (!eventCreate)
|
|
|
|
return;
|
2008-06-15 23:16:18 -07:00
|
|
|
|
2009-06-29 08:38:17 -07:00
|
|
|
FirePlatformEvent(eventCreate);
|
2008-06-15 23:16:18 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: protected implementation
|
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
already_AddRefed<nsAccessible>
|
|
|
|
nsXULTreeAccessible::CreateTreeItemAccessible(PRInt32 aRow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-10 02:26:11 -08:00
|
|
|
nsRefPtr<nsAccessible> accessible =
|
2010-06-11 01:23:18 -07:00
|
|
|
new nsXULTreeItemAccessible(mContent, mWeakShell, this, mTree, mTreeView,
|
2010-03-10 02:26:11 -08:00
|
|
|
aRow);
|
|
|
|
|
|
|
|
return accessible.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-08-19 23:45:19 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessibleBase
|
2008-06-15 23:16:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
nsXULTreeItemAccessibleBase::
|
2010-06-11 01:23:18 -07:00
|
|
|
nsXULTreeItemAccessibleBase(nsIContent *aContent, nsIWeakReference *aShell,
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible *aParent, nsITreeBoxObject *aTree,
|
2009-08-19 23:45:19 -07:00
|
|
|
nsITreeView *aTreeView, PRInt32 aRow) :
|
2010-07-16 07:15:07 -07:00
|
|
|
nsAccessibleWrap(aContent, aShell),
|
|
|
|
mTree(aTree), mTreeView(aTreeView), mRow(aRow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
mParent = aParent;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessibleBase: nsISupports implementation
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeItemAccessibleBase,
|
|
|
|
nsAccessible,
|
|
|
|
nsXULTreeItemAccessibleBase)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessibleBase: nsIAccessible implementation
|
2009-06-29 08:38:17 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeItemAccessibleBase::GetFocusedChild(nsIAccessible **aFocusedChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aFocusedChild);
|
|
|
|
*aFocusedChild = nsnull;
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
if (gLastFocusedNode != mContent)
|
2009-08-19 23:45:19 -07:00
|
|
|
return NS_OK;
|
2007-12-14 20:40:57 -08:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
|
2010-06-11 01:23:18 -07:00
|
|
|
do_QueryInterface(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
if (multiSelect) {
|
|
|
|
PRInt32 row = -1;
|
|
|
|
multiSelect->GetCurrentIndex(&row);
|
|
|
|
if (row == mRow)
|
|
|
|
NS_ADDREF(*aFocusedChild = this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeItemAccessibleBase::GetBounds(PRInt32 *aX, PRInt32 *aY,
|
|
|
|
PRInt32 *aWidth, PRInt32 *aHeight)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aX);
|
|
|
|
*aX = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aY);
|
|
|
|
*aY = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
|
|
|
*aWidth = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aHeight);
|
|
|
|
*aHeight = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// Get x coordinate and width from treechildren element, get y coordinate and
|
|
|
|
// height from tree cell.
|
2007-05-06 07:50:03 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
nsCOMPtr<nsIBoxObject> boxObj = nsCoreUtils::GetTreeBodyBoxObject(mTree);
|
|
|
|
NS_ENSURE_STATE(boxObj);
|
|
|
|
|
|
|
|
nsCOMPtr<nsITreeColumn> column = nsCoreUtils::GetFirstSensibleColumn(mTree);
|
|
|
|
|
|
|
|
PRInt32 x = 0, y = 0, width = 0, height = 0;
|
|
|
|
nsresult rv = mTree->GetCoordsForCellItem(mRow, column, EmptyCString(),
|
|
|
|
&x, &y, &width, &height);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
boxObj->GetWidth(&width);
|
|
|
|
|
|
|
|
PRInt32 tcX = 0, tcY = 0;
|
|
|
|
boxObj->GetScreenX(&tcX);
|
|
|
|
boxObj->GetScreenY(&tcY);
|
|
|
|
|
|
|
|
x = tcX;
|
|
|
|
y += tcY;
|
|
|
|
|
|
|
|
nsPresContext *presContext = GetPresContext();
|
|
|
|
*aX = presContext->CSSPixelsToDevPixels(x);
|
|
|
|
*aY = presContext->CSSPixelsToDevPixels(y);
|
|
|
|
*aWidth = presContext->CSSPixelsToDevPixels(width);
|
|
|
|
*aHeight = presContext->CSSPixelsToDevPixels(height);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeItemAccessibleBase::SetSelected(PRBool aSelect)
|
|
|
|
{
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
|
|
|
PRBool isSelected;
|
|
|
|
selection->IsSelected(mRow, &isSelected);
|
|
|
|
if (isSelected != aSelect)
|
|
|
|
selection->ToggleSelect(mRow);
|
2007-05-06 07:50:03 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeItemAccessibleBase::TakeFocus()
|
2007-12-21 19:17:31 -08:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-12-21 19:17:31 -08:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection)
|
|
|
|
selection->SetCurrentIndex(mRow);
|
2009-03-18 01:21:13 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// focus event will be fired here
|
|
|
|
return nsAccessible::TakeFocus();
|
2007-12-21 19:17:31 -08:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeItemAccessibleBase::GetRelationByType(PRUint32 aRelationType,
|
|
|
|
nsIAccessibleRelation **aRelation)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aRelation);
|
|
|
|
*aRelation = nsnull;
|
|
|
|
|
2007-12-21 19:17:31 -08:00
|
|
|
if (IsDefunct())
|
2009-08-19 23:45:19 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-12-21 19:17:31 -08:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
if (aRelationType == nsIAccessibleRelation::RELATION_NODE_CHILD_OF) {
|
|
|
|
PRInt32 parentIndex;
|
|
|
|
if (NS_SUCCEEDED(mTreeView->GetParentIndex(mRow, &parentIndex))) {
|
|
|
|
if (parentIndex == -1)
|
|
|
|
return nsRelUtils::AddTarget(aRelationType, aRelation, mParent);
|
|
|
|
|
2010-04-26 20:16:41 -07:00
|
|
|
nsRefPtr<nsXULTreeAccessible> treeAcc = do_QueryObject(mParent);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible *logicalParent = treeAcc->GetTreeItemAccessible(parentIndex);
|
2009-08-19 23:45:19 -07:00
|
|
|
return nsRelUtils::AddTarget(aRelationType, aRelation, logicalParent);
|
2007-09-05 06:35:35 -07:00
|
|
|
}
|
2009-08-19 23:45:19 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-09-05 06:35:35 -07:00
|
|
|
}
|
2009-08-19 23:45:19 -07:00
|
|
|
|
|
|
|
return nsAccessible::GetRelationByType(aRelationType, aRelation);
|
2007-09-05 06:35:35 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeItemAccessibleBase::GetNumActions(PRUint8 *aActionsCount)
|
2007-09-05 06:35:35 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aActionsCount);
|
|
|
|
*aActionsCount = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-21 19:17:31 -08:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// "activate" action is available for all treeitems, "expand/collapse" action
|
|
|
|
// is avaible for treeitem which is container.
|
|
|
|
*aActionsCount = IsExpandable() ? 2 : 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeItemAccessibleBase::GetActionName(PRUint8 aIndex, nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-21 19:17:31 -08:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aIndex == eAction_Click) {
|
2009-08-19 23:45:19 -07:00
|
|
|
aName.AssignLiteral("activate");
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-08-19 23:45:19 -07:00
|
|
|
|
|
|
|
if (aIndex == eAction_Expand && IsExpandable()) {
|
2007-09-05 06:35:35 -07:00
|
|
|
PRBool isContainerOpen;
|
|
|
|
mTreeView->IsContainerOpen(mRow, &isContainerOpen);
|
|
|
|
if (isContainerOpen)
|
|
|
|
aName.AssignLiteral("collapse");
|
|
|
|
else
|
|
|
|
aName.AssignLiteral("expand");
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULTreeItemAccessibleBase::DoAction(PRUint8 aIndex)
|
2007-03-27 05:17:11 -07:00
|
|
|
{
|
2007-12-21 19:17:31 -08:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
if (aIndex != eAction_Click &&
|
|
|
|
(aIndex != eAction_Expand || !IsExpandable()))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2010-01-25 07:09:25 -08:00
|
|
|
DoCommand(nsnull, aIndex);
|
|
|
|
return NS_OK;
|
2009-08-19 23:45:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessibleBase: nsAccessNode implementation
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsXULTreeItemAccessibleBase::IsDefunct()
|
|
|
|
{
|
|
|
|
if (nsAccessibleWrap::IsDefunct() || !mTree || !mTreeView || mRow < 0)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
nsresult rv = mTreeView->GetRowCount(&rowCount);
|
|
|
|
return NS_FAILED(rv) || mRow >= rowCount;
|
|
|
|
}
|
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
void
|
2009-08-19 23:45:19 -07:00
|
|
|
nsXULTreeItemAccessibleBase::Shutdown()
|
|
|
|
{
|
|
|
|
mTree = nsnull;
|
|
|
|
mTreeView = nsnull;
|
|
|
|
mRow = -1;
|
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
nsAccessibleWrap::Shutdown();
|
2009-08-19 23:45:19 -07:00
|
|
|
}
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2010-10-20 21:16:10 -07:00
|
|
|
bool
|
|
|
|
nsXULTreeItemAccessibleBase::IsPrimaryForNode() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-12-10 11:12:19 -08:00
|
|
|
// nsXULTreeItemAccessibleBase: nsAccessible public methods
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
// nsIAccessible::groupPosition
|
2009-08-19 23:45:19 -07:00
|
|
|
nsresult
|
2010-01-06 02:36:50 -08:00
|
|
|
nsXULTreeItemAccessibleBase::GroupPosition(PRInt32 *aGroupLevel,
|
|
|
|
PRInt32 *aSimilarItemsInGroup,
|
|
|
|
PRInt32 *aPositionInGroup)
|
2009-08-19 23:45:19 -07:00
|
|
|
{
|
2010-01-06 02:36:50 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aGroupLevel);
|
|
|
|
*aGroupLevel = 0;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aSimilarItemsInGroup);
|
|
|
|
*aSimilarItemsInGroup = 0;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aPositionInGroup);
|
|
|
|
*aPositionInGroup = 0;
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-27 05:17:11 -07:00
|
|
|
|
|
|
|
PRInt32 level;
|
2009-08-19 23:45:19 -07:00
|
|
|
nsresult rv = mTreeView->GetLevel(mRow, &level);
|
2007-03-27 05:17:11 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-08-22 20:26:53 -07:00
|
|
|
PRInt32 topCount = 1;
|
|
|
|
for (PRInt32 index = mRow - 1; index >= 0; index--) {
|
|
|
|
PRInt32 lvl = -1;
|
2009-08-19 23:45:19 -07:00
|
|
|
if (NS_SUCCEEDED(mTreeView->GetLevel(index, &lvl))) {
|
2007-08-22 20:26:53 -07:00
|
|
|
if (lvl < level)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (lvl == level)
|
|
|
|
topCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 rowCount = 0;
|
2009-08-19 23:45:19 -07:00
|
|
|
rv = mTreeView->GetRowCount(&rowCount);
|
2007-08-22 20:26:53 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 bottomCount = 0;
|
|
|
|
for (PRInt32 index = mRow + 1; index < rowCount; index++) {
|
|
|
|
PRInt32 lvl = -1;
|
2009-08-19 23:45:19 -07:00
|
|
|
if (NS_SUCCEEDED(mTreeView->GetLevel(index, &lvl))) {
|
2007-08-22 20:26:53 -07:00
|
|
|
if (lvl < level)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (lvl == level)
|
|
|
|
bottomCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 setSize = topCount + bottomCount;
|
|
|
|
PRInt32 posInSet = topCount;
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
*aGroupLevel = level + 1;
|
|
|
|
*aSimilarItemsInGroup = setSize;
|
|
|
|
*aPositionInGroup = posInSet;
|
|
|
|
|
2007-03-27 05:17:11 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
nsresult
|
|
|
|
nsXULTreeItemAccessibleBase::GetStateInternal(PRUint32 *aState,
|
|
|
|
PRUint32 *aExtraState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
*aState = 0;
|
|
|
|
if (aExtraState)
|
|
|
|
*aExtraState = 0;
|
2007-12-21 19:17:31 -08:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
if (IsDefunct()) {
|
|
|
|
if (aExtraState)
|
|
|
|
*aExtraState = nsIAccessibleStates::EXT_STATE_DEFUNCT;
|
|
|
|
return NS_OK_DEFUNCT_OBJECT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// focusable and selectable states
|
|
|
|
*aState = nsIAccessibleStates::STATE_FOCUSABLE |
|
|
|
|
nsIAccessibleStates::STATE_SELECTABLE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// expanded/collapsed state
|
|
|
|
if (IsExpandable()) {
|
|
|
|
PRBool isContainerOpen;
|
|
|
|
mTreeView->IsContainerOpen(mRow, &isContainerOpen);
|
|
|
|
*aState |= isContainerOpen ?
|
2010-08-18 19:14:50 -07:00
|
|
|
static_cast<PRUint32>(nsIAccessibleStates::STATE_EXPANDED) :
|
|
|
|
static_cast<PRUint32>(nsIAccessibleStates::STATE_COLLAPSED);
|
2009-08-19 23:45:19 -07:00
|
|
|
}
|
2009-06-29 08:38:17 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// selected state
|
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
|
|
|
PRBool isSelected;
|
|
|
|
selection->IsSelected(mRow, &isSelected);
|
|
|
|
if (isSelected)
|
|
|
|
*aState |= nsIAccessibleStates::STATE_SELECTED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// focused state
|
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
|
2010-06-11 01:23:18 -07:00
|
|
|
do_QueryInterface(mContent);
|
2009-08-19 23:45:19 -07:00
|
|
|
if (multiSelect) {
|
|
|
|
PRInt32 currentIndex;
|
|
|
|
multiSelect->GetCurrentIndex(¤tIndex);
|
|
|
|
if (currentIndex == mRow) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_FOCUSED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// invisible state
|
|
|
|
PRInt32 firstVisibleRow, lastVisibleRow;
|
|
|
|
mTree->GetFirstVisibleRow(&firstVisibleRow);
|
|
|
|
mTree->GetLastVisibleRow(&lastVisibleRow);
|
|
|
|
if (mRow < firstVisibleRow || mRow > lastVisibleRow)
|
|
|
|
*aState |= nsIAccessibleStates::STATE_INVISIBLE;
|
|
|
|
|
2009-06-29 08:38:17 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-12-10 11:12:19 -08:00
|
|
|
// nsXULTreeItemAccessibleBase: nsAccessible protected methods
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
void
|
|
|
|
nsXULTreeItemAccessibleBase::DispatchClickEvent(nsIContent *aContent,
|
|
|
|
PRUint32 aActionIndex)
|
|
|
|
{
|
2007-12-21 19:17:31 -08:00
|
|
|
if (IsDefunct())
|
2009-08-19 23:45:19 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
nsCOMPtr<nsITreeColumns> columns;
|
|
|
|
mTree->GetColumns(getter_AddRefs(columns));
|
|
|
|
if (!columns)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// Get column and pseudo element.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsITreeColumn> column;
|
2009-08-19 23:45:19 -07:00
|
|
|
nsCAutoString pseudoElm;
|
|
|
|
|
|
|
|
if (aActionIndex == eAction_Click) {
|
|
|
|
// Key column is visible and clickable.
|
|
|
|
columns->GetKeyColumn(getter_AddRefs(column));
|
|
|
|
} else {
|
|
|
|
// Primary column contains a twisty we should click on.
|
|
|
|
columns->GetPrimaryColumn(getter_AddRefs(column));
|
|
|
|
pseudoElm = NS_LITERAL_CSTRING("twisty");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
if (column)
|
|
|
|
nsCoreUtils::DispatchClickEvent(mTree, mRow, column, pseudoElm);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible*
|
2009-12-10 11:12:19 -08:00
|
|
|
nsXULTreeItemAccessibleBase::GetSiblingAtOffset(PRInt32 aOffset,
|
|
|
|
nsresult* aError)
|
|
|
|
{
|
|
|
|
if (IsDefunct()) {
|
|
|
|
if (aError)
|
|
|
|
*aError = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aError)
|
|
|
|
*aError = NS_OK; // fail peacefully
|
|
|
|
|
2010-07-01 18:22:41 -07:00
|
|
|
return mParent->GetChildAt(GetIndexInParent() + aOffset);
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessibleBase: protected implementation
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
PRBool
|
|
|
|
nsXULTreeItemAccessibleBase::IsExpandable()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
PRBool isContainer = PR_FALSE;
|
|
|
|
mTreeView->IsContainer(mRow, &isContainer);
|
|
|
|
if (isContainer) {
|
|
|
|
PRBool isEmpty = PR_FALSE;
|
|
|
|
mTreeView->IsContainerEmpty(mRow, &isEmpty);
|
|
|
|
if (!isEmpty) {
|
|
|
|
nsCOMPtr<nsITreeColumns> columns;
|
|
|
|
mTree->GetColumns(getter_AddRefs(columns));
|
|
|
|
nsCOMPtr<nsITreeColumn> primaryColumn;
|
|
|
|
if (columns) {
|
|
|
|
columns->GetPrimaryColumn(getter_AddRefs(primaryColumn));
|
2010-06-25 04:49:02 -07:00
|
|
|
if (primaryColumn &&
|
|
|
|
!nsCoreUtils::IsColumnHidden(primaryColumn))
|
2009-08-19 23:45:19 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-05-06 02:54:26 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
nsXULTreeItemAccessible::
|
2010-06-11 01:23:18 -07:00
|
|
|
nsXULTreeItemAccessible(nsIContent *aContent, nsIWeakReference *aShell,
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible *aParent, nsITreeBoxObject *aTree,
|
|
|
|
nsITreeView *aTreeView, PRInt32 aRow) :
|
2010-06-11 01:23:18 -07:00
|
|
|
nsXULTreeItemAccessibleBase(aContent, aShell, aParent, aTree, aTreeView, aRow)
|
2009-08-19 23:45:19 -07:00
|
|
|
{
|
|
|
|
mColumn = nsCoreUtils::GetFirstSensibleColumn(mTree);
|
|
|
|
}
|
2009-05-06 02:54:26 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessible: nsIAccessible implementation
|
2009-05-06 02:54:26 -07:00
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
NS_IMETHODIMP
|
2009-08-19 23:45:19 -07:00
|
|
|
nsXULTreeItemAccessible::GetName(nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
aName.Truncate();
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2007-12-21 19:17:31 -08:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
mTreeView->GetCellText(mRow, mColumn, aName);
|
|
|
|
|
|
|
|
// If there is still no name try the cell value:
|
|
|
|
// This is for graphical cells. We need tree/table view implementors to implement
|
|
|
|
// FooView::GetCellValue to return a meaningful string for cases where there is
|
|
|
|
// something shown in the cell (non-text) such as a star icon; in which case
|
|
|
|
// GetCellValue for that cell would return "starred" or "flagged" for example.
|
|
|
|
if (aName.IsEmpty())
|
|
|
|
mTreeView->GetCellValue(mRow, mColumn, aName);
|
2009-06-29 08:38:17 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessible: nsAccessNode implementation
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
PRBool
|
|
|
|
nsXULTreeItemAccessible::IsDefunct()
|
|
|
|
{
|
|
|
|
return nsXULTreeItemAccessibleBase::IsDefunct() || !mColumn;
|
|
|
|
}
|
2008-02-08 18:14:03 -08:00
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
PRBool
|
2009-08-19 23:45:19 -07:00
|
|
|
nsXULTreeItemAccessible::Init()
|
|
|
|
{
|
2010-06-11 21:04:35 -07:00
|
|
|
if (!nsXULTreeItemAccessibleBase::Init())
|
|
|
|
return PR_FALSE;
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
GetName(mCachedName);
|
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
void
|
2009-08-19 23:45:19 -07:00
|
|
|
nsXULTreeItemAccessible::Shutdown()
|
2008-02-08 04:55:57 -08:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
mColumn = nsnull;
|
2010-06-11 21:04:35 -07:00
|
|
|
nsXULTreeItemAccessibleBase::Shutdown();
|
2009-08-19 23:45:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessible: nsAccessible implementation
|
|
|
|
|
2010-09-04 19:14:01 -07:00
|
|
|
PRUint32
|
|
|
|
nsXULTreeItemAccessible::NativeRole()
|
2009-08-19 23:45:19 -07:00
|
|
|
{
|
2010-03-18 18:24:41 -07:00
|
|
|
nsCOMPtr<nsITreeColumns> columns;
|
|
|
|
mTree->GetColumns(getter_AddRefs(columns));
|
2010-09-04 19:14:01 -07:00
|
|
|
if (!columns) {
|
|
|
|
NS_ERROR("No tree columns object in the tree!");
|
|
|
|
return nsIAccessibleRole::ROLE_NOTHING;
|
|
|
|
}
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-03-18 18:24:41 -07:00
|
|
|
nsCOMPtr<nsITreeColumn> primaryColumn;
|
|
|
|
columns->GetPrimaryColumn(getter_AddRefs(primaryColumn));
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-09-04 19:14:01 -07:00
|
|
|
return primaryColumn ?
|
2010-08-18 19:14:50 -07:00
|
|
|
static_cast<PRUint32>(nsIAccessibleRole::ROLE_OUTLINEITEM) :
|
|
|
|
static_cast<PRUint32>(nsIAccessibleRole::ROLE_LISTITEM);
|
2008-02-08 04:55:57 -08:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessible: nsXULTreeItemAccessibleBase implementation
|
|
|
|
|
2009-06-29 08:38:17 -07:00
|
|
|
void
|
2009-08-19 23:45:19 -07:00
|
|
|
nsXULTreeItemAccessible::RowInvalidated(PRInt32 aStartColIdx,
|
|
|
|
PRInt32 aEndColIdx)
|
2008-02-08 04:55:57 -08:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
nsAutoString name;
|
|
|
|
GetName(name);
|
|
|
|
|
|
|
|
if (name != mCachedName) {
|
2010-01-18 08:16:07 -08:00
|
|
|
nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_NAME_CHANGE, this);
|
2009-08-19 23:45:19 -07:00
|
|
|
mCachedName = name;
|
|
|
|
}
|
2008-02-08 04:55:57 -08:00
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessible: nsAccessible protected implementation
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULTreeItemAccessible::CacheChildren()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2007-09-18 20:31:14 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeColumnsAccessible
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-09-18 20:31:14 -07:00
|
|
|
nsXULTreeColumnsAccessible::
|
2010-06-11 01:23:18 -07:00
|
|
|
nsXULTreeColumnsAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
|
|
|
nsXULColumnsAccessible(aContent, aShell)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible*
|
2009-12-10 11:12:19 -08:00
|
|
|
nsXULTreeColumnsAccessible::GetSiblingAtOffset(PRInt32 aOffset,
|
|
|
|
nsresult* aError)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
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
|
2008-03-19 23:19:48 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsITreeBoxObject> tree = nsCoreUtils::GetTreeBoxObject(mContent);
|
2008-03-19 23:19:48 -07:00
|
|
|
if (tree) {
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsITreeView> treeView;
|
2008-03-19 23:19:48 -07:00
|
|
|
tree->GetView(getter_AddRefs(treeView));
|
|
|
|
if (treeView) {
|
2009-08-19 23:45:19 -07:00
|
|
|
PRInt32 rowCount = 0;
|
2008-03-19 23:19:48 -07:00
|
|
|
treeView->GetRowCount(&rowCount);
|
2009-12-10 11:12:19 -08:00
|
|
|
if (rowCount > 0 && aOffset <= rowCount) {
|
2010-04-26 20:16:41 -07:00
|
|
|
nsRefPtr<nsXULTreeAccessible> treeAcc = do_QueryObject(mParent);
|
2008-03-19 23:19:48 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
if (treeAcc)
|
|
|
|
return treeAcc->GetTreeItemAccessible(aOffset - 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|