2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "Accessible-inl.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-07-02 20:11:35 -07:00
|
|
|
#include "AccGroupInfo.h"
|
2010-06-21 06:08:27 -07:00
|
|
|
#include "AccIterator.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsAccUtils.h"
|
2010-08-24 19:08:28 -07:00
|
|
|
#include "nsAccEvent.h"
|
2011-08-09 18:44:00 -07:00
|
|
|
#include "nsAccessibleRelation.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#include "nsAccTreeWalker.h"
|
2011-08-09 18:44:00 -07:00
|
|
|
#include "nsIAccessibleRelation.h"
|
2012-02-20 07:45:29 -08:00
|
|
|
#include "nsEventShell.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsTextEquivUtils.h"
|
2011-08-09 18:44:00 -07:00
|
|
|
#include "Relation.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
2012-05-03 23:09:22 -07:00
|
|
|
#include "RootAccessible.h"
|
2011-04-09 16:38:06 -07:00
|
|
|
#include "States.h"
|
2012-02-20 07:45:29 -08:00
|
|
|
#include "StyleInfo.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
|
2012-05-23 23:57:16 -07:00
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#include "nsIDOMNodeFilter.h"
|
2011-10-29 13:03:55 -07:00
|
|
|
#include "nsIDOMHTMLElement.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#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
|
|
|
|
2011-05-30 11:23:36 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#include "nsIPresShell.h"
|
2012-05-10 06:43:04 -07:00
|
|
|
#include "nsIStringBundle.h"
|
2007-08-10 06:03:52 -07:00
|
|
|
#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 "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"
|
2011-04-21 10:35:52 -07:00
|
|
|
#include "nsEventStates.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMCharacterData.h"
|
|
|
|
#endif
|
|
|
|
|
2010-08-18 19:14:50 -07:00
|
|
|
#include "mozilla/unused.h"
|
2011-06-02 23:01:02 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-07-20 12:18:54 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-06-02 23:01:02 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
2010-08-18 19:14:50 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-06 05:19:56 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible. nsISupports
|
2008-08-06 05:19:56 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Accessible)
|
2008-08-06 05:19:56 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(Accessible, 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
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Accessible, nsAccessNode)
|
2008-08-06 05:19:56 -07:00
|
|
|
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
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(Accessible, nsAccessNode)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(Accessible, nsAccessNode)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
nsresult
|
|
|
|
Accessible::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// 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))) {
|
2012-06-03 23:30:26 -07:00
|
|
|
*aInstancePtr = NS_CYCLE_COLLECTION_PARTICIPANT(Accessible);
|
2008-08-06 05:19:56 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
if (aIID.Equals(NS_GET_IID(Accessible))) {
|
|
|
|
*aInstancePtr = static_cast<Accessible*>(this);
|
2008-10-10 05:26:55 -07:00
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIAccessibleSelectable))) {
|
2010-09-01 17:46:59 -07:00
|
|
|
if (IsSelect()) {
|
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
|
|
|
}
|
2010-09-01 17:46:59 -07:00
|
|
|
return NS_ERROR_NO_INTERFACE;
|
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))) {
|
2011-06-23 21:29:43 -07:00
|
|
|
if (IsLink()) {
|
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
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::Accessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-02-07 14:38:54 -08:00
|
|
|
nsAccessNodeWrap(aContent, aDoc),
|
2011-01-27 21:15:04 -08:00
|
|
|
mParent(nsnull), mIndexInParent(-1), mFlags(eChildrenUninitialized),
|
2010-08-15 04:28:49 -07:00
|
|
|
mIndexOfEmbeddedChild(-1), 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) {
|
2011-05-05 09:26:33 -07:00
|
|
|
printf(" Con: %s@%p",
|
|
|
|
NS_ConvertUTF16toUTF8(content->NodeInfo()->QualifiedName()).get(),
|
|
|
|
(void *)content.get());
|
2007-04-23 08:37:55 -07:00
|
|
|
nsAutoString buf;
|
2012-04-30 20:08:31 -07:00
|
|
|
Name(buf);
|
|
|
|
printf(" Name:[%s]", NS_ConvertUTF16toUTF8(buf).get());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------
|
|
|
|
// destruction
|
|
|
|
//-----------------------------------------------------
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::~Accessible()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-18 00:37:38 -07:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::SetRoleMapEntry(nsRoleMapEntry* aRoleMapEntry)
|
2007-11-11 17:05:37 -08:00
|
|
|
{
|
|
|
|
mRoleMapEntry = aRoleMapEntry;
|
|
|
|
}
|
|
|
|
|
2012-07-10 05:32:30 -07:00
|
|
|
bool
|
|
|
|
Accessible::Init()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-07 05:18:33 -08:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetDocument(nsIAccessibleDocument** aDocument)
|
2012-02-07 05:18:33 -08:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDocument);
|
|
|
|
|
2011-11-09 14:52:00 -08:00
|
|
|
NS_IF_ADDREF(*aDocument = Document());
|
2012-02-07 05:18:33 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetDOMNode(nsIDOMNode** aDOMNode)
|
2012-02-07 05:18:33 -08:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDOMNode);
|
|
|
|
*aDOMNode = nsnull;
|
|
|
|
|
|
|
|
nsINode *node = GetNode();
|
|
|
|
if (node)
|
|
|
|
CallQueryInterface(node, aDOMNode);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetRootDocument(nsIAccessibleDocument** aRootDocument)
|
2012-02-07 05:18:33 -08:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRootDocument);
|
|
|
|
|
2012-05-03 23:09:22 -07:00
|
|
|
NS_IF_ADDREF(*aRootDocument = RootAccessible());
|
2012-02-07 05:18:33 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetLanguage(nsAString& aLanguage)
|
2012-02-07 05:18:33 -08:00
|
|
|
{
|
|
|
|
Language(aLanguage);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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
|
|
|
|
2012-04-30 20:08:31 -07:00
|
|
|
nsAutoString name;
|
|
|
|
Name(name);
|
|
|
|
aName.Assign(name);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ENameValueFlag
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::Name(nsString& aName)
|
2012-04-30 20:08:31 -07:00
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
GetARIAName(aName);
|
|
|
|
if (!aName.IsEmpty())
|
2012-04-30 20:08:31 -07:00
|
|
|
return eNameOK;
|
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())
|
2012-04-30 20:08:31 -07:00
|
|
|
return eNameOK;
|
2009-05-13 22:29:33 -07:00
|
|
|
}
|
|
|
|
|
2008-12-02 23:21:08 -08:00
|
|
|
nsresult rv = GetNameInternal(aName);
|
|
|
|
if (!aName.IsEmpty())
|
2012-04-30 20:08:31 -07:00
|
|
|
return eNameOK;
|
2008-12-02 23:21:08 -08:00
|
|
|
|
|
|
|
// In the end get the name from tooltip.
|
2012-04-30 20:08:31 -07:00
|
|
|
if (mContent->IsHTML()) {
|
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::title, aName)) {
|
|
|
|
aName.CompressWhitespace();
|
|
|
|
return eNameFromTooltip;
|
|
|
|
}
|
|
|
|
} else if (mContent->IsXUL()) {
|
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::tooltiptext, aName)) {
|
|
|
|
aName.CompressWhitespace();
|
|
|
|
return eNameFromTooltip;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return eNameOK;
|
2008-12-02 23:21:08 -08:00
|
|
|
}
|
|
|
|
|
2009-02-27 02:54:39 -08:00
|
|
|
if (rv != NS_OK_EMPTY_NAME)
|
2011-10-17 07:59:28 -07:00
|
|
|
aName.SetIsVoid(true);
|
2009-02-27 02:54:39 -08:00
|
|
|
|
2012-04-30 20:08:31 -07:00
|
|
|
return eNameOK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-23 06:14:05 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetDescription(nsAString& aDescription)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-04-24 07:40:18 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-04-23 06:14:05 -07:00
|
|
|
nsAutoString desc;
|
|
|
|
Description(desc);
|
|
|
|
aDescription.Assign(desc);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::Description(nsString& aDescription)
|
2011-04-23 06:14:05 -07:00
|
|
|
{
|
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
|
|
|
|
2011-04-23 06:14:05 -07:00
|
|
|
if (mContent->IsNodeOfType(nsINode::eTEXT))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsTextEquivUtils::
|
2011-06-03 14:35:17 -07:00
|
|
|
GetTextEquivFromIDRefs(this, nsGkAtoms::aria_describedby,
|
2011-04-23 06:14:05 -07:00
|
|
|
aDescription);
|
|
|
|
|
|
|
|
if (aDescription.IsEmpty()) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isXUL = mContent->IsXUL();
|
2011-04-23 06:14:05 -07:00
|
|
|
if (isXUL) {
|
|
|
|
// Try XUL <description control="[id]">description text</description>
|
2011-11-09 14:52:00 -08:00
|
|
|
XULDescriptionIterator iter(Document(), mContent);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* descr = nsnull;
|
2011-04-23 06:14:05 -07:00
|
|
|
while ((descr = iter.Next()))
|
|
|
|
nsTextEquivUtils::AppendTextEquivFromContent(this, descr->GetContent(),
|
|
|
|
&aDescription);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-04-23 06:14:05 -07:00
|
|
|
|
|
|
|
if (aDescription.IsEmpty()) {
|
2011-06-03 14:35:17 -07:00
|
|
|
nsIAtom *descAtom = isXUL ? nsGkAtoms::tooltiptext :
|
|
|
|
nsGkAtoms::title;
|
2011-04-23 06:14:05 -07:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, descAtom, aDescription)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString name;
|
2012-04-30 20:08:31 -07:00
|
|
|
Name(name);
|
2011-04-23 06:14:05 -07:00
|
|
|
if (name.IsEmpty() || aDescription == name)
|
2007-03-22 10:30:00 -07:00
|
|
|
// Don't use tooltip for a description if this object
|
|
|
|
// has no name or the tooltip is the same as the name
|
2011-04-23 06:14:05 -07:00
|
|
|
aDescription.Truncate();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-23 06:14:05 -07:00
|
|
|
aDescription.CompressWhitespace();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-28 23:52:46 -07:00
|
|
|
NS_IMETHODIMP
|
2012-06-09 02:49:21 -07:00
|
|
|
Accessible::GetAccessKey(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;
|
|
|
|
|
2011-07-19 01:30:24 -07:00
|
|
|
AccessKey().ToString(aAccessKey);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyBinding
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::AccessKey() const
|
2011-07-19 01:30:24 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
PRUint32 key = nsCoreUtils::GetAccessKeyFor(mContent);
|
|
|
|
if (!key && mContent->IsElement()) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* label = nsnull;
|
2010-11-19 18:37:18 -08:00
|
|
|
|
|
|
|
// Copy access key from label node.
|
|
|
|
if (mContent->IsHTML()) {
|
|
|
|
// Unless it is labeled via an ancestor <label>, in which case that would
|
|
|
|
// be redundant.
|
2011-11-09 14:52:00 -08:00
|
|
|
HTMLLabelIterator iter(Document(), this,
|
2010-11-19 18:37:18 -08:00
|
|
|
HTMLLabelIterator::eSkipAncestorLabel);
|
|
|
|
label = iter.Next();
|
|
|
|
|
|
|
|
} else if (mContent->IsXUL()) {
|
2011-11-09 14:52:00 -08:00
|
|
|
XULLabelIterator iter(Document(), mContent);
|
2010-11-19 18:37:18 -08:00
|
|
|
label = iter.Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (label)
|
|
|
|
key = nsCoreUtils::GetAccessKeyFor(label->GetContent());
|
2007-08-28 23:52:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!key)
|
2011-07-19 01:30:24 -07:00
|
|
|
return KeyBinding();
|
2007-08-28 23:52:46 -07:00
|
|
|
|
2011-07-19 01:30:24 -07:00
|
|
|
// Get modifier mask. Use ui.key.generalAccessKey (unless it is -1).
|
|
|
|
switch (Preferences::GetInt("ui.key.generalAccessKey", -1)) {
|
|
|
|
case -1:
|
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_SHIFT:
|
|
|
|
return KeyBinding(key, KeyBinding::kShift);
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_CONTROL:
|
|
|
|
return KeyBinding(key, KeyBinding::kControl);
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ALT:
|
|
|
|
return KeyBinding(key, KeyBinding::kAlt);
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_META:
|
|
|
|
return KeyBinding(key, KeyBinding::kMeta);
|
|
|
|
default:
|
|
|
|
return KeyBinding();
|
2007-08-28 23:52:46 -07:00
|
|
|
}
|
2011-07-19 01:30:24 -07:00
|
|
|
|
|
|
|
// Determine the access modifier used in this context.
|
|
|
|
nsIDocument* document = mContent->GetCurrentDoc();
|
|
|
|
if (!document)
|
|
|
|
return KeyBinding();
|
|
|
|
nsCOMPtr<nsISupports> container = document->GetContainer();
|
|
|
|
if (!container)
|
|
|
|
return KeyBinding();
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(container));
|
|
|
|
if (!treeItem)
|
|
|
|
return KeyBinding();
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
PRInt32 itemType = 0, modifierMask = 0;
|
|
|
|
treeItem->GetItemType(&itemType);
|
|
|
|
switch (itemType) {
|
|
|
|
case nsIDocShellTreeItem::typeChrome:
|
|
|
|
rv = Preferences::GetInt("ui.key.chromeAccess", &modifierMask);
|
|
|
|
break;
|
|
|
|
case nsIDocShellTreeItem::typeContent:
|
|
|
|
rv = Preferences::GetInt("ui.key.contentAccess", &modifierMask);
|
|
|
|
break;
|
2007-08-28 23:52:46 -07:00
|
|
|
}
|
|
|
|
|
2011-07-19 01:30:24 -07:00
|
|
|
return NS_SUCCEEDED(rv) ? KeyBinding(key, modifierMask) : KeyBinding();
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyBinding
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::KeyboardShortcut() const
|
2011-07-19 01:30:24 -07:00
|
|
|
{
|
|
|
|
return KeyBinding();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-06-18 00:37:38 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetParent(nsIAccessible** aParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
2011-07-23 01:38:33 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-23 01:38:33 -07:00
|
|
|
NS_IF_ADDREF(*aParent = Parent());
|
2009-12-10 11:12:19 -08:00
|
|
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetNextSibling(nsIAccessible** aNextSibling)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aNextSibling);
|
2011-06-06 19:23:13 -07:00
|
|
|
*aNextSibling = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetPreviousSibling(nsIAccessible ** aPreviousSibling)
|
2007-09-28 13:55:46 -07:00
|
|
|
{
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aPreviousSibling);
|
2011-06-06 19:23:13 -07:00
|
|
|
*aPreviousSibling = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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
|
|
|
|
2011-04-06 22:17:54 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-05-25 03:53:45 -07:00
|
|
|
NS_IF_ADDREF(*aFirstChild = FirstChild());
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetLastChild(nsIAccessible** aLastChild)
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLastChild);
|
|
|
|
*aLastChild = nsnull;
|
2009-11-19 08:35:38 -08:00
|
|
|
|
2011-04-06 22:17:54 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-05-25 03:53:45 -07:00
|
|
|
NS_IF_ADDREF(*aLastChild = LastChild());
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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
|
|
|
|
2011-04-06 22:17:54 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
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)
|
2012-05-25 03:53:45 -07:00
|
|
|
aChildIndex = ChildCount() - 1;
|
2009-11-19 08:35:38 -08:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* 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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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
|
|
|
|
2011-04-06 22:17:54 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIMutableArray> children =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-05-25 03:53:45 -07:00
|
|
|
PRUint32 childCount = ChildCount();
|
|
|
|
for (PRUint32 childIdx = 0; childIdx < childCount; childIdx++) {
|
2009-12-10 11:12:19 -08:00
|
|
|
nsIAccessible* child = GetChildAt(childIdx);
|
2011-10-17 07:59:28 -07:00
|
|
|
children->AppendElement(child, 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;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::CanHaveAnonChildren()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute long childCount; */
|
2009-12-10 11:12:19 -08:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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
|
|
|
|
2011-04-06 22:17:54 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-05-25 03:53:45 -07:00
|
|
|
*aChildCount = ChildCount();
|
|
|
|
return NS_OK;
|
2009-11-19 08:35:38 -08:00
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
/* readonly attribute long indexInParent; */
|
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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
|
|
|
|
2011-06-13 02:08:40 -07:00
|
|
|
*aIndexInParent = IndexInParent();
|
2009-12-10 11:12:19 -08:00
|
|
|
return *aIndexInParent != -1 ? NS_OK : NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-26 22:14:09 -08:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::TranslateString(const nsString& aKey, nsAString& aStringOut)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-10 06:43:04 -07:00
|
|
|
nsCOMPtr<nsIStringBundleService> stringBundleService =
|
|
|
|
services::GetStringBundleService();
|
|
|
|
if (!stringBundleService)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-10 06:43:04 -07:00
|
|
|
nsCOMPtr<nsIStringBundle> stringBundle;
|
|
|
|
stringBundleService->CreateBundle(
|
|
|
|
"chrome://global-platform/locale/accessible.properties",
|
|
|
|
getter_AddRefs(stringBundle));
|
|
|
|
if (!stringBundle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsXPIDLString xsValue;
|
|
|
|
nsresult rv = stringBundle->GetStringFromName(aKey.get(), getter_Copies(xsValue));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
aStringOut.Assign(xsValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-05 19:45:11 -08:00
|
|
|
PRUint64
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::VisibilityState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-05 19:45:11 -08:00
|
|
|
PRUint64 vstates = states::INVISIBLE | states::OFFSCREEN;
|
|
|
|
|
|
|
|
nsIFrame* frame = GetFrame();
|
2012-01-23 10:24:13 -08:00
|
|
|
if (!frame)
|
|
|
|
return vstates;
|
|
|
|
|
2012-02-07 14:38:54 -08:00
|
|
|
nsIPresShell* shell(mDoc->PresShell());
|
2012-01-30 19:03:31 -08:00
|
|
|
if (!shell)
|
|
|
|
return vstates;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-05 19:45:11 -08:00
|
|
|
// We need to know if at least a kMinPixels around the object is visible,
|
|
|
|
// otherwise it will be marked states::OFFSCREEN.
|
|
|
|
const PRUint16 kMinPixels = 12;
|
|
|
|
const nsSize frameSize = frame->GetSize();
|
|
|
|
const nsRectVisibility rectVisibility =
|
2009-09-08 22:40:02 -07:00
|
|
|
shell->GetRectVisibility(frame, nsRect(nsPoint(0,0), frameSize),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(kMinPixels));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-05 19:45:11 -08:00
|
|
|
if (rectVisibility == nsRectVisibility_kVisible)
|
|
|
|
vstates &= ~states::OFFSCREEN;
|
|
|
|
|
|
|
|
// Zero area rects can occur in the first frame of a multi-frame text flow,
|
|
|
|
// in which case the rendered text is not empty and the frame should not be
|
|
|
|
// marked invisible.
|
|
|
|
// XXX Can we just remove this check? Why do we need to mark empty
|
|
|
|
// text invisible?
|
|
|
|
if (frame->GetType() == nsGkAtoms::textFrame &&
|
|
|
|
!(frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
|
|
|
|
frame->GetRect().IsEmpty()) {
|
|
|
|
nsAutoString renderedText;
|
|
|
|
frame->GetRenderedText(&renderedText, nsnull, nsnull, 0, 1);
|
|
|
|
if (renderedText.IsEmpty())
|
|
|
|
return vstates;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-23 08:41:26 -07:00
|
|
|
}
|
2009-09-08 22:40:02 -07:00
|
|
|
|
2012-01-30 19:03:31 -08:00
|
|
|
// XXX Do we really need to cross from content to chrome ancestor?
|
|
|
|
if (!frame->IsVisibleConsideringAncestors(nsIFrame::VISIBILITY_CROSS_CHROME_CONTENT_BOUNDARY))
|
|
|
|
return vstates;
|
|
|
|
|
2012-01-05 19:45:11 -08:00
|
|
|
// Assume we are visible enough.
|
|
|
|
return vstates &= ~states::INVISIBLE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::NativeState()
|
2007-04-02 08:56:24 -07:00
|
|
|
{
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint64 state = 0;
|
2011-08-04 02:54:06 -07:00
|
|
|
|
2012-06-12 07:30:59 -07:00
|
|
|
if (!IsInDocument())
|
2011-08-04 02:54:06 -07:00
|
|
|
state |= states::STALE;
|
|
|
|
|
2011-05-31 18:46:56 -07:00
|
|
|
if (mContent->IsElement()) {
|
2011-05-31 18:46:57 -07:00
|
|
|
nsEventStates elementState = mContent->AsElement()->State();
|
2011-05-31 18:46:56 -07:00
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
if (elementState.HasState(NS_EVENT_STATE_INVALID))
|
2011-05-31 18:46:56 -07:00
|
|
|
state |= states::INVALID;
|
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
if (elementState.HasState(NS_EVENT_STATE_REQUIRED))
|
2011-05-31 18:46:56 -07:00
|
|
|
state |= states::REQUIRED;
|
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
state |= NativeInteractiveState();
|
2011-09-27 18:46:11 -07:00
|
|
|
if (FocusMgr()->IsFocused(this))
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::FOCUSED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-05 19:45:11 -08:00
|
|
|
// Gather states::INVISIBLE and states::OFFSCREEN flags for this object.
|
|
|
|
state |= VisibilityState();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-05 09:45:48 -07:00
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (frame && (frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW))
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::FLOATING;
|
2007-09-05 09:45:48 -07:00
|
|
|
|
2009-08-23 22:13:05 -07:00
|
|
|
// Check if a XUL element has the popup attribute (an attached popup menu).
|
2012-07-17 07:41:59 -07:00
|
|
|
if (mContent->IsXUL()) {
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::popup))
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::HASPOPUP;
|
2009-08-23 22:13:05 -07:00
|
|
|
|
2012-07-17 07:41:59 -07:00
|
|
|
const nsStyleXUL *xulStyle = frame->GetStyleXUL();
|
|
|
|
if (xulStyle && frame->IsBoxFrame()) {
|
|
|
|
// In XUL all boxes are either vertical or horizontal
|
|
|
|
if (xulStyle->mBoxOrient == NS_STYLE_BOX_ORIENT_VERTICAL)
|
|
|
|
state |= states::VERTICAL;
|
|
|
|
else
|
|
|
|
state |= states::HORIZONTAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-17 02:37:37 -07:00
|
|
|
// Bypass the link states specialization for non links.
|
|
|
|
if (!mRoleMapEntry || mRoleMapEntry->roleRule == kUseNativeRole ||
|
|
|
|
mRoleMapEntry->role == roles::LINK)
|
|
|
|
state |= NativeLinkState();
|
2008-03-30 23:21:35 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
return state;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
PRUint64
|
|
|
|
Accessible::NativeInteractiveState() const
|
|
|
|
{
|
|
|
|
if (!mContent->IsElement())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (NativelyUnavailable())
|
|
|
|
return states::UNAVAILABLE;
|
|
|
|
|
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
if (frame && frame->IsFocusable())
|
|
|
|
return states::FOCUSABLE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-17 02:37:37 -07:00
|
|
|
PRUint64
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::NativeLinkState() const
|
2012-05-17 02:37:37 -07:00
|
|
|
{
|
|
|
|
// Expose linked state for simple xlink.
|
|
|
|
return nsCoreUtils::IsXLink(mContent) ? states::LINKED : 0;
|
|
|
|
}
|
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
bool
|
|
|
|
Accessible::NativelyUnavailable() const
|
|
|
|
{
|
|
|
|
if (mContent->IsHTML())
|
|
|
|
return mContent->AsElement()->State().HasState(NS_EVENT_STATE_DISABLED);
|
|
|
|
|
|
|
|
return mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* readonly attribute boolean focusedChild; */
|
2010-06-11 01:23:18 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetFocusedChild(nsIAccessible** aChild)
|
2011-07-15 15:58:49 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aChild);
|
|
|
|
*aChild = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-15 15:58:49 -07:00
|
|
|
NS_IF_ADDREF(*aChild = FocusedChild());
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
Accessible::FocusedChild()
|
2011-07-15 15:58:49 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* focus = FocusMgr()->FocusedAccessible();
|
2011-09-27 18:46:11 -07:00
|
|
|
if (focus && (focus == this || focus->Parent() == this))
|
|
|
|
return focus;
|
2011-07-15 15:58:49 -07:00
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
return nsnull;
|
2011-07-15 15:58:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
Accessible::ChildAtPoint(PRInt32 aX, PRInt32 aY,
|
|
|
|
EWhichChildAtPoint aWhichChild)
|
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);
|
2011-03-28 21:44:20 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
2009-05-11 03:57:28 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* fallbackAnswer = nsnull;
|
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
|
|
|
|
2011-03-28 21:44:20 -07:00
|
|
|
if (nsAccUtils::MustPrune(this)) // Do not dig any further
|
|
|
|
return fallbackAnswer;
|
2007-09-18 14:44:43 -07:00
|
|
|
|
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.
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* accDocument = Document();
|
2011-03-28 21:44:20 -07:00
|
|
|
NS_ENSURE_TRUE(accDocument, nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-18 11:50:31 -07:00
|
|
|
nsIFrame *frame = accDocument->GetFrame();
|
2011-03-28 21:44:20 -07:00
|
|
|
NS_ENSURE_TRUE(frame, nsnull);
|
2007-09-05 01:00:40 -07:00
|
|
|
|
|
|
|
nsPresContext *presContext = frame->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-22 19:16:57 -08:00
|
|
|
nsRect screenRect = frame->GetScreenRectInAppUnits();
|
|
|
|
nsPoint offset(presContext->DevPixelsToAppUnits(aX) - screenRect.x,
|
|
|
|
presContext->DevPixelsToAppUnits(aY) - screenRect.y);
|
2007-09-05 01:00:40 -07:00
|
|
|
|
2012-04-04 20:11:39 -07:00
|
|
|
nsIPresShell* presShell = presContext->PresShell();
|
2007-09-05 01:00:40 -07:00
|
|
|
nsIFrame *foundFrame = presShell->GetFrameForPoint(frame, offset);
|
2009-05-11 03:57:28 -07:00
|
|
|
|
|
|
|
nsIContent* content = nsnull;
|
2011-03-28 21:44:20 -07:00
|
|
|
if (!foundFrame || !(content = foundFrame->GetContent()))
|
|
|
|
return fallbackAnswer;
|
2007-09-05 01:00:40 -07:00
|
|
|
|
2010-06-30 19:18:08 -07:00
|
|
|
// Get accessible for the node with the point or the first accessible in
|
|
|
|
// the DOM parent chain.
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* contentDocAcc = GetAccService()->
|
2012-02-15 13:51:04 -08:00
|
|
|
GetDocAccessible(content->OwnerDoc());
|
2012-02-23 23:31:24 -08:00
|
|
|
|
2012-02-24 12:36:01 -08:00
|
|
|
// contentDocAcc in some circumstances can be NULL. See bug 729861
|
|
|
|
NS_ASSERTION(contentDocAcc, "could not get the document accessible");
|
|
|
|
if (!contentDocAcc)
|
|
|
|
return fallbackAnswer;
|
2012-02-23 23:31:24 -08:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* accessible = contentDocAcc->GetAccessibleOrContainer(content);
|
2011-03-28 21:44:20 -07:00
|
|
|
if (!accessible)
|
|
|
|
return fallbackAnswer;
|
2007-09-05 01:00:40 -07:00
|
|
|
|
2012-06-25 10:34:52 -07:00
|
|
|
// Hurray! We have an accessible for the frame that layout gave us.
|
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.
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = accessible;
|
2012-06-25 10:34:52 -07:00
|
|
|
while (child != this) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parent = child->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.
|
2011-03-28 21:44:20 -07:00
|
|
|
return fallbackAnswer;
|
2008-09-17 06:11:39 -07:00
|
|
|
}
|
|
|
|
|
2012-06-25 10:34:52 -07:00
|
|
|
// If we landed on a legitimate child of |this|, and we want the direct
|
|
|
|
// child, return it here.
|
|
|
|
if (parent == this && aWhichChild == eDirectChild)
|
|
|
|
return child;
|
2011-03-28 21:44:20 -07:00
|
|
|
|
|
|
|
child = parent;
|
2007-09-18 14:44:43 -07:00
|
|
|
}
|
2007-09-05 01:00:40 -07:00
|
|
|
|
2012-06-25 10:34:52 -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
|
|
|
|
// OuterDocAccessibles).
|
|
|
|
PRUint32 childCount = accessible->ChildCount();
|
|
|
|
for (PRUint32 childIdx = 0; childIdx < childCount; childIdx++) {
|
|
|
|
Accessible* child = accessible->GetChildAt(childIdx);
|
|
|
|
|
|
|
|
PRInt32 childX, childY, childWidth, childHeight;
|
|
|
|
child->GetBounds(&childX, &childY, &childWidth, &childHeight);
|
|
|
|
if (aX >= childX && aX < childX + childWidth &&
|
|
|
|
aY >= childY && aY < childY + childHeight &&
|
|
|
|
(child->State() & states::INVISIBLE) == 0) {
|
|
|
|
|
|
|
|
if (aWhichChild == eDeepestChild)
|
|
|
|
return child->ChildAtPoint(aX, aY, eDeepestChild);
|
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return accessible;
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetChildAtPoint(PRInt32 aX, PRInt32 aY,
|
|
|
|
nsIAccessible** aAccessible)
|
2009-05-11 03:57:28 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aAccessible);
|
|
|
|
*aAccessible = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-06-13 15:20:54 -07:00
|
|
|
NS_IF_ADDREF(*aAccessible = ChildAtPoint(aX, aY, eDirectChild));
|
2011-03-28 21:44:20 -07:00
|
|
|
return NS_OK;
|
2009-05-11 03:57:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIAccessible getDeepestChildAtPoint(in long x, in long y)
|
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetDeepestChildAtPoint(PRInt32 aX, PRInt32 aY,
|
|
|
|
nsIAccessible** aAccessible)
|
2009-05-11 03:57:28 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aAccessible);
|
|
|
|
*aAccessible = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-06-13 15:20:54 -07:00
|
|
|
NS_IF_ADDREF(*aAccessible = ChildAtPoint(aX, aY, eDeepestChild));
|
2011-03-28 21:44:20 -07:00
|
|
|
return NS_OK;
|
2009-05-11 03:57:28 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
void
|
|
|
|
Accessible::GetBoundsRect(nsRect& aTotalBounds, nsIFrame** aBoundingFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-10 06:31:27 -07:00
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
if (frame) {
|
|
|
|
*aBoundingFrame = nsLayoutUtils::GetContainingBlockForClientRect(frame);
|
|
|
|
aTotalBounds = nsLayoutUtils::
|
|
|
|
GetAllInFlowRectsUnion(frame, *aBoundingFrame,
|
|
|
|
nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void getBounds (out long x, out long y, out long width, out long height); */
|
2010-10-14 07:05:25 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetBounds(PRInt32* aX, PRInt32* aY,
|
|
|
|
PRInt32* aWidth, PRInt32* aHeight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-10-14 07:05:25 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aX);
|
|
|
|
*aX = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aY);
|
|
|
|
*aY = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
|
|
|
*aWidth = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aHeight);
|
|
|
|
*aHeight = 0;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-02-07 14:38:54 -08:00
|
|
|
nsIPresShell* presShell = mDoc->PresShell();
|
2010-10-14 07:05:25 -07:00
|
|
|
|
|
|
|
// This routine will get the entire rectangle for all the frames in this node.
|
2007-03-22 10:30:00 -07:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Primary Frame for node
|
|
|
|
// Another frame, same node <- Example
|
|
|
|
// Another frame, same node
|
|
|
|
|
|
|
|
nsRect unionRectTwips;
|
2010-10-14 07:05:25 -07:00
|
|
|
nsIFrame* boundingFrame = nsnull;
|
|
|
|
GetBoundsRect(unionRectTwips, &boundingFrame); // Unions up all primary frames for this node and all siblings after it
|
|
|
|
NS_ENSURE_STATE(boundingFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-10-14 07:05:25 -07:00
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
|
|
|
*aX = presContext->AppUnitsToDevPixels(unionRectTwips.x);
|
|
|
|
*aY = presContext->AppUnitsToDevPixels(unionRectTwips.y);
|
|
|
|
*aWidth = presContext->AppUnitsToDevPixels(unionRectTwips.width);
|
|
|
|
*aHeight = presContext->AppUnitsToDevPixels(unionRectTwips.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// We have the union of the rectangle, now we need to put it in absolute screen coords
|
2012-02-21 18:07:43 -08:00
|
|
|
nsIntRect orgRectPixels = boundingFrame->GetScreenRectInAppUnits().
|
|
|
|
ToNearestPixels(presContext->AppUnitsPerDevPixel());
|
2010-10-14 07:05:25 -07:00
|
|
|
*aX += orgRectPixels.x;
|
|
|
|
*aY += orgRectPixels.y;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Accessible::SetSelected(bool aSelect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
if (IsDefunct())
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* select = nsAccUtils::GetSelectableContainer(this, State());
|
2012-03-15 19:13:44 -07:00
|
|
|
if (select) {
|
|
|
|
if (select->State() & states::MULTISELECTABLE) {
|
|
|
|
if (mRoleMapEntry) {
|
|
|
|
if (aSelect) {
|
|
|
|
return mContent->SetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::aria_selected,
|
|
|
|
NS_LITERAL_STRING("true"), true);
|
|
|
|
}
|
|
|
|
return mContent->UnsetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::aria_selected, true);
|
2007-09-24 18:19:03 -07:00
|
|
|
}
|
2012-03-15 19:13:44 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-03-15 19:13:44 -07:00
|
|
|
|
|
|
|
return aSelect ? TakeFocus() : NS_ERROR_FAILURE;
|
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
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Accessible::TakeSelection()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
if (IsDefunct())
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* select = nsAccUtils::GetSelectableContainer(this, State());
|
2012-03-15 19:13:44 -07:00
|
|
|
if (select) {
|
|
|
|
if (select->State() & states::MULTISELECTABLE)
|
|
|
|
select->ClearSelection();
|
2011-10-17 07:59:28 -07:00
|
|
|
return SetSelected(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2008-04-22 23:04:53 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::TakeFocus()
|
2008-04-22 23:04:53 -07:00
|
|
|
{
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
NS_ENSURE_STATE(frame);
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent* focusContent = mContent;
|
|
|
|
|
2011-12-08 04:20:15 -08:00
|
|
|
// If the accessible focus is managed by container widget then focus the
|
|
|
|
// widget and set the accessible as its current item.
|
2008-04-22 23:04:53 -07:00
|
|
|
if (!frame->IsFocusable()) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* widget = ContainerWidget();
|
2011-12-08 04:20:15 -08:00
|
|
|
if (widget && widget->AreItemsOperable()) {
|
|
|
|
nsIContent* widgetElm = widget->GetContent();
|
|
|
|
nsIFrame* widgetFrame = widgetElm->GetPrimaryFrame();
|
|
|
|
if (widgetFrame && widgetFrame->IsFocusable()) {
|
|
|
|
focusContent = widgetElm;
|
|
|
|
widget->SetCurrentItem(this);
|
2008-04-22 23:04:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(focusContent));
|
2012-02-11 18:34:00 -08:00
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
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
|
|
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetHTMLName(nsAString& aLabel)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-11-19 18:37:18 -08:00
|
|
|
nsAutoString label;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* labelAcc = nsnull;
|
2011-11-09 14:52:00 -08:00
|
|
|
HTMLLabelIterator iter(Document(), this);
|
2010-11-19 18:37:18 -08:00
|
|
|
while ((labelAcc = iter.Next())) {
|
|
|
|
nsresult rv = nsTextEquivUtils::
|
|
|
|
AppendTextEquivFromContent(this, labelAcc->GetContent(), &label);
|
2008-10-13 01:58:58 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
label.CompressWhitespace();
|
|
|
|
}
|
|
|
|
|
2010-11-19 18:37:18 -08:00
|
|
|
if (label.IsEmpty())
|
|
|
|
return nsTextEquivUtils::GetNameFromSubtree(this, aLabel);
|
|
|
|
|
|
|
|
aLabel = label;
|
|
|
|
return NS_OK;
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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();
|
2010-11-19 18:37:18 -08:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* labelAcc = nsnull;
|
2011-11-09 14:52:00 -08:00
|
|
|
XULLabelIterator iter(Document(), mContent);
|
2010-11-19 18:37:18 -08:00
|
|
|
while ((labelAcc = iter.Next())) {
|
|
|
|
nsCOMPtr<nsIDOMXULLabelElement> xulLabel =
|
|
|
|
do_QueryInterface(labelAcc->GetContent());
|
|
|
|
// Check if label's value attribute is used
|
|
|
|
if (xulLabel && NS_SUCCEEDED(xulLabel->GetValue(label)) && label.IsEmpty()) {
|
|
|
|
// If no value attribute, a non-empty label must contain
|
|
|
|
// children that define its text -- possibly using HTML
|
|
|
|
nsTextEquivUtils::
|
|
|
|
AppendTextEquivFromContent(this, labelAcc->GetContent(), &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) {
|
2011-06-03 14:35:17 -07:00
|
|
|
if (parent->Tag() == nsGkAtoms::toolbaritem &&
|
|
|
|
parent->GetAttr(kNameSpaceID_None, nsGkAtoms::title, label)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::HandleAccEvent(AccEvent* aEvent)
|
2007-04-12 23:03:30 -07:00
|
|
|
{
|
2007-04-24 11:20:52 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aEvent);
|
|
|
|
|
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);
|
|
|
|
|
2010-08-24 19:08:28 -07:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> observers;
|
|
|
|
obsService->EnumerateObservers(NS_ACCESSIBLE_EVENT_TOPIC,
|
|
|
|
getter_AddRefs(observers));
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(observers);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasObservers = false;
|
2010-08-24 19:08:28 -07:00
|
|
|
observers->HasMoreElements(&hasObservers);
|
|
|
|
if (hasObservers) {
|
|
|
|
nsRefPtr<nsAccEvent> evnt(aEvent->CreateXPCOMObject());
|
|
|
|
return obsService->NotifyObservers(evnt, NS_ACCESSIBLE_EVENT_TOPIC, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-03-07 07:38:58 -08:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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;
|
|
|
|
|
2010-09-05 20:33:29 -07:00
|
|
|
*aRole = Role();
|
2010-09-04 19:14:01 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-07 02:07:24 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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;
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::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
|
2011-04-09 16:38:06 -07:00
|
|
|
if (State() & states::CHECKABLE)
|
2011-06-03 14:35:17 -07:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::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)
|
2012-05-29 17:51:00 -07:00
|
|
|
GroupPos groupPos = GroupPosition();
|
|
|
|
nsAccUtils::SetAccGroupAttrs(attributes, groupPos.level,
|
|
|
|
groupPos.setSize, groupPos.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;
|
2011-06-03 14:35:17 -07:00
|
|
|
nsAccUtils::GetAccAttr(attributes, nsGkAtoms::live, live);
|
2009-02-18 22:56:19 -08:00
|
|
|
if (live.IsEmpty()) {
|
2009-08-27 22:27:27 -07:00
|
|
|
if (nsAccUtils::GetLiveAttrValue(mRoleMapEntry->liveAttRule, live))
|
2011-06-03 14:35:17 -07:00
|
|
|
nsAccUtils::SetAccAttr(attributes, nsGkAtoms::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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
|
2007-04-07 02:07:24 -07:00
|
|
|
{
|
2012-03-25 21:42:28 -07:00
|
|
|
// If the accessible isn't primary for its node (such as list item bullet or
|
|
|
|
// xul tree item then don't calculate content based attributes.
|
2012-03-25 21:37:07 -07:00
|
|
|
if (!IsPrimaryForNode())
|
|
|
|
return NS_OK;
|
|
|
|
|
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
|
2007-04-07 02:07:24 -07:00
|
|
|
|
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;
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, _class))
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::_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
|
2012-03-25 21:37:07 -07:00
|
|
|
nsIContent* startContent = mContent;
|
|
|
|
while (startContent) {
|
|
|
|
nsIDocument* doc = startContent->GetDocument();
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent* rootContent = nsCoreUtils::GetRoleContent(doc);
|
2012-03-25 21:37:07 -07:00
|
|
|
if (!rootContent)
|
|
|
|
return NS_OK;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-02-20 07:45:29 -08:00
|
|
|
if (!mContent->IsElement())
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-03-25 21:37:07 -07:00
|
|
|
// Expose tag.
|
|
|
|
nsAutoString tagName;
|
|
|
|
mContent->NodeInfo()->GetName(tagName);
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::tag, tagName);
|
|
|
|
|
2012-03-09 06:20:17 -08:00
|
|
|
// Expose draggable object attribute?
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(mContent);
|
|
|
|
if (htmlElement) {
|
|
|
|
bool draggable = false;
|
|
|
|
htmlElement->GetDraggable(&draggable);
|
|
|
|
if (draggable) {
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::draggable,
|
|
|
|
NS_LITERAL_STRING("true"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't calculate CSS-based object attributes when no frame (i.e.
|
2012-03-25 21:42:28 -07:00
|
|
|
// the accessible is unattached from the tree).
|
2012-03-25 21:37:07 -07:00
|
|
|
if (!mContent->GetPrimaryFrame())
|
2012-03-09 06:20:17 -08:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-02-20 07:45:29 -08:00
|
|
|
// CSS style based object attributes.
|
2008-10-28 04:54:57 -07:00
|
|
|
nsAutoString value;
|
2012-02-20 07:45:29 -08:00
|
|
|
StyleInfo styleInfo(mContent->AsElement(), mDoc->PresShell());
|
|
|
|
|
|
|
|
// Expose 'display' attribute.
|
|
|
|
styleInfo.Display(value);
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::display, value);
|
2008-10-28 04:54:57 -07:00
|
|
|
|
|
|
|
// Expose 'text-align' attribute.
|
2012-02-20 07:45:29 -08:00
|
|
|
styleInfo.TextAlign(value);
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::textAlign, value);
|
2008-10-28 04:54:57 -07:00
|
|
|
|
|
|
|
// Expose 'text-indent' attribute.
|
2012-02-20 07:45:29 -08:00
|
|
|
styleInfo.TextIndent(value);
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::textIndent, value);
|
2008-10-28 04:54:57 -07:00
|
|
|
|
2012-02-06 09:18:25 -08:00
|
|
|
// Expose 'margin-left' attribute.
|
2012-02-20 07:45:29 -08:00
|
|
|
styleInfo.MarginLeft(value);
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::marginLeft, value);
|
2012-02-06 09:18:25 -08:00
|
|
|
|
|
|
|
// Expose 'margin-right' attribute.
|
2012-02-20 07:45:29 -08:00
|
|
|
styleInfo.MarginRight(value);
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::marginRight, value);
|
2012-02-06 09:18:25 -08:00
|
|
|
|
|
|
|
// Expose 'margin-top' attribute.
|
2012-02-20 07:45:29 -08:00
|
|
|
styleInfo.MarginTop(value);
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::marginTop, value);
|
2012-02-06 09:18:25 -08:00
|
|
|
|
|
|
|
// Expose 'margin-bottom' attribute.
|
2012-02-20 07:45:29 -08:00
|
|
|
styleInfo.MarginBottom(value);
|
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::marginBottom, value);
|
2012-02-06 09:18:25 -08:00
|
|
|
|
2007-04-07 02:07:24 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-29 17:51:00 -07:00
|
|
|
GroupPos
|
|
|
|
Accessible::GroupPosition()
|
2007-03-27 05:17:11 -07:00
|
|
|
{
|
2012-05-29 17:51:00 -07:00
|
|
|
GroupPos groupPos;
|
2010-01-06 02:36:50 -08:00
|
|
|
|
|
|
|
// Get group position from ARIA attributes.
|
2012-05-29 17:51:00 -07:00
|
|
|
nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_level, &groupPos.level);
|
|
|
|
nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_setsize, &groupPos.setSize);
|
|
|
|
nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_posinset, &groupPos.posInSet);
|
2010-01-06 02:36:50 -08:00
|
|
|
|
|
|
|
// If ARIA is missed and the accessible is visible then calculate group
|
|
|
|
// position from hierarchy.
|
2011-04-09 16:38:06 -07:00
|
|
|
if (State() & states::INVISIBLE)
|
2012-05-29 17:51:00 -07:00
|
|
|
return groupPos;
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2010-01-06 02:36:50 -08:00
|
|
|
// Calculate group level if ARIA is missed.
|
2012-05-29 17:51:00 -07:00
|
|
|
if (groupPos.level == 0) {
|
2010-01-06 02:36:50 -08:00
|
|
|
PRInt32 level = GetLevelInternal();
|
|
|
|
if (level != 0)
|
2012-05-29 17:51:00 -07:00
|
|
|
groupPos.level = level;
|
2010-01-06 02:36:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate position in group and group size if ARIA is missed.
|
2012-05-29 17:51:00 -07:00
|
|
|
if (groupPos.posInSet == 0 || groupPos.setSize == 0) {
|
2010-01-06 02:36:50 -08:00
|
|
|
PRInt32 posInSet = 0, setSize = 0;
|
|
|
|
GetPositionAndSizeInternal(&posInSet, &setSize);
|
|
|
|
if (posInSet != 0 && setSize != 0) {
|
2012-05-29 17:51:00 -07:00
|
|
|
if (groupPos.posInSet == 0)
|
|
|
|
groupPos.posInSet = posInSet;
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2012-05-29 17:51:00 -07:00
|
|
|
if (groupPos.setSize == 0)
|
|
|
|
groupPos.setSize = setSize;
|
2010-01-06 02:36:50 -08:00
|
|
|
}
|
|
|
|
}
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2012-05-29 17:51:00 -07:00
|
|
|
return groupPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Accessible::GroupPosition(PRInt32* aGroupLevel,
|
|
|
|
PRInt32* aSimilarItemsInGroup,
|
|
|
|
PRInt32* aPositionInGroup)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aGroupLevel);
|
|
|
|
*aGroupLevel = 0;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aSimilarItemsInGroup);
|
|
|
|
*aSimilarItemsInGroup = 0;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aPositionInGroup);
|
|
|
|
*aPositionInGroup = 0;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
GroupPos groupPos = GroupPosition();
|
|
|
|
|
|
|
|
*aGroupLevel = groupPos.level;
|
|
|
|
*aSimilarItemsInGroup = groupPos.setSize;
|
|
|
|
*aPositionInGroup = groupPos.posInSet;
|
|
|
|
|
2007-03-27 05:17:11 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-02 08:56:24 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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);
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
nsAccUtils::To32States(State(), aState, aExtraState);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint64
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::State()
|
2011-04-09 16:38:06 -07:00
|
|
|
{
|
2011-04-11 23:18:42 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return states::DEFUNCT;
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2011-04-11 23:18:42 -07:00
|
|
|
PRUint64 state = NativeState();
|
2011-05-24 07:02:44 -07:00
|
|
|
// Apply ARIA states to be sure accessible states will be overridden.
|
2011-04-09 16:38:06 -07:00
|
|
|
ApplyARIAState(&state);
|
2007-08-08 06:46:38 -07:00
|
|
|
|
2012-01-21 03:06:26 -08:00
|
|
|
// If this is an ARIA item of the selectable widget and if it's focused and
|
|
|
|
// not marked unselected explicitly (i.e. aria-selected="false") then expose
|
|
|
|
// it as selected to make ARIA widget authors life easier.
|
|
|
|
if (mRoleMapEntry && !(state & states::SELECTED) &&
|
2011-05-24 07:02:44 -07:00
|
|
|
!mContent->AttrValueIs(kNameSpaceID_None,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_selected,
|
|
|
|
nsGkAtoms::_false, eCaseMatters)) {
|
2012-01-21 03:06:26 -08:00
|
|
|
// Special case for tabs: focused tab or focus inside related tab panel
|
|
|
|
// implies selected state.
|
|
|
|
if (mRoleMapEntry->role == roles::PAGETAB) {
|
|
|
|
if (state & states::FOCUSED) {
|
|
|
|
state |= states::SELECTED;
|
|
|
|
} else {
|
|
|
|
// If focus is in a child of the tab panel surely the tab is selected!
|
|
|
|
Relation rel = RelationByType(nsIAccessibleRelation::RELATION_LABEL_FOR);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* relTarget = nsnull;
|
2012-01-21 03:06:26 -08:00
|
|
|
while ((relTarget = rel.Next())) {
|
|
|
|
if (relTarget->Role() == roles::PROPERTYPAGE &&
|
|
|
|
FocusMgr()->IsFocusWithin(relTarget))
|
|
|
|
state |= states::SELECTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (state & states::FOCUSED) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* container = nsAccUtils::GetSelectableContainer(this, state);
|
2012-01-21 03:06:26 -08:00
|
|
|
if (container &&
|
|
|
|
!nsAccUtils::HasDefinedARIAToken(container->GetContent(),
|
|
|
|
nsGkAtoms::aria_multiselectable)) {
|
|
|
|
state |= states::SELECTED;
|
2007-10-03 02:31:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
const PRUint32 kExpandCollapseStates = states::COLLAPSED | states::EXPANDED;
|
|
|
|
if ((state & kExpandCollapseStates) == kExpandCollapseStates) {
|
2008-10-07 22:27:24 -07:00
|
|
|
// 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.
|
2011-04-09 16:38:06 -07:00
|
|
|
state &= ~states::COLLAPSED;
|
2008-10-07 22:27:24 -07:00
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
if (!(state & states::UNAVAILABLE)) {
|
|
|
|
state |= states::ENABLED | states::SENSITIVE;
|
2011-12-07 01:10:22 -08:00
|
|
|
|
|
|
|
// If the object is a current item of container widget then mark it as
|
|
|
|
// ACTIVE. 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.
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* widget = ContainerWidget();
|
2011-12-07 01:10:22 -08:00
|
|
|
if (widget && widget->CurrentItem() == this)
|
|
|
|
state |= states::ACTIVE;
|
2007-09-20 19:58:29 -07:00
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
if ((state & states::COLLAPSED) || (state & states::EXPANDED))
|
|
|
|
state |= states::EXPANDABLE;
|
2007-08-29 06:36:07 -07:00
|
|
|
|
2007-09-20 19:58:29 -07:00
|
|
|
// For some reasons DOM node may have not a frame. We tract such accessibles
|
|
|
|
// as invisible.
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (!frame)
|
2011-04-09 16:38:06 -07:00
|
|
|
return state;
|
2007-09-20 19:58:29 -07:00
|
|
|
|
|
|
|
const nsStyleDisplay* display = frame->GetStyleDisplay();
|
|
|
|
if (display && display->mOpacity == 1.0f &&
|
2011-04-09 16:38:06 -07:00
|
|
|
!(state & states::INVISIBLE)) {
|
|
|
|
state |= states::OPAQUE1;
|
2007-09-20 19:58:29 -07:00
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
return state;
|
2007-04-02 08:56:24 -07:00
|
|
|
}
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::ApplyARIAState(PRUint64* aState) const
|
2007-04-02 08:56:24 -07:00
|
|
|
{
|
2012-04-05 09:23:30 -07:00
|
|
|
if (!mContent->IsElement())
|
|
|
|
return;
|
|
|
|
|
|
|
|
dom::Element* element = mContent->AsElement();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Test for universal states first
|
2012-07-10 18:00:30 -07:00
|
|
|
*aState |= aria::UniversalStatesFor(element);
|
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.
|
2012-01-11 19:07:35 -08:00
|
|
|
if (mRoleMapEntry->role != roles::NOTHING)
|
2011-04-09 16:38:06 -07:00
|
|
|
*aState &= ~states::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) {
|
2011-06-03 14:35:17 -07:00
|
|
|
if (ancestorContent->HasAttr(kNameSpaceID_None, nsGkAtoms::aria_activedescendant)) {
|
2008-06-15 22:45:58 -07:00
|
|
|
// ancestor has activedescendant property, this content could be active
|
2011-04-09 16:38:06 -07:00
|
|
|
*aState |= states::FOCUSABLE;
|
2008-06-15 22:45:58 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
if (*aState & states::FOCUSABLE) {
|
2008-06-15 22:45:58 -07:00
|
|
|
// 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) {
|
2011-06-03 14:35:17 -07:00
|
|
|
if (ancestorContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::aria_disabled,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
2008-06-15 22:45:58 -07:00
|
|
|
// ancestor has aria-disabled property, this is disabled
|
2011-04-09 16:38:06 -07:00
|
|
|
*aState |= states::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)
|
2011-04-09 16:38:06 -07:00
|
|
|
return;
|
2008-06-15 22:45:58 -07:00
|
|
|
|
2008-03-29 14:52:14 -07:00
|
|
|
*aState |= mRoleMapEntry->state;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-04-05 09:23:30 -07:00
|
|
|
if (aria::MapToState(mRoleMapEntry->attributeMap1, element, aState) &&
|
|
|
|
aria::MapToState(mRoleMapEntry->attributeMap2, element, aState))
|
|
|
|
aria::MapToState(mRoleMapEntry->attributeMap3, element, aState);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-30 23:21:35 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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;
|
|
|
|
|
2012-04-09 02:48:41 -07:00
|
|
|
nsAutoString value;
|
|
|
|
Value(value);
|
|
|
|
aValue.Assign(value);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::Value(nsString& aValue)
|
2012-04-09 02:48:41 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mRoleMapEntry) {
|
2012-04-09 02:48:41 -07:00
|
|
|
if (mRoleMapEntry->valueRule == eNoValue)
|
|
|
|
return;
|
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,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_valuetext, aValue)) {
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_valuenow,
|
2010-06-11 01:23:18 -07:00
|
|
|
aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2008-03-30 23:21:35 -07:00
|
|
|
|
|
|
|
if (!aValue.IsEmpty())
|
2012-04-09 02:48:41 -07:00
|
|
|
return;
|
2008-03-30 23:21:35 -07:00
|
|
|
|
2008-10-01 23:49:45 -07:00
|
|
|
// Check if it's a simple xlink.
|
2012-05-23 23:57:16 -07:00
|
|
|
if (nsCoreUtils::IsXLink(mContent))
|
|
|
|
nsContentUtils::GetLinkLocation(mContent->AsElement(), aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
// nsIAccessibleValue
|
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetMaximumValue(double *aMaximumValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-03 14:35:17 -07:00
|
|
|
return GetAttrValue(nsGkAtoms::aria_valuemax, aMaximumValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetMinimumValue(double *aMinimumValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-03 14:35:17 -07:00
|
|
|
return GetAttrValue(nsGkAtoms::aria_valuemin, aMinimumValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetCurrentValue(double *aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-03 14:35:17 -07:00
|
|
|
return GetAttrValue(nsGkAtoms::aria_valuenow, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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;
|
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
const PRUint32 kValueCannotChange = states::READONLY | states::UNAVAILABLE;
|
2007-08-03 22:27:27 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
if (State() & 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,
|
2011-10-17 07:59:28 -07:00
|
|
|
nsGkAtoms::aria_valuenow, newValue, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void setName (in DOMString name); */
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Accessible::SetName(const nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-06-09 02:49:21 -07:00
|
|
|
Accessible::GetKeyboardShortcut(nsAString& aKeyBinding)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aKeyBinding.Truncate();
|
2011-07-19 01:30:24 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
KeyboardShortcut().ToString(aKeyBinding);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::ARIATransformRole(role aRole)
|
2010-09-05 20:33:29 -07:00
|
|
|
{
|
|
|
|
// XXX: these unfortunate exceptions don't fit into the ARIA table. This is
|
|
|
|
// where the accessible role depends on both the role and ARIA state.
|
2012-03-29 17:04:06 -07:00
|
|
|
if (aRole == roles::PUSHBUTTON) {
|
2011-06-03 14:35:17 -07:00
|
|
|
if (nsAccUtils::HasDefinedARIAToken(mContent, nsGkAtoms::aria_pressed)) {
|
2010-09-05 20:33:29 -07:00
|
|
|
// For simplicity, any existing pressed attribute except "" or "undefined"
|
|
|
|
// indicates a toggle.
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::TOGGLE_BUTTON;
|
2010-09-05 20:33:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_haspopup,
|
|
|
|
nsGkAtoms::_true,
|
2010-09-05 20:33:29 -07:00
|
|
|
eCaseMatters)) {
|
|
|
|
// For button with aria-haspopup="true".
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::BUTTONMENU;
|
2010-09-05 20:33:29 -07:00
|
|
|
}
|
|
|
|
|
2012-03-29 17:04:06 -07:00
|
|
|
} else if (aRole == roles::LISTBOX) {
|
2010-09-05 20:33:29 -07:00
|
|
|
// A listbox inside of a combobox needs a special role because of ATK
|
|
|
|
// mapping to menu.
|
2012-01-11 19:07:35 -08:00
|
|
|
if (mParent && mParent->Role() == roles::COMBOBOX) {
|
|
|
|
return roles::COMBOBOX_LIST;
|
2010-09-05 20:33:29 -07:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
Relation rel = RelationByType(nsIAccessibleRelation::RELATION_NODE_CHILD_OF);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* targetAcc = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((targetAcc = rel.Next()))
|
2012-01-11 19:07:35 -08:00
|
|
|
if (targetAcc->Role() == roles::COMBOBOX)
|
|
|
|
return roles::COMBOBOX_LIST;
|
2010-09-05 20:33:29 -07:00
|
|
|
}
|
|
|
|
|
2012-03-29 17:04:06 -07:00
|
|
|
} else if (aRole == roles::OPTION) {
|
2012-01-11 19:07:35 -08:00
|
|
|
if (mParent && mParent->Role() == roles::COMBOBOX_LIST)
|
|
|
|
return roles::COMBOBOX_OPTION;
|
2010-09-05 20:33:29 -07:00
|
|
|
}
|
|
|
|
|
2012-03-29 17:04:06 -07:00
|
|
|
return aRole;
|
2010-09-05 20:33:29 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return nsCoreUtils::IsXLink(mContent) ? roles::LINK : roles::NOTHING;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-26 08:47:22 -07:00
|
|
|
// readonly attribute PRUint8 actionCount
|
2008-03-15 18:23:41 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetActionCount(PRUint8* aActionCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-05 12:35:43 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aActionCount);
|
|
|
|
*aActionCount = 0;
|
2008-03-15 18:23:41 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-06-05 12:35:43 -07:00
|
|
|
*aActionCount = ActionCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-05 12:35:43 -07:00
|
|
|
PRUint8
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::ActionCount()
|
2011-06-05 12:35:43 -07:00
|
|
|
{
|
2012-06-03 22:41:06 -07:00
|
|
|
return GetActionRule() == eNoAction ? 0 : 1;
|
2011-06-05 12:35:43 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* DOMString getAccActionName (in PRUint8 index); */
|
2008-03-15 18:23:41 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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;
|
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
PRUint32 actionRule = GetActionRule();
|
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;
|
|
|
|
|
2012-02-01 17:13:09 -08:00
|
|
|
case ePressAction:
|
|
|
|
aName.AssignLiteral("press");
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
case eCheckUncheckAction:
|
2012-06-03 22:41:06 -07:00
|
|
|
{
|
|
|
|
PRUint64 state = State();
|
|
|
|
if (state & states::CHECKED)
|
2008-10-08 05:54:58 -07:00
|
|
|
aName.AssignLiteral("uncheck");
|
2012-06-03 22:41:06 -07:00
|
|
|
else if (state & states::MIXED)
|
2009-03-09 23:03:21 -07:00
|
|
|
aName.AssignLiteral("cycle");
|
2008-10-08 05:54:58 -07:00
|
|
|
else
|
|
|
|
aName.AssignLiteral("check");
|
|
|
|
return NS_OK;
|
2012-06-03 22:41:06 -07:00
|
|
|
}
|
2008-10-08 05:54:58 -07:00
|
|
|
|
|
|
|
case eJumpAction:
|
|
|
|
aName.AssignLiteral("jump");
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eOpenCloseAction:
|
2012-06-03 22:41:06 -07:00
|
|
|
if (State() & states::COLLAPSED)
|
2008-10-08 05:54:58 -07:00
|
|
|
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;
|
2012-06-03 22:41:06 -07:00
|
|
|
|
2009-04-19 23:06:19 -07:00
|
|
|
case eSortAction:
|
|
|
|
aName.AssignLiteral("sort");
|
|
|
|
return NS_OK;
|
2012-06-03 22:41:06 -07:00
|
|
|
|
2009-04-19 23:06:19 -07:00
|
|
|
case eExpandAction:
|
2012-06-03 22:41:06 -07:00
|
|
|
if (State() & states::COLLAPSED)
|
2009-04-19 23:06:19 -07:00
|
|
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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);
|
|
|
|
|
2012-01-26 22:14:09 -08:00
|
|
|
TranslateString(name, aDescription);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
// void doAction(in PRUint8 index)
|
2008-03-15 18:23:41 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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;
|
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
if (GetActionRule() != 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 (); */
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP Accessible::GetHelp(nsAString& _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
nsIContent*
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetAtomicRegion() const
|
2007-09-18 14:40:04 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent *loopContent = mContent;
|
2007-09-18 14:40:04 -07:00
|
|
|
nsAutoString atomic;
|
2011-06-03 14:35:17 -07:00
|
|
|
while (loopContent && !loopContent->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_atomic, atomic))
|
2007-09-18 14:40:04 -07:00
|
|
|
loopContent = loopContent->GetParent();
|
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
return atomic.EqualsLiteral("true") ? loopContent : nsnull;
|
2007-09-18 14:40:04 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-02-10 02:03:30 -08:00
|
|
|
// nsIAccessible getRelationByType()
|
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetRelationByType(PRUint32 aType,
|
2011-08-09 18:44:00 -07:00
|
|
|
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;
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
Relation rel = RelationByType(aType);
|
|
|
|
NS_ADDREF(*aRelation = new nsAccessibleRelation(aType, &rel));
|
|
|
|
return *aRelation ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Relation
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::RelationByType(PRUint32 aType)
|
2011-08-09 18:44:00 -07:00
|
|
|
{
|
2009-02-10 02:03:30 -08:00
|
|
|
// Relationships are defined on the same content node that the role would be
|
|
|
|
// defined on.
|
2011-08-09 18:44:00 -07:00
|
|
|
switch (aType) {
|
|
|
|
case nsIAccessibleRelation::RELATION_LABEL_FOR: {
|
2011-11-09 14:52:00 -08:00
|
|
|
Relation rel(new RelatedAccIterator(Document(), mContent,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_labelledby));
|
|
|
|
if (mContent->Tag() == nsGkAtoms::label)
|
2012-03-22 22:26:52 -07:00
|
|
|
rel.AppendIter(new IDRefsIterator(mDoc, mContent, mContent->IsHTML() ?
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::_for :
|
|
|
|
nsGkAtoms::control));
|
2011-08-09 18:44:00 -07:00
|
|
|
|
|
|
|
return rel;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_LABELLED_BY: {
|
2012-03-22 22:26:52 -07:00
|
|
|
Relation rel(new IDRefsIterator(mDoc, mContent,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_labelledby));
|
2010-11-19 18:37:18 -08:00
|
|
|
if (mContent->IsHTML()) {
|
2011-11-09 14:52:00 -08:00
|
|
|
rel.AppendIter(new HTMLLabelIterator(Document(), this));
|
2011-08-09 18:44:00 -07:00
|
|
|
} else if (mContent->IsXUL()) {
|
2011-11-09 14:52:00 -08:00
|
|
|
rel.AppendIter(new XULLabelIterator(Document(), mContent));
|
2010-11-19 18:37:18 -08:00
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
return rel;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_DESCRIBED_BY: {
|
2012-03-22 22:26:52 -07:00
|
|
|
Relation rel(new IDRefsIterator(mDoc, mContent,
|
|
|
|
nsGkAtoms::aria_describedby));
|
2011-08-09 18:44:00 -07:00
|
|
|
if (mContent->IsXUL())
|
2011-11-09 14:52:00 -08:00
|
|
|
rel.AppendIter(new XULDescriptionIterator(Document(), mContent));
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
return rel;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_DESCRIPTION_FOR: {
|
2011-11-09 14:52:00 -08:00
|
|
|
Relation rel(new RelatedAccIterator(Document(), mContent,
|
|
|
|
nsGkAtoms::aria_describedby));
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2011-08-09 18:44: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.
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->Tag() == nsGkAtoms::description &&
|
2011-08-09 18:44:00 -07:00
|
|
|
mContent->IsXUL())
|
2012-03-22 22:26:52 -07:00
|
|
|
rel.AppendIter(new IDRefsIterator(mDoc, mContent,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::control));
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
return rel;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_NODE_CHILD_OF: {
|
2011-11-09 14:52:00 -08:00
|
|
|
Relation rel(new RelatedAccIterator(Document(), mContent,
|
|
|
|
nsGkAtoms::aria_owns));
|
2011-08-09 18:44:00 -07:00
|
|
|
|
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.
|
2012-01-11 19:07:35 -08:00
|
|
|
if (mRoleMapEntry && (mRoleMapEntry->role == roles::OUTLINEITEM ||
|
2011-11-09 14:52:00 -08:00
|
|
|
mRoleMapEntry->role == roles::ROW)) {
|
2010-07-02 20:11:35 -07:00
|
|
|
AccGroupInfo* groupInfo = GetGroupInfo();
|
|
|
|
if (!groupInfo)
|
2011-08-09 18:44:00 -07:00
|
|
|
return rel;
|
2009-10-20 00:53:49 -07:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
rel.AppendTarget(groupInfo->ConceptualParent());
|
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);
|
2011-07-23 01:38:33 -07:00
|
|
|
if (scrollFrame || view->GetWidget() || !frame->GetParent())
|
2011-08-09 18:44:00 -07:00
|
|
|
rel.AppendTarget(Parent());
|
2008-03-05 19:45:43 -08:00
|
|
|
}
|
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
return rel;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_CONTROLLED_BY:
|
2011-11-09 14:52:00 -08:00
|
|
|
return Relation(new RelatedAccIterator(Document(), mContent,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_controls));
|
2011-08-09 18:44:00 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_CONTROLLER_FOR: {
|
2012-03-22 22:26:52 -07:00
|
|
|
Relation rel(new IDRefsIterator(mDoc, mContent,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_controls));
|
2011-11-09 14:52:00 -08:00
|
|
|
rel.AppendIter(new HTMLOutputIterator(Document(), mContent));
|
2011-08-09 18:44:00 -07:00
|
|
|
return rel;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_FLOWS_TO:
|
2012-03-22 22:26:52 -07:00
|
|
|
return Relation(new IDRefsIterator(mDoc, mContent,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_flowto));
|
2011-08-09 18:44:00 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_FLOWS_FROM:
|
2011-11-09 14:52:00 -08:00
|
|
|
return Relation(new RelatedAccIterator(Document(), mContent,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_flowto));
|
2011-08-09 18:44:00 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_DEFAULT_BUTTON: {
|
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) {
|
2010-05-09 12:33:00 -07:00
|
|
|
nsCOMPtr<nsIForm> form(do_QueryInterface(control->GetFormElement()));
|
2009-02-10 02:03:30 -08:00
|
|
|
if (form) {
|
|
|
|
nsCOMPtr<nsIContent> formContent =
|
|
|
|
do_QueryInterface(form->GetDefaultSubmitElement());
|
2012-05-07 17:00:29 -07:00
|
|
|
return Relation(mDoc, formContent);
|
2009-02-10 02:03:30 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
// In XUL, use first <button default="true" .../> in the document
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDoc =
|
2011-10-18 03:53:36 -07:00
|
|
|
do_QueryInterface(mContent->OwnerDoc());
|
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>
|
2012-05-27 21:52:53 -07:00
|
|
|
dom::Element* rootElm = mContent->OwnerDoc()->GetRootElement();
|
|
|
|
if (rootElm) {
|
|
|
|
nsIContent* possibleButtonEl = rootElm->OwnerDoc()->
|
|
|
|
GetAnonymousElementByAttribute(rootElm, nsGkAtoms::_default,
|
|
|
|
NS_LITERAL_STRING("true"));
|
|
|
|
buttonEl = do_QueryInterface(possibleButtonEl);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2009-02-10 02:03:30 -08:00
|
|
|
nsCOMPtr<nsIContent> relatedContent(do_QueryInterface(buttonEl));
|
2012-05-07 17:00:29 -07:00
|
|
|
return Relation(mDoc, relatedContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
return Relation();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
case nsIAccessibleRelation::RELATION_MEMBER_OF:
|
2012-05-07 17:00:29 -07:00
|
|
|
return Relation(mDoc, GetAtomicRegion());
|
2011-08-09 18:44:00 -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:
|
|
|
|
default:
|
|
|
|
return Relation();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-19 19:41:33 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetRelations(nsIArray **aRelations)
|
2007-05-19 19:41:33 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRelations);
|
2011-08-09 18:44:00 -07:00
|
|
|
*aRelations = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-05-19 19:41:33 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && relation) {
|
|
|
|
PRUint32 targets = 0;
|
|
|
|
relation->GetTargetsCount(&targets);
|
|
|
|
if (targets)
|
2011-10-17 07:59:28 -07:00
|
|
|
relations->AppendElement(relation, false);
|
2011-08-09 18:44:00 -07:00
|
|
|
}
|
2007-05-19 19:41:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aRelations = relations);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* void extendSelection (); */
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP Accessible::ExtendSelection()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// XXX Should be implemented, but not high priority
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [noscript] void getNativeInterface(out voidPtr aOutAccessible); */
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP Accessible::GetNativeInterface(void **aOutAccessible)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2010-01-25 07:09:25 -08:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::DoCommand(nsIContent *aContent, PRUint32 aActionIndex)
|
2009-08-19 23:45:19 -07:00
|
|
|
{
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::DispatchClickEvent(nsIContent *aContent, PRUint32 aActionIndex)
|
2009-08-19 23:45:19 -07:00
|
|
|
{
|
|
|
|
if (IsDefunct())
|
2008-08-06 05:16:54 -07:00
|
|
|
return;
|
|
|
|
|
2012-02-07 14:38:54 -08:00
|
|
|
nsIPresShell* presShell = mDoc->PresShell();
|
2008-08-06 05:16:54 -07:00
|
|
|
|
|
|
|
// Scroll into view.
|
2012-03-19 19:09:50 -07:00
|
|
|
presShell->ScrollContentIntoView(aContent,
|
|
|
|
nsIPresShell::ScrollAxis(),
|
|
|
|
nsIPresShell::ScrollAxis(),
|
2010-10-28 09:01:37 -07:00
|
|
|
nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
|
2008-08-06 05:16:54 -07:00
|
|
|
|
|
|
|
// Fire mouse down and mouse up events.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool 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
|
|
|
}
|
|
|
|
|
2012-02-07 05:18:33 -08:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::ScrollTo(PRUint32 aHow)
|
2012-02-07 05:18:33 -08:00
|
|
|
{
|
2012-05-09 06:17:03 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-04-09 17:39:00 -07:00
|
|
|
nsCoreUtils::ScrollTo(mDoc->PresShell(), mContent, aHow);
|
2012-02-07 05:18:33 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::ScrollToPoint(PRUint32 aCoordinateType, PRInt32 aX, PRInt32 aY)
|
2012-02-07 05:18:33 -08:00
|
|
|
{
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
if (!frame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsIntPoint coords;
|
|
|
|
nsresult rv = nsAccUtils::ConvertToScreenCoords(aX, aY, aCoordinateType,
|
|
|
|
this, &coords);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsIFrame *parentFrame = frame;
|
|
|
|
while ((parentFrame = parentFrame->GetParent()))
|
|
|
|
nsCoreUtils::ScrollFrameToPoint(parentFrame, frame, coords);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIAccessibleSelectable
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Accessible::GetSelectedChildren(nsIArray** aSelectedAccessibles)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-01 17:46:59 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aSelectedAccessibles);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aSelectedAccessibles = nsnull;
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
if (IsDefunct() || !IsSelect())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
nsCOMPtr<nsIArray> items = SelectedItems();
|
|
|
|
if (items) {
|
|
|
|
PRUint32 length = 0;
|
|
|
|
items->GetLength(&length);
|
|
|
|
if (length)
|
|
|
|
items.swap(*aSelectedAccessibles);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the nth selected descendant nsIAccessible object
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Accessible::RefSelection(PRInt32 aIndex, nsIAccessible** aSelected)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
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
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
if (IsDefunct() || !IsSelect())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
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-09-01 17:46:59 -07:00
|
|
|
*aSelected = GetSelectedItem(aIndex);
|
|
|
|
if (*aSelected) {
|
|
|
|
NS_ADDREF(*aSelected);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-09-01 17:46:59 -07:00
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Accessible::GetSelectionCount(PRInt32* aSelectionCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
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-09-01 17:46:59 -07:00
|
|
|
if (IsDefunct() || !IsSelect())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
*aSelectionCount = SelectedItemCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP Accessible::AddChildToSelection(PRInt32 aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-01 17:46:59 -07:00
|
|
|
if (IsDefunct() || !IsSelect())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
return aIndex >= 0 && AddItemToSelection(aIndex) ?
|
|
|
|
NS_OK : NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP Accessible::RemoveChildFromSelection(PRInt32 aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-01 17:46:59 -07:00
|
|
|
if (IsDefunct() || !IsSelect())
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
return aIndex >=0 && RemoveItemFromSelection(aIndex) ?
|
|
|
|
NS_OK : NS_ERROR_INVALID_ARG;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
NS_IMETHODIMP Accessible::IsChildSelected(PRInt32 aIndex, bool *aIsSelected)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-01 17:46:59 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsSelected = false;
|
2010-09-01 17:46:59 -07:00
|
|
|
|
|
|
|
if (IsDefunct() || !IsSelect())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(aIndex >= 0, NS_ERROR_FAILURE);
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
*aIsSelected = IsItemSelected(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-20 00:40:25 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::ClearSelection()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-01 17:46:59 -07:00
|
|
|
if (IsDefunct() || !IsSelect())
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
UnselectAll();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::SelectAllSelection(bool* aIsMultiSelect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-01 17:46:59 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aIsMultiSelect);
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsMultiSelect = false;
|
2010-09-01 17:46:59 -07:00
|
|
|
|
|
|
|
if (IsDefunct() || !IsSelect())
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
*aIsMultiSelect = SelectAll();
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetAnchorCount(PRInt32 *aAnchorCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-04-11 08:57:36 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aAnchorCount);
|
2010-08-31 20:26:13 -07:00
|
|
|
*aAnchorCount = 0;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*aAnchorCount = AnchorCount();
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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;
|
|
|
|
|
2010-08-31 20:26:13 -07:00
|
|
|
*aStartIndex = StartOffset();
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-30 08:33:01 -07:00
|
|
|
// readonly attribute long nsIAccessibleHyperLink::endIndex
|
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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;
|
|
|
|
|
2010-08-31 20:26:13 -07:00
|
|
|
*aEndIndex = EndOffset();
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-30 08:33:01 -07:00
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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);
|
2008-03-30 23:21:35 -07:00
|
|
|
|
2010-08-31 20:26:13 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-03-30 23:21:35 -07:00
|
|
|
|
2010-08-31 20:26:13 -07:00
|
|
|
if (aIndex < 0 || aIndex >= static_cast<PRInt32>(AnchorCount()))
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2008-03-30 23:21:35 -07:00
|
|
|
|
2011-07-03 02:53:40 -07:00
|
|
|
nsRefPtr<nsIURI>(AnchorURIAt(aIndex)).forget(aURI);
|
2008-03-30 23:21:35 -07:00
|
|
|
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
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetAnchor(PRInt32 aIndex, 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;
|
|
|
|
|
2010-08-31 20:26:13 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (aIndex < 0 || aIndex >= static_cast<PRInt32>(AnchorCount()))
|
2008-03-29 20:24:02 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2011-06-13 20:56:42 -07:00
|
|
|
NS_IF_ADDREF(*aAccessible = AnchorAt(aIndex));
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-30 08:33:01 -07:00
|
|
|
// readonly attribute boolean nsIAccessibleHyperLink::valid
|
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetValid(bool *aValid)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-30 08:33:01 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aValid);
|
2011-10-17 07:59:28 -07:00
|
|
|
*aValid = false;
|
2010-08-31 20:26:13 -07:00
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-06-21 22:43:25 -07:00
|
|
|
*aValid = IsLinkValid();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-30 08:33:01 -07:00
|
|
|
// readonly attribute boolean nsIAccessibleHyperLink::selected
|
|
|
|
NS_IMETHODIMP
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetSelected(bool *aSelected)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-30 08:33:01 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aSelected);
|
2011-10-17 07:59:28 -07:00
|
|
|
*aSelected = false;
|
2010-06-11 01:23:18 -07:00
|
|
|
|
2010-08-31 20:26:13 -07:00
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-05-17 09:15:52 -07:00
|
|
|
|
2011-06-13 17:26:32 -07:00
|
|
|
*aSelected = IsLinkSelected();
|
2010-08-31 20:26:13 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-31 19:00:24 -08:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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.
|
2011-01-31 19:00:24 -08:00
|
|
|
if (aStartOffset != 0 || aLength == 0)
|
|
|
|
return;
|
2010-06-09 20:29:56 -07:00
|
|
|
|
|
|
|
nsIFrame *frame = GetFrame();
|
2011-01-31 19:00:24 -08:00
|
|
|
if (!frame)
|
|
|
|
return;
|
2010-06-09 20:29:56 -07:00
|
|
|
|
2012-05-29 10:15:49 -07:00
|
|
|
NS_ASSERTION(mParent,
|
|
|
|
"Called on accessible unbound from tree. Result can be wrong.");
|
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
if (frame->GetType() == nsGkAtoms::brFrame) {
|
2010-06-09 20:29:56 -07:00
|
|
|
aText += kForcedNewLineChar;
|
2012-05-29 10:15:49 -07:00
|
|
|
} else if (mParent && nsAccUtils::MustPrune(mParent)) {
|
2011-02-03 06:29:05 -08:00
|
|
|
// Expose the embedded object accessible as imaginary embedded object
|
|
|
|
// character if its parent hypertext accessible doesn't expose children to
|
|
|
|
// AT.
|
2010-06-09 20:29:56 -07:00
|
|
|
aText += kImaginaryEmbeddedObjectChar;
|
|
|
|
} else {
|
|
|
|
aText += kEmbeddedObjectChar;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAccessNode public methods
|
|
|
|
|
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::Shutdown()
|
2010-06-11 21:04:35 -07:00
|
|
|
{
|
2012-03-28 08:59:01 -07:00
|
|
|
// Mark the accessible as defunct, invalidate the child count and pointers to
|
|
|
|
// other accessibles, also make sure none of its children point to this parent
|
|
|
|
mFlags |= eIsDefunct;
|
|
|
|
|
2010-06-11 21:04:35 -07:00
|
|
|
InvalidateChildren();
|
2010-10-20 21:16:10 -07:00
|
|
|
if (mParent)
|
|
|
|
mParent->RemoveChild(this);
|
2010-06-11 21:04:35 -07:00
|
|
|
|
|
|
|
nsAccessNodeWrap::Shutdown();
|
|
|
|
}
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible public methods
|
2008-10-10 05:26:55 -07:00
|
|
|
|
|
|
|
nsresult
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetARIAName(nsAString& aName)
|
2008-10-10 05:26:55 -07:00
|
|
|
{
|
|
|
|
nsAutoString label;
|
2010-08-06 06:58:15 -07:00
|
|
|
|
|
|
|
// aria-labelledby now takes precedence over aria-label
|
2009-02-18 23:06:14 -08:00
|
|
|
nsresult rv = nsTextEquivUtils::
|
2011-06-03 14:35:17 -07:00
|
|
|
GetTextEquivFromIDRefs(this, nsGkAtoms::aria_labelledby, label);
|
2009-02-18 23:06:14 -08:00
|
|
|
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
|
|
|
|
2010-08-06 06:58:15 -07:00
|
|
|
if (label.IsEmpty() &&
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_label,
|
2010-08-06 06:58:15 -07:00
|
|
|
label)) {
|
|
|
|
label.CompressWhitespace();
|
|
|
|
aName = label;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-10-10 05:26:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetNameInternal(nsAString& aName)
|
2008-10-10 05:26:55 -07:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible protected
|
2009-12-10 11:12:19 -08:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::BindToParent(Accessible* aParent, PRUint32 aIndexInParent)
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParent, "This method isn't used to set null parent!");
|
|
|
|
|
2010-10-20 21:16:10 -07:00
|
|
|
if (mParent) {
|
|
|
|
if (mParent != aParent) {
|
|
|
|
NS_ERROR("Adopting child!");
|
2011-03-28 21:44:07 -07:00
|
|
|
mParent->RemoveChild(this);
|
2010-10-20 21:16:10 -07:00
|
|
|
} else {
|
|
|
|
NS_ERROR("Binding to the same parent!");
|
|
|
|
return;
|
|
|
|
}
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
mParent = aParent;
|
2010-07-01 18:22:41 -07:00
|
|
|
mIndexInParent = aIndexInParent;
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
2010-07-16 07:15:03 -07:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::UnbindFromParent()
|
2010-07-16 07:15:03 -07:00
|
|
|
{
|
|
|
|
mParent = nsnull;
|
|
|
|
mIndexInParent = -1;
|
2010-08-15 04:28:49 -07:00
|
|
|
mIndexOfEmbeddedChild = -1;
|
2010-07-16 07:15:03 -07:00
|
|
|
mGroupInfo = nsnull;
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::InvalidateChildren()
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
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++) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = mChildren.ElementAt(childIdx);
|
2010-07-01 18:22:41 -07:00
|
|
|
child->UnbindFromParent();
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
2010-08-15 04:28:49 -07:00
|
|
|
mEmbeddedObjCollector = nsnull;
|
2009-12-10 11:12:19 -08:00
|
|
|
mChildren.Clear();
|
2011-01-27 21:15:04 -08:00
|
|
|
SetChildrenFlag(eChildrenUninitialized);
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::AppendChild(Accessible* aChild)
|
2010-07-01 18:22:41 -07:00
|
|
|
{
|
2010-11-09 02:21:56 -08:00
|
|
|
if (!aChild)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-09 02:21:56 -08:00
|
|
|
|
2010-07-01 18:22:41 -07:00
|
|
|
if (!mChildren.AppendElement(aChild))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-01 18:22:41 -07:00
|
|
|
|
2010-10-06 06:46:24 -07:00
|
|
|
if (!nsAccUtils::IsEmbeddedObject(aChild))
|
2011-01-27 21:15:04 -08:00
|
|
|
SetChildrenFlag(eMixedChildren);
|
2010-08-15 04:28:49 -07:00
|
|
|
|
2010-07-01 18:22:41 -07:00
|
|
|
aChild->BindToParent(this, mChildren.Length() - 1);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-07-01 18:22:41 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::InsertChildAt(PRUint32 aIndex, Accessible* aChild)
|
2010-07-01 18:22:41 -07:00
|
|
|
{
|
2010-11-09 02:21:56 -08:00
|
|
|
if (!aChild)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-09 02:21:56 -08:00
|
|
|
|
2010-07-01 18:22:41 -07:00
|
|
|
if (!mChildren.InsertElementAt(aIndex, aChild))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-01 18:22:41 -07:00
|
|
|
|
2010-11-09 02:21:56 -08:00
|
|
|
for (PRUint32 idx = aIndex + 1; idx < mChildren.Length(); idx++) {
|
|
|
|
NS_ASSERTION(mChildren[idx]->mIndexInParent == idx - 1, "Accessible child index doesn't match");
|
|
|
|
mChildren[idx]->mIndexInParent = idx;
|
|
|
|
}
|
2010-07-01 18:22:41 -07:00
|
|
|
|
2010-08-15 04:28:49 -07:00
|
|
|
if (nsAccUtils::IsText(aChild))
|
2011-01-27 21:15:04 -08:00
|
|
|
SetChildrenFlag(eMixedChildren);
|
2010-08-15 04:28:49 -07:00
|
|
|
|
|
|
|
mEmbeddedObjCollector = nsnull;
|
|
|
|
|
2010-07-01 18:22:41 -07:00
|
|
|
aChild->BindToParent(this, aIndex);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-07-01 18:22:41 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::RemoveChild(Accessible* aChild)
|
2010-07-01 18:22:41 -07:00
|
|
|
{
|
2010-11-09 02:21:56 -08:00
|
|
|
if (!aChild)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-09 02:21:56 -08:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
if (aChild->mParent != this || aChild->mIndexInParent == -1)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-01 18:22:41 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
PRUint32 index = static_cast<PRUint32>(aChild->mIndexInParent);
|
2010-11-09 02:21:56 -08:00
|
|
|
if (index >= mChildren.Length() || mChildren[index] != aChild) {
|
2010-10-25 06:01:30 -07:00
|
|
|
NS_ERROR("Child is bound to parent but parent hasn't this child at its index!");
|
|
|
|
aChild->UnbindFromParent();
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-10-25 06:01:30 -07:00
|
|
|
}
|
|
|
|
|
2010-11-09 02:21:56 -08:00
|
|
|
for (PRUint32 idx = index + 1; idx < mChildren.Length(); idx++) {
|
|
|
|
NS_ASSERTION(mChildren[idx]->mIndexInParent == idx, "Accessible child index doesn't match");
|
|
|
|
mChildren[idx]->mIndexInParent = idx - 1;
|
|
|
|
}
|
2010-07-01 18:22:41 -07:00
|
|
|
|
2010-11-09 02:21:56 -08:00
|
|
|
aChild->UnbindFromParent();
|
|
|
|
mChildren.RemoveElementAt(index);
|
2010-08-15 04:28:49 -07:00
|
|
|
mEmbeddedObjCollector = nsnull;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-07-01 18:22:41 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
Accessible::GetChildAt(PRUint32 aIndex)
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = mChildren.SafeElementAt(aIndex, nsnull);
|
2009-12-10 11:12:19 -08:00
|
|
|
if (!child)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* 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;
|
|
|
|
}
|
|
|
|
|
2012-05-25 03:53:45 -07:00
|
|
|
PRUint32
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::ChildCount() const
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
2011-04-06 22:17:54 -07:00
|
|
|
return mChildren.Length();
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetIndexOf(Accessible* aChild)
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
2011-06-13 02:08:40 -07:00
|
|
|
return (aChild->mParent != this) ? -1 : aChild->IndexInParent();
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::IndexInParent() const
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
2010-07-01 18:22:41 -07:00
|
|
|
return mIndexInParent;
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
2012-05-25 03:53:45 -07:00
|
|
|
PRUint32
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::EmbeddedChildCount()
|
2010-08-15 04:28:49 -07:00
|
|
|
{
|
2011-01-27 21:15:04 -08:00
|
|
|
if (IsChildrenFlag(eMixedChildren)) {
|
2010-08-15 04:28:49 -07:00
|
|
|
if (!mEmbeddedObjCollector)
|
|
|
|
mEmbeddedObjCollector = new EmbeddedObjCollector(this);
|
2012-05-25 03:53:45 -07:00
|
|
|
return mEmbeddedObjCollector->Count();
|
2010-08-15 04:28:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-25 03:53:45 -07:00
|
|
|
return ChildCount();
|
2010-08-15 04:28:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
Accessible::GetEmbeddedChildAt(PRUint32 aIndex)
|
2010-08-15 04:28:49 -07:00
|
|
|
{
|
2011-01-27 21:15:04 -08:00
|
|
|
if (IsChildrenFlag(eMixedChildren)) {
|
2010-08-15 04:28:49 -07:00
|
|
|
if (!mEmbeddedObjCollector)
|
|
|
|
mEmbeddedObjCollector = new EmbeddedObjCollector(this);
|
|
|
|
return mEmbeddedObjCollector ?
|
|
|
|
mEmbeddedObjCollector->GetAccessibleAt(aIndex) : nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetChildAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetIndexOfEmbeddedChild(Accessible* aChild)
|
2010-08-15 04:28:49 -07:00
|
|
|
{
|
2011-01-27 21:15:04 -08:00
|
|
|
if (IsChildrenFlag(eMixedChildren)) {
|
2010-08-15 04:28:49 -07:00
|
|
|
if (!mEmbeddedObjCollector)
|
|
|
|
mEmbeddedObjCollector = new EmbeddedObjCollector(this);
|
|
|
|
return mEmbeddedObjCollector ?
|
|
|
|
mEmbeddedObjCollector->GetIndexAt(aChild) : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetIndexOf(aChild);
|
|
|
|
}
|
|
|
|
|
2010-08-31 20:26:13 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HyperLinkAccessible methods
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::IsLink()
|
2010-08-31 20:26:13 -07:00
|
|
|
{
|
|
|
|
// Every embedded accessible within hypertext accessible implements
|
|
|
|
// hyperlink interface.
|
2011-01-27 21:15:22 -08:00
|
|
|
return mParent && mParent->IsHyperText() && nsAccUtils::IsEmbeddedObject(this);
|
2010-08-31 20:26:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::StartOffset()
|
2010-08-31 20:26:13 -07:00
|
|
|
{
|
2011-06-23 21:29:43 -07:00
|
|
|
NS_PRECONDITION(IsLink(), "StartOffset is called not on hyper link!");
|
2010-08-31 20:26:13 -07:00
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible* hyperText = mParent ? mParent->AsHyperText() : nsnull;
|
2010-08-31 20:26:13 -07:00
|
|
|
return hyperText ? hyperText->GetChildOffset(this) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::EndOffset()
|
2010-08-31 20:26:13 -07:00
|
|
|
{
|
2011-06-23 21:29:43 -07:00
|
|
|
NS_PRECONDITION(IsLink(), "EndOffset is called on not hyper link!");
|
2010-08-31 20:26:13 -07:00
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible* hyperText = mParent ? mParent->AsHyperText() : nsnull;
|
2010-08-31 20:26:13 -07:00
|
|
|
return hyperText ? (hyperText->GetChildOffset(this) + 1) : 0;
|
|
|
|
}
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::IsLinkSelected()
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(IsLink(),
|
|
|
|
"IsLinkSelected() called on something that is not a hyper link!");
|
|
|
|
return FocusMgr()->IsFocused(this);
|
|
|
|
}
|
|
|
|
|
2010-08-31 20:26:13 -07:00
|
|
|
PRUint32
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::AnchorCount()
|
2010-08-31 20:26:13 -07:00
|
|
|
{
|
2011-06-23 21:29:43 -07:00
|
|
|
NS_PRECONDITION(IsLink(), "AnchorCount is called on not hyper link!");
|
2010-08-31 20:26:13 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
Accessible::AnchorAt(PRUint32 aAnchorIndex)
|
2010-08-31 20:26:13 -07:00
|
|
|
{
|
2011-06-23 21:29:43 -07:00
|
|
|
NS_PRECONDITION(IsLink(), "GetAnchor is called on not hyper link!");
|
2010-08-31 20:26:13 -07:00
|
|
|
return aAnchorIndex == 0 ? this : nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIURI>
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::AnchorURIAt(PRUint32 aAnchorIndex)
|
2010-08-31 20:26:13 -07:00
|
|
|
{
|
2011-06-23 21:29:43 -07:00
|
|
|
NS_PRECONDITION(IsLink(), "AnchorURIAt is called on not hyper link!");
|
2010-08-31 20:26:13 -07:00
|
|
|
|
|
|
|
if (aAnchorIndex != 0)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// Check if it's a simple xlink.
|
|
|
|
if (nsCoreUtils::IsXLink(mContent)) {
|
|
|
|
nsAutoString href;
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_XLink, nsGkAtoms::href, href);
|
2010-08-31 20:26:13 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
|
2011-10-18 03:53:36 -07:00
|
|
|
nsCOMPtr<nsIDocument> document = mContent->OwnerDoc();
|
2010-08-31 20:26:13 -07:00
|
|
|
nsIURI* anchorURI = nsnull;
|
|
|
|
NS_NewURI(&anchorURI, href,
|
|
|
|
document ? document->GetDocumentCharacterSet().get() : nsnull,
|
|
|
|
baseURI);
|
|
|
|
return anchorURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2010-09-01 17:46:59 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SelectAccessible
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::IsSelect()
|
2010-09-01 17:46:59 -07:00
|
|
|
{
|
|
|
|
// If we have an ARIA role attribute present and the role allows multi
|
|
|
|
// selectable state, then we need to support SelectAccessible interface. If
|
|
|
|
// either attribute (role or multiselectable) change, then we'll destroy this
|
|
|
|
// accessible so that we can follow COM identity rules.
|
|
|
|
|
|
|
|
return mRoleMapEntry &&
|
2012-04-05 09:23:30 -07:00
|
|
|
(mRoleMapEntry->attributeMap1 == aria::eARIAMultiSelectable ||
|
|
|
|
mRoleMapEntry->attributeMap2 == aria::eARIAMultiSelectable ||
|
|
|
|
mRoleMapEntry->attributeMap3 == aria::eARIAMultiSelectable);
|
2010-09-01 17:46:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIArray>
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::SelectedItems()
|
2010-09-01 17:46:59 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMutableArray> selectedItems = do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
if (!selectedItems)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
AccIterator iter(this, filters::GetSelected, AccIterator::eTreeNav);
|
|
|
|
nsIAccessible* selected = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((selected = iter.Next()))
|
2011-10-17 07:59:28 -07:00
|
|
|
selectedItems->AppendElement(selected, false);
|
2010-09-01 17:46:59 -07:00
|
|
|
|
|
|
|
nsIMutableArray* items = nsnull;
|
|
|
|
selectedItems.forget(&items);
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::SelectedItemCount()
|
2010-09-01 17:46:59 -07:00
|
|
|
{
|
|
|
|
PRUint32 count = 0;
|
|
|
|
AccIterator iter(this, filters::GetSelected, AccIterator::eTreeNav);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* selected = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((selected = iter.Next()))
|
2010-09-01 17:46:59 -07:00
|
|
|
++count;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
Accessible::GetSelectedItem(PRUint32 aIndex)
|
2010-09-01 17:46:59 -07:00
|
|
|
{
|
|
|
|
AccIterator iter(this, filters::GetSelected, AccIterator::eTreeNav);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* selected = nsnull;
|
2010-09-01 17:46:59 -07:00
|
|
|
|
|
|
|
PRUint32 index = 0;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((selected = iter.Next()) && index < aIndex)
|
2010-09-01 17:46:59 -07:00
|
|
|
index++;
|
|
|
|
|
|
|
|
return selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::IsItemSelected(PRUint32 aIndex)
|
2010-09-01 17:46:59 -07:00
|
|
|
{
|
|
|
|
PRUint32 index = 0;
|
|
|
|
AccIterator iter(this, filters::GetSelectable, AccIterator::eTreeNav);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* selected = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((selected = iter.Next()) && index < aIndex)
|
2010-09-01 17:46:59 -07:00
|
|
|
index++;
|
|
|
|
|
|
|
|
return selected &&
|
2011-04-09 16:38:06 -07:00
|
|
|
selected->State() & states::SELECTED;
|
2010-09-01 17:46:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::AddItemToSelection(PRUint32 aIndex)
|
2010-09-01 17:46:59 -07:00
|
|
|
{
|
|
|
|
PRUint32 index = 0;
|
|
|
|
AccIterator iter(this, filters::GetSelectable, AccIterator::eTreeNav);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* selected = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((selected = iter.Next()) && index < aIndex)
|
2010-09-01 17:46:59 -07:00
|
|
|
index++;
|
|
|
|
|
|
|
|
if (selected)
|
2011-10-17 07:59:28 -07:00
|
|
|
selected->SetSelected(true);
|
2010-09-01 17:46:59 -07:00
|
|
|
|
|
|
|
return static_cast<bool>(selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::RemoveItemFromSelection(PRUint32 aIndex)
|
2010-09-01 17:46:59 -07:00
|
|
|
{
|
|
|
|
PRUint32 index = 0;
|
|
|
|
AccIterator iter(this, filters::GetSelectable, AccIterator::eTreeNav);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* selected = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((selected = iter.Next()) && index < aIndex)
|
2010-09-01 17:46:59 -07:00
|
|
|
index++;
|
|
|
|
|
|
|
|
if (selected)
|
2011-10-17 07:59:28 -07:00
|
|
|
selected->SetSelected(false);
|
2010-09-01 17:46:59 -07:00
|
|
|
|
|
|
|
return static_cast<bool>(selected);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::SelectAll()
|
2010-09-01 17:46:59 -07:00
|
|
|
{
|
|
|
|
bool success = false;
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* selectable = nsnull;
|
2010-09-01 17:46:59 -07:00
|
|
|
|
|
|
|
AccIterator iter(this, filters::GetSelectable, AccIterator::eTreeNav);
|
2011-08-09 18:44:00 -07:00
|
|
|
while((selectable = iter.Next())) {
|
2010-09-01 17:46:59 -07:00
|
|
|
success = true;
|
2011-10-17 07:59:28 -07:00
|
|
|
selectable->SetSelected(true);
|
2010-09-01 17:46:59 -07:00
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::UnselectAll()
|
2010-09-01 17:46:59 -07:00
|
|
|
{
|
|
|
|
bool success = false;
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* selected = nsnull;
|
2010-09-01 17:46:59 -07:00
|
|
|
|
|
|
|
AccIterator iter(this, filters::GetSelected, AccIterator::eTreeNav);
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((selected = iter.Next())) {
|
2010-09-01 17:46:59 -07:00
|
|
|
success = true;
|
2011-10-17 07:59:28 -07:00
|
|
|
selected->SetSelected(false);
|
2010-09-01 17:46:59 -07:00
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Widgets
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::IsWidget() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::IsActiveWidget() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
return FocusMgr()->IsFocused(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::AreItemsOperable() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
return mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::aria_activedescendant);
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
Accessible::CurrentItem()
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
// Check for aria-activedescendant, which changes which element has focus.
|
|
|
|
// For activedescendant, the ARIA spec does not require that the user agent
|
|
|
|
// checks whether pointed node is actually a DOM descendant of the element
|
|
|
|
// with the aria-activedescendant attribute.
|
|
|
|
nsAutoString id;
|
|
|
|
if (mContent->GetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::aria_activedescendant, id)) {
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* DOMDoc = mContent->OwnerDoc();
|
2011-09-27 18:46:11 -07:00
|
|
|
dom::Element* activeDescendantElm = DOMDoc->GetElementById(id);
|
|
|
|
if (activeDescendantElm) {
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* document = Document();
|
2011-09-27 18:46:11 -07:00
|
|
|
if (document)
|
|
|
|
return document->GetAccessible(activeDescendantElm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2011-12-08 04:20:15 -08:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::SetCurrentItem(Accessible* aItem)
|
2011-12-08 04:20:15 -08:00
|
|
|
{
|
|
|
|
nsIAtom* id = aItem->GetContent()->GetID();
|
|
|
|
if (id) {
|
|
|
|
nsAutoString idStr;
|
|
|
|
id->ToString(idStr);
|
|
|
|
mContent->SetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::aria_activedescendant, idStr, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
Accessible::ContainerWidget() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
2012-01-20 07:22:31 -08:00
|
|
|
if (HasARIARole() && mContent->HasID()) {
|
2012-05-28 18:18:45 -07:00
|
|
|
for (Accessible* parent = Parent(); parent; parent = parent->Parent()) {
|
2012-01-20 07:22:31 -08:00
|
|
|
nsIContent* parentContent = parent->GetContent();
|
|
|
|
if (parentContent &&
|
|
|
|
parentContent->HasAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::aria_activedescendant)) {
|
|
|
|
return parent;
|
2011-12-07 01:10:22 -08:00
|
|
|
}
|
2012-01-20 07:22:31 -08:00
|
|
|
|
|
|
|
// Don't cross DOM document boundaries.
|
|
|
|
if (parent->IsDocumentNode())
|
|
|
|
break;
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
2010-09-01 17:46:59 -07:00
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible protected methods
|
2009-12-10 11:12:19 -08:00
|
|
|
|
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::CacheChildren()
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* doc = Document();
|
2012-02-07 14:38:54 -08:00
|
|
|
NS_ENSURE_TRUE(doc,);
|
|
|
|
|
2012-02-09 08:49:17 -08:00
|
|
|
nsAccTreeWalker walker(doc, mContent, CanHaveAnonChildren());
|
2009-12-10 11:12:19 -08:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = nsnull;
|
2011-03-31 02:30:58 -07:00
|
|
|
while ((child = walker.NextChild()) && AppendChild(child));
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::TestChildCache(Accessible* aCachedChild) const
|
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) {
|
2011-01-27 21:15:04 -08:00
|
|
|
NS_ASSERTION(IsChildrenFlag(eChildrenUninitialized),
|
2010-08-15 04:28:49 -07:00
|
|
|
"No children but initialized!");
|
2009-12-10 11:12:19 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* 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
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible public
|
2011-01-27 20:38:02 -08:00
|
|
|
bool
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::EnsureChildren()
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
|
|
|
if (IsDefunct()) {
|
2011-01-27 21:15:04 -08:00
|
|
|
SetChildrenFlag(eChildrenUninitialized);
|
2011-01-27 20:38:02 -08:00
|
|
|
return true;
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
2011-01-27 21:15:04 -08:00
|
|
|
if (!IsChildrenFlag(eChildrenUninitialized))
|
2011-01-27 20:38:02 -08:00
|
|
|
return false;
|
2009-12-10 11:12:19 -08:00
|
|
|
|
2010-08-15 04:28:49 -07:00
|
|
|
// State is embedded children until text leaf accessible is appended.
|
2011-01-27 21:15:04 -08:00
|
|
|
SetChildrenFlag(eEmbeddedChildren); // Prevent reentry
|
2010-11-18 21:44:47 -08:00
|
|
|
|
2009-12-10 11:12:19 -08:00
|
|
|
CacheChildren();
|
2011-01-27 20:38:02 -08:00
|
|
|
return false;
|
2009-12-10 11:12:19 -08:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
Accessible::GetSiblingAtOffset(PRInt32 aOffset, nsresult* aError) const
|
2009-12-10 11:12:19 -08:00
|
|
|
{
|
2011-06-06 19:23:13 -07:00
|
|
|
if (!mParent || mIndexInParent == -1) {
|
2009-12-10 11:12:19 -08:00
|
|
|
if (aError)
|
|
|
|
*aError = NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2012-05-25 03:53:45 -07:00
|
|
|
if (aError &&
|
|
|
|
mIndexInParent + aOffset >= static_cast<PRInt32>(mParent->ChildCount())) {
|
2011-06-06 19:23:13 -07:00
|
|
|
*aError = NS_OK; // fail peacefully
|
2009-12-10 11:12:19 -08:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = mParent->GetChildAt(mIndexInParent + 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
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
Accessible::GetFirstAvailableAccessible(nsINode *aStartNode) const
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* accessible = mDoc->GetAccessible(aStartNode);
|
2010-06-11 01:23:18 -07:00
|
|
|
if (accessible)
|
|
|
|
return accessible;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aStartNode->OwnerDoc());
|
2011-05-15 03:07:30 -07:00
|
|
|
NS_ENSURE_TRUE(domDoc, nsnull);
|
2011-03-28 06:58:59 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> currentNode = do_QueryInterface(aStartNode);
|
2011-05-15 03:07:30 -07:00
|
|
|
nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(GetNode());
|
2011-03-28 06:58:59 -07:00
|
|
|
nsCOMPtr<nsIDOMTreeWalker> walker;
|
2011-05-15 03:07:30 -07:00
|
|
|
domDoc->CreateTreeWalker(rootNode,
|
|
|
|
nsIDOMNodeFilter::SHOW_ELEMENT | nsIDOMNodeFilter::SHOW_TEXT,
|
2011-10-17 07:59:28 -07:00
|
|
|
nsnull, false, getter_AddRefs(walker));
|
2011-03-28 06:58:59 -07:00
|
|
|
NS_ENSURE_TRUE(walker, nsnull);
|
|
|
|
|
|
|
|
walker->SetCurrentNode(currentNode);
|
|
|
|
while (true) {
|
|
|
|
walker->NextNode(getter_AddRefs(currentNode));
|
|
|
|
if (!currentNode)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsINode> node(do_QueryInterface(currentNode));
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* accessible = mDoc->GetAccessible(node);
|
2011-03-28 06:58:59 -07:00
|
|
|
if (accessible)
|
|
|
|
return accessible;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-03 22:27:27 -07:00
|
|
|
nsresult
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::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;
|
2011-03-25 04:14:19 -07:00
|
|
|
double value = attrValue.ToDouble(&error);
|
2009-05-05 20:16:36 -07:00
|
|
|
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
|
2012-06-03 22:41:06 -07:00
|
|
|
Accessible::GetActionRule()
|
2008-10-08 05:54:58 -07:00
|
|
|
{
|
2012-06-03 22:41:06 -07:00
|
|
|
if (InteractiveState() & states::UNAVAILABLE)
|
2008-10-08 05:54:58 -07:00
|
|
|
return eNoAction;
|
2012-06-03 22:41:06 -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())
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::popup))
|
2009-08-23 22:13:05 -07:00
|
|
|
return eClickAction;
|
|
|
|
|
2008-10-08 05:54:58 -07:00
|
|
|
// Has registered 'click' event handler.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool 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,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::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-07-02 20:11:35 -07:00
|
|
|
AccGroupInfo*
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetGroupInfo()
|
2010-01-06 02:36:50 -08:00
|
|
|
{
|
2010-07-02 20:11:35 -07:00
|
|
|
if (mGroupInfo)
|
|
|
|
return mGroupInfo;
|
2010-01-12 11:07:38 -08:00
|
|
|
|
2010-07-02 20:11:35 -07:00
|
|
|
mGroupInfo = AccGroupInfo::CreateGroupInfo(this);
|
|
|
|
return mGroupInfo;
|
|
|
|
}
|
2010-01-12 11:07:38 -08:00
|
|
|
|
2010-07-02 20:11:35 -07:00
|
|
|
void
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetPositionAndSizeInternal(PRInt32 *aPosInSet, PRInt32 *aSetSize)
|
2010-07-02 20:11:35 -07:00
|
|
|
{
|
|
|
|
AccGroupInfo* groupInfo = GetGroupInfo();
|
|
|
|
if (groupInfo) {
|
|
|
|
*aPosInSet = groupInfo->PosInSet();
|
|
|
|
*aSetSize = groupInfo->SetSize();
|
2009-01-04 23:41:30 -08:00
|
|
|
}
|
2010-01-06 02:36:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible::GetLevelInternal()
|
2010-01-06 02:36:50 -08:00
|
|
|
{
|
2010-01-12 11:07:38 -08:00
|
|
|
PRInt32 level = nsAccUtils::GetDefaultLevel(this);
|
|
|
|
|
2011-07-23 01:38:33 -07:00
|
|
|
if (!IsBoundToParent())
|
|
|
|
return level;
|
2010-01-06 02:36:50 -08:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role role = Role();
|
|
|
|
if (role == roles::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;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parent = this;
|
2011-07-23 01:38:33 -07:00
|
|
|
while ((parent = parent->Parent())) {
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role parentRole = parent->Role();
|
2009-01-04 23:41:30 -08:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
if (parentRole == roles::OUTLINE)
|
2009-01-04 23:41:30 -08:00
|
|
|
break;
|
2012-01-11 19:07:35 -08:00
|
|
|
if (parentRole == roles::GROUPING)
|
2010-01-06 02:36:50 -08:00
|
|
|
++ level;
|
2009-01-04 23:41:30 -08:00
|
|
|
|
|
|
|
}
|
2010-01-06 02:36:50 -08:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
} else if (role == roles::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;
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parent = this;
|
2011-07-23 01:38:33 -07:00
|
|
|
while ((parent = parent->Parent())) {
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role parentRole = parent->Role();
|
2009-01-04 23:41:30 -08:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
if (parentRole == roles::LISTITEM)
|
2010-01-06 02:36:50 -08:00
|
|
|
++ level;
|
2012-01-11 19:07:35 -08:00
|
|
|
else if (parentRole != roles::LIST)
|
2009-01-04 23:41:30 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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.
|
2011-07-23 01:38:33 -07:00
|
|
|
parent = Parent();
|
2012-05-25 03:53:45 -07:00
|
|
|
PRUint32 siblingCount = parent->ChildCount();
|
|
|
|
for (PRUint32 siblingIdx = 0; siblingIdx < siblingCount; siblingIdx++) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* sibling = parent->GetChildAt(siblingIdx);
|
2009-01-04 23:41:30 -08:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* siblingChild = sibling->LastChild();
|
2012-01-11 19:07:35 -08:00
|
|
|
if (siblingChild && siblingChild->Role() == roles::LIST)
|
2011-07-23 01:38:33 -07:00
|
|
|
return 1;
|
2009-01-04 23:41:30 -08:00
|
|
|
}
|
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
|
|
|
}
|
2011-07-19 01:30:24 -07:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// KeyBinding class
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyBinding::ToPlatformFormat(nsAString& aValue) const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStringBundle> keyStringBundle;
|
|
|
|
nsCOMPtr<nsIStringBundleService> stringBundleService =
|
|
|
|
mozilla::services::GetStringBundleService();
|
|
|
|
if (stringBundleService)
|
2012-05-10 06:43:04 -07:00
|
|
|
stringBundleService->CreateBundle(
|
|
|
|
"chrome://global-platform/locale/platformKeys.properties",
|
|
|
|
getter_AddRefs(keyStringBundle));
|
2011-07-19 01:30:24 -07:00
|
|
|
|
|
|
|
if (!keyStringBundle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoString separator;
|
|
|
|
keyStringBundle->GetStringFromName(NS_LITERAL_STRING("MODIFIER_SEPARATOR").get(),
|
|
|
|
getter_Copies(separator));
|
|
|
|
|
|
|
|
nsAutoString modifierName;
|
|
|
|
if (mModifierMask & kControl) {
|
|
|
|
keyStringBundle->GetStringFromName(NS_LITERAL_STRING("VK_CONTROL").get(),
|
|
|
|
getter_Copies(modifierName));
|
|
|
|
|
|
|
|
aValue.Append(modifierName);
|
|
|
|
aValue.Append(separator);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mModifierMask & kAlt) {
|
|
|
|
keyStringBundle->GetStringFromName(NS_LITERAL_STRING("VK_ALT").get(),
|
|
|
|
getter_Copies(modifierName));
|
|
|
|
|
|
|
|
aValue.Append(modifierName);
|
|
|
|
aValue.Append(separator);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mModifierMask & kShift) {
|
|
|
|
keyStringBundle->GetStringFromName(NS_LITERAL_STRING("VK_SHIFT").get(),
|
|
|
|
getter_Copies(modifierName));
|
|
|
|
|
|
|
|
aValue.Append(modifierName);
|
|
|
|
aValue.Append(separator);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mModifierMask & kMeta) {
|
|
|
|
keyStringBundle->GetStringFromName(NS_LITERAL_STRING("VK_META").get(),
|
|
|
|
getter_Copies(modifierName));
|
|
|
|
|
|
|
|
aValue.Append(modifierName);
|
|
|
|
aValue.Append(separator);
|
|
|
|
}
|
|
|
|
|
|
|
|
aValue.Append(mKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyBinding::ToAtkFormat(nsAString& aValue) const
|
|
|
|
{
|
|
|
|
nsAutoString modifierName;
|
|
|
|
if (mModifierMask & kControl)
|
|
|
|
aValue.Append(NS_LITERAL_STRING("<Control>"));
|
|
|
|
|
|
|
|
if (mModifierMask & kAlt)
|
|
|
|
aValue.Append(NS_LITERAL_STRING("<Alt>"));
|
|
|
|
|
|
|
|
if (mModifierMask & kShift)
|
|
|
|
aValue.Append(NS_LITERAL_STRING("<Shift>"));
|
|
|
|
|
|
|
|
if (mModifierMask & kMeta)
|
|
|
|
aValue.Append(NS_LITERAL_STRING("<Meta>"));
|
|
|
|
|
|
|
|
aValue.Append(mKey);
|
|
|
|
}
|