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
|
|
|
|
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) {
|
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
|
|
|
}
|
|
|
|
|
2018-05-15 19:13:02 +03:00
|
|
|
ENameValueFlag XULLabelAccessible::NativeName(nsString& aName) const {
|
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
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role XULLabelAccessible::NativeRole() const { return roles::LABEL; }
|
2009-03-07 18:38:58 +03:00
|
|
|
|
2018-05-15 21:04:50 +03:00
|
|
|
uint64_t XULLabelAccessible::NativeState() const {
|
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
|
|
|
|
2018-05-15 16:47:10 +03:00
|
|
|
Relation XULLabelAccessible::RelationByType(RelationType aType) const {
|
2012-05-31 12:04:41 +04:00
|
|
|
Relation rel = HyperTextAccessibleWrap::RelationByType(aType);
|
2018-11-15 15:05:09 +03:00
|
|
|
|
|
|
|
// The label for xul:groupbox is generated from the first xul:label
|
2013-10-19 22:19:50 +04:00
|
|
|
if (aType == RelationType::LABEL_FOR) {
|
2018-11-15 15:05:09 +03:00
|
|
|
Accessible* parent = Parent();
|
|
|
|
if (parent && parent->Role() == roles::GROUPING &&
|
|
|
|
parent->GetChildAt(0) == this) {
|
2018-11-21 18:24:13 +03:00
|
|
|
nsIContent* parentContent = parent->GetContent();
|
|
|
|
if (parentContent && parentContent->IsXULElement(nsGkAtoms::groupbox)) {
|
|
|
|
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
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role XULLabelTextLeafAccessible::NativeRole() const { return roles::TEXT_LEAF; }
|
2013-03-01 08:06:16 +04:00
|
|
|
|
2018-05-15 21:04:50 +03:00
|
|
|
uint64_t XULLabelTextLeafAccessible::NativeState() const {
|
2013-03-01 08:06:16 +04:00
|
|
|
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) {}
|
2002-11-06 04:29:58 +03:00
|
|
|
|
2018-05-15 21:04:50 +03:00
|
|
|
uint64_t XULTooltipAccessible::NativeState() const {
|
2012-06-04 16:32:29 +04:00
|
|
|
return LeafAccessible::NativeState() | states::READONLY;
|
2002-11-06 04:29:58 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role XULTooltipAccessible::NativeRole() const { return roles::TOOLTIP; }
|
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
|
|
|
|
2018-05-15 19:55:28 +03:00
|
|
|
void XULLinkAccessible::Value(nsString& aValue) const {
|
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
|
|
|
}
|
|
|
|
|
2018-05-15 19:13:02 +03:00
|
|
|
ENameValueFlag XULLinkAccessible::NativeName(nsString& aName) const {
|
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
|
|
|
}
|
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role XULLinkAccessible::NativeRole() const { return roles::LINK; }
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
uint64_t XULLinkAccessible::NativeLinkState() const { return states::LINKED; }
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2018-05-15 20:40:22 +03:00
|
|
|
uint8_t XULLinkAccessible::ActionCount() const { 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
|
|
|
}
|
|
|
|
|
2018-05-15 20:40:22 +03:00
|
|
|
bool XULLinkAccessible::DoAction(uint8_t aIndex) const {
|
2008-03-18 14:37:12 +03:00
|
|
|
if (aIndex != eAction_Jump) return false;
|
|
|
|
|
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
|
|
|
|
2018-05-04 15:48:34 +03:00
|
|
|
bool XULLinkAccessible::IsLink() const {
|
2010-09-01 07:26:13 +04:00
|
|
|
// Expose HyperLinkAccessible unconditionally.
|
|
|
|
return true;
|
|
|
|
}
|
2008-03-18 14:37:12 +03:00
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
uint32_t 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-06-11 03:44:50 +04:00
|
|
|
uint32_t XULLinkAccessible::EndOffset() {
|
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
|
|
|
}
|
|
|
|
|
2018-05-15 20:19:54 +03:00
|
|
|
already_AddRefed<nsIURI> XULLinkAccessible::AnchorURIAt(
|
|
|
|
uint32_t aAnchorIndex) const {
|
2010-09-01 07:26:13 +04:00
|
|
|
if (aAnchorIndex != 0) 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();
|
2019-01-02 16:05:23 +03:00
|
|
|
dom::Document* 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(), baseURI);
|
2010-09-01 07:26:13 +04:00
|
|
|
|
2013-04-22 15:15:59 +04:00
|
|
|
return anchorURI.forget();
|
2005-07-14 19:12:12 +04:00
|
|
|
}
|