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-06-10 16:44:50 -07:00
|
|
|
#include "XULElementAccessibles.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "Accessible-inl.h"
|
2012-06-04 05:32:29 -07:00
|
|
|
#include "BaseAccessibles.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsAccUtils.h"
|
|
|
|
#include "nsCoreUtils.h"
|
|
|
|
#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"
|
2011-04-09 16:38:06 -07:00
|
|
|
#include "States.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
#include "nsIAccessibleRelation.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMXULDescriptionElement.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsString.h"
|
2008-03-18 04:37:12 -07:00
|
|
|
#include "nsNetUtil.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULLabelAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
XULLabelAccessible::
|
|
|
|
XULLabelAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessibleWrap(aContent, aDoc)
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-13 21:18:39 -07:00
|
|
|
ENameValueFlag
|
|
|
|
XULLabelAccessible::NativeName(nsString& aName)
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
2008-01-23 15:49:10 -08:00
|
|
|
// if the value attr doesn't exist, the screen reader must get the accessible text
|
|
|
|
// from the accessible text interface or from the children
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName);
|
2012-10-13 21:18:39 -07:00
|
|
|
return eNameOK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-10 16:44:50 -07:00
|
|
|
XULLabelAccessible::NativeRole()
|
2009-03-07 07:38:58 -08:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::LABEL;
|
2009-03-07 07:38:58 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULLabelAccessible::NativeState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Labels and description have read only state
|
|
|
|
// They are not focusable or selectable
|
2012-05-31 01:04:41 -07:00
|
|
|
return HyperTextAccessibleWrap::NativeState() | states::READONLY;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
Relation
|
2012-08-22 08:56:38 -07:00
|
|
|
XULLabelAccessible::RelationByType(uint32_t aType)
|
2007-09-29 00:04:27 -07:00
|
|
|
{
|
2012-05-31 01:04:41 -07:00
|
|
|
Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
|
2011-08-09 18:44:00 -07:00
|
|
|
if (aType == nsIAccessibleRelation::RELATION_LABEL_FOR) {
|
2007-09-29 00:04:27 -07:00
|
|
|
// Caption is the label for groupbox
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent *parent = mContent->GetParent();
|
2011-06-03 14:35:17 -07:00
|
|
|
if (parent && parent->Tag() == nsGkAtoms::caption) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parent = Parent();
|
2012-01-11 19:07:35 -08:00
|
|
|
if (parent && parent->Role() == roles::GROUPING)
|
2011-08-09 18:44:00 -07:00
|
|
|
rel.AppendTarget(parent);
|
2007-09-29 00:04:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
return rel;
|
2007-09-29 00:04:27 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULTooltipAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
XULTooltipAccessible::
|
|
|
|
XULTooltipAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-06-04 05:32:29 -07:00
|
|
|
LeafAccessible(aContent, aDoc)
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULTooltipAccessible::NativeState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-04 05:32:29 -07:00
|
|
|
return LeafAccessible::NativeState() | states::READONLY;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-10 16:44:50 -07:00
|
|
|
XULTooltipAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::TOOLTIP;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
|
2008-03-18 04:37:12 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULLinkAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
XULLinkAccessible::
|
|
|
|
XULLinkAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessibleWrap(aContent, aDoc)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-03-29 20:22:10 -07:00
|
|
|
// Expose nsIAccessibleHyperLink unconditionally
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(XULLinkAccessible, HyperTextAccessibleWrap,
|
2008-03-29 20:22:10 -07:00
|
|
|
nsIAccessibleHyperLink)
|
|
|
|
|
2008-03-18 04:37:12 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULLinkAccessible. nsIAccessible
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2012-04-09 02:48:41 -07:00
|
|
|
void
|
2012-06-10 16:44:50 -07:00
|
|
|
XULLinkAccessible::Value(nsString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-18 04:37:12 -07:00
|
|
|
aValue.Truncate();
|
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::href, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-13 21:18:39 -07:00
|
|
|
ENameValueFlag
|
|
|
|
XULLinkAccessible::NativeName(nsString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName);
|
2012-10-13 21:18:39 -07:00
|
|
|
if (aName.IsEmpty())
|
|
|
|
nsTextEquivUtils::GetNameFromSubtree(this, aName);
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2012-10-13 21:18:39 -07:00
|
|
|
return eNameOK;
|
2008-03-18 04:37:12 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-10 16:44:50 -07:00
|
|
|
XULLinkAccessible::NativeRole()
|
2008-03-18 04:37:12 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::LINK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULLinkAccessible::NativeLinkState() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-17 02:37:37 -07:00
|
|
|
return states::LINKED;
|
2008-03-18 04:37:12 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULLinkAccessible::ActionCount()
|
2008-03-18 04:37:12 -07:00
|
|
|
{
|
2011-06-05 12:35:43 -07:00
|
|
|
return 1;
|
2008-03-18 04:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
XULLinkAccessible::GetActionName(uint8_t aIndex, nsAString& aName)
|
2008-03-18 04:37:12 -07:00
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
|
|
|
|
if (aIndex != eAction_Jump)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2008-03-18 04:37:12 -07:00
|
|
|
aName.AssignLiteral("jump");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
XULLinkAccessible::DoAction(uint8_t aIndex)
|
2008-03-18 04:37:12 -07:00
|
|
|
{
|
|
|
|
if (aIndex != eAction_Jump)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-01-25 07:09:25 -08:00
|
|
|
DoCommand();
|
|
|
|
return NS_OK;
|
2008-03-18 04:37:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULLinkAccessible: HyperLinkAccessible
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2010-08-31 20:26:13 -07:00
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULLinkAccessible::IsLink()
|
2008-03-18 04:37:12 -07:00
|
|
|
{
|
2010-08-31 20:26:13 -07:00
|
|
|
// Expose HyperLinkAccessible unconditionally.
|
|
|
|
return true;
|
|
|
|
}
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULLinkAccessible::StartOffset()
|
2010-08-31 20:26:13 -07:00
|
|
|
{
|
|
|
|
// If XUL link accessible is not contained by hypertext accessible then
|
|
|
|
// start offset matches index in parent because the parent doesn't contains
|
|
|
|
// a text.
|
|
|
|
// XXX: accessible parent of XUL link accessible should be a hypertext
|
|
|
|
// accessible.
|
2012-05-28 18:18:45 -07:00
|
|
|
if (Accessible::IsLink())
|
|
|
|
return Accessible::StartOffset();
|
2011-06-13 02:08:40 -07:00
|
|
|
return IndexInParent();
|
2010-08-31 20:26:13 -07:00
|
|
|
}
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULLinkAccessible::EndOffset()
|
2010-08-31 20:26:13 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
if (Accessible::IsLink())
|
|
|
|
return Accessible::EndOffset();
|
2011-06-13 02:08:40 -07:00
|
|
|
return IndexInParent() + 1;
|
2010-08-31 20:26:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIURI>
|
2012-08-22 08:56:38 -07:00
|
|
|
XULLinkAccessible::AnchorURIAt(uint32_t aAnchorIndex)
|
2010-08-31 20:26:13 -07:00
|
|
|
{
|
|
|
|
if (aAnchorIndex != 0)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-11 01:23:18 -07:00
|
|
|
|
2008-03-18 04:37:12 -07:00
|
|
|
nsAutoString href;
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* document = mContent->OwnerDoc();
|
2010-08-31 20:26:13 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIURI* anchorURI = nullptr;
|
2010-08-31 20:26:13 -07:00
|
|
|
NS_NewURI(&anchorURI, href,
|
2011-10-18 04:19:44 -07:00
|
|
|
document->GetDocumentCharacterSet().get(),
|
2010-08-31 20:26:13 -07:00
|
|
|
baseURI);
|
|
|
|
|
|
|
|
return anchorURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|