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):
|
|
|
|
* John Gaunt (jgaunt@netscape.com)
|
|
|
|
* Aaron Leventhal (aaronl@netscape.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 ***** */
|
|
|
|
|
|
|
|
#include "nsAccessible.h"
|
2007-05-19 19:41:33 -07:00
|
|
|
#include "nsAccessibleRelation.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#include "nsHyperTextAccessibleWrap.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIAccessibleDocument.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#include "nsIAccessibleHyperText.h"
|
|
|
|
#include "nsAccessibleTreeWalker.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMDocumentXBL.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#include "nsIDOMDocumentTraversal.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMHTMLDocument.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
|
|
|
#include "nsIDOMNodeFilter.h"
|
|
|
|
#include "nsIDOMNSHTMLElement.h"
|
|
|
|
#include "nsIDOMTreeWalker.h"
|
|
|
|
#include "nsIDOMXULButtonElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMXULDocument.h"
|
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#include "nsIDOMXULLabelElement.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#include "nsIDOMXULSelectCntrlEl.h"
|
|
|
|
#include "nsIDOMXULSelectCntrlItemEl.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIContent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIForm.h"
|
|
|
|
#include "nsIFormControl.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
2008-03-05 19:45:43 -08:00
|
|
|
#include "nsIScrollableFrame.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2007-09-24 18:19:03 -07:00
|
|
|
#include "nsReadableUtils.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#include "prdtoa.h"
|
|
|
|
#include "nsIAtom.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsIMutableArray.h"
|
2007-04-12 23:03:30 -07:00
|
|
|
#include "nsIObserverService.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#include "nsIServiceManager.h"
|
2007-11-11 17:05:37 -08:00
|
|
|
#include "nsWhitespaceTokenizer.h"
|
2008-03-13 10:39:18 -07:00
|
|
|
#include "nsAttrName.h"
|
2008-03-30 23:21:35 -07:00
|
|
|
#include "nsNetUtil.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#include "nsIFrameDebug.h"
|
|
|
|
#include "nsIDOMCharacterData.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nsAccessibleDOMStringList implementation
|
|
|
|
*/
|
|
|
|
nsAccessibleDOMStringList::nsAccessibleDOMStringList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAccessibleDOMStringList::~nsAccessibleDOMStringList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsAccessibleDOMStringList, nsIDOMDOMStringList)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessibleDOMStringList::Item(PRUint32 aIndex, nsAString& aResult)
|
|
|
|
{
|
|
|
|
if (aIndex >= (PRUint32)mNames.Count()) {
|
|
|
|
SetDOMStringToNull(aResult);
|
|
|
|
} else {
|
|
|
|
mNames.StringAt(aIndex, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessibleDOMStringList::GetLength(PRUint32 *aLength)
|
|
|
|
{
|
|
|
|
*aLength = (PRUint32)mNames.Count();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessibleDOMStringList::Contains(const nsAString& aString, PRBool *aResult)
|
|
|
|
{
|
|
|
|
*aResult = mNames.IndexOf(aString) > -1;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class nsAccessible
|
|
|
|
*/
|
|
|
|
|
2008-08-06 05:19:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAccessible. nsISupports
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsAccessible)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsAccessible, nsAccessNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mParent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstChild)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNextSibling)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsAccessible, nsAccessNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mParent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstChild)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mNextSibling)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsAccessible, nsAccessNode)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsAccessible, nsAccessNode)
|
|
|
|
|
|
|
|
#ifdef DEBUG_A11Y
|
|
|
|
/*
|
|
|
|
* static
|
|
|
|
* help method. to detect whether this accessible object implements
|
|
|
|
* nsIAccessibleText, when it is text or has text child node.
|
|
|
|
*/
|
|
|
|
PRBool nsAccessible::IsTextInterfaceSupportCorrect(nsIAccessible *aAccessible)
|
|
|
|
{
|
|
|
|
PRBool foundText = PR_FALSE;
|
|
|
|
|
2007-10-01 11:27:13 -07:00
|
|
|
nsCOMPtr<nsIAccessibleDocument> accDoc = do_QueryInterface(aAccessible);
|
|
|
|
if (accDoc) {
|
|
|
|
// Don't test for accessible docs, it makes us create accessibles too
|
|
|
|
// early and fire mutation events before we need to
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIAccessible> child, nextSibling;
|
|
|
|
aAccessible->GetFirstChild(getter_AddRefs(child));
|
|
|
|
while (child) {
|
|
|
|
if (IsText(child)) {
|
|
|
|
foundText = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
child->GetNextSibling(getter_AddRefs(nextSibling));
|
|
|
|
child.swap(nextSibling);
|
|
|
|
}
|
|
|
|
if (foundText) {
|
|
|
|
// found text child node
|
|
|
|
nsCOMPtr<nsIAccessibleText> text = do_QueryInterface(aAccessible);
|
|
|
|
if (!text) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult nsAccessible::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
// Custom-built QueryInterface() knows when we support nsIAccessibleSelectable
|
2007-12-11 18:10:26 -08:00
|
|
|
// based on role attribute and aria-multiselectable
|
2007-03-22 10:30:00 -07:00
|
|
|
*aInstancePtr = nsnull;
|
2008-08-06 05:19:56 -07:00
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) {
|
|
|
|
*aInstancePtr = &NS_CYCLE_COLLECTION_NAME(nsAccessible);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIAccessible))) {
|
2007-07-08 00:08:04 -07:00
|
|
|
*aInstancePtr = static_cast<nsIAccessible*>(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(aIID.Equals(NS_GET_IID(nsPIAccessible))) {
|
2007-07-08 00:08:04 -07:00
|
|
|
*aInstancePtr = static_cast<nsPIAccessible*>(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIAccessibleSelectable))) {
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
if (!content) {
|
|
|
|
return NS_ERROR_FAILURE; // This accessible has been shut down
|
|
|
|
}
|
2007-12-11 18:10:26 -08:00
|
|
|
if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::role)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// If we have an XHTML role attribute present and the
|
2007-12-11 18:10:26 -08:00
|
|
|
// aria-multiselectable attribute is true, then we need
|
2007-03-22 10:30:00 -07:00
|
|
|
// to support nsIAccessibleSelectable
|
|
|
|
// If either attribute (role or multiselectable) change, then we'll
|
|
|
|
// destroy this accessible so that we can follow COM identity rules.
|
2007-09-24 18:19:03 -07:00
|
|
|
nsAutoString multiselectable;
|
2007-12-11 18:10:26 -08:00
|
|
|
if (content->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::aria_multiselectable,
|
|
|
|
nsAccessibilityAtoms::_true, eCaseMatters)) {
|
2007-07-08 00:08:04 -07:00
|
|
|
*aInstancePtr = static_cast<nsIAccessibleSelectable*>(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ADDREF_THIS();
|
2007-08-14 17:53:32 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIAccessibleValue))) {
|
|
|
|
if (mRoleMapEntry && mRoleMapEntry->valueRule != eNoValue) {
|
2007-07-08 00:08:04 -07:00
|
|
|
*aInstancePtr = static_cast<nsIAccessibleValue*>(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ADDREF_THIS();
|
2007-08-14 17:53:32 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIAccessibleHyperLink))) {
|
|
|
|
nsCOMPtr<nsIAccessible> parent(GetParent());
|
|
|
|
nsCOMPtr<nsIAccessibleHyperText> hyperTextParent(do_QueryInterface(parent));
|
|
|
|
if (hyperTextParent) {
|
2007-07-08 00:08:04 -07:00
|
|
|
*aInstancePtr = static_cast<nsIAccessibleHyperLink*>(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
2007-08-10 12:30:02 -07:00
|
|
|
return nsAccessNodeWrap::QueryInterface(aIID, aInstancePtr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAccessible::nsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell): nsAccessNodeWrap(aNode, aShell),
|
|
|
|
mParent(nsnull), mFirstChild(nsnull), mNextSibling(nsnull), mRoleMapEntry(nsnull),
|
|
|
|
mAccChildCount(eChildCountUninitialized)
|
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG_X
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(aShell));
|
2007-04-23 08:37:55 -07:00
|
|
|
printf(">>> %p Created Acc - DOM: %p PS: %p",
|
2007-07-08 00:08:04 -07:00
|
|
|
(void*)static_cast<nsIAccessible*>(this), (void*)aNode,
|
2007-04-23 08:37:55 -07:00
|
|
|
(void*)shell.get());
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
|
|
|
if (content) {
|
|
|
|
nsAutoString buf;
|
|
|
|
if (content->NodeInfo())
|
|
|
|
content->NodeInfo()->GetQualifiedName(buf);
|
|
|
|
printf(" Con: %s@%p", NS_ConvertUTF16toUTF8(buf).get(), (void *)content.get());
|
|
|
|
if (NS_SUCCEEDED(GetName(buf))) {
|
|
|
|
printf(" Name:[%s]", NS_ConvertUTF16toUTF8(buf).get());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
// destruction
|
|
|
|
//-----------------------------------------------------
|
|
|
|
nsAccessible::~nsAccessible()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-11 17:05:37 -08:00
|
|
|
NS_IMETHODIMP nsAccessible::SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry)
|
|
|
|
{
|
|
|
|
mRoleMapEntry = aRoleMapEntry;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP nsAccessible::GetName(nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
if (!content) {
|
|
|
|
return NS_ERROR_FAILURE; // Node shut down
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool canAggregateName = mRoleMapEntry &&
|
|
|
|
mRoleMapEntry->nameRule == eNameOkFromChildren;
|
|
|
|
|
|
|
|
if (content->IsNodeOfType(nsINode::eHTML)) {
|
|
|
|
return GetHTMLName(aName, canAggregateName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content->IsNodeOfType(nsINode::eXUL)) {
|
|
|
|
return GetXULName(aName, canAggregateName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::GetDescription(nsAString& aDescription)
|
|
|
|
{
|
|
|
|
// There are 4 conditions that make an accessible have no accDescription:
|
|
|
|
// 1. it's a text node; or
|
|
|
|
// 2. It has no DHTML describedby property
|
|
|
|
// 3. it doesn't have an accName; or
|
|
|
|
// 4. its title attribute already equals to its accName nsAutoString name;
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
if (!content) {
|
|
|
|
return NS_ERROR_FAILURE; // Node shut down
|
|
|
|
}
|
|
|
|
if (!content->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
nsAutoString description;
|
2007-12-11 18:10:26 -08:00
|
|
|
nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_describedby, description);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PRBool isXUL = content->IsNodeOfType(nsINode::eXUL);
|
|
|
|
if (isXUL) {
|
|
|
|
// Try XUL <description control="[id]">description text</description>
|
|
|
|
nsIContent *descriptionContent =
|
2007-12-11 18:10:26 -08:00
|
|
|
nsAccUtils::FindNeighbourPointingToNode(content, nsAccessibilityAtoms::control,
|
|
|
|
nsAccessibilityAtoms::description);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (descriptionContent) {
|
|
|
|
// We have a description content node
|
|
|
|
AppendFlatStringFromSubtree(descriptionContent, &description);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (description.IsEmpty()) {
|
|
|
|
nsIAtom *descAtom = isXUL ? nsAccessibilityAtoms::tooltiptext :
|
|
|
|
nsAccessibilityAtoms::title;
|
|
|
|
if (content->GetAttr(kNameSpaceID_None, descAtom, description)) {
|
|
|
|
nsAutoString name;
|
|
|
|
GetName(name);
|
|
|
|
if (name.IsEmpty() || description == name) {
|
|
|
|
// Don't use tooltip for a description if this object
|
|
|
|
// has no name or the tooltip is the same as the name
|
|
|
|
description.Truncate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
description.CompressWhitespace();
|
|
|
|
aDescription = description;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mask values for ui.key.chromeAccess and ui.key.contentAccess
|
|
|
|
#define NS_MODIFIER_SHIFT 1
|
|
|
|
#define NS_MODIFIER_CONTROL 2
|
|
|
|
#define NS_MODIFIER_ALT 4
|
|
|
|
#define NS_MODIFIER_META 8
|
|
|
|
|
|
|
|
// returns the accesskey modifier mask used in the given node's context
|
|
|
|
// (i.e. chrome or content), or 0 if an error occurs
|
|
|
|
static PRInt32
|
2007-08-28 23:52:46 -07:00
|
|
|
GetAccessModifierMask(nsIContent* aContent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch =
|
|
|
|
do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (!prefBranch)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// use ui.key.generalAccessKey (unless it is -1)
|
|
|
|
PRInt32 accessKey;
|
|
|
|
nsresult rv = prefBranch->GetIntPref("ui.key.generalAccessKey", &accessKey);
|
|
|
|
if (NS_SUCCEEDED(rv) && accessKey != -1) {
|
|
|
|
switch (accessKey) {
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_SHIFT: return NS_MODIFIER_SHIFT;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_CONTROL: return NS_MODIFIER_CONTROL;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ALT: return NS_MODIFIER_ALT;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_META: return NS_MODIFIER_META;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the docShell to this DOMNode, return 0 on failure
|
2007-08-28 23:52:46 -07:00
|
|
|
nsCOMPtr<nsIDocument> document = aContent->GetCurrentDoc();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!document)
|
|
|
|
return 0;
|
|
|
|
nsCOMPtr<nsISupports> container = document->GetContainer();
|
|
|
|
if (!container)
|
|
|
|
return 0;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(container));
|
|
|
|
if (!treeItem)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// determine the access modifier used in this context
|
|
|
|
PRInt32 itemType, accessModifierMask = 0;
|
|
|
|
treeItem->GetItemType(&itemType);
|
|
|
|
switch (itemType) {
|
|
|
|
|
|
|
|
case nsIDocShellTreeItem::typeChrome:
|
|
|
|
rv = prefBranch->GetIntPref("ui.key.chromeAccess", &accessModifierMask);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDocShellTreeItem::typeContent:
|
|
|
|
rv = prefBranch->GetIntPref("ui.key.contentAccess", &accessModifierMask);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_SUCCEEDED(rv) ? accessModifierMask : 0;
|
|
|
|
}
|
|
|
|
|
2007-08-28 23:52:46 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetKeyboardShortcut(nsAString& aAccessKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-28 23:52:46 -07:00
|
|
|
aAccessKey.Truncate();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-28 23:52:46 -07:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
if (!content)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRUint32 key = nsAccUtils::GetAccessKeyFor(content);
|
2007-09-18 20:36:20 -07:00
|
|
|
if (!key && content->IsNodeOfType(nsIContent::eELEMENT)) {
|
|
|
|
// Copy access key from label node unless it is labeled
|
|
|
|
// via an ancestor <label>, in which case that would be redundant
|
2007-08-28 23:52:46 -07:00
|
|
|
nsCOMPtr<nsIContent> labelContent(GetLabelContent(content));
|
2007-09-18 20:36:20 -07:00
|
|
|
nsCOMPtr<nsIDOMNode> labelNode = do_QueryInterface(labelContent);
|
|
|
|
if (labelNode && !nsAccUtils::IsAncestorOf(labelNode, mDOMNode))
|
2007-08-28 23:52:46 -07:00
|
|
|
key = nsAccUtils::GetAccessKeyFor(labelContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!key)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
2007-08-28 23:52:46 -07:00
|
|
|
|
|
|
|
nsAutoString accesskey(key);
|
|
|
|
|
|
|
|
// Append the modifiers in reverse order, result: Control+Alt+Shift+Meta+<key>
|
|
|
|
nsAutoString propertyKey;
|
|
|
|
PRInt32 modifierMask = GetAccessModifierMask(content);
|
|
|
|
if (modifierMask & NS_MODIFIER_META) {
|
|
|
|
propertyKey.AssignLiteral("VK_META");
|
|
|
|
nsAccessible::GetFullKeyName(propertyKey, accesskey, accesskey);
|
|
|
|
}
|
|
|
|
if (modifierMask & NS_MODIFIER_SHIFT) {
|
|
|
|
propertyKey.AssignLiteral("VK_SHIFT");
|
|
|
|
nsAccessible::GetFullKeyName(propertyKey, accesskey, accesskey);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-28 23:52:46 -07:00
|
|
|
if (modifierMask & NS_MODIFIER_ALT) {
|
|
|
|
propertyKey.AssignLiteral("VK_ALT");
|
|
|
|
nsAccessible::GetFullKeyName(propertyKey, accesskey, accesskey);
|
|
|
|
}
|
|
|
|
if (modifierMask & NS_MODIFIER_CONTROL) {
|
|
|
|
propertyKey.AssignLiteral("VK_CONTROL");
|
|
|
|
nsAccessible::GetFullKeyName(propertyKey, accesskey, accesskey);
|
|
|
|
}
|
|
|
|
|
|
|
|
aAccessKey = accesskey;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::SetParent(nsIAccessible *aParent)
|
|
|
|
{
|
2007-11-13 11:47:15 -08:00
|
|
|
if (mParent != aParent) {
|
|
|
|
// Adopt a child -- we allow this now. the new parent
|
|
|
|
// may be a dom node which wasn't previously accessible but now is.
|
|
|
|
// The old parent's children now need to be invalidated, since
|
|
|
|
// it no longer owns the child, the new parent does
|
|
|
|
nsCOMPtr<nsPIAccessible> privOldParent = do_QueryInterface(mParent);
|
|
|
|
if (privOldParent) {
|
|
|
|
privOldParent->InvalidateChildren();
|
2007-09-28 13:55:46 -07:00
|
|
|
}
|
|
|
|
}
|
2007-11-13 11:47:15 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mParent = aParent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::SetFirstChild(nsIAccessible *aFirstChild)
|
|
|
|
{
|
|
|
|
mFirstChild = aFirstChild;
|
2007-04-24 11:20:52 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::SetNextSibling(nsIAccessible *aNextSibling)
|
|
|
|
{
|
2008-08-06 05:19:56 -07:00
|
|
|
mNextSibling = aNextSibling;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *nsAccessible::GetRoleContent(nsIDOMNode *aDOMNode)
|
|
|
|
{
|
|
|
|
// Given the DOM node for an acessible, return content node that
|
2008-03-14 13:49:38 -07:00
|
|
|
// we should look for ARIA properties on.
|
2007-03-22 10:30:00 -07:00
|
|
|
// For non-document accessibles, this is the associated content node.
|
2008-03-14 13:49:38 -07:00
|
|
|
// For doc accessibles, use the <body>/<frameset> if it's HTML.
|
2007-03-22 10:30:00 -07:00
|
|
|
// For any other doc accessible , this is the document element.
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aDOMNode));
|
|
|
|
if (!content) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aDOMNode));
|
|
|
|
if (domDoc) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(aDOMNode));
|
|
|
|
if (htmlDoc) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> bodyElement;
|
|
|
|
htmlDoc->GetBody(getter_AddRefs(bodyElement));
|
|
|
|
content = do_QueryInterface(bodyElement);
|
|
|
|
}
|
2008-03-14 13:49:38 -07:00
|
|
|
else {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> docElement;
|
|
|
|
domDoc->GetDocumentElement(getter_AddRefs(docElement));
|
|
|
|
content = do_QueryInterface(docElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::Shutdown()
|
|
|
|
{
|
|
|
|
mNextSibling = nsnull;
|
2007-11-22 00:19:49 -08:00
|
|
|
|
|
|
|
// Invalidate the child count and pointers to other accessibles, also make
|
|
|
|
// sure none of it's children point to this parent
|
2007-03-22 10:30:00 -07:00
|
|
|
InvalidateChildren();
|
|
|
|
if (mParent) {
|
|
|
|
nsCOMPtr<nsPIAccessible> privateParent(do_QueryInterface(mParent));
|
|
|
|
privateParent->InvalidateChildren();
|
|
|
|
mParent = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsAccessNodeWrap::Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::InvalidateChildren()
|
|
|
|
{
|
|
|
|
// Document has transformed, reset our invalid children and child count
|
2007-07-23 07:01:46 -07:00
|
|
|
|
|
|
|
// Reset the sibling pointers, they will be set up again the next time
|
|
|
|
// CacheChildren() is called.
|
|
|
|
// Note: we don't want to start creating accessibles at this point,
|
|
|
|
// so don't use GetNextSibling() here. (bug 387252)
|
2008-08-06 05:19:56 -07:00
|
|
|
nsAccessible* child = static_cast<nsAccessible*>(mFirstChild.get());
|
2007-11-13 11:47:15 -08:00
|
|
|
while (child) {
|
|
|
|
child->mParent = nsnull;
|
2008-08-06 05:19:56 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> next = child->mNextSibling;
|
2007-07-23 07:01:46 -07:00
|
|
|
child->mNextSibling = nsnull;
|
2008-08-06 05:19:56 -07:00
|
|
|
child = static_cast<nsAccessible*>(next.get());
|
2007-07-23 07:01:46 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mAccChildCount = eChildCountUninitialized;
|
|
|
|
mFirstChild = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::GetParent(nsIAccessible ** aParent)
|
|
|
|
{
|
|
|
|
nsresult rv = GetCachedParent(aParent);
|
|
|
|
if (NS_FAILED(rv) || *aParent) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessibleDocument> docAccessible(GetDocAccessible());
|
|
|
|
NS_ENSURE_TRUE(docAccessible, NS_ERROR_FAILURE);
|
|
|
|
|
2007-10-01 11:27:13 -07:00
|
|
|
return docAccessible->GetAccessibleInParentChain(mDOMNode, PR_TRUE, aParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::GetCachedParent(nsIAccessible ** aParent)
|
|
|
|
{
|
|
|
|
*aParent = nsnull;
|
|
|
|
if (!mWeakShell) {
|
|
|
|
// This node has been shut down
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
NS_IF_ADDREF(*aParent = mParent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-09-28 13:55:46 -07:00
|
|
|
NS_IMETHODIMP nsAccessible::GetCachedFirstChild(nsIAccessible ** aFirstChild)
|
|
|
|
{
|
|
|
|
*aFirstChild = nsnull;
|
|
|
|
if (!mWeakShell) {
|
|
|
|
// This node has been shut down
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
NS_IF_ADDREF(*aFirstChild = mFirstChild);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* readonly attribute nsIAccessible nextSibling; */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetNextSibling(nsIAccessible * *aNextSibling)
|
|
|
|
{
|
|
|
|
*aNextSibling = nsnull;
|
|
|
|
if (!mWeakShell) {
|
|
|
|
// This node has been shut down
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (!mParent) {
|
|
|
|
nsCOMPtr<nsIAccessible> parent(GetParent());
|
|
|
|
if (parent) {
|
|
|
|
PRInt32 numChildren;
|
|
|
|
parent->GetChildCount(&numChildren); // Make sure we cache all of the children
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNextSibling || !mParent) {
|
|
|
|
// If no parent, don't try to calculate a new sibling
|
|
|
|
// It either means we're at the root or shutting down the parent
|
2008-08-06 05:19:56 -07:00
|
|
|
NS_IF_ADDREF(*aNextSibling = mNextSibling);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute nsIAccessible previousSibling; */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetPreviousSibling(nsIAccessible * *aPreviousSibling)
|
|
|
|
{
|
|
|
|
*aPreviousSibling = nsnull;
|
|
|
|
|
|
|
|
if (!mWeakShell) {
|
|
|
|
// This node has been shut down
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> parent;
|
|
|
|
if (NS_FAILED(GetParent(getter_AddRefs(parent))) || !parent) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> testAccessible, prevSibling;
|
|
|
|
parent->GetFirstChild(getter_AddRefs(testAccessible));
|
|
|
|
while (testAccessible && this != testAccessible) {
|
|
|
|
prevSibling = testAccessible;
|
|
|
|
prevSibling->GetNextSibling(getter_AddRefs(testAccessible));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prevSibling) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aPreviousSibling = prevSibling);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute nsIAccessible firstChild; */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetFirstChild(nsIAccessible * *aFirstChild)
|
|
|
|
{
|
|
|
|
if (gIsCacheDisabled) {
|
|
|
|
InvalidateChildren();
|
|
|
|
}
|
|
|
|
PRInt32 numChildren;
|
|
|
|
GetChildCount(&numChildren); // Make sure we cache all of the children
|
|
|
|
|
2007-09-28 13:55:46 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsPIAccessible> firstChild(do_QueryInterface(mFirstChild));
|
|
|
|
if (firstChild) {
|
|
|
|
nsCOMPtr<nsIAccessible> realParent;
|
|
|
|
firstChild->GetCachedParent(getter_AddRefs(realParent));
|
|
|
|
NS_ASSERTION(!realParent || realParent == this,
|
|
|
|
"Two accessibles have the same first child accessible.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IF_ADDREF(*aFirstChild = mFirstChild);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute nsIAccessible lastChild; */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetLastChild(nsIAccessible * *aLastChild)
|
|
|
|
{
|
|
|
|
GetChildAt(-1, aLastChild);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::GetChildAt(PRInt32 aChildNum, nsIAccessible **aChild)
|
|
|
|
{
|
|
|
|
// aChildNum is a zero-based index
|
|
|
|
|
|
|
|
PRInt32 numChildren;
|
|
|
|
GetChildCount(&numChildren);
|
|
|
|
|
|
|
|
// If no children or aChildNum is larger than numChildren, return null
|
|
|
|
if (aChildNum >= numChildren || numChildren == 0 || !mWeakShell) {
|
|
|
|
*aChild = nsnull;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
// If aChildNum is less than zero, set aChild to last index
|
|
|
|
} else if (aChildNum < 0) {
|
|
|
|
aChildNum = numChildren - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> current(mFirstChild), nextSibling;
|
|
|
|
PRInt32 index = 0;
|
|
|
|
|
|
|
|
while (current) {
|
|
|
|
nextSibling = current;
|
|
|
|
if (++index > aChildNum) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nextSibling->GetNextSibling(getter_AddRefs(current));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aChild = nextSibling);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// readonly attribute nsIArray children;
|
|
|
|
NS_IMETHODIMP nsAccessible::GetChildren(nsIArray **aOutChildren)
|
|
|
|
{
|
2008-01-28 20:03:26 -08:00
|
|
|
*aOutChildren = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIMutableArray> children = do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
if (!children)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> curChild;
|
|
|
|
while (NextChild(curChild)) {
|
|
|
|
children->AppendElement(curChild, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aOutChildren = children);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAccessible *nsAccessible::NextChild(nsCOMPtr<nsIAccessible>& aAccessible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessible> nextChild;
|
|
|
|
if (!aAccessible) {
|
|
|
|
GetFirstChild(getter_AddRefs(nextChild));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aAccessible->GetNextSibling(getter_AddRefs(nextChild));
|
|
|
|
}
|
|
|
|
return (aAccessible = nextChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsAccessible::CacheChildren()
|
|
|
|
{
|
|
|
|
if (!mWeakShell) {
|
|
|
|
// This node has been shut down
|
|
|
|
mAccChildCount = eChildCountUninitialized;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAccChildCount == eChildCountUninitialized) {
|
2007-12-02 14:23:51 -08:00
|
|
|
mAccChildCount = 0;// Prevent reentry
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool allowsAnonChildren = PR_FALSE;
|
|
|
|
GetAllowsAnonChildAccessibles(&allowsAnonChildren);
|
|
|
|
nsAccessibleTreeWalker walker(mWeakShell, mDOMNode, allowsAnonChildren);
|
|
|
|
// Seed the frame hint early while we're still on a container node.
|
|
|
|
// This is better than doing the GetPrimaryFrameFor() later on
|
|
|
|
// a text node, because text nodes aren't in the frame map.
|
|
|
|
walker.mState.frame = GetFrame();
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIAccessible> privatePrevAccessible;
|
|
|
|
PRInt32 childCount = 0;
|
|
|
|
walker.GetFirstChild();
|
|
|
|
SetFirstChild(walker.mState.accessible);
|
|
|
|
|
|
|
|
while (walker.mState.accessible) {
|
|
|
|
++ childCount;
|
|
|
|
privatePrevAccessible = do_QueryInterface(walker.mState.accessible);
|
|
|
|
privatePrevAccessible->SetParent(this);
|
|
|
|
walker.GetNextSibling();
|
|
|
|
privatePrevAccessible->SetNextSibling(walker.mState.accessible);
|
|
|
|
}
|
|
|
|
mAccChildCount = childCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::GetAllowsAnonChildAccessibles(PRBool *aAllowsAnonChildren)
|
|
|
|
{
|
|
|
|
*aAllowsAnonChildren = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute long childCount; */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetChildCount(PRInt32 *aAccChildCount)
|
|
|
|
{
|
|
|
|
CacheChildren();
|
|
|
|
*aAccChildCount = mAccChildCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute long indexInParent; */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetIndexInParent(PRInt32 *aIndexInParent)
|
|
|
|
{
|
|
|
|
*aIndexInParent = -1;
|
|
|
|
if (!mWeakShell) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> parent;
|
|
|
|
GetParent(getter_AddRefs(parent));
|
|
|
|
if (!parent) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> sibling;
|
|
|
|
parent->GetFirstChild(getter_AddRefs(sibling));
|
|
|
|
if (!sibling) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aIndexInParent = 0;
|
|
|
|
while (sibling != this) {
|
|
|
|
NS_ASSERTION(sibling, "Never ran into the same child that we started from");
|
|
|
|
|
|
|
|
if (!sibling)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
++*aIndexInParent;
|
|
|
|
nsCOMPtr<nsIAccessible> tempAccessible;
|
|
|
|
sibling->GetNextSibling(getter_AddRefs(tempAccessible));
|
|
|
|
sibling = tempAccessible;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::TestChildCache(nsIAccessible *aCachedChild)
|
|
|
|
{
|
|
|
|
#ifndef DEBUG_A11Y
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
// All cached accessible nodes should be in the parent
|
|
|
|
// It will assert if not all the children were created
|
|
|
|
// when they were first cached, and no invalidation
|
|
|
|
// ever corrected parent accessible's child cache.
|
2008-01-25 05:52:44 -08:00
|
|
|
if (mAccChildCount <= 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIAccessible> sibling = mFirstChild;
|
|
|
|
|
|
|
|
while (sibling != aCachedChild) {
|
|
|
|
NS_ASSERTION(sibling, "[TestChildCache] Never ran into the same child that we started from");
|
|
|
|
if (!sibling)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> tempAccessible;
|
|
|
|
sibling->GetNextSibling(getter_AddRefs(tempAccessible));
|
|
|
|
sibling = tempAccessible;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsAccessible::GetTranslatedString(const nsAString& aKey, nsAString& aStringOut)
|
|
|
|
{
|
|
|
|
nsXPIDLString xsValue;
|
|
|
|
|
|
|
|
if (!gStringBundle ||
|
|
|
|
NS_FAILED(gStringBundle->GetStringFromName(PromiseFlatString(aKey).get(), getter_Copies(xsValue))))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
aStringOut.Assign(xsValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsAccessible::GetFullKeyName(const nsAString& aModifierName, const nsAString& aKeyName, nsAString& aStringOut)
|
|
|
|
{
|
|
|
|
nsXPIDLString modifierName, separator;
|
|
|
|
|
|
|
|
if (!gKeyStringBundle ||
|
|
|
|
NS_FAILED(gKeyStringBundle->GetStringFromName(PromiseFlatString(aModifierName).get(),
|
|
|
|
getter_Copies(modifierName))) ||
|
|
|
|
NS_FAILED(gKeyStringBundle->GetStringFromName(PromiseFlatString(NS_LITERAL_STRING("MODIFIER_SEPARATOR")).get(),
|
|
|
|
getter_Copies(separator)))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aStringOut = modifierName + separator + aKeyName;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsAccessible::IsVisible(PRBool *aIsOffscreen)
|
|
|
|
{
|
|
|
|
// We need to know if at least a kMinPixels around the object is visible
|
|
|
|
// Otherwise it will be marked nsIAccessibleStates::STATE_OFFSCREEN
|
|
|
|
// The STATE_INVISIBLE flag is for elements which are programmatically hidden
|
|
|
|
|
2007-04-23 08:41:26 -07:00
|
|
|
*aIsOffscreen = PR_TRUE;
|
2007-11-09 11:01:52 -08:00
|
|
|
if (!mDOMNode) {
|
|
|
|
return PR_FALSE; // Defunct object
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const PRUint16 kMinPixels = 12;
|
|
|
|
// Set up the variables we need, return false if we can't get at them all
|
|
|
|
nsCOMPtr<nsIPresShell> shell(GetPresShell());
|
|
|
|
if (!shell)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIViewManager* viewManager = shell->GetViewManager();
|
|
|
|
if (!viewManager)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (!frame) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If visibility:hidden or visibility:collapsed then mark with STATE_INVISIBLE
|
|
|
|
if (!frame->GetStyleVisibility()->IsVisible())
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext *presContext = shell->GetPresContext();
|
|
|
|
if (!presContext)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// Get the bounds of the current frame, relative to the current view.
|
|
|
|
// We don't use the more accurate GetBoundsRect, because that is more expensive
|
|
|
|
// and the STATE_OFFSCREEN flag that this is used for only needs to be a rough
|
|
|
|
// indicator
|
|
|
|
|
|
|
|
nsRect relFrameRect = frame->GetRect();
|
|
|
|
nsIView *containingView = frame->GetViewExternal();
|
2007-05-06 20:12:00 -07:00
|
|
|
if (containingView) {
|
|
|
|
// When frame itself has a view, it has the same bounds as the view
|
|
|
|
relFrameRect.x = relFrameRect.y = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsPoint frameOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
frame->GetOffsetFromView(frameOffset, &containingView);
|
|
|
|
if (!containingView)
|
|
|
|
return PR_FALSE; // no view -- not visible
|
|
|
|
relFrameRect.x = frameOffset.x;
|
|
|
|
relFrameRect.y = frameOffset.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRectVisibility rectVisibility;
|
|
|
|
viewManager->GetRectVisibility(containingView, relFrameRect,
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(kMinPixels),
|
|
|
|
&rectVisibility);
|
|
|
|
|
|
|
|
if (rectVisibility == nsRectVisibility_kZeroAreaRect) {
|
2007-12-19 04:57:08 -08:00
|
|
|
nsIAtom *frameType = frame->GetType();
|
|
|
|
if (frameType == nsAccessibilityAtoms::textFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Zero area rects can occur in the first frame of a multi-frame text flow,
|
2007-12-19 04:57:08 -08:00
|
|
|
// in which case the rendered text is not empty and the frame should not be marked invisible
|
|
|
|
nsAutoString renderedText;
|
|
|
|
frame->GetRenderedText (&renderedText, nsnull, nsnull, 0, 1);
|
|
|
|
if (!renderedText.IsEmpty()) {
|
|
|
|
rectVisibility = nsRectVisibility_kVisible;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-12-19 04:57:08 -08:00
|
|
|
else if (frameType == nsAccessibilityAtoms::inlineFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Yuck. Unfortunately inline frames can contain larger frames inside of them,
|
|
|
|
// so we can't really believe this is a zero area rect without checking more deeply.
|
|
|
|
// GetBounds() will do that for us.
|
|
|
|
PRInt32 x, y, width, height;
|
|
|
|
GetBounds(&x, &y, &width, &height);
|
|
|
|
if (width > 0 && height > 0) {
|
|
|
|
rectVisibility = nsRectVisibility_kVisible;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-09 11:01:52 -08:00
|
|
|
if (rectVisibility == nsRectVisibility_kZeroAreaRect && frame &&
|
|
|
|
0 == (frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) {
|
|
|
|
// Consider zero area objects hidden unless they are absoultely positioned
|
|
|
|
// or floating and may have descendants that have a non-zero size
|
|
|
|
return PR_FALSE;
|
2007-04-23 08:41:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Currently one of:
|
|
|
|
// nsRectVisibility_kVisible,
|
|
|
|
// nsRectVisibility_kAboveViewport,
|
|
|
|
// nsRectVisibility_kBelowViewport,
|
|
|
|
// nsRectVisibility_kLeftOfViewport,
|
|
|
|
// nsRectVisibility_kRightOfViewport
|
|
|
|
// This view says it is visible, but we need to check the parent view chain :(
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
|
|
|
|
if (!doc) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-23 08:41:26 -07:00
|
|
|
PRBool isVisible = CheckVisibilityInParentChain(doc, containingView);
|
|
|
|
if (isVisible && rectVisibility == nsRectVisibility_kVisible) {
|
|
|
|
*aIsOffscreen = PR_FALSE;
|
|
|
|
}
|
|
|
|
return isVisible;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-29 06:36:07 -07:00
|
|
|
nsresult
|
2007-04-02 08:56:24 -07:00
|
|
|
nsAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
*aState = 0;
|
|
|
|
|
2007-11-15 11:53:40 -08:00
|
|
|
if (!mDOMNode) {
|
|
|
|
if (aExtraState) {
|
|
|
|
*aExtraState = nsIAccessibleStates::EXT_STATE_DEFUNCT;
|
|
|
|
}
|
2007-04-02 08:56:24 -07:00
|
|
|
return NS_OK; // Node shut down
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-11-15 11:53:40 -08:00
|
|
|
if (aExtraState)
|
|
|
|
*aExtraState = 0;
|
|
|
|
|
2007-04-02 08:56:24 -07:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
2007-04-18 06:40:52 -07:00
|
|
|
if (!content) {
|
|
|
|
return NS_OK; // On document, this is not an error
|
|
|
|
}
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Set STATE_UNAVAILABLE state based on disabled attribute
|
|
|
|
// The disabled attribute is mostly used in XUL elements and HTML forms, but
|
|
|
|
// if someone sets it on another attribute,
|
|
|
|
// it seems reasonable to consider it unavailable
|
|
|
|
PRBool isDisabled;
|
|
|
|
if (content->IsNodeOfType(nsINode::eHTML)) {
|
|
|
|
// In HTML, just the presence of the disabled attribute means it is disabled,
|
|
|
|
// therefore disabled="false" indicates disabled!
|
|
|
|
isDisabled = content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::disabled);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
isDisabled = content->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::disabled,
|
|
|
|
nsAccessibilityAtoms::_true,
|
|
|
|
eCaseMatters);
|
|
|
|
}
|
|
|
|
if (isDisabled) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
else if (content->IsNodeOfType(nsINode::eELEMENT)) {
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (frame && frame->IsFocusable()) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_FOCUSABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gLastFocusedNode == mDOMNode) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_FOCUSED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if nsIAccessibleStates::STATE_INVISIBLE and
|
|
|
|
// STATE_OFFSCREEN flags should be turned on for this object.
|
|
|
|
PRBool isOffscreen;
|
|
|
|
if (!IsVisible(&isOffscreen)) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_INVISIBLE;
|
|
|
|
}
|
|
|
|
if (isOffscreen) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_OFFSCREEN;
|
|
|
|
}
|
|
|
|
|
2007-09-05 09:45:48 -07:00
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (frame && (frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW))
|
|
|
|
*aState |= nsIAccessibleStates::STATE_FLOATING;
|
|
|
|
|
2008-03-30 23:21:35 -07:00
|
|
|
// Add 'linked' state for simple xlink.
|
|
|
|
if (nsAccUtils::IsXLink(content))
|
|
|
|
*aState |= nsIAccessibleStates::STATE_LINKED;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute boolean focusedChild; */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetFocusedChild(nsIAccessible **aFocusedChild)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessible> focusedChild;
|
|
|
|
if (gLastFocusedNode == mDOMNode) {
|
|
|
|
focusedChild = this;
|
|
|
|
}
|
|
|
|
else if (gLastFocusedNode) {
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService =
|
|
|
|
do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
NS_ENSURE_TRUE(accService, NS_ERROR_FAILURE);
|
2007-04-20 06:35:35 -07:00
|
|
|
|
|
|
|
accService->GetAccessibleFor(gLastFocusedNode,
|
|
|
|
getter_AddRefs(focusedChild));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (focusedChild) {
|
|
|
|
nsCOMPtr<nsIAccessible> focusedParentAccessible;
|
|
|
|
focusedChild->GetParent(getter_AddRefs(focusedParentAccessible));
|
|
|
|
if (focusedParentAccessible != this) {
|
|
|
|
focusedChild = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aFocusedChild = focusedChild);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsIAccessible getChildAtPoint (in long x, in long y); */
|
2007-09-05 01:00:40 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetChildAtPoint(PRInt32 aX, PRInt32 aY,
|
|
|
|
nsIAccessible **aAccessible)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-09-05 01:00:40 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aAccessible);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aAccessible = nsnull;
|
|
|
|
|
2007-09-18 14:44:43 -07:00
|
|
|
if (!mDOMNode) {
|
|
|
|
return NS_ERROR_FAILURE; // Already shut down
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we can't find the point in a child, we will return the fallback answer:
|
|
|
|
// we return |this| if the point is within it, otherwise nsnull
|
|
|
|
nsCOMPtr<nsIAccessible> fallbackAnswer;
|
|
|
|
PRInt32 x, y, width, height;
|
|
|
|
GetBounds(&x, &y, &width, &height);
|
|
|
|
if (aX >= x && aX < x + width &&
|
|
|
|
aY >= y && aY < y + height) {
|
|
|
|
fallbackAnswer = this;
|
|
|
|
}
|
|
|
|
if (MustPrune(this)) { // Do not dig any further
|
|
|
|
NS_IF_ADDREF(*aAccessible = fallbackAnswer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-09-05 01:00:40 -07:00
|
|
|
// Search an accessible at the given point starting from accessible document
|
|
|
|
// because containing block (see CSS2) for out of flow element (for example,
|
|
|
|
// absolutely positioned element) may be different from its DOM parent and
|
|
|
|
// therefore accessible for containing block may be different from accessible
|
|
|
|
// for DOM parent but GetFrameForPoint() should be called for containing block
|
|
|
|
// to get an out of flow element.
|
|
|
|
nsCOMPtr<nsIAccessibleDocument> accDocument;
|
|
|
|
nsresult rv = GetAccessibleDocument(getter_AddRefs(accDocument));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-09-18 14:44:43 -07:00
|
|
|
NS_ENSURE_TRUE(accDocument, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-05 01:00:40 -07:00
|
|
|
nsCOMPtr<nsPIAccessNode> accessNodeDocument(do_QueryInterface(accDocument));
|
|
|
|
NS_ASSERTION(accessNodeDocument,
|
|
|
|
"nsIAccessibleDocument doesn't implement nsPIAccessNode");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-05 01:00:40 -07:00
|
|
|
nsIFrame *frame = accessNodeDocument->GetFrame();
|
|
|
|
NS_ENSURE_STATE(frame);
|
|
|
|
|
|
|
|
nsPresContext *presContext = frame->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-05 01:00:40 -07:00
|
|
|
nsIntRect screenRect = frame->GetScreenRectExternal();
|
|
|
|
nsPoint offset(presContext->DevPixelsToAppUnits(aX - screenRect.x),
|
|
|
|
presContext->DevPixelsToAppUnits(aY - screenRect.y));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = presContext->PresShell();
|
|
|
|
nsIFrame *foundFrame = presShell->GetFrameForPoint(frame, offset);
|
2007-09-18 14:44:43 -07:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
if (!foundFrame || !(content = foundFrame->GetContent())) {
|
|
|
|
NS_IF_ADDREF(*aAccessible = fallbackAnswer);
|
2007-09-05 01:00:40 -07:00
|
|
|
return NS_OK;
|
2007-09-18 14:44:43 -07:00
|
|
|
}
|
2007-09-05 01:00:40 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = GetAccService();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> relevantNode;
|
|
|
|
accService->GetRelevantContentNodeFor(node, getter_AddRefs(relevantNode));
|
2007-09-18 14:44:43 -07:00
|
|
|
if (!relevantNode) {
|
|
|
|
NS_IF_ADDREF(*aAccessible = fallbackAnswer);
|
2007-09-05 01:00:40 -07:00
|
|
|
return NS_OK;
|
2007-09-18 14:44:43 -07:00
|
|
|
}
|
2007-09-05 01:00:40 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> accessible;
|
|
|
|
accService->GetAccessibleFor(relevantNode, getter_AddRefs(accessible));
|
2007-09-18 14:44:43 -07:00
|
|
|
if (!accessible) {
|
|
|
|
// No accessible for the node with the point, so find the first
|
|
|
|
// accessible in the DOM parent chain
|
2007-10-01 11:27:13 -07:00
|
|
|
accDocument->GetAccessibleInParentChain(relevantNode, PR_TRUE,
|
2007-09-18 14:44:43 -07:00
|
|
|
getter_AddRefs(accessible));
|
|
|
|
if (!accessible) {
|
|
|
|
NS_IF_ADDREF(*aAccessible = fallbackAnswer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-09-05 01:00:40 -07:00
|
|
|
|
2007-09-18 14:44:43 -07:00
|
|
|
if (accessible == this) {
|
|
|
|
// Manually walk through accessible children and see if
|
|
|
|
// the are within this point.
|
|
|
|
// This takes care of cases where layout won't walk into
|
|
|
|
// things for us, such as image map areas and sub documents
|
|
|
|
nsCOMPtr<nsIAccessible> child;
|
|
|
|
while (NextChild(child)) {
|
|
|
|
PRInt32 childX, childY, childWidth, childHeight;
|
|
|
|
child->GetBounds(&childX, &childY, &childWidth, &childHeight);
|
|
|
|
if (aX >= childX && aX < childX + childWidth &&
|
|
|
|
aY >= childY && aY < childY + childHeight &&
|
|
|
|
(State(child) & nsIAccessibleStates::STATE_INVISIBLE) == 0) {
|
|
|
|
// Don't walk into offscreen or invisible items
|
|
|
|
NS_IF_ADDREF(*aAccessible = child);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Fall through -- the point is in this accessible but not in a child
|
|
|
|
// We are allowed to return |this| as the answer
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIAccessible> parent;
|
|
|
|
while (PR_TRUE) {
|
|
|
|
accessible->GetParent(getter_AddRefs(parent));
|
|
|
|
if (!parent) {
|
|
|
|
// Reached the top of the hierarchy
|
|
|
|
// these bounds were inside an accessible that is not a descendant of this one
|
|
|
|
NS_IF_ADDREF(*aAccessible = fallbackAnswer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (parent == this) {
|
|
|
|
// We reached |this|, so |accessible| is the
|
|
|
|
// child we want to return
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
accessible.swap(parent);
|
|
|
|
}
|
|
|
|
}
|
2007-09-05 01:00:40 -07:00
|
|
|
|
2007-09-18 14:44:43 -07:00
|
|
|
NS_IF_ADDREF(*aAccessible = accessible);
|
2007-09-05 01:00:40 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsAccessible::GetBoundsRect(nsRect& aTotalBounds, nsIFrame** aBoundingFrame)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This method is used to determine the bounds of a content node.
|
|
|
|
* Because HTML wraps and links are not always rectangular, this
|
|
|
|
* method uses the following algorithm:
|
|
|
|
*
|
|
|
|
* 1) Start with an empty rectangle
|
|
|
|
* 2) Add the rect for the primary frame from for the DOM node.
|
|
|
|
* 3) For each next frame at the same depth with the same DOM node, add that rect to total
|
|
|
|
* 4) If that frame is an inline frame, search deeper at that point in the tree, adding all rects
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Initialization area
|
|
|
|
*aBoundingFrame = nsnull;
|
|
|
|
nsIFrame *firstFrame = GetBoundsFrame();
|
|
|
|
if (!firstFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Find common relative parent
|
|
|
|
// This is an ancestor frame that will incompass all frames for this content node.
|
|
|
|
// We need the relative parent so we can get absolute screen coordinates
|
|
|
|
nsIFrame *ancestorFrame = firstFrame;
|
|
|
|
|
|
|
|
while (ancestorFrame) {
|
|
|
|
*aBoundingFrame = ancestorFrame;
|
|
|
|
// If any other frame type, we only need to deal with the primary frame
|
|
|
|
// Otherwise, there may be more frames attached to the same content node
|
|
|
|
if (!IsCorrectFrameType(ancestorFrame, nsAccessibilityAtoms::inlineFrame) &&
|
|
|
|
!IsCorrectFrameType(ancestorFrame, nsAccessibilityAtoms::textFrame))
|
|
|
|
break;
|
|
|
|
ancestorFrame = ancestorFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *iterFrame = firstFrame;
|
|
|
|
nsCOMPtr<nsIContent> firstContent(do_QueryInterface(mDOMNode));
|
|
|
|
nsIContent* iterContent = firstContent;
|
|
|
|
PRInt32 depth = 0;
|
|
|
|
|
|
|
|
// Look only at frames below this depth, or at this depth (if we're still on the content node we started with)
|
|
|
|
while (iterContent == firstContent || depth > 0) {
|
|
|
|
// Coordinates will come back relative to parent frame
|
|
|
|
nsRect currFrameBounds = iterFrame->GetRect();
|
|
|
|
|
|
|
|
// Make this frame's bounds relative to common parent frame
|
|
|
|
currFrameBounds +=
|
|
|
|
iterFrame->GetParent()->GetOffsetToExternal(*aBoundingFrame);
|
|
|
|
|
|
|
|
// Add this frame's bounds to total
|
|
|
|
aTotalBounds.UnionRect(aTotalBounds, currFrameBounds);
|
|
|
|
|
|
|
|
nsIFrame *iterNextFrame = nsnull;
|
|
|
|
|
|
|
|
if (IsCorrectFrameType(iterFrame, nsAccessibilityAtoms::inlineFrame)) {
|
|
|
|
// Only do deeper bounds search if we're on an inline frame
|
|
|
|
// Inline frames can contain larger frames inside of them
|
|
|
|
iterNextFrame = iterFrame->GetFirstChild(nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iterNextFrame)
|
|
|
|
++depth; // Child was found in code above this: We are going deeper in this iteration of the loop
|
|
|
|
else {
|
|
|
|
// Use next sibling if it exists, or go back up the tree to get the first next-in-flow or next-sibling
|
|
|
|
// within our search
|
|
|
|
while (iterFrame) {
|
|
|
|
iterNextFrame = iterFrame->GetNextContinuation();
|
|
|
|
if (!iterNextFrame)
|
|
|
|
iterNextFrame = iterFrame->GetNextSibling();
|
|
|
|
if (iterNextFrame || --depth < 0)
|
|
|
|
break;
|
|
|
|
iterFrame = iterFrame->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get ready for the next round of our loop
|
|
|
|
iterFrame = iterNextFrame;
|
|
|
|
if (iterFrame == nsnull)
|
|
|
|
break;
|
|
|
|
iterContent = nsnull;
|
|
|
|
if (depth == 0)
|
|
|
|
iterContent = iterFrame->GetContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* void getBounds (out long x, out long y, out long width, out long height); */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetBounds(PRInt32 *x, PRInt32 *y, PRInt32 *width, PRInt32 *height)
|
|
|
|
{
|
|
|
|
// This routine will get the entire rectange for all the frames in this node
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Primary Frame for node
|
|
|
|
// Another frame, same node <- Example
|
|
|
|
// Another frame, same node
|
|
|
|
|
|
|
|
nsPresContext *presContext = GetPresContext();
|
|
|
|
if (!presContext)
|
|
|
|
{
|
|
|
|
*x = *y = *width = *height = 0;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect unionRectTwips;
|
|
|
|
nsIFrame* aBoundingFrame = nsnull;
|
|
|
|
GetBoundsRect(unionRectTwips, &aBoundingFrame); // Unions up all primary frames for this node and all siblings after it
|
|
|
|
if (!aBoundingFrame) {
|
|
|
|
*x = *y = *width = *height = 0;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*x = presContext->AppUnitsToDevPixels(unionRectTwips.x);
|
|
|
|
*y = presContext->AppUnitsToDevPixels(unionRectTwips.y);
|
|
|
|
*width = presContext->AppUnitsToDevPixels(unionRectTwips.width);
|
|
|
|
*height = presContext->AppUnitsToDevPixels(unionRectTwips.height);
|
|
|
|
|
|
|
|
// We have the union of the rectangle, now we need to put it in absolute screen coords
|
|
|
|
|
|
|
|
nsRect orgRectPixels = aBoundingFrame->GetScreenRectExternal();
|
|
|
|
*x += orgRectPixels.x;
|
|
|
|
*y += orgRectPixels.y;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// helpers
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Static
|
|
|
|
* Helper method to help sub classes make sure they have the proper
|
|
|
|
* frame when walking the frame tree to get at children and such
|
|
|
|
*/
|
|
|
|
PRBool nsAccessible::IsCorrectFrameType( nsIFrame* aFrame, nsIAtom* aAtom )
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame != nsnull, "aFrame is null in call to IsCorrectFrameType!");
|
|
|
|
NS_ASSERTION(aAtom != nsnull, "aAtom is null in call to IsCorrectFrameType!");
|
|
|
|
|
|
|
|
return aFrame->GetType() == aAtom;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsIFrame* nsAccessible::GetBoundsFrame()
|
|
|
|
{
|
|
|
|
return GetFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIAccessible>
|
|
|
|
nsAccessible::GetMultiSelectFor(nsIDOMNode *aNode)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aNode, nsnull);
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService =
|
|
|
|
do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
NS_ENSURE_TRUE(accService, nsnull);
|
|
|
|
nsCOMPtr<nsIAccessible> accessible;
|
|
|
|
accService->GetAccessibleFor(aNode, getter_AddRefs(accessible));
|
|
|
|
if (!accessible) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2007-04-02 08:56:24 -07:00
|
|
|
PRUint32 state = State(accessible);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (0 == (state & nsIAccessibleStates::STATE_SELECTABLE)) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 containerRole;
|
|
|
|
while (0 == (state & nsIAccessibleStates::STATE_MULTISELECTABLE)) {
|
|
|
|
nsIAccessible *current = accessible;
|
|
|
|
current->GetParent(getter_AddRefs(accessible));
|
|
|
|
if (!accessible || (NS_SUCCEEDED(accessible->GetFinalRole(&containerRole)) &&
|
|
|
|
containerRole == nsIAccessibleRole::ROLE_PANE)) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2007-04-02 08:56:24 -07:00
|
|
|
state = State(accessible);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
nsIAccessible *returnAccessible = nsnull;
|
|
|
|
accessible.swap(returnAccessible);
|
|
|
|
return returnAccessible;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void removeSelection (); */
|
|
|
|
NS_IMETHODIMP nsAccessible::SetSelected(PRBool aSelect)
|
|
|
|
{
|
|
|
|
// Add or remove selection
|
|
|
|
if (!mDOMNode) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-04-02 08:56:24 -07:00
|
|
|
PRUint32 state = State(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (state & nsIAccessibleStates::STATE_SELECTABLE) {
|
|
|
|
nsCOMPtr<nsIAccessible> multiSelect = GetMultiSelectFor(mDOMNode);
|
|
|
|
if (!multiSelect) {
|
|
|
|
return aSelect ? TakeFocus() : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
NS_ASSERTION(content, "Called for dead accessible");
|
|
|
|
|
2007-09-24 18:19:03 -07:00
|
|
|
if (mRoleMapEntry) {
|
2007-12-11 18:10:26 -08:00
|
|
|
if (aSelect) {
|
|
|
|
return content->SetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_selected,
|
|
|
|
NS_LITERAL_STRING("true"), PR_TRUE);
|
2007-09-24 18:19:03 -07:00
|
|
|
}
|
2007-12-11 18:10:26 -08:00
|
|
|
return content->UnsetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_selected, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void takeSelection (); */
|
|
|
|
NS_IMETHODIMP nsAccessible::TakeSelection()
|
|
|
|
{
|
|
|
|
// Select only this item
|
|
|
|
if (!mDOMNode) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-04-02 08:56:24 -07:00
|
|
|
PRUint32 state = State(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (state & nsIAccessibleStates::STATE_SELECTABLE) {
|
|
|
|
nsCOMPtr<nsIAccessible> multiSelect = GetMultiSelectFor(mDOMNode);
|
|
|
|
if (multiSelect) {
|
|
|
|
nsCOMPtr<nsIAccessibleSelectable> selectable = do_QueryInterface(multiSelect);
|
|
|
|
selectable->ClearSelection();
|
|
|
|
}
|
|
|
|
return SetSelected(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void takeFocus (); */
|
2008-04-22 23:04:53 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::TakeFocus()
|
|
|
|
{
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
NS_ENSURE_STATE(frame);
|
|
|
|
|
|
|
|
// If the current element can't take real DOM focus and if it has an ID and
|
|
|
|
// ancestor with a the aria-activedescendant attribute present, then set DOM
|
|
|
|
// focus to that ancestor and set aria-activedescendant on the ancestor to
|
|
|
|
// the ID of the desired element.
|
|
|
|
if (!frame->IsFocusable()) {
|
|
|
|
nsAutoString id;
|
|
|
|
if (content && nsAccUtils::GetID(content, id)) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> ancestorContent = content;
|
|
|
|
while ((ancestorContent = ancestorContent->GetParent()) &&
|
|
|
|
!ancestorContent->HasAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::aria_activedescendant));
|
|
|
|
|
|
|
|
if (ancestorContent) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
|
|
|
|
if (presShell) {
|
|
|
|
nsIFrame *frame = presShell->GetPrimaryFrameFor(ancestorContent);
|
|
|
|
if (frame && frame->IsFocusable()) {
|
|
|
|
|
|
|
|
content = ancestorContent;
|
|
|
|
content->SetAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::aria_activedescendant,
|
|
|
|
id, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNSHTMLElement> htmlElement(do_QueryInterface(content));
|
2007-05-07 12:02:57 -07:00
|
|
|
if (htmlElement) {
|
|
|
|
// HTML Elements also set the caret position
|
|
|
|
// in order to affect tabbing order
|
|
|
|
return htmlElement->Focus();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-04-22 23:04:53 -07:00
|
|
|
content->SetFocus(GetPresContext());
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsAccessible::AppendStringWithSpaces(nsAString *aFlatString, const nsAString& textEquivalent)
|
|
|
|
{
|
|
|
|
// Insert spaces to insure that words from controls aren't jammed together
|
|
|
|
if (!textEquivalent.IsEmpty()) {
|
|
|
|
if (!aFlatString->IsEmpty())
|
|
|
|
aFlatString->Append(PRUnichar(' '));
|
|
|
|
aFlatString->Append(textEquivalent);
|
|
|
|
aFlatString->Append(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsAccessible::AppendNameFromAccessibleFor(nsIContent *aContent,
|
|
|
|
nsAString *aFlatString,
|
|
|
|
PRBool aFromValue)
|
|
|
|
{
|
|
|
|
nsAutoString textEquivalent, value;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(aContent));
|
|
|
|
nsCOMPtr<nsIAccessible> accessible;
|
|
|
|
if (domNode == mDOMNode) {
|
|
|
|
accessible = this;
|
2007-08-05 20:50:11 -07:00
|
|
|
if (!aFromValue) {
|
|
|
|
// prevent recursive call GetName()
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService =
|
|
|
|
do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
NS_ENSURE_TRUE(accService, NS_ERROR_FAILURE);
|
|
|
|
accService->GetAccessibleInWeakShell(domNode, mWeakShell, getter_AddRefs(accessible));
|
|
|
|
}
|
|
|
|
if (accessible) {
|
|
|
|
if (aFromValue) {
|
|
|
|
accessible->GetValue(textEquivalent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
accessible->GetName(textEquivalent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
textEquivalent.CompressWhitespace();
|
|
|
|
return AppendStringWithSpaces(aFlatString, textEquivalent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AppendFlatStringFromContentNode and AppendFlatStringFromSubtree
|
|
|
|
*
|
|
|
|
* This method will glean useful text, in whatever form it exists, from any content node given to it.
|
|
|
|
* It is used by any decendant of nsAccessible that needs to get text from a single node, as
|
|
|
|
* well as by nsAccessible::AppendFlatStringFromSubtree, which gleans and concatenates text from any node and
|
|
|
|
* that node's decendants.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsresult nsAccessible::AppendFlatStringFromContentNode(nsIContent *aContent, nsAString *aFlatString)
|
|
|
|
{
|
|
|
|
if (aContent->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
// If it's a text node, append the text
|
|
|
|
PRBool isHTMLBlock = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIPresShell> shell = GetPresShell();
|
|
|
|
if (!shell) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *parentContent = aContent->GetParent();
|
|
|
|
nsCOMPtr<nsIContent> appendedSubtreeStart(do_QueryInterface(mDOMNode));
|
|
|
|
if (parentContent && parentContent != appendedSubtreeStart) {
|
|
|
|
nsIFrame *frame = shell->GetPrimaryFrameFor(parentContent);
|
|
|
|
if (frame) {
|
|
|
|
// If this text is inside a block level frame (as opposed to span level), we need to add spaces around that
|
|
|
|
// block's text, so we don't get words jammed together in final name
|
|
|
|
// Extra spaces will be trimmed out later
|
|
|
|
const nsStyleDisplay* display = frame->GetStyleDisplay();
|
2007-06-26 20:06:04 -07:00
|
|
|
if (display->IsBlockOutside() ||
|
2007-03-22 10:30:00 -07:00
|
|
|
display->mDisplay == NS_STYLE_DISPLAY_TABLE_CELL) {
|
|
|
|
isHTMLBlock = PR_TRUE;
|
|
|
|
if (!aFlatString->IsEmpty()) {
|
|
|
|
aFlatString->Append(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aContent->TextLength() > 0) {
|
2007-08-03 18:12:24 -07:00
|
|
|
nsIFrame *frame = shell->GetPrimaryFrameFor(aContent);
|
2007-11-15 07:44:04 -08:00
|
|
|
if (frame) {
|
|
|
|
nsresult rv = frame->GetRenderedText(aFlatString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
//if aContent is an object that is display: none, we have no a frame
|
|
|
|
aContent->AppendTextTo(*aFlatString);
|
|
|
|
}
|
2007-08-03 18:12:24 -07:00
|
|
|
if (isHTMLBlock && !aFlatString->IsEmpty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aFlatString->Append(PRUnichar(' '));
|
2007-08-03 18:12:24 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString textEquivalent;
|
|
|
|
if (!aContent->IsNodeOfType(nsINode::eHTML)) {
|
|
|
|
if (aContent->IsNodeOfType(nsINode::eXUL)) {
|
|
|
|
nsCOMPtr<nsIDOMXULLabeledControlElement> labeledEl(do_QueryInterface(aContent));
|
|
|
|
if (labeledEl) {
|
|
|
|
labeledEl->GetLabel(textEquivalent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (aContent->NodeInfo()->Equals(nsAccessibilityAtoms::label, kNameSpaceID_XUL)) {
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::value, textEquivalent);
|
|
|
|
}
|
|
|
|
if (textEquivalent.IsEmpty()) {
|
|
|
|
aContent->GetAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::tooltiptext, textEquivalent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AppendNameFromAccessibleFor(aContent, &textEquivalent, PR_TRUE /* use value */);
|
|
|
|
|
|
|
|
return AppendStringWithSpaces(aFlatString, textEquivalent);
|
|
|
|
}
|
|
|
|
return NS_OK; // Not HTML and not XUL -- we don't handle it yet
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> tag = aContent->Tag();
|
|
|
|
if (tag == nsAccessibilityAtoms::img) {
|
|
|
|
return AppendNameFromAccessibleFor(aContent, aFlatString);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tag == nsAccessibilityAtoms::input) {
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsAccessibilityAtoms::button, &nsAccessibilityAtoms::submit,
|
|
|
|
&nsAccessibilityAtoms::reset, &nsAccessibilityAtoms::image, nsnull};
|
|
|
|
if (aContent->FindAttrValueIn(kNameSpaceID_None, nsAccessibilityAtoms::type,
|
|
|
|
strings, eIgnoreCase) >= 0) {
|
|
|
|
return AppendNameFromAccessibleFor(aContent, aFlatString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tag == nsAccessibilityAtoms::object && !aContent->GetChildCount()) {
|
|
|
|
// If object has no alternative content children, try title
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::title, textEquivalent);
|
|
|
|
}
|
|
|
|
else if (tag == nsAccessibilityAtoms::br) {
|
|
|
|
// If it's a line break, insert a space so that words aren't jammed together
|
|
|
|
aFlatString->AppendLiteral("\r\n");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (tag != nsAccessibilityAtoms::a && tag != nsAccessibilityAtoms::area) {
|
|
|
|
AppendNameFromAccessibleFor(aContent, aFlatString, PR_TRUE /* use value */);
|
|
|
|
}
|
|
|
|
|
|
|
|
textEquivalent.CompressWhitespace();
|
|
|
|
return AppendStringWithSpaces(aFlatString, textEquivalent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult nsAccessible::AppendFlatStringFromSubtree(nsIContent *aContent, nsAString *aFlatString)
|
|
|
|
{
|
2007-10-25 13:22:50 -07:00
|
|
|
static PRBool isAlreadyHere; // Prevent recursion which can cause infinite loops
|
|
|
|
if (isAlreadyHere) {
|
2007-10-14 23:39:57 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-07-16 08:24:36 -07:00
|
|
|
|
2007-10-25 13:22:50 -07:00
|
|
|
isAlreadyHere = PR_TRUE;
|
2008-07-16 08:24:36 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell = GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsIFrame *frame = shell->GetPrimaryFrameFor(aContent);
|
|
|
|
PRBool isHidden = (!frame || !frame->GetStyleVisibility()->IsVisible());
|
|
|
|
nsresult rv = AppendFlatStringFromSubtreeRecurse(aContent, aFlatString,
|
|
|
|
isHidden);
|
|
|
|
|
2007-10-25 13:22:50 -07:00
|
|
|
isAlreadyHere = PR_FALSE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && !aFlatString->IsEmpty()) {
|
|
|
|
nsAString::const_iterator start, end;
|
|
|
|
aFlatString->BeginReading(start);
|
|
|
|
aFlatString->EndReading(end);
|
|
|
|
|
|
|
|
PRInt32 spacesToTruncate = 0;
|
|
|
|
while (-- end != start && *end == ' ')
|
|
|
|
++ spacesToTruncate;
|
|
|
|
|
|
|
|
if (spacesToTruncate > 0)
|
|
|
|
aFlatString->Truncate(aFlatString->Length() - spacesToTruncate);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-07-16 08:24:36 -07:00
|
|
|
nsresult
|
|
|
|
nsAccessible::AppendFlatStringFromSubtreeRecurse(nsIContent *aContent,
|
|
|
|
nsAString *aFlatString,
|
|
|
|
PRBool aIsRootHidden)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Depth first search for all text nodes that are decendants of content node.
|
|
|
|
// Append all the text into one flat string
|
|
|
|
PRUint32 numChildren = 0;
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlElement> selectControlEl(do_QueryInterface(aContent));
|
2008-09-04 21:48:42 -07:00
|
|
|
|
|
|
|
if (!selectControlEl && aContent->Tag() != nsAccessibilityAtoms::textarea) {
|
|
|
|
// Don't walk children of elements with options, just get label directly.
|
|
|
|
// Don't traverse the children of a textarea, we want the value, not the
|
|
|
|
// static text node.
|
2007-03-22 10:30:00 -07:00
|
|
|
numChildren = aContent->GetChildCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numChildren == 0) {
|
|
|
|
// There are no children or they are irrelvant: get the text from the current node
|
|
|
|
AppendFlatStringFromContentNode(aContent, aFlatString);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There are relevant children: use them to get the text.
|
2008-07-16 08:24:36 -07:00
|
|
|
nsCOMPtr<nsIPresShell> shell = GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 index;
|
|
|
|
for (index = 0; index < numChildren; index++) {
|
2008-07-16 08:24:36 -07:00
|
|
|
nsCOMPtr<nsIContent> childContent = aContent->GetChildAt(index);
|
|
|
|
|
|
|
|
// Walk into hidden subtree if the the root parent is also hidden. This
|
|
|
|
// happens when the author explictly uses a hidden label or description.
|
|
|
|
if (!aIsRootHidden) {
|
|
|
|
nsIFrame *childFrame = shell->GetPrimaryFrameFor(childContent);
|
|
|
|
if (!childFrame || !childFrame->GetStyleVisibility()->IsVisible())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
AppendFlatStringFromSubtreeRecurse(childContent, aFlatString,
|
|
|
|
aIsRootHidden);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-07-16 08:24:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *nsAccessible::GetLabelContent(nsIContent *aForNode)
|
|
|
|
{
|
|
|
|
if (aForNode->IsNodeOfType(nsINode::eXUL))
|
2007-12-11 18:10:26 -08:00
|
|
|
return nsAccUtils::FindNeighbourPointingToNode(aForNode, nsAccessibilityAtoms::control,
|
|
|
|
nsAccessibilityAtoms::label);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return GetHTMLLabelContent(aForNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* nsAccessible::GetHTMLLabelContent(nsIContent *aForNode)
|
|
|
|
{
|
|
|
|
// Get either <label for="[id]"> element which explictly points to aForNode, or
|
|
|
|
// <label> ancestor which implicitly point to it
|
|
|
|
nsIContent *walkUpContent = aForNode;
|
|
|
|
|
|
|
|
// go up tree get name of ancestor label if there is one. Don't go up farther than form element
|
|
|
|
while ((walkUpContent = walkUpContent->GetParent()) != nsnull) {
|
|
|
|
nsIAtom *tag = walkUpContent->Tag();
|
|
|
|
if (tag == nsAccessibilityAtoms::label) {
|
|
|
|
return walkUpContent; // An ancestor <label> implicitly points to us
|
|
|
|
}
|
|
|
|
if (tag == nsAccessibilityAtoms::form ||
|
|
|
|
tag == nsAccessibilityAtoms::body) {
|
|
|
|
// Reached top ancestor in form
|
|
|
|
// There can be a label targeted at this control using the
|
|
|
|
// for="control_id" attribute. To save computing time, only
|
|
|
|
// look for those inside of a form element
|
|
|
|
nsAutoString forId;
|
2007-09-18 14:36:41 -07:00
|
|
|
if (!nsAccUtils::GetID(aForNode, forId)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-09-18 14:36:41 -07:00
|
|
|
// Actually we'll be walking down the content this time, with a depth first search
|
2007-12-11 18:10:26 -08:00
|
|
|
return nsAccUtils::FindDescendantPointingToID(&forId, walkUpContent,
|
2007-09-24 18:19:03 -07:00
|
|
|
nsAccessibilityAtoms::_for);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2007-12-11 18:10:26 -08:00
|
|
|
nsresult nsAccessible::GetTextFromRelationID(nsIAtom *aIDProperty, nsString &aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Get DHTML name from content subtree pointed to by ID attribute
|
|
|
|
aName.Truncate();
|
2008-03-24 11:50:16 -07:00
|
|
|
NS_ASSERTION(mDOMNode, "Called from shutdown accessible");
|
2007-10-11 23:58:18 -07:00
|
|
|
nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode);
|
2008-03-24 11:50:16 -07:00
|
|
|
if (!content)
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString ids;
|
2007-12-11 18:10:26 -08:00
|
|
|
if (!content->GetAttr(kNameSpaceID_None, aIDProperty, ids)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
ids.CompressWhitespace(PR_TRUE, PR_TRUE);
|
|
|
|
|
2007-10-11 23:58:18 -07:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(content->GetOwnerDoc());
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
2007-12-11 18:10:26 -08:00
|
|
|
// Support idlist as in aria-labelledby="id1 id2 id3"
|
2007-03-22 10:30:00 -07:00
|
|
|
while (!ids.IsEmpty()) {
|
|
|
|
nsAutoString id;
|
|
|
|
PRInt32 idLength = ids.FindChar(' ');
|
|
|
|
NS_ASSERTION(idLength != 0, "Should not be 0 because of CompressWhitespace() call above");
|
|
|
|
if (idLength == kNotFound) {
|
|
|
|
id = ids;
|
|
|
|
ids.Truncate();
|
|
|
|
} else {
|
|
|
|
id = Substring(ids, 0, idLength);
|
|
|
|
ids.Cut(0, idLength + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aName.IsEmpty()) {
|
|
|
|
aName += ' '; // Need whitespace between multiple labels or descriptions
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMElement> labelElement;
|
|
|
|
domDoc->GetElementById(id, getter_AddRefs(labelElement));
|
|
|
|
content = do_QueryInterface(labelElement);
|
|
|
|
if (!content) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// We have a label content
|
|
|
|
rv = AppendFlatStringFromSubtree(content, &aName);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aName.CompressWhitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Only called if the element is not a nsIDOMXULControlElement. Initially walks up
|
|
|
|
* the DOM tree to the form, concatonating label elements as it goes. Then checks for
|
|
|
|
* labels with the for="controlID" property.
|
|
|
|
*/
|
|
|
|
nsresult nsAccessible::GetHTMLName(nsAString& aLabel, PRBool aCanAggregateSubtree)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
if (!content) {
|
|
|
|
return NS_ERROR_FAILURE; // Node shut down
|
|
|
|
}
|
|
|
|
|
2008-09-04 07:11:40 -07:00
|
|
|
// Check for aria-label property
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString label;
|
2008-09-04 07:11:40 -07:00
|
|
|
if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label, label)) {
|
|
|
|
aLabel = label;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for aria-labelledby relationship property
|
2007-12-11 18:10:26 -08:00
|
|
|
nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, label);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aLabel = label;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *labelContent = GetHTMLLabelContent(content);
|
|
|
|
if (labelContent) {
|
|
|
|
AppendFlatStringFromSubtree(labelContent, &label);
|
|
|
|
label.CompressWhitespace();
|
|
|
|
if (!label.IsEmpty()) {
|
|
|
|
aLabel = label;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCanAggregateSubtree) {
|
|
|
|
// Don't use AppendFlatStringFromSubtree for container widgets like menulist
|
|
|
|
nsresult rv = AppendFlatStringFromSubtree(content, &aLabel);
|
2007-05-29 07:45:38 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && !aLabel.IsEmpty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Still try the title as as fallback method in that case.
|
|
|
|
if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::title,
|
|
|
|
aLabel)) {
|
|
|
|
aLabel.SetIsVoid(PR_TRUE);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 3 main cases for XUL Controls to be labeled
|
|
|
|
* 1 - control contains label="foo"
|
|
|
|
* 2 - control has, as a child, a label element
|
|
|
|
* - label has either value="foo" or children
|
|
|
|
* 3 - non-child label contains control="controlID"
|
|
|
|
* - label has either value="foo" or children
|
|
|
|
* Once a label is found, the search is discontinued, so a control
|
|
|
|
* that has a label child as well as having a label external to
|
|
|
|
* the control that uses the control="controlID" syntax will use
|
|
|
|
* the child label for its Name.
|
|
|
|
*/
|
|
|
|
nsresult nsAccessible::GetXULName(nsAString& aLabel, PRBool aCanAggregateSubtree)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
NS_ASSERTION(content, "No nsIContent for DOM node");
|
|
|
|
|
2008-09-04 07:11:40 -07:00
|
|
|
// First check for label override via aria-label property
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString label;
|
2008-09-04 07:11:40 -07:00
|
|
|
if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label, label)) {
|
|
|
|
aLabel = label;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Second check for label override via aria-labelledby relationship
|
2007-12-11 18:10:26 -08:00
|
|
|
nsresult rv = GetTextFromRelationID(nsAccessibilityAtoms::aria_labelledby, label);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aLabel = label;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CASE #1 (via label attribute) -- great majority of the cases
|
|
|
|
nsCOMPtr<nsIDOMXULLabeledControlElement> labeledEl(do_QueryInterface(mDOMNode));
|
|
|
|
if (labeledEl) {
|
|
|
|
rv = labeledEl->GetLabel(label);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemEl(do_QueryInterface(mDOMNode));
|
|
|
|
if (itemEl) {
|
|
|
|
rv = itemEl->GetLabel(label);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlElement> select(do_QueryInterface(mDOMNode));
|
|
|
|
// Use label if this is not a select control element which
|
|
|
|
// uses label attribute to indicate which option is selected
|
|
|
|
if (!select) {
|
|
|
|
nsCOMPtr<nsIDOMXULElement> xulEl(do_QueryInterface(mDOMNode));
|
|
|
|
if (xulEl) {
|
|
|
|
rv = xulEl->GetAttribute(NS_LITERAL_STRING("label"), label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CASES #2 and #3 ------ label as a child or <label control="id" ... > </label>
|
|
|
|
if (NS_FAILED(rv) || label.IsEmpty()) {
|
|
|
|
label.Truncate();
|
|
|
|
nsIContent *labelContent =
|
2007-12-11 18:10:26 -08:00
|
|
|
nsAccUtils::FindNeighbourPointingToNode(content, nsAccessibilityAtoms::control,
|
|
|
|
nsAccessibilityAtoms::label);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULLabelElement> xulLabel(do_QueryInterface(labelContent));
|
|
|
|
// Check if label's value attribute is used
|
|
|
|
if (xulLabel && NS_SUCCEEDED(xulLabel->GetValue(label)) && label.IsEmpty()) {
|
|
|
|
// If no value attribute, a non-empty label must contain
|
|
|
|
// children that define it's text -- possibly using HTML
|
|
|
|
AppendFlatStringFromSubtree(labelContent, &label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX If CompressWhiteSpace worked on nsAString we could avoid a copy
|
|
|
|
label.CompressWhitespace();
|
|
|
|
if (!label.IsEmpty()) {
|
|
|
|
aLabel = label;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::tooltiptext, label);
|
|
|
|
label.CompressWhitespace();
|
|
|
|
if (!label.IsEmpty()) {
|
|
|
|
aLabel = label;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can get text from title of <toolbaritem> if we're a child of a <toolbaritem>
|
|
|
|
nsIContent *bindingParent = content->GetBindingParent();
|
|
|
|
nsIContent *parent = bindingParent? bindingParent->GetParent() :
|
|
|
|
content->GetParent();
|
|
|
|
while (parent) {
|
|
|
|
if (parent->Tag() == nsAccessibilityAtoms::toolbaritem &&
|
|
|
|
parent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::title, label)) {
|
|
|
|
label.CompressWhitespace();
|
|
|
|
aLabel = label;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't use AppendFlatStringFromSubtree for container widgets like menulist
|
|
|
|
return aCanAggregateSubtree? AppendFlatStringFromSubtree(content, &aLabel) : NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-24 11:20:52 -07:00
|
|
|
PRBool nsAccessible::IsNodeRelevant(nsIDOMNode *aNode)
|
|
|
|
{
|
|
|
|
// Can this node be accessible and attached to
|
|
|
|
// the document's accessible tree?
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService =
|
|
|
|
do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
NS_ENSURE_TRUE(accService, PR_FALSE);
|
|
|
|
nsCOMPtr<nsIDOMNode> relevantNode;
|
|
|
|
accService->GetRelevantContentNodeFor(aNode, getter_AddRefs(relevantNode));
|
|
|
|
return aNode == relevantNode;
|
|
|
|
}
|
|
|
|
|
2008-01-17 18:49:04 -08:00
|
|
|
NS_IMETHODIMP
|
2008-01-17 18:56:38 -08:00
|
|
|
nsAccessible::FireToolkitEvent(PRUint32 aEvent, nsIAccessible *aTarget)
|
2008-01-17 18:49:04 -08:00
|
|
|
{
|
|
|
|
// Don't fire event for accessible that has been shut down.
|
|
|
|
if (!mWeakShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessibleEvent> accEvent =
|
2008-01-17 18:56:38 -08:00
|
|
|
new nsAccEvent(aEvent, aTarget);
|
2008-01-17 18:49:04 -08:00
|
|
|
NS_ENSURE_TRUE(accEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
return FireAccessibleEvent(accEvent);
|
|
|
|
}
|
|
|
|
|
2007-04-12 23:03:30 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::FireAccessibleEvent(nsIAccessibleEvent *aEvent)
|
|
|
|
{
|
2007-04-24 11:20:52 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aEvent);
|
|
|
|
nsCOMPtr<nsIDOMNode> eventNode;
|
|
|
|
aEvent->GetDOMNode(getter_AddRefs(eventNode));
|
|
|
|
NS_ENSURE_TRUE(IsNodeRelevant(eventNode), NS_ERROR_FAILURE);
|
|
|
|
|
2007-04-12 23:03:30 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
|
|
|
do_GetService("@mozilla.org/observer-service;1");
|
|
|
|
NS_ENSURE_TRUE(obsService, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return obsService->NotifyObservers(aEvent, NS_ACCESSIBLE_EVENT_TOPIC, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::GetFinalRole(PRUint32 *aRole)
|
|
|
|
{
|
2007-08-20 20:26:48 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aRole);
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_NOTHING;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mRoleMapEntry) {
|
|
|
|
*aRole = mRoleMapEntry->role;
|
2007-08-03 18:54:07 -07:00
|
|
|
|
|
|
|
// These unfortunate exceptions don't fit into the ARIA table
|
|
|
|
// This is where the nsIAccessible role depends on both the role and ARIA state
|
2008-02-12 18:35:48 -08:00
|
|
|
if (*aRole == nsIAccessibleRole::ROLE_PUSHBUTTON) {
|
2007-08-03 18:54:07 -07:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
|
|
|
|
if (content) {
|
2007-12-11 18:10:26 -08:00
|
|
|
if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_pressed)) {
|
|
|
|
// For aria-pressed="false" or aria-pressed="true"
|
2007-08-03 18:54:07 -07:00
|
|
|
// For simplicity, any pressed attribute indicates it's a toggle button
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_TOGGLE_BUTTON;
|
|
|
|
}
|
2008-01-26 18:34:27 -08:00
|
|
|
else if (content->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::aria_haspopup,
|
2007-12-11 18:10:26 -08:00
|
|
|
nsAccessibilityAtoms::_true, eCaseMatters)) {
|
|
|
|
// For button with aria-haspopup="true"
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_BUTTONMENU;
|
2007-08-03 18:54:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 11:46:29 -08:00
|
|
|
else if (*aRole == nsIAccessibleRole::ROLE_LISTBOX) {
|
|
|
|
// A listbox inside of a combo box needs a special role because of ATK mapping to menu
|
2008-03-13 10:39:18 -07:00
|
|
|
nsCOMPtr<nsIAccessible> possibleCombo;
|
|
|
|
GetParent(getter_AddRefs(possibleCombo));
|
|
|
|
if (possibleCombo && Role(possibleCombo) == nsIAccessibleRole::ROLE_COMBOBOX) {
|
2007-11-15 11:46:29 -08:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_COMBOBOX_LIST;
|
|
|
|
}
|
2008-03-13 10:39:18 -07:00
|
|
|
else { // Check to see if combo owns the listbox instead
|
|
|
|
GetAccessibleRelated(nsIAccessibleRelation::RELATION_NODE_CHILD_OF, getter_AddRefs(possibleCombo));
|
|
|
|
if (possibleCombo && Role(possibleCombo) == nsIAccessibleRole::ROLE_COMBOBOX) {
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_COMBOBOX_LIST;
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 11:46:29 -08:00
|
|
|
}
|
|
|
|
else if (*aRole == nsIAccessibleRole::ROLE_OPTION) {
|
|
|
|
nsCOMPtr<nsIAccessible> parent;
|
|
|
|
GetParent(getter_AddRefs(parent));
|
|
|
|
if (parent && Role(parent) == nsIAccessibleRole::ROLE_COMBOBOX_LIST) {
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_COMBOBOX_OPTION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-06 20:14:59 -08:00
|
|
|
// gLandmarkRoleMap: can use role of accessible class impl
|
|
|
|
// gEmptyRoleMap and all others: cannot use role of accessible class impl
|
|
|
|
if (mRoleMapEntry != &nsARIAMap::gLandmarkRoleMap) {
|
|
|
|
// We can now expose ROLE_NOTHING when there is a role map entry, which
|
|
|
|
// will cause ATK to use ROLE_UNKNOWN and MSAA to use a BSTR role with
|
|
|
|
// the ARIA role or element's tag. In either case the AT can also use
|
|
|
|
// the object attributes tag and xml-roles to find out more.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return mDOMNode ? GetRole(aRole) : NS_ERROR_FAILURE; // Node already shut down
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:07:24 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetAttributes(nsIPersistentProperties **aAttributes)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-14 13:49:38 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aAttributes); // In/out param. Created if necessary.
|
|
|
|
|
2008-06-24 13:46:32 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-12-11 18:10:26 -08:00
|
|
|
nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode);
|
|
|
|
if (!content) {
|
2007-04-19 21:48:04 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-12-11 18:10:26 -08:00
|
|
|
}
|
2007-04-19 21:48:04 -07:00
|
|
|
|
2008-03-14 13:49:38 -07:00
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes = *aAttributes;
|
|
|
|
if (!attributes) {
|
|
|
|
// Create only if an array wasn't already passed in
|
|
|
|
attributes = do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(attributes, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
NS_ADDREF(*aAttributes = attributes);
|
|
|
|
}
|
2007-08-10 18:44:44 -07:00
|
|
|
|
2007-04-07 02:07:24 -07:00
|
|
|
nsresult rv = GetAttributesInternal(attributes);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-18 14:36:41 -07:00
|
|
|
nsAutoString id;
|
2007-10-11 14:35:01 -07:00
|
|
|
nsAutoString oldValueUnused;
|
2007-12-11 18:10:26 -08:00
|
|
|
if (nsAccUtils::GetID(content, id)) {
|
2008-03-14 13:49:38 -07:00
|
|
|
// Expose ID. If an <iframe id> exists override the one on the <body> of the source doc,
|
|
|
|
// because the specific instance is what makes the ID useful for scripts
|
2007-09-18 14:36:41 -07:00
|
|
|
attributes->SetStringProperty(NS_LITERAL_CSTRING("id"), id, oldValueUnused);
|
2007-10-11 14:35:01 -07:00
|
|
|
}
|
2008-03-13 10:39:18 -07:00
|
|
|
|
2007-12-11 18:10:26 -08:00
|
|
|
nsAutoString xmlRoles;
|
|
|
|
if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::role, xmlRoles)) {
|
|
|
|
attributes->SetStringProperty(NS_LITERAL_CSTRING("xml-roles"), xmlRoles, oldValueUnused);
|
2007-10-11 14:35:01 -07:00
|
|
|
}
|
|
|
|
|
2008-02-08 05:13:50 -08:00
|
|
|
nsCOMPtr<nsIAccessibleValue> supportsValue = do_QueryInterface(static_cast<nsIAccessible*>(this));
|
|
|
|
if (supportsValue) {
|
|
|
|
// We support values, so expose the string value as well, via the valuetext object attribute
|
|
|
|
// We test for the value interface because we don't want to expose traditional get_accValue()
|
|
|
|
// information such as URL's on links and documents, or text in an input
|
|
|
|
nsAutoString valuetext;
|
|
|
|
GetValue(valuetext);
|
|
|
|
attributes->SetStringProperty(NS_LITERAL_CSTRING("valuetext"), valuetext, oldValueUnused);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-13 10:39:18 -07:00
|
|
|
PRUint32 role = Role(this);
|
|
|
|
if (role == nsIAccessibleRole::ROLE_CHECKBUTTON ||
|
|
|
|
role == nsIAccessibleRole::ROLE_PUSHBUTTON ||
|
|
|
|
role == nsIAccessibleRole::ROLE_MENUITEM ||
|
|
|
|
role == nsIAccessibleRole::ROLE_LISTITEM ||
|
2008-04-15 01:50:15 -07:00
|
|
|
role == nsIAccessibleRole::ROLE_OPTION ||
|
|
|
|
role == nsIAccessibleRole::ROLE_RADIOBUTTON ||
|
|
|
|
role == nsIAccessibleRole::ROLE_RICH_OPTION ||
|
2008-03-13 10:39:18 -07:00
|
|
|
role == nsIAccessibleRole::ROLE_OUTLINEITEM ||
|
|
|
|
content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_checked)) {
|
|
|
|
// Might be checkable -- checking role & ARIA attribute first is faster than getting state
|
|
|
|
PRUint32 state = 0;
|
|
|
|
GetFinalState(&state, nsnull);
|
|
|
|
if (state & nsIAccessibleStates::STATE_CHECKABLE) {
|
|
|
|
// No official state for checkable, so use object attribute to expose that
|
|
|
|
attributes->SetStringProperty(NS_LITERAL_CSTRING("checkable"), NS_LITERAL_STRING("true"),
|
|
|
|
oldValueUnused);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Level/setsize/posinset
|
2007-07-05 04:29:28 -07:00
|
|
|
if (!nsAccUtils::HasAccGroupAttrs(attributes)) {
|
2007-04-07 02:07:24 -07:00
|
|
|
// The role of an accessible can be pointed by ARIA attribute but ARIA
|
|
|
|
// posinset, level, setsize may be skipped. Therefore we calculate here
|
|
|
|
// these properties to map them into description.
|
|
|
|
|
2007-04-10 06:35:17 -07:00
|
|
|
// If accessible is invisible we don't want to calculate group ARIA
|
|
|
|
// attributes for it.
|
2007-08-10 18:44:44 -07:00
|
|
|
if ((role == nsIAccessibleRole::ROLE_LISTITEM ||
|
2008-06-27 23:16:34 -07:00
|
|
|
role == nsIAccessibleRole::ROLE_MENUITEM ||
|
|
|
|
role == nsIAccessibleRole::ROLE_CHECK_MENU_ITEM ||
|
|
|
|
role == nsIAccessibleRole::ROLE_RADIO_MENU_ITEM ||
|
|
|
|
role == nsIAccessibleRole::ROLE_RADIOBUTTON ||
|
|
|
|
role == nsIAccessibleRole::ROLE_PAGETAB ||
|
|
|
|
role == nsIAccessibleRole::ROLE_OPTION ||
|
|
|
|
role == nsIAccessibleRole::ROLE_RADIOBUTTON ||
|
|
|
|
role == nsIAccessibleRole::ROLE_OUTLINEITEM) &&
|
2007-08-10 18:44:44 -07:00
|
|
|
0 == (State(this) & nsIAccessibleStates::STATE_INVISIBLE)) {
|
2008-06-27 23:16:34 -07:00
|
|
|
|
|
|
|
PRUint32 baseRole = role;
|
|
|
|
if (role == nsIAccessibleRole::ROLE_CHECK_MENU_ITEM ||
|
|
|
|
role == nsIAccessibleRole::ROLE_RADIO_MENU_ITEM)
|
|
|
|
baseRole = nsIAccessibleRole::ROLE_MENUITEM;
|
|
|
|
|
2007-04-07 02:07:24 -07:00
|
|
|
nsCOMPtr<nsIAccessible> parent = GetParent();
|
|
|
|
NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
PRInt32 positionInGroup = 0;
|
|
|
|
PRInt32 setSize = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> sibling, nextSibling;
|
|
|
|
parent->GetFirstChild(getter_AddRefs(sibling));
|
|
|
|
NS_ENSURE_TRUE(sibling, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
PRBool foundCurrent = PR_FALSE;
|
2008-06-27 23:16:34 -07:00
|
|
|
PRUint32 siblingRole, siblingBaseRole;
|
2007-04-07 02:07:24 -07:00
|
|
|
while (sibling) {
|
|
|
|
sibling->GetFinalRole(&siblingRole);
|
2008-06-27 23:16:34 -07:00
|
|
|
|
|
|
|
siblingBaseRole = siblingRole;
|
|
|
|
if (siblingRole == nsIAccessibleRole::ROLE_CHECK_MENU_ITEM ||
|
|
|
|
siblingRole == nsIAccessibleRole::ROLE_RADIO_MENU_ITEM)
|
|
|
|
siblingBaseRole = nsIAccessibleRole::ROLE_MENUITEM;
|
|
|
|
|
|
|
|
// If sibling is visible and has the same base role.
|
|
|
|
if (siblingBaseRole == baseRole &&
|
2007-04-10 06:35:17 -07:00
|
|
|
!(State(sibling) & nsIAccessibleStates::STATE_INVISIBLE)) {
|
2007-04-07 02:07:24 -07:00
|
|
|
++ setSize;
|
|
|
|
if (!foundCurrent) {
|
|
|
|
++ positionInGroup;
|
|
|
|
if (sibling == this)
|
|
|
|
foundCurrent = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-06-27 23:16:34 -07:00
|
|
|
|
|
|
|
// If the sibling is separator
|
|
|
|
if (siblingRole == nsIAccessibleRole::ROLE_SEPARATOR) {
|
|
|
|
if (foundCurrent) // the our group is ended
|
|
|
|
break;
|
|
|
|
|
|
|
|
// not our group, continue the searching
|
|
|
|
positionInGroup = 0;
|
|
|
|
setSize = 0;
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:07:24 -07:00
|
|
|
sibling->GetNextSibling(getter_AddRefs(nextSibling));
|
|
|
|
sibling = nextSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 groupLevel = 0;
|
|
|
|
if (role == nsIAccessibleRole::ROLE_OUTLINEITEM) {
|
|
|
|
groupLevel = 1;
|
|
|
|
nsCOMPtr<nsIAccessible> nextParent;
|
|
|
|
while (parent) {
|
|
|
|
parent->GetFinalRole(&role);
|
|
|
|
|
|
|
|
if (role == nsIAccessibleRole::ROLE_OUTLINE)
|
|
|
|
break;
|
2007-08-10 12:33:55 -07:00
|
|
|
if (role == nsIAccessibleRole::ROLE_GROUPING)
|
2007-04-07 02:07:24 -07:00
|
|
|
++ groupLevel;
|
|
|
|
|
|
|
|
parent->GetParent(getter_AddRefs(nextParent));
|
|
|
|
parent.swap(nextParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-05 04:29:28 -07:00
|
|
|
nsAccUtils::SetAccGroupAttrs(attributes, groupLevel, positionInGroup,
|
|
|
|
setSize);
|
2007-04-07 02:07:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-13 10:39:18 -07:00
|
|
|
// Expose all ARIA attributes
|
|
|
|
PRUint32 numAttrs = content->GetAttrCount();
|
|
|
|
for (PRUint32 count = 0; count < numAttrs; count ++) {
|
|
|
|
const nsAttrName *attr = content->GetAttrNameAt(count);
|
|
|
|
if (attr && attr->NamespaceEquals(kNameSpaceID_None)) {
|
|
|
|
nsIAtom *attrAtom = attr->Atom();
|
|
|
|
const char *attrStr;
|
|
|
|
attrAtom->GetUTF8String(&attrStr);
|
|
|
|
if (PL_strncmp(attrStr, "aria-", 5))
|
|
|
|
continue; // Not ARIA
|
|
|
|
if (!nsAccUtils::IsARIAPropForObjectAttr(attrAtom))
|
|
|
|
continue; // No need to expose obj attribute -- will be exposed some other way
|
|
|
|
nsAutoString value;
|
|
|
|
if (content->GetAttr(kNameSpaceID_None, attrAtom, value)) {
|
|
|
|
attributes->SetStringProperty(nsDependentCString(attrStr + 5), value, oldValueUnused);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:07:24 -07:00
|
|
|
nsresult
|
|
|
|
nsAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
|
|
|
|
{
|
2008-03-14 13:49:38 -07:00
|
|
|
// Attributes set by this method will not be used to override attributes on a sub-document accessible
|
|
|
|
// when there is a <frame>/<iframe> element that spawned the sub-document
|
|
|
|
nsIContent *content = GetRoleContent(mDOMNode);
|
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(content));
|
2007-04-07 02:07:24 -07:00
|
|
|
NS_ENSURE_TRUE(element, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
nsAutoString tagName;
|
|
|
|
element->GetTagName(tagName);
|
|
|
|
if (!tagName.IsEmpty()) {
|
|
|
|
nsAutoString oldValueUnused;
|
|
|
|
aAttributes->SetStringProperty(NS_LITERAL_CSTRING("tag"), tagName,
|
|
|
|
oldValueUnused);
|
|
|
|
}
|
|
|
|
|
2008-03-14 13:49:38 -07:00
|
|
|
nsAccEvent::GetLastEventAttributes(mDOMNode, aAttributes);
|
|
|
|
|
|
|
|
// Expose class because it may have useful microformat information
|
|
|
|
// Let the class from an iframe's document be exposed, don't override from <iframe class>
|
|
|
|
nsAutoString _class;
|
|
|
|
if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::_class, _class))
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::_class, _class);
|
|
|
|
|
|
|
|
// Get container-foo computed live region properties based on the closest container with
|
|
|
|
// the live region attribute.
|
|
|
|
// Inner nodes override outer nodes within the same document --
|
|
|
|
// The inner nodes can be used to override live region behavior on more general outer nodes
|
|
|
|
// However, nodes in outer documents override nodes in inner documents:
|
|
|
|
// Outer doc author may want to override properties on a widget they used in an iframe
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode = mDOMNode;
|
|
|
|
nsIContent *startContent = content;
|
|
|
|
while (PR_TRUE) {
|
|
|
|
NS_ENSURE_STATE(startContent);
|
|
|
|
nsIDocument *doc = startContent->GetDocument();
|
|
|
|
nsCOMPtr<nsIDOMNode> docNode = do_QueryInterface(doc);
|
|
|
|
NS_ENSURE_STATE(docNode);
|
|
|
|
nsIContent *topContent = GetRoleContent(docNode);
|
|
|
|
NS_ENSURE_STATE(topContent);
|
|
|
|
nsAccUtils::GetLiveContainerAttributes(aAttributes, startContent, topContent);
|
|
|
|
// Allow ARIA live region markup from outer documents to override
|
|
|
|
nsCOMPtr<nsISupports> container = doc->GetContainer();
|
|
|
|
nsIDocShellTreeItem *docShellTreeItem = nsnull;
|
|
|
|
if (container)
|
|
|
|
CallQueryInterface(container, &docShellTreeItem);
|
2008-03-19 18:55:26 -07:00
|
|
|
if (!docShellTreeItem)
|
|
|
|
break;
|
2008-03-14 13:49:38 -07:00
|
|
|
nsIDocShellTreeItem *sameTypeParent = nsnull;
|
|
|
|
docShellTreeItem->GetSameTypeParent(&sameTypeParent);
|
|
|
|
if (!sameTypeParent || sameTypeParent == docShellTreeItem)
|
|
|
|
break;
|
|
|
|
nsIDocument *parentDoc = doc->GetParentDocument();
|
2008-03-20 19:34:29 -07:00
|
|
|
if (!parentDoc)
|
|
|
|
break;
|
2008-03-14 13:49:38 -07:00
|
|
|
startContent = parentDoc->FindContentForSubDocument(doc);
|
|
|
|
}
|
|
|
|
|
2008-07-02 21:12:45 -07:00
|
|
|
// Expose 'display' attribute.
|
|
|
|
nsAutoString displayValue;
|
|
|
|
nsresult rv = GetComputedStyleValue(EmptyString(),
|
|
|
|
NS_LITERAL_STRING("display"),
|
|
|
|
displayValue);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::display,
|
|
|
|
displayValue);
|
2007-04-07 02:07:24 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-27 05:17:11 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GroupPosition(PRInt32 *aGroupLevel,
|
|
|
|
PRInt32 *aSimilarItemsInGroup,
|
|
|
|
PRInt32 *aPositionInGroup)
|
|
|
|
{
|
|
|
|
// Every element exposes level/posinset/sizeset for IAccessdible::attributes
|
|
|
|
// if they make sense for it. These attributes are mapped into groupPosition.
|
|
|
|
// If 'level' attribute doesn't make sense element then it isn't represented
|
|
|
|
// via IAccessible::attributes and groupLevel of groupPosition method is 0.
|
|
|
|
// Elements that expose 'level' attribute only (like html headings elements)
|
2007-09-18 21:05:05 -07:00
|
|
|
// don't support this method and all arguments are equalled 0.
|
2007-03-27 05:17:11 -07:00
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aGroupLevel);
|
|
|
|
NS_ENSURE_ARG_POINTER(aSimilarItemsInGroup);
|
|
|
|
NS_ENSURE_ARG_POINTER(aPositionInGroup);
|
|
|
|
|
|
|
|
*aGroupLevel = 0;
|
|
|
|
*aSimilarItemsInGroup = 0;
|
|
|
|
*aPositionInGroup = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes;
|
|
|
|
nsresult rv = GetAttributes(getter_AddRefs(attributes));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-04-24 08:42:33 -07:00
|
|
|
if (!attributes) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-03-27 05:17:11 -07:00
|
|
|
PRInt32 level, posInSet, setSize;
|
2007-07-05 04:29:28 -07:00
|
|
|
nsAccUtils::GetAccGroupAttrs(attributes, &level, &posInSet, &setSize);
|
2007-03-27 05:17:11 -07:00
|
|
|
|
|
|
|
if (!posInSet && !setSize)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
*aGroupLevel = level;
|
|
|
|
|
2007-04-16 22:13:24 -07:00
|
|
|
*aPositionInGroup = posInSet;
|
2007-11-12 19:03:29 -08:00
|
|
|
*aSimilarItemsInGroup = setSize;
|
2007-03-27 05:17:11 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool nsAccessible::MappedAttrState(nsIContent *aContent, PRUint32 *aStateInOut,
|
|
|
|
nsStateMapEntry *aStateMapEntry)
|
|
|
|
{
|
|
|
|
// Return true if we should continue
|
2007-12-11 18:10:26 -08:00
|
|
|
if (!aStateMapEntry->attributeName) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE; // Stop looking -- no more states
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString attribValue;
|
2007-12-11 18:10:26 -08:00
|
|
|
if (aContent->GetAttr(kNameSpaceID_None, *aStateMapEntry->attributeName, attribValue)) {
|
2007-06-05 08:41:07 -07:00
|
|
|
if (aStateMapEntry->attributeValue == kBoolState) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// No attribute value map specified in state map entry indicates state cleared
|
|
|
|
if (attribValue.EqualsLiteral("false")) {
|
2007-09-05 21:20:26 -07:00
|
|
|
*aStateInOut &= ~aStateMapEntry->state;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aStateInOut |= aStateMapEntry->state;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-09-05 21:20:26 -07:00
|
|
|
else if (NS_ConvertUTF16toUTF8(attribValue).Equals(aStateMapEntry->attributeValue)) {
|
|
|
|
*aStateInOut |= aStateMapEntry->state;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-04-02 08:56:24 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetFinalState(PRUint32 *aState, PRUint32 *aExtraState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-04-02 08:56:24 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aState);
|
|
|
|
|
|
|
|
nsresult rv = GetState(aState, aExtraState);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-08-08 06:46:38 -07:00
|
|
|
// Apply ARIA states to be sure accessible states will be overriden.
|
2008-03-14 13:49:38 -07:00
|
|
|
GetARIAState(aState);
|
2007-08-08 06:46:38 -07:00
|
|
|
|
2007-10-03 02:31:41 -07:00
|
|
|
if (mRoleMapEntry && mRoleMapEntry->role == nsIAccessibleRole::ROLE_PAGETAB) {
|
|
|
|
if (*aState & nsIAccessibleStates::STATE_FOCUSED) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_SELECTED;
|
|
|
|
} else {
|
|
|
|
// Expose 'selected' state on ARIA tab if the focus is on internal element
|
|
|
|
// of related tabpanel.
|
|
|
|
nsCOMPtr<nsIAccessible> tabPanel;
|
|
|
|
rv = GetAccessibleRelated(nsIAccessibleRelation::RELATION_LABEL_FOR,
|
|
|
|
getter_AddRefs(tabPanel));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (tabPanel && Role(tabPanel) == nsIAccessibleRole::ROLE_PROPERTYPAGE) {
|
|
|
|
nsCOMPtr<nsIAccessNode> tabPanelAccessNode(do_QueryInterface(tabPanel));
|
|
|
|
nsCOMPtr<nsIDOMNode> tabPanelNode;
|
|
|
|
tabPanelAccessNode->GetDOMNode(getter_AddRefs(tabPanelNode));
|
|
|
|
NS_ENSURE_STATE(tabPanelNode);
|
|
|
|
|
|
|
|
if (nsAccUtils::IsAncestorOf(tabPanelNode, gLastFocusedNode))
|
|
|
|
*aState |= nsIAccessibleStates::STATE_SELECTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-13 20:02:39 -07:00
|
|
|
// Set additional states which presence depends on another states.
|
2007-09-20 19:58:29 -07:00
|
|
|
if (!aExtraState)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (!(*aState & nsIAccessibleStates::STATE_UNAVAILABLE)) {
|
|
|
|
*aExtraState |= nsIAccessibleStates::EXT_STATE_ENABLED |
|
|
|
|
nsIAccessibleStates::EXT_STATE_SENSITIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PRUint32 kExpandCollapseStates =
|
|
|
|
nsIAccessibleStates::STATE_COLLAPSED | nsIAccessibleStates::STATE_EXPANDED;
|
|
|
|
if (*aState & kExpandCollapseStates) {
|
|
|
|
*aExtraState |= nsIAccessibleStates::EXT_STATE_EXPANDABLE;
|
|
|
|
if ((*aState & kExpandCollapseStates) == kExpandCollapseStates) {
|
|
|
|
// Cannot be both expanded and collapsed -- this happens
|
|
|
|
// in ARIA expanded combobox because of limitation of nsARIAMap
|
|
|
|
// XXX Perhaps we will be able to make this less hacky if
|
|
|
|
// we support extended states in nsARIAMap, e.g. derive
|
|
|
|
// COLLAPSED from EXPANDABLE && !EXPANDED
|
|
|
|
*aExtraState &= ~nsIAccessibleStates::STATE_COLLAPSED;
|
2007-07-13 20:02:39 -07:00
|
|
|
}
|
2007-09-20 19:58:29 -07:00
|
|
|
}
|
2007-08-29 06:36:07 -07:00
|
|
|
|
2007-12-10 19:30:02 -08:00
|
|
|
if (mRoleMapEntry) {
|
|
|
|
// If an object has an ancestor with the activedescendant property
|
|
|
|
// pointing at it, we mark it as ACTIVE even if it's not currently focused.
|
|
|
|
// This allows screen reader virtual buffer modes to know which descendant
|
|
|
|
// is the current one that would get focus if the user navigates to the container widget.
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(mDOMNode);
|
|
|
|
nsAutoString id;
|
|
|
|
if (content && nsAccUtils::GetID(content, id)) {
|
|
|
|
nsIContent *ancestorContent = content;
|
|
|
|
nsAutoString activeID;
|
|
|
|
while ((ancestorContent = ancestorContent->GetParent()) != nsnull) {
|
|
|
|
if (ancestorContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_activedescendant, activeID)) {
|
|
|
|
if (id == activeID) {
|
|
|
|
*aExtraState |= nsIAccessibleStates::EXT_STATE_ACTIVE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-20 19:58:29 -07:00
|
|
|
PRUint32 role;
|
|
|
|
rv = GetFinalRole(&role);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (role == nsIAccessibleRole::ROLE_ENTRY ||
|
|
|
|
role == nsIAccessibleRole::ROLE_COMBOBOX) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
NS_ENSURE_STATE(content);
|
|
|
|
|
|
|
|
nsAutoString autocomplete;
|
2007-12-11 18:10:26 -08:00
|
|
|
if (content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_autocomplete, autocomplete) &&
|
2007-09-20 19:58:29 -07:00
|
|
|
(autocomplete.EqualsIgnoreCase("inline") ||
|
|
|
|
autocomplete.EqualsIgnoreCase("list") ||
|
|
|
|
autocomplete.EqualsIgnoreCase("both"))) {
|
|
|
|
*aExtraState |= nsIAccessibleStates::EXT_STATE_SUPPORTS_AUTOCOMPLETION;
|
2007-08-29 06:36:07 -07:00
|
|
|
}
|
|
|
|
|
2007-09-20 19:58:29 -07:00
|
|
|
// XXX We can remove this hack once we support RDF-based role & state maps
|
|
|
|
if (mRoleMapEntry && mRoleMapEntry->role == nsIAccessibleRole::ROLE_ENTRY) {
|
2007-12-11 18:10:26 -08:00
|
|
|
PRBool isMultiLine = content->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::aria_multiline,
|
|
|
|
nsAccessibilityAtoms::_true, eCaseMatters);
|
|
|
|
*aExtraState |= isMultiLine ? nsIAccessibleStates::EXT_STATE_MULTI_LINE : nsIAccessibleStates::EXT_STATE_SINGLE_LINE;
|
2008-03-13 10:39:18 -07:00
|
|
|
if (0 == (*aState & nsIAccessibleStates::STATE_READONLY))
|
|
|
|
*aExtraState |= nsIAccessibleStates::EXT_STATE_EDITABLE; // Not readonly
|
|
|
|
else // We're readonly: make sure editable state wasn't set by impl class
|
|
|
|
*aExtraState &= ~nsIAccessibleStates::EXT_STATE_EDITABLE;
|
2007-08-29 06:36:07 -07:00
|
|
|
}
|
2007-07-13 20:02:39 -07:00
|
|
|
}
|
|
|
|
|
2007-09-20 19:58:29 -07:00
|
|
|
// For some reasons DOM node may have not a frame. We tract such accessibles
|
|
|
|
// as invisible.
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (!frame)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
const nsStyleDisplay* display = frame->GetStyleDisplay();
|
|
|
|
if (display && display->mOpacity == 1.0f &&
|
|
|
|
!(*aState & nsIAccessibleStates::STATE_INVISIBLE)) {
|
|
|
|
*aExtraState |= nsIAccessibleStates::EXT_STATE_OPAQUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsStyleXUL *xulStyle = frame->GetStyleXUL();
|
|
|
|
if (xulStyle) {
|
|
|
|
// In XUL all boxes are either vertical or horizontal
|
|
|
|
if (xulStyle->mBoxOrient == NS_STYLE_BOX_ORIENT_VERTICAL) {
|
|
|
|
*aExtraState |= nsIAccessibleStates::EXT_STATE_VERTICAL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aExtraState |= nsIAccessibleStates::EXT_STATE_HORIZONTAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-08 06:46:38 -07:00
|
|
|
return NS_OK;
|
2007-04-02 08:56:24 -07:00
|
|
|
}
|
|
|
|
|
2008-03-14 13:49:38 -07:00
|
|
|
nsresult
|
|
|
|
nsAccessible::GetARIAState(PRUint32 *aState)
|
2007-04-02 08:56:24 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
// Test for universal states first
|
|
|
|
nsIContent *content = GetRoleContent(mDOMNode);
|
2007-08-29 18:15:16 -07:00
|
|
|
if (!content) {
|
2008-03-14 13:49:38 -07:00
|
|
|
return NS_OK;
|
2007-08-29 18:15:16 -07:00
|
|
|
}
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2007-06-05 08:41:07 -07:00
|
|
|
PRUint32 index = 0;
|
2008-03-14 13:49:38 -07:00
|
|
|
while (MappedAttrState(content, aState, &nsARIAMap::gWAIUnivStateMap[index])) {
|
2007-06-05 08:41:07 -07:00
|
|
|
++ index;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-06-15 22:45:58 -07:00
|
|
|
if (mRoleMapEntry) {
|
|
|
|
// Once DHTML role is used, we're only readonly if DHTML readonly used
|
|
|
|
*aState &= ~nsIAccessibleStates::STATE_READONLY;
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2008-06-15 22:45:58 -07:00
|
|
|
if (content->HasAttr(kNameSpaceID_None, content->GetIDAttributeName())) {
|
|
|
|
// If has a role & ID and aria-activedescendant on the container, assume focusable
|
|
|
|
nsIContent *ancestorContent = content;
|
|
|
|
while ((ancestorContent = ancestorContent->GetParent()) != nsnull) {
|
|
|
|
if (ancestorContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_activedescendant)) {
|
|
|
|
// ancestor has activedescendant property, this content could be active
|
|
|
|
*aState |= nsIAccessibleStates::STATE_FOCUSABLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-15 22:45:58 -07:00
|
|
|
if (*aState & nsIAccessibleStates::STATE_FOCUSABLE) {
|
|
|
|
// Special case: aria-disabled propagates from ancestors down to any focusable descendant
|
2008-03-29 15:04:04 -07:00
|
|
|
nsIContent *ancestorContent = content;
|
|
|
|
while ((ancestorContent = ancestorContent->GetParent()) != nsnull) {
|
2008-06-15 22:45:58 -07:00
|
|
|
if (ancestorContent->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::aria_disabled,
|
|
|
|
nsAccessibilityAtoms::_true, eCaseMatters)) {
|
|
|
|
// ancestor has aria-disabled property, this is disabled
|
|
|
|
*aState |= nsIAccessibleStates::STATE_UNAVAILABLE;
|
2008-03-29 15:04:04 -07:00
|
|
|
break;
|
|
|
|
}
|
2008-06-15 22:45:58 -07:00
|
|
|
}
|
2008-03-29 15:04:04 -07:00
|
|
|
}
|
|
|
|
|
2008-06-15 22:45:58 -07:00
|
|
|
if (!mRoleMapEntry)
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-03-29 14:52:14 -07:00
|
|
|
*aState |= mRoleMapEntry->state;
|
2008-03-14 13:49:38 -07:00
|
|
|
if (MappedAttrState(content, aState, &mRoleMapEntry->attributeMap1) &&
|
|
|
|
MappedAttrState(content, aState, &mRoleMapEntry->attributeMap2) &&
|
|
|
|
MappedAttrState(content, aState, &mRoleMapEntry->attributeMap3) &&
|
|
|
|
MappedAttrState(content, aState, &mRoleMapEntry->attributeMap4) &&
|
|
|
|
MappedAttrState(content, aState, &mRoleMapEntry->attributeMap5) &&
|
|
|
|
MappedAttrState(content, aState, &mRoleMapEntry->attributeMap6) &&
|
|
|
|
MappedAttrState(content, aState, &mRoleMapEntry->attributeMap7)) {
|
|
|
|
MappedAttrState(content, aState, &mRoleMapEntry->attributeMap8);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-14 13:49:38 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Not implemented by this class
|
|
|
|
|
|
|
|
/* DOMString getValue (); */
|
2008-03-30 23:21:35 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetValue(nsAString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-30 23:21:35 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
2008-03-31 19:50:00 -07:00
|
|
|
if (!content)
|
|
|
|
return NS_OK;
|
2008-03-30 23:21:35 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mRoleMapEntry) {
|
|
|
|
if (mRoleMapEntry->valueRule == eNoValue) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-03-30 23:21:35 -07:00
|
|
|
|
2008-02-08 05:13:50 -08:00
|
|
|
// aria-valuenow is a number, and aria-valuetext is the optional text equivalent
|
|
|
|
// For the string value, we will try the optional text equivalent first
|
|
|
|
if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_valuetext, aValue)) {
|
|
|
|
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_valuenow, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2008-03-30 23:21:35 -07:00
|
|
|
|
|
|
|
if (!aValue.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Check if it's an simple xlink.
|
|
|
|
if (nsAccUtils::IsXLink(content)) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
|
|
|
|
if (presShell)
|
|
|
|
return presShell->GetLinkLocation(mDOMNode, aValue);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
// nsIAccessibleValue
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetMaximumValue(double *aMaximumValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-11 18:10:26 -08:00
|
|
|
return GetAttrValue(nsAccessibilityAtoms::aria_valuemax, aMaximumValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetMinimumValue(double *aMinimumValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-11 18:10:26 -08:00
|
|
|
return GetAttrValue(nsAccessibilityAtoms::aria_valuemin, aMinimumValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetMinimumIncrement(double *aMinIncrement)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-03 22:27:27 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aMinIncrement);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aMinIncrement = 0;
|
2007-08-03 22:27:27 -07:00
|
|
|
|
|
|
|
// No mimimum increment in dynamic content spec right now
|
|
|
|
return NS_OK_NO_ARIA_VALUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetCurrentValue(double *aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-11 18:10:26 -08:00
|
|
|
return GetAttrValue(nsAccessibilityAtoms::aria_valuenow, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::SetCurrentValue(double aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-03 22:27:27 -07:00
|
|
|
if (!mDOMNode)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE; // Node already shut down
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
if (!mRoleMapEntry || mRoleMapEntry->valueRule == eNoValue)
|
|
|
|
return NS_OK_NO_ARIA_VALUE;
|
|
|
|
|
|
|
|
const PRUint32 kValueCannotChange = nsIAccessibleStates::STATE_READONLY |
|
|
|
|
nsIAccessibleStates::STATE_UNAVAILABLE;
|
|
|
|
|
|
|
|
if (State(this) & kValueCannotChange)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
double minValue = 0;
|
|
|
|
if (NS_SUCCEEDED(GetMinimumValue(&minValue)) && aValue < minValue)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
double maxValue = 0;
|
|
|
|
if (NS_SUCCEEDED(GetMaximumValue(&maxValue)) && aValue > maxValue)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
NS_ENSURE_STATE(content);
|
|
|
|
|
|
|
|
nsAutoString newValue;
|
|
|
|
newValue.AppendFloat(aValue);
|
2007-12-11 18:10:26 -08:00
|
|
|
return content->SetAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::aria_valuenow, newValue, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setName (in DOMString name); */
|
|
|
|
NS_IMETHODIMP nsAccessible::SetName(const nsAString& name)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetDefaultKeyBinding(nsAString& aKeyBinding)
|
|
|
|
{
|
|
|
|
aKeyBinding.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetKeyBindings(PRUint8 aActionIndex,
|
|
|
|
nsIDOMDOMStringList **aKeyBindings)
|
|
|
|
{
|
|
|
|
// Currently we support only unique key binding on element for default action.
|
|
|
|
NS_ENSURE_TRUE(aActionIndex == 0, NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
nsAccessibleDOMStringList *keyBindings = new nsAccessibleDOMStringList();
|
|
|
|
NS_ENSURE_TRUE(keyBindings, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsAutoString defaultKey;
|
|
|
|
nsresult rv = GetDefaultKeyBinding(defaultKey);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!defaultKey.IsEmpty())
|
|
|
|
keyBindings->Add(defaultKey);
|
|
|
|
|
|
|
|
NS_ADDREF(*aKeyBindings = keyBindings);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unsigned long getRole (); */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetRole(PRUint32 *aRole)
|
|
|
|
{
|
2007-08-20 20:26:48 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aRole);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_NOTHING;
|
2008-03-30 23:21:35 -07:00
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
if (nsAccUtils::IsXLink(content))
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_LINK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PRUint8 getAccNumActions (); */
|
2008-03-15 18:23:41 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetNumActions(PRUint8 *aNumActions)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-15 18:23:41 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aNumActions);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aNumActions = 0;
|
2008-03-15 18:23:41 -07:00
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2008-06-11 01:27:25 -07:00
|
|
|
nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode);
|
|
|
|
if (!content)
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-03-30 23:21:35 -07:00
|
|
|
// Check if it's an simple xlink.
|
|
|
|
if (nsAccUtils::IsXLink(content)) {
|
|
|
|
*aNumActions = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has registered 'click' event handler.
|
2008-03-15 18:23:41 -07:00
|
|
|
PRBool isOnclick = nsAccUtils::HasListener(content,
|
|
|
|
NS_LITERAL_STRING("click"));
|
|
|
|
|
|
|
|
if (isOnclick)
|
|
|
|
*aNumActions = 1;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DOMString getAccActionName (in PRUint8 index); */
|
2008-03-15 18:23:41 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-15 18:23:41 -07:00
|
|
|
aName.Truncate();
|
|
|
|
|
|
|
|
if (aIndex != 0)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2008-03-30 23:21:35 -07:00
|
|
|
// Check if it's simple xlink.
|
2008-03-15 18:23:41 -07:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
2008-03-30 23:21:35 -07:00
|
|
|
if (nsAccUtils::IsXLink(content)) {
|
|
|
|
aName.AssignLiteral("jump");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has registered 'click' event handler.
|
2008-03-15 18:23:41 -07:00
|
|
|
PRBool isOnclick = nsAccUtils::HasListener(content,
|
|
|
|
NS_LITERAL_STRING("click"));
|
|
|
|
|
|
|
|
if (isOnclick) {
|
|
|
|
aName.AssignLiteral("click");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DOMString getActionDescription (in PRUint8 index); */
|
2008-03-15 18:23:41 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetActionDescription(PRUint8 aIndex, nsAString& aDescription)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// default to localized action name.
|
|
|
|
nsAutoString name;
|
|
|
|
nsresult rv = GetActionName(aIndex, name);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return GetTranslatedString(name, aDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void doAction (in PRUint8 index); */
|
2008-03-15 18:23:41 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::DoAction(PRUint8 aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-15 18:23:41 -07:00
|
|
|
if (aIndex != 0)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2008-03-30 23:21:35 -07:00
|
|
|
PRBool doAction = PR_FALSE;
|
|
|
|
|
|
|
|
// Check if it's simple xlink.
|
2008-03-15 18:23:41 -07:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
2008-03-30 23:21:35 -07:00
|
|
|
if (nsAccUtils::IsXLink(content))
|
|
|
|
doAction = PR_TRUE;
|
|
|
|
|
|
|
|
// Has registered 'click' event handler.
|
|
|
|
if (!doAction)
|
|
|
|
doAction = nsAccUtils::HasListener(content, NS_LITERAL_STRING("click"));
|
2008-03-15 18:23:41 -07:00
|
|
|
|
2008-03-30 23:21:35 -07:00
|
|
|
if (doAction)
|
2008-03-15 18:23:41 -07:00
|
|
|
return DoCommand(content);
|
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DOMString getHelp (); */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetHelp(nsAString& _retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsIAccessible getAccessibleToRight(); */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetAccessibleToRight(nsIAccessible **_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsIAccessible getAccessibleToLeft(); */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetAccessibleToLeft(nsIAccessible **_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsIAccessible getAccessibleAbove(); */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetAccessibleAbove(nsIAccessible **_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsIAccessible getAccessibleBelow(); */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetAccessibleBelow(nsIAccessible **_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2007-09-18 14:40:04 -07:00
|
|
|
nsIDOMNode* nsAccessible::GetAtomicRegion()
|
|
|
|
{
|
2007-11-09 10:39:56 -08:00
|
|
|
nsCOMPtr<nsIContent> content = GetRoleContent(mDOMNode);
|
2007-09-18 14:40:04 -07:00
|
|
|
nsIContent *loopContent = content;
|
|
|
|
nsAutoString atomic;
|
2007-12-11 18:10:26 -08:00
|
|
|
while (loopContent && !loopContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_atomic, atomic)) {
|
2007-09-18 14:40:04 -07:00
|
|
|
loopContent = loopContent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> atomicRegion;
|
|
|
|
if (atomic.EqualsLiteral("true")) {
|
|
|
|
atomicRegion = do_QueryInterface(loopContent);
|
|
|
|
}
|
|
|
|
return atomicRegion;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* nsIAccessible getAccessibleRelated(); */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetAccessibleRelated(PRUint32 aRelationType, nsIAccessible **aRelated)
|
|
|
|
{
|
|
|
|
// When adding support for relations, make sure to add them to
|
|
|
|
// appropriate places in nsAccessibleWrap implementations
|
|
|
|
*aRelated = nsnull;
|
|
|
|
|
|
|
|
// Relationships are defined on the same content node
|
|
|
|
// that the role would be defined on
|
|
|
|
nsIContent *content = GetRoleContent(mDOMNode);
|
|
|
|
if (!content) {
|
|
|
|
return NS_ERROR_FAILURE; // Node already shut down
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> relatedNode;
|
|
|
|
nsAutoString relatedID;
|
|
|
|
|
|
|
|
// Search for the related DOM node according to the specified "relation type"
|
|
|
|
switch (aRelationType)
|
|
|
|
{
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_LABEL_FOR:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (content->Tag() == nsAccessibilityAtoms::label) {
|
|
|
|
nsIAtom *relatedIDAttr = content->IsNodeOfType(nsINode::eHTML) ?
|
|
|
|
nsAccessibilityAtoms::_for : nsAccessibilityAtoms::control;
|
|
|
|
content->GetAttr(kNameSpaceID_None, relatedIDAttr, relatedID);
|
|
|
|
}
|
|
|
|
if (relatedID.IsEmpty()) {
|
2007-09-24 18:19:03 -07:00
|
|
|
relatedNode =
|
2007-12-11 18:10:26 -08:00
|
|
|
do_QueryInterface(nsAccUtils::FindNeighbourPointingToNode(content, nsAccessibilityAtoms::aria_labelledby));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_LABELLED_BY:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-11 18:10:26 -08:00
|
|
|
if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_labelledby, relatedID)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
relatedNode = do_QueryInterface(GetLabelContent(content));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_DESCRIBED_BY:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-11 18:10:26 -08:00
|
|
|
if (!content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_describedby, relatedID)) {
|
2007-09-24 18:19:03 -07:00
|
|
|
relatedNode = do_QueryInterface(
|
2007-12-11 18:10:26 -08:00
|
|
|
nsAccUtils::FindNeighbourPointingToNode(content, nsAccessibilityAtoms::control, nsAccessibilityAtoms::description));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_DESCRIPTION_FOR:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
relatedNode =
|
2007-12-11 18:10:26 -08:00
|
|
|
do_QueryInterface(nsAccUtils::FindNeighbourPointingToNode(content, nsAccessibilityAtoms::aria_describedby));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!relatedNode && content->Tag() == nsAccessibilityAtoms::description &&
|
|
|
|
content->IsNodeOfType(nsINode::eXUL)) {
|
|
|
|
// This affectively adds an optional control attribute to xul:description,
|
|
|
|
// which only affects accessibility, by allowing the description to be
|
|
|
|
// tied to a control.
|
|
|
|
content->GetAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::control, relatedID);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_NODE_CHILD_OF:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-09-24 18:19:03 -07:00
|
|
|
relatedNode =
|
2007-12-11 18:10:26 -08:00
|
|
|
do_QueryInterface(nsAccUtils::FindNeighbourPointingToNode(content, nsAccessibilityAtoms::aria_owns));
|
2008-02-08 18:14:03 -08:00
|
|
|
if (!relatedNode && mRoleMapEntry && mRoleMapEntry->role == nsIAccessibleRole::ROLE_OUTLINEITEM) {
|
|
|
|
// This is an ARIA tree that doesn't use owns, so we need to get the parent the hard way
|
|
|
|
nsAccUtils::GetARIATreeItemParent(this, content, aRelated);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-03-05 19:45:43 -08:00
|
|
|
// If accessible is in its own Window then we should provide NODE_CHILD_OF relation
|
|
|
|
// so that MSAA clients can easily get to true parent instead of getting to oleacc's
|
|
|
|
// ROLE_WINDOW accessible which will prevent us from going up further (because it is
|
|
|
|
// system generated and has no idea about the hierarchy above it).
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (frame) {
|
|
|
|
nsIView *view = frame->GetViewExternal();
|
|
|
|
if (view) {
|
|
|
|
nsIScrollableFrame *scrollFrame = nsnull;
|
|
|
|
CallQueryInterface(frame, &scrollFrame);
|
|
|
|
if (scrollFrame || view->GetWidget()) {
|
|
|
|
return GetParent(aRelated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_CONTROLLED_BY:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-09-24 18:19:03 -07:00
|
|
|
relatedNode =
|
2007-12-11 18:10:26 -08:00
|
|
|
do_QueryInterface(nsAccUtils::FindNeighbourPointingToNode(content, nsAccessibilityAtoms::aria_controls));
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_CONTROLLER_FOR:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-11 18:10:26 -08:00
|
|
|
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_controls, relatedID);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_FLOWS_TO:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-11 18:10:26 -08:00
|
|
|
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_flowto, relatedID);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_FLOWS_FROM:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-09-24 18:19:03 -07:00
|
|
|
relatedNode =
|
2007-12-11 18:10:26 -08:00
|
|
|
do_QueryInterface(nsAccUtils::FindNeighbourPointingToNode(content, nsAccessibilityAtoms::aria_flowto));
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_DEFAULT_BUTTON:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (content->IsNodeOfType(nsINode::eHTML)) {
|
2007-08-10 06:03:52 -07:00
|
|
|
// HTML form controls implements nsIFormControl interface.
|
|
|
|
nsCOMPtr<nsIFormControl> control(do_QueryInterface(content));
|
|
|
|
if (control) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLFormElement> htmlform;
|
|
|
|
control->GetForm(getter_AddRefs(htmlform));
|
|
|
|
nsCOMPtr<nsIForm> form(do_QueryInterface(htmlform));
|
|
|
|
if (form)
|
2007-03-22 10:30:00 -07:00
|
|
|
relatedNode = do_QueryInterface(form->GetDefaultSubmitElement());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// In XUL, use first <button default="true" .../> in the document
|
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(content->GetDocument());
|
|
|
|
nsCOMPtr<nsIDOMXULButtonElement> buttonEl;
|
|
|
|
if (xulDoc) {
|
|
|
|
nsCOMPtr<nsIDOMNodeList> possibleDefaultButtons;
|
|
|
|
xulDoc->GetElementsByAttribute(NS_LITERAL_STRING("default"),
|
|
|
|
NS_LITERAL_STRING("true"),
|
|
|
|
getter_AddRefs(possibleDefaultButtons));
|
|
|
|
if (possibleDefaultButtons) {
|
|
|
|
PRUint32 length;
|
|
|
|
possibleDefaultButtons->GetLength(&length);
|
|
|
|
nsCOMPtr<nsIDOMNode> possibleButton;
|
|
|
|
// Check for button in list of default="true" elements
|
|
|
|
for (PRUint32 count = 0; count < length && !buttonEl; count ++) {
|
|
|
|
possibleDefaultButtons->Item(count, getter_AddRefs(possibleButton));
|
|
|
|
buttonEl = do_QueryInterface(possibleButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!buttonEl) { // Check for anonymous accept button in <dialog>
|
|
|
|
nsCOMPtr<nsIDOMDocumentXBL> xblDoc(do_QueryInterface(xulDoc));
|
|
|
|
if (xblDoc) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(xulDoc);
|
|
|
|
NS_ASSERTION(domDoc, "No DOM document");
|
|
|
|
nsCOMPtr<nsIDOMElement> rootEl;
|
|
|
|
domDoc->GetDocumentElement(getter_AddRefs(rootEl));
|
|
|
|
if (rootEl) {
|
|
|
|
nsCOMPtr<nsIDOMElement> possibleButtonEl;
|
|
|
|
xblDoc->GetAnonymousElementByAttribute(rootEl,
|
|
|
|
NS_LITERAL_STRING("default"),
|
|
|
|
NS_LITERAL_STRING("true"),
|
|
|
|
getter_AddRefs(possibleButtonEl));
|
|
|
|
buttonEl = do_QueryInterface(possibleButtonEl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
relatedNode = do_QueryInterface(buttonEl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-08-10 18:44:44 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_MEMBER_OF:
|
|
|
|
{
|
2007-09-18 14:40:04 -07:00
|
|
|
relatedNode = GetAtomicRegion();
|
2007-08-10 18:44:44 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!relatedID.IsEmpty()) {
|
|
|
|
// In some cases we need to get the relatedNode from an ID-style attribute
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
mDOMNode->GetOwnerDocument(getter_AddRefs(domDoc));
|
|
|
|
NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIDOMElement> relatedEl;
|
|
|
|
domDoc->GetElementById(relatedID, getter_AddRefs(relatedEl));
|
|
|
|
relatedNode = do_QueryInterface(relatedEl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the corresponding accessible if the related DOM node is found
|
|
|
|
if (relatedNode) {
|
2007-05-19 19:41:33 -07:00
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = GetAccService();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(accService, NS_ERROR_FAILURE);
|
2007-06-30 13:06:13 -07:00
|
|
|
accService->GetAccessibleInWeakShell(relatedNode, mWeakShell, aRelated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-06-30 13:06:13 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetRelationsCount(PRUint32 *aCount)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
*aCount = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIArray> relations;
|
|
|
|
nsresult rv = GetRelations(getter_AddRefs(relations));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return relations->GetLength(aCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetRelation(PRUint32 aIndex, nsIAccessibleRelation **aRelation)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRelation);
|
|
|
|
*aRelation = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIArray> relations;
|
|
|
|
nsresult rv = GetRelations(getter_AddRefs(relations));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessibleRelation> relation;
|
|
|
|
rv = relations->QueryElementAt(aIndex, NS_GET_IID(nsIAccessibleRelation),
|
|
|
|
getter_AddRefs(relation));
|
2008-03-29 20:24:02 -07:00
|
|
|
|
|
|
|
// nsIArray::QueryElementAt() returns NS_ERROR_ILLEGAL_VALUE on invalid index.
|
|
|
|
if (rv == NS_ERROR_ILLEGAL_VALUE)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aRelation = relation);
|
2008-03-29 20:24:02 -07:00
|
|
|
return NS_OK;
|
2007-05-19 19:41:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetRelations(nsIArray **aRelations)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRelations);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMutableArray> relations = do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(relations, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2007-08-30 11:51:47 -07:00
|
|
|
for (PRUint32 relType = nsIAccessibleRelation::RELATION_FIRST;
|
|
|
|
relType < nsIAccessibleRelation::RELATION_LAST;
|
|
|
|
++relType) {
|
2007-05-19 19:41:33 -07:00
|
|
|
nsCOMPtr<nsIAccessible> accessible;
|
2007-08-30 11:51:47 -07:00
|
|
|
GetAccessibleRelated(relType, getter_AddRefs(accessible));
|
2007-05-19 19:41:33 -07:00
|
|
|
|
|
|
|
if (accessible) {
|
|
|
|
nsCOMPtr<nsIAccessibleRelation> relation =
|
2007-05-24 06:26:54 -07:00
|
|
|
new nsAccessibleRelationWrap(relType, accessible);
|
2007-05-19 19:41:33 -07:00
|
|
|
NS_ENSURE_TRUE(relation, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
relations->AppendElement(relation, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aRelations = relations);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* void extendSelection (); */
|
|
|
|
NS_IMETHODIMP nsAccessible::ExtendSelection()
|
|
|
|
{
|
|
|
|
// XXX Should be implemented, but not high priority
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [noscript] void getNativeInterface(out voidPtr aOutAccessible); */
|
|
|
|
NS_IMETHODIMP nsAccessible::GetNativeInterface(void **aOutAccessible)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsAccessible::DoCommandCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
2008-08-06 05:16:54 -07:00
|
|
|
NS_ASSERTION(gDoCommandTimer,
|
|
|
|
"How did we get here if there was no gDoCommandTimer?");
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_RELEASE(gDoCommandTimer);
|
|
|
|
|
2008-08-06 05:16:54 -07:00
|
|
|
nsCOMPtr<nsIContent> content =
|
|
|
|
reinterpret_cast<nsIContent*>(aClosure);
|
|
|
|
|
|
|
|
nsIDocument *doc = content->GetDocument();
|
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
|
|
|
|
|
|
|
|
// Scroll into view.
|
|
|
|
presShell->ScrollContentIntoView(content, NS_PRESSHELL_SCROLL_ANYWHERE,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE);
|
|
|
|
|
|
|
|
// Fire mouse down and mouse up events.
|
|
|
|
PRBool res = nsAccUtils::DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, presShell,
|
|
|
|
content);
|
|
|
|
if (!res)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAccUtils::DispatchMouseEvent(NS_MOUSE_BUTTON_UP, presShell, content);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use Timer to execute "Click" command of XUL/HTML element (e.g. menuitem, button...).
|
|
|
|
*
|
|
|
|
* When "Click" is to open a "modal" dialog/window, it won't return untill the
|
|
|
|
* dialog/window is closed. If executing "Click" command directly in
|
|
|
|
* nsXXXAccessible::DoAction, it will block AT-Tools(e.g. GOK) that invoke
|
|
|
|
* "action" of mozilla accessibles direclty.
|
|
|
|
*/
|
|
|
|
nsresult nsAccessible::DoCommand(nsIContent *aContent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content = aContent;
|
|
|
|
if (!content) {
|
|
|
|
content = do_QueryInterface(mDOMNode);
|
|
|
|
}
|
|
|
|
if (gDoCommandTimer) {
|
|
|
|
// Already have timer going for another command
|
|
|
|
NS_WARNING("Doubling up on do command timers doesn't work. This wasn't expected.");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> timer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (!timer) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(gDoCommandTimer = timer);
|
|
|
|
return gDoCommandTimer->InitWithFuncCallback(DoCommandCallback,
|
|
|
|
(void*)content, 0,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIAccessible>
|
|
|
|
nsAccessible::GetNextWithState(nsIAccessible *aStart, PRUint32 matchState)
|
|
|
|
{
|
|
|
|
// Return the next descendant that matches one of the states in matchState
|
|
|
|
// Uses depth first search
|
|
|
|
NS_ASSERTION(matchState, "GetNextWithState() not called with a state to match");
|
|
|
|
NS_ASSERTION(aStart, "GetNextWithState() not called with an accessible to start with");
|
|
|
|
nsCOMPtr<nsIAccessible> look, current = aStart;
|
|
|
|
PRUint32 state = 0;
|
|
|
|
while (0 == (state & matchState)) {
|
|
|
|
current->GetFirstChild(getter_AddRefs(look));
|
|
|
|
while (!look) {
|
|
|
|
if (current == this) {
|
|
|
|
return nsnull; // At top of subtree
|
|
|
|
}
|
|
|
|
current->GetNextSibling(getter_AddRefs(look));
|
|
|
|
if (!look) {
|
|
|
|
current->GetParent(getter_AddRefs(look));
|
2007-11-09 10:43:08 -08:00
|
|
|
current = look;
|
|
|
|
look = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
current.swap(look);
|
2007-04-02 08:56:24 -07:00
|
|
|
state = State(current);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAccessible *returnAccessible = nsnull;
|
|
|
|
current.swap(returnAccessible);
|
|
|
|
|
|
|
|
return returnAccessible;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIAccessibleSelectable
|
|
|
|
NS_IMETHODIMP nsAccessible::GetSelectedChildren(nsIArray **aSelectedAccessibles)
|
|
|
|
{
|
|
|
|
*aSelectedAccessibles = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMutableArray> selectedAccessibles =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
NS_ENSURE_STATE(selectedAccessibles);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> selected = this;
|
|
|
|
while ((selected = GetNextWithState(selected, nsIAccessibleStates::STATE_SELECTED)) != nsnull) {
|
|
|
|
selectedAccessibles->AppendElement(selected, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 length = 0;
|
|
|
|
selectedAccessibles->GetLength(&length);
|
|
|
|
if (length) { // length of nsIArray containing selected options
|
|
|
|
*aSelectedAccessibles = selectedAccessibles;
|
|
|
|
NS_ADDREF(*aSelectedAccessibles);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the nth selected descendant nsIAccessible object
|
|
|
|
NS_IMETHODIMP nsAccessible::RefSelection(PRInt32 aIndex, nsIAccessible **aSelected)
|
|
|
|
{
|
|
|
|
*aSelected = nsnull;
|
|
|
|
if (aIndex < 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIAccessible> selected = this;
|
|
|
|
PRInt32 count = 0;
|
|
|
|
while (count ++ <= aIndex) {
|
|
|
|
selected = GetNextWithState(selected, nsIAccessibleStates::STATE_SELECTED);
|
|
|
|
if (!selected) {
|
|
|
|
return NS_ERROR_FAILURE; // aIndex out of range
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_ADDREF(*aSelected = selected);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::GetSelectionCount(PRInt32 *aSelectionCount)
|
|
|
|
{
|
|
|
|
*aSelectionCount = 0;
|
|
|
|
nsCOMPtr<nsIAccessible> selected = this;
|
|
|
|
while ((selected = GetNextWithState(selected, nsIAccessibleStates::STATE_SELECTED)) != nsnull) {
|
|
|
|
++ *aSelectionCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::AddChildToSelection(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
// Tree views and other container widgets which may have grandchildren should
|
|
|
|
// implement a selection methods for their specific interfaces, because being
|
|
|
|
// able to deal with selection on a per-child basis would not be enough.
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(aIndex >= 0, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> child;
|
|
|
|
GetChildAt(aIndex, getter_AddRefs(child));
|
|
|
|
|
2007-04-02 08:56:24 -07:00
|
|
|
PRUint32 state = State(child);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!(state & nsIAccessibleStates::STATE_SELECTABLE)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return child->SetSelected(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::RemoveChildFromSelection(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
// Tree views and other container widgets which may have grandchildren should
|
|
|
|
// implement a selection methods for their specific interfaces, because being
|
|
|
|
// able to deal with selection on a per-child basis would not be enough.
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(aIndex >= 0, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> child;
|
|
|
|
GetChildAt(aIndex, getter_AddRefs(child));
|
|
|
|
|
2007-04-02 08:56:24 -07:00
|
|
|
PRUint32 state = State(child);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!(state & nsIAccessibleStates::STATE_SELECTED)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return child->SetSelected(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::IsChildSelected(PRInt32 aIndex, PRBool *aIsSelected)
|
|
|
|
{
|
|
|
|
// Tree views and other container widgets which may have grandchildren should
|
|
|
|
// implement a selection methods for their specific interfaces, because being
|
|
|
|
// able to deal with selection on a per-child basis would not be enough.
|
|
|
|
|
|
|
|
*aIsSelected = PR_FALSE;
|
|
|
|
NS_ENSURE_TRUE(aIndex >= 0, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> child;
|
|
|
|
GetChildAt(aIndex, getter_AddRefs(child));
|
|
|
|
|
2007-04-02 08:56:24 -07:00
|
|
|
PRUint32 state = State(child);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (state & nsIAccessibleStates::STATE_SELECTED) {
|
|
|
|
*aIsSelected = PR_TRUE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::ClearSelection()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessible> selected = this;
|
|
|
|
while ((selected = GetNextWithState(selected, nsIAccessibleStates::STATE_SELECTED)) != nsnull) {
|
|
|
|
selected->SetSelected(PR_FALSE);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::SelectAllSelection(PRBool *_retval)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessible> selectable = this;
|
|
|
|
while ((selectable = GetNextWithState(selectable, nsIAccessibleStates::STATE_SELECTED)) != nsnull) {
|
|
|
|
selectable->SetSelected(PR_TRUE);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIAccessibleHyperLink
|
|
|
|
// Because of new-atk design, any embedded object in text can implement
|
|
|
|
// nsIAccessibleHyperLink, which helps determine where it is located
|
|
|
|
// within containing text
|
|
|
|
|
2008-04-11 08:57:36 -07:00
|
|
|
// readonly attribute long nsIAccessibleHyperLink::anchorCount
|
2008-03-30 08:33:01 -07:00
|
|
|
NS_IMETHODIMP
|
2008-04-11 08:57:36 -07:00
|
|
|
nsAccessible::GetAnchorCount(PRInt32 *aAnchorCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-04-11 08:57:36 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aAnchorCount);
|
|
|
|
*aAnchorCount = 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-30 08:33:01 -07:00
|
|
|
// readonly attribute long nsIAccessibleHyperLink::startIndex
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetStartIndex(PRInt32 *aStartIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-30 08:33:01 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aStartIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aStartIndex = 0;
|
|
|
|
PRInt32 endIndex;
|
|
|
|
return GetLinkOffset(aStartIndex, &endIndex);
|
|
|
|
}
|
|
|
|
|
2008-03-30 08:33:01 -07:00
|
|
|
// readonly attribute long nsIAccessibleHyperLink::endIndex
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetEndIndex(PRInt32 *aEndIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-30 08:33:01 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aEndIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aEndIndex = 0;
|
|
|
|
PRInt32 startIndex;
|
|
|
|
return GetLinkOffset(&startIndex, aEndIndex);
|
|
|
|
}
|
|
|
|
|
2008-03-30 08:33:01 -07:00
|
|
|
NS_IMETHODIMP
|
2008-03-30 23:21:35 -07:00
|
|
|
nsAccessible::GetURI(PRInt32 aIndex, nsIURI **aURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-30 08:33:01 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aURI = nsnull;
|
2008-03-30 23:21:35 -07:00
|
|
|
|
|
|
|
if (aIndex != 0)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// Check if it's simple xlink.
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
if (nsAccUtils::IsXLink(content)) {
|
|
|
|
nsAutoString href;
|
|
|
|
content->GetAttr(kNameSpaceID_XLink, nsAccessibilityAtoms::href, href);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURI = content->GetBaseURI();
|
|
|
|
nsCOMPtr<nsIDocument> document = content->GetOwnerDoc();
|
|
|
|
return NS_NewURI(aURI, href,
|
|
|
|
document ? document->GetDocumentCharacterSet().get() : nsnull,
|
|
|
|
baseURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-30 23:21:35 -07:00
|
|
|
|
2008-03-30 08:33:01 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetAnchor(PRInt32 aIndex,
|
2008-03-30 23:21:35 -07:00
|
|
|
nsIAccessible **aAccessible)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-29 20:24:02 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aAccessible);
|
|
|
|
*aAccessible = nsnull;
|
|
|
|
|
|
|
|
if (aIndex != 0)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*aAccessible = this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-30 08:33:01 -07:00
|
|
|
// readonly attribute boolean nsIAccessibleHyperLink::valid
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetValid(PRBool *aValid)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-30 08:33:01 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aValid);
|
2007-04-02 08:56:24 -07:00
|
|
|
PRUint32 state = State(this);
|
2008-03-30 08:33:01 -07:00
|
|
|
*aValid = (0 == (state & nsIAccessibleStates::STATE_INVALID));
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX In order to implement this we would need to follow every link
|
|
|
|
// Perhaps we can get information about invalid links from the cache
|
2008-03-30 08:33:01 -07:00
|
|
|
// In the mean time authors can use role="link" aria-invalid="true"
|
2007-03-22 10:30:00 -07:00
|
|
|
// to force it for links they internally know to be invalid
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-30 08:33:01 -07:00
|
|
|
// readonly attribute boolean nsIAccessibleHyperLink::selected
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetSelected(PRBool *aSelected)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-30 08:33:01 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aSelected);
|
|
|
|
*aSelected = (gLastFocusedNode == mDOMNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsAccessible::GetLinkOffset(PRInt32* aStartOffset, PRInt32* aEndOffset)
|
|
|
|
{
|
|
|
|
*aStartOffset = *aEndOffset = 0;
|
|
|
|
nsCOMPtr<nsIAccessible> parent(GetParent());
|
|
|
|
if (!parent) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> accessible, nextSibling;
|
|
|
|
PRInt32 characterCount = 0;
|
|
|
|
parent->GetFirstChild(getter_AddRefs(accessible));
|
|
|
|
|
|
|
|
while (accessible) {
|
|
|
|
if (IsText(accessible)) {
|
|
|
|
characterCount += TextLength(accessible);
|
|
|
|
}
|
|
|
|
else if (accessible == this) {
|
|
|
|
*aStartOffset = characterCount;
|
|
|
|
*aEndOffset = characterCount + 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++ characterCount;
|
|
|
|
}
|
|
|
|
accessible->GetNextSibling(getter_AddRefs(nextSibling));
|
|
|
|
accessible.swap(nextSibling);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 nsAccessible::TextLength(nsIAccessible *aAccessible)
|
|
|
|
{
|
2007-04-10 21:17:33 -07:00
|
|
|
if (!IsText(aAccessible))
|
2007-03-22 10:30:00 -07:00
|
|
|
return 1;
|
2007-04-10 21:17:33 -07:00
|
|
|
|
2007-08-03 18:12:24 -07:00
|
|
|
nsCOMPtr<nsPIAccessNode> pAccNode(do_QueryInterface(aAccessible));
|
|
|
|
NS_ASSERTION(pAccNode, "QI to nsPIAccessNode failed");
|
|
|
|
|
|
|
|
nsIFrame *frame = pAccNode->GetFrame();
|
2007-09-05 06:31:33 -07:00
|
|
|
if (frame && frame->GetType() == nsAccessibilityAtoms::textFrame) {
|
|
|
|
// Ensure that correct text length is calculated (with non-rendered whitespace chars not counted)
|
2007-08-03 18:12:24 -07:00
|
|
|
nsIContent *content = frame->GetContent();
|
|
|
|
if (content) {
|
|
|
|
PRUint32 length;
|
|
|
|
nsresult rv = nsHyperTextAccessible::ContentToRenderedOffset(frame, content->TextLength(), &length);
|
2007-09-05 06:31:33 -07:00
|
|
|
return NS_SUCCEEDED(rv) ? static_cast<PRInt32>(length) : -1;
|
2007-08-03 18:12:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For list bullets (or anything other accessible which would compute its own text
|
|
|
|
// They don't have their own frame.
|
|
|
|
// XXX In the future, list bullets may have frame and anon content, so
|
|
|
|
// we should be able to remove this at that point
|
2007-04-10 21:17:33 -07:00
|
|
|
nsCOMPtr<nsPIAccessible> pAcc(do_QueryInterface(aAccessible));
|
2007-08-03 18:12:24 -07:00
|
|
|
NS_ASSERTION(pAcc, "QI to nsPIAccessible failed");
|
2007-04-10 21:17:33 -07:00
|
|
|
|
|
|
|
nsAutoString text;
|
2007-08-03 18:12:24 -07:00
|
|
|
pAcc->AppendTextTo(text, 0, PR_UINT32_MAX); // Get all the text
|
2007-04-10 21:17:33 -07:00
|
|
|
return text.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-08-03 18:12:24 -07:00
|
|
|
nsAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset, PRUint32 aLength)
|
2007-04-10 21:17:33 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIAccessible>
|
|
|
|
nsAccessible::GetFirstAvailableAccessible(nsIDOMNode *aStartNode, PRBool aRequireLeaf)
|
|
|
|
{
|
|
|
|
nsIAccessibilityService *accService = GetAccService();
|
|
|
|
nsCOMPtr<nsIAccessible> accessible;
|
|
|
|
nsCOMPtr<nsIDOMTreeWalker> walker;
|
|
|
|
nsCOMPtr<nsIDOMNode> currentNode(aStartNode);
|
|
|
|
|
|
|
|
while (currentNode) {
|
|
|
|
accService->GetAccessibleInWeakShell(currentNode, mWeakShell, getter_AddRefs(accessible)); // AddRef'd
|
|
|
|
if (accessible && (!aRequireLeaf || IsLeaf(accessible))) {
|
|
|
|
nsIAccessible *retAccessible = accessible;
|
|
|
|
NS_ADDREF(retAccessible);
|
|
|
|
return retAccessible;
|
|
|
|
}
|
|
|
|
if (!walker) {
|
|
|
|
// Instantiate walker lazily since we won't need it in 90% of the cases
|
|
|
|
// where the first DOM node we're given provides an accessible
|
|
|
|
nsCOMPtr<nsIDOMDocument> document;
|
|
|
|
currentNode->GetOwnerDocument(getter_AddRefs(document));
|
|
|
|
nsCOMPtr<nsIDOMDocumentTraversal> trav = do_QueryInterface(document);
|
|
|
|
NS_ASSERTION(trav, "No DOM document traversal for document");
|
|
|
|
NS_ENSURE_TRUE(trav, nsnull);
|
|
|
|
trav->CreateTreeWalker(mDOMNode, nsIDOMNodeFilter::SHOW_ELEMENT | nsIDOMNodeFilter::SHOW_TEXT,
|
|
|
|
nsnull, PR_FALSE, getter_AddRefs(walker));
|
|
|
|
NS_ENSURE_TRUE(walker, nsnull);
|
|
|
|
walker->SetCurrentNode(currentNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
walker->NextNode(getter_AddRefs(currentNode));
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsAccessible::CheckVisibilityInParentChain(nsIDocument* aDocument, nsIView* aView)
|
|
|
|
{
|
|
|
|
nsIDocument* document = aDocument;
|
|
|
|
nsIView* view = aView;
|
|
|
|
// both view chain and widget chain are broken between chrome and content
|
|
|
|
while (document != nsnull) {
|
|
|
|
while (view != nsnull) {
|
|
|
|
if (view->GetVisibility() == nsViewVisibility_kHide) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
view = view->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* parentDoc = document->GetParentDocument();
|
|
|
|
if (parentDoc != nsnull) {
|
|
|
|
nsIContent* content = parentDoc->FindContentForSubDocument(document);
|
|
|
|
if (content != nsnull) {
|
2007-05-01 15:24:20 -07:00
|
|
|
nsIPresShell* shell = parentDoc->GetPrimaryShell();
|
2007-11-12 19:05:34 -08:00
|
|
|
if (!shell) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* frame = shell->GetPrimaryFrameFor(content);
|
|
|
|
while (frame != nsnull && !frame->HasView()) {
|
|
|
|
frame = frame->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame != nsnull) {
|
|
|
|
view = frame->GetViewExternal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document = parentDoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2007-08-03 22:27:27 -07:00
|
|
|
|
|
|
|
nsresult
|
2007-12-11 18:10:26 -08:00
|
|
|
nsAccessible::GetAttrValue(nsIAtom *aProperty, double *aValue)
|
2007-08-03 22:27:27 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aValue);
|
|
|
|
*aValue = 0;
|
|
|
|
|
|
|
|
if (!mDOMNode)
|
|
|
|
return NS_ERROR_FAILURE; // Node already shut down
|
|
|
|
|
|
|
|
if (!mRoleMapEntry || mRoleMapEntry->valueRule == eNoValue)
|
|
|
|
return NS_OK_NO_ARIA_VALUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
NS_ENSURE_STATE(content);
|
|
|
|
|
|
|
|
PRInt32 result = NS_OK;
|
|
|
|
nsAutoString value;
|
2007-12-11 18:10:26 -08:00
|
|
|
if (content->GetAttr(kNameSpaceID_None, aProperty, value))
|
2007-08-03 22:27:27 -07:00
|
|
|
*aValue = value.ToFloat(&result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-08-15 14:02:31 -07:00
|
|
|
PRBool nsAccessible::MustPrune(nsIAccessible *aAccessible)
|
|
|
|
{
|
|
|
|
PRUint32 role = Role(aAccessible);
|
|
|
|
return role == nsIAccessibleRole::ROLE_MENUITEM ||
|
2007-11-15 11:46:29 -08:00
|
|
|
role == nsIAccessibleRole::ROLE_COMBOBOX_OPTION ||
|
|
|
|
role == nsIAccessibleRole::ROLE_OPTION ||
|
2007-08-15 14:02:31 -07:00
|
|
|
role == nsIAccessibleRole::ROLE_ENTRY ||
|
2008-04-11 12:53:19 -07:00
|
|
|
role == nsIAccessibleRole::ROLE_FLAT_EQUATION ||
|
2007-08-15 14:02:31 -07:00
|
|
|
role == nsIAccessibleRole::ROLE_PASSWORD_TEXT ||
|
|
|
|
role == nsIAccessibleRole::ROLE_PUSHBUTTON ||
|
|
|
|
role == nsIAccessibleRole::ROLE_TOGGLE_BUTTON ||
|
|
|
|
role == nsIAccessibleRole::ROLE_GRAPHIC ||
|
|
|
|
role == nsIAccessibleRole::ROLE_SLIDER ||
|
|
|
|
role == nsIAccessibleRole::ROLE_PROGRESSBAR ||
|
|
|
|
role == nsIAccessibleRole::ROLE_SEPARATOR;
|
|
|
|
}
|