Bug 1313693 - implement iterable states, part2, r=smaug

This commit is contained in:
Alexander Surkov 2016-12-13 17:36:19 -05:00
parent 19b9d0a8d9
commit 6281dc2bac
5 changed files with 54 additions and 2 deletions

View File

@ -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<nsString>& aStates)
{
if (mIntl) {
if (!mStates) {
mStates = GetOrCreateAccService()->GetStringStates(mIntl->State());
}
aStates = mStates->StringArray();
return;
}
mStates->Add(NS_LITERAL_STRING("defunct"));
}
nsINode*
AccessibleNode::GetDOMNode()
{

View File

@ -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<nsString>& 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<a11y::Accessible> mIntl;
RefPtr<nsINode> mDOMNode;
RefPtr<dom::DOMStringList> mStates;
};
} // dom

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

@ -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();
}
</script>

View File

@ -7,5 +7,7 @@
[Pref="accessibility.AOM.enabled"]
interface AccessibleNode {
readonly attribute DOMString role;
[Frozen, Cached, Pure]
readonly attribute sequence<DOMString> states;
readonly attribute Node? DOMNode;
};