Bug 1468110 - add AccessibleNode unsigned long, long & double attributes attributes, r=yzen, qdot

based on ARIA and AOM's ARIA reflection specs (https://wicg.github.io/aom/spec/aria-reflection.html)
This commit is contained in:
Tokio Kajitsuka 2018-07-22 03:45:22 +09:00
parent ae68a9de15
commit b3ddbd6aaf
4 changed files with 109 additions and 0 deletions

View File

@ -43,6 +43,9 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(AccessibleNode)
NS_IMPL_CYCLE_COLLECTING_RELEASE(AccessibleNode)
AccessibleNode::AccessibleNode(nsINode* aNode) :
mDoubleProperties(3),
mIntProperties(3),
mUIntProperties(6),
mBooleanProperties(0),
mDOMNode(aNode)
{

View File

@ -7,6 +7,7 @@
#ifndef A11Y_AOM_ACCESSIBLENODE_H
#define A11Y_AOM_ACCESSIBLENODE_H
#include "nsDataHashtable.h"
#include "nsWrapperCache.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
@ -45,6 +46,28 @@ struct ParentObject;
}; \
MOZ_FOR_EACH(ANODE_FUNC, (typeName, type,), (__VA_ARGS__)) \
#define ANODE_ACCESSOR_MUTATOR(typeName, type, defVal) \
nsDataHashtable<nsUint32HashKey, type> m##typeName##Properties; \
\
dom::Nullable<type> GetProperty(AOM##typeName##Property aProperty) \
{ \
type value = defVal; \
if (m##typeName##Properties.Get(static_cast<int>(aProperty), &value)) { \
return dom::Nullable<type>(value); \
} \
return dom::Nullable<type>(); \
} \
\
void SetProperty(AOM##typeName##Property aProperty, \
const dom::Nullable<type>& aValue) \
{ \
if (aValue.IsNull()) { \
m##typeName##Properties.Remove(static_cast<int>(aProperty)); \
} else { \
m##typeName##Properties.Put(static_cast<int>(aProperty), aValue.Value()); \
} \
} \
class AccessibleNode : public nsISupports,
public nsWrapperCache
{
@ -84,6 +107,27 @@ public:
Selected
)
ANODE_PROPS(UInt, uint32_t,
ColIndex,
ColSpan,
Level,
PosInSet,
RowIndex,
RowSpan
)
ANODE_PROPS(Int, int32_t,
ColCount,
RowCount,
SetSize
)
ANODE_PROPS(Double, double,
ValueMax,
ValueMin,
ValueNow
)
protected:
AccessibleNode(const AccessibleNode& aCopy) = delete;
AccessibleNode& operator=(const AccessibleNode& aCopy) = delete;
@ -112,6 +156,10 @@ protected:
}
}
ANODE_ACCESSOR_MUTATOR(Double, double, 0.0)
ANODE_ACCESSOR_MUTATOR(Int, int32_t, 0)
ANODE_ACCESSOR_MUTATOR(UInt, uint32_t, 0)
// The 2k'th bit indicates whether the k'th boolean property is used(1) or not(0)
// and 2k+1'th bit contains the property's value(1:true, 0:false)
uint32_t mBooleanProperties;

View File

@ -51,6 +51,30 @@
is(anode[prop], null, `anode.${prop} was assigned null`);
}
function testDoubleProp(anode, prop) {
is(anode[prop], null, `anode.${prop} should be null`);
anode[prop] = Number.MAX_VALUE;
is(anode[prop], Number.MAX_VALUE, `anode.${prop} was assigned ${Number.MAX_VALUE}`);
anode[prop] = null;
is(anode[prop], null, `anode.${prop} was assigned null`);
}
function testIntProp(anode, prop) {
is(anode[prop], null, `anode.${prop} should be null`);
anode[prop] = -1;
is(anode[prop], -1, `anode.${prop} was assigned -1`);
anode[prop] = null;
is(anode[prop], null, `anode.${prop} was assigned null`);
}
function testUIntProp(anode, prop) {
is(anode[prop], null, `anode.${prop} should be null`);
anode[prop] = 4294967295;
is(anode[prop], 4294967295, `anode.${prop} was assigned 4294967295`);
anode[prop] = null;
is(anode[prop], null, `anode.${prop} was assigned null`);
}
// Check that the WebIDL is as expected.
function checkImplementation(ifrDoc) {
let anode = ifrDoc.accessibleNode;
@ -118,6 +142,24 @@
testBoolProp(anode, boolProp);
}
const doubleProps = ["valueMax", "valueMin", "valueNow"];
for (const doubleProp of doubleProps) {
testDoubleProp(anode, doubleProp);
}
const intProps = ["colCount", "rowCount", "setSize"];
for (const intProp of intProps) {
testIntProp(anode, intProp);
}
const uintProps = ["colIndex", "colSpan", "level", "posInSet", "rowIndex", "rowSpan"];
for (const uintProp of uintProps) {
testUIntProp(anode, uintProp);
}
// Check if an AccessibleNode is properly cached.
let node = ifrDoc.createElement("div");
anode = node.accessibleNode;

View File

@ -25,6 +25,11 @@ interface AccessibleNode {
attribute boolean? readOnly;
attribute boolean? required;
// Range values
attribute double? valueMax;
attribute double? valueMin;
attribute double? valueNow;
// Accessible states
attribute boolean? disabled;
attribute boolean? expanded;
@ -34,4 +39,15 @@ interface AccessibleNode {
// Live regions
attribute boolean? atomic;
attribute boolean? busy;
// Collections.
attribute long? colCount;
attribute unsigned long? colIndex;
attribute unsigned long? colSpan;
attribute unsigned long? level;
attribute unsigned long? posInSet;
attribute long? rowCount;
attribute unsigned long? rowIndex;
attribute unsigned long? rowSpan;
attribute long? setSize;
};