diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /accessible/html | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'accessible/html')
-rw-r--r-- | accessible/html/HTMLCanvasAccessible.cpp | 16 | ||||
-rw-r--r-- | accessible/html/HTMLCanvasAccessible.h | 35 | ||||
-rw-r--r-- | accessible/html/HTMLElementAccessibles.cpp | 244 | ||||
-rw-r--r-- | accessible/html/HTMLElementAccessibles.h | 155 | ||||
-rw-r--r-- | accessible/html/HTMLFormControlAccessible.cpp | 797 | ||||
-rw-r--r-- | accessible/html/HTMLFormControlAccessible.h | 330 | ||||
-rw-r--r-- | accessible/html/HTMLImageMapAccessible.cpp | 182 | ||||
-rw-r--r-- | accessible/html/HTMLImageMapAccessible.h | 85 | ||||
-rw-r--r-- | accessible/html/HTMLLinkAccessible.cpp | 118 | ||||
-rw-r--r-- | accessible/html/HTMLLinkAccessible.h | 56 | ||||
-rw-r--r-- | accessible/html/HTMLListAccessible.cpp | 182 | ||||
-rw-r--r-- | accessible/html/HTMLListAccessible.h | 102 | ||||
-rw-r--r-- | accessible/html/HTMLSelectAccessible.cpp | 496 | ||||
-rw-r--r-- | accessible/html/HTMLSelectAccessible.h | 212 | ||||
-rw-r--r-- | accessible/html/HTMLTableAccessible.cpp | 806 | ||||
-rw-r--r-- | accessible/html/HTMLTableAccessible.h | 232 | ||||
-rw-r--r-- | accessible/html/moz.build | 55 |
17 files changed, 4103 insertions, 0 deletions
diff --git a/accessible/html/HTMLCanvasAccessible.cpp b/accessible/html/HTMLCanvasAccessible.cpp new file mode 100644 index 0000000000..91e3f1c57d --- /dev/null +++ b/accessible/html/HTMLCanvasAccessible.cpp @@ -0,0 +1,16 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#include "HTMLCanvasAccessible.h" + +#include "Role.h" + +using namespace mozilla::a11y; + +HTMLCanvasAccessible::HTMLCanvasAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) {} + +role HTMLCanvasAccessible::NativeRole() const { return roles::CANVAS; } diff --git a/accessible/html/HTMLCanvasAccessible.h b/accessible/html/HTMLCanvasAccessible.h new file mode 100644 index 0000000000..436d2a152d --- /dev/null +++ b/accessible/html/HTMLCanvasAccessible.h @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#ifndef mozilla_a11y_HTMLCanvasAccessible_h__ +#define mozilla_a11y_HTMLCanvasAccessible_h__ + +#include "HyperTextAccessibleWrap.h" + +namespace mozilla { +namespace a11y { + +/** + * HTML canvas accessible (html:canvas). + */ +class HTMLCanvasAccessible : public HyperTextAccessibleWrap { + public: + HTMLCanvasAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // nsISupports + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLCanvasAccessible, + HyperTextAccessibleWrap) + + // Accessible + virtual a11y::role NativeRole() const override; + + protected: + virtual ~HTMLCanvasAccessible() {} +}; + +} // namespace a11y +} // namespace mozilla + +#endif diff --git a/accessible/html/HTMLElementAccessibles.cpp b/accessible/html/HTMLElementAccessibles.cpp new file mode 100644 index 0000000000..f19c49e1db --- /dev/null +++ b/accessible/html/HTMLElementAccessibles.cpp @@ -0,0 +1,244 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#include "HTMLElementAccessibles.h" + +#include "DocAccessible.h" +#include "nsAccUtils.h" +#include "nsTextEquivUtils.h" +#include "Relation.h" +#include "Role.h" +#include "States.h" + +#include "mozilla/dom/HTMLLabelElement.h" +#include "mozilla/dom/HTMLDetailsElement.h" +#include "mozilla/dom/HTMLSummaryElement.h" + +using namespace mozilla::a11y; + +//////////////////////////////////////////////////////////////////////////////// +// HTMLHRAccessible +//////////////////////////////////////////////////////////////////////////////// + +role HTMLHRAccessible::NativeRole() const { return roles::SEPARATOR; } + +//////////////////////////////////////////////////////////////////////////////// +// HTMLBRAccessible +//////////////////////////////////////////////////////////////////////////////// + +role HTMLBRAccessible::NativeRole() const { return roles::WHITESPACE; } + +uint64_t HTMLBRAccessible::NativeState() const { return states::READONLY; } + +ENameValueFlag HTMLBRAccessible::NativeName(nsString& aName) const { + aName = static_cast<char16_t>('\n'); // Newline char + return eNameOK; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLLabelAccessible +//////////////////////////////////////////////////////////////////////////////// + +ENameValueFlag HTMLLabelAccessible::NativeName(nsString& aName) const { + nsTextEquivUtils::GetNameFromSubtree(this, aName); + return aName.IsEmpty() ? eNameOK : eNameFromSubtree; +} + +Relation HTMLLabelAccessible::RelationByType(RelationType aType) const { + Relation rel = AccessibleWrap::RelationByType(aType); + if (aType == RelationType::LABEL_FOR) { + dom::HTMLLabelElement* label = dom::HTMLLabelElement::FromNode(mContent); + rel.AppendTarget(mDoc, label->GetControl()); + } + + return rel; +} + +uint8_t HTMLLabelAccessible::ActionCount() const { + return nsCoreUtils::IsLabelWithControl(mContent) ? 1 : 0; +} + +void HTMLLabelAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) { + if (aIndex == 0) { + if (nsCoreUtils::IsLabelWithControl(mContent)) aName.AssignLiteral("click"); + } +} + +bool HTMLLabelAccessible::DoAction(uint8_t aIndex) const { + if (aIndex != 0) return false; + + DoCommand(); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +// nsHTMLOuputAccessible +//////////////////////////////////////////////////////////////////////////////// + +Relation HTMLOutputAccessible::RelationByType(RelationType aType) const { + Relation rel = AccessibleWrap::RelationByType(aType); + if (aType == RelationType::CONTROLLED_BY) + rel.AppendIter(new IDRefsIterator(mDoc, mContent, nsGkAtoms::_for)); + + return rel; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSummaryAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLSummaryAccessible::HTMLSummaryAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) { + mGenericTypes |= eButton; +} + +uint8_t HTMLSummaryAccessible::ActionCount() const { return 1; } + +void HTMLSummaryAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) { + if (aIndex != eAction_Click) { + return; + } + + dom::HTMLSummaryElement* summary = + dom::HTMLSummaryElement::FromNode(mContent); + if (!summary) { + return; + } + + dom::HTMLDetailsElement* details = summary->GetDetails(); + if (!details) { + return; + } + + if (details->Open()) { + aName.AssignLiteral("collapse"); + } else { + aName.AssignLiteral("expand"); + } +} + +bool HTMLSummaryAccessible::DoAction(uint8_t aIndex) const { + if (aIndex != eAction_Click) return false; + + DoCommand(); + return true; +} + +uint64_t HTMLSummaryAccessible::NativeState() const { + uint64_t state = HyperTextAccessibleWrap::NativeState(); + + dom::HTMLSummaryElement* summary = + dom::HTMLSummaryElement::FromNode(mContent); + 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* HTMLSummaryAccessible::FromDetails(Accessible* details) { + if (!dom::HTMLDetailsElement::FromNodeOrNull(details->GetContent())) { + return nullptr; + } + + HTMLSummaryAccessible* summaryAccessible = nullptr; + for (uint32_t i = 0; i < details->ChildCount(); i++) { + // Iterate through the children of our details accessible to locate main + // summary. This iteration includes the anonymous summary if the details + // element was not explicitly created with one. + Accessible* child = details->GetChildAt(i); + auto* summary = + mozilla::dom::HTMLSummaryElement::FromNodeOrNull(child->GetContent()); + if (summary && summary->IsMainSummary()) { + summaryAccessible = static_cast<HTMLSummaryAccessible*>(child); + break; + } + } + + return summaryAccessible; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSummaryAccessible: Widgets + +bool HTMLSummaryAccessible::IsWidget() const { return true; } + +//////////////////////////////////////////////////////////////////////////////// +// HTMLHeaderOrFooterAccessible +//////////////////////////////////////////////////////////////////////////////// + +role HTMLHeaderOrFooterAccessible::NativeRole() const { + // 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::main, 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) { + return roles::LANDMARK; + } + + return roles::SECTION; +} + +nsAtom* HTMLHeaderOrFooterAccessible::LandmarkRole() const { + if (!HasOwnContent()) return nullptr; + + a11y::role r = const_cast<HTMLHeaderOrFooterAccessible*>(this)->Role(); + if (r == roles::LANDMARK) { + if (mContent->IsHTMLElement(nsGkAtoms::header)) { + return nsGkAtoms::banner; + } + + if (mContent->IsHTMLElement(nsGkAtoms::footer)) { + return nsGkAtoms::contentinfo; + } + } + + return HyperTextAccessibleWrap::LandmarkRole(); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSectionAccessible +//////////////////////////////////////////////////////////////////////////////// + +role HTMLSectionAccessible::NativeRole() const { + nsAutoString name; + const_cast<HTMLSectionAccessible*>(this)->Name(name); + return name.IsEmpty() ? roles::SECTION : roles::REGION; +} + +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() ? HyperTextAccessibleWrap::LandmarkRole() + : nsGkAtoms::region; +} diff --git a/accessible/html/HTMLElementAccessibles.h b/accessible/html/HTMLElementAccessibles.h new file mode 100644 index 0000000000..955f482770 --- /dev/null +++ b/accessible/html/HTMLElementAccessibles.h @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#ifndef mozilla_a11y_HTMLElementAccessibles_h__ +#define mozilla_a11y_HTMLElementAccessibles_h__ + +#include "BaseAccessibles.h" + +namespace mozilla { +namespace a11y { + +/** + * Used for HTML hr element. + */ +class HTMLHRAccessible : public LeafAccessible { + public: + HTMLHRAccessible(nsIContent* aContent, DocAccessible* aDoc) + : LeafAccessible(aContent, aDoc) {} + + // Accessible + virtual a11y::role NativeRole() const override; +}; + +/** + * Used for HTML br element. + */ +class HTMLBRAccessible : public LeafAccessible { + public: + HTMLBRAccessible(nsIContent* aContent, DocAccessible* aDoc) + : LeafAccessible(aContent, aDoc) { + mType = eHTMLBRType; + mGenericTypes |= eText; + } + + // Accessible + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + + protected: + // Accessible + virtual ENameValueFlag NativeName(nsString& aName) const override; +}; + +/** + * Used for HTML label element. + */ +class HTMLLabelAccessible : public HyperTextAccessibleWrap { + public: + HTMLLabelAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) {} + + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLLabelAccessible, + HyperTextAccessibleWrap) + + // Accessible + virtual Relation RelationByType(RelationType aType) const override; + + // ActionAccessible + virtual uint8_t ActionCount() const override; + virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override; + virtual bool DoAction(uint8_t aIndex) const override; + + protected: + virtual ~HTMLLabelAccessible() {} + virtual ENameValueFlag NativeName(nsString& aName) const override; +}; + +/** + * Used for HTML output element. + */ +class HTMLOutputAccessible : public HyperTextAccessibleWrap { + public: + HTMLOutputAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) {} + + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLOutputAccessible, + HyperTextAccessibleWrap) + + // Accessible + virtual Relation RelationByType(RelationType aType) const override; + + protected: + virtual ~HTMLOutputAccessible() {} +}; + +/** + * Accessible for the HTML summary element. + */ +class HTMLSummaryAccessible : public HyperTextAccessibleWrap { + public: + enum { eAction_Click = 0 }; + + HTMLSummaryAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // Check that the given Accessible belongs to a details frame. + // If so, find and return the accessible for the detail frame's + // main summary. + static HTMLSummaryAccessible* FromDetails(Accessible* aDetails); + + // Accessible + virtual uint64_t NativeState() const override; + + // ActionAccessible + virtual uint8_t ActionCount() const override; + virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override; + virtual bool DoAction(uint8_t aIndex) const override; + + // Widgets + virtual bool IsWidget() const override; +}; + +/** + * Used for HTML header and footer elements. + */ +class HTMLHeaderOrFooterAccessible : public HyperTextAccessibleWrap { + public: + HTMLHeaderOrFooterAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) {} + + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLHeaderOrFooterAccessible, + HyperTextAccessibleWrap) + + // Accessible + virtual nsAtom* LandmarkRole() const override; + virtual a11y::role NativeRole() const override; + + protected: + virtual ~HTMLHeaderOrFooterAccessible() {} +}; + +/** + * Used for HTML section element. + */ +class HTMLSectionAccessible : public HyperTextAccessibleWrap { + public: + HTMLSectionAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) {} + + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLSectionAccessible, + HyperTextAccessibleWrap) + + // Accessible + virtual nsAtom* LandmarkRole() const override; + virtual a11y::role NativeRole() const override; + + protected: + virtual ~HTMLSectionAccessible() = default; +}; + +} // namespace a11y +} // namespace mozilla + +#endif diff --git a/accessible/html/HTMLFormControlAccessible.cpp b/accessible/html/HTMLFormControlAccessible.cpp new file mode 100644 index 0000000000..ed0da75622 --- /dev/null +++ b/accessible/html/HTMLFormControlAccessible.cpp @@ -0,0 +1,797 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#include "HTMLFormControlAccessible.h" + +#include "Accessible-inl.h" +#include "nsAccUtils.h" +#include "nsEventShell.h" +#include "nsTextEquivUtils.h" +#include "Relation.h" +#include "Role.h" +#include "States.h" + +#include "nsContentList.h" +#include "mozilla/dom/HTMLInputElement.h" +#include "mozilla/dom/HTMLTextAreaElement.h" +#include "nsIFormControl.h" +#include "nsIPersistentProperties2.h" +#include "nsITextControlFrame.h" +#include "nsNameSpaceManager.h" +#include "mozilla/dom/ScriptSettings.h" + +#include "mozilla/EventStates.h" +#include "mozilla/FloatingPoint.h" +#include "mozilla/Preferences.h" +#include "mozilla/TextEditor.h" + +using namespace mozilla; +using namespace mozilla::dom; +using namespace mozilla::a11y; + +//////////////////////////////////////////////////////////////////////////////// +// HTMLFormAccessible +//////////////////////////////////////////////////////////////////////////////// + +role HTMLFormAccessible::NativeRole() const { + nsAutoString name; + const_cast<HTMLFormAccessible*>(this)->Name(name); + return name.IsEmpty() ? roles::FORM : roles::FORM_LANDMARK; +} + +nsAtom* HTMLFormAccessible::LandmarkRole() const { + if (!HasOwnContent()) { + return nullptr; + } + + // Only return xml-roles "form" if the form has an accessible name. + nsAutoString name; + const_cast<HTMLFormAccessible*>(this)->Name(name); + return name.IsEmpty() ? HyperTextAccessibleWrap::LandmarkRole() + : nsGkAtoms::form; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLRadioButtonAccessible +//////////////////////////////////////////////////////////////////////////////// + +uint64_t HTMLRadioButtonAccessible::NativeState() const { + uint64_t state = AccessibleWrap::NativeState(); + + state |= states::CHECKABLE; + + HTMLInputElement* input = HTMLInputElement::FromNode(mContent); + if (input && input->Checked()) state |= states::CHECKED; + + return state; +} + +void HTMLRadioButtonAccessible::GetPositionAndSizeInternal(int32_t* aPosInSet, + int32_t* aSetSize) { + Unused << ComputeGroupAttributes(aPosInSet, aSetSize); +} + +Relation HTMLRadioButtonAccessible::ComputeGroupAttributes( + int32_t* aPosInSet, int32_t* aSetSize) const { + Relation rel = Relation(); + int32_t namespaceId = mContent->NodeInfo()->NamespaceID(); + nsAutoString tagName; + mContent->NodeInfo()->GetName(tagName); + + nsAutoString type; + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::type, type); + nsAutoString name; + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::name, name); + + RefPtr<nsContentList> inputElms; + + nsCOMPtr<nsIFormControl> formControlNode(do_QueryInterface(mContent)); + if (dom::Element* formElm = formControlNode->GetFormElement()) { + inputElms = NS_GetContentList(formElm, namespaceId, tagName); + } else { + inputElms = NS_GetContentList(mContent->OwnerDoc(), namespaceId, tagName); + } + NS_ENSURE_TRUE(inputElms, rel); + + uint32_t inputCount = inputElms->Length(false); + + // Compute posinset and setsize. + int32_t indexOf = 0; + int32_t count = 0; + + for (uint32_t index = 0; index < inputCount; index++) { + nsIContent* inputElm = inputElms->Item(index, false); + if (inputElm->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, + type, eCaseMatters) && + inputElm->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, + name, eCaseMatters) && + mDoc->HasAccessible(inputElm)) { + count++; + rel.AppendTarget(mDoc->GetAccessible(inputElm)); + if (inputElm == mContent) indexOf = count; + } + } + + *aPosInSet = indexOf; + *aSetSize = count; + return rel; +} + +Relation HTMLRadioButtonAccessible::RelationByType(RelationType aType) const { + if (aType == RelationType::MEMBER_OF) { + int32_t unusedPos, unusedSetSize; + return ComputeGroupAttributes(&unusedPos, &unusedSetSize); + } + + return Accessible::RelationByType(aType); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLButtonAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLButtonAccessible::HTMLButtonAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) { + mGenericTypes |= eButton; +} + +uint8_t HTMLButtonAccessible::ActionCount() const { return 1; } + +void HTMLButtonAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) { + if (aIndex == eAction_Click) aName.AssignLiteral("press"); +} + +bool HTMLButtonAccessible::DoAction(uint8_t aIndex) const { + if (aIndex != eAction_Click) return false; + + DoCommand(); + return true; +} + +uint64_t HTMLButtonAccessible::State() { + uint64_t state = HyperTextAccessibleWrap::State(); + if (state == states::DEFUNCT) return state; + + // Inherit states from input@type="file" suitable for the button. Note, + // no special processing for unavailable state since inheritance is supplied + // other code paths. + if (mParent && mParent->IsHTMLFileInput()) { + uint64_t parentState = mParent->State(); + state |= parentState & (states::BUSY | states::REQUIRED | states::HASPOPUP | + states::INVALID); + } + + return state; +} + +uint64_t HTMLButtonAccessible::NativeState() const { + uint64_t state = HyperTextAccessibleWrap::NativeState(); + + EventStates elmState = mContent->AsElement()->State(); + if (elmState.HasState(NS_EVENT_STATE_DEFAULT)) state |= states::DEFAULT; + + return state; +} + +role HTMLButtonAccessible::NativeRole() const { return roles::PUSHBUTTON; } + +ENameValueFlag HTMLButtonAccessible::NativeName(nsString& aName) const { + // No need to check @value attribute for buttons since this attribute results + // in native anonymous text node and the name is calculated from subtree. + // The same magic works for @alt and @value attributes in case of type="image" + // element that has no valid @src (note if input@type="image" has an image + // then neither @alt nor @value attributes are used to generate a visual label + // and thus we need to obtain the accessible name directly from attribute + // value). Also the same algorithm works in case of default labels for + // type="submit"/"reset"/"image" elements. + + ENameValueFlag nameFlag = Accessible::NativeName(aName); + if (!aName.IsEmpty() || !mContent->IsHTMLElement(nsGkAtoms::input) || + !mContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, + nsGkAtoms::image, eCaseMatters)) + return nameFlag; + + if (!mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, aName)) + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName); + + aName.CompressWhitespace(); + return eNameOK; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLButtonAccessible: Widgets + +bool HTMLButtonAccessible::IsWidget() const { return true; } + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTextFieldAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLTextFieldAccessible::HTMLTextFieldAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) { + mType = mContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, + nsGkAtoms::password, eIgnoreCase) + ? eHTMLTextPasswordFieldType + : eHTMLTextFieldType; +} + +role HTMLTextFieldAccessible::NativeRole() const { + if (mType == eHTMLTextPasswordFieldType) { + return roles::PASSWORD_TEXT; + } + if (mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::list_)) { + return roles::EDITCOMBOBOX; + } + return roles::ENTRY; +} + +already_AddRefed<nsIPersistentProperties> +HTMLTextFieldAccessible::NativeAttributes() { + nsCOMPtr<nsIPersistentProperties> attributes = + HyperTextAccessibleWrap::NativeAttributes(); + + // Expose type for text input elements as it gives some useful context, + // especially for mobile. + nsAutoString type; + // In the case of this element being part of a binding, the binding's + // parent's type should have precedence. For example an input[type=number] + // has an embedded anonymous input[type=text] (along with spinner buttons). + // In that case, we would want to take the input type from the parent + // and not the anonymous content. + nsIContent* widgetElm = BindingOrWidgetParent(); + if ((widgetElm && widgetElm->AsElement()->GetAttr(kNameSpaceID_None, + nsGkAtoms::type, type)) || + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::type, + type)) { + nsAccUtils::SetAccAttr(attributes, nsGkAtoms::textInputType, type); + if (!ARIARoleMap() && type.EqualsLiteral("search")) { + nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles, u"searchbox"_ns); + } + } + + // If this element has the placeholder attribute set, + // and if that is not identical to the name, expose it as an object attribute. + nsAutoString placeholderText; + if (mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder, + placeholderText)) { + nsAutoString name; + const_cast<HTMLTextFieldAccessible*>(this)->Name(name); + if (!name.Equals(placeholderText)) { + nsAccUtils::SetAccAttr(attributes, nsGkAtoms::placeholder, + placeholderText); + } + } + + return attributes.forget(); +} + +ENameValueFlag HTMLTextFieldAccessible::NativeName(nsString& aName) const { + ENameValueFlag nameFlag = Accessible::NativeName(aName); + if (!aName.IsEmpty()) return nameFlag; + + // If part of compound of XUL widget then grab a name from XUL widget element. + nsIContent* widgetElm = BindingOrWidgetParent(); + if (widgetElm) XULElmName(mDoc, widgetElm, aName); + + if (!aName.IsEmpty()) return eNameOK; + + // text inputs and textareas might have useful placeholder text + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder, + aName); + return eNameOK; +} + +void HTMLTextFieldAccessible::Value(nsString& aValue) const { + aValue.Truncate(); + if (NativeState() & states::PROTECTED) // Don't return password text! + return; + + HTMLTextAreaElement* textArea = HTMLTextAreaElement::FromNode(mContent); + if (textArea) { + textArea->GetValue(aValue); + return; + } + + HTMLInputElement* input = HTMLInputElement::FromNode(mContent); + if (input) { + // Pass NonSystem as the caller type, to be safe. We don't expect to have a + // file input here. + input->GetValue(aValue, CallerType::NonSystem); + } +} + +void HTMLTextFieldAccessible::ApplyARIAState(uint64_t* aState) const { + HyperTextAccessibleWrap::ApplyARIAState(aState); + aria::MapToState(aria::eARIAAutoComplete, mContent->AsElement(), aState); + + // If part of compound of XUL widget then pick up ARIA stuff from XUL widget + // element. + nsIContent* widgetElm = BindingOrWidgetParent(); + if (widgetElm) + aria::MapToState(aria::eARIAAutoComplete, widgetElm->AsElement(), aState); +} + +uint64_t HTMLTextFieldAccessible::NativeState() const { + uint64_t state = HyperTextAccessibleWrap::NativeState(); + + // Text fields are always editable, even if they are also read only or + // disabled. + state |= states::EDITABLE; + + // can be focusable, focused, protected. readonly, unavailable, selected + if (mContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, + nsGkAtoms::password, eIgnoreCase)) { + state |= states::PROTECTED; + } + + if (mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::readonly)) { + state |= states::READONLY; + } + + // Is it an <input> or a <textarea> ? + HTMLInputElement* input = HTMLInputElement::FromNode(mContent); + state |= input && input->IsSingleLineTextControl() ? states::SINGLE_LINE + : states::MULTI_LINE; + + if (state & (states::PROTECTED | states::MULTI_LINE | states::READONLY | + states::UNAVAILABLE)) + return state; + + // Expose autocomplete states if this input is part of autocomplete widget. + Accessible* widget = ContainerWidget(); + if (widget && widget - IsAutoComplete()) { + state |= states::HASPOPUP | states::SUPPORTS_AUTOCOMPLETION; + return state; + } + + // Expose autocomplete state if it has associated autocomplete list. + if (mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::list_)) + return state | states::SUPPORTS_AUTOCOMPLETION | states::HASPOPUP; + + // Ordinal XUL textboxes don't support autocomplete. + if (!BindingOrWidgetParent() && + Preferences::GetBool("browser.formfill.enable")) { + // Check to see if autocompletion is allowed on this input. We don't expose + // it for password fields even though the entire password can be remembered + // for a page if the user asks it to be. However, the kind of autocomplete + // we're talking here is based on what the user types, where a popup of + // possible choices comes up. + nsAutoString autocomplete; + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::autocomplete, + autocomplete); + + if (!autocomplete.LowerCaseEqualsLiteral("off")) { + Element* formElement = input->GetFormElement(); + if (formElement) { + formElement->GetAttr(kNameSpaceID_None, nsGkAtoms::autocomplete, + autocomplete); + } + + if (!formElement || !autocomplete.LowerCaseEqualsLiteral("off")) + state |= states::SUPPORTS_AUTOCOMPLETION; + } + } + + return state; +} + +uint8_t HTMLTextFieldAccessible::ActionCount() const { return 1; } + +void HTMLTextFieldAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) { + if (aIndex == eAction_Click) aName.AssignLiteral("activate"); +} + +bool HTMLTextFieldAccessible::DoAction(uint8_t aIndex) const { + if (aIndex != 0) return false; + + if (FocusMgr()->IsFocused(this)) { + // This already has focus, so TakeFocus()will do nothing. However, the user + // might be activating this element because they dismissed a touch keyboard + // and want to bring it back. + DoCommand(); + } else { + TakeFocus(); + } + return true; +} + +already_AddRefed<TextEditor> HTMLTextFieldAccessible::GetEditor() const { + RefPtr<TextControlElement> textControlElement = + TextControlElement::FromNodeOrNull(mContent); + if (!textControlElement) { + return nullptr; + } + RefPtr<TextEditor> textEditor = textControlElement->GetTextEditor(); + return textEditor.forget(); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTextFieldAccessible: Widgets + +bool HTMLTextFieldAccessible::IsWidget() const { return true; } + +Accessible* HTMLTextFieldAccessible::ContainerWidget() const { + if (!mParent || mParent->Role() != roles::AUTOCOMPLETE) { + return nullptr; + } + return mParent; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLFileInputAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLFileInputAccessible::HTMLFileInputAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) { + mType = eHTMLFileInputType; +} + +role HTMLFileInputAccessible::NativeRole() const { + // No specific role in AT APIs. We use GROUPING so that the label will be + // reported by screen readers when focus enters this control . + return roles::GROUPING; +} + +nsresult HTMLFileInputAccessible::HandleAccEvent(AccEvent* aEvent) { + nsresult rv = HyperTextAccessibleWrap::HandleAccEvent(aEvent); + NS_ENSURE_SUCCESS(rv, rv); + + // Redirect state change events for inherited states to child controls. Note, + // unavailable state is not redirected. That's a standard for unavailable + // state handling. + AccStateChangeEvent* event = downcast_accEvent(aEvent); + if (event && (event->GetState() == states::BUSY || + event->GetState() == states::REQUIRED || + event->GetState() == states::HASPOPUP || + event->GetState() == states::INVALID)) { + Accessible* button = GetChildAt(0); + if (button && button->Role() == roles::PUSHBUTTON) { + RefPtr<AccStateChangeEvent> childEvent = new AccStateChangeEvent( + button, event->GetState(), event->IsStateEnabled(), + event->FromUserInput()); + nsEventShell::FireEvent(childEvent); + } + } + + return NS_OK; +} + +Accessible* HTMLFileInputAccessible::CurrentItem() const { + // Allow aria-activedescendant to override. + if (Accessible* item = HyperTextAccessibleWrap::CurrentItem()) { + return item; + } + + // The HTML file input itself gets DOM focus, not the button inside it. + // For a11y, we want the button to get focus. + Accessible* button = FirstChild(); + if (!button) { + MOZ_ASSERT_UNREACHABLE("File input doesn't contain a button"); + return nullptr; + } + MOZ_ASSERT(button->IsButton()); + return button; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSpinnerAccessible +//////////////////////////////////////////////////////////////////////////////// + +role HTMLSpinnerAccessible::NativeRole() const { return roles::SPINBUTTON; } + +void HTMLSpinnerAccessible::Value(nsString& aValue) const { + HTMLTextFieldAccessible::Value(aValue); + if (!aValue.IsEmpty()) return; + + // Pass NonSystem as the caller type, to be safe. We don't expect to have a + // file input here. + HTMLInputElement::FromNode(mContent)->GetValue(aValue, CallerType::NonSystem); +} + +double HTMLSpinnerAccessible::MaxValue() const { + double value = HTMLTextFieldAccessible::MaxValue(); + if (!IsNaN(value)) return value; + + return HTMLInputElement::FromNode(mContent)->GetMaximum().toDouble(); +} + +double HTMLSpinnerAccessible::MinValue() const { + double value = HTMLTextFieldAccessible::MinValue(); + if (!IsNaN(value)) return value; + + return HTMLInputElement::FromNode(mContent)->GetMinimum().toDouble(); +} + +double HTMLSpinnerAccessible::Step() const { + double value = HTMLTextFieldAccessible::Step(); + if (!IsNaN(value)) return value; + + return HTMLInputElement::FromNode(mContent)->GetStep().toDouble(); +} + +double HTMLSpinnerAccessible::CurValue() const { + double value = HTMLTextFieldAccessible::CurValue(); + if (!IsNaN(value)) return value; + + return HTMLInputElement::FromNode(mContent)->GetValueAsDecimal().toDouble(); +} + +bool HTMLSpinnerAccessible::SetCurValue(double aValue) { + ErrorResult er; + HTMLInputElement::FromNode(mContent)->SetValueAsNumber(aValue, er); + return !er.Failed(); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLRangeAccessible +//////////////////////////////////////////////////////////////////////////////// + +role HTMLRangeAccessible::NativeRole() const { return roles::SLIDER; } + +bool HTMLRangeAccessible::IsWidget() const { return true; } + +void HTMLRangeAccessible::Value(nsString& aValue) const { + LeafAccessible::Value(aValue); + if (!aValue.IsEmpty()) return; + + // Pass NonSystem as the caller type, to be safe. We don't expect to have a + // file input here. + HTMLInputElement::FromNode(mContent)->GetValue(aValue, CallerType::NonSystem); +} + +double HTMLRangeAccessible::MaxValue() const { + double value = LeafAccessible::MaxValue(); + if (!IsNaN(value)) return value; + + return HTMLInputElement::FromNode(mContent)->GetMaximum().toDouble(); +} + +double HTMLRangeAccessible::MinValue() const { + double value = LeafAccessible::MinValue(); + if (!IsNaN(value)) return value; + + return HTMLInputElement::FromNode(mContent)->GetMinimum().toDouble(); +} + +double HTMLRangeAccessible::Step() const { + double value = LeafAccessible::Step(); + if (!IsNaN(value)) return value; + + return HTMLInputElement::FromNode(mContent)->GetStep().toDouble(); +} + +double HTMLRangeAccessible::CurValue() const { + double value = LeafAccessible::CurValue(); + if (!IsNaN(value)) return value; + + return HTMLInputElement::FromNode(mContent)->GetValueAsDecimal().toDouble(); +} + +bool HTMLRangeAccessible::SetCurValue(double aValue) { + ErrorResult er; + HTMLInputElement::FromNode(mContent)->SetValueAsNumber(aValue, er); + return !er.Failed(); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLGroupboxAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLGroupboxAccessible::HTMLGroupboxAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) {} + +role HTMLGroupboxAccessible::NativeRole() const { return roles::GROUPING; } + +nsIContent* HTMLGroupboxAccessible::GetLegend() const { + for (nsIContent* legendContent = mContent->GetFirstChild(); legendContent; + legendContent = legendContent->GetNextSibling()) { + if (legendContent->NodeInfo()->Equals(nsGkAtoms::legend, + mContent->GetNameSpaceID())) { + // Either XHTML namespace or no namespace + return legendContent; + } + } + + return nullptr; +} + +ENameValueFlag HTMLGroupboxAccessible::NativeName(nsString& aName) const { + ENameValueFlag nameFlag = Accessible::NativeName(aName); + if (!aName.IsEmpty()) return nameFlag; + + nsIContent* legendContent = GetLegend(); + if (legendContent) + nsTextEquivUtils::AppendTextEquivFromContent(this, legendContent, &aName); + + aName.CompressWhitespace(); + return eNameOK; +} + +Relation HTMLGroupboxAccessible::RelationByType(RelationType aType) const { + Relation rel = HyperTextAccessibleWrap::RelationByType(aType); + // No override for label, so use <legend> for this <fieldset> + if (aType == RelationType::LABELLED_BY) rel.AppendTarget(mDoc, GetLegend()); + + return rel; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLLegendAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLLegendAccessible::HTMLLegendAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) {} + +Relation HTMLLegendAccessible::RelationByType(RelationType aType) const { + Relation rel = HyperTextAccessibleWrap::RelationByType(aType); + if (aType != RelationType::LABEL_FOR) return rel; + + Accessible* groupbox = Parent(); + if (groupbox && groupbox->Role() == roles::GROUPING) + rel.AppendTarget(groupbox); + + return rel; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLFigureAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLFigureAccessible::HTMLFigureAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) {} + +ENameValueFlag HTMLFigureAccessible::NativeName(nsString& aName) const { + ENameValueFlag nameFlag = HyperTextAccessibleWrap::NativeName(aName); + if (!aName.IsEmpty()) return nameFlag; + + nsIContent* captionContent = Caption(); + if (captionContent) + nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, &aName); + + aName.CompressWhitespace(); + return eNameOK; +} + +Relation HTMLFigureAccessible::RelationByType(RelationType aType) const { + Relation rel = HyperTextAccessibleWrap::RelationByType(aType); + if (aType == RelationType::LABELLED_BY) rel.AppendTarget(mDoc, Caption()); + + return rel; +} + +nsIContent* HTMLFigureAccessible::Caption() const { + for (nsIContent* childContent = mContent->GetFirstChild(); childContent; + childContent = childContent->GetNextSibling()) { + if (childContent->NodeInfo()->Equals(nsGkAtoms::figcaption, + mContent->GetNameSpaceID())) { + return childContent; + } + } + + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLFigcaptionAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLFigcaptionAccessible::HTMLFigcaptionAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) {} + +Relation HTMLFigcaptionAccessible::RelationByType(RelationType aType) const { + Relation rel = HyperTextAccessibleWrap::RelationByType(aType); + if (aType != RelationType::LABEL_FOR) return rel; + + Accessible* figure = Parent(); + if (figure && figure->GetContent()->NodeInfo()->Equals( + nsGkAtoms::figure, mContent->GetNameSpaceID())) { + rel.AppendTarget(figure); + } + + return rel; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLProgressAccessible +//////////////////////////////////////////////////////////////////////////////// + +role HTMLProgressAccessible::NativeRole() const { return roles::PROGRESSBAR; } + +uint64_t HTMLProgressAccessible::NativeState() const { + uint64_t state = LeafAccessible::NativeState(); + + // An undetermined progressbar (i.e. without a value) has a mixed state. + nsAutoString attrValue; + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::value, + attrValue); + if (attrValue.IsEmpty()) { + state |= states::MIXED; + } + + return state; +} + +bool HTMLProgressAccessible::IsWidget() const { return true; } + +void HTMLProgressAccessible::Value(nsString& aValue) const { + LeafAccessible::Value(aValue); + if (!aValue.IsEmpty()) { + return; + } + + double maxValue = MaxValue(); + if (IsNaN(maxValue) || maxValue == 0) { + return; + } + + double curValue = CurValue(); + if (IsNaN(curValue)) { + return; + } + + // Treat the current value bigger than maximum as 100%. + double percentValue = + (curValue < maxValue) ? (curValue / maxValue) * 100 : 100; + + aValue.AppendFloat(percentValue); + aValue.Append('%'); +} + +double HTMLProgressAccessible::MaxValue() const { + double value = LeafAccessible::MaxValue(); + if (!IsNaN(value)) { + return value; + } + + nsAutoString strValue; + if (mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::max, + strValue)) { + nsresult result = NS_OK; + value = strValue.ToDouble(&result); + if (NS_SUCCEEDED(result)) { + return value; + } + } + + return 1; +} + +double HTMLProgressAccessible::MinValue() const { + double value = LeafAccessible::MinValue(); + return IsNaN(value) ? 0 : value; +} + +double HTMLProgressAccessible::Step() const { + double value = LeafAccessible::Step(); + return IsNaN(value) ? 0 : value; +} + +double HTMLProgressAccessible::CurValue() const { + double value = LeafAccessible::CurValue(); + if (!IsNaN(value)) { + return value; + } + + nsAutoString attrValue; + if (!mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::value, + attrValue)) { + return UnspecifiedNaN<double>(); + } + + nsresult error = NS_OK; + value = attrValue.ToDouble(&error); + return NS_FAILED(error) ? UnspecifiedNaN<double>() : value; +} + +bool HTMLProgressAccessible::SetCurValue(double aValue) { + return false; // progress meters are readonly. +} diff --git a/accessible/html/HTMLFormControlAccessible.h b/accessible/html/HTMLFormControlAccessible.h new file mode 100644 index 0000000000..fce3b484ea --- /dev/null +++ b/accessible/html/HTMLFormControlAccessible.h @@ -0,0 +1,330 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#ifndef MOZILLA_A11Y_HTMLFormControlAccessible_H_ +#define MOZILLA_A11Y_HTMLFormControlAccessible_H_ + +#include "FormControlAccessible.h" +#include "HyperTextAccessibleWrap.h" +#include "mozilla/dom/Element.h" +#include "nsAccUtils.h" +#include "nsIPersistentProperties2.h" +#include "Relation.h" + +namespace mozilla { +class TextEditor; +namespace a11y { + +/** + * Accessible for HTML input@type="radio" element. + */ +class HTMLRadioButtonAccessible : public RadioButtonAccessible { + public: + HTMLRadioButtonAccessible(nsIContent* aContent, DocAccessible* aDoc) + : RadioButtonAccessible(aContent, aDoc) { + // Ignore "RadioStateChange" DOM event in lieu of document observer + // state change notification. + mStateFlags |= eIgnoreDOMUIEvent; + } + + // Accessible + virtual uint64_t NativeState() const override; + virtual void GetPositionAndSizeInternal(int32_t* aPosInSet, + int32_t* aSetSize) override; + virtual Relation RelationByType(RelationType aType) const override; + + private: + Relation ComputeGroupAttributes(int32_t* aPosInSet, int32_t* aSetSize) const; +}; + +/** + * Accessible for HTML input@type="button", @type="submit", @type="image" + * and HTML button elements. + */ +class HTMLButtonAccessible : public HyperTextAccessibleWrap { + public: + enum { eAction_Click = 0 }; + + HTMLButtonAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // Accessible + virtual mozilla::a11y::role NativeRole() const override; + virtual uint64_t State() override; + virtual uint64_t NativeState() const override; + + // ActionAccessible + virtual uint8_t ActionCount() const override; + virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override; + virtual bool DoAction(uint8_t aIndex) const override; + + // Widgets + virtual bool IsWidget() const override; + + protected: + // Accessible + virtual ENameValueFlag NativeName(nsString& aName) const override; +}; + +/** + * Accessible for HTML input@type="text", input@type="password", textarea and + * other HTML text controls. + */ +class HTMLTextFieldAccessible : public HyperTextAccessibleWrap { + public: + enum { eAction_Click = 0 }; + + HTMLTextFieldAccessible(nsIContent* aContent, DocAccessible* aDoc); + + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLTextFieldAccessible, + HyperTextAccessibleWrap) + + // HyperTextAccessible + MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual already_AddRefed<TextEditor> GetEditor() + const override; + + // Accessible + virtual void Value(nsString& aValue) const override; + virtual void ApplyARIAState(uint64_t* aState) const override; + virtual mozilla::a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() override; + + // ActionAccessible + virtual uint8_t ActionCount() const override; + virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override; + virtual bool DoAction(uint8_t aIndex) const override; + + // Widgets + virtual bool IsWidget() const override; + virtual Accessible* ContainerWidget() const override; + + protected: + virtual ~HTMLTextFieldAccessible() {} + + // Accessible + virtual ENameValueFlag NativeName(nsString& aName) const override; + + /** + * Return a widget element this input is part of, for example, search-textbox. + * + * FIXME: This should probably be renamed. + */ + nsIContent* BindingOrWidgetParent() const { + if (auto* el = mContent->GetClosestNativeAnonymousSubtreeRootParent()) { + return el; + } + // XUL search-textbox custom element + return Elm()->Closest("search-textbox"_ns, IgnoreErrors()); + } +}; + +/** + * Accessible for input@type="file" element. + */ +class HTMLFileInputAccessible : public HyperTextAccessibleWrap { + public: + HTMLFileInputAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // Accessible + virtual mozilla::a11y::role NativeRole() const override; + virtual nsresult HandleAccEvent(AccEvent* aAccEvent) override; + virtual Accessible* CurrentItem() const override; +}; + +/** + * Used for HTML input@type="number". + */ +class HTMLSpinnerAccessible final : public HTMLTextFieldAccessible { + public: + HTMLSpinnerAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HTMLTextFieldAccessible(aContent, aDoc) { + mStateFlags |= eHasNumericValue; + } + + // Accessible + virtual mozilla::a11y::role NativeRole() const override; + virtual void Value(nsString& aValue) const override; + + virtual double MaxValue() const override; + virtual double MinValue() const override; + virtual double CurValue() const override; + virtual double Step() const override; + virtual bool SetCurValue(double aValue) override; +}; + +/** + * Used for input@type="range" element. + */ +class HTMLRangeAccessible : public LeafAccessible { + public: + HTMLRangeAccessible(nsIContent* aContent, DocAccessible* aDoc) + : LeafAccessible(aContent, aDoc) { + mStateFlags |= eHasNumericValue; + } + + // Accessible + virtual void Value(nsString& aValue) const override; + virtual mozilla::a11y::role NativeRole() const override; + + // Value + virtual double MaxValue() const override; + virtual double MinValue() const override; + virtual double CurValue() const override; + virtual double Step() const override; + virtual bool SetCurValue(double aValue) override; + + // Widgets + virtual bool IsWidget() const override; +}; + +/** + * Accessible for HTML fieldset element. + */ +class HTMLGroupboxAccessible : public HyperTextAccessibleWrap { + public: + HTMLGroupboxAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // Accessible + virtual mozilla::a11y::role NativeRole() const override; + virtual Relation RelationByType(RelationType aType) const override; + + protected: + // Accessible + virtual ENameValueFlag NativeName(nsString& aName) const override; + + // HTMLGroupboxAccessible + nsIContent* GetLegend() const; +}; + +/** + * Accessible for HTML legend element. + */ +class HTMLLegendAccessible : public HyperTextAccessibleWrap { + public: + HTMLLegendAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // Accessible + virtual Relation RelationByType(RelationType aType) const override; +}; + +/** + * Accessible for HTML5 figure element. + */ +class HTMLFigureAccessible : public HyperTextAccessibleWrap { + public: + HTMLFigureAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // Accessible + virtual Relation RelationByType(RelationType aType) const override; + + protected: + // Accessible + virtual ENameValueFlag NativeName(nsString& aName) const override; + + // HTMLLegendAccessible + nsIContent* Caption() const; +}; + +/** + * Accessible for HTML5 figcaption element. + */ +class HTMLFigcaptionAccessible : public HyperTextAccessibleWrap { + public: + HTMLFigcaptionAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // Accessible + virtual Relation RelationByType(RelationType aType) const override; +}; + +/** + * Used for HTML form element. + */ +class HTMLFormAccessible : public HyperTextAccessibleWrap { + public: + HTMLFormAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) {} + + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLFormAccessible, + HyperTextAccessibleWrap) + + // Accessible + virtual nsAtom* LandmarkRole() const override; + virtual a11y::role NativeRole() const override; + + protected: + virtual ~HTMLFormAccessible() = default; +}; + +/** + * Accessible for HTML progress element. + */ + +class HTMLProgressAccessible : public LeafAccessible { + public: + HTMLProgressAccessible(nsIContent* aContent, DocAccessible* aDoc) + : LeafAccessible(aContent, aDoc) { + // Ignore 'ValueChange' DOM event in lieu of @value attribute change + // notifications. + mStateFlags |= eHasNumericValue | eIgnoreDOMUIEvent; + mType = eProgressType; + } + + // Accessible + virtual void Value(nsString& aValue) const override; + virtual mozilla::a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + + // Value + virtual double MaxValue() const override; + virtual double MinValue() const override; + virtual double CurValue() const override; + virtual double Step() const override; + virtual bool SetCurValue(double aValue) override; + + // Widgets + virtual bool IsWidget() const override; + + protected: + virtual ~HTMLProgressAccessible() {} +}; + +/** + * Accessible for HTML date/time inputs. + */ +template <a11y::role R> +class HTMLDateTimeAccessible : public AccessibleWrap { + public: + HTMLDateTimeAccessible(nsIContent* aContent, DocAccessible* aDoc) + : AccessibleWrap(aContent, aDoc) {} + + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLDateTimeAccessible, AccessibleWrap) + + // Accessible + virtual mozilla::a11y::role NativeRole() const override { return R; } + virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() + override { + nsCOMPtr<nsIPersistentProperties> attributes = + AccessibleWrap::NativeAttributes(); + // Unfortunately, an nsStaticAtom can't be passed as a + // template argument, so fetch the type from the DOM. + nsAutoString type; + if (mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::type, + type)) { + nsAccUtils::SetAccAttr(attributes, nsGkAtoms::textInputType, type); + } + return attributes.forget(); + } + + // Widgets + virtual bool IsWidget() const override { return true; } + + protected: + virtual ~HTMLDateTimeAccessible() {} +}; + +} // namespace a11y +} // namespace mozilla + +#endif diff --git a/accessible/html/HTMLImageMapAccessible.cpp b/accessible/html/HTMLImageMapAccessible.cpp new file mode 100644 index 0000000000..af416866f0 --- /dev/null +++ b/accessible/html/HTMLImageMapAccessible.cpp @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#include "HTMLImageMapAccessible.h" + +#include "ARIAMap.h" +#include "nsAccUtils.h" +#include "DocAccessible-inl.h" +#include "Role.h" + +#include "nsIFrame.h" +#include "nsImageFrame.h" +#include "nsImageMap.h" +#include "nsIURI.h" +#include "mozilla/dom/HTMLAreaElement.h" + +using namespace mozilla::a11y; + +//////////////////////////////////////////////////////////////////////////////// +// HTMLImageMapAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLImageMapAccessible::HTMLImageMapAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : ImageAccessibleWrap(aContent, aDoc) { + mType = eImageMapType; + + UpdateChildAreas(false); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLImageMapAccessible: Accessible public + +role HTMLImageMapAccessible::NativeRole() const { return roles::IMAGE_MAP; } + +//////////////////////////////////////////////////////////////////////////////// +// HTMLImageMapAccessible: HyperLinkAccessible + +uint32_t HTMLImageMapAccessible::AnchorCount() { return ChildCount(); } + +Accessible* HTMLImageMapAccessible::AnchorAt(uint32_t aAnchorIndex) { + return GetChildAt(aAnchorIndex); +} + +already_AddRefed<nsIURI> HTMLImageMapAccessible::AnchorURIAt( + uint32_t aAnchorIndex) const { + Accessible* area = GetChildAt(aAnchorIndex); + if (!area) return nullptr; + + nsIContent* linkContent = area->GetContent(); + return linkContent ? linkContent->GetHrefURI() : nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLImageMapAccessible: public + +void HTMLImageMapAccessible::UpdateChildAreas(bool aDoFireEvents) { + nsImageFrame* imageFrame = do_QueryFrame(mContent->GetPrimaryFrame()); + + // If image map is not initialized yet then we trigger one time more later. + nsImageMap* imageMapObj = imageFrame->GetExistingImageMap(); + if (!imageMapObj) return; + + TreeMutation mt(this, TreeMutation::kNoEvents & !aDoFireEvents); + + // Remove areas that are not a valid part of the image map anymore. + for (int32_t childIdx = mChildren.Length() - 1; childIdx >= 0; childIdx--) { + Accessible* area = mChildren.ElementAt(childIdx); + if (area->GetContent()->GetPrimaryFrame()) continue; + + mt.BeforeRemoval(area); + RemoveChild(area); + } + + // Insert new areas into the tree. + uint32_t areaElmCount = imageMapObj->AreaCount(); + for (uint32_t idx = 0; idx < areaElmCount; idx++) { + nsIContent* areaContent = imageMapObj->GetAreaAt(idx); + Accessible* area = mChildren.SafeElementAt(idx); + if (!area || area->GetContent() != areaContent) { + RefPtr<Accessible> area = new HTMLAreaAccessible(areaContent, mDoc); + mDoc->BindToDocument(area, aria::GetRoleMap(areaContent->AsElement())); + + if (!InsertChildAt(idx, area)) { + mDoc->UnbindFromDocument(area); + break; + } + + mt.AfterInsertion(area); + } + } + + mt.Done(); +} + +Accessible* HTMLImageMapAccessible::GetChildAccessibleFor( + const nsINode* aNode) const { + uint32_t length = mChildren.Length(); + for (uint32_t i = 0; i < length; i++) { + Accessible* area = mChildren[i]; + if (area->GetContent() == aNode) return area; + } + + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLAreaAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLAreaAccessible::HTMLAreaAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HTMLLinkAccessible(aContent, aDoc) { + // Make HTML area DOM element not accessible. HTML image map accessible + // manages its tree itself. + mStateFlags |= eNotNodeMapEntry; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLAreaAccessible: Accessible + +ENameValueFlag HTMLAreaAccessible::NativeName(nsString& aName) const { + ENameValueFlag nameFlag = Accessible::NativeName(aName); + if (!aName.IsEmpty()) return nameFlag; + + if (!mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, aName)) + Value(aName); + + return eNameOK; +} + +void HTMLAreaAccessible::Description(nsString& aDescription) { + aDescription.Truncate(); + + // Still to do - follow IE's standard here + RefPtr<dom::HTMLAreaElement> area = + dom::HTMLAreaElement::FromNodeOrNull(mContent); + if (area) area->GetShape(aDescription); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLAreaAccessible: Accessible public + +Accessible* HTMLAreaAccessible::ChildAtPoint(int32_t aX, int32_t aY, + EWhichChildAtPoint aWhichChild) { + // Don't walk into area accessibles. + return this; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLImageMapAccessible: HyperLinkAccessible + +uint32_t HTMLAreaAccessible::StartOffset() { + // Image map accessible is not hypertext accessible therefore + // StartOffset/EndOffset implementations of Accessible doesn't work here. + // We return index in parent because image map contains area links only which + // are embedded objects. + // XXX: image map should be a hypertext accessible. + return IndexInParent(); +} + +uint32_t HTMLAreaAccessible::EndOffset() { return IndexInParent() + 1; } + +nsRect HTMLAreaAccessible::RelativeBounds(nsIFrame** aBoundingFrame) const { + nsIFrame* frame = GetFrame(); + if (!frame) return nsRect(); + + nsImageFrame* imageFrame = do_QueryFrame(frame); + nsImageMap* map = imageFrame->GetImageMap(); + + nsRect bounds; + nsresult rv = map->GetBoundsForAreaContent(mContent, bounds); + if (NS_FAILED(rv)) return nsRect(); + + // XXX Areas are screwy; they return their rects as a pair of points, one pair + // stored into the width and height. + *aBoundingFrame = frame; + bounds.SizeTo(bounds.Width() - bounds.X(), bounds.Height() - bounds.Y()); + return bounds; +} diff --git a/accessible/html/HTMLImageMapAccessible.h b/accessible/html/HTMLImageMapAccessible.h new file mode 100644 index 0000000000..fdc24303cb --- /dev/null +++ b/accessible/html/HTMLImageMapAccessible.h @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#ifndef mozilla_a11y_HTMLImageMapAccessible_h__ +#define mozilla_a11y_HTMLImageMapAccessible_h__ + +#include "HTMLLinkAccessible.h" +#include "ImageAccessibleWrap.h" + +namespace mozilla { +namespace a11y { + +/** + * Used for HTML image maps. + */ +class HTMLImageMapAccessible final : public ImageAccessibleWrap { + public: + HTMLImageMapAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // nsISupports and cycle collector + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLImageMapAccessible, + ImageAccessibleWrap) + + // Accessible + virtual a11y::role NativeRole() const override; + + // HyperLinkAccessible + virtual uint32_t AnchorCount() override; + virtual Accessible* AnchorAt(uint32_t aAnchorIndex) override; + virtual already_AddRefed<nsIURI> AnchorURIAt( + uint32_t aAnchorIndex) const override; + + /** + * Update area children of the image map. + */ + void UpdateChildAreas(bool aDoFireEvents = true); + + /** + * Return accessible of child node. + */ + Accessible* GetChildAccessibleFor(const nsINode* aNode) const; + + protected: + virtual ~HTMLImageMapAccessible() {} +}; + +/** + * Accessible for image map areas - must be child of image. + */ +class HTMLAreaAccessible final : public HTMLLinkAccessible { + public: + HTMLAreaAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // Accessible + virtual void Description(nsString& aDescription) override; + virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY, + EWhichChildAtPoint aWhichChild) override; + virtual nsRect RelativeBounds(nsIFrame** aBoundingFrame) const override; + + // HyperLinkAccessible + virtual uint32_t StartOffset() override; + virtual uint32_t EndOffset() override; + + virtual bool IsAcceptableChild(nsIContent* aEl) const override { + return false; + } + + protected: + // Accessible + virtual ENameValueFlag NativeName(nsString& aName) const override; +}; + +//////////////////////////////////////////////////////////////////////////////// +// Accessible downcasting method + +inline HTMLImageMapAccessible* Accessible::AsImageMap() { + return IsImageMap() ? static_cast<HTMLImageMapAccessible*>(this) : nullptr; +} + +} // namespace a11y +} // namespace mozilla + +#endif diff --git a/accessible/html/HTMLLinkAccessible.cpp b/accessible/html/HTMLLinkAccessible.cpp new file mode 100644 index 0000000000..a6b952dcf3 --- /dev/null +++ b/accessible/html/HTMLLinkAccessible.cpp @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#include "HTMLLinkAccessible.h" + +#include "nsCoreUtils.h" +#include "DocAccessible.h" +#include "Role.h" +#include "States.h" + +#include "nsContentUtils.h" +#include "mozilla/EventStates.h" +#include "mozilla/dom/Element.h" + +using namespace mozilla; +using namespace mozilla::a11y; + +//////////////////////////////////////////////////////////////////////////////// +// HTMLLinkAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLLinkAccessible::HTMLLinkAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) { + mType = eHTMLLinkType; +} + +//////////////////////////////////////////////////////////////////////////////// +// nsIAccessible + +role HTMLLinkAccessible::NativeRole() const { return roles::LINK; } + +uint64_t HTMLLinkAccessible::NativeState() const { + return HyperTextAccessibleWrap::NativeState() & ~states::READONLY; +} + +uint64_t HTMLLinkAccessible::NativeLinkState() const { + EventStates eventState = mContent->AsElement()->State(); + if (eventState.HasState(NS_EVENT_STATE_UNVISITED)) return states::LINKED; + + if (eventState.HasState(NS_EVENT_STATE_VISITED)) + return states::LINKED | states::TRAVERSED; + + // This is a either named anchor (a link with also a name attribute) or + // it doesn't have any attributes. Check if 'click' event handler is + // registered, otherwise bail out. + return nsCoreUtils::HasClickListener(mContent) ? states::LINKED : 0; +} + +uint64_t HTMLLinkAccessible::NativeInteractiveState() const { + uint64_t state = HyperTextAccessibleWrap::NativeInteractiveState(); + + // This is how we indicate it is a named anchor. In other words, this anchor + // can be selected as a location :) There is no other better state to use to + // indicate this. + if (mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::name)) + state |= states::SELECTABLE; + + return state; +} + +void HTMLLinkAccessible::Value(nsString& aValue) const { + aValue.Truncate(); + + HyperTextAccessible::Value(aValue); + if (aValue.IsEmpty()) + nsContentUtils::GetLinkLocation(mContent->AsElement(), aValue); +} + +uint8_t HTMLLinkAccessible::ActionCount() const { + return IsLinked() ? 1 : HyperTextAccessible::ActionCount(); +} + +void HTMLLinkAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) { + aName.Truncate(); + + if (!IsLinked()) { + HyperTextAccessible::ActionNameAt(aIndex, aName); + return; + } + + // Action 0 (default action): Jump to link + if (aIndex == eAction_Jump) aName.AssignLiteral("jump"); +} + +bool HTMLLinkAccessible::DoAction(uint8_t aIndex) const { + if (!IsLinked()) return HyperTextAccessible::DoAction(aIndex); + + // Action 0 (default action): Jump to link + if (aIndex != eAction_Jump) return false; + + DoCommand(); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// +// HyperLinkAccessible + +bool HTMLLinkAccessible::IsLink() const { + // Expose HyperLinkAccessible unconditionally. + return true; +} + +already_AddRefed<nsIURI> HTMLLinkAccessible::AnchorURIAt( + uint32_t aAnchorIndex) const { + return aAnchorIndex == 0 ? mContent->GetHrefURI() : nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLLinkAccessible + +bool HTMLLinkAccessible::IsLinked() const { + EventStates state = mContent->AsElement()->State(); + return state.HasAtLeastOneOfStates(NS_EVENT_STATE_VISITED | + NS_EVENT_STATE_UNVISITED); +} diff --git a/accessible/html/HTMLLinkAccessible.h b/accessible/html/HTMLLinkAccessible.h new file mode 100644 index 0000000000..01c8a3f620 --- /dev/null +++ b/accessible/html/HTMLLinkAccessible.h @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#ifndef mozilla_a11y_HTMLLinkAccessible_h__ +#define mozilla_a11y_HTMLLinkAccessible_h__ + +#include "HyperTextAccessibleWrap.h" + +namespace mozilla { +namespace a11y { + +class HTMLLinkAccessible : public HyperTextAccessibleWrap { + public: + HTMLLinkAccessible(nsIContent* aContent, DocAccessible* aDoc); + + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLLinkAccessible, + HyperTextAccessibleWrap) + + // Accessible + virtual void Value(nsString& aValue) const override; + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + virtual uint64_t NativeLinkState() const override; + virtual uint64_t NativeInteractiveState() const override; + + // ActionAccessible + virtual uint8_t ActionCount() const override; + virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override; + virtual bool DoAction(uint8_t aIndex) const override; + + // HyperLinkAccessible + virtual bool IsLink() const override; + virtual already_AddRefed<nsIURI> AnchorURIAt( + uint32_t aAnchorIndex) const override; + + /** + * Returns true if the link has href attribute. + */ + bool IsLinked() const; + + protected: + virtual ~HTMLLinkAccessible() {} + + enum { eAction_Jump = 0 }; +}; + +inline HTMLLinkAccessible* Accessible::AsHTMLLink() { + return IsHTMLLink() ? static_cast<HTMLLinkAccessible*>(this) : nullptr; +} + +} // namespace a11y +} // namespace mozilla + +#endif diff --git a/accessible/html/HTMLListAccessible.cpp b/accessible/html/HTMLListAccessible.cpp new file mode 100644 index 0000000000..ad403ab55a --- /dev/null +++ b/accessible/html/HTMLListAccessible.cpp @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* 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/. */ + +#include "HTMLListAccessible.h" + +#include "DocAccessible.h" +#include "EventTree.h" +#include "nsAccUtils.h" +#include "Role.h" +#include "States.h" + +#include "nsBulletFrame.h" +#include "nsLayoutUtils.h" + +using namespace mozilla; +using namespace mozilla::a11y; + +//////////////////////////////////////////////////////////////////////////////// +// HTMLListAccessible +//////////////////////////////////////////////////////////////////////////////// + +role HTMLListAccessible::NativeRole() const { + a11y::role r = GetAccService()->MarkupRole(mContent); + return r != roles::NOTHING ? r : roles::LIST; +} + +uint64_t HTMLListAccessible::NativeState() const { + return HyperTextAccessibleWrap::NativeState() | states::READONLY; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLLIAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLLIAccessible::HTMLLIAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc), mBullet(nullptr) { + mType = eHTMLLiType; + + if (nsBulletFrame* bulletFrame = + do_QueryFrame(nsLayoutUtils::GetMarkerFrame(aContent))) { + const nsStyleList* styleList = bulletFrame->StyleList(); + if (styleList->GetListStyleImage() || !styleList->mCounterStyle.IsNone()) { + mBullet = new HTMLListBulletAccessible(mContent, mDoc); + Document()->BindToDocument(mBullet, nullptr); + AppendChild(mBullet); + } + } +} + +void HTMLLIAccessible::Shutdown() { + mBullet = nullptr; + + HyperTextAccessibleWrap::Shutdown(); +} + +role HTMLLIAccessible::NativeRole() const { + a11y::role r = GetAccService()->MarkupRole(mContent); + return r != roles::NOTHING ? r : roles::LISTITEM; +} + +uint64_t HTMLLIAccessible::NativeState() const { + return HyperTextAccessibleWrap::NativeState() | states::READONLY; +} + +nsRect HTMLLIAccessible::BoundsInAppUnits() const { + nsRect rect = AccessibleWrap::BoundsInAppUnits(); + if (rect.IsEmpty() || !mBullet || mBullet->IsInside()) { + return rect; + } + + nsRect bulletRect = mBullet->BoundsInAppUnits(); + // Move x coordinate of list item over to cover bullet as well + rect.SetLeftEdge(bulletRect.X()); + return rect; +} + +bool HTMLLIAccessible::InsertChildAt(uint32_t aIndex, Accessible* aChild) { + // Adjust index if there's a bullet. + if (mBullet && aIndex == 0 && aChild != mBullet) { + return HyperTextAccessible::InsertChildAt(aIndex + 1, aChild); + } + + return HyperTextAccessible::InsertChildAt(aIndex, aChild); +} + +void HTMLLIAccessible::RelocateChild(uint32_t aNewIndex, Accessible* aChild) { + // Don't allow moving a child in front of the bullet. + if (mBullet && aChild != mBullet && aNewIndex != 0) { + HyperTextAccessible::RelocateChild(aNewIndex, aChild); + } +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLLIAccessible: public + +void HTMLLIAccessible::UpdateBullet(bool aHasBullet) { + if (aHasBullet == !!mBullet) { + MOZ_ASSERT_UNREACHABLE("Bullet and accessible are in sync already!"); + return; + } + + TreeMutation mt(this); + if (aHasBullet) { + mBullet = new HTMLListBulletAccessible(mContent, mDoc); + mDoc->BindToDocument(mBullet, nullptr); + InsertChildAt(0, mBullet); + mt.AfterInsertion(mBullet); + } else { + mt.BeforeRemoval(mBullet); + RemoveChild(mBullet); + mBullet = nullptr; + } + mt.Done(); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLListBulletAccessible +//////////////////////////////////////////////////////////////////////////////// +HTMLListBulletAccessible::HTMLListBulletAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : LeafAccessible(aContent, aDoc) { + mGenericTypes |= eText; + mStateFlags |= eSharedNode; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLListBulletAccessible: Accessible + +nsIFrame* HTMLListBulletAccessible::GetFrame() const { + return nsLayoutUtils::GetMarkerFrame(mContent); +} + +ENameValueFlag HTMLListBulletAccessible::Name(nsString& aName) const { + aName.Truncate(); + + // Native anonymous content, ARIA can't be used. Get list bullet text. + nsBulletFrame* frame = do_QueryFrame(GetFrame()); + if (!frame) { + return eNameOK; + } + + if (frame->StyleList()->GetListStyleImage()) { + // Bullet is an image, so use default bullet character. + const char16_t kDiscCharacter = 0x2022; + aName.Assign(kDiscCharacter); + aName.Append(' '); + return eNameOK; + } + + frame->GetSpokenText(aName); + return eNameOK; +} + +role HTMLListBulletAccessible::NativeRole() const { + return roles::LISTITEM_MARKER; +} + +uint64_t HTMLListBulletAccessible::NativeState() const { + return LeafAccessible::NativeState() | states::READONLY; +} + +void HTMLListBulletAccessible::AppendTextTo(nsAString& aText, + uint32_t aStartOffset, + uint32_t aLength) { + nsAutoString bulletText; + Name(bulletText); + aText.Append(Substring(bulletText, aStartOffset, aLength)); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLListBulletAccessible: public + +bool HTMLListBulletAccessible::IsInside() const { + if (nsIFrame* frame = mContent->GetPrimaryFrame()) { + return frame->StyleList()->mListStylePosition == + NS_STYLE_LIST_STYLE_POSITION_INSIDE; + } + return false; +} diff --git a/accessible/html/HTMLListAccessible.h b/accessible/html/HTMLListAccessible.h new file mode 100644 index 0000000000..c78e6d3b18 --- /dev/null +++ b/accessible/html/HTMLListAccessible.h @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* 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/. */ + +#ifndef mozilla_a11y_HTMLListAccessible_h__ +#define mozilla_a11y_HTMLListAccessible_h__ + +#include "BaseAccessibles.h" +#include "HyperTextAccessibleWrap.h" + +namespace mozilla { +namespace a11y { + +class HTMLListBulletAccessible; + +/** + * Used for HTML list (like HTML ul). + */ +class HTMLListAccessible : public HyperTextAccessibleWrap { + public: + HTMLListAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) { + mGenericTypes |= eList; + } + + // nsISupports + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLListAccessible, + HyperTextAccessibleWrap) + + // Accessible + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + + protected: + virtual ~HTMLListAccessible() {} +}; + +/** + * Used for HTML list item (e.g. HTML li). + */ +class HTMLLIAccessible : public HyperTextAccessibleWrap { + public: + HTMLLIAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // nsISupports + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLLIAccessible, + HyperTextAccessibleWrap) + + // Accessible + virtual void Shutdown() override; + virtual nsRect BoundsInAppUnits() const override; + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + + virtual bool InsertChildAt(uint32_t aIndex, Accessible* aChild) override; + virtual void RelocateChild(uint32_t aNewIndex, Accessible* aChild) override; + + // HTMLLIAccessible + HTMLListBulletAccessible* Bullet() const { return mBullet; } + void UpdateBullet(bool aHasBullet); + + protected: + virtual ~HTMLLIAccessible() {} + + private: + HTMLListBulletAccessible* mBullet; +}; + +/** + * Used for bullet of HTML list item element (for example, HTML li). + */ +class HTMLListBulletAccessible : public LeafAccessible { + public: + HTMLListBulletAccessible(nsIContent* aContent, DocAccessible* aDoc); + virtual ~HTMLListBulletAccessible() {} + + // Accessible + virtual nsIFrame* GetFrame() const override; + virtual ENameValueFlag Name(nsString& aName) const override; + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + virtual void AppendTextTo(nsAString& aText, uint32_t aStartOffset = 0, + uint32_t aLength = UINT32_MAX) override; + + // HTMLListBulletAccessible + + /** + * Return true if the bullet is inside of list item element boundaries. + */ + bool IsInside() const; +}; + +inline HTMLLIAccessible* Accessible::AsHTMLListItem() { + return IsHTMLListItem() ? static_cast<HTMLLIAccessible*>(this) : nullptr; +} + +} // namespace a11y +} // namespace mozilla + +#endif diff --git a/accessible/html/HTMLSelectAccessible.cpp b/accessible/html/HTMLSelectAccessible.cpp new file mode 100644 index 0000000000..4dc6c4dade --- /dev/null +++ b/accessible/html/HTMLSelectAccessible.cpp @@ -0,0 +1,496 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#include "HTMLSelectAccessible.h" + +#include "Accessible-inl.h" +#include "nsAccessibilityService.h" +#include "nsAccUtils.h" +#include "DocAccessible.h" +#include "nsEventShell.h" +#include "nsTextEquivUtils.h" +#include "Role.h" +#include "States.h" + +#include "nsCOMPtr.h" +#include "mozilla/dom/HTMLOptionElement.h" +#include "mozilla/dom/HTMLSelectElement.h" +#include "nsComboboxControlFrame.h" +#include "nsContainerFrame.h" +#include "nsListControlFrame.h" + +using namespace mozilla::a11y; +using namespace mozilla::dom; + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSelectListAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLSelectListAccessible::HTMLSelectListAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : AccessibleWrap(aContent, aDoc) { + mGenericTypes |= eListControl | eSelect; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSelectListAccessible: Accessible public + +uint64_t HTMLSelectListAccessible::NativeState() const { + uint64_t state = AccessibleWrap::NativeState(); + if (mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::multiple)) + state |= states::MULTISELECTABLE | states::EXTSELECTABLE; + + return state; +} + +role HTMLSelectListAccessible::NativeRole() const { return roles::LISTBOX; } + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSelectListAccessible: SelectAccessible + +bool HTMLSelectListAccessible::SelectAll() { + return mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::multiple) + ? AccessibleWrap::SelectAll() + : false; +} + +bool HTMLSelectListAccessible::UnselectAll() { + return mContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::multiple) + ? AccessibleWrap::UnselectAll() + : false; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSelectListAccessible: Widgets + +bool HTMLSelectListAccessible::IsWidget() const { return true; } + +bool HTMLSelectListAccessible::IsActiveWidget() const { + return FocusMgr()->HasDOMFocus(mContent); +} + +bool HTMLSelectListAccessible::AreItemsOperable() const { return true; } + +Accessible* HTMLSelectListAccessible::CurrentItem() const { + nsListControlFrame* listControlFrame = do_QueryFrame(GetFrame()); + if (listControlFrame) { + nsCOMPtr<nsIContent> activeOptionNode = + listControlFrame->GetCurrentOption(); + if (activeOptionNode) { + DocAccessible* document = Document(); + if (document) return document->GetAccessible(activeOptionNode); + } + } + return nullptr; +} + +void HTMLSelectListAccessible::SetCurrentItem(const Accessible* aItem) { + if (!aItem->GetContent()->IsElement()) return; + + aItem->GetContent()->AsElement()->SetAttr( + kNameSpaceID_None, nsGkAtoms::selected, u"true"_ns, true); +} + +bool HTMLSelectListAccessible::IsAcceptableChild(nsIContent* aEl) const { + return aEl->IsAnyOfHTMLElements(nsGkAtoms::option, nsGkAtoms::optgroup); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSelectOptionAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLSelectOptionAccessible::HTMLSelectOptionAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) {} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSelectOptionAccessible: Accessible public + +role HTMLSelectOptionAccessible::NativeRole() const { + if (GetCombobox()) return roles::COMBOBOX_OPTION; + + return roles::OPTION; +} + +ENameValueFlag HTMLSelectOptionAccessible::NativeName(nsString& aName) const { + // CASE #1 -- great majority of the cases + // find the label attribute - this is what the W3C says we should use + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::label, aName); + if (!aName.IsEmpty()) return eNameOK; + + // CASE #2 -- no label parameter, get the first child, + // use it if it is a text node + nsIContent* text = mContent->GetFirstChild(); + if (text && text->IsText()) { + nsTextEquivUtils::AppendTextEquivFromTextContent(text, &aName); + aName.CompressWhitespace(); + return aName.IsEmpty() ? eNameOK : eNameFromSubtree; + } + + return eNameOK; +} + +uint64_t HTMLSelectOptionAccessible::NativeState() const { + // As a HTMLSelectOptionAccessible we can have the following states: + // SELECTABLE, SELECTED, FOCUSED, FOCUSABLE, OFFSCREEN + // Upcall to Accessible, but skip HyperTextAccessible impl + // because we don't want EDITABLE or SELECTABLE_TEXT + uint64_t state = Accessible::NativeState(); + + Accessible* select = GetSelect(); + if (!select) return state; + + uint64_t selectState = select->State(); + if (selectState & states::INVISIBLE) return state; + + // Are we selected? + HTMLOptionElement* option = HTMLOptionElement::FromNode(mContent); + bool selected = option && option->Selected(); + if (selected) state |= states::SELECTED; + + if (selectState & states::OFFSCREEN) { + state |= states::OFFSCREEN; + } else if (selectState & states::COLLAPSED) { + // <select> is COLLAPSED: add OFFSCREEN, if not the currently + // visible option + if (!selected) { + state |= states::OFFSCREEN; + // Ensure the invisible state is removed. Otherwise, group info will skip + // this option. Furthermore, this gets cached and this doesn't get + // invalidated even once the select is expanded. + state &= ~states::INVISIBLE; + } else { + // Clear offscreen and invisible for currently showing option + state &= ~(states::OFFSCREEN | states::INVISIBLE); + state |= selectState & states::OPAQUE1; + } + } else { + // XXX list frames are weird, don't rely on Accessible's general + // visibility implementation unless they get reimplemented in layout + state &= ~states::OFFSCREEN; + // <select> is not collapsed: compare bounds to calculate OFFSCREEN + Accessible* listAcc = Parent(); + if (listAcc) { + nsIntRect optionRect = Bounds(); + nsIntRect listRect = listAcc->Bounds(); + if (optionRect.Y() < listRect.Y() || + optionRect.YMost() > listRect.YMost()) { + state |= states::OFFSCREEN; + } + } + } + + return state; +} + +uint64_t HTMLSelectOptionAccessible::NativeInteractiveState() const { + return NativelyUnavailable() ? states::UNAVAILABLE + : states::FOCUSABLE | states::SELECTABLE; +} + +int32_t HTMLSelectOptionAccessible::GetLevelInternal() { + nsIContent* parentContent = mContent->GetParent(); + + int32_t level = + parentContent->NodeInfo()->Equals(nsGkAtoms::optgroup) ? 2 : 1; + + if (level == 1 && Role() != roles::HEADING) + level = 0; // In a single level list, the level is irrelevant + + return level; +} + +nsRect HTMLSelectOptionAccessible::RelativeBounds( + nsIFrame** aBoundingFrame) const { + Accessible* combobox = GetCombobox(); + if (combobox && (combobox->State() & states::COLLAPSED)) + return combobox->RelativeBounds(aBoundingFrame); + + return HyperTextAccessibleWrap::RelativeBounds(aBoundingFrame); +} + +void HTMLSelectOptionAccessible::ActionNameAt(uint8_t aIndex, + nsAString& aName) { + if (aIndex == eAction_Select) aName.AssignLiteral("select"); +} + +uint8_t HTMLSelectOptionAccessible::ActionCount() const { return 1; } + +bool HTMLSelectOptionAccessible::DoAction(uint8_t aIndex) const { + if (aIndex != eAction_Select) return false; + + DoCommand(); + return true; +} + +void HTMLSelectOptionAccessible::SetSelected(bool aSelect) { + HTMLOptionElement* option = HTMLOptionElement::FromNode(mContent); + if (option) option->SetSelected(aSelect); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSelectOptionAccessible: Widgets + +Accessible* HTMLSelectOptionAccessible::ContainerWidget() const { + Accessible* parent = Parent(); + if (parent && parent->IsHTMLOptGroup()) parent = parent->Parent(); + + return parent && parent->IsListControl() ? parent : nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLSelectOptGroupAccessible +//////////////////////////////////////////////////////////////////////////////// + +role HTMLSelectOptGroupAccessible::NativeRole() const { + return roles::GROUPING; +} + +uint64_t HTMLSelectOptGroupAccessible::NativeInteractiveState() const { + return NativelyUnavailable() ? states::UNAVAILABLE : 0; +} + +bool HTMLSelectOptGroupAccessible::IsAcceptableChild(nsIContent* aEl) const { + return aEl->IsCharacterData() || aEl->IsHTMLElement(nsGkAtoms::option); +} + +uint8_t HTMLSelectOptGroupAccessible::ActionCount() const { return 0; } + +void HTMLSelectOptGroupAccessible::ActionNameAt(uint8_t aIndex, + nsAString& aName) { + aName.Truncate(); +} + +bool HTMLSelectOptGroupAccessible::DoAction(uint8_t aIndex) const { + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLComboboxAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLComboboxAccessible::HTMLComboboxAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : AccessibleWrap(aContent, aDoc) { + mType = eHTMLComboboxType; + mGenericTypes |= eCombobox; + mStateFlags |= eNoKidsFromDOM; + + nsComboboxControlFrame* comboFrame = do_QueryFrame(GetFrame()); + if (comboFrame) { + nsIFrame* listFrame = comboFrame->GetDropDown(); + if (listFrame) { + mListAccessible = new HTMLComboboxListAccessible(mParent, mContent, mDoc); + Document()->BindToDocument(mListAccessible, nullptr); + AppendChild(mListAccessible); + } + } +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLComboboxAccessible: Accessible + +role HTMLComboboxAccessible::NativeRole() const { return roles::COMBOBOX; } + +bool HTMLComboboxAccessible::RemoveChild(Accessible* aChild) { + MOZ_ASSERT(aChild == mListAccessible); + if (AccessibleWrap::RemoveChild(aChild)) { + mListAccessible = nullptr; + return true; + } + return false; +} + +void HTMLComboboxAccessible::Shutdown() { + MOZ_ASSERT(!mDoc || mDoc->IsDefunct() || !mListAccessible); + if (mListAccessible) { + mListAccessible->Shutdown(); + mListAccessible = nullptr; + } + + AccessibleWrap::Shutdown(); +} + +uint64_t HTMLComboboxAccessible::NativeState() const { + // As a HTMLComboboxAccessible we can have the following states: + // FOCUSED, FOCUSABLE, HASPOPUP, EXPANDED, COLLAPSED + // Get focus status from base class + uint64_t state = Accessible::NativeState(); + + nsComboboxControlFrame* comboFrame = do_QueryFrame(GetFrame()); + if (comboFrame && comboFrame->IsDroppedDown()) + state |= states::EXPANDED; + else + state |= states::COLLAPSED; + + state |= states::HASPOPUP; + return state; +} + +void HTMLComboboxAccessible::Description(nsString& aDescription) { + aDescription.Truncate(); + // First check to see if combo box itself has a description, perhaps through + // tooltip (title attribute) or via aria-describedby + Accessible::Description(aDescription); + if (!aDescription.IsEmpty()) return; + + // Otherwise use description of selected option. + Accessible* option = SelectedOption(); + if (option) option->Description(aDescription); +} + +void HTMLComboboxAccessible::Value(nsString& aValue) const { + // Use accessible name of selected option. + Accessible* option = SelectedOption(); + if (option) option->Name(aValue); +} + +uint8_t HTMLComboboxAccessible::ActionCount() const { return 1; } + +bool HTMLComboboxAccessible::DoAction(uint8_t aIndex) const { + if (aIndex != eAction_Click) return false; + + DoCommand(); + return true; +} + +void HTMLComboboxAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName) { + if (aIndex != HTMLComboboxAccessible::eAction_Click) return; + + nsComboboxControlFrame* comboFrame = do_QueryFrame(GetFrame()); + if (!comboFrame) return; + + if (comboFrame->IsDroppedDown()) + aName.AssignLiteral("close"); + else + aName.AssignLiteral("open"); +} + +bool HTMLComboboxAccessible::IsAcceptableChild(nsIContent* aEl) const { + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLComboboxAccessible: Widgets + +bool HTMLComboboxAccessible::IsWidget() const { return true; } + +bool HTMLComboboxAccessible::IsActiveWidget() const { + return FocusMgr()->HasDOMFocus(mContent); +} + +bool HTMLComboboxAccessible::AreItemsOperable() const { + nsComboboxControlFrame* comboboxFrame = do_QueryFrame(GetFrame()); + return comboboxFrame && comboboxFrame->IsDroppedDown(); +} + +Accessible* HTMLComboboxAccessible::CurrentItem() const { + return AreItemsOperable() ? mListAccessible->CurrentItem() : nullptr; +} + +void HTMLComboboxAccessible::SetCurrentItem(const Accessible* aItem) { + if (AreItemsOperable()) mListAccessible->SetCurrentItem(aItem); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLComboboxAccessible: protected + +Accessible* HTMLComboboxAccessible::SelectedOption() const { + HTMLSelectElement* select = HTMLSelectElement::FromNode(mContent); + int32_t selectedIndex = select->SelectedIndex(); + + if (selectedIndex >= 0) { + HTMLOptionElement* option = select->Item(selectedIndex); + if (option) { + DocAccessible* document = Document(); + if (document) return document->GetAccessible(option); + } + } + + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLComboboxListAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLComboboxListAccessible::HTMLComboboxListAccessible(Accessible* aParent, + nsIContent* aContent, + DocAccessible* aDoc) + : HTMLSelectListAccessible(aContent, aDoc) { + mStateFlags |= eSharedNode; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLComboboxAccessible: Accessible + +nsIFrame* HTMLComboboxListAccessible::GetFrame() const { + nsIFrame* frame = HTMLSelectListAccessible::GetFrame(); + nsComboboxControlFrame* comboBox = do_QueryFrame(frame); + if (comboBox) { + return comboBox->GetDropDown(); + } + + return nullptr; +} + +role HTMLComboboxListAccessible::NativeRole() const { + return roles::COMBOBOX_LIST; +} + +uint64_t HTMLComboboxListAccessible::NativeState() const { + // As a HTMLComboboxListAccessible we can have the following states: + // FOCUSED, FOCUSABLE, FLOATING, INVISIBLE + // Get focus status from base class + uint64_t state = Accessible::NativeState(); + + nsComboboxControlFrame* comboFrame = do_QueryFrame(mParent->GetFrame()); + if (comboFrame && comboFrame->IsDroppedDown()) + state |= states::FLOATING; + else + state |= states::INVISIBLE; + + return state; +} + +nsRect HTMLComboboxListAccessible::RelativeBounds( + nsIFrame** aBoundingFrame) const { + *aBoundingFrame = nullptr; + + Accessible* comboAcc = Parent(); + if (!comboAcc) return nsRect(); + + if (0 == (comboAcc->State() & states::COLLAPSED)) { + return HTMLSelectListAccessible::RelativeBounds(aBoundingFrame); + } + + // Get the first option. + nsIContent* content = mContent->GetFirstChild(); + if (!content) return nsRect(); + + nsIFrame* frame = content->GetPrimaryFrame(); + if (!frame) { + *aBoundingFrame = nullptr; + return nsRect(); + } + + *aBoundingFrame = frame->GetParent(); + return (*aBoundingFrame)->GetRect(); +} + +bool HTMLComboboxListAccessible::IsAcceptableChild(nsIContent* aEl) const { + return aEl->IsAnyOfHTMLElements(nsGkAtoms::option, nsGkAtoms::optgroup); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLComboboxListAccessible: Widgets + +bool HTMLComboboxListAccessible::IsActiveWidget() const { + return mParent && mParent->IsActiveWidget(); +} + +bool HTMLComboboxListAccessible::AreItemsOperable() const { + return mParent && mParent->AreItemsOperable(); +} diff --git a/accessible/html/HTMLSelectAccessible.h b/accessible/html/HTMLSelectAccessible.h new file mode 100644 index 0000000000..b6c9dabbed --- /dev/null +++ b/accessible/html/HTMLSelectAccessible.h @@ -0,0 +1,212 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#ifndef mozilla_a11y_HTMLSelectAccessible_h__ +#define mozilla_a11y_HTMLSelectAccessible_h__ + +#include "HTMLFormControlAccessible.h" + +namespace mozilla { +namespace a11y { + +/** + * Selects, Listboxes and Comboboxes, are made up of a number of different + * widgets, some of which are shared between the two. This file contains + * all of the widgets for both of the Selects, for HTML only. + * + * Listbox: + * - HTMLSelectListAccessible + * - HTMLSelectOptionAccessible + * + * Comboboxes: + * - HTMLComboboxAccessible + * - HTMLComboboxListAccessible [ inserted in accessible tree ] + * - HTMLSelectOptionAccessible(s) + */ + +/* + * The list that contains all the options in the select. + */ +class HTMLSelectListAccessible : public AccessibleWrap { + public: + HTMLSelectListAccessible(nsIContent* aContent, DocAccessible* aDoc); + virtual ~HTMLSelectListAccessible() {} + + // Accessible + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + virtual bool IsAcceptableChild(nsIContent* aEl) const override; + + // SelectAccessible + virtual bool SelectAll() override; + virtual bool UnselectAll() override; + + // Widgets + virtual bool IsWidget() const override; + virtual bool IsActiveWidget() const override; + virtual bool AreItemsOperable() const override; + virtual Accessible* CurrentItem() const override; + virtual void SetCurrentItem(const Accessible* aItem) override; +}; + +/* + * Options inside the select, contained within the list + */ +class HTMLSelectOptionAccessible : public HyperTextAccessibleWrap { + public: + enum { eAction_Select = 0 }; + + HTMLSelectOptionAccessible(nsIContent* aContent, DocAccessible* aDoc); + virtual ~HTMLSelectOptionAccessible() {} + + // Accessible + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + virtual uint64_t NativeInteractiveState() const override; + + virtual int32_t GetLevelInternal() override; + virtual nsRect RelativeBounds(nsIFrame** aBoundingFrame) const override; + virtual void SetSelected(bool aSelect) override; + + // ActionAccessible + virtual uint8_t ActionCount() const override; + virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override; + virtual bool DoAction(uint8_t aIndex) const override; + + // Widgets + virtual Accessible* ContainerWidget() const override; + + protected: + // Accessible + virtual ENameValueFlag NativeName(nsString& aName) const override; + + private: + /** + * Return a select accessible the option belongs to if any. + */ + Accessible* GetSelect() const { + Accessible* parent = mParent; + if (parent && parent->IsHTMLOptGroup()) parent = parent->Parent(); + + if (parent && parent->IsListControl()) { + Accessible* combobox = parent->Parent(); + return combobox && combobox->IsCombobox() ? combobox : mParent; + } + + return nullptr; + } + + /** + * Return a combobox accessible the option belongs to if any. + */ + Accessible* GetCombobox() const { + Accessible* parent = mParent; + if (parent && parent->IsHTMLOptGroup()) parent = parent->Parent(); + + if (parent && parent->IsListControl()) { + Accessible* combobox = parent->Parent(); + return combobox && combobox->IsCombobox() ? combobox : nullptr; + } + + return nullptr; + } +}; + +/* + * Opt Groups inside the select, contained within the list + */ +class HTMLSelectOptGroupAccessible : public HTMLSelectOptionAccessible { + public: + HTMLSelectOptGroupAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HTMLSelectOptionAccessible(aContent, aDoc) { + mType = eHTMLOptGroupType; + } + virtual ~HTMLSelectOptGroupAccessible() {} + + // Accessible + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeInteractiveState() const override; + virtual bool IsAcceptableChild(nsIContent* aEl) const override; + + // ActionAccessible + virtual uint8_t ActionCount() const override; + virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override; + virtual bool DoAction(uint8_t aIndex) const override; +}; + +/** ------------------------------------------------------ */ +/** Finally, the Combobox widgets */ +/** ------------------------------------------------------ */ + +class HTMLComboboxListAccessible; + +/* + * A class the represents the HTML Combobox widget. + */ +class HTMLComboboxAccessible final : public AccessibleWrap { + public: + enum { eAction_Click = 0 }; + + HTMLComboboxAccessible(nsIContent* aContent, DocAccessible* aDoc); + virtual ~HTMLComboboxAccessible() {} + + // Accessible + virtual void Shutdown() override; + virtual void Description(nsString& aDescription) override; + virtual void Value(nsString& aValue) const override; + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + virtual bool RemoveChild(Accessible* aChild) override; + virtual bool IsAcceptableChild(nsIContent* aEl) const override; + + // ActionAccessible + virtual uint8_t ActionCount() const override; + virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override; + virtual bool DoAction(uint8_t aIndex) const override; + + // Widgets + virtual bool IsWidget() const override; + virtual bool IsActiveWidget() const override; + virtual bool AreItemsOperable() const override; + virtual Accessible* CurrentItem() const override; + virtual void SetCurrentItem(const Accessible* aItem) override; + + protected: + /** + * Return selected option. + */ + Accessible* SelectedOption() const; + + private: + RefPtr<HTMLComboboxListAccessible> mListAccessible; +}; + +/* + * A class that represents the window that lives to the right + * of the drop down button inside the Select. This is the window + * that is made visible when the button is pressed. + */ +class HTMLComboboxListAccessible : public HTMLSelectListAccessible { + public: + HTMLComboboxListAccessible(Accessible* aParent, nsIContent* aContent, + DocAccessible* aDoc); + virtual ~HTMLComboboxListAccessible() {} + + // Accessible + virtual nsIFrame* GetFrame() const override; + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + virtual nsRect RelativeBounds(nsIFrame** aBoundingFrame) const override; + virtual bool IsAcceptableChild(nsIContent* aEl) const override; + + // Widgets + virtual bool IsActiveWidget() const override; + virtual bool AreItemsOperable() const override; +}; + +} // namespace a11y +} // namespace mozilla + +#endif diff --git a/accessible/html/HTMLTableAccessible.cpp b/accessible/html/HTMLTableAccessible.cpp new file mode 100644 index 0000000000..4a1979361a --- /dev/null +++ b/accessible/html/HTMLTableAccessible.cpp @@ -0,0 +1,806 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#include "HTMLTableAccessible.h" + +#include "mozilla/DebugOnly.h" + +#include "Accessible-inl.h" +#include "nsAccessibilityService.h" +#include "nsAccUtils.h" +#include "DocAccessible.h" +#include "nsTextEquivUtils.h" +#include "Relation.h" +#include "Role.h" +#include "States.h" +#include "TreeWalker.h" + +#include "mozilla/PresShell.h" +#include "mozilla/dom/HTMLTableElement.h" +#include "nsIHTMLCollection.h" +#include "mozilla/dom/Document.h" +#include "nsIPersistentProperties2.h" +#include "nsITableCellLayout.h" +#include "nsFrameSelection.h" +#include "nsError.h" +#include "nsArrayUtils.h" +#include "nsComponentManagerUtils.h" +#include "nsNameSpaceManager.h" +#include "nsTableCellFrame.h" +#include "nsTableWrapperFrame.h" + +using namespace mozilla; +using namespace mozilla::dom; +using namespace mozilla::a11y; + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableCellAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLTableCellAccessible::HTMLTableCellAccessible(nsIContent* aContent, + DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) { + mType = eHTMLTableCellType; + mGenericTypes |= eTableCell; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableCellAccessible: Accessible implementation + +role HTMLTableCellAccessible::NativeRole() const { + if (mContent->IsMathMLElement(nsGkAtoms::mtd_)) { + return roles::MATHML_CELL; + } + return roles::CELL; +} + +uint64_t HTMLTableCellAccessible::NativeState() const { + uint64_t state = HyperTextAccessibleWrap::NativeState(); + + nsIFrame* frame = mContent->GetPrimaryFrame(); + NS_ASSERTION(frame, "No frame for valid cell accessible!"); + + if (frame && frame->IsSelected()) state |= states::SELECTED; + + return state; +} + +uint64_t HTMLTableCellAccessible::NativeInteractiveState() const { + return HyperTextAccessibleWrap::NativeInteractiveState() | states::SELECTABLE; +} + +already_AddRefed<nsIPersistentProperties> +HTMLTableCellAccessible::NativeAttributes() { + nsCOMPtr<nsIPersistentProperties> attributes = + HyperTextAccessibleWrap::NativeAttributes(); + + // table-cell-index attribute + TableAccessible* table = Table(); + if (!table) return attributes.forget(); + + int32_t rowIdx = -1, colIdx = -1; + nsresult rv = GetCellIndexes(rowIdx, colIdx); + if (NS_FAILED(rv)) return attributes.forget(); + + nsAutoString stringIdx; + stringIdx.AppendInt(table->CellIndexAt(rowIdx, colIdx)); + nsAccUtils::SetAccAttr(attributes, nsGkAtoms::tableCellIndex, stringIdx); + + // abbr attribute + + // Pick up object attribute from abbr DOM element (a child of the cell) or + // from abbr DOM attribute. + nsAutoString abbrText; + if (ChildCount() == 1) { + Accessible* abbr = FirstChild(); + if (abbr->IsAbbreviation()) { + nsIContent* firstChildNode = abbr->GetContent()->GetFirstChild(); + if (firstChildNode) { + nsTextEquivUtils::AppendTextEquivFromTextContent(firstChildNode, + &abbrText); + } + } + } + if (abbrText.IsEmpty()) + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::abbr, + abbrText); + + if (!abbrText.IsEmpty()) + nsAccUtils::SetAccAttr(attributes, nsGkAtoms::abbr, abbrText); + + // axis attribute + nsAutoString axisText; + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::axis, axisText); + if (!axisText.IsEmpty()) + nsAccUtils::SetAccAttr(attributes, nsGkAtoms::axis, axisText); + +#ifdef DEBUG + nsAutoString unused; + attributes->SetStringProperty("cppclass"_ns, u"HTMLTableCellAccessible"_ns, + unused); +#endif + + return attributes.forget(); +} + +GroupPos HTMLTableCellAccessible::GroupPosition() { + int32_t count = 0, index = 0; + TableAccessible* table = Table(); + if (table && + nsCoreUtils::GetUIntAttr(table->AsAccessible()->GetContent(), + nsGkAtoms::aria_colcount, &count) && + nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_colindex, &index)) { + return GroupPos(0, index, count); + } + + return HyperTextAccessibleWrap::GroupPosition(); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableCellAccessible: TableCellAccessible implementation + +TableAccessible* HTMLTableCellAccessible::Table() const { + Accessible* parent = const_cast<HTMLTableCellAccessible*>(this); + while ((parent = parent->Parent())) { + if (parent->IsTable()) return parent->AsTable(); + } + + return nullptr; +} + +uint32_t HTMLTableCellAccessible::ColIdx() const { + nsTableCellFrame* cellFrame = GetCellFrame(); + NS_ENSURE_TRUE(cellFrame, 0); + return cellFrame->ColIndex(); +} + +uint32_t HTMLTableCellAccessible::RowIdx() const { + nsTableCellFrame* cellFrame = GetCellFrame(); + NS_ENSURE_TRUE(cellFrame, 0); + return cellFrame->RowIndex(); +} + +uint32_t HTMLTableCellAccessible::ColExtent() const { + int32_t rowIdx = -1, colIdx = -1; + GetCellIndexes(rowIdx, colIdx); + + TableAccessible* table = Table(); + NS_ASSERTION(table, "cell not in a table!"); + if (!table) return 0; + + return table->ColExtentAt(rowIdx, colIdx); +} + +uint32_t HTMLTableCellAccessible::RowExtent() const { + int32_t rowIdx = -1, colIdx = -1; + GetCellIndexes(rowIdx, colIdx); + + TableAccessible* table = Table(); + NS_ASSERTION(table, "cell not in atable!"); + if (!table) return 0; + + return table->RowExtentAt(rowIdx, colIdx); +} + +void HTMLTableCellAccessible::ColHeaderCells(nsTArray<Accessible*>* aCells) { + IDRefsIterator itr(mDoc, mContent, nsGkAtoms::headers); + while (Accessible* cell = itr.Next()) { + a11y::role cellRole = cell->Role(); + if (cellRole == roles::COLUMNHEADER) { + aCells->AppendElement(cell); + } else if (cellRole != roles::ROWHEADER) { + // If referred table cell is at the same column then treat it as a column + // header. + TableCellAccessible* tableCell = cell->AsTableCell(); + if (tableCell && tableCell->ColIdx() == ColIdx()) + aCells->AppendElement(cell); + } + } + + if (aCells->IsEmpty()) TableCellAccessible::ColHeaderCells(aCells); +} + +void HTMLTableCellAccessible::RowHeaderCells(nsTArray<Accessible*>* aCells) { + IDRefsIterator itr(mDoc, mContent, nsGkAtoms::headers); + while (Accessible* cell = itr.Next()) { + a11y::role cellRole = cell->Role(); + if (cellRole == roles::ROWHEADER) { + aCells->AppendElement(cell); + } else if (cellRole != roles::COLUMNHEADER) { + // If referred table cell is at the same row then treat it as a column + // header. + TableCellAccessible* tableCell = cell->AsTableCell(); + if (tableCell && tableCell->RowIdx() == RowIdx()) + aCells->AppendElement(cell); + } + } + + if (aCells->IsEmpty()) TableCellAccessible::RowHeaderCells(aCells); +} + +bool HTMLTableCellAccessible::Selected() { + int32_t rowIdx = -1, colIdx = -1; + GetCellIndexes(rowIdx, colIdx); + + TableAccessible* table = Table(); + NS_ENSURE_TRUE(table, false); + + return table->IsCellSelected(rowIdx, colIdx); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableCellAccessible: protected implementation + +nsITableCellLayout* HTMLTableCellAccessible::GetCellLayout() const { + return do_QueryFrame(mContent->GetPrimaryFrame()); +} + +nsTableCellFrame* HTMLTableCellAccessible::GetCellFrame() const { + return do_QueryFrame(mContent->GetPrimaryFrame()); +} + +nsresult HTMLTableCellAccessible::GetCellIndexes(int32_t& aRowIdx, + int32_t& aColIdx) const { + nsITableCellLayout* cellLayout = GetCellLayout(); + NS_ENSURE_STATE(cellLayout); + + return cellLayout->GetCellIndexes(aRowIdx, aColIdx); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableHeaderCellAccessible +//////////////////////////////////////////////////////////////////////////////// + +HTMLTableHeaderCellAccessible::HTMLTableHeaderCellAccessible( + nsIContent* aContent, DocAccessible* aDoc) + : HTMLTableCellAccessible(aContent, aDoc) {} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableHeaderCellAccessible: Accessible implementation + +role HTMLTableHeaderCellAccessible::NativeRole() const { + // Check value of @scope attribute. + static Element::AttrValuesArray scopeValues[] = { + nsGkAtoms::col, nsGkAtoms::colgroup, nsGkAtoms::row, nsGkAtoms::rowgroup, + nullptr}; + int32_t valueIdx = mContent->AsElement()->FindAttrValueIn( + kNameSpaceID_None, nsGkAtoms::scope, scopeValues, eCaseMatters); + + switch (valueIdx) { + case 0: + case 1: + return roles::COLUMNHEADER; + case 2: + case 3: + return roles::ROWHEADER; + } + + TableAccessible* table = Table(); + if (!table) return roles::NOTHING; + + // If the cell next to this one is not a header cell then assume this cell is + // a row header for it. + uint32_t rowIdx = RowIdx(), colIdx = ColIdx(); + Accessible* cell = table->CellAt(rowIdx, colIdx + ColExtent()); + if (cell && !nsCoreUtils::IsHTMLTableHeader(cell->GetContent())) + return roles::ROWHEADER; + + // If the cell below this one is not a header cell then assume this cell is + // a column header for it. + uint32_t rowExtent = RowExtent(); + cell = table->CellAt(rowIdx + rowExtent, colIdx); + if (cell && !nsCoreUtils::IsHTMLTableHeader(cell->GetContent())) + return roles::COLUMNHEADER; + + // Otherwise if this cell is surrounded by header cells only then make a guess + // based on its cell spanning. In other words if it is row spanned then assume + // it's a row header, otherwise it's a column header. + return rowExtent > 1 ? roles::ROWHEADER : roles::COLUMNHEADER; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableRowAccessible +//////////////////////////////////////////////////////////////////////////////// + +role HTMLTableRowAccessible::NativeRole() const { + if (mContent->IsMathMLElement(nsGkAtoms::mtr_)) { + return roles::MATHML_TABLE_ROW; + } else if (mContent->IsMathMLElement(nsGkAtoms::mlabeledtr_)) { + return roles::MATHML_LABELED_ROW; + } + return roles::ROW; +} + +GroupPos HTMLTableRowAccessible::GroupPosition() { + int32_t count = 0, index = 0; + Accessible* table = nsAccUtils::TableFor(this); + if (table && + nsCoreUtils::GetUIntAttr(table->GetContent(), nsGkAtoms::aria_rowcount, + &count) && + nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_rowindex, &index)) { + return GroupPos(0, index, count); + } + + return AccessibleWrap::GroupPosition(); +} + +// Accessible protected +ENameValueFlag HTMLTableRowAccessible::NativeName(nsString& aName) const { + // For table row accessibles, we only want to calculate the name from the + // sub tree if an ARIA role is present. + if (HasStrongARIARole()) { + return AccessibleWrap::NativeName(aName); + } + + return eNameOK; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableAccessible +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableAccessible: Accessible + +bool HTMLTableAccessible::InsertChildAt(uint32_t aIndex, Accessible* aChild) { + // Move caption accessible so that it's the first child. Check for the first + // caption only, because nsAccessibilityService ensures we don't create + // accessibles for the other captions, since only the first is actually + // visible. + return Accessible::InsertChildAt(aChild->IsHTMLCaption() ? 0 : aIndex, + aChild); +} + +role HTMLTableAccessible::NativeRole() const { + if (mContent->IsMathMLElement(nsGkAtoms::mtable_)) { + return roles::MATHML_TABLE; + } + return roles::TABLE; +} + +uint64_t HTMLTableAccessible::NativeState() const { + return Accessible::NativeState() | states::READONLY; +} + +ENameValueFlag HTMLTableAccessible::NativeName(nsString& aName) const { + ENameValueFlag nameFlag = Accessible::NativeName(aName); + if (!aName.IsEmpty()) return nameFlag; + + // Use table caption as a name. + Accessible* caption = Caption(); + if (caption) { + nsIContent* captionContent = caption->GetContent(); + if (captionContent) { + nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, + &aName); + if (!aName.IsEmpty()) return eNameOK; + } + } + + // If no caption then use summary as a name. + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, aName); + return eNameOK; +} + +already_AddRefed<nsIPersistentProperties> +HTMLTableAccessible::NativeAttributes() { + nsCOMPtr<nsIPersistentProperties> attributes = + AccessibleWrap::NativeAttributes(); + + if (mContent->IsMathMLElement(nsGkAtoms::mtable_)) { + GetAccService()->MarkupAttributes(mContent, attributes); + } + + if (IsProbablyLayoutTable()) { + nsAutoString unused; + attributes->SetStringProperty("layout-guess"_ns, u"true"_ns, unused); + } + + return attributes.forget(); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableAccessible: Accessible + +Relation HTMLTableAccessible::RelationByType(RelationType aType) const { + Relation rel = AccessibleWrap::RelationByType(aType); + if (aType == RelationType::LABELLED_BY) rel.AppendTarget(Caption()); + + return rel; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableAccessible: Table + +Accessible* HTMLTableAccessible::Caption() const { + Accessible* child = mChildren.SafeElementAt(0, nullptr); + return child && child->Role() == roles::CAPTION ? child : nullptr; +} + +void HTMLTableAccessible::Summary(nsString& aSummary) { + dom::HTMLTableElement* table = dom::HTMLTableElement::FromNode(mContent); + + if (table) table->GetSummary(aSummary); +} + +uint32_t HTMLTableAccessible::ColCount() const { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + return tableFrame ? tableFrame->GetColCount() : 0; +} + +uint32_t HTMLTableAccessible::RowCount() { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + return tableFrame ? tableFrame->GetRowCount() : 0; +} + +uint32_t HTMLTableAccessible::SelectedCellCount() { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return 0; + + uint32_t count = 0, rowCount = RowCount(), colCount = ColCount(); + for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) { + for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) { + nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(rowIdx, colIdx); + if (!cellFrame || !cellFrame->IsSelected()) continue; + + uint32_t startRow = cellFrame->RowIndex(); + uint32_t startCol = cellFrame->ColIndex(); + if (startRow == rowIdx && startCol == colIdx) count++; + } + } + + return count; +} + +uint32_t HTMLTableAccessible::SelectedColCount() { + uint32_t count = 0, colCount = ColCount(); + + for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) + if (IsColSelected(colIdx)) count++; + + return count; +} + +uint32_t HTMLTableAccessible::SelectedRowCount() { + uint32_t count = 0, rowCount = RowCount(); + + for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) + if (IsRowSelected(rowIdx)) count++; + + return count; +} + +void HTMLTableAccessible::SelectedCells(nsTArray<Accessible*>* aCells) { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return; + + uint32_t rowCount = RowCount(), colCount = ColCount(); + for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) { + for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) { + nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(rowIdx, colIdx); + if (!cellFrame || !cellFrame->IsSelected()) continue; + + uint32_t startRow = cellFrame->RowIndex(); + uint32_t startCol = cellFrame->ColIndex(); + if (startRow != rowIdx || startCol != colIdx) continue; + + Accessible* cell = mDoc->GetAccessible(cellFrame->GetContent()); + aCells->AppendElement(cell); + } + } +} + +void HTMLTableAccessible::SelectedCellIndices(nsTArray<uint32_t>* aCells) { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return; + + uint32_t rowCount = RowCount(), colCount = ColCount(); + for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) { + for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) { + nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(rowIdx, colIdx); + if (!cellFrame || !cellFrame->IsSelected()) continue; + + uint32_t startCol = cellFrame->ColIndex(); + uint32_t startRow = cellFrame->RowIndex(); + if (startRow == rowIdx && startCol == colIdx) + aCells->AppendElement(CellIndexAt(rowIdx, colIdx)); + } + } +} + +void HTMLTableAccessible::SelectedColIndices(nsTArray<uint32_t>* aCols) { + uint32_t colCount = ColCount(); + for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) + if (IsColSelected(colIdx)) aCols->AppendElement(colIdx); +} + +void HTMLTableAccessible::SelectedRowIndices(nsTArray<uint32_t>* aRows) { + uint32_t rowCount = RowCount(); + for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) + if (IsRowSelected(rowIdx)) aRows->AppendElement(rowIdx); +} + +Accessible* HTMLTableAccessible::CellAt(uint32_t aRowIdx, uint32_t aColIdx) { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return nullptr; + + nsIContent* cellContent = tableFrame->GetCellAt(aRowIdx, aColIdx); + Accessible* cell = mDoc->GetAccessible(cellContent); + + // Sometimes, the accessible returned here is a row accessible instead of + // a cell accessible, for example when a cell has CSS display:block; set. + // In such cases, iterate through the cells in this row differently to find + // it. + if (cell && cell->IsTableRow()) { + return CellInRowAt(cell, aColIdx); + } + + // XXX bug 576838: bizarre tables (like table6 in tables/test_table2.html) may + // return itself as a cell what makes Orca hang. + return cell == this ? nullptr : cell; +} + +int32_t HTMLTableAccessible::CellIndexAt(uint32_t aRowIdx, uint32_t aColIdx) { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return -1; + + int32_t cellIndex = tableFrame->GetIndexByRowAndColumn(aRowIdx, aColIdx); + if (cellIndex == -1) { + // Sometimes, the accessible returned here is a row accessible instead of + // a cell accessible, for example when a cell has CSS display:block; set. + // In such cases, iterate through the cells in this row differently to find + // it. + nsIContent* cellContent = tableFrame->GetCellAt(aRowIdx, aColIdx); + Accessible* cell = mDoc->GetAccessible(cellContent); + if (cell && cell->IsTableRow()) { + return TableAccessible::CellIndexAt(aRowIdx, aColIdx); + } + } + + return cellIndex; +} + +int32_t HTMLTableAccessible::ColIndexAt(uint32_t aCellIdx) { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return -1; + + int32_t rowIdx = -1, colIdx = -1; + tableFrame->GetRowAndColumnByIndex(aCellIdx, &rowIdx, &colIdx); + + if (colIdx == -1) { + // Sometimes, the index returned indicates that this is not a regular + // cell, for example when a cell has CSS display:block; set. + // In such cases, try the super class method to find it. + return TableAccessible::ColIndexAt(aCellIdx); + } + + return colIdx; +} + +int32_t HTMLTableAccessible::RowIndexAt(uint32_t aCellIdx) { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return -1; + + int32_t rowIdx = -1, colIdx = -1; + tableFrame->GetRowAndColumnByIndex(aCellIdx, &rowIdx, &colIdx); + + if (rowIdx == -1) { + // Sometimes, the index returned indicates that this is not a regular + // cell, for example when a cell has CSS display:block; set. + // In such cases, try the super class method to find it. + return TableAccessible::RowIndexAt(aCellIdx); + } + + return rowIdx; +} + +void HTMLTableAccessible::RowAndColIndicesAt(uint32_t aCellIdx, + int32_t* aRowIdx, + int32_t* aColIdx) { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (tableFrame) { + tableFrame->GetRowAndColumnByIndex(aCellIdx, aRowIdx, aColIdx); + if (*aRowIdx == -1 || *aColIdx == -1) { + // Sometimes, the index returned indicates that this is not a regular + // cell, for example when a cell has CSS display:block; set. + // In such cases, try the super class method to find it. + TableAccessible::RowAndColIndicesAt(aCellIdx, aRowIdx, aColIdx); + } + } +} + +uint32_t HTMLTableAccessible::ColExtentAt(uint32_t aRowIdx, uint32_t aColIdx) { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return 0; + + uint32_t colExtent = tableFrame->GetEffectiveColSpanAt(aRowIdx, aColIdx); + if (colExtent == 0) { + nsIContent* cellContent = tableFrame->GetCellAt(aRowIdx, aColIdx); + Accessible* cell = mDoc->GetAccessible(cellContent); + if (cell && cell->IsTableRow()) { + return TableAccessible::ColExtentAt(aRowIdx, aColIdx); + } + } + + return colExtent; +} + +uint32_t HTMLTableAccessible::RowExtentAt(uint32_t aRowIdx, uint32_t aColIdx) { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return 0; + + return tableFrame->GetEffectiveRowSpanAt(aRowIdx, aColIdx); +} + +bool HTMLTableAccessible::IsColSelected(uint32_t aColIdx) { + bool isSelected = false; + + uint32_t rowCount = RowCount(); + for (uint32_t rowIdx = 0; rowIdx < rowCount; rowIdx++) { + isSelected = IsCellSelected(rowIdx, aColIdx); + if (!isSelected) return false; + } + + return isSelected; +} + +bool HTMLTableAccessible::IsRowSelected(uint32_t aRowIdx) { + bool isSelected = false; + + uint32_t colCount = ColCount(); + for (uint32_t colIdx = 0; colIdx < colCount; colIdx++) { + isSelected = IsCellSelected(aRowIdx, colIdx); + if (!isSelected) return false; + } + + return isSelected; +} + +bool HTMLTableAccessible::IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx) { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return false; + + nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(aRowIdx, aColIdx); + return cellFrame ? cellFrame->IsSelected() : false; +} + +void HTMLTableAccessible::SelectRow(uint32_t aRowIdx) { + DebugOnly<nsresult> rv = + RemoveRowsOrColumnsFromSelection(aRowIdx, TableSelectionMode::Row, true); + NS_ASSERTION(NS_SUCCEEDED(rv), + "RemoveRowsOrColumnsFromSelection() Shouldn't fail!"); + + AddRowOrColumnToSelection(aRowIdx, TableSelectionMode::Row); +} + +void HTMLTableAccessible::SelectCol(uint32_t aColIdx) { + DebugOnly<nsresult> rv = RemoveRowsOrColumnsFromSelection( + aColIdx, TableSelectionMode::Column, true); + NS_ASSERTION(NS_SUCCEEDED(rv), + "RemoveRowsOrColumnsFromSelection() Shouldn't fail!"); + + AddRowOrColumnToSelection(aColIdx, TableSelectionMode::Column); +} + +void HTMLTableAccessible::UnselectRow(uint32_t aRowIdx) { + RemoveRowsOrColumnsFromSelection(aRowIdx, TableSelectionMode::Row, false); +} + +void HTMLTableAccessible::UnselectCol(uint32_t aColIdx) { + RemoveRowsOrColumnsFromSelection(aColIdx, TableSelectionMode::Column, false); +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLTableAccessible: protected implementation + +nsresult HTMLTableAccessible::AddRowOrColumnToSelection( + int32_t aIndex, TableSelectionMode aTarget) { + bool doSelectRow = (aTarget == TableSelectionMode::Row); + + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return NS_OK; + + uint32_t count = 0; + if (doSelectRow) + count = ColCount(); + else + count = RowCount(); + + PresShell* presShell = mDoc->PresShellPtr(); + RefPtr<nsFrameSelection> tableSelection = + const_cast<nsFrameSelection*>(presShell->ConstFrameSelection()); + + for (uint32_t idx = 0; idx < count; idx++) { + int32_t rowIdx = doSelectRow ? aIndex : idx; + int32_t colIdx = doSelectRow ? idx : aIndex; + nsTableCellFrame* cellFrame = tableFrame->GetCellFrameAt(rowIdx, colIdx); + if (cellFrame && !cellFrame->IsSelected()) { + nsresult rv = tableSelection->SelectCellElement(cellFrame->GetContent()); + NS_ENSURE_SUCCESS(rv, rv); + } + } + + return NS_OK; +} + +nsresult HTMLTableAccessible::RemoveRowsOrColumnsFromSelection( + int32_t aIndex, TableSelectionMode aTarget, bool aIsOuter) { + nsTableWrapperFrame* tableFrame = GetTableWrapperFrame(); + if (!tableFrame) return NS_OK; + + PresShell* presShell = mDoc->PresShellPtr(); + RefPtr<nsFrameSelection> tableSelection = + const_cast<nsFrameSelection*>(presShell->ConstFrameSelection()); + + bool doUnselectRow = (aTarget == TableSelectionMode::Row); + uint32_t count = doUnselectRow ? ColCount() : RowCount(); + + int32_t startRowIdx = doUnselectRow ? aIndex : 0; + int32_t endRowIdx = doUnselectRow ? aIndex : count - 1; + int32_t startColIdx = doUnselectRow ? 0 : aIndex; + int32_t endColIdx = doUnselectRow ? count - 1 : aIndex; + + if (aIsOuter) + return tableSelection->RestrictCellsToSelection( + mContent, startRowIdx, startColIdx, endRowIdx, endColIdx); + + return tableSelection->RemoveCellsFromSelection( + mContent, startRowIdx, startColIdx, endRowIdx, endColIdx); +} + +void HTMLTableAccessible::Description(nsString& aDescription) { + // Helpful for debugging layout vs. data tables + aDescription.Truncate(); + Accessible::Description(aDescription); + if (!aDescription.IsEmpty()) return; + + // Use summary as description if it weren't used as a name. + // XXX: get rid code duplication with NameInternal(). + Accessible* caption = Caption(); + if (caption) { + nsIContent* captionContent = caption->GetContent(); + if (captionContent) { + nsAutoString captionText; + nsTextEquivUtils::AppendTextEquivFromContent(this, captionContent, + &captionText); + + if (!captionText.IsEmpty()) { // summary isn't used as a name. + mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::summary, + aDescription); + } + } + } + +#ifdef SHOW_LAYOUT_HEURISTIC + if (aDescription.IsEmpty()) { + bool isProbablyForLayout = IsProbablyLayoutTable(); + aDescription = mLayoutHeuristic; + } + printf("\nTABLE: %s\n", NS_ConvertUTF16toUTF8(mLayoutHeuristic).get()); +#endif +} + +nsTableWrapperFrame* HTMLTableAccessible::GetTableWrapperFrame() const { + nsTableWrapperFrame* tableFrame = do_QueryFrame(mContent->GetPrimaryFrame()); + if (tableFrame && + tableFrame->GetChildList(nsIFrame::kPrincipalList).FirstChild()) { + return tableFrame; + } + + return nullptr; +} + +//////////////////////////////////////////////////////////////////////////////// +// HTMLCaptionAccessible +//////////////////////////////////////////////////////////////////////////////// + +Relation HTMLCaptionAccessible::RelationByType(RelationType aType) const { + Relation rel = HyperTextAccessible::RelationByType(aType); + if (aType == RelationType::LABEL_FOR) rel.AppendTarget(Parent()); + + return rel; +} + +role HTMLCaptionAccessible::NativeRole() const { return roles::CAPTION; } diff --git a/accessible/html/HTMLTableAccessible.h b/accessible/html/HTMLTableAccessible.h new file mode 100644 index 0000000000..fe647b735c --- /dev/null +++ b/accessible/html/HTMLTableAccessible.h @@ -0,0 +1,232 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +#ifndef mozilla_a11y_HTMLTableAccessible_h__ +#define mozilla_a11y_HTMLTableAccessible_h__ + +#include "HyperTextAccessibleWrap.h" +#include "TableAccessible.h" +#include "TableCellAccessible.h" + +class nsITableCellLayout; +class nsTableCellFrame; +class nsTableWrapperFrame; + +namespace mozilla { + +enum class TableSelectionMode : uint32_t; + +namespace a11y { + +/** + * HTML table cell accessible (html:td). + */ +class HTMLTableCellAccessible : public HyperTextAccessibleWrap, + public TableCellAccessible { + public: + HTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // nsISupports + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLTableCellAccessible, + HyperTextAccessibleWrap) + + // Accessible + virtual TableCellAccessible* AsTableCell() override { return this; } + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + virtual uint64_t NativeInteractiveState() const override; + virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() override; + virtual mozilla::a11y::GroupPos GroupPosition() override; + + // TableCellAccessible + virtual TableAccessible* Table() const override; + virtual uint32_t ColIdx() const override; + virtual uint32_t RowIdx() const override; + virtual uint32_t ColExtent() const override; + virtual uint32_t RowExtent() const override; + virtual void ColHeaderCells(nsTArray<Accessible*>* aCells) override; + virtual void RowHeaderCells(nsTArray<Accessible*>* aCells) override; + virtual bool Selected() override; + + protected: + virtual ~HTMLTableCellAccessible() {} + + /** + * Return nsITableCellLayout of the table cell frame. + */ + nsITableCellLayout* GetCellLayout() const; + + /** + * Return the table cell frame. + */ + nsTableCellFrame* GetCellFrame() const; + + /** + * Return row and column indices of the cell. + */ + nsresult GetCellIndexes(int32_t& aRowIdx, int32_t& aColIdx) const; +}; + +/** + * HTML table row/column header accessible (html:th or html:td@scope). + */ +class HTMLTableHeaderCellAccessible : public HTMLTableCellAccessible { + public: + HTMLTableHeaderCellAccessible(nsIContent* aContent, DocAccessible* aDoc); + + // Accessible + virtual a11y::role NativeRole() const override; +}; + +/** + * HTML table row accessible (html:tr). + */ +class HTMLTableRowAccessible : public HyperTextAccessibleWrap { + public: + HTMLTableRowAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) { + mType = eHTMLTableRowType; + mGenericTypes |= eTableRow; + } + + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLTableRowAccessible, + HyperTextAccessibleWrap) + + // Accessible + virtual a11y::role NativeRole() const override; + virtual mozilla::a11y::GroupPos GroupPosition() override; + + protected: + virtual ~HTMLTableRowAccessible() {} + + // Accessible + virtual ENameValueFlag NativeName(nsString& aName) const override; +}; + +/** + * HTML table accessible (html:table). + */ + +// To turn on table debugging descriptions define SHOW_LAYOUT_HEURISTIC +// This allow release trunk builds to be used by testers to refine the +// data vs. layout heuristic +// #define SHOW_LAYOUT_HEURISTIC + +class HTMLTableAccessible : public HyperTextAccessibleWrap, + public TableAccessible { + public: + HTMLTableAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) { + mType = eHTMLTableType; + mGenericTypes |= eTable; + } + + NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLTableAccessible, + HyperTextAccessibleWrap) + + // TableAccessible + virtual Accessible* Caption() const override; + virtual void Summary(nsString& aSummary) override; + virtual uint32_t ColCount() const override; + virtual uint32_t RowCount() override; + virtual Accessible* CellAt(uint32_t aRowIndex, + uint32_t aColumnIndex) override; + virtual int32_t CellIndexAt(uint32_t aRowIdx, uint32_t aColIdx) override; + virtual int32_t ColIndexAt(uint32_t aCellIdx) override; + virtual int32_t RowIndexAt(uint32_t aCellIdx) override; + virtual void RowAndColIndicesAt(uint32_t aCellIdx, int32_t* aRowIdx, + int32_t* aColIdx) override; + virtual uint32_t ColExtentAt(uint32_t aRowIdx, uint32_t aColIdx) override; + virtual uint32_t RowExtentAt(uint32_t aRowIdx, uint32_t aColIdx) override; + virtual bool IsColSelected(uint32_t aColIdx) override; + virtual bool IsRowSelected(uint32_t aRowIdx) override; + virtual bool IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx) override; + virtual uint32_t SelectedCellCount() override; + virtual uint32_t SelectedColCount() override; + virtual uint32_t SelectedRowCount() override; + virtual void SelectedCells(nsTArray<Accessible*>* aCells) override; + virtual void SelectedCellIndices(nsTArray<uint32_t>* aCells) override; + virtual void SelectedColIndices(nsTArray<uint32_t>* aCols) override; + virtual void SelectedRowIndices(nsTArray<uint32_t>* aRows) override; + virtual void SelectCol(uint32_t aColIdx) override; + virtual void SelectRow(uint32_t aRowIdx) override; + virtual void UnselectCol(uint32_t aColIdx) override; + virtual void UnselectRow(uint32_t aRowIdx) override; + virtual Accessible* AsAccessible() override { return this; } + + // Accessible + virtual TableAccessible* AsTable() override { return this; } + virtual void Description(nsString& aDescription) override; + virtual a11y::role NativeRole() const override; + virtual uint64_t NativeState() const override; + virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() override; + virtual Relation RelationByType(RelationType aRelationType) const override; + + virtual bool InsertChildAt(uint32_t aIndex, Accessible* aChild) override; + + protected: + virtual ~HTMLTableAccessible() {} + + // Accessible + virtual ENameValueFlag NativeName(nsString& aName) const override; + + // HTMLTableAccessible + + /** + * Add row or column to selection. + * + * @param aIndex [in] index of row or column to be selected + * @param aTarget [in] indicates what should be selected, either row or + * column (see nsFrameSelection) + */ + nsresult AddRowOrColumnToSelection(int32_t aIndex, + TableSelectionMode aTarget); + + /** + * Removes rows or columns at the given index or outside it from selection. + * + * @param aIndex [in] row or column index + * @param aTarget [in] indicates whether row or column should unselected + * @param aIsOuter [in] indicates whether all rows or column excepting + * the given one should be unselected or the given one + * should be unselected only + */ + nsresult RemoveRowsOrColumnsFromSelection(int32_t aIndex, + TableSelectionMode aTarget, + bool aIsOuter); + +#ifdef SHOW_LAYOUT_HEURISTIC + nsString mLayoutHeuristic; +#endif + + private: + /** + * Get table wrapper frame, or return null if there is no inner table. + */ + nsTableWrapperFrame* GetTableWrapperFrame() const; +}; + +/** + * HTML caption accessible (html:caption). + */ +class HTMLCaptionAccessible : public HyperTextAccessibleWrap { + public: + HTMLCaptionAccessible(nsIContent* aContent, DocAccessible* aDoc) + : HyperTextAccessibleWrap(aContent, aDoc) { + mType = eHTMLCaptionType; + } + + // Accessible + virtual a11y::role NativeRole() const override; + virtual Relation RelationByType(RelationType aRelationType) const override; + + protected: + virtual ~HTMLCaptionAccessible() {} +}; + +} // namespace a11y +} // namespace mozilla + +#endif diff --git a/accessible/html/moz.build b/accessible/html/moz.build new file mode 100644 index 0000000000..5b74f6741f --- /dev/null +++ b/accessible/html/moz.build @@ -0,0 +1,55 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +UNIFIED_SOURCES += [ + "HTMLCanvasAccessible.cpp", + "HTMLElementAccessibles.cpp", + "HTMLFormControlAccessible.cpp", + "HTMLImageMapAccessible.cpp", + "HTMLLinkAccessible.cpp", + "HTMLListAccessible.cpp", + "HTMLSelectAccessible.cpp", + "HTMLTableAccessible.cpp", +] + +LOCAL_INCLUDES += [ + "/accessible/base", + "/accessible/generic", + "/accessible/xpcom", + "/layout/forms", + "/layout/generic", + "/layout/tables", + "/layout/xul", +] + +if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk": + LOCAL_INCLUDES += [ + "/accessible/atk", + ] +elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows": + LOCAL_INCLUDES += [ + "/accessible/windows/ia2", + "/accessible/windows/msaa", + ] +elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa": + LOCAL_INCLUDES += [ + "/accessible/mac", + ] +elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "android": + LOCAL_INCLUDES += [ + "/accessible/android", + ] +else: + LOCAL_INCLUDES += [ + "/accessible/other", + ] + +include("/ipc/chromium/chromium-config.mozbuild") + +FINAL_LIBRARY = "xul" + +if CONFIG["CC_TYPE"] in ("clang", "gcc"): + CXXFLAGS += ["-Wno-error=shadow"] |