2001-09-25 04:48:50 +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-04-18 03:06:38 +04:00
|
|
|
|
2012-06-02 15:30:29 +04:00
|
|
|
#include "HTMLElementAccessibles.h"
|
2010-03-17 09:02:28 +03:00
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
#include "DocAccessible.h"
|
2010-09-21 19:05:31 +04:00
|
|
|
#include "nsAccUtils.h"
|
2013-09-11 02:18:59 +04:00
|
|
|
#include "nsIPersistentProperties2.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
#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"
|
2010-03-17 09:02:28 +03:00
|
|
|
|
2013-09-20 01:51:58 +04:00
|
|
|
#include "mozilla/dom/HTMLLabelElement.h"
|
2016-06-01 18:07:56 +03:00
|
|
|
#include "mozilla/dom/HTMLDetailsElement.h"
|
|
|
|
#include "mozilla/dom/HTMLSummaryElement.h"
|
2013-09-20 01:51:58 +04:00
|
|
|
|
2011-07-27 16:43:01 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2009-10-22 08:45:52 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-02 15:30:29 +04:00
|
|
|
// HTMLHRAccessible
|
2009-10-22 08:45:52 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role HTMLHRAccessible::NativeRole() const { return roles::SEPARATOR; }
|
2002-11-06 04:29:58 +03:00
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-02 15:30:29 +04:00
|
|
|
// HTMLBRAccessible
|
2010-06-11 12:23:18 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role HTMLBRAccessible::NativeRole() const { return roles::WHITESPACE; }
|
2006-07-12 17:14:53 +04:00
|
|
|
|
2018-05-15 21:04:50 +03:00
|
|
|
uint64_t HTMLBRAccessible::NativeState() const { return states::READONLY; }
|
2006-07-12 17:14:53 +04:00
|
|
|
|
2018-05-15 19:13:02 +03:00
|
|
|
ENameValueFlag HTMLBRAccessible::NativeName(nsString& aName) const {
|
2014-01-04 19:02:17 +04:00
|
|
|
aName = static_cast<char16_t>('\n'); // Newline char
|
2012-10-14 08:18:39 +04:00
|
|
|
return eNameOK;
|
2006-07-12 17:14:53 +04:00
|
|
|
}
|
|
|
|
|
2009-10-22 08:45:52 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-02 15:30:29 +04:00
|
|
|
// HTMLLabelAccessible
|
2009-10-22 08:45:52 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-02-22 12:52:01 +03:00
|
|
|
|
2018-05-15 19:13:02 +03:00
|
|
|
ENameValueFlag HTMLLabelAccessible::NativeName(nsString& aName) const {
|
2012-10-14 08:18:39 +04:00
|
|
|
nsTextEquivUtils::GetNameFromSubtree(this, aName);
|
2012-10-17 10:38:16 +04:00
|
|
|
return aName.IsEmpty() ? eNameOK : eNameFromSubtree;
|
2003-03-06 21:50:39 +03:00
|
|
|
}
|
|
|
|
|
2018-05-15 16:47:10 +03:00
|
|
|
Relation HTMLLabelAccessible::RelationByType(RelationType aType) const {
|
2013-09-20 01:51:58 +04:00
|
|
|
Relation rel = AccessibleWrap::RelationByType(aType);
|
2013-10-19 22:19:50 +04:00
|
|
|
if (aType == RelationType::LABEL_FOR) {
|
2018-03-22 00:39:04 +03:00
|
|
|
dom::HTMLLabelElement* label = dom::HTMLLabelElement::FromNode(mContent);
|
2013-09-20 01:51:58 +04:00
|
|
|
rel.AppendTarget(mDoc, label->GetControl());
|
|
|
|
}
|
|
|
|
|
|
|
|
return rel;
|
|
|
|
}
|
|
|
|
|
2018-05-15 20:40:22 +03:00
|
|
|
uint8_t HTMLLabelAccessible::ActionCount() const {
|
2016-01-14 23:37:15 +03:00
|
|
|
return nsCoreUtils::IsLabelWithControl(mContent) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLLabelAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) {
|
|
|
|
if (aIndex == 0) {
|
|
|
|
if (nsCoreUtils::IsLabelWithControl(mContent)) aName.AssignLiteral("click");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 20:40:22 +03:00
|
|
|
bool HTMLLabelAccessible::DoAction(uint8_t aIndex) const {
|
2016-01-14 23:37:15 +03:00
|
|
|
if (aIndex != 0) return false;
|
|
|
|
|
|
|
|
DoCommand();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-21 19:05:31 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsHTMLOuputAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-05-15 16:47:10 +03:00
|
|
|
Relation HTMLOutputAccessible::RelationByType(RelationType aType) const {
|
2012-05-29 05:18:45 +04:00
|
|
|
Relation rel = AccessibleWrap::RelationByType(aType);
|
2013-10-19 22:19:50 +04:00
|
|
|
if (aType == RelationType::CONTROLLED_BY)
|
2012-03-23 09:26:52 +04:00
|
|
|
rel.AppendIter(new IDRefsIterator(mDoc, mContent, nsGkAtoms::_for));
|
2010-09-21 19:05:31 +04:00
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
return rel;
|
2010-09-21 19:05:31 +04:00
|
|
|
}
|
2016-06-01 18:07:56 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLSummaryAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
HTMLSummaryAccessible::HTMLSummaryAccessible(nsIContent* aContent,
|
|
|
|
DocAccessible* aDoc)
|
|
|
|
: HyperTextAccessibleWrap(aContent, aDoc) {
|
|
|
|
mGenericTypes |= eButton;
|
|
|
|
}
|
|
|
|
|
2018-05-15 20:40:22 +03:00
|
|
|
uint8_t HTMLSummaryAccessible::ActionCount() const { return 1; }
|
2016-06-01 18:07:56 +03:00
|
|
|
|
|
|
|
void HTMLSummaryAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) {
|
|
|
|
if (aIndex != eAction_Click) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
dom::HTMLSummaryElement* summary =
|
|
|
|
dom::HTMLSummaryElement::FromNode(mContent);
|
2016-06-01 18:07:56 +03:00
|
|
|
if (!summary) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom::HTMLDetailsElement* details = summary->GetDetails();
|
|
|
|
if (!details) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (details->Open()) {
|
|
|
|
aName.AssignLiteral("collapse");
|
|
|
|
} else {
|
|
|
|
aName.AssignLiteral("expand");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 20:40:22 +03:00
|
|
|
bool HTMLSummaryAccessible::DoAction(uint8_t aIndex) const {
|
2016-06-01 18:07:56 +03:00
|
|
|
if (aIndex != eAction_Click) return false;
|
|
|
|
|
|
|
|
DoCommand();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-15 21:04:50 +03:00
|
|
|
uint64_t HTMLSummaryAccessible::NativeState() const {
|
2016-06-01 18:07:56 +03:00
|
|
|
uint64_t state = HyperTextAccessibleWrap::NativeState();
|
|
|
|
|
2018-03-22 00:39:04 +03:00
|
|
|
dom::HTMLSummaryElement* summary =
|
|
|
|
dom::HTMLSummaryElement::FromNode(mContent);
|
2016-06-01 18:07:56 +03:00
|
|
|
if (!summary) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom::HTMLDetailsElement* details = summary->GetDetails();
|
|
|
|
if (!details) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (details->Open()) {
|
|
|
|
state |= states::EXPANDED;
|
|
|
|
} else {
|
|
|
|
state |= states::COLLAPSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLSummaryAccessible: Widgets
|
|
|
|
|
|
|
|
bool HTMLSummaryAccessible::IsWidget() const { return true; }
|
2017-08-28 15:30:17 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLHeaderOrFooterAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role HTMLHeaderOrFooterAccessible::NativeRole() const {
|
2017-08-28 15:30:17 +03:00
|
|
|
// Only map header and footer if they are direct descendants of the body tag.
|
|
|
|
// If other sectioning or sectioning root elements, they become sections.
|
|
|
|
nsIContent* parent = mContent->GetParent();
|
|
|
|
while (parent) {
|
|
|
|
if (parent->IsAnyOfHTMLElements(nsGkAtoms::article, nsGkAtoms::aside,
|
|
|
|
nsGkAtoms::nav, nsGkAtoms::section,
|
|
|
|
nsGkAtoms::blockquote, nsGkAtoms::details,
|
|
|
|
nsGkAtoms::dialog, nsGkAtoms::fieldset,
|
|
|
|
nsGkAtoms::figure, nsGkAtoms::td)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// No sectioning or sectioning root elements found.
|
|
|
|
if (!parent) {
|
2018-10-23 09:11:59 +03:00
|
|
|
return roles::LANDMARK;
|
2017-08-28 15:30:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return roles::SECTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAtom* HTMLHeaderOrFooterAccessible::LandmarkRole() const {
|
|
|
|
if (!HasOwnContent()) return nullptr;
|
|
|
|
|
|
|
|
a11y::role r = const_cast<HTMLHeaderOrFooterAccessible*>(this)->Role();
|
2018-10-23 09:11:59 +03:00
|
|
|
if (r == roles::LANDMARK) {
|
|
|
|
if (mContent->IsHTMLElement(nsGkAtoms::header)) {
|
|
|
|
return nsGkAtoms::banner;
|
|
|
|
}
|
2017-08-28 15:30:17 +03:00
|
|
|
|
2018-10-23 09:11:59 +03:00
|
|
|
if (mContent->IsHTMLElement(nsGkAtoms::footer)) {
|
|
|
|
return nsGkAtoms::contentinfo;
|
|
|
|
}
|
2017-08-28 15:30:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-10-24 08:34:22 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLSectionAccessible
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
role HTMLSectionAccessible::NativeRole() const {
|
|
|
|
nsAutoString name;
|
|
|
|
const_cast<HTMLSectionAccessible*>(this)->Name(name);
|
2018-10-25 04:41:15 +03:00
|
|
|
return name.IsEmpty() ? roles::SECTION : roles::REGION;
|
2018-10-24 08:34:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAtom* HTMLSectionAccessible::LandmarkRole() const {
|
|
|
|
if (!HasOwnContent()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only return xml-roles "region" if the section has an accessible name.
|
|
|
|
nsAutoString name;
|
|
|
|
const_cast<HTMLSectionAccessible*>(this)->Name(name);
|
|
|
|
return name.IsEmpty() ? nullptr : nsGkAtoms::region;
|
|
|
|
}
|