2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-08-09 18:44:00 -07:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2007-03-22 10:30:00 -07:00
|
|
|
/* ***** 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"
|
2011-08-09 18:44:00 -07:00
|
|
|
#include "Relation.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
2011-04-09 16:38:06 -07:00
|
|
|
#include "States.h"
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2011-08-09 18:44:00 -07:00
|
|
|
#include "nsIAccessibleRelation.h"
|
2011-09-27 18:46:11 -07:00
|
|
|
#include "nsIAutoCompleteInput.h"
|
|
|
|
#include "nsIAutoCompletePopup.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMXULElement.h"
|
2011-09-27 18:46:11 -07:00
|
|
|
#include "nsIDOMXULMenuListElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#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"
|
|
|
|
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
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::
|
2012-02-07 14:38:54 -08:00
|
|
|
nsXULTreeAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
|
|
|
|
nsAccessibleWrap(aContent, aDoc)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-03 02:54:01 -07:00
|
|
|
mFlags |= eXULTreeAccessible;
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
mTree = nsCoreUtils::GetTreeBoxObject(aContent);
|
2012-04-27 00:56:49 -07:00
|
|
|
NS_ASSERTION(mTree, "Can't get mTree!\n");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-27 00:56:49 -07:00
|
|
|
if (mTree) {
|
|
|
|
nsCOMPtr<nsITreeView> treeView;
|
|
|
|
mTree->GetView(getter_AddRefs(treeView));
|
|
|
|
mTreeView = treeView;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
nsIContent* parentContent = mContent->GetParent();
|
|
|
|
if (parentContent) {
|
|
|
|
nsCOMPtr<nsIAutoCompletePopup> autoCompletePopupElm =
|
|
|
|
do_QueryInterface(parentContent);
|
|
|
|
if (autoCompletePopupElm)
|
|
|
|
mFlags |= eAutoCompletePopupAccessible;
|
|
|
|
}
|
|
|
|
|
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)
|
2012-03-23 19:30:11 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTree)
|
|
|
|
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)
|
2012-03-23 19:30:11 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTree)
|
|
|
|
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)
|
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
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64
|
|
|
|
nsXULTreeAccessible::NativeState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
// Get focus status from base class.
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64 state = nsAccessible::NativeState();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// readonly state
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::READONLY;
|
2009-08-19 23:45:19 -07:00
|
|
|
|
|
|
|
// multiselectable state.
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return state;
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
2011-04-09 16:38:06 -07:00
|
|
|
NS_ENSURE_TRUE(selection, state);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSingle = false;
|
2011-04-09 16:38:06 -07:00
|
|
|
nsresult rv = selection->GetSingle(&isSingle);
|
|
|
|
NS_ENSURE_SUCCESS(rv, state);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
|
|
|
if (!isSingle)
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::MULTISELECTABLE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
return state;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-04-09 02:48:41 -07:00
|
|
|
void
|
|
|
|
nsXULTreeAccessible::Value(nsString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-19 23:45:19 -07:00
|
|
|
aValue.Truncate();
|
2012-04-27 01:11:03 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return;
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2012-04-27 01:11:03 -07:00
|
|
|
// Return the value is the first selected child.
|
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)
|
2012-04-09 02:48:41 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2012-04-09 02:48:41 -07:00
|
|
|
mTreeView->GetCellText(currentIndex, keyCol, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: nsAccessNode implementation
|
|
|
|
|
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)
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2010-09-04 19:14:01 -07:00
|
|
|
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));
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
return primaryCol ? roles::OUTLINE : roles::LIST;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: nsAccessible implementation (DON'T put methods here)
|
|
|
|
|
2011-03-28 21:44:20 -07:00
|
|
|
nsAccessible*
|
2011-06-13 15:20:54 -07:00
|
|
|
nsXULTreeAccessible::ChildAtPoint(PRInt32 aX, PRInt32 aY,
|
|
|
|
EWhichChildAtPoint aWhichChild)
|
2007-09-05 01:00:40 -07:00
|
|
|
{
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (!frame)
|
2011-03-28 21:44:20 -07:00
|
|
|
return nsnull;
|
2007-09-05 01:00:40 -07:00
|
|
|
|
|
|
|
nsPresContext *presContext = frame->PresContext();
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = presContext->PresShell();
|
|
|
|
|
|
|
|
nsIFrame *rootFrame = presShell->GetRootFrame();
|
2011-03-28 21:44:20 -07:00
|
|
|
NS_ENSURE_TRUE(rootFrame, nsnull);
|
2007-09-05 01:00:40 -07:00
|
|
|
|
2012-03-26 05:19:07 -07:00
|
|
|
nsIntRect rootRect = rootFrame->GetScreenRect();
|
2007-09-05 01:00:40 -07:00
|
|
|
|
2012-03-26 05:19:07 -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)
|
2011-06-13 15:20:54 -07:00
|
|
|
return nsAccessibleWrap::ChildAtPoint(aX, aY, aWhichChild);
|
2009-05-11 03:57:28 -07:00
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible *child = GetTreeItemAccessible(row);
|
2011-03-28 21:44:20 -07:00
|
|
|
if (aWhichChild == eDeepestChild && 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
|
|
|
}
|
|
|
|
|
2011-03-28 21:44:20 -07:00
|
|
|
return child;
|
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
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
nsAccessible*
|
|
|
|
nsXULTreeAccessible::CurrentItem()
|
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return nsnull;
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
|
|
|
PRInt32 currentIndex = -1;
|
|
|
|
selection->GetCurrentIndex(¤tIndex);
|
|
|
|
if (currentIndex >= 0)
|
|
|
|
return GetTreeItemAccessible(currentIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2011-12-08 04:20:15 -08:00
|
|
|
void
|
|
|
|
nsXULTreeAccessible::SetCurrentItem(nsAccessible* aItem)
|
|
|
|
{
|
|
|
|
NS_ERROR("nsXULTreeAccessible::SetCurrentItem not implemented");
|
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
already_AddRefed<nsIArray>
|
|
|
|
nsXULTreeAccessible::SelectedItems()
|
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return nsnull;
|
|
|
|
|
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
|
|
|
|
2011-01-17 00:46:42 -08:00
|
|
|
PRInt32 rangeCount = 0;
|
|
|
|
selection->GetRangeCount(&rangeCount);
|
|
|
|
for (PRInt32 rangeIdx = 0; rangeIdx < rangeCount; rangeIdx++) {
|
|
|
|
PRInt32 firstIdx = 0, lastIdx = -1;
|
|
|
|
selection->GetRangeAt(rangeIdx, &firstIdx, &lastIdx);
|
|
|
|
for (PRInt32 rowIdx = firstIdx; rowIdx <= lastIdx; rowIdx++) {
|
|
|
|
nsIAccessible* item = GetTreeItemAccessible(rowIdx);
|
2010-09-01 17:46:59 -07:00
|
|
|
if (item)
|
2011-10-17 07:59:28 -07:00
|
|
|
selectedItems->AppendElement(item, 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
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return 0;
|
|
|
|
|
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
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return false;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected = false;
|
2010-09-01 17:46:59 -07:00
|
|
|
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
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return false;
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected = false;
|
2010-09-01 17:46:59 -07:00
|
|
|
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
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return false;
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected = false;
|
2010-09-01 17:46:59 -07:00
|
|
|
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
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return false;
|
|
|
|
|
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
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return nsnull;
|
|
|
|
|
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
|
|
|
|
2011-01-17 20:15:13 -08:00
|
|
|
PRUint32 selCount = 0;
|
|
|
|
PRInt32 rangeCount = 0;
|
|
|
|
selection->GetRangeCount(&rangeCount);
|
|
|
|
for (PRInt32 rangeIdx = 0; rangeIdx < rangeCount; rangeIdx++) {
|
|
|
|
PRInt32 firstIdx = 0, lastIdx = -1;
|
|
|
|
selection->GetRangeAt(rangeIdx, &firstIdx, &lastIdx);
|
|
|
|
for (PRInt32 rowIdx = firstIdx; rowIdx <= lastIdx; rowIdx++) {
|
2010-09-01 17:46:59 -07:00
|
|
|
if (selCount == aIndex)
|
2011-01-17 20:15:13 -08:00
|
|
|
return GetTreeItemAccessible(rowIdx);
|
2010-09-01 17:46:59 -07:00
|
|
|
|
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
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return false;
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool single = false;
|
2010-06-11 01:23:18 -07:00
|
|
|
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();
|
2012-03-28 08:59:01 -07:00
|
|
|
if (childCount == -1 || !mTreeView)
|
|
|
|
return childCount;
|
2009-12-10 11:12:19 -08:00
|
|
|
|
|
|
|
PRInt32 rowCount = 0;
|
|
|
|
mTreeView->GetRowCount(&rowCount);
|
|
|
|
childCount += rowCount;
|
|
|
|
|
|
|
|
return childCount;
|
|
|
|
}
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeAccessible: Widgets
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsXULTreeAccessible::IsWidget() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsXULTreeAccessible::IsActiveWidget() const
|
|
|
|
{
|
|
|
|
if (IsAutoCompletePopup()) {
|
|
|
|
nsCOMPtr<nsIAutoCompletePopup> autoCompletePopupElm =
|
|
|
|
do_QueryInterface(mContent->GetParent());
|
|
|
|
|
|
|
|
if (autoCompletePopupElm) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isOpen = false;
|
2011-09-27 18:46:11 -07:00
|
|
|
autoCompletePopupElm->GetPopupOpen(&isOpen);
|
|
|
|
return isOpen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FocusMgr()->HasDOMFocus(mContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsXULTreeAccessible::AreItemsOperable() const
|
|
|
|
{
|
|
|
|
if (IsAutoCompletePopup()) {
|
|
|
|
nsCOMPtr<nsIAutoCompletePopup> autoCompletePopupElm =
|
|
|
|
do_QueryInterface(mContent->GetParent());
|
|
|
|
|
|
|
|
if (autoCompletePopupElm) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isOpen = false;
|
2011-09-27 18:46:11 -07:00
|
|
|
autoCompletePopupElm->GetPopupOpen(&isOpen);
|
|
|
|
return isOpen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAccessible*
|
|
|
|
nsXULTreeAccessible::ContainerWidget() const
|
|
|
|
{
|
|
|
|
if (IsAutoCompletePopup()) {
|
|
|
|
// This works for XUL autocompletes. It doesn't work for HTML forms
|
|
|
|
// autocomplete because of potential crossprocess calls (when autocomplete
|
|
|
|
// lives in content process while popup lives in chrome process). If that's
|
|
|
|
// a problem then rethink Widgets interface.
|
|
|
|
nsCOMPtr<nsIDOMXULMenuListElement> menuListElm =
|
|
|
|
do_QueryInterface(mContent->GetParent());
|
|
|
|
if (menuListElm) {
|
|
|
|
nsCOMPtr<nsIDOMNode> inputElm;
|
|
|
|
menuListElm->GetInputField(getter_AddRefs(inputElm));
|
|
|
|
if (inputElm) {
|
|
|
|
nsCOMPtr<nsINode> inputNode = do_QueryInterface(inputElm);
|
|
|
|
if (inputNode) {
|
2012-02-09 08:49:17 -08:00
|
|
|
nsAccessible* input =
|
2012-02-15 11:22:17 -08:00
|
|
|
mDoc->GetAccessible(inputNode);
|
2011-09-27 18:46:11 -07:00
|
|
|
return input ? input->ContainerWidget() : nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (aRow < 0 || IsDefunct() || !mTreeView)
|
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-11-12 11:00:55 -08:00
|
|
|
nsAccessible* cachedTreeItem = mAccessibleCache.GetWeak(key);
|
|
|
|
if (cachedTreeItem)
|
|
|
|
return cachedTreeItem;
|
2009-06-29 08:38:17 -07:00
|
|
|
|
2010-11-12 11:00:55 -08:00
|
|
|
nsRefPtr<nsAccessible> treeItem = CreateTreeItemAccessible(aRow);
|
|
|
|
if (treeItem) {
|
|
|
|
if (mAccessibleCache.Put(key, treeItem)) {
|
2011-11-09 14:52:00 -08:00
|
|
|
if (Document()->BindToDocument(treeItem, nsnull))
|
2010-11-12 11:00:55 -08:00
|
|
|
return treeItem;
|
2008-10-31 20:58:07 -07:00
|
|
|
|
2010-11-12 11:00:55 -08:00
|
|
|
mAccessibleCache.Remove(key);
|
2010-03-10 02:26:11 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-06-29 08:38:17 -07:00
|
|
|
|
2010-11-12 11:00:55 -08:00
|
|
|
return nsnull;
|
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
|
|
|
|
2011-11-09 14:52:00 -08:00
|
|
|
nsDocAccessible* document = Document();
|
2010-11-12 11:00:55 -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-11-12 11:00:55 -08:00
|
|
|
nsAccessible* treeItem = mAccessibleCache.GetWeak(key);
|
2007-12-11 00:18:04 -08:00
|
|
|
|
2010-11-12 11:00:55 -08:00
|
|
|
if (treeItem) {
|
2010-08-24 19:08:28 -07:00
|
|
|
nsRefPtr<AccEvent> event =
|
2010-11-12 11:00:55 -08:00
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_HIDE, treeItem);
|
2010-01-18 08:17:01 -08:00
|
|
|
nsEventShell::FireEvent(event);
|
2007-12-11 00:18:04 -08:00
|
|
|
|
2010-11-12 11:00:55 -08:00
|
|
|
// Unbind from document, shutdown and remove from tree cache.
|
|
|
|
document->UnbindFromDocument(treeItem);
|
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-11-12 11:00:55 -08:00
|
|
|
nsAccessible* treeItem = mAccessibleCache.GetWeak(key);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-11-12 11:00:55 -08:00
|
|
|
if (treeItem) {
|
|
|
|
// Unbind from document, shutdown and remove from tree cache.
|
|
|
|
document->UnbindFromDocument(treeItem);
|
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
|
2012-04-02 04:31:10 -07:00
|
|
|
nsXULTreeAccessible::TreeViewChanged(nsITreeView* aView)
|
2008-06-15 23:16:18 -07:00
|
|
|
{
|
2009-06-29 08:38:17 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return;
|
2008-06-15 23:16:18 -07:00
|
|
|
|
2010-11-25 07:56:37 -08:00
|
|
|
// Fire reorder event on tree accessible on accessible tree (do not fire
|
|
|
|
// show/hide events on tree items because it can be expensive to fire them for
|
|
|
|
// each tree item.
|
|
|
|
nsRefPtr<AccEvent> reorderEvent =
|
|
|
|
new AccEvent(nsIAccessibleEvent::EVENT_REORDER, this, eAutoDetect,
|
|
|
|
AccEvent::eCoalesceFromSameSubtree);
|
|
|
|
if (reorderEvent)
|
2011-11-09 14:52:00 -08:00
|
|
|
Document()->FireDelayedAccessibleEvent(reorderEvent);
|
2010-11-25 07:56:37 -08:00
|
|
|
|
|
|
|
// Clear cache.
|
2010-03-10 02:26:11 -08:00
|
|
|
ClearCache(mAccessibleCache);
|
2012-04-02 04:31:10 -07:00
|
|
|
mTreeView = aView;
|
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 =
|
2012-02-07 14:38:54 -08:00
|
|
|
new nsXULTreeItemAccessible(mContent, mDoc, 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::
|
2012-02-07 14:38:54 -08:00
|
|
|
nsXULTreeItemAccessibleBase(nsIContent* aContent, nsDocAccessible* aDoc,
|
|
|
|
nsAccessible* aParent, nsITreeBoxObject* aTree,
|
|
|
|
nsITreeView* aTreeView, PRInt32 aRow) :
|
|
|
|
nsAccessibleWrap(aContent, aDoc),
|
2010-07-16 07:15:07 -07:00
|
|
|
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
|
|
|
|
2011-06-09 02:44:31 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULTreeItemAccessibleBase)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULTreeItemAccessibleBase,
|
|
|
|
nsAccessible)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTree)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsXULTreeItemAccessibleBase,
|
|
|
|
nsAccessible)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTree)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsXULTreeItemAccessibleBase)
|
|
|
|
NS_INTERFACE_TABLE_INHERITED1(nsXULTreeItemAccessibleBase,
|
|
|
|
nsXULTreeItemAccessibleBase)
|
|
|
|
NS_INTERFACE_TABLE_TAIL_INHERITING(nsAccessible)
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsXULTreeItemAccessibleBase, nsAccessible)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsXULTreeItemAccessibleBase, nsAccessible)
|
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
|
|
|
|
2011-07-15 15:58:49 -07:00
|
|
|
nsAccessible*
|
|
|
|
nsXULTreeItemAccessibleBase::FocusedChild()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-27 18:46:11 -07:00
|
|
|
return FocusMgr()->FocusedAccessible() == this ? this : nsnull;
|
2009-08-19 23:45:19 -07:00
|
|
|
}
|
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;
|
|
|
|
|
2012-04-10 20:42:42 -07:00
|
|
|
nsPresContext* presContext = mDoc->PresContext();
|
2009-08-19 23:45:19 -07:00
|
|
|
*aX = presContext->CSSPixelsToDevPixels(x);
|
|
|
|
*aY = presContext->CSSPixelsToDevPixels(y);
|
|
|
|
*aWidth = presContext->CSSPixelsToDevPixels(width);
|
|
|
|
*aHeight = presContext->CSSPixelsToDevPixels(height);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULTreeItemAccessibleBase::SetSelected(bool aSelect)
|
2009-08-19 23:45:19 -07:00
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (IsDefunct() || !mTreeView)
|
2009-08-19 23:45:19 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITreeSelection> selection;
|
|
|
|
mTreeView->GetSelection(getter_AddRefs(selection));
|
|
|
|
if (selection) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected;
|
2009-08-19 23:45:19 -07:00
|
|
|
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
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (IsDefunct() || !mTreeView)
|
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
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
Relation
|
|
|
|
nsXULTreeItemAccessibleBase::RelationByType(PRUint32 aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return Relation();
|
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
if (aType != nsIAccessibleRelation::RELATION_NODE_CHILD_OF)
|
2011-10-03 07:26:11 -07:00
|
|
|
return Relation();
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2012-03-28 08:59:01 -07:00
|
|
|
PRInt32 parentIndex = -1;
|
2011-08-09 18:44:00 -07:00
|
|
|
if (!NS_SUCCEEDED(mTreeView->GetParentIndex(mRow, &parentIndex)))
|
2011-10-03 07:26:11 -07:00
|
|
|
return Relation();
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2011-10-03 07:26:11 -07:00
|
|
|
if (parentIndex == -1)
|
|
|
|
return Relation(mParent);
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2012-04-03 02:54:01 -07:00
|
|
|
nsXULTreeAccessible* treeAcc = mParent->AsXULTree();
|
2011-10-03 07:26:11 -07:00
|
|
|
return Relation(treeAcc->GetTreeItemAccessible(parentIndex));
|
2007-09-05 06:35:35 -07:00
|
|
|
}
|
|
|
|
|
2011-06-05 12:35:43 -07:00
|
|
|
PRUint8
|
|
|
|
nsXULTreeItemAccessibleBase::ActionCount()
|
2007-09-05 06:35:35 -07:00
|
|
|
{
|
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.
|
2011-06-05 12:35:43 -07:00
|
|
|
return IsExpandable() ? 2 : 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
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()) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isContainerOpen;
|
2007-09-05 06:35:35 -07:00
|
|
|
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
|
|
|
|
|
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
|
|
|
|
2012-03-28 08:59:01 -07:00
|
|
|
if (IsDefunct() || !mTreeView)
|
2009-08-19 23:45:19 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64
|
|
|
|
nsXULTreeItemAccessibleBase::NativeState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return states::DEFUNCT;
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// focusable and selectable states
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64 state = states::FOCUSABLE | states::SELECTABLE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// expanded/collapsed state
|
|
|
|
if (IsExpandable()) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isContainerOpen;
|
2009-08-19 23:45:19 -07:00
|
|
|
mTreeView->IsContainerOpen(mRow, &isContainerOpen);
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= isContainerOpen ? states::EXPANDED : states::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) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected;
|
2009-08-19 23:45:19 -07:00
|
|
|
selection->IsSelected(mRow, &isSelected);
|
|
|
|
if (isSelected)
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::SELECTED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
// focused state
|
2011-09-27 18:46:11 -07:00
|
|
|
if (FocusMgr()->IsFocused(this))
|
|
|
|
state |= states::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)
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::INVISIBLE;
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
return state;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-01-30 20:04:39 -08:00
|
|
|
PRInt32
|
2011-06-13 02:08:40 -07:00
|
|
|
nsXULTreeItemAccessibleBase::IndexInParent() const
|
2011-01-30 20:04:39 -08:00
|
|
|
{
|
2011-06-06 19:24:01 -07:00
|
|
|
return mParent ? mParent->ContentChildCount() + mRow : -1;
|
2011-01-30 20:04:39 -08:00
|
|
|
}
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessibleBase: Widgets
|
|
|
|
|
|
|
|
nsAccessible*
|
|
|
|
nsXULTreeItemAccessibleBase::ContainerWidget() const
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
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,
|
2011-06-06 19:23:13 -07:00
|
|
|
nsresult* aError) const
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
|
|
|
if (aError)
|
|
|
|
*aError = NS_OK; // fail peacefully
|
|
|
|
|
2011-06-13 02:08:40 -07:00
|
|
|
return mParent->GetChildAt(IndexInParent() + aOffset);
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessibleBase: protected implementation
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-08-19 23:45:19 -07:00
|
|
|
nsXULTreeItemAccessibleBase::IsExpandable()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return false;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isContainer = false;
|
2009-08-19 23:45:19 -07:00
|
|
|
mTreeView->IsContainer(mRow, &isContainer);
|
|
|
|
if (isContainer) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isEmpty = false;
|
2009-08-19 23:45:19 -07:00
|
|
|
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))
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-06-09 02:09:05 -07:00
|
|
|
void
|
|
|
|
nsXULTreeItemAccessibleBase::GetCellName(nsITreeColumn* aColumn,
|
|
|
|
nsAString& aName)
|
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
if (!mTreeView)
|
|
|
|
return;
|
|
|
|
|
2011-06-09 02:09:05 -07:00
|
|
|
mTreeView->GetCellText(mRow, aColumn, 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, aColumn, aName);
|
|
|
|
}
|
|
|
|
|
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::
|
2012-02-07 14:38:54 -08:00
|
|
|
nsXULTreeItemAccessible(nsIContent* aContent, nsDocAccessible* aDoc,
|
|
|
|
nsAccessible* aParent, nsITreeBoxObject* aTree,
|
|
|
|
nsITreeView* aTreeView, PRInt32 aRow) :
|
|
|
|
nsXULTreeItemAccessibleBase(aContent, aDoc, aParent, aTree, aTreeView, aRow)
|
2009-08-19 23:45:19 -07:00
|
|
|
{
|
|
|
|
mColumn = nsCoreUtils::GetFirstSensibleColumn(mTree);
|
|
|
|
}
|
2009-05-06 02:54:26 -07:00
|
|
|
|
2011-06-09 02:44:31 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsXULTreeItemAccessible: nsISupports implementation
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULTreeItemAccessible)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULTreeItemAccessible,
|
|
|
|
nsXULTreeItemAccessibleBase)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mColumn)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsXULTreeItemAccessible,
|
|
|
|
nsXULTreeItemAccessibleBase)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mColumn)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsXULTreeItemAccessible)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsXULTreeItemAccessibleBase)
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsXULTreeItemAccessible, nsXULTreeItemAccessibleBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsXULTreeItemAccessible, nsXULTreeItemAccessibleBase)
|
|
|
|
|
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;
|
|
|
|
|
2011-06-09 02:09:05 -07:00
|
|
|
GetCellName(mColumn, aName);
|
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
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-08-19 23:45:19 -07:00
|
|
|
nsXULTreeItemAccessible::Init()
|
|
|
|
{
|
2010-06-11 21:04:35 -07:00
|
|
|
if (!nsXULTreeItemAccessibleBase::Init())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-08-19 23:45:19 -07:00
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
GetName(mCachedName);
|
2011-10-17 07:59:28 -07:00
|
|
|
return 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
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2010-09-04 19:14:01 -07:00
|
|
|
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!");
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::NOTHING;
|
2010-09-04 19:14:01 -07:00
|
|
|
}
|
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
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
return primaryColumn ? roles::OUTLINEITEM : roles::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::
|
2012-02-07 14:38:54 -08:00
|
|
|
nsXULTreeColumnsAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
|
|
|
|
nsXULColumnsAccessible(aContent, aDoc)
|
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,
|
2011-06-06 19:23:13 -07:00
|
|
|
nsresult* aError) const
|
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 (aError)
|
2011-06-06 19:23:13 -07:00
|
|
|
*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) {
|
2012-04-03 02:54:01 -07:00
|
|
|
nsXULTreeAccessible* treeAcc = Parent()->AsXULTree();
|
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
|
|
|
}
|
|
|
|
|