diff --git a/accessible/aom/AccessibleNode.cpp b/accessible/aom/AccessibleNode.cpp index 2fbd2d7bd36b..41596c6ca83b 100644 --- a/accessible/aom/AccessibleNode.cpp +++ b/accessible/aom/AccessibleNode.cpp @@ -76,6 +76,33 @@ AccessibleNode::GetStates(nsTArray& aStates) mStates->Add(NS_LITERAL_STRING("defunct")); } +bool +AccessibleNode::Is(const Sequence& aFlavors) +{ + if (!mIntl) { + for (const auto& flavor : aFlavors) { + if (!flavor.EqualsLiteral("unknown") && !flavor.EqualsLiteral("defunct")) { + return false; + } + } + return true; + } + + nsAutoString role; + GetOrCreateAccService()->GetStringRole(mIntl->Role(), role); + + if (!mStates) { + mStates = GetOrCreateAccService()->GetStringStates(mIntl->State()); + } + + for (const auto& flavor : aFlavors) { + if (!flavor.Equals(role) && !mStates->Contains(flavor)) { + return false; + } + } + return true; +} + nsINode* AccessibleNode::GetDOMNode() { diff --git a/accessible/aom/AccessibleNode.h b/accessible/aom/AccessibleNode.h index 0a75e18d55b4..5ccd9a85840b 100644 --- a/accessible/aom/AccessibleNode.h +++ b/accessible/aom/AccessibleNode.h @@ -8,9 +8,7 @@ #define A11Y_AOM_ACCESSIBLENODE_H #include "nsWrapperCache.h" -#include "mozilla/RefPtr.h" -#include "nsTArray.h" -#include "nsString.h" +#include "mozilla/dom/BindingDeclarations.h" class nsINode; @@ -41,6 +39,8 @@ public: void GetStates(nsTArray& aStates); nsINode* GetDOMNode(); + bool Is(const Sequence& aFlavors); + a11y::Accessible* Internal() const { return mIntl; } protected: diff --git a/accessible/aom/moz.build b/accessible/aom/moz.build index c1adb0cc77d6..700081215312 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 e67b51c4e19c..bc1038987f05 100644 --- a/accessible/tests/mochitest/aom/test_general.html +++ b/accessible/tests/mochitest/aom/test_general.html @@ -77,6 +77,9 @@ } } + ok(anode.is('document', 'focusable'), + 'correct role and state on an accessible node'); + finish(); } diff --git a/dom/webidl/AccessibleNode.webidl b/dom/webidl/AccessibleNode.webidl index 544fe06304aa..442f1a18ba43 100644 --- a/dom/webidl/AccessibleNode.webidl +++ b/dom/webidl/AccessibleNode.webidl @@ -10,4 +10,6 @@ interface AccessibleNode { [Frozen, Cached, Pure] readonly attribute sequence states; readonly attribute Node? DOMNode; + + boolean is(DOMString... states); };