2001-10-10 01:52:36 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2001-10-10 01:52:36 +04:00
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
#include "XULElementAccessibles.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
|
2012-04-13 18:17:03 +04:00
|
|
|
#include "Accessible-inl.h"
|
2012-06-04 16:32:29 +04:00
|
|
|
#include "BaseAccessibles.h"
|
2013-03-01 08:06:16 +04:00
|
|
|
#include "DocAccessible-inl.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
#include "nsAccUtils.h"
|
|
|
|
#include "nsCoreUtils.h"
|
|
|
|
#include "nsTextEquivUtils.h"
|
2011-08-10 05:44:00 +04:00
|
|
|
#include "Relation.h"
|
2012-01-12 07:07:35 +04:00
|
|
|
#include "Role.h"
|
2011-04-10 03:38:06 +04:00
|
|
|
#include "States.h"
|
2013-03-01 08:06:16 +04:00
|
|
|
#include "TextUpdater.h"
|
|
|
|
|
|
|
|
#ifdef A11Y_LOG
|
|
|
|
#include "Logging.h"
|
|
|
|
#endif
|
2010-04-27 10:52:03 +04:00
|
|
|
|
2001-10-10 01:52:36 +04:00
|
|
|
#include "nsIDOMXULDescriptionElement.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2008-03-18 14:37:12 +03:00
|
|
|
#include "nsNetUtil.h"
|
2013-03-01 08:06:16 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTextBoxFrame.h"
|
2001-10-10 01:52:36 +04:00
|
|
|
|
2011-07-27 16:43:01 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-11 03:44:50 +04:00
|
|
|
// XULLabelAccessible
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
XULLabelAccessible::
|
|
|
|
XULLabelAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-31 12:04:41 +04:00
|
|
|
HyperTextAccessibleWrap(aContent, aDoc)
|
2010-06-11 12:23:18 +04:00
|
|
|
{
|
2013-03-01 08:06:16 +04: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 23:27:07 +04:00
|
|
|
mDoc->BindToDocument(mValueTextLeaf, nullptr);
|
2013-03-01 08:06:16 +04:00
|
|
|
|
2013-09-06 23:27:07 +04:00
|
|
|
nsAutoString text;
|
|
|
|
textBoxFrame->GetCroppedTitle(text);
|
|
|
|
mValueTextLeaf->SetText(text);
|
2016-04-01 18:07:57 +03:00
|
|
|
AppendChild(mValueTextLeaf);
|
2013-03-01 08:06:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
XULLabelAccessible::Shutdown()
|
|
|
|
{
|
|
|
|
mValueTextLeaf = nullptr;
|
|
|
|
HyperTextAccessibleWrap::Shutdown();
|
2001-10-10 01:52:36 +04:00
|
|
|
}
|
|
|
|
|
2012-10-14 08:18:39 +04:00
|
|
|
ENameValueFlag
|
2018-05-15 19:13:02 +03:00
|
|
|
XULLabelAccessible::NativeName(nsString& aName) const
|
2010-06-11 12:23:18 +04:00
|
|
|
{
|
2008-01-24 02:49:10 +03: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-03-01 08:06:16 +04:00
|
|
|
if (mValueTextLeaf)
|
|
|
|
return mValueTextLeaf->Name(aName);
|
|
|
|
|
2016-05-18 08:10:49 +03:00
|
|
|
return Accessible::NativeName(aName);
|
2001-10-10 01:52:36 +04:00
|
|
|
}
|
2002-06-14 05:47:35 +04:00
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
role
|
2018-05-07 22:05:50 +03:00
|
|
|
XULLabelAccessible::NativeRole() const
|
2009-03-07 18:38:58 +03:00
|
|
|
{
|
2012-01-12 07:07:35 +04:00
|
|
|
return roles::LABEL;
|
2009-03-07 18:38:58 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t
|
2012-06-11 03:44:50 +04:00
|
|
|
XULLabelAccessible::NativeState()
|
2002-06-14 05:47:35 +04:00
|
|
|
{
|
2006-12-29 11:52:04 +03:00
|
|
|
// Labels and description have read only state
|
2002-06-14 05:47:35 +04:00
|
|
|
// They are not focusable or selectable
|
2012-05-31 12:04:41 +04:00
|
|
|
return HyperTextAccessibleWrap::NativeState() | states::READONLY;
|
2002-06-14 05:47:35 +04:00
|
|
|
}
|
2002-11-06 04:29:58 +03:00
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
Relation
|
2018-05-15 16:47:10 +03:00
|
|
|
XULLabelAccessible::RelationByType(RelationType aType) const
|
2007-09-29 11:04:27 +04:00
|
|
|
{
|
2012-05-31 12:04:41 +04:00
|
|
|
Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
|
2013-10-19 22:19:50 +04:00
|
|
|
if (aType == RelationType::LABEL_FOR) {
|
2007-09-29 11:04:27 +04:00
|
|
|
// Caption is the label for groupbox
|
2013-05-02 02:50:08 +04:00
|
|
|
nsIContent* parent = mContent->GetFlattenedTreeParent();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (parent && parent->IsXULElement(nsGkAtoms::caption)) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* parent = Parent();
|
2012-01-12 07:07:35 +04:00
|
|
|
if (parent && parent->Role() == roles::GROUPING)
|
2011-08-10 05:44:00 +04:00
|
|
|
rel.AppendTarget(parent);
|
2007-09-29 11:04:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
return rel;
|
2007-09-29 11:04:27 +04:00
|
|
|
}
|
|
|
|
|
2013-03-01 08:06:16 +04: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// XULLabelTextLeafAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
role
|
2018-05-07 22:05:50 +03:00
|
|
|
XULLabelTextLeafAccessible::NativeRole() const
|
2013-03-01 08:06:16 +04:00
|
|
|
{
|
|
|
|
return roles::TEXT_LEAF;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
XULLabelTextLeafAccessible::NativeState()
|
|
|
|
{
|
|
|
|
return TextLeafAccessibleWrap::NativeState() | states::READONLY;
|
|
|
|
}
|
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-11 03:44:50 +04:00
|
|
|
// XULTooltipAccessible
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
XULTooltipAccessible::
|
|
|
|
XULTooltipAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-06-04 16:32:29 +04:00
|
|
|
LeafAccessible(aContent, aDoc)
|
2010-06-11 12:23:18 +04:00
|
|
|
{
|
2002-11-06 04:29:58 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t
|
2012-06-11 03:44:50 +04:00
|
|
|
XULTooltipAccessible::NativeState()
|
2002-11-06 04:29:58 +03:00
|
|
|
{
|
2012-06-04 16:32:29 +04:00
|
|
|
return LeafAccessible::NativeState() | states::READONLY;
|
2002-11-06 04:29:58 +03:00
|
|
|
}
|
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
role
|
2018-05-07 22:05:50 +03:00
|
|
|
XULTooltipAccessible::NativeRole() const
|
2002-11-06 04:29:58 +03:00
|
|
|
{
|
2012-01-12 07:07:35 +04:00
|
|
|
return roles::TOOLTIP;
|
2002-11-06 04:29:58 +03:00
|
|
|
}
|
2005-07-14 19:12:12 +04:00
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
|
2008-03-18 14:37:12 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-11 03:44:50 +04:00
|
|
|
// XULLinkAccessible
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
XULLinkAccessible::
|
|
|
|
XULLinkAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2013-08-21 00:42:26 +04:00
|
|
|
XULLabelAccessible(aContent, aDoc)
|
2005-07-14 19:12:12 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-09 01:23:18 +04:00
|
|
|
XULLinkAccessible::~XULLinkAccessible()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-03-18 14:37:12 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-10-22 04:49:28 +04:00
|
|
|
// XULLinkAccessible: Accessible
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2012-04-09 13:48:41 +04:00
|
|
|
void
|
2018-05-15 19:55:28 +03:00
|
|
|
XULLinkAccessible::Value(nsString& aValue) const
|
2005-07-14 19:12:12 +04:00
|
|
|
{
|
2008-03-18 14:37:12 +03:00
|
|
|
aValue.Truncate();
|
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::href, aValue);
|
2006-07-12 08:21:52 +04:00
|
|
|
}
|
|
|
|
|
2012-10-14 08:18:39 +04:00
|
|
|
ENameValueFlag
|
2018-05-15 19:13:02 +03:00
|
|
|
XULLinkAccessible::NativeName(nsString& aName) const
|
2005-07-14 19:12:12 +04:00
|
|
|
{
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName);
|
2012-10-17 10:38:16 +04:00
|
|
|
if (!aName.IsEmpty())
|
|
|
|
return eNameOK;
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2012-10-17 10:38:16 +04:00
|
|
|
nsTextEquivUtils::GetNameFromSubtree(this, aName);
|
|
|
|
return aName.IsEmpty() ? eNameOK : eNameFromSubtree;
|
2008-03-18 14:37:12 +03:00
|
|
|
}
|
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
role
|
2018-05-07 22:05:50 +03:00
|
|
|
XULLinkAccessible::NativeRole() const
|
2008-03-18 14:37:12 +03:00
|
|
|
{
|
2012-01-12 07:07:35 +04:00
|
|
|
return roles::LINK;
|
2005-07-14 19:12:12 +04:00
|
|
|
}
|
|
|
|
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t
|
2012-06-11 03:44:50 +04:00
|
|
|
XULLinkAccessible::NativeLinkState() const
|
2005-07-14 19:12:12 +04:00
|
|
|
{
|
2012-05-17 13:37:37 +04:00
|
|
|
return states::LINKED;
|
2008-03-18 14:37:12 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t
|
2012-06-11 03:44:50 +04:00
|
|
|
XULLinkAccessible::ActionCount()
|
2008-03-18 14:37:12 +03:00
|
|
|
{
|
2011-06-05 23:35:43 +04:00
|
|
|
return 1;
|
2008-03-18 14:37:12 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 21:30:23 +04:00
|
|
|
void
|
|
|
|
XULLinkAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
|
2008-03-18 14:37:12 +03:00
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
|
2014-09-16 21:30:23 +04:00
|
|
|
if (aIndex == eAction_Jump)
|
|
|
|
aName.AssignLiteral("jump");
|
2008-03-18 14:37:12 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 21:30:23 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
XULLinkAccessible::DoAction(uint8_t aIndex)
|
2008-03-18 14:37:12 +03:00
|
|
|
{
|
|
|
|
if (aIndex != eAction_Jump)
|
2014-09-16 21:30:23 +04:00
|
|
|
return false;
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2010-01-25 18:09:25 +03:00
|
|
|
DoCommand();
|
2014-09-16 21:30:23 +04:00
|
|
|
return true;
|
2008-03-18 14:37:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-11 03:44:50 +04:00
|
|
|
// XULLinkAccessible: HyperLinkAccessible
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2010-09-01 07:26:13 +04:00
|
|
|
bool
|
2018-05-04 15:48:34 +03:00
|
|
|
XULLinkAccessible::IsLink() const
|
2008-03-18 14:37:12 +03:00
|
|
|
{
|
2010-09-01 07:26:13 +04:00
|
|
|
// Expose HyperLinkAccessible unconditionally.
|
|
|
|
return true;
|
|
|
|
}
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-06-11 03:44:50 +04:00
|
|
|
XULLinkAccessible::StartOffset()
|
2010-09-01 07:26:13 +04: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-29 05:18:45 +04:00
|
|
|
if (Accessible::IsLink())
|
|
|
|
return Accessible::StartOffset();
|
2011-06-13 13:08:40 +04:00
|
|
|
return IndexInParent();
|
2010-09-01 07:26:13 +04:00
|
|
|
}
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-06-11 03:44:50 +04:00
|
|
|
XULLinkAccessible::EndOffset()
|
2010-09-01 07:26:13 +04:00
|
|
|
{
|
2012-05-29 05:18:45 +04:00
|
|
|
if (Accessible::IsLink())
|
|
|
|
return Accessible::EndOffset();
|
2011-06-13 13:08:40 +04:00
|
|
|
return IndexInParent() + 1;
|
2010-09-01 07:26:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIURI>
|
2012-08-22 19:56:38 +04:00
|
|
|
XULLinkAccessible::AnchorURIAt(uint32_t aAnchorIndex)
|
2010-09-01 07:26:13 +04:00
|
|
|
{
|
|
|
|
if (aAnchorIndex != 0)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-06-11 12:23:18 +04:00
|
|
|
|
2008-03-18 14:37:12 +03:00
|
|
|
nsAutoString href;
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
|
2011-10-18 14:53:36 +04:00
|
|
|
nsIDocument* document = mContent->OwnerDoc();
|
2010-09-01 07:26:13 +04:00
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
nsCOMPtr<nsIURI> anchorURI;
|
|
|
|
NS_NewURI(getter_AddRefs(anchorURI), href,
|
2017-06-18 14:37:50 +03:00
|
|
|
document->GetDocumentCharacterSet(),
|
2010-09-01 07:26:13 +04:00
|
|
|
baseURI);
|
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
return anchorURI.forget();
|
2005-07-14 19:12:12 +04:00
|
|
|
}
|