Bug 1323449 - implement is() method for testing boolean characteristics, r=smaug

This commit is contained in:
Alexander Surkov 2016-12-15 14:37:27 -05:00
parent e3a96b536f
commit 3aacbd7973
5 changed files with 37 additions and 5 deletions

View File

@ -76,6 +76,33 @@ AccessibleNode::GetStates(nsTArray<nsString>& aStates)
mStates->Add(NS_LITERAL_STRING("defunct"));
}
bool
AccessibleNode::Is(const Sequence<nsString>& 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()
{

View File

@ -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<nsString>& aStates);
nsINode* GetDOMNode();
bool Is(const Sequence<nsString>& aFlavors);
a11y::Accessible* Internal() const { return mIntl; }
protected:

View File

@ -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 += [

View File

@ -77,6 +77,9 @@
}
}
ok(anode.is('document', 'focusable'),
'correct role and state on an accessible node');
finish();
}
</script>

View File

@ -10,4 +10,6 @@ interface AccessibleNode {
[Frozen, Cached, Pure]
readonly attribute sequence<DOMString> states;
readonly attribute Node? DOMNode;
boolean is(DOMString... states);
};