зеркало из https://github.com/mozilla/gecko-dev.git
bug 109217:Active Accessibility: implement support for <tree>
r=aaronl, sr=jst Check in for Kyle Yuan(kyle.yuan@sun.com)'s fix Check in the new file. Will check in others later
This commit is contained in:
Родитель
d7d65019fa
Коммит
851c29b903
|
@ -0,0 +1,623 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIAccessibilityService.h"
|
||||
#include "nsIBoxObject.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsITreeSelection.h"
|
||||
#include "nsITreeView.h"
|
||||
#include "nsXULAtoms.h"
|
||||
#include "nsXULTreeAccessible.h"
|
||||
|
||||
// ---------- nsXULTreeAccessible ----------
|
||||
|
||||
nsXULTreeAccessible::nsXULTreeAccessible(nsIDOMNode *aDOMNode, nsIWeakReference *aShell):
|
||||
nsAccessible(aDOMNode, aShell)
|
||||
{
|
||||
GetTreeBoxObject(aDOMNode, getter_AddRefs(mTree));
|
||||
if (mTree)
|
||||
mTree->GetView(getter_AddRefs(mTreeView));
|
||||
NS_ASSERTION(mTree && mTreeView, "Can't get mTree or mTreeView!\n");
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsXULTreeAccessible, nsAccessible, nsIAccessibleSelectable)
|
||||
|
||||
NS_IMETHODIMP nsXULTreeAccessible::GetAccState(PRUint32 *_retval)
|
||||
{
|
||||
// Get focus status from base class
|
||||
nsAccessible::GetAccState(_retval);
|
||||
|
||||
// see if we are multiple select if so set ourselves as such
|
||||
nsCOMPtr<nsIDOMElement> element (do_QueryInterface(mDOMNode));
|
||||
if (element) {
|
||||
nsAutoString selType;
|
||||
element->GetAttribute(NS_LITERAL_STRING("seltype"), selType);
|
||||
if (!selType.IsEmpty() && selType.Equals(NS_LITERAL_STRING("multiple")))
|
||||
*_retval |= STATE_MULTISELECTABLE;
|
||||
}
|
||||
|
||||
*_retval |= STATE_READONLY | STATE_FOCUSABLE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// The value is the first selected child
|
||||
NS_IMETHODIMP nsXULTreeAccessible::GetAccValue(nsAString& _retval)
|
||||
{
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsITreeSelection> selection;
|
||||
mTree->GetSelection(getter_AddRefs(selection));
|
||||
if (selection) {
|
||||
PRInt32 currentIndex;
|
||||
nsCOMPtr<nsIDOMElement> selectItem;
|
||||
selection->GetCurrentIndex(¤tIndex);
|
||||
|
||||
nsAutoString colID;
|
||||
PRInt32 keyColumn;
|
||||
mTree->GetKeyColumnIndex(&keyColumn);
|
||||
mTree->GetColumnID(keyColumn, colID);
|
||||
return mTreeView->GetCellText(currentIndex, colID.get(), _retval);
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeAccessible::GetAccRole(PRUint32 *_retval)
|
||||
{
|
||||
*_retval = ROLE_OUTLINE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeAccessible::GetAccFirstChild(nsIAccessible **aAccFirstChild)
|
||||
{
|
||||
nsAccessible::GetAccFirstChild(aAccFirstChild);
|
||||
|
||||
// in normal case, tree's first child should be treecols, if it is not here,
|
||||
// use the first row as tree's first child
|
||||
if (*aAccFirstChild == nsnull) {
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
PRInt32 rowCount;
|
||||
mTreeView->GetRowCount(&rowCount);
|
||||
if (rowCount > 0) {
|
||||
*aAccFirstChild = new nsXULTreeitemAccessible(this, mDOMNode, mPresShell, 0);
|
||||
if (! *aAccFirstChild)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*aAccFirstChild);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeAccessible::GetAccLastChild(nsIAccessible **aAccLastChild)
|
||||
{
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
PRInt32 rowCount;
|
||||
mTreeView->GetRowCount(&rowCount);
|
||||
if (rowCount > 0) {
|
||||
*aAccLastChild = new nsXULTreeitemAccessible(this, mDOMNode, mPresShell, rowCount - 1);
|
||||
if (! *aAccLastChild)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*aAccLastChild);
|
||||
}
|
||||
else // if there is not any rows, use treecols as tree's last child
|
||||
nsAccessible::GetAccLastChild(aAccLastChild);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// tree's children count is row count + treecols count
|
||||
NS_IMETHODIMP nsXULTreeAccessible::GetAccChildCount(PRInt32 *aAccChildCount)
|
||||
{
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
nsAccessible::GetAccChildCount(aAccChildCount);
|
||||
|
||||
PRInt32 rowCount;
|
||||
mTreeView->GetRowCount(&rowCount);
|
||||
*aAccChildCount += rowCount;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Ask treeselection to get all selected children
|
||||
NS_IMETHODIMP nsXULTreeAccessible::GetSelectedChildren(nsISupportsArray **_retval)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsITreeSelection> selection;
|
||||
mTree->GetSelection(getter_AddRefs(selection));
|
||||
if (!selection)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsISupportsArray> selectedAccessibles;
|
||||
NS_NewISupportsArray(getter_AddRefs(selectedAccessibles));
|
||||
if (!selectedAccessibles)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PRInt32 rowIndex, rowCount;
|
||||
PRBool isSelected;
|
||||
mTreeView->GetRowCount(&rowCount);
|
||||
for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
||||
selection->IsSelected(rowIndex, &isSelected);
|
||||
if (isSelected) {
|
||||
nsCOMPtr<nsIAccessible> tempAccess;
|
||||
tempAccess = new nsXULTreeitemAccessible(this, mDOMNode, mPresShell, rowIndex);
|
||||
if (!tempAccess)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
selectedAccessibles->AppendElement(tempAccess);
|
||||
}
|
||||
}
|
||||
|
||||
PRUint32 length;
|
||||
selectedAccessibles->Count(&length);
|
||||
if (length != 0) {
|
||||
*_retval = selectedAccessibles;
|
||||
NS_IF_ADDREF(*_retval);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get the nsITreeBoxObject interface from any levels DOMNode under the <tree>
|
||||
void nsXULTreeAccessible::GetTreeBoxObject(nsIDOMNode *aDOMNode, nsITreeBoxObject **aBoxObject)
|
||||
{
|
||||
nsAutoString name;
|
||||
nsCOMPtr<nsIDOMNode> parentNode, currentNode;
|
||||
|
||||
// Find DOMNode's parents recursively until reach the <tree> tag
|
||||
currentNode = aDOMNode;
|
||||
while (currentNode) {
|
||||
currentNode->GetLocalName(name);
|
||||
if (name.Equals(NS_LITERAL_STRING("tree"))) {
|
||||
// We will get the nsITreeBoxObject from the tree node
|
||||
nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(currentNode));
|
||||
if (xulElement) {
|
||||
nsCOMPtr<nsIBoxObject> box;
|
||||
xulElement->GetBoxObject(getter_AddRefs(box));
|
||||
nsCOMPtr<nsITreeBoxObject> treeBox(do_QueryInterface(box));
|
||||
if (treeBox) {
|
||||
*aBoxObject = treeBox;
|
||||
NS_ADDREF(*aBoxObject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
currentNode->GetParentNode(getter_AddRefs(parentNode));
|
||||
currentNode = parentNode;
|
||||
}
|
||||
|
||||
*aBoxObject = nsnull;
|
||||
}
|
||||
|
||||
// ---------- nsXULTreeitemAccessible ----------
|
||||
|
||||
nsXULTreeitemAccessible::nsXULTreeitemAccessible(nsIAccessible *aParent, nsIDOMNode *aDOMNode, nsIWeakReference *aShell, PRInt32 aRow):
|
||||
nsLeafAccessible(aDOMNode, aShell)
|
||||
{
|
||||
mParent = aParent;
|
||||
|
||||
nsXULTreeAccessible::GetTreeBoxObject(aDOMNode, getter_AddRefs(mTree));
|
||||
if (mTree)
|
||||
mTree->GetView(getter_AddRefs(mTreeView));
|
||||
NS_ASSERTION(mTree && mTreeView, "Can't get mTree or mTreeView!\n");
|
||||
|
||||
// Since the real tree item does not correspond to any DOMNode, use the row index to distinguish each item
|
||||
mRow = aRow;
|
||||
if (mTree) {
|
||||
PRInt32 keyColumn;
|
||||
mTree->GetKeyColumnIndex(&keyColumn);
|
||||
mTree->GetColumnID(keyColumn, mColumn);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED0(nsXULTreeitemAccessible, nsLeafAccessible)
|
||||
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::GetAccName(nsAString& _retval)
|
||||
{
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
return mTreeView->GetCellText(mRow, mColumn.get(), _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::GetAccValue(nsAString& _retval)
|
||||
{
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
PRInt32 level;
|
||||
mTreeView->GetLevel(mRow, &level);
|
||||
|
||||
nsCString str;
|
||||
str.AppendInt(level);
|
||||
_retval = NS_ConvertASCIItoUCS2(str);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::GetAccId(PRInt32 *aAccId)
|
||||
{
|
||||
// Since mDOMNode is same for all tree item, let RootAccessible generate the unique Id
|
||||
*aAccId = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::GetAccRole(PRUint32 *_retval)
|
||||
{
|
||||
*_retval = ROLE_OUTLINEITEM;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Possible states: focused, focusable, selected, expanded/collapsed
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::GetAccState(PRUint32 *_retval)
|
||||
{
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
*_retval = STATE_FOCUSABLE;
|
||||
|
||||
// get expanded/collapsed state
|
||||
PRBool isContainer, isContainerOpen;
|
||||
mTreeView->IsContainer(mRow, &isContainer);
|
||||
if (isContainer) {
|
||||
mTreeView->IsContainerOpen(mRow, &isContainerOpen);
|
||||
if (isContainerOpen)
|
||||
*_retval |= STATE_EXPANDED;
|
||||
else
|
||||
*_retval |= STATE_COLLAPSED;
|
||||
}
|
||||
|
||||
// get selected state
|
||||
nsCOMPtr<nsITreeSelection> selection;
|
||||
mTree->GetSelection(getter_AddRefs(selection));
|
||||
if (selection) {
|
||||
PRBool isSelected, currentIndex;
|
||||
selection->IsSelected(mRow, &isSelected);
|
||||
if (isSelected)
|
||||
*_retval |= STATE_SELECTED;
|
||||
selection->GetCurrentIndex(¤tIndex);
|
||||
if (currentIndex == mRow)
|
||||
*_retval |= STATE_FOCUSED;
|
||||
}
|
||||
|
||||
PRInt32 firstVisibleRow, lastVisibleRow;
|
||||
mTree->GetFirstVisibleRow(&firstVisibleRow);
|
||||
mTree->GetLastVisibleRow(&lastVisibleRow);
|
||||
if (mRow < firstVisibleRow || mRow > lastVisibleRow)
|
||||
*_retval |= STATE_INVISIBLE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Only one actions available
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::GetAccNumActions(PRUint8 *_retval)
|
||||
{
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
*_retval = eNo_Action;
|
||||
|
||||
PRBool isContainer;
|
||||
mTreeView->IsContainer(mRow, &isContainer);
|
||||
if (isContainer)
|
||||
*_retval = eSingle_Action;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Return the name of our only action
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::GetAccActionName(PRUint8 index, nsAString& _retval)
|
||||
{
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
if (index == eAction_Click) {
|
||||
PRBool isContainer, isContainerOpen;
|
||||
mTreeView->IsContainer(mRow, &isContainer);
|
||||
if (isContainer) {
|
||||
mTreeView->IsContainerOpen(mRow, &isContainerOpen);
|
||||
if (isContainerOpen)
|
||||
nsAccessible::GetTranslatedString(NS_LITERAL_STRING("collapse"), _retval);
|
||||
else
|
||||
nsAccessible::GetTranslatedString(NS_LITERAL_STRING("expand"), _retval);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::GetAccParent(nsIAccessible **aAccParent)
|
||||
{
|
||||
*aAccParent = nsnull;
|
||||
|
||||
if (mParent) {
|
||||
*aAccParent = mParent;
|
||||
NS_ADDREF(*aAccParent);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Return the next row of tree (if any)
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::GetAccNextSibling(nsIAccessible **aAccNextSibling)
|
||||
{
|
||||
*aAccNextSibling = nsnull;
|
||||
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
PRInt32 rowCount;
|
||||
mTreeView->GetRowCount(&rowCount);
|
||||
|
||||
if (mRow < rowCount - 1) {
|
||||
*aAccNextSibling = new nsXULTreeitemAccessible(mParent, mDOMNode, mPresShell, mRow + 1);
|
||||
if (! *aAccNextSibling)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*aAccNextSibling);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Return the previous row of tree (if any)
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::GetAccPreviousSibling(nsIAccessible **aAccPreviousSibling)
|
||||
{
|
||||
*aAccPreviousSibling = nsnull;
|
||||
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
if (mRow > 0) {
|
||||
*aAccPreviousSibling = new nsXULTreeitemAccessible(mParent, mDOMNode, mPresShell, mRow - 1);
|
||||
if (! *aAccPreviousSibling)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*aAccPreviousSibling);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::AccDoAction(PRUint8 index)
|
||||
{
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
if (index == eAction_Click)
|
||||
return mTreeView->ToggleOpenState(mRow);
|
||||
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
|
||||
{
|
||||
*x = *y = *width = *height = 0;
|
||||
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
||||
const PRUnichar empty[] = {'\0'};
|
||||
|
||||
// This Bounds are based on Tree's coord
|
||||
mTree->GetCoordsForCellItem(mRow, mColumn.get(), empty, x, y, width, height);
|
||||
|
||||
// Get treechildren's BoxObject to adjust the Bounds' upper left corner
|
||||
nsCOMPtr<nsIBoxObject> boxObject(do_QueryInterface(mTree));
|
||||
if (boxObject) {
|
||||
nsCOMPtr<nsIDOMElement> boxElement;
|
||||
boxObject->GetElement(getter_AddRefs(boxElement));
|
||||
nsCOMPtr<nsIDOMNode> boxNode(do_QueryInterface(boxElement));
|
||||
if (boxNode) {
|
||||
nsCOMPtr<nsIDOMNodeList> childNodes;
|
||||
boxNode->GetChildNodes(getter_AddRefs(childNodes));
|
||||
if (childNodes) {
|
||||
nsAutoString name;
|
||||
nsCOMPtr<nsIDOMNode> childNode;
|
||||
PRUint32 childCount, childIndex;
|
||||
|
||||
childNodes->GetLength(&childCount);
|
||||
for (childIndex = 0; childIndex < childCount; childIndex++) {
|
||||
childNodes->Item(childIndex, getter_AddRefs(childNode));
|
||||
childNode->GetLocalName(name);
|
||||
if (name.Equals(NS_LITERAL_STRING("treechildren"))) {
|
||||
nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(childNode));
|
||||
if (xulElement) {
|
||||
nsCOMPtr<nsIBoxObject> box;
|
||||
xulElement->GetBoxObject(getter_AddRefs(box));
|
||||
if (box) {
|
||||
PRInt32 myX, myY;
|
||||
box->GetScreenX(&myX);
|
||||
box->GetScreenY(&myY);
|
||||
*x += myX;
|
||||
*y += myY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// ---------- nsXULTreeColumnsAccessible ----------
|
||||
|
||||
nsXULTreeColumnsAccessible::nsXULTreeColumnsAccessible(nsIDOMNode *aDOMNode, nsIWeakReference *aShell):
|
||||
nsAccessible(aDOMNode, aShell)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED0(nsXULTreeColumnsAccessible, nsAccessible)
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnsAccessible::GetAccState(PRUint32 *_retval)
|
||||
{
|
||||
*_retval = STATE_READONLY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnsAccessible::GetAccRole(PRUint32 *_retval)
|
||||
{
|
||||
*_retval = ROLE_LIST;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnsAccessible::GetAccNumActions(PRUint8 *_retval)
|
||||
{
|
||||
*_retval = eSingle_Action;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnsAccessible::GetAccActionName(PRUint8 index, nsAString& _retval)
|
||||
{
|
||||
if (index == eAction_Click) {
|
||||
nsAccessible::GetTranslatedString(NS_LITERAL_STRING("click"), _retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnsAccessible::GetAccNextSibling(nsIAccessible **aAccNextSibling)
|
||||
{
|
||||
nsresult ret = nsAccessible::GetAccNextSibling(aAccNextSibling);
|
||||
|
||||
if (*aAccNextSibling == nsnull) { // if there is not other sibling, use the first row as its sibling
|
||||
nsCOMPtr<nsITreeBoxObject> tree;
|
||||
nsCOMPtr<nsITreeView> treeView;
|
||||
|
||||
nsXULTreeAccessible::GetTreeBoxObject(mDOMNode, getter_AddRefs(tree));
|
||||
if (tree) {
|
||||
tree->GetView(getter_AddRefs(treeView));
|
||||
if (treeView) {
|
||||
PRInt32 rowCount;
|
||||
treeView->GetRowCount(&rowCount);
|
||||
if (rowCount > 0) {
|
||||
*aAccNextSibling = new nsXULTreeitemAccessible(mParent, mDOMNode, mPresShell, 0);
|
||||
if (! *aAccNextSibling)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*aAccNextSibling);
|
||||
ret = NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnsAccessible::GetAccPreviousSibling(nsIAccessible **aAccPreviousSibling)
|
||||
{
|
||||
return nsAccessible::GetAccPreviousSibling(aAccPreviousSibling);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnsAccessible::AccDoAction(PRUint8 index)
|
||||
{
|
||||
if (index == eAction_Click)
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// ---------- nsXULTreeColumnitemAccessible ----------
|
||||
|
||||
nsXULTreeColumnitemAccessible::nsXULTreeColumnitemAccessible(nsIDOMNode *aDOMNode, nsIWeakReference *aShell):
|
||||
nsLeafAccessible(aDOMNode, aShell)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED0(nsXULTreeColumnitemAccessible, nsLeafAccessible)
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnitemAccessible::GetAccState(PRUint32 *_retval)
|
||||
{
|
||||
*_retval = STATE_READONLY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnitemAccessible::GetAccName(nsAString& _retval)
|
||||
{
|
||||
return GetXULAccName(_retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnitemAccessible::GetAccRole(PRUint32 *_retval)
|
||||
{
|
||||
*_retval = ROLE_COLUMNHEADER;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnitemAccessible::GetAccNumActions(PRUint8 *_retval)
|
||||
{
|
||||
*_retval = eSingle_Action;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnitemAccessible::GetAccActionName(PRUint8 index, nsAString& _retval)
|
||||
{
|
||||
if (index == eAction_Click) {
|
||||
nsAccessible::GetTranslatedString(NS_LITERAL_STRING("click"), _retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeColumnitemAccessible::AccDoAction(PRUint8 index)
|
||||
{
|
||||
if (index == eAction_Click) {
|
||||
nsCOMPtr<nsITreeBoxObject> tree;
|
||||
nsCOMPtr<nsITreeView> treeView;
|
||||
|
||||
nsXULTreeAccessible::GetTreeBoxObject(mDOMNode, getter_AddRefs(tree));
|
||||
if (tree) {
|
||||
tree->GetView(getter_AddRefs(treeView));
|
||||
if (treeView) {
|
||||
nsCOMPtr<nsIDOMElement> colElement(do_QueryInterface(mDOMNode));
|
||||
if (colElement) {
|
||||
nsAutoString colID;
|
||||
colElement->GetAttribute(NS_LITERAL_STRING("id"), colID);
|
||||
treeView->CycleHeader(colID.get(), colElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#ifndef __nsXULTreeAccessible_h__
|
||||
#define __nsXULTreeAccessible_h__
|
||||
|
||||
#include "nsAccessible.h"
|
||||
#include "nsBaseWidgetAccessible.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIAccessibleSelectable.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIWeakReference.h"
|
||||
#include "nsITreeBoxObject.h"
|
||||
#include "nsITreeView.h"
|
||||
|
||||
/*
|
||||
* A class the represents the XUL Tree widget.
|
||||
*/
|
||||
class nsXULTreeAccessible : public nsAccessible,
|
||||
public nsIAccessibleSelectable
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIACCESSIBLESELECTABLE
|
||||
|
||||
nsXULTreeAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
|
||||
virtual ~nsXULTreeAccessible() {}
|
||||
|
||||
/* ----- nsIAccessible ----- */
|
||||
NS_IMETHOD GetAccRole(PRUint32 *_retval);
|
||||
NS_IMETHOD GetAccState(PRUint32 *_retval);
|
||||
NS_IMETHOD GetAccValue(nsAString& _retval);
|
||||
|
||||
NS_IMETHOD GetAccFirstChild(nsIAccessible **_retval);
|
||||
NS_IMETHOD GetAccLastChild(nsIAccessible **_retval);
|
||||
NS_IMETHOD GetAccChildCount(PRInt32 *_retval);
|
||||
|
||||
static void GetTreeBoxObject(nsIDOMNode* aDOMNode, nsITreeBoxObject** aBoxObject);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsITreeBoxObject> mTree;
|
||||
nsCOMPtr<nsITreeView> mTreeView;
|
||||
};
|
||||
|
||||
/**
|
||||
* Treeitems -- used in Trees
|
||||
*/
|
||||
class nsXULTreeitemAccessible : public nsLeafAccessible
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
nsXULTreeitemAccessible(nsIAccessible* aParent, nsIDOMNode* aDOMNode, nsIWeakReference* aShell, PRInt32 aRow);
|
||||
virtual ~nsXULTreeitemAccessible() {}
|
||||
|
||||
/* ----- nsIAccessible ----- */
|
||||
NS_IMETHOD GetAccName(nsAString& _retval);
|
||||
NS_IMETHOD GetAccValue(nsAString& _retval);
|
||||
NS_IMETHOD GetAccId(PRInt32 *_retval);
|
||||
NS_IMETHOD GetAccRole(PRUint32 *_retval);
|
||||
NS_IMETHOD GetAccState(PRUint32 *_retval);
|
||||
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
|
||||
NS_IMETHOD GetAccActionName(PRUint8 index, nsAString& _retval);
|
||||
|
||||
NS_IMETHOD GetAccParent(nsIAccessible **_retval);
|
||||
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
|
||||
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
|
||||
|
||||
NS_IMETHOD AccDoAction(PRUint8 index);
|
||||
NS_IMETHOD AccGetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsITreeBoxObject> mTree;
|
||||
nsCOMPtr<nsITreeView> mTreeView;
|
||||
PRInt32 mRow;
|
||||
nsString mColumn;
|
||||
};
|
||||
|
||||
class nsXULTreeColumnsAccessible : public nsAccessible
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
nsXULTreeColumnsAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
|
||||
virtual ~nsXULTreeColumnsAccessible() {}
|
||||
|
||||
/* ----- nsIAccessible ----- */
|
||||
NS_IMETHOD GetAccRole(PRUint32 *_retval);
|
||||
NS_IMETHOD GetAccState(PRUint32 *_retval);
|
||||
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
|
||||
NS_IMETHOD GetAccActionName(PRUint8 index, nsAString& _retval);
|
||||
|
||||
NS_IMETHOD GetAccNextSibling(nsIAccessible **_retval);
|
||||
NS_IMETHOD GetAccPreviousSibling(nsIAccessible **_retval);
|
||||
|
||||
NS_IMETHOD AccDoAction(PRUint8 index);
|
||||
};
|
||||
|
||||
class nsXULTreeColumnitemAccessible : public nsLeafAccessible
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
nsXULTreeColumnitemAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell);
|
||||
virtual ~nsXULTreeColumnitemAccessible() {}
|
||||
|
||||
/* ----- nsIAccessible ----- */
|
||||
NS_IMETHOD GetAccName(nsAString& _retval);
|
||||
NS_IMETHOD GetAccRole(PRUint32 *_retval);
|
||||
NS_IMETHOD GetAccState(PRUint32 *_retval);
|
||||
NS_IMETHOD GetAccNumActions(PRUint8 *_retval);
|
||||
NS_IMETHOD GetAccActionName(PRUint8 index, nsAString& _retval);
|
||||
|
||||
NS_IMETHOD AccDoAction(PRUint8 index);
|
||||
};
|
||||
|
||||
#endif
|
Загрузка…
Ссылка в новой задаче