From da2f7bc6c1d21349b678f95bb86bff7bc0beba7d Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Sat, 7 Mar 2015 20:20:17 -0500 Subject: [PATCH] Bug 1140500 - add object attributes declaration into markup map, r=marcoz --- accessible/base/MarkupMap.h | 16 ++++-- accessible/base/nsAccessibilityService.cpp | 51 ++++++++++++++++++- accessible/base/nsAccessibilityService.h | 16 ++++++ accessible/generic/HyperTextAccessible.cpp | 21 +------- accessible/html/HTMLElementAccessibles.cpp | 12 ----- accessible/html/HTMLElementAccessibles.h | 1 - accessible/html/HTMLFormControlAccessible.cpp | 14 +---- accessible/html/HTMLFormControlAccessible.h | 1 - dom/base/nsGkAtomList.h | 1 + 9 files changed, 80 insertions(+), 53 deletions(-) diff --git a/accessible/base/MarkupMap.h b/accessible/base/MarkupMap.h index 8a51e5af607..286c8bc1b42 100644 --- a/accessible/base/MarkupMap.h +++ b/accessible/base/MarkupMap.h @@ -19,7 +19,8 @@ MARKUPMAP(acronym, MARKUPMAP(article, New_HyperText, - roles::DOCUMENT) + roles::DOCUMENT, + Attr(xmlroles, article)) MARKUPMAP(aside, New_HyperText, @@ -51,7 +52,8 @@ MARKUPMAP(figcaption, MARKUPMAP(figure, New_HTMLFigure, - roles::FIGURE) + roles::FIGURE, + Attr(xmlroles, figure)) MARKUPMAP(form, New_HyperText, @@ -119,7 +121,8 @@ MARKUPMAP(optgroup, MARKUPMAP(output, New_HTMLOutput, - roles::SECTION) + roles::SECTION, + Attr(live, polite)) MARKUPMAP(progress, New_HTMLProgress, @@ -131,11 +134,14 @@ MARKUPMAP(q, MARKUPMAP(section, New_HyperText, - roles::SECTION) + roles::SECTION, + Attr(xmlroles, region)) MARKUPMAP(time, New_HyperText, - 0) + 0, + Attr(xmlroles, time), + AttrFromDOM(datetime, datetime)) MARKUPMAP(td, New_HTMLTableHeaderCellIfScope, diff --git a/accessible/base/nsAccessibilityService.cpp b/accessible/base/nsAccessibilityService.cpp index a540ade4687..07ab4d621d6 100644 --- a/accessible/base/nsAccessibilityService.cpp +++ b/accessible/base/nsAccessibilityService.cpp @@ -220,13 +220,25 @@ New_HTMLTableHeaderCellIfScope(nsIContent* aContent, Accessible* aContext) //////////////////////////////////////////////////////////////////////////////// // Markup maps array. -#define MARKUPMAP(atom, new_func, r) \ - { &nsGkAtoms::atom, new_func, static_cast(r) }, +#define Attr(name, value) \ + { &nsGkAtoms::name, &nsGkAtoms::value } + +#define AttrFromDOM(name, DOMAttrName) \ + { &nsGkAtoms::name, nullptr, &nsGkAtoms::DOMAttrName } + +#define AttrFromDOMIf(name, DOMAttrName, DOMAttrValue) \ + { &nsGkAtoms::name, nullptr, &nsGkAtoms::DOMAttrName, &nsGkAtoms::DOMAttrValue } + +#define MARKUPMAP(atom, new_func, r, ... ) \ + { &nsGkAtoms::atom, new_func, static_cast(r), { __VA_ARGS__ } }, static const MarkupMapInfo sMarkupMapList[] = { #include "MarkupMap.h" }; +#undef Attr +#undef AttrFromDOM +#undef AttrFromDOMIf #undef MARKUPMAP //////////////////////////////////////////////////////////////////////////////// @@ -1610,6 +1622,41 @@ nsAccessibilityService::CreateAccessibleByFrameType(nsIFrame* aFrame, return newAcc.forget(); } +void +nsAccessibilityService::MarkupAttributes(const nsIContent* aContent, + nsIPersistentProperties* aAttributes) const +{ + const mozilla::a11y::MarkupMapInfo* markupMap = + mMarkupMaps.Get(aContent->NodeInfo()->NameAtom()); + if (!markupMap) + return; + + for (uint32_t i = 0; i < ArrayLength(markupMap->attrs); i++) { + const MarkupAttrInfo* info = markupMap->attrs + i; + if (!info->name) + break; + + if (info->DOMAttrName) { + if (info->DOMAttrValue) { + if (aContent->AttrValueIs(kNameSpaceID_None, *info->DOMAttrName, + *info->DOMAttrValue, eCaseMatters)) { + nsAccUtils::SetAccAttr(aAttributes, *info->name, *info->DOMAttrValue); + } + continue; + } + + nsAutoString value; + aContent->GetAttr(kNameSpaceID_None, *info->DOMAttrName, value); + if (!value.IsEmpty()) + nsAccUtils::SetAccAttr(aAttributes, *info->name, value); + + continue; + } + + nsAccUtils::SetAccAttr(aAttributes, *info->name, *info->value); + } +} + //////////////////////////////////////////////////////////////////////////////// // nsIAccessibilityService (DON'T put methods here) diff --git a/accessible/base/nsAccessibilityService.h b/accessible/base/nsAccessibilityService.h index 586eddd446c..7761058e9a3 100644 --- a/accessible/base/nsAccessibilityService.h +++ b/accessible/base/nsAccessibilityService.h @@ -17,6 +17,7 @@ #include "nsIObserver.h" class nsImageFrame; +class nsIPersistentProperties; class nsPluginFrame; class nsITreeView; @@ -44,10 +45,19 @@ xpcAccessibleApplication* XPCApplicationAcc(); typedef Accessible* (New_Accessible)(nsIContent* aContent, Accessible* aContext); +struct MarkupAttrInfo { + nsIAtom** name; + nsIAtom** value; + + nsIAtom** DOMAttrName; + nsIAtom** DOMAttrValue; +}; + struct MarkupMapInfo { nsIAtom** tag; New_Accessible* new_func; a11y::role role; + MarkupAttrInfo attrs[2]; }; } // namespace a11y @@ -182,6 +192,12 @@ public: return markupMap ? markupMap->role : mozilla::a11y::roles::NOTHING; } + /** + * Set the object attribute defined by markup for the given element. + */ + void MarkupAttributes(const nsIContent* aContent, + nsIPersistentProperties* aAttributes) const; + private: // nsAccessibilityService creation is controlled by friend // NS_GetAccessibilityService, keep constructors private. diff --git a/accessible/generic/HyperTextAccessible.cpp b/accessible/generic/HyperTextAccessible.cpp index 1992b219a71..bba558296b7 100644 --- a/accessible/generic/HyperTextAccessible.cpp +++ b/accessible/generic/HyperTextAccessible.cpp @@ -977,25 +977,8 @@ HyperTextAccessible::NativeAttributes() } } - if (!HasOwnContent()) - return attributes.forget(); - - if (mContent->IsHTMLElement(nsGkAtoms::section)) { - nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles, - NS_LITERAL_STRING("region")); - } else if (mContent->IsHTMLElement(nsGkAtoms::article)) { - nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles, - NS_LITERAL_STRING("article")); - } else if (mContent->IsHTMLElement(nsGkAtoms::time)) { - nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles, - NS_LITERAL_STRING("time")); - - if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::datetime)) { - nsAutoString datetime; - mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::datetime, datetime); - nsAccUtils::SetAccAttr(attributes, nsGkAtoms::datetime, datetime); - } - } + if (HasOwnContent()) + GetAccService()->MarkupAttributes(mContent, attributes); return attributes.forget(); } diff --git a/accessible/html/HTMLElementAccessibles.cpp b/accessible/html/HTMLElementAccessibles.cpp index c56740bc32f..938abc178e8 100644 --- a/accessible/html/HTMLElementAccessibles.cpp +++ b/accessible/html/HTMLElementAccessibles.cpp @@ -90,15 +90,3 @@ HTMLOutputAccessible::RelationByType(RelationType aType) return rel; } - -already_AddRefed -HTMLOutputAccessible::NativeAttributes() -{ - nsCOMPtr attributes = - AccessibleWrap::NativeAttributes(); - nsAccUtils::SetAccAttr(attributes, nsGkAtoms::live, - NS_LITERAL_STRING("polite")); - - return attributes.forget(); -} - diff --git a/accessible/html/HTMLElementAccessibles.h b/accessible/html/HTMLElementAccessibles.h index ae81c43558e..397d59c5e18 100644 --- a/accessible/html/HTMLElementAccessibles.h +++ b/accessible/html/HTMLElementAccessibles.h @@ -80,7 +80,6 @@ public: NS_DECL_ISUPPORTS_INHERITED // Accessible - virtual already_AddRefed NativeAttributes() MOZ_OVERRIDE; virtual Relation RelationByType(RelationType aType) MOZ_OVERRIDE; protected: diff --git a/accessible/html/HTMLFormControlAccessible.cpp b/accessible/html/HTMLFormControlAccessible.cpp index d2eb8897f13..27fe73e900a 100644 --- a/accessible/html/HTMLFormControlAccessible.cpp +++ b/accessible/html/HTMLFormControlAccessible.cpp @@ -89,7 +89,7 @@ HTMLCheckboxAccessible::NativeState() if (input->Checked()) return state | states::CHECKED; - + return state; } @@ -772,18 +772,6 @@ HTMLFigureAccessible:: { } -already_AddRefed -HTMLFigureAccessible::NativeAttributes() -{ - nsCOMPtr attributes = - HyperTextAccessibleWrap::NativeAttributes(); - - // Expose figure xml-role. - nsAccUtils::SetAccAttr(attributes, nsGkAtoms::xmlroles, - NS_LITERAL_STRING("figure")); - return attributes.forget(); -} - ENameValueFlag HTMLFigureAccessible::NativeName(nsString& aName) { diff --git a/accessible/html/HTMLFormControlAccessible.h b/accessible/html/HTMLFormControlAccessible.h index 12356f76cc5..8e5be863822 100644 --- a/accessible/html/HTMLFormControlAccessible.h +++ b/accessible/html/HTMLFormControlAccessible.h @@ -255,7 +255,6 @@ public: HTMLFigureAccessible(nsIContent* aContent, DocAccessible* aDoc); // Accessible - virtual already_AddRefed NativeAttributes() MOZ_OVERRIDE; virtual Relation RelationByType(RelationType aType) MOZ_OVERRIDE; protected: diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h index 651eaca938a..6eca907de9d 100644 --- a/dom/base/nsGkAtomList.h +++ b/dom/base/nsGkAtomList.h @@ -2289,6 +2289,7 @@ GK_ATOM(mixed, "mixed") GK_ATOM(multiline, "multiline") GK_ATOM(navigation, "navigation") GK_ATOM(password, "password") +GK_ATOM(polite, "polite") GK_ATOM(posinset, "posinset") GK_ATOM(presentation, "presentation") GK_ATOM(progressbar, "progressbar")