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-08-10 06:03:52 -07:00
|
|
|
|
2009-05-13 22:29:33 -07:00
|
|
|
#include "nsIXBLAccessible.h"
|
2010-03-16 23:02:28 -07:00
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
#include "AccIterator.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsAccUtils.h"
|
|
|
|
#include "nsARIAMap.h"
|
2010-03-16 23:02:28 -07:00
|
|
|
#include "nsDocAccessible.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsEventShell.h"
|
|
|
|
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#include "nsAccTreeWalker.h"
|
|
|
|
#include "nsRelUtils.h"
|
|
|
|
#include "nsTextEquivUtils.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
|
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"
|
2009-09-08 22:40:02 -07:00
|
|
|
#include "nsIView.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2008-03-05 19:45:43 -08:00
|
|
|
#include "nsIScrollableFrame.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
#include "nsFocusManager.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"
|
2009-02-10 02:03:30 -08:00
|
|
|
#include "nsArrayUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#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 "nsIDOMCharacterData.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
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)
|
2010-01-11 06:14:06 -08:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mParent");
|
|
|
|
cb.NoteXPCOMChild(static_cast<nsIAccessible*>(tmp->mParent.get()));
|
|
|
|
|
|
|
|
PRUint32 i, length = tmp->mChildren.Length();
|
|
|
|
for (i = 0; i < length; ++i) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mChildren[i]");
|
|
|
|
cb.NoteXPCOMChild(static_cast<nsIAccessible*>(tmp->mChildren[i].get()));
|
|
|
|
}
|
2008-08-06 05:19:56 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsAccessible, nsAccessNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mParent)
|
2010-01-11 06:14:06 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mChildren)
|
2008-08-06 05:19:56 -07:00
|
|
|
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)
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsAccessible))) {
|
|
|
|
*aInstancePtr = static_cast<nsAccessible*>(this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIAccessibleSelectable))) {
|
2009-12-11 11:38:55 -08:00
|
|
|
if (mRoleMapEntry &&
|
|
|
|
(mRoleMapEntry->attributeMap1 == eARIAMultiSelectable ||
|
|
|
|
mRoleMapEntry->attributeMap2 == eARIAMultiSelectable ||
|
|
|
|
mRoleMapEntry->attributeMap3 == eARIAMultiSelectable)) {
|
|
|
|
|
|
|
|
// If we have an ARIA role attribute present and the role allows multi
|
|
|
|
// selectable state, then we need to support nsIAccessibleSelectable.
|
2007-03-22 10:30:00 -07:00
|
|
|
// If either attribute (role or multiselectable) change, then we'll
|
|
|
|
// destroy this accessible so that we can follow COM identity rules.
|
2009-12-11 11:38:55 -08:00
|
|
|
|
|
|
|
*aInstancePtr = static_cast<nsIAccessibleSelectable*>(this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
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))) {
|
2010-05-17 09:15:52 -07:00
|
|
|
// Every embedded accessible within hypertext accessible implements
|
|
|
|
// hyperlink interface.
|
2010-05-11 02:48:10 -07:00
|
|
|
nsCOMPtr<nsIAccessibleHyperText> hyperTextParent = do_QueryObject(GetParent());
|
2010-05-17 09:15:52 -07:00
|
|
|
if (hyperTextParent && nsAccUtils::IsEmbeddedObject(this)) {
|
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
|
|
|
}
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccessible::nsAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
|
|
|
|
nsAccessNodeWrap(aContent, aShell),
|
|
|
|
mParent(nsnull), mAreChildrenInitialized(PR_FALSE), mRoleMapEntry(nsnull)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-18 00:37:38 -07:00
|
|
|
void
|
|
|
|
nsAccessible::SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry)
|
2007-11-11 17:05:37 -08:00
|
|
|
{
|
|
|
|
mRoleMapEntry = aRoleMapEntry;
|
|
|
|
}
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetName(nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
GetARIAName(aName);
|
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIXBLAccessible> xblAccessible(do_QueryInterface(mContent));
|
2009-05-13 22:29:33 -07:00
|
|
|
if (xblAccessible) {
|
2009-06-24 16:18:46 -07:00
|
|
|
xblAccessible->GetAccessibleName(aName);
|
2009-05-13 22:29:33 -07:00
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-12-02 23:21:08 -08:00
|
|
|
nsresult rv = GetNameInternal(aName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// In the end get the name from tooltip.
|
|
|
|
nsIAtom *tooltipAttr = nsnull;
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->IsHTML())
|
2008-12-02 23:21:08 -08:00
|
|
|
tooltipAttr = nsAccessibilityAtoms::title;
|
2010-06-11 01:23:18 -07:00
|
|
|
else if (mContent->IsXUL())
|
2008-12-02 23:21:08 -08:00
|
|
|
tooltipAttr = nsAccessibilityAtoms::tooltiptext;
|
|
|
|
else
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// XXX: if CompressWhiteSpace worked on nsAString we could avoid a copy.
|
|
|
|
nsAutoString name;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, tooltipAttr, name)) {
|
2008-12-02 23:21:08 -08:00
|
|
|
name.CompressWhitespace();
|
|
|
|
aName = name;
|
2009-02-27 02:54:39 -08:00
|
|
|
return NS_OK_NAME_FROM_TOOLTIP;
|
2008-12-02 23:21:08 -08:00
|
|
|
}
|
|
|
|
|
2009-02-27 02:54:39 -08:00
|
|
|
if (rv != NS_OK_EMPTY_NAME)
|
|
|
|
aName.SetIsVoid(PR_TRUE);
|
|
|
|
|
2008-12-02 23:21:08 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::GetDescription(nsAString& aDescription)
|
|
|
|
{
|
2009-04-24 07:40:18 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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;
|
2009-04-24 07:40:18 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
if (!mContent->IsNodeOfType(nsINode::eTEXT)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString description;
|
2009-02-18 23:06:14 -08:00
|
|
|
nsresult rv = nsTextEquivUtils::
|
|
|
|
GetTextEquivFromIDRefs(this, nsAccessibilityAtoms::aria_describedby,
|
|
|
|
description);
|
2009-04-24 07:40:18 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (description.IsEmpty()) {
|
2010-06-11 01:23:18 -07:00
|
|
|
PRBool isXUL = mContent->IsXUL();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isXUL) {
|
|
|
|
// Try XUL <description control="[id]">description text</description>
|
|
|
|
nsIContent *descriptionContent =
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCoreUtils::FindNeighbourPointingToNode(mContent,
|
2008-10-15 18:52:58 -07:00
|
|
|
nsAccessibilityAtoms::control,
|
|
|
|
nsAccessibilityAtoms::description);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (descriptionContent) {
|
|
|
|
// We have a description content node
|
2009-02-18 23:06:14 -08:00
|
|
|
nsTextEquivUtils::
|
|
|
|
AppendTextEquivFromContent(this, descriptionContent, &description);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (description.IsEmpty()) {
|
|
|
|
nsIAtom *descAtom = isXUL ? nsAccessibilityAtoms::tooltiptext :
|
|
|
|
nsAccessibilityAtoms::title;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, descAtom, description)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
if (IsDefunct())
|
2007-08-28 23:52:46 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
PRUint32 key = nsCoreUtils::GetAccessKeyFor(mContent);
|
|
|
|
if (!key && mContent->IsElement()) {
|
2007-09-18 20:36:20 -07:00
|
|
|
// Copy access key from label node unless it is labeled
|
|
|
|
// via an ancestor <label>, in which case that would be redundant
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIContent> labelContent(nsCoreUtils::GetLabelContent(mContent));
|
|
|
|
if (labelContent && !nsCoreUtils::IsAncestorOf(labelContent, mContent))
|
2008-10-15 18:52:58 -07:00
|
|
|
key = nsCoreUtils::GetAccessKeyFor(labelContent);
|
2007-08-28 23:52:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2010-06-11 01:23:18 -07:00
|
|
|
PRInt32 modifierMask = GetAccessModifierMask(mContent);
|
2007-08-28 23:52:46 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-06-18 00:37:38 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetParent(nsIAccessible **aParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_IF_ADDREF(*aParent = GetParent());
|
|
|
|
return *aParent ? NS_OK : NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
/* readonly attribute nsIAccessible nextSibling; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetNextSibling(nsIAccessible **aNextSibling)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aNextSibling);
|
2009-06-18 00:37:38 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
NS_IF_ADDREF(*aNextSibling = GetSiblingAtOffset(1, &rv));
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
/* readonly attribute nsIAccessible previousSibling; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetPreviousSibling(nsIAccessible * *aPreviousSibling)
|
2007-09-28 13:55:46 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aPreviousSibling);
|
2009-06-18 00:37:38 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
NS_IF_ADDREF(*aPreviousSibling = GetSiblingAtOffset(-1, &rv));
|
|
|
|
return rv;
|
2009-11-19 08:35:38 -08:00
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
/* readonly attribute nsIAccessible firstChild; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetFirstChild(nsIAccessible **aFirstChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aFirstChild);
|
|
|
|
*aFirstChild = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
if (gIsCacheDisabled)
|
|
|
|
InvalidateChildren();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
PRInt32 childCount = GetChildCount();
|
|
|
|
NS_ENSURE_TRUE(childCount != -1, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
if (childCount > 0)
|
|
|
|
NS_ADDREF(*aFirstChild = GetChildAt(0));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
/* readonly attribute nsIAccessible lastChild; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetLastChild(nsIAccessible **aLastChild)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLastChild);
|
|
|
|
*aLastChild = nsnull;
|
2009-11-19 08:35:38 -08:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
PRInt32 childCount = GetChildCount();
|
|
|
|
NS_ENSURE_TRUE(childCount != -1, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_IF_ADDREF(*aLastChild = GetChildAt(childCount - 1));
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetChildAt(PRInt32 aChildIndex, nsIAccessible **aChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aChild);
|
|
|
|
*aChild = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
PRInt32 childCount = GetChildCount();
|
|
|
|
NS_ENSURE_TRUE(childCount != -1, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
// If child index is negative, then return last child.
|
|
|
|
// XXX: do we really need this?
|
|
|
|
if (aChildIndex < 0)
|
|
|
|
aChildIndex = childCount - 1;
|
2009-11-19 08:35:38 -08:00
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible* child = GetChildAt(aChildIndex);
|
2009-12-10 11:12:19 -08:00
|
|
|
if (!child)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ADDREF(*aChild = child);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// readonly attribute nsIArray children;
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetChildren(nsIArray **aOutChildren)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aOutChildren);
|
2008-01-28 20:03:26 -08:00
|
|
|
*aOutChildren = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
PRInt32 childCount = GetChildCount();
|
|
|
|
NS_ENSURE_TRUE(childCount != -1, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIMutableArray> children =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
for (PRInt32 childIdx = 0; childIdx < childCount; childIdx++) {
|
|
|
|
nsIAccessible* child = GetChildAt(childIdx);
|
|
|
|
children->AppendElement(child, PR_FALSE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-12-10 11:12:19 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ADDREF(*aOutChildren = children);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-18 00:37:38 -07:00
|
|
|
PRBool
|
|
|
|
nsAccessible::GetAllowsAnonChildAccessibles()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-06-18 00:37:38 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute long childCount; */
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetChildCount(PRInt32 *aChildCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aChildCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
*aChildCount = GetChildCount();
|
|
|
|
return *aChildCount != -1 ? NS_OK : NS_ERROR_FAILURE;
|
2009-11-19 08:35:38 -08:00
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
/* readonly attribute long indexInParent; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetIndexInParent(PRInt32 *aIndexInParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aIndexInParent);
|
2009-06-18 00:37:38 -07:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
*aIndexInParent = GetIndexInParent();
|
|
|
|
return *aIndexInParent != -1 ? NS_OK : NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return PR_FALSE;
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2009-09-08 22:40:02 -07:00
|
|
|
nsSize frameSize = frame->GetSize();
|
|
|
|
nsRectVisibility rectVisibility =
|
|
|
|
shell->GetRectVisibility(frame, nsRect(nsPoint(0,0), frameSize),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(kMinPixels));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-08 22:40:02 -07:00
|
|
|
if (frame->GetRect().IsEmpty()) {
|
|
|
|
PRBool isEmpty = PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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);
|
2009-09-08 22:40:02 -07:00
|
|
|
isEmpty = renderedText.IsEmpty();
|
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);
|
2009-09-08 22:40:02 -07:00
|
|
|
isEmpty = width == 0 || height == 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-08 22:40:02 -07:00
|
|
|
if (isEmpty && !(frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) {
|
|
|
|
// Consider zero area objects hidden unless they are absolutely positioned
|
|
|
|
// or floating and may have descendants that have a non-zero size
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-04-23 08:41:26 -07:00
|
|
|
}
|
2009-09-08 22:40:02 -07:00
|
|
|
|
|
|
|
// The frame intersects the viewport, but we need to check the parent view chain :(
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIDocument* doc = mContent->GetOwnerDoc();
|
2007-04-23 08:41:26 -07:00
|
|
|
if (!doc) {
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-08 22:40:02 -07:00
|
|
|
nsIFrame* frameWithView =
|
|
|
|
frame->HasView() ? frame : frame->GetAncestorWithViewExternal();
|
|
|
|
nsIView* view = frameWithView->GetViewExternal();
|
|
|
|
PRBool isVisible = CheckVisibilityInParentChain(doc, view);
|
2007-04-23 08:41:26 -07:00
|
|
|
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
|
2008-11-03 19:37:46 -08:00
|
|
|
nsAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState)
|
2007-04-02 08:56:24 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
*aState = 0;
|
|
|
|
|
2008-11-26 20:04:05 -08:00
|
|
|
if (IsDefunct()) {
|
|
|
|
if (aExtraState)
|
2007-11-15 11:53:40 -08:00
|
|
|
*aExtraState = nsIAccessibleStates::EXT_STATE_DEFUNCT;
|
2008-11-26 20:04:05 -08:00
|
|
|
|
|
|
|
return NS_OK_DEFUNCT_OBJECT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-11-15 11:53:40 -08:00
|
|
|
if (aExtraState)
|
|
|
|
*aExtraState = 0;
|
|
|
|
|
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;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->IsHTML()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// In HTML, just the presence of the disabled attribute means it is disabled,
|
|
|
|
// therefore disabled="false" indicates disabled!
|
2010-06-11 01:23:18 -07:00
|
|
|
isDisabled = mContent->HasAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::disabled);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2010-06-11 01:23:18 -07:00
|
|
|
isDisabled = mContent->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::disabled,
|
|
|
|
nsAccessibilityAtoms::_true,
|
|
|
|
eCaseMatters);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (isDisabled) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_UNAVAILABLE;
|
|
|
|
}
|
2010-06-11 01:23:18 -07:00
|
|
|
else if (mContent->IsElement()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (frame && frame->IsFocusable()) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_FOCUSABLE;
|
|
|
|
}
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
if (gLastFocusedNode == mContent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*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;
|
|
|
|
|
2009-08-23 22:13:05 -07:00
|
|
|
// Check if a XUL element has the popup attribute (an attached popup menu).
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->IsXUL())
|
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::popup))
|
2009-08-23 22:13:05 -07:00
|
|
|
*aState |= nsIAccessibleStates::STATE_HASPOPUP;
|
|
|
|
|
2008-03-30 23:21:35 -07:00
|
|
|
// Add 'linked' state for simple xlink.
|
2010-06-11 01:23:18 -07:00
|
|
|
if (nsCoreUtils::IsXLink(mContent))
|
2008-03-30 23:21:35 -07:00
|
|
|
*aState |= nsIAccessibleStates::STATE_LINKED;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute boolean focusedChild; */
|
2010-06-11 01:23:18 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetFocusedChild(nsIAccessible **aFocusedChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccessible *focusedChild = nsnull;
|
|
|
|
if (gLastFocusedNode == mContent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
focusedChild = this;
|
|
|
|
}
|
|
|
|
else if (gLastFocusedNode) {
|
2010-06-11 01:23:18 -07:00
|
|
|
focusedChild = GetAccService()->GetAccessible(gLastFocusedNode);
|
|
|
|
if (focusedChild && focusedChild->GetParent() != this)
|
|
|
|
focusedChild = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aFocusedChild = focusedChild);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-05-11 03:57:28 -07:00
|
|
|
// nsAccessible::GetChildAtPoint()
|
|
|
|
nsresult
|
|
|
|
nsAccessible::GetChildAtPoint(PRInt32 aX, PRInt32 aY, PRBool aDeepestChild,
|
|
|
|
nsIAccessible **aChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-09-18 14:44:43 -07:00
|
|
|
// If we can't find the point in a child, we will return the fallback answer:
|
2009-05-11 03:57:28 -07:00
|
|
|
// we return |this| if the point is within it, otherwise nsnull.
|
|
|
|
PRInt32 x = 0, y = 0, width = 0, height = 0;
|
|
|
|
nsresult rv = GetBounds(&x, &y, &width, &height);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-09-18 14:44:43 -07:00
|
|
|
nsCOMPtr<nsIAccessible> fallbackAnswer;
|
2009-05-11 03:57:28 -07:00
|
|
|
if (aX >= x && aX < x + width && aY >= y && aY < y + height)
|
2007-09-18 14:44:43 -07:00
|
|
|
fallbackAnswer = this;
|
2009-05-11 03:57:28 -07:00
|
|
|
|
2008-10-17 03:10:43 -07:00
|
|
|
if (nsAccUtils::MustPrune(this)) { // Do not dig any further
|
2009-05-11 03:57:28 -07:00
|
|
|
NS_IF_ADDREF(*aChild = fallbackAnswer);
|
2007-09-18 14:44:43 -07:00
|
|
|
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.
|
2010-03-18 11:50:31 -07:00
|
|
|
nsDocAccessible *accDocument = GetDocAccessible();
|
2007-09-18 14:44:43 -07:00
|
|
|
NS_ENSURE_TRUE(accDocument, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-18 11:50:31 -07:00
|
|
|
nsIFrame *frame = accDocument->GetFrame();
|
2007-09-05 01:00:40 -07:00
|
|
|
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);
|
2009-05-11 03:57:28 -07:00
|
|
|
|
|
|
|
nsIContent* content = nsnull;
|
2007-09-18 14:44:43 -07:00
|
|
|
if (!foundFrame || !(content = foundFrame->GetContent())) {
|
2009-05-11 03:57:28 -07:00
|
|
|
NS_IF_ADDREF(*aChild = 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
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsINode *relevantNode = GetAccService()->GetRelevantContentNodeFor(content);
|
2010-05-25 01:40:39 -07:00
|
|
|
nsAccessible *accessible = GetAccService()->GetAccessible(relevantNode);
|
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
|
2010-05-25 01:40:39 -07:00
|
|
|
accessible = GetAccService()->GetContainerAccessible(relevantNode, PR_TRUE);
|
2007-09-18 14:44:43 -07:00
|
|
|
if (!accessible) {
|
2009-05-11 03:57:28 -07:00
|
|
|
NS_IF_ADDREF(*aChild = fallbackAnswer);
|
2007-09-18 14:44:43 -07:00
|
|
|
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) {
|
2009-05-11 03:57:28 -07:00
|
|
|
// Manually walk through accessible children and see if the are within this
|
|
|
|
// point. Skip offscreen or invisible accessibles. This takes care of cases
|
|
|
|
// where layout won't walk into things for us, such as image map areas and
|
|
|
|
// sub documents (XXX: subdocuments should be handled by methods of
|
|
|
|
// nsOuterDocAccessibles).
|
2010-04-19 06:39:57 -07:00
|
|
|
PRInt32 childCount = GetChildCount();
|
|
|
|
for (PRInt32 childIdx = 0; childIdx < childCount; childIdx++) {
|
|
|
|
nsAccessible *child = GetChildAt(childIdx);
|
|
|
|
|
2007-09-18 14:44:43 -07:00
|
|
|
PRInt32 childX, childY, childWidth, childHeight;
|
|
|
|
child->GetBounds(&childX, &childY, &childWidth, &childHeight);
|
|
|
|
if (aX >= childX && aX < childX + childWidth &&
|
|
|
|
aY >= childY && aY < childY + childHeight &&
|
2008-10-17 03:10:43 -07:00
|
|
|
(nsAccUtils::State(child) & nsIAccessibleStates::STATE_INVISIBLE) == 0) {
|
2009-05-11 03:57:28 -07:00
|
|
|
|
|
|
|
if (aDeepestChild)
|
|
|
|
return child->GetDeepestChildAtPoint(aX, aY, aChild);
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aChild = child);
|
2007-09-18 14:44:43 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2008-09-17 06:11:39 -07:00
|
|
|
|
2009-05-11 03:57:28 -07:00
|
|
|
// The point is in this accessible but not in a child. We are allowed to
|
|
|
|
// return |this| as the answer.
|
|
|
|
NS_IF_ADDREF(*aChild = accessible);
|
2008-09-17 06:11:39 -07:00
|
|
|
return NS_OK;
|
2009-05-11 03:57:28 -07:00
|
|
|
}
|
2008-09-17 06:11:39 -07:00
|
|
|
|
2009-05-11 03:57:28 -07:00
|
|
|
// Since DOM node of obtained accessible may be out of flow then we should
|
|
|
|
// ensure obtained accessible is a child of this accessible.
|
|
|
|
nsCOMPtr<nsIAccessible> parent, child(accessible);
|
2008-09-17 06:11:39 -07:00
|
|
|
while (PR_TRUE) {
|
2009-05-11 03:57:28 -07:00
|
|
|
child->GetParent(getter_AddRefs(parent));
|
2008-09-17 06:11:39 -07:00
|
|
|
if (!parent) {
|
|
|
|
// Reached the top of the hierarchy. These bounds were inside an
|
|
|
|
// accessible that is not a descendant of this one.
|
2009-05-11 03:57:28 -07:00
|
|
|
NS_IF_ADDREF(*aChild = fallbackAnswer);
|
2008-09-17 06:11:39 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent == this) {
|
2009-05-11 03:57:28 -07:00
|
|
|
NS_ADDREF(*aChild = (aDeepestChild ? accessible : child));
|
2008-09-17 06:11:39 -07:00
|
|
|
return NS_OK;
|
2007-09-18 14:44:43 -07:00
|
|
|
}
|
2009-05-11 03:57:28 -07:00
|
|
|
child.swap(parent);
|
2007-09-18 14:44:43 -07:00
|
|
|
}
|
2007-09-05 01:00:40 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-05-11 03:57:28 -07:00
|
|
|
// nsIAccessible getChildAtPoint(in long x, in long y)
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetChildAtPoint(PRInt32 aX, PRInt32 aY,
|
|
|
|
nsIAccessible **aAccessible)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aAccessible);
|
|
|
|
*aAccessible = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return GetChildAtPoint(aX, aY, PR_FALSE, aAccessible);
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIAccessible getDeepestChildAtPoint(in long x, in long y)
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetDeepestChildAtPoint(PRInt32 aX, PRInt32 aY,
|
|
|
|
nsIAccessible **aAccessible)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aAccessible);
|
|
|
|
*aAccessible = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return GetChildAtPoint(aX, aY, PR_TRUE, aAccessible);
|
|
|
|
}
|
|
|
|
|
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
|
2008-10-17 03:10:43 -07:00
|
|
|
if (!nsCoreUtils::IsCorrectFrameType(ancestorFrame,
|
|
|
|
nsAccessibilityAtoms::inlineFrame) &&
|
|
|
|
!nsCoreUtils::IsCorrectFrameType(ancestorFrame,
|
|
|
|
nsAccessibilityAtoms::textFrame))
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
ancestorFrame = ancestorFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *iterFrame = firstFrame;
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIContent> firstContent(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
|
2008-10-17 03:10:43 -07:00
|
|
|
if (nsCoreUtils::IsCorrectFrameType(iterFrame,
|
|
|
|
nsAccessibilityAtoms::inlineFrame)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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
|
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect orgRectPixels = aBoundingFrame->GetScreenRectExternal();
|
2007-03-22 10:30:00 -07:00
|
|
|
*x += orgRectPixels.x;
|
|
|
|
*y += orgRectPixels.y;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// helpers
|
|
|
|
|
|
|
|
nsIFrame* nsAccessible::GetBoundsFrame()
|
|
|
|
{
|
|
|
|
return GetFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void removeSelection (); */
|
|
|
|
NS_IMETHODIMP nsAccessible::SetSelected(PRBool aSelect)
|
|
|
|
{
|
|
|
|
// Add or remove selection
|
2010-06-11 01:23:18 -07:00
|
|
|
if (IsDefunct())
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2008-10-17 03:10:43 -07:00
|
|
|
PRUint32 state = nsAccUtils::State(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (state & nsIAccessibleStates::STATE_SELECTABLE) {
|
2008-10-17 03:10:43 -07:00
|
|
|
nsCOMPtr<nsIAccessible> multiSelect =
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccUtils::GetMultiSelectableContainer(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!multiSelect) {
|
|
|
|
return aSelect ? TakeFocus() : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-09-24 18:19:03 -07:00
|
|
|
if (mRoleMapEntry) {
|
2007-12-11 18:10:26 -08:00
|
|
|
if (aSelect) {
|
2010-06-11 01:23:18 -07:00
|
|
|
return mContent->SetAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::aria_selected,
|
|
|
|
NS_LITERAL_STRING("true"), PR_TRUE);
|
2007-09-24 18:19:03 -07:00
|
|
|
}
|
2010-06-11 01:23:18 -07:00
|
|
|
return mContent->UnsetAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::aria_selected, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void takeSelection (); */
|
|
|
|
NS_IMETHODIMP nsAccessible::TakeSelection()
|
|
|
|
{
|
|
|
|
// Select only this item
|
2010-06-11 01:23:18 -07:00
|
|
|
if (IsDefunct())
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2008-10-17 03:10:43 -07:00
|
|
|
PRUint32 state = nsAccUtils::State(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (state & nsIAccessibleStates::STATE_SELECTABLE) {
|
2008-10-17 03:10:43 -07:00
|
|
|
nsCOMPtr<nsIAccessible> multiSelect =
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccUtils::GetMultiSelectableContainer(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
NS_ENSURE_STATE(frame);
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent* focusContent = mContent;
|
|
|
|
|
2008-04-22 23:04:53 -07:00
|
|
|
// 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;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (nsCoreUtils::GetID(mContent, id)) {
|
2008-04-22 23:04:53 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent* ancestorContent = mContent;
|
2008-04-22 23:04:53 -07:00
|
|
|
while ((ancestorContent = ancestorContent->GetParent()) &&
|
|
|
|
!ancestorContent->HasAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::aria_activedescendant));
|
|
|
|
|
|
|
|
if (ancestorContent) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
|
|
|
|
if (presShell) {
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame *frame = ancestorContent->GetPrimaryFrame();
|
2008-04-22 23:04:53 -07:00
|
|
|
if (frame && frame->IsFocusable()) {
|
2010-06-11 01:23:18 -07:00
|
|
|
focusContent = ancestorContent;
|
|
|
|
focusContent->SetAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::aria_activedescendant,
|
|
|
|
id, PR_TRUE);
|
2008-04-22 23:04:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(focusContent));
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
|
|
|
|
if (fm)
|
|
|
|
fm->SetFocus(element, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-12-02 23:18:41 -08:00
|
|
|
nsresult
|
|
|
|
nsAccessible::GetHTMLName(nsAString& aLabel)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent *labelContent = nsCoreUtils::GetHTMLLabelContent(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (labelContent) {
|
2008-10-10 05:26:55 -07:00
|
|
|
nsAutoString label;
|
2009-02-18 23:06:14 -08:00
|
|
|
nsresult rv =
|
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, labelContent, &label);
|
2008-10-13 01:58:58 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
label.CompressWhitespace();
|
|
|
|
if (!label.IsEmpty()) {
|
|
|
|
aLabel = label;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-18 23:06:14 -08:00
|
|
|
return nsTextEquivUtils::GetNameFromSubtree(this, aLabel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-12-02 23:18:41 -08:00
|
|
|
nsresult
|
|
|
|
nsAccessible::GetXULName(nsAString& aLabel)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-10 05:26:55 -07:00
|
|
|
// CASE #1 (via label attribute) -- great majority of the cases
|
|
|
|
nsresult rv = NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString label;
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULLabeledControlElement> labeledEl(do_QueryInterface(mContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (labeledEl) {
|
|
|
|
rv = labeledEl->GetLabel(label);
|
|
|
|
}
|
|
|
|
else {
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> itemEl(do_QueryInterface(mContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (itemEl) {
|
|
|
|
rv = itemEl->GetLabel(label);
|
|
|
|
}
|
|
|
|
else {
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlElement> select(do_QueryInterface(mContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
// Use label if this is not a select control element which
|
|
|
|
// uses label attribute to indicate which option is selected
|
|
|
|
if (!select) {
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULElement> xulEl(do_QueryInterface(mContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
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 =
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCoreUtils::FindNeighbourPointingToNode(mContent,
|
|
|
|
nsAccessibilityAtoms::control,
|
2008-10-15 18:52:58 -07:00
|
|
|
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
|
2008-10-01 23:49:45 -07:00
|
|
|
// children that define its text -- possibly using HTML
|
2009-02-18 23:06:14 -08:00
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, labelContent, &label);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX If CompressWhiteSpace worked on nsAString we could avoid a copy
|
|
|
|
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>
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent *bindingParent = mContent->GetBindingParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent *parent = bindingParent? bindingParent->GetParent() :
|
2010-06-11 01:23:18 -07:00
|
|
|
mContent->GetParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (parent) {
|
|
|
|
if (parent->Tag() == nsAccessibilityAtoms::toolbaritem &&
|
|
|
|
parent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::title, label)) {
|
|
|
|
label.CompressWhitespace();
|
|
|
|
aLabel = label;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
2009-02-18 23:06:14 -08:00
|
|
|
return nsTextEquivUtils::GetNameFromSubtree(this, aLabel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-06-18 00:37:38 -07:00
|
|
|
nsresult
|
2010-01-18 20:23:44 -08:00
|
|
|
nsAccessible::HandleAccEvent(nsAccEvent *aEvent)
|
2007-04-12 23:03:30 -07:00
|
|
|
{
|
2007-04-24 11:20:52 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aEvent);
|
2010-06-11 01:23:18 -07:00
|
|
|
NS_ENSURE_TRUE(nsAccUtils::IsNodeRelevant(aEvent->GetNode()),
|
|
|
|
NS_ERROR_FAILURE);
|
2007-04-24 11:20:52 -07:00
|
|
|
|
2007-04-12 23:03:30 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
mozilla::services::GetObserverService();
|
2007-04-12 23:03:30 -07:00
|
|
|
NS_ENSURE_TRUE(obsService, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return obsService->NotifyObservers(aEvent, NS_ACCESSIBLE_EVENT_TOPIC, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-03-07 07:38:58 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetRole(PRUint32 *aRole)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-20 20:26:48 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aRole);
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_NOTHING;
|
|
|
|
|
2009-06-11 11:18:24 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
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) {
|
2010-06-11 01:23:18 -07:00
|
|
|
|
|
|
|
if (nsAccUtils::HasDefinedARIAToken(mContent,
|
|
|
|
nsAccessibilityAtoms::aria_pressed)) {
|
|
|
|
// For simplicity, any existing pressed attribute except "", or "undefined"
|
|
|
|
// indicates a toggle.
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_TOGGLE_BUTTON;
|
|
|
|
|
|
|
|
} else if (mContent->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::aria_haspopup,
|
|
|
|
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));
|
2008-10-17 03:10:43 -07:00
|
|
|
if (nsAccUtils::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
|
2009-02-10 02:03:30 -08:00
|
|
|
possibleCombo = nsRelUtils::
|
|
|
|
GetRelatedAccessible(this, nsIAccessibleRelation::RELATION_NODE_CHILD_OF);
|
2008-10-17 03:10:43 -07:00
|
|
|
if (nsAccUtils::Role(possibleCombo) == nsIAccessibleRole::ROLE_COMBOBOX)
|
2008-03-13 10:39:18 -07:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_COMBOBOX_LIST;
|
|
|
|
}
|
2007-11-15 11:46:29 -08:00
|
|
|
}
|
|
|
|
else if (*aRole == nsIAccessibleRole::ROLE_OPTION) {
|
2010-06-11 01:23:18 -07:00
|
|
|
if (nsAccUtils::Role(GetParent()) == nsIAccessibleRole::ROLE_COMBOBOX_LIST)
|
2007-11-15 11:46:29 -08:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_COMBOBOX_OPTION;
|
|
|
|
}
|
|
|
|
|
2009-06-11 11:18:24 -07:00
|
|
|
// We are done if the mapped role trumps native semantics
|
|
|
|
if (mRoleMapEntry->roleRule == kUseMapRole)
|
2008-02-06 20:14:59 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-03-07 07:38:58 -08:00
|
|
|
|
2009-06-11 11:18:24 -07:00
|
|
|
return GetRoleInternal(aRole);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
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;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (nsCoreUtils::GetID(mContent, 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;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::role, xmlRoles)) {
|
2007-12-11 18:10:26 -08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-02-20 23:43:51 -08:00
|
|
|
// Expose checkable object attribute if the accessible has checkable state
|
|
|
|
if (nsAccUtils::State(this) & nsIAccessibleStates::STATE_CHECKABLE)
|
|
|
|
nsAccUtils::SetAccAttr(attributes, nsAccessibilityAtoms::checkable, NS_LITERAL_STRING("true"));
|
2008-03-13 10:39:18 -07:00
|
|
|
|
2009-01-04 23:41:30 -08:00
|
|
|
// Group attributes (level/setsize/posinset)
|
2010-01-06 02:36:50 -08:00
|
|
|
PRInt32 level = 0, posInSet = 0, setSize = 0;
|
|
|
|
rv = GroupPosition(&level, &setSize, &posInSet);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
nsAccUtils::SetAccGroupAttrs(attributes, level, setSize, posInSet);
|
2007-04-07 02:07:24 -07:00
|
|
|
|
2009-02-18 22:56:19 -08:00
|
|
|
// Expose object attributes from ARIA attributes.
|
2010-06-11 01:23:18 -07:00
|
|
|
PRUint32 numAttrs = mContent->GetAttrCount();
|
2008-03-13 10:39:18 -07:00
|
|
|
for (PRUint32 count = 0; count < numAttrs; count ++) {
|
2010-06-11 01:23:18 -07:00
|
|
|
const nsAttrName *attr = mContent->GetAttrNameAt(count);
|
2008-03-13 10:39:18 -07:00
|
|
|
if (attr && attr->NamespaceEquals(kNameSpaceID_None)) {
|
|
|
|
nsIAtom *attrAtom = attr->Atom();
|
2010-03-08 07:45:00 -08:00
|
|
|
nsDependentAtomString attrStr(attrAtom);
|
|
|
|
if (!StringBeginsWith(attrStr, NS_LITERAL_STRING("aria-")))
|
2008-03-13 10:39:18 -07:00
|
|
|
continue; // Not ARIA
|
2009-02-15 00:15:31 -08:00
|
|
|
PRUint8 attrFlags = nsAccUtils::GetAttributeCharacteristics(attrAtom);
|
2009-03-10 13:44:43 -07:00
|
|
|
if (attrFlags & ATTR_BYPASSOBJ)
|
|
|
|
continue; // No need to handle exposing as obj attribute here
|
2009-02-15 00:15:31 -08:00
|
|
|
if ((attrFlags & ATTR_VALTOKEN) &&
|
2010-06-11 01:23:18 -07:00
|
|
|
!nsAccUtils::HasDefinedARIAToken(mContent, attrAtom))
|
2009-02-15 00:15:31 -08:00
|
|
|
continue; // only expose token based attributes if they are defined
|
2008-03-13 10:39:18 -07:00
|
|
|
nsAutoString value;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, attrAtom, value)) {
|
2010-03-08 07:45:00 -08:00
|
|
|
attributes->SetStringProperty(NS_ConvertUTF16toUTF8(Substring(attrStr, 5)), value, oldValueUnused);
|
2008-03-13 10:39:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-18 22:56:19 -08:00
|
|
|
// If there is no aria-live attribute then expose default value of 'live'
|
|
|
|
// object attribute used for ARIA role of this accessible.
|
|
|
|
if (mRoleMapEntry) {
|
|
|
|
nsAutoString live;
|
|
|
|
nsAccUtils::GetAccAttr(attributes, nsAccessibilityAtoms::live, live);
|
|
|
|
if (live.IsEmpty()) {
|
2009-08-27 22:27:27 -07:00
|
|
|
if (nsAccUtils::GetLiveAttrValue(mRoleMapEntry->liveAttRule, live))
|
|
|
|
nsAccUtils::SetAccAttr(attributes, nsAccessibilityAtoms::live, live);
|
2009-02-18 22:56:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mContent));
|
2007-04-07 02:07:24 -07:00
|
|
|
|
|
|
|
nsAutoString tagName;
|
|
|
|
element->GetTagName(tagName);
|
|
|
|
if (!tagName.IsEmpty()) {
|
|
|
|
nsAutoString oldValueUnused;
|
|
|
|
aAttributes->SetStringProperty(NS_LITERAL_CSTRING("tag"), tagName,
|
|
|
|
oldValueUnused);
|
|
|
|
}
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsEventShell::GetEventAttributes(GetNode(), aAttributes);
|
2008-03-14 13:49:38 -07:00
|
|
|
|
|
|
|
// 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;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::_class, _class))
|
2008-10-16 02:12:05 -07:00
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::_class, _class);
|
2008-03-14 13:49:38 -07:00
|
|
|
|
|
|
|
// 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
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent *startContent = mContent;
|
2008-03-14 13:49:38 -07:00
|
|
|
while (PR_TRUE) {
|
|
|
|
NS_ENSURE_STATE(startContent);
|
|
|
|
nsIDocument *doc = startContent->GetDocument();
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent* rootContent = nsCoreUtils::GetRoleContent(doc);
|
|
|
|
NS_ENSURE_STATE(rootContent);
|
2008-10-16 02:12:05 -07:00
|
|
|
nsAccUtils::SetLiveContainerAttributes(aAttributes, startContent,
|
2010-06-11 01:23:18 -07:00
|
|
|
rootContent);
|
2008-10-31 20:58:07 -07:00
|
|
|
|
2008-03-14 13:49:38 -07:00
|
|
|
// Allow ARIA live region markup from outer documents to override
|
2008-10-31 20:58:07 -07:00
|
|
|
nsCOMPtr<nsISupports> container = doc->GetContainer();
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
|
|
|
|
do_QueryInterface(container);
|
2008-03-19 18:55:26 -07:00
|
|
|
if (!docShellTreeItem)
|
|
|
|
break;
|
2008-10-31 20:58:07 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> sameTypeParent;
|
|
|
|
docShellTreeItem->GetSameTypeParent(getter_AddRefs(sameTypeParent));
|
2008-03-14 13:49:38 -07:00
|
|
|
if (!sameTypeParent || sameTypeParent == docShellTreeItem)
|
|
|
|
break;
|
2008-10-31 20:58:07 -07:00
|
|
|
|
2008-03-14 13:49:38 -07:00
|
|
|
nsIDocument *parentDoc = doc->GetParentDocument();
|
2008-03-20 19:34:29 -07:00
|
|
|
if (!parentDoc)
|
|
|
|
break;
|
2008-10-31 20:58:07 -07:00
|
|
|
|
2008-03-14 13:49:38 -07:00
|
|
|
startContent = parentDoc->FindContentForSubDocument(doc);
|
|
|
|
}
|
|
|
|
|
2008-07-02 21:12:45 -07:00
|
|
|
// Expose 'display' attribute.
|
2008-10-28 04:54:57 -07:00
|
|
|
nsAutoString value;
|
2008-07-02 21:12:45 -07:00
|
|
|
nsresult rv = GetComputedStyleValue(EmptyString(),
|
|
|
|
NS_LITERAL_STRING("display"),
|
2008-10-28 04:54:57 -07:00
|
|
|
value);
|
2008-07-02 21:12:45 -07:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2008-10-16 02:12:05 -07:00
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::display,
|
2008-10-28 04:54:57 -07:00
|
|
|
value);
|
|
|
|
|
|
|
|
// Expose 'text-align' attribute.
|
|
|
|
rv = GetComputedStyleValue(EmptyString(), NS_LITERAL_STRING("text-align"),
|
|
|
|
value);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::textAlign,
|
|
|
|
value);
|
|
|
|
|
|
|
|
// Expose 'text-indent' attribute.
|
|
|
|
rv = GetComputedStyleValue(EmptyString(), NS_LITERAL_STRING("text-indent"),
|
|
|
|
value);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::textIndent,
|
|
|
|
value);
|
|
|
|
|
2009-06-19 11:23:44 -07:00
|
|
|
// Expose draggable object attribute?
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMNSHTMLElement> htmlElement = do_QueryInterface(mContent);
|
2009-06-19 11:23:44 -07:00
|
|
|
if (htmlElement) {
|
|
|
|
PRBool draggable = PR_FALSE;
|
|
|
|
htmlElement->GetDraggable(&draggable);
|
|
|
|
if (draggable) {
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::draggable,
|
|
|
|
NS_LITERAL_STRING("true"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aGroupLevel);
|
|
|
|
*aGroupLevel = 0;
|
2010-01-06 02:36:50 -08:00
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aSimilarItemsInGroup);
|
2007-03-27 05:17:11 -07:00
|
|
|
*aSimilarItemsInGroup = 0;
|
2010-01-06 02:36:50 -08:00
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aPositionInGroup);
|
2007-03-27 05:17:11 -07:00
|
|
|
*aPositionInGroup = 0;
|
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
if (IsDefunct())
|
2007-04-24 08:42:33 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-01-06 02:36:50 -08:00
|
|
|
|
|
|
|
// Get group position from ARIA attributes.
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCoreUtils::GetUIntAttr(mContent, nsAccessibilityAtoms::aria_level,
|
2010-01-12 11:07:38 -08:00
|
|
|
aGroupLevel);
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCoreUtils::GetUIntAttr(mContent, nsAccessibilityAtoms::aria_posinset,
|
2010-01-12 11:07:38 -08:00
|
|
|
aPositionInGroup);
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCoreUtils::GetUIntAttr(mContent, nsAccessibilityAtoms::aria_setsize,
|
2010-01-12 11:07:38 -08:00
|
|
|
aSimilarItemsInGroup);
|
2010-01-06 02:36:50 -08:00
|
|
|
|
|
|
|
// If ARIA is missed and the accessible is visible then calculate group
|
|
|
|
// position from hierarchy.
|
|
|
|
if (nsAccUtils::State(this) & nsIAccessibleStates::STATE_INVISIBLE)
|
2007-03-27 05:17:11 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
// Calculate group level if ARIA is missed.
|
|
|
|
if (*aGroupLevel == 0) {
|
|
|
|
PRInt32 level = GetLevelInternal();
|
|
|
|
if (level != 0)
|
|
|
|
*aGroupLevel = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate position in group and group size if ARIA is missed.
|
|
|
|
if (*aSimilarItemsInGroup == 0 || *aPositionInGroup == 0) {
|
|
|
|
PRInt32 posInSet = 0, setSize = 0;
|
|
|
|
GetPositionAndSizeInternal(&posInSet, &setSize);
|
|
|
|
if (posInSet != 0 && setSize != 0) {
|
|
|
|
if (*aPositionInGroup == 0)
|
|
|
|
*aPositionInGroup = posInSet;
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
if (*aSimilarItemsInGroup == 0)
|
|
|
|
*aSimilarItemsInGroup = setSize;
|
|
|
|
}
|
|
|
|
}
|
2007-03-27 05:17:11 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-02 08:56:24 -07:00
|
|
|
NS_IMETHODIMP
|
2008-11-03 19:37:46 -08:00
|
|
|
nsAccessible::GetState(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);
|
|
|
|
|
2009-06-22 11:28:20 -07:00
|
|
|
if (!IsDefunct()) {
|
|
|
|
// Flush layout so that all the frame construction, reflow, and styles are
|
|
|
|
// up-to-date since we rely on frames, and styles when calculating state.
|
|
|
|
// We don't flush the display because we don't care about painting.
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
|
|
|
|
presShell->FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
|
|
|
|
2008-11-03 19:37:46 -08:00
|
|
|
nsresult rv = GetStateInternal(aState, aExtraState);
|
2008-11-26 20:04:05 -08:00
|
|
|
NS_ENSURE_A11Y_SUCCESS(rv, rv);
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2007-08-08 06:46:38 -07:00
|
|
|
// Apply ARIA states to be sure accessible states will be overriden.
|
2009-06-24 19:12:38 -07:00
|
|
|
GetARIAState(aState, aExtraState);
|
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.
|
2009-02-10 02:03:30 -08:00
|
|
|
nsCOMPtr<nsIAccessible> tabPanel = nsRelUtils::
|
|
|
|
GetRelatedAccessible(this, nsIAccessibleRelation::RELATION_LABEL_FOR);
|
2007-10-03 02:31:41 -07:00
|
|
|
|
2008-10-17 03:10:43 -07:00
|
|
|
if (nsAccUtils::Role(tabPanel) == nsIAccessibleRole::ROLE_PROPERTYPAGE) {
|
2010-06-11 01:23:18 -07:00
|
|
|
nsRefPtr<nsAccessible> tabPanelAcc(do_QueryObject(tabPanel));
|
|
|
|
nsINode *tabPanelNode = tabPanelAcc->GetNode();
|
|
|
|
if (nsCoreUtils::IsAncestorOf(tabPanelNode, gLastFocusedNode))
|
2007-10-03 02:31:41 -07:00
|
|
|
*aState |= nsIAccessibleStates::STATE_SELECTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-07 22:27:24 -07:00
|
|
|
const PRUint32 kExpandCollapseStates =
|
|
|
|
nsIAccessibleStates::STATE_COLLAPSED | nsIAccessibleStates::STATE_EXPANDED;
|
|
|
|
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.
|
|
|
|
*aState &= ~nsIAccessibleStates::STATE_COLLAPSED;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-10-07 22:27:24 -07:00
|
|
|
if ((*aState & nsIAccessibleStates::STATE_COLLAPSED) ||
|
|
|
|
(*aState & nsIAccessibleStates::STATE_EXPANDED))
|
2007-09-20 19:58:29 -07:00
|
|
|
*aExtraState |= nsIAccessibleStates::EXT_STATE_EXPANDABLE;
|
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.
|
|
|
|
nsAutoString id;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (nsCoreUtils::GetID(mContent, id)) {
|
|
|
|
nsIContent *ancestorContent = mContent;
|
2007-12-10 19:30:02 -08:00
|
|
|
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;
|
2009-03-07 07:38:58 -08:00
|
|
|
rv = GetRole(&role);
|
2007-09-20 19:58:29 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 08:16:38 -08:00
|
|
|
|
|
|
|
// If we are editable, force readonly bit off
|
|
|
|
if (*aExtraState & nsIAccessibleStates::EXT_STATE_EDITABLE)
|
|
|
|
*aState &= ~nsIAccessibleStates::STATE_READONLY;
|
|
|
|
|
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
|
2009-06-24 19:12:38 -07:00
|
|
|
nsAccessible::GetARIAState(PRUint32 *aState, PRUint32 *aExtraState)
|
2007-04-02 08:56:24 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
// Test for universal states first
|
2007-06-05 08:41:07 -07:00
|
|
|
PRUint32 index = 0;
|
2010-06-11 01:23:18 -07:00
|
|
|
while (nsStateMapEntry::MapToStates(mContent, aState, aExtraState,
|
2009-06-24 19:12:38 -07:00
|
|
|
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) {
|
2009-08-31 06:12:08 -07:00
|
|
|
|
|
|
|
// We only force the readonly bit off if we have a real mapping for the aria
|
|
|
|
// role. This preserves the ability for screen readers to use readonly
|
|
|
|
// (primarily on the document) as the hint for creating a virtual buffer.
|
|
|
|
if (mRoleMapEntry->role != nsIAccessibleRole::ROLE_NOTHING)
|
|
|
|
*aState &= ~nsIAccessibleStates::STATE_READONLY;
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, mContent->GetIDAttributeName())) {
|
2008-06-15 22:45:58 -07:00
|
|
|
// If has a role & ID and aria-activedescendant on the container, assume focusable
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent *ancestorContent = mContent;
|
2008-06-15 22:45:58 -07:00
|
|
|
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
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent *ancestorContent = mContent;
|
2008-03-29 15:04:04 -07:00
|
|
|
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;
|
|
|
|
|
2009-02-17 08:16:38 -08:00
|
|
|
// Note: the readonly bitflag will be overridden later if content is editable
|
2008-03-29 14:52:14 -07:00
|
|
|
*aState |= mRoleMapEntry->state;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (nsStateMapEntry::MapToStates(mContent, aState, aExtraState,
|
2009-06-24 19:12:38 -07:00
|
|
|
mRoleMapEntry->attributeMap1) &&
|
2010-06-11 01:23:18 -07:00
|
|
|
nsStateMapEntry::MapToStates(mContent, aState, aExtraState,
|
2009-06-24 19:12:38 -07:00
|
|
|
mRoleMapEntry->attributeMap2)) {
|
2010-06-11 01:23:18 -07:00
|
|
|
nsStateMapEntry::MapToStates(mContent, aState, aExtraState,
|
2009-06-24 19:12:38 -07:00
|
|
|
mRoleMapEntry->attributeMap3);
|
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;
|
|
|
|
|
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
|
2010-06-11 01:23:18 -07:00
|
|
|
if (!mContent->GetAttr(kNameSpaceID_None,
|
|
|
|
nsAccessibilityAtoms::aria_valuetext, aValue)) {
|
|
|
|
mContent->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;
|
|
|
|
|
2008-10-01 23:49:45 -07:00
|
|
|
// Check if it's a simple xlink.
|
2010-06-11 01:23:18 -07:00
|
|
|
if (nsCoreUtils::IsXLink(mContent)) {
|
2008-03-30 23:21:35 -07:00
|
|
|
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
|
2010-06-11 01:23:18 -07:00
|
|
|
if (presShell) {
|
|
|
|
nsCOMPtr<nsIDOMNode> DOMNode(do_QueryInterface(mContent));
|
|
|
|
return presShell->GetLinkLocation(DOMNode, aValue);
|
|
|
|
}
|
2008-03-30 23:21:35 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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;
|
|
|
|
|
2008-10-17 03:10:43 -07:00
|
|
|
if (nsAccUtils::State(this) & kValueCannotChange)
|
2007-08-03 22:27:27 -07:00
|
|
|
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;
|
|
|
|
|
|
|
|
nsAutoString newValue;
|
|
|
|
newValue.AppendFloat(aValue);
|
2010-06-11 01:23:18 -07:00
|
|
|
return mContent->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 (); */
|
2009-03-07 07:38:58 -08:00
|
|
|
nsresult
|
|
|
|
nsAccessible::GetRoleInternal(PRUint32 *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;
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
if (nsCoreUtils::IsXLink(mContent))
|
2008-03-30 23:21:35 -07:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_LINK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
// readonly attribute PRUint8 numActions
|
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-10-17 03:10:43 -07:00
|
|
|
PRUint32 actionRule = GetActionRule(nsAccUtils::State(this));
|
2008-10-08 05:54:58 -07:00
|
|
|
if (actionRule == eNoAction)
|
2008-06-11 01:27:25 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
*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-10-17 03:10:43 -07:00
|
|
|
PRUint32 states = nsAccUtils::State(this);
|
2008-10-08 05:54:58 -07:00
|
|
|
PRUint32 actionRule = GetActionRule(states);
|
2008-03-30 23:21:35 -07:00
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
switch (actionRule) {
|
|
|
|
case eActivateAction:
|
|
|
|
aName.AssignLiteral("activate");
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eClickAction:
|
|
|
|
aName.AssignLiteral("click");
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eCheckUncheckAction:
|
2009-03-09 23:03:21 -07:00
|
|
|
if (states & nsIAccessibleStates::STATE_CHECKED)
|
2008-10-08 05:54:58 -07:00
|
|
|
aName.AssignLiteral("uncheck");
|
2009-03-09 23:03:21 -07:00
|
|
|
else if (states & nsIAccessibleStates::STATE_MIXED)
|
|
|
|
aName.AssignLiteral("cycle");
|
2008-10-08 05:54:58 -07:00
|
|
|
else
|
|
|
|
aName.AssignLiteral("check");
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eJumpAction:
|
|
|
|
aName.AssignLiteral("jump");
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eOpenCloseAction:
|
|
|
|
if (states & nsIAccessibleStates::STATE_COLLAPSED)
|
|
|
|
aName.AssignLiteral("open");
|
|
|
|
else
|
|
|
|
aName.AssignLiteral("close");
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eSelectAction:
|
|
|
|
aName.AssignLiteral("select");
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eSwitchAction:
|
|
|
|
aName.AssignLiteral("switch");
|
|
|
|
return NS_OK;
|
2009-04-19 23:06:19 -07:00
|
|
|
|
|
|
|
case eSortAction:
|
|
|
|
aName.AssignLiteral("sort");
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eExpandAction:
|
|
|
|
if (states & nsIAccessibleStates::STATE_COLLAPSED)
|
|
|
|
aName.AssignLiteral("expand");
|
|
|
|
else
|
|
|
|
aName.AssignLiteral("collapse");
|
|
|
|
return NS_OK;
|
2008-03-15 18:23:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
// AString 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);
|
|
|
|
}
|
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
// 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-10-17 03:10:43 -07:00
|
|
|
if (GetActionRule(nsAccUtils::State(this)) != eNoAction) {
|
2010-01-25 07:09:25 -08:00
|
|
|
DoCommand();
|
|
|
|
return NS_OK;
|
2008-10-08 05:54:58 -07:00
|
|
|
}
|
2008-03-15 18:23:41 -07:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent *loopContent = mContent;
|
2007-09-18 14:40:04 -07:00
|
|
|
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
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
// nsIAccessible getRelationByType()
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::GetRelationByType(PRUint32 aRelationType,
|
|
|
|
nsIAccessibleRelation **aRelation)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-10 02:03:30 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aRelation);
|
|
|
|
*aRelation = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Relationships are defined on the same content node that the role would be
|
|
|
|
// defined on.
|
|
|
|
nsresult rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (aRelationType)
|
|
|
|
{
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_LABEL_FOR:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->Tag() == nsAccessibilityAtoms::label) {
|
|
|
|
nsIAtom *IDAttr = mContent->IsHTML() ?
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAccessibilityAtoms::_for : nsAccessibilityAtoms::control;
|
2009-02-10 02:03:30 -08:00
|
|
|
rv = nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromIDRefAttr(aRelationType, aRelation, mContent, IDAttr);
|
2009-02-10 02:03:30 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (rv != NS_OK_NO_RELATION_TARGET)
|
|
|
|
return NS_OK; // XXX bug 381599, avoid performance problems
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
|
|
|
return nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromNeighbour(aRelationType, aRelation, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
nsAccessibilityAtoms::aria_labelledby);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_LABELLED_BY:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-10 02:03:30 -08:00
|
|
|
rv = nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromIDRefsAttr(aRelationType, aRelation, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
nsAccessibilityAtoms::aria_labelledby);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (rv != NS_OK_NO_RELATION_TARGET)
|
|
|
|
return NS_OK; // XXX bug 381599, avoid performance problems
|
|
|
|
|
|
|
|
return nsRelUtils::
|
|
|
|
AddTargetFromContent(aRelationType, aRelation,
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCoreUtils::GetLabelContent(mContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_DESCRIBED_BY:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-10 02:03:30 -08:00
|
|
|
rv = nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromIDRefsAttr(aRelationType, aRelation, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
nsAccessibilityAtoms::aria_describedby);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (rv != NS_OK_NO_RELATION_TARGET)
|
|
|
|
return NS_OK; // XXX bug 381599, avoid performance problems
|
|
|
|
|
|
|
|
return nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromNeighbour(aRelationType, aRelation, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
nsAccessibilityAtoms::control,
|
|
|
|
nsAccessibilityAtoms::description);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_DESCRIPTION_FOR:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-10 02:03:30 -08:00
|
|
|
rv = nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromNeighbour(aRelationType, aRelation, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
nsAccessibilityAtoms::aria_describedby);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
if (rv != NS_OK_NO_RELATION_TARGET)
|
|
|
|
return NS_OK; // XXX bug 381599, avoid performance problems
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->Tag() == nsAccessibilityAtoms::description &&
|
|
|
|
mContent->IsXUL()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// This affectively adds an optional control attribute to xul:description,
|
|
|
|
// which only affects accessibility, by allowing the description to be
|
|
|
|
// tied to a control.
|
2009-02-10 02:03:30 -08:00
|
|
|
return nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromIDRefAttr(aRelationType, aRelation, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
nsAccessibilityAtoms::control);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_NODE_CHILD_OF:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-10 02:03:30 -08:00
|
|
|
rv = nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromNeighbour(aRelationType, aRelation, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
nsAccessibilityAtoms::aria_owns);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (rv != NS_OK_NO_RELATION_TARGET)
|
|
|
|
return NS_OK; // XXX bug 381599, avoid performance problems
|
|
|
|
|
2009-10-20 00:53:49 -07:00
|
|
|
// This is an ARIA tree or treegrid that doesn't use owns, so we need to
|
|
|
|
// get the parent the hard way.
|
2009-02-10 02:03:30 -08:00
|
|
|
if (mRoleMapEntry &&
|
2009-10-20 00:53:49 -07:00
|
|
|
(mRoleMapEntry->role == nsIAccessibleRole::ROLE_OUTLINEITEM ||
|
|
|
|
mRoleMapEntry->role == nsIAccessibleRole::ROLE_ROW)) {
|
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
nsCOMPtr<nsIAccessible> accTarget;
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccUtils::GetARIATreeItemParent(this, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
getter_AddRefs(accTarget));
|
2009-10-20 00:53:49 -07:00
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
return nsRelUtils::AddTarget(aRelationType, aRelation, accTarget);
|
2008-02-08 18:14:03 -08:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2009-07-21 17:45:04 -07:00
|
|
|
// If accessible is in its own Window, or is the root of a document,
|
|
|
|
// 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).
|
2008-03-05 19:45:43 -08:00
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (frame) {
|
|
|
|
nsIView *view = frame->GetViewExternal();
|
|
|
|
if (view) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollableFrame *scrollFrame = do_QueryFrame(frame);
|
2009-07-21 17:45:04 -07:00
|
|
|
if (scrollFrame || view->GetWidget() || !frame->GetParent()) {
|
2010-01-11 06:14:06 -08:00
|
|
|
return nsRelUtils::AddTarget(aRelationType, aRelation, GetParent());
|
2008-03-05 19:45:43 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_CONTROLLED_BY:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-10 02:03:30 -08:00
|
|
|
return nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromNeighbour(aRelationType, aRelation, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
nsAccessibilityAtoms::aria_controls);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_CONTROLLER_FOR:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-10 02:03:30 -08:00
|
|
|
return nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromIDRefsAttr(aRelationType, aRelation, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
nsAccessibilityAtoms::aria_controls);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_FLOWS_TO:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-10 02:03:30 -08:00
|
|
|
return nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromIDRefsAttr(aRelationType, aRelation, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
nsAccessibilityAtoms::aria_flowto);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_FLOWS_FROM:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-10 02:03:30 -08:00
|
|
|
return nsRelUtils::
|
2010-06-11 01:23:18 -07:00
|
|
|
AddTargetFromNeighbour(aRelationType, aRelation, mContent,
|
2009-02-10 02:03:30 -08:00
|
|
|
nsAccessibilityAtoms::aria_flowto);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_DEFAULT_BUTTON:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->IsHTML()) {
|
2007-08-10 06:03:52 -07:00
|
|
|
// HTML form controls implements nsIFormControl interface.
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIFormControl> control(do_QueryInterface(mContent));
|
2007-08-10 06:03:52 -07:00
|
|
|
if (control) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLFormElement> htmlform;
|
|
|
|
control->GetForm(getter_AddRefs(htmlform));
|
|
|
|
nsCOMPtr<nsIForm> form(do_QueryInterface(htmlform));
|
2009-02-10 02:03:30 -08:00
|
|
|
if (form) {
|
|
|
|
nsCOMPtr<nsIContent> formContent =
|
|
|
|
do_QueryInterface(form->GetDefaultSubmitElement());
|
|
|
|
return nsRelUtils::AddTargetFromContent(aRelationType, aRelation,
|
|
|
|
formContent);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// In XUL, use first <button default="true" .../> in the document
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDoc =
|
|
|
|
do_QueryInterface(mContent->GetOwnerDoc());
|
2007-03-22 10:30:00 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
nsCOMPtr<nsIContent> relatedContent(do_QueryInterface(buttonEl));
|
|
|
|
return nsRelUtils::AddTargetFromContent(aRelationType, aRelation,
|
|
|
|
relatedContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2007-08-10 18:44:44 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_MEMBER_OF:
|
|
|
|
{
|
2009-02-10 02:03:30 -08:00
|
|
|
nsCOMPtr<nsIContent> regionContent = do_QueryInterface(GetAtomicRegion());
|
|
|
|
return nsRelUtils::
|
|
|
|
AddTargetFromContent(aRelationType, aRelation, regionContent);
|
2007-08-10 18:44:44 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-17 20:42:43 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_SUBWINDOW_OF:
|
|
|
|
case nsIAccessibleRelation::RELATION_EMBEDS:
|
|
|
|
case nsIAccessibleRelation::RELATION_EMBEDDED_BY:
|
|
|
|
case nsIAccessibleRelation::RELATION_POPUP_FOR:
|
|
|
|
case nsIAccessibleRelation::RELATION_PARENT_WINDOW_OF:
|
|
|
|
{
|
|
|
|
return NS_OK_NO_RELATION_TARGET;
|
|
|
|
}
|
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
default:
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
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
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
nsCOMPtr<nsIAccessibleRelation> relation;
|
|
|
|
nsresult rv = GetRelationByType(relType, getter_AddRefs(relation));
|
2007-05-19 19:41:33 -07:00
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
if (NS_SUCCEEDED(rv) && relation)
|
2007-05-19 19:41:33 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-01-25 07:09:25 -08:00
|
|
|
void
|
2009-08-19 23:45:19 -07:00
|
|
|
nsAccessible::DoCommand(nsIContent *aContent, PRUint32 aActionIndex)
|
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent* content = aContent ? aContent : mContent.get();
|
|
|
|
NS_DISPATCH_RUNNABLEMETHOD_ARG2(DispatchClickEvent, this, content,
|
|
|
|
aActionIndex);
|
2009-08-19 23:45:19 -07:00
|
|
|
}
|
2008-08-06 05:16:54 -07:00
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
void
|
|
|
|
nsAccessible::DispatchClickEvent(nsIContent *aContent, PRUint32 aActionIndex)
|
|
|
|
{
|
|
|
|
if (IsDefunct())
|
2008-08-06 05:16:54 -07:00
|
|
|
return;
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
|
2008-08-06 05:16:54 -07:00
|
|
|
|
|
|
|
// Scroll into view.
|
2009-08-19 23:45:19 -07:00
|
|
|
presShell->ScrollContentIntoView(aContent, NS_PRESSHELL_SCROLL_ANYWHERE,
|
2008-08-06 05:16:54 -07:00
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE);
|
|
|
|
|
|
|
|
// Fire mouse down and mouse up events.
|
2008-10-15 18:52:58 -07:00
|
|
|
PRBool res = nsCoreUtils::DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, presShell,
|
2009-08-19 23:45:19 -07:00
|
|
|
aContent);
|
2008-08-06 05:16:54 -07:00
|
|
|
if (!res)
|
|
|
|
return;
|
|
|
|
|
2009-08-19 23:45:19 -07:00
|
|
|
nsCoreUtils::DispatchMouseEvent(NS_MOUSE_BUTTON_UP, presShell, aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIAccessibleSelectable
|
|
|
|
NS_IMETHODIMP nsAccessible::GetSelectedChildren(nsIArray **aSelectedAccessibles)
|
|
|
|
{
|
|
|
|
*aSelectedAccessibles = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMutableArray> selectedAccessibles =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
NS_ENSURE_STATE(selectedAccessibles);
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator iter(this, filters::GetSelected, AccIterator::eTreeNav);
|
2010-05-20 00:40:25 -07:00
|
|
|
nsIAccessible *selected = nsnull;
|
|
|
|
while ((selected = iter.GetNext()))
|
2007-03-22 10:30:00 -07:00
|
|
|
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)
|
|
|
|
{
|
2010-05-20 00:40:25 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aSelected);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aSelected = nsnull;
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aIndex < 0) {
|
2010-05-20 00:40:25 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator iter(this, filters::GetSelected, AccIterator::eTreeNav);
|
2010-05-20 00:40:25 -07:00
|
|
|
nsAccessible *selected = nsnull;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 count = 0;
|
|
|
|
while (count ++ <= aIndex) {
|
2010-05-20 00:40:25 -07:00
|
|
|
selected = iter.GetNext();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!selected) {
|
2010-05-20 00:40:25 -07:00
|
|
|
// The index is out of range.
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_ADDREF(*aSelected = selected);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::GetSelectionCount(PRInt32 *aSelectionCount)
|
|
|
|
{
|
2010-05-20 00:40:25 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aSelectionCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aSelectionCount = 0;
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator iter(this, filters::GetSelected, AccIterator::eTreeNav);
|
2010-05-20 00:40:25 -07:00
|
|
|
nsAccessible *selected = nsnull;
|
|
|
|
while ((selected = iter.GetNext()))
|
|
|
|
++(*aSelectionCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible* child = GetChildAt(aIndex);
|
2008-10-17 03:10:43 -07:00
|
|
|
PRUint32 state = nsAccUtils::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);
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible* child = GetChildAt(aIndex);
|
2008-10-17 03:10:43 -07:00
|
|
|
PRUint32 state = nsAccUtils::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);
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible* child = GetChildAt(aIndex);
|
2008-10-17 03:10:43 -07:00
|
|
|
PRUint32 state = nsAccUtils::State(child);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (state & nsIAccessibleStates::STATE_SELECTED) {
|
|
|
|
*aIsSelected = PR_TRUE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-20 00:40:25 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAccessible::ClearSelection()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator iter(this, filters::GetSelected, AccIterator::eTreeNav);
|
2010-05-20 00:40:25 -07:00
|
|
|
nsAccessible *selected = nsnull;
|
|
|
|
while ((selected = iter.GetNext()))
|
2007-03-22 10:30:00 -07:00
|
|
|
selected->SetSelected(PR_FALSE);
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsAccessible::SelectAllSelection(PRBool *_retval)
|
|
|
|
{
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator iter(this, filters::GetSelectable, AccIterator::eTreeNav);
|
2010-05-20 00:40:25 -07:00
|
|
|
nsAccessible *selectable = nsnull;
|
|
|
|
while((selectable = iter.GetNext()))
|
2007-03-22 10:30:00 -07:00
|
|
|
selectable->SetSelected(PR_TRUE);
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
2010-05-17 09:15:52 -07:00
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
2010-05-17 09:15:52 -07:00
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
|
2008-10-01 23:49:45 -07:00
|
|
|
// Check if it's a simple xlink.
|
2010-06-11 01:23:18 -07:00
|
|
|
if (nsCoreUtils::IsXLink(mContent)) {
|
2008-03-30 23:21:35 -07:00
|
|
|
nsAutoString href;
|
2010-06-11 01:23:18 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_XLink, nsAccessibilityAtoms::href, href);
|
2008-03-30 23:21:35 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
|
|
|
|
nsCOMPtr<nsIDocument> document = mContent->GetOwnerDoc();
|
2008-03-30 23:21:35 -07:00
|
|
|
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);
|
2008-10-17 03:10:43 -07:00
|
|
|
PRUint32 state = nsAccUtils::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);
|
2010-06-11 01:23:18 -07:00
|
|
|
|
|
|
|
*aSelected = (gLastFocusedNode == GetNode());
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-17 09:15:52 -07:00
|
|
|
nsresult
|
|
|
|
nsAccessible::GetLinkOffset(PRInt32 *aStartOffset, PRInt32 *aEndOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-17 09:15:52 -07:00
|
|
|
nsAccessible *parent = GetParent();
|
|
|
|
NS_ENSURE_STATE(parent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-25 01:40:54 -07:00
|
|
|
PRUint32 characterCount = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-05-17 09:15:52 -07:00
|
|
|
PRInt32 childCount = parent->GetChildCount();
|
|
|
|
for (PRInt32 childIdx = 0; childIdx < childCount; childIdx++) {
|
|
|
|
nsAccessible *sibling = parent->GetChildAt(childIdx);
|
2008-10-17 03:10:43 -07:00
|
|
|
|
2010-05-17 09:15:52 -07:00
|
|
|
if (sibling == this) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*aStartOffset = characterCount;
|
|
|
|
*aEndOffset = characterCount + 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-05-17 09:15:52 -07:00
|
|
|
|
2010-05-25 01:40:54 -07:00
|
|
|
characterCount += nsAccUtils::TextLength(sibling);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2009-06-18 00:37:38 -07:00
|
|
|
nsresult
|
2007-08-03 18:12:24 -07:00
|
|
|
nsAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset, PRUint32 aLength)
|
2007-04-10 21:17:33 -07:00
|
|
|
{
|
2010-06-09 20:29:56 -07:00
|
|
|
// Return text representation of non-text accessible within hypertext
|
|
|
|
// accessible. Text accessible overrides this method to return enclosed text.
|
|
|
|
if (aStartOffset != 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
NS_ENSURE_STATE(frame);
|
|
|
|
|
|
|
|
if (frame->GetType() == nsAccessibilityAtoms::brFrame) {
|
|
|
|
aText += kForcedNewLineChar;
|
|
|
|
} else if (nsAccUtils::MustPrune(this)) {
|
|
|
|
// Expose imaginary embedded object character if the accessible hans't
|
|
|
|
// children.
|
|
|
|
aText += kImaginaryEmbeddedObjectChar;
|
|
|
|
} else {
|
|
|
|
aText += kEmbeddedObjectChar;
|
|
|
|
}
|
|
|
|
|
2007-04-10 21:17:33 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAccessNode public methods
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsAccessible::Init()
|
|
|
|
{
|
|
|
|
if (!nsAccessNodeWrap::Init())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsDocAccessible *docAcc =
|
|
|
|
GetAccService()->GetDocAccessible(mContent->GetOwnerDoc());
|
|
|
|
NS_ASSERTION(docAcc, "Cannot cache new nsAccessible!");
|
|
|
|
if (!docAcc)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
void *uniqueID = nsnull;
|
|
|
|
GetUniqueID(&uniqueID);
|
|
|
|
|
|
|
|
if (!docAcc->CacheAccessible(uniqueID, this))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// Make sure an ancestor in real content is cached so that
|
|
|
|
// nsDocAccessible::RefreshNodes() can find the anonymous subtree to release
|
|
|
|
// when the root node goes away. /Specific examples of where this is used:
|
|
|
|
// <input type="file"> and <xul:findbar>.
|
|
|
|
// XXX: remove this once we create correct accessible tree.
|
|
|
|
if (mContent && mContent->IsInAnonymousSubtree()) {
|
|
|
|
nsAccessible *parent = GetAccService()->GetContainerAccessible(mContent,
|
|
|
|
PR_TRUE);
|
|
|
|
if (parent)
|
|
|
|
parent->EnsureChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAccessible::Shutdown()
|
|
|
|
{
|
|
|
|
// Invalidate the child count and pointers to other accessibles, also make
|
|
|
|
// sure none of its children point to this parent
|
|
|
|
InvalidateChildren();
|
|
|
|
if (mParent) {
|
|
|
|
mParent->InvalidateChildren();
|
|
|
|
mParent = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAccessNodeWrap::Shutdown();
|
|
|
|
}
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAccessible public methods
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsAccessible::GetARIAName(nsAString& aName)
|
|
|
|
{
|
|
|
|
// First check for label override via aria-label property
|
|
|
|
nsAutoString label;
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::aria_label,
|
|
|
|
label)) {
|
2009-02-18 23:06:14 -08:00
|
|
|
label.CompressWhitespace();
|
2008-10-10 05:26:55 -07:00
|
|
|
aName = label;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Second check for label override via aria-labelledby relationship
|
2009-02-18 23:06:14 -08:00
|
|
|
nsresult rv = nsTextEquivUtils::
|
|
|
|
GetTextEquivFromIDRefs(this, nsAccessibilityAtoms::aria_labelledby, label);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
label.CompressWhitespace();
|
2008-10-10 05:26:55 -07:00
|
|
|
aName = label;
|
2009-02-18 23:06:14 -08:00
|
|
|
}
|
2008-10-10 05:26:55 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsAccessible::GetNameInternal(nsAString& aName)
|
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->IsHTML())
|
2008-12-02 23:18:41 -08:00
|
|
|
return GetHTMLName(aName);
|
2008-10-10 05:26:55 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->IsXUL())
|
2008-12-02 23:18:41 -08:00
|
|
|
return GetXULName(aName);
|
2008-10-10 05:26:55 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
void
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible::SetParent(nsAccessible *aParent)
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParent, "This method isn't used to set null parent!");
|
|
|
|
|
|
|
|
if (mParent && 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
|
|
|
|
NS_ASSERTION(PR_FALSE, "Adopting child!");
|
2010-01-11 06:14:06 -08:00
|
|
|
if (mParent)
|
|
|
|
mParent->InvalidateChildren();
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
mParent = aParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAccessible::InvalidateChildren()
|
|
|
|
{
|
2010-01-11 06:14:06 -08:00
|
|
|
PRInt32 childCount = mChildren.Length();
|
2009-12-10 11:12:19 -08:00
|
|
|
for (PRInt32 childIdx = 0; childIdx < childCount; childIdx++) {
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible* child = mChildren.ElementAt(childIdx);
|
2009-12-10 11:12:19 -08:00
|
|
|
child->mParent = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
mChildren.Clear();
|
|
|
|
mAreChildrenInitialized = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible*
|
2009-12-10 11:12:19 -08:00
|
|
|
nsAccessible::GetParent()
|
|
|
|
{
|
|
|
|
if (IsDefunct())
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
if (mParent)
|
|
|
|
return mParent;
|
|
|
|
|
2010-05-25 01:40:39 -07:00
|
|
|
#ifdef DEBUG
|
2010-03-16 23:02:28 -07:00
|
|
|
nsDocAccessible *docAccessible = GetDocAccessible();
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ASSERTION(docAccessible, "No document accessible for valid accessible!");
|
2010-05-25 01:40:39 -07:00
|
|
|
#endif
|
2009-12-10 11:12:19 -08:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccessible *parent = GetAccService()->GetContainerAccessible(mContent,
|
2010-05-25 01:40:39 -07:00
|
|
|
PR_TRUE);
|
|
|
|
NS_ASSERTION(parent, "No accessible parent for valid accessible!");
|
|
|
|
if (!parent)
|
2009-12-10 11:12:19 -08:00
|
|
|
return nsnull;
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
#ifdef DEBUG
|
2010-05-25 01:40:39 -07:00
|
|
|
NS_ASSERTION(!parent->IsDefunct(), "Defunct parent!");
|
2009-12-10 11:12:19 -08:00
|
|
|
|
2010-05-25 01:40:39 -07:00
|
|
|
parent->EnsureChildren();
|
2009-12-10 11:12:19 -08:00
|
|
|
if (parent != mParent)
|
|
|
|
NS_WARNING("Bad accessible tree!");
|
|
|
|
#endif
|
|
|
|
|
2010-05-25 01:40:39 -07:00
|
|
|
return parent;
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible*
|
2009-12-10 11:12:19 -08:00
|
|
|
nsAccessible::GetChildAt(PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
if (EnsureChildren())
|
|
|
|
return nsnull;
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible *child = mChildren.SafeElementAt(aIndex, nsnull);
|
2009-12-10 11:12:19 -08:00
|
|
|
if (!child)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible* realParent = child->mParent;
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ASSERTION(!realParent || realParent == this,
|
|
|
|
"Two accessibles have the same first child accessible!");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsAccessible::GetChildCount()
|
|
|
|
{
|
2010-01-11 06:14:06 -08:00
|
|
|
return EnsureChildren() ? -1 : mChildren.Length();
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsAccessible::GetIndexOf(nsIAccessible *aChild)
|
|
|
|
{
|
|
|
|
return EnsureChildren() ? -1 : mChildren.IndexOf(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsAccessible::GetIndexInParent()
|
|
|
|
{
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible *parent = GetParent();
|
|
|
|
return parent ? parent->GetIndexOf(this) : -1;
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible*
|
2009-12-10 11:12:19 -08:00
|
|
|
nsAccessible::GetCachedParent()
|
|
|
|
{
|
|
|
|
if (IsDefunct())
|
|
|
|
return nsnull;
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
return mParent;
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible*
|
2009-12-10 11:12:19 -08:00
|
|
|
nsAccessible::GetCachedFirstChild()
|
|
|
|
{
|
|
|
|
if (IsDefunct())
|
|
|
|
return nsnull;
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
return mChildren.SafeElementAt(0, nsnull);
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool
|
|
|
|
nsAccessible::IsInCache()
|
|
|
|
{
|
|
|
|
nsDocAccessible *docAccessible =
|
|
|
|
GetAccService()->GetDocAccessible(mContent->GetOwnerDoc());
|
|
|
|
if (!docAccessible)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
void *uniqueID = nsnull;
|
|
|
|
GetUniqueID(&uniqueID);
|
|
|
|
|
|
|
|
return docAccessible->GetCachedAccessible(uniqueID) ? PR_TRUE : PR_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2009-12-10 11:12:19 -08:00
|
|
|
// nsAccessible protected methods
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAccessible::CacheChildren()
|
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccTreeWalker walker(mWeakShell, mContent, GetAllowsAnonChildAccessibles());
|
2009-12-10 11:12:19 -08:00
|
|
|
|
2010-02-20 16:56:35 -08:00
|
|
|
nsRefPtr<nsAccessible> child;
|
2010-02-20 16:55:04 -08:00
|
|
|
while ((child = walker.GetNextChild())) {
|
2010-02-20 16:56:35 -08:00
|
|
|
mChildren.AppendElement(child);
|
|
|
|
child->SetParent(this);
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible::TestChildCache(nsAccessible *aCachedChild)
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
2010-02-09 05:29:22 -08:00
|
|
|
#ifdef DEBUG
|
2010-04-19 06:39:57 -07:00
|
|
|
PRInt32 childCount = mChildren.Length();
|
2009-12-10 11:12:19 -08:00
|
|
|
if (childCount == 0) {
|
2010-03-08 23:25:24 -08:00
|
|
|
NS_ASSERTION(!mAreChildrenInitialized, "No children but initialized!");
|
2009-12-10 11:12:19 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-08 23:25:24 -08:00
|
|
|
nsAccessible *child = nsnull;
|
2009-12-10 11:12:19 -08:00
|
|
|
for (PRInt32 childIdx = 0; childIdx < childCount; childIdx++) {
|
2010-03-08 23:25:24 -08:00
|
|
|
child = mChildren[childIdx];
|
2009-12-10 11:12:19 -08:00
|
|
|
if (child == aCachedChild)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(child == aCachedChild,
|
|
|
|
"[TestChildCache] cached accessible wasn't found. Wrong accessible tree!");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-04-07 23:43:08 -07:00
|
|
|
// nsAccessible public
|
2009-12-10 11:12:19 -08:00
|
|
|
PRBool
|
|
|
|
nsAccessible::EnsureChildren()
|
|
|
|
{
|
|
|
|
if (IsDefunct()) {
|
|
|
|
mAreChildrenInitialized = PR_FALSE;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAreChildrenInitialized)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
mAreChildrenInitialized = PR_TRUE; // Prevent reentry
|
|
|
|
CacheChildren();
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-03-10 02:26:11 -08:00
|
|
|
nsAccessible*
|
2009-12-10 11:12:19 -08:00
|
|
|
nsAccessible::GetSiblingAtOffset(PRInt32 aOffset, nsresult* aError)
|
|
|
|
{
|
|
|
|
if (IsDefunct()) {
|
|
|
|
if (aError)
|
|
|
|
*aError = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible *parent = GetParent();
|
2009-12-10 11:12:19 -08:00
|
|
|
if (!parent) {
|
|
|
|
if (aError)
|
|
|
|
*aError = NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
PRInt32 indexInParent = parent->GetIndexOf(this);
|
2009-12-10 11:12:19 -08:00
|
|
|
if (indexInParent == -1) {
|
|
|
|
if (aError)
|
|
|
|
*aError = NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aError) {
|
2010-01-11 06:14:06 -08:00
|
|
|
PRInt32 childCount = parent->GetChildCount();
|
2009-12-10 11:12:19 -08:00
|
|
|
if (indexInParent + aOffset >= childCount) {
|
|
|
|
*aError = NS_OK; // fail peacefully
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible *child = parent->GetChildAt(indexInParent + aOffset);
|
2009-12-10 11:12:19 -08:00
|
|
|
if (aError && !child)
|
|
|
|
*aError = NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
2008-10-10 05:26:55 -07:00
|
|
|
|
2010-05-25 01:05:52 -07:00
|
|
|
nsAccessible *
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAccessible::GetFirstAvailableAccessible(nsINode *aStartNode) const
|
|
|
|
{
|
|
|
|
nsAccessible *accessible =
|
|
|
|
GetAccService()->GetAccessibleInWeakShell(aStartNode, mWeakShell);
|
|
|
|
if (accessible)
|
|
|
|
return accessible;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent *content = nsCoreUtils::GetRoleContent(aStartNode);
|
|
|
|
nsAccTreeWalker walker(mWeakShell, content, PR_FALSE);
|
|
|
|
nsRefPtr<nsAccessible> childAccessible = walker.GetNextChild();
|
|
|
|
return childAccessible;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2010-06-25 06:59:57 -07:00
|
|
|
nsIPresShell* shell = parentDoc->GetShell();
|
2007-11-12 19:05:34 -08:00
|
|
|
if (!shell) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
|
2009-05-05 20:16:36 -07:00
|
|
|
if (IsDefunct())
|
2007-08-03 22:27:27 -07:00
|
|
|
return NS_ERROR_FAILURE; // Node already shut down
|
|
|
|
|
|
|
|
if (!mRoleMapEntry || mRoleMapEntry->valueRule == eNoValue)
|
|
|
|
return NS_OK_NO_ARIA_VALUE;
|
|
|
|
|
2009-05-05 20:16:36 -07:00
|
|
|
nsAutoString attrValue;
|
2010-06-11 01:23:18 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, aProperty, attrValue);
|
2007-08-03 22:27:27 -07:00
|
|
|
|
2009-05-05 20:16:36 -07:00
|
|
|
// Return zero value if there is no attribute or its value is empty.
|
|
|
|
if (attrValue.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRInt32 error = NS_OK;
|
|
|
|
double value = attrValue.ToFloat(&error);
|
|
|
|
if (NS_SUCCEEDED(error))
|
|
|
|
*aValue = value;
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-08-03 22:27:27 -07:00
|
|
|
}
|
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
PRUint32
|
|
|
|
nsAccessible::GetActionRule(PRUint32 aStates)
|
|
|
|
{
|
|
|
|
if (aStates & nsIAccessibleStates::STATE_UNAVAILABLE)
|
|
|
|
return eNoAction;
|
2009-04-19 23:06:19 -07:00
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
// Check if it's simple xlink.
|
2010-06-11 01:23:18 -07:00
|
|
|
if (nsCoreUtils::IsXLink(mContent))
|
2008-10-08 05:54:58 -07:00
|
|
|
return eJumpAction;
|
|
|
|
|
2009-08-23 22:13:05 -07:00
|
|
|
// Return "click" action on elements that have an attached popup menu.
|
2010-06-11 01:23:18 -07:00
|
|
|
if (mContent->IsXUL())
|
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::popup))
|
2009-08-23 22:13:05 -07:00
|
|
|
return eClickAction;
|
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
// Has registered 'click' event handler.
|
2010-06-11 01:23:18 -07:00
|
|
|
PRBool isOnclick = nsCoreUtils::HasClickListener(mContent);
|
2008-10-08 05:54:58 -07:00
|
|
|
|
|
|
|
if (isOnclick)
|
|
|
|
return eClickAction;
|
2009-04-19 23:06:19 -07:00
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
// Get an action based on ARIA role.
|
2009-04-19 23:06:19 -07:00
|
|
|
if (mRoleMapEntry &&
|
|
|
|
mRoleMapEntry->actionRule != eNoAction)
|
2008-10-08 05:54:58 -07:00
|
|
|
return mRoleMapEntry->actionRule;
|
|
|
|
|
2009-04-19 23:06:19 -07:00
|
|
|
// Get an action based on ARIA attribute.
|
2010-06-11 01:23:18 -07:00
|
|
|
if (nsAccUtils::HasDefinedARIAToken(mContent,
|
|
|
|
nsAccessibilityAtoms::aria_expanded))
|
2009-04-19 23:06:19 -07:00
|
|
|
return eExpandAction;
|
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
return eNoAction;
|
|
|
|
}
|
2009-01-04 23:41:30 -08:00
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
void
|
|
|
|
nsAccessible::GetPositionAndSizeInternal(PRInt32 *aPosInSet, PRInt32 *aSetSize)
|
|
|
|
{
|
|
|
|
PRUint32 role = nsAccUtils::Role(this);
|
|
|
|
if (role != nsIAccessibleRole::ROLE_LISTITEM &&
|
|
|
|
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_OUTLINEITEM &&
|
|
|
|
role != nsIAccessibleRole::ROLE_ROW &&
|
|
|
|
role != nsIAccessibleRole::ROLE_GRID_CELL)
|
|
|
|
return;
|
2009-01-04 23:41:30 -08:00
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
PRUint32 baseRole = role;
|
|
|
|
if (role == nsIAccessibleRole::ROLE_CHECK_MENU_ITEM ||
|
|
|
|
role == nsIAccessibleRole::ROLE_RADIO_MENU_ITEM)
|
2009-01-04 23:41:30 -08:00
|
|
|
baseRole = nsIAccessibleRole::ROLE_MENUITEM;
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible* parent = GetParent();
|
2010-01-06 02:36:50 -08:00
|
|
|
NS_ENSURE_TRUE(parent,);
|
2009-01-04 23:41:30 -08:00
|
|
|
|
2010-01-12 11:07:38 -08:00
|
|
|
PRInt32 indexInParent = parent->GetIndexOf(this);
|
|
|
|
PRInt32 level = nsAccUtils::GetARIAOrDefaultLevel(this);
|
|
|
|
|
|
|
|
// Compute 'posinset'.
|
|
|
|
PRInt32 positionInGroup = 1;
|
|
|
|
for (PRInt32 idx = indexInParent - 1; idx >= 0; idx--) {
|
|
|
|
nsAccessible* sibling = parent->GetChildAt(idx);
|
2009-01-04 23:41:30 -08:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
PRUint32 siblingRole = nsAccUtils::Role(sibling);
|
2010-01-12 11:07:38 -08:00
|
|
|
|
|
|
|
// If the sibling is separator then the group is ended.
|
|
|
|
if (siblingRole == nsIAccessibleRole::ROLE_SEPARATOR)
|
|
|
|
break;
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
PRUint32 siblingBaseRole = siblingRole;
|
2009-01-04 23:41:30 -08:00
|
|
|
if (siblingRole == nsIAccessibleRole::ROLE_CHECK_MENU_ITEM ||
|
|
|
|
siblingRole == nsIAccessibleRole::ROLE_RADIO_MENU_ITEM)
|
|
|
|
siblingBaseRole = nsIAccessibleRole::ROLE_MENUITEM;
|
|
|
|
|
2010-01-12 11:07:38 -08:00
|
|
|
// If sibling is visible and has the same base role
|
2009-01-04 23:41:30 -08:00
|
|
|
if (siblingBaseRole == baseRole &&
|
|
|
|
!(nsAccUtils::State(sibling) & nsIAccessibleStates::STATE_INVISIBLE)) {
|
2010-01-12 11:07:38 -08:00
|
|
|
|
|
|
|
// and check if it's hierarchical flatten structure, i.e. if the sibling
|
|
|
|
// level is lesser than this one then group is ended, if the sibling level
|
|
|
|
// is greater than this one then the group is splited by some child
|
|
|
|
// elements (group will be continued).
|
|
|
|
PRInt32 siblingLevel = nsAccUtils::GetARIAOrDefaultLevel(sibling);
|
|
|
|
if (siblingLevel < level)
|
|
|
|
break;
|
|
|
|
else if (level == siblingLevel)
|
2009-01-04 23:41:30 -08:00
|
|
|
++ positionInGroup;
|
|
|
|
}
|
2010-01-12 11:07:38 -08:00
|
|
|
}
|
2009-01-04 23:41:30 -08:00
|
|
|
|
2010-01-12 11:07:38 -08:00
|
|
|
// Compute 'setsize'.
|
|
|
|
PRInt32 setSize = positionInGroup;
|
2009-01-04 23:41:30 -08:00
|
|
|
|
2010-01-12 11:07:38 -08:00
|
|
|
PRInt32 siblingCount = parent->GetChildCount();
|
|
|
|
for (PRInt32 idx = indexInParent + 1; idx < siblingCount; idx++) {
|
|
|
|
nsAccessible* sibling = parent->GetChildAt(idx);
|
|
|
|
NS_ENSURE_TRUE(sibling,);
|
|
|
|
|
|
|
|
PRUint32 siblingRole = nsAccUtils::Role(sibling);
|
|
|
|
|
|
|
|
// If the sibling is separator then the group is ended.
|
|
|
|
if (siblingRole == nsIAccessibleRole::ROLE_SEPARATOR)
|
|
|
|
break;
|
|
|
|
|
|
|
|
PRUint32 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 &&
|
|
|
|
!(nsAccUtils::State(sibling) & nsIAccessibleStates::STATE_INVISIBLE)) {
|
|
|
|
|
|
|
|
// and check if it's hierarchical flatten structure.
|
|
|
|
PRInt32 siblingLevel = nsAccUtils::GetARIAOrDefaultLevel(sibling);
|
|
|
|
if (siblingLevel < level)
|
|
|
|
break;
|
|
|
|
else if (level == siblingLevel)
|
|
|
|
++ setSize;
|
2009-01-04 23:41:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
*aPosInSet = positionInGroup;
|
|
|
|
*aSetSize = setSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsAccessible::GetLevelInternal()
|
|
|
|
{
|
2010-01-12 11:07:38 -08:00
|
|
|
PRInt32 level = nsAccUtils::GetDefaultLevel(this);
|
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
PRUint32 role = nsAccUtils::Role(this);
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible* parent = GetParent();
|
2010-01-06 02:36:50 -08:00
|
|
|
|
|
|
|
if (role == nsIAccessibleRole::ROLE_OUTLINEITEM) {
|
2009-01-04 23:41:30 -08:00
|
|
|
// Always expose 'level' attribute for 'outlineitem' accessible. The number
|
|
|
|
// of nested 'grouping' accessibles containing 'outlineitem' accessible is
|
|
|
|
// its level.
|
2010-01-12 11:07:38 -08:00
|
|
|
level = 1;
|
|
|
|
|
2009-01-04 23:41:30 -08:00
|
|
|
while (parent) {
|
|
|
|
PRUint32 parentRole = nsAccUtils::Role(parent);
|
|
|
|
|
|
|
|
if (parentRole == nsIAccessibleRole::ROLE_OUTLINE)
|
|
|
|
break;
|
|
|
|
if (parentRole == nsIAccessibleRole::ROLE_GROUPING)
|
2010-01-06 02:36:50 -08:00
|
|
|
++ level;
|
2009-01-04 23:41:30 -08:00
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
parent = parent->GetParent();
|
2009-01-04 23:41:30 -08:00
|
|
|
}
|
2010-01-06 02:36:50 -08:00
|
|
|
|
2010-01-12 11:07:38 -08:00
|
|
|
} else if (role == nsIAccessibleRole::ROLE_LISTITEM) {
|
2009-01-04 23:41:30 -08:00
|
|
|
// Expose 'level' attribute on nested lists. We assume nested list is a last
|
|
|
|
// child of listitem of parent list. We don't handle the case when nested
|
|
|
|
// lists have more complex structure, for example when there are accessibles
|
|
|
|
// between parent listitem and nested list.
|
|
|
|
|
|
|
|
// Calculate 'level' attribute based on number of parent listitems.
|
2010-01-12 11:07:38 -08:00
|
|
|
level = 0;
|
2010-01-06 02:36:50 -08:00
|
|
|
|
2009-01-04 23:41:30 -08:00
|
|
|
while (parent) {
|
|
|
|
PRUint32 parentRole = nsAccUtils::Role(parent);
|
|
|
|
|
|
|
|
if (parentRole == nsIAccessibleRole::ROLE_LISTITEM)
|
2010-01-06 02:36:50 -08:00
|
|
|
++ level;
|
2009-01-04 23:41:30 -08:00
|
|
|
else if (parentRole != nsIAccessibleRole::ROLE_LIST)
|
|
|
|
break;
|
|
|
|
|
2010-01-11 06:14:06 -08:00
|
|
|
parent = parent->GetParent();
|
2009-01-04 23:41:30 -08:00
|
|
|
}
|
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
if (level == 0) {
|
2009-01-04 23:41:30 -08:00
|
|
|
// If this listitem is on top of nested lists then expose 'level'
|
|
|
|
// attribute.
|
2010-01-11 06:14:06 -08:00
|
|
|
nsAccessible* parent(GetParent());
|
|
|
|
PRInt32 siblingCount = parent->GetChildCount();
|
|
|
|
for (PRInt32 siblingIdx = 0; siblingIdx < siblingCount; siblingIdx++) {
|
|
|
|
nsAccessible* sibling = parent->GetChildAt(siblingIdx);
|
2009-01-04 23:41:30 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> siblingChild;
|
|
|
|
sibling->GetLastChild(getter_AddRefs(siblingChild));
|
|
|
|
if (nsAccUtils::Role(siblingChild) == nsIAccessibleRole::ROLE_LIST) {
|
2010-01-06 02:36:50 -08:00
|
|
|
level = 1;
|
2009-01-04 23:41:30 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-01-06 02:36:50 -08:00
|
|
|
} else {
|
|
|
|
++ level; // level is 1-index based
|
|
|
|
}
|
2009-01-04 23:41:30 -08:00
|
|
|
}
|
|
|
|
|
2010-01-12 11:07:38 -08:00
|
|
|
return level;
|
2009-01-04 23:41:30 -08:00
|
|
|
}
|