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"
|
2013-02-28 20:06:16 -08:00
|
|
|
#include "DocAccessible-inl.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"
|
2013-02-28 20:06:16 -08:00
|
|
|
#include "TextUpdater.h"
|
|
|
|
|
|
|
|
#ifdef A11Y_LOG
|
|
|
|
#include "Logging.h"
|
|
|
|
#endif
|
2010-04-26 23:52:03 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMXULDescriptionElement.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsNameSpaceManager.h"
|
2008-03-18 04:37:12 -07:00
|
|
|
#include "nsNetUtil.h"
|
2013-02-28 20:06:16 -08:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTextBoxFrame.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
|
|
|
{
|
2013-02-28 20:06:16 -08:00
|
|
|
mType = eXULLabelType;
|
|
|
|
|
|
|
|
// If @value attribute is given then it's rendered instead text content. In
|
|
|
|
// this case we need to create a text leaf accessible to make @value attribute
|
|
|
|
// accessible.
|
|
|
|
// XXX: text interface doesn't let you get the text by words.
|
|
|
|
nsTextBoxFrame* textBoxFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
|
|
|
if (textBoxFrame) {
|
|
|
|
mValueTextLeaf = new XULLabelTextLeafAccessible(mContent, mDoc);
|
2013-09-06 12:27:07 -07:00
|
|
|
mDoc->BindToDocument(mValueTextLeaf, nullptr);
|
2013-02-28 20:06:16 -08:00
|
|
|
|
2013-09-06 12:27:07 -07:00
|
|
|
nsAutoString text;
|
|
|
|
textBoxFrame->GetCroppedTitle(text);
|
|
|
|
mValueTextLeaf->SetText(text);
|
2013-02-28 20:06:16 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
XULLabelAccessible::Shutdown()
|
|
|
|
{
|
|
|
|
mValueTextLeaf = nullptr;
|
|
|
|
HyperTextAccessibleWrap::Shutdown();
|
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
|
2013-02-28 20:06:16 -08:00
|
|
|
if (mValueTextLeaf)
|
|
|
|
return mValueTextLeaf->Name(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
|
2013-10-19 11:19:50 -07:00
|
|
|
XULLabelAccessible::RelationByType(RelationType aType)
|
2007-09-29 00:04:27 -07:00
|
|
|
{
|
2012-05-31 01:04:41 -07:00
|
|
|
Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
|
2013-10-19 11:19:50 -07:00
|
|
|
if (aType == RelationType::LABEL_FOR) {
|
2007-09-29 00:04:27 -07:00
|
|
|
// Caption is the label for groupbox
|
2013-05-01 15:50:08 -07:00
|
|
|
nsIContent* parent = mContent->GetFlattenedTreeParent();
|
2015-03-03 03:08:59 -08:00
|
|
|
if (parent && parent->IsXULElement(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
|
|
|
}
|
|
|
|
|
2013-02-28 20:06:16 -08:00
|
|
|
void
|
|
|
|
XULLabelAccessible::UpdateLabelValue(const nsString& aValue)
|
|
|
|
{
|
|
|
|
#ifdef A11Y_LOG
|
|
|
|
if (logging::IsEnabled(logging::eText)) {
|
|
|
|
logging::MsgBegin("TEXT", "text may be changed (xul:label @value update)");
|
|
|
|
logging::Node("container", mContent);
|
|
|
|
logging::MsgEntry("old text '%s'",
|
|
|
|
NS_ConvertUTF16toUTF8(mValueTextLeaf->Text()).get());
|
|
|
|
logging::MsgEntry("new text: '%s'",
|
|
|
|
NS_ConvertUTF16toUTF8(aValue).get());
|
|
|
|
logging::MsgEnd();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
TextUpdater::Run(mDoc, mValueTextLeaf, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
XULLabelAccessible::CacheChildren()
|
|
|
|
{
|
|
|
|
if (mValueTextLeaf) {
|
|
|
|
AppendChild(mValueTextLeaf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache children from subtree.
|
|
|
|
AccessibleWrap::CacheChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// XULLabelTextLeafAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
role
|
|
|
|
XULLabelTextLeafAccessible::NativeRole()
|
|
|
|
{
|
|
|
|
return roles::TEXT_LEAF;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
XULLabelTextLeafAccessible::NativeState()
|
|
|
|
{
|
|
|
|
return TextLeafAccessibleWrap::NativeState() | states::READONLY;
|
|
|
|
}
|
|
|
|
|
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) :
|
2013-08-20 13:42:26 -07:00
|
|
|
XULLabelAccessible(aContent, aDoc)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-08 14:23:18 -07:00
|
|
|
XULLinkAccessible::~XULLinkAccessible()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-03-18 04:37:12 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-10-21 17:49:28 -07:00
|
|
|
// XULLinkAccessible: Accessible
|
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-16 23:38:16 -07:00
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return eNameOK;
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2012-10-16 23:38:16 -07:00
|
|
|
nsTextEquivUtils::GetNameFromSubtree(this, aName);
|
|
|
|
return aName.IsEmpty() ? eNameOK : eNameFromSubtree;
|
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
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
void
|
|
|
|
XULLinkAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
|
2008-03-18 04:37:12 -07:00
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
if (aIndex == eAction_Jump)
|
|
|
|
aName.AssignLiteral("jump");
|
2008-03-18 04:37:12 -07:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:30:23 -07:00
|
|
|
bool
|
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)
|
2014-09-16 10:30:23 -07:00
|
|
|
return false;
|
2008-03-18 04:37:12 -07:00
|
|
|
|
2010-01-25 07:09:25 -08:00
|
|
|
DoCommand();
|
2014-09-16 10:30:23 -07:00
|
|
|
return true;
|
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
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
nsCOMPtr<nsIURI> anchorURI;
|
|
|
|
NS_NewURI(getter_AddRefs(anchorURI), href,
|
2011-10-18 04:19:44 -07:00
|
|
|
document->GetDocumentCharacterSet().get(),
|
2010-08-31 20:26:13 -07:00
|
|
|
baseURI);
|
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
return anchorURI.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|