diff --git a/accessible/aom/AccessibleNode.cpp b/accessible/aom/AccessibleNode.cpp index dd26c6a29fe4..2fbd2d7bd36b 100644 --- a/accessible/aom/AccessibleNode.cpp +++ b/accessible/aom/AccessibleNode.cpp @@ -6,6 +6,7 @@ #include "AccessibleNode.h" #include "mozilla/dom/AccessibleNodeBinding.h" #include "mozilla/dom/BindingDeclarations.h" +#include "mozilla/dom/DOMStringList.h" #include "Accessible-inl.h" #include "nsAccessibilityService.h" @@ -61,6 +62,20 @@ AccessibleNode::GetRole(nsAString& aRole) aRole.AssignLiteral("unknown"); } +void +AccessibleNode::GetStates(nsTArray& aStates) +{ + if (mIntl) { + if (!mStates) { + mStates = GetOrCreateAccService()->GetStringStates(mIntl->State()); + } + aStates = mStates->StringArray(); + return; + } + + mStates->Add(NS_LITERAL_STRING("defunct")); +} + nsINode* AccessibleNode::GetDOMNode() { diff --git a/accessible/aom/AccessibleNode.h b/accessible/aom/AccessibleNode.h index 355bb395c897..0a75e18d55b4 100644 --- a/accessible/aom/AccessibleNode.h +++ b/accessible/aom/AccessibleNode.h @@ -9,6 +9,8 @@ #include "nsWrapperCache.h" #include "mozilla/RefPtr.h" +#include "nsTArray.h" +#include "nsString.h" class nsINode; @@ -20,6 +22,7 @@ namespace a11y { namespace dom { +class DOMStringList; struct ParentObject; class AccessibleNode : public nsISupports, @@ -35,8 +38,11 @@ public: virtual dom::ParentObject GetParentObject() const final; void GetRole(nsAString& aRole); + void GetStates(nsTArray& aStates); nsINode* GetDOMNode(); + a11y::Accessible* Internal() const { return mIntl; } + protected: AccessibleNode(const AccessibleNode& aCopy) = delete; AccessibleNode& operator=(const AccessibleNode& aCopy) = delete; @@ -44,6 +50,7 @@ protected: RefPtr mIntl; RefPtr mDOMNode; + RefPtr mStates; }; } // dom diff --git a/accessible/aom/moz.build b/accessible/aom/moz.build index 700081215312..c1adb0cc77d6 100644 --- a/accessible/aom/moz.build +++ b/accessible/aom/moz.build @@ -5,11 +5,11 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. EXPORTS.mozilla.dom += [ - 'AccessibleNode.h', + 'AccessibleNode.h' ] UNIFIED_SOURCES += [ - 'AccessibleNode.cpp', + 'AccessibleNode.cpp' ] LOCAL_INCLUDES += [ diff --git a/accessible/tests/mochitest/aom/test_general.html b/accessible/tests/mochitest/aom/test_general.html index 5812ac55f5f4..e67b51c4e19c 100644 --- a/accessible/tests/mochitest/aom/test_general.html +++ b/accessible/tests/mochitest/aom/test_general.html @@ -49,6 +49,34 @@ is(anode.role, 'document', 'correct role of a document accessible node'); is(anode.DOMNode, ifrDoc, 'correct DOM Node of a document accessible node'); + // States may differ depending on the document state, for example, if it is + // loaded or is loading still. + var states = null; + switch (anode.states.length) { + case 5: + states = [ + 'readonly', 'focusable', 'opaque', 'enabled', 'sensitive' + ]; + break; + case 6: + states = [ + 'readonly', 'busy', 'focusable', 'opaque', 'enabled', 'sensitive' + ]; + break; + case 7: + states = [ + 'readonly', 'busy', 'focusable', 'opaque', 'stale', 'enabled', 'sensitive' + ]; + break; + default: + ok(false, 'Unexpected amount of states'); + } + if (states) { + for (var i = 0; i < states.length; i++) { + is(anode.states[i], states[i], `${states[i]} state is expected at ${i}th index`); + } + } + finish(); } diff --git a/dom/webidl/AccessibleNode.webidl b/dom/webidl/AccessibleNode.webidl index 42bc93aa9f78..544fe06304aa 100644 --- a/dom/webidl/AccessibleNode.webidl +++ b/dom/webidl/AccessibleNode.webidl @@ -7,5 +7,7 @@ [Pref="accessibility.AOM.enabled"] interface AccessibleNode { readonly attribute DOMString role; + [Frozen, Cached, Pure] + readonly attribute sequence states; readonly attribute Node? DOMNode; };