Bug 1525470 - Include description in accessible hints. r=yzen

Differential Revision: https://phabricator.services.mozilla.com/D19870

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eitan Isaacson 2019-02-21 17:45:17 +00:00
parent 5e37afdb09
commit bf64f6d78e
6 changed files with 54 additions and 29 deletions

View File

@ -419,9 +419,12 @@ mozilla::java::GeckoBundle::LocalRef AccessibleWrap::ToBundle(bool aSmall) {
Value(textValue);
nsAutoString nodeID;
WrapperDOMNodeID(nodeID);
nsAutoString description;
Description(description);
if (aSmall) {
return ToBundle(State(), Bounds(), ActionCount(), name, textValue, nodeID);
return ToBundle(State(), Bounds(), ActionCount(), name, textValue, nodeID,
description);
}
double curValue = UnspecifiedNaN<double>();
@ -433,15 +436,15 @@ mozilla::java::GeckoBundle::LocalRef AccessibleWrap::ToBundle(bool aSmall) {
nsCOMPtr<nsIPersistentProperties> attributes = Attributes();
return ToBundle(State(), Bounds(), ActionCount(), name, textValue, nodeID,
curValue, minValue, maxValue, step, attributes);
description, curValue, minValue, maxValue, step, attributes);
}
mozilla::java::GeckoBundle::LocalRef AccessibleWrap::ToBundle(
const uint64_t aState, const nsIntRect& aBounds, const uint8_t aActionCount,
const nsString& aName, const nsString& aTextValue,
const nsString& aDOMNodeID, const double& aCurVal, const double& aMinVal,
const double& aMaxVal, const double& aStep,
nsIPersistentProperties* aAttributes) {
const nsString& aDOMNodeID, const nsString& aDescription,
const double& aCurVal, const double& aMinVal, const double& aMaxVal,
const double& aStep, nsIPersistentProperties* aAttributes) {
if (!IsProxy() && IsDefunct()) {
return nullptr;
}
@ -461,10 +464,18 @@ mozilla::java::GeckoBundle::LocalRef AccessibleWrap::ToBundle(
java::sdk::Integer::ValueOf(AndroidClass()));
if (aState & states::EDITABLE) {
GECKOBUNDLE_PUT(nodeInfo, "hint", jni::StringParam(aName));
nsAutoString hint(aName);
if (!aDescription.IsEmpty()) {
hint.AppendLiteral(" ");
hint.Append(aDescription);
}
GECKOBUNDLE_PUT(nodeInfo, "hint", jni::StringParam(hint));
GECKOBUNDLE_PUT(nodeInfo, "text", jni::StringParam(aTextValue));
} else {
GECKOBUNDLE_PUT(nodeInfo, "text", jni::StringParam(aName));
if (!aDescription.IsEmpty()) {
GECKOBUNDLE_PUT(nodeInfo, "hint", jni::StringParam(aDescription));
}
}
nsAutoString geckoRole;

View File

@ -39,6 +39,7 @@ class AccessibleWrap : public Accessible {
const uint64_t aState, const nsIntRect& aBounds,
const uint8_t aActionCount, const nsString& aName,
const nsString& aTextValue, const nsString& aDOMNodeID,
const nsString& aDescription,
const double& aCurVal = UnspecifiedNaN<double>(),
const double& aMinVal = UnspecifiedNaN<double>(),
const double& aMaxVal = UnspecifiedNaN<double>(),

View File

@ -140,11 +140,13 @@ void DocAccessibleWrap::CacheViewportCallback(nsITimer* aTimer,
accessible->Value(textValue);
nsAutoString nodeID;
static_cast<AccessibleWrap*>(accessible)->WrapperDOMNodeID(nodeID);
nsAutoString description;
accessible->Description(description);
cacheData.AppendElement(
BatchData(accessible->Document()->IPCDoc(), uid, accessible->State(),
accessible->Bounds(), accessible->ActionCount(), name,
textValue, nodeID, UnspecifiedNaN<double>(),
textValue, nodeID, description, UnspecifiedNaN<double>(),
UnspecifiedNaN<double>(), UnspecifiedNaN<double>(),
UnspecifiedNaN<double>(), nsTArray<Attribute>()));
}
@ -205,13 +207,16 @@ void DocAccessibleWrap::CacheFocusPath(AccessibleWrap* aAccessible) {
acc->Value(textValue);
nsAutoString nodeID;
acc->WrapperDOMNodeID(nodeID);
nsAutoString description;
acc->Description(description);
nsCOMPtr<nsIPersistentProperties> props = acc->Attributes();
nsTArray<Attribute> attributes;
nsAccUtils::PersistentPropertiesToArray(props, &attributes);
cacheData.AppendElement(BatchData(
acc->Document()->IPCDoc(), uid, acc->State(), acc->Bounds(),
acc->ActionCount(), name, textValue, nodeID, acc->CurValue(),
acc->MinValue(), acc->MaxValue(), acc->Step(), attributes));
cacheData.AppendElement(
BatchData(acc->Document()->IPCDoc(), uid, acc->State(), acc->Bounds(),
acc->ActionCount(), name, textValue, nodeID, description,
acc->CurValue(), acc->MinValue(), acc->MaxValue(),
acc->Step(), attributes));
mFocusPath.Put(acc->UniqueID(), acc);
}
@ -247,11 +252,12 @@ void DocAccessibleWrap::UpdateFocusPathBounds() {
auto uid = accessible->IsDoc() && accessible->AsDoc()->IPCDoc()
? 0
: reinterpret_cast<uint64_t>(accessible->UniqueID());
boundsData.AppendElement(BatchData(
accessible->Document()->IPCDoc(), uid, 0, accessible->Bounds(), 0,
nsString(), nsString(), nsString(), UnspecifiedNaN<double>(),
UnspecifiedNaN<double>(), UnspecifiedNaN<double>(),
UnspecifiedNaN<double>(), nsTArray<Attribute>()));
boundsData.AppendElement(
BatchData(accessible->Document()->IPCDoc(), uid, 0,
accessible->Bounds(), 0, nsString(), nsString(), nsString(),
nsString(), UnspecifiedNaN<double>(),
UnspecifiedNaN<double>(), UnspecifiedNaN<double>(),
UnspecifiedNaN<double>(), nsTArray<Attribute>()));
}
ipcDoc->SendBatch(eBatch_BoundsUpdate, boundsData);

View File

@ -332,9 +332,9 @@ void SessionAccessibility::ReplaceViewportCache(
AccessibleWrap* acc = aAccessibles.ElementAt(i);
if (aData.Length() == aAccessibles.Length()) {
const BatchData& data = aData.ElementAt(i);
auto bundle =
acc->ToBundle(data.State(), data.Bounds(), data.ActionCount(),
data.Name(), data.TextValue(), data.DOMNodeID());
auto bundle = acc->ToBundle(
data.State(), data.Bounds(), data.ActionCount(), data.Name(),
data.TextValue(), data.DOMNodeID(), data.Description());
infos->SetElement(i, bundle);
} else {
infos->SetElement(i, acc->ToBundle(true));
@ -354,10 +354,11 @@ void SessionAccessibility::ReplaceFocusPathCache(
const BatchData& data = aData.ElementAt(i);
nsCOMPtr<nsIPersistentProperties> props =
AccessibleWrap::AttributeArrayToProperties(data.Attributes());
auto bundle = acc->ToBundle(
data.State(), data.Bounds(), data.ActionCount(), data.Name(),
data.TextValue(), data.DOMNodeID(), data.CurValue(), data.MinValue(),
data.MaxValue(), data.Step(), props);
auto bundle =
acc->ToBundle(data.State(), data.Bounds(), data.ActionCount(),
data.Name(), data.TextValue(), data.DOMNodeID(),
data.Description(), data.CurValue(), data.MinValue(),
data.MaxValue(), data.Step(), props);
infos->SetElement(i, bundle);
} else {
infos->SetElement(i, acc->ToBundle());
@ -380,9 +381,9 @@ void SessionAccessibility::UpdateCachedBounds(
if (aData.Length() == aAccessibles.Length()) {
const BatchData& data = aData.ElementAt(i);
auto bundle =
acc->ToBundle(data.State(), data.Bounds(), data.ActionCount(),
data.Name(), data.TextValue(), data.DOMNodeID());
auto bundle = acc->ToBundle(
data.State(), data.Bounds(), data.ActionCount(), data.Name(),
data.TextValue(), data.DOMNodeID(), data.Description());
infos->SetElement(i, bundle);
} else {
infos->SetElement(i, acc->ToBundle(true));

View File

@ -40,6 +40,7 @@ struct BatchData
nsString Name;
nsString TextValue;
nsString DOMNodeID;
nsString Description;
double CurValue;
double MinValue;
double MaxValue;

View File

@ -229,7 +229,7 @@ class AccessibilityTest : BaseSessionTest() {
}
@Test fun testTextEntryNode() {
sessionRule.session.loadString("<input aria-label='Name' value='Tobias'>", "text/html")
sessionRule.session.loadString("<input aria-label='Name' aria-describedby='desc' value='Tobias'><div id='desc'>description</div>", "text/html")
waitForInitialFocus()
mainSession.evaluateJS("$('input').focus()")
@ -244,7 +244,7 @@ class AccessibilityTest : BaseSessionTest() {
if (Build.VERSION.SDK_INT >= 19) {
assertThat("Hint has field name",
node.extras.getString("AccessibilityNodeInfo.hint"),
equalTo("Name"))
equalTo("Name description"))
}
}
})
@ -514,7 +514,7 @@ class AccessibilityTest : BaseSessionTest() {
@Test fun testCheckbox() {
var nodeId = AccessibilityNodeProvider.HOST_VIEW_ID;
sessionRule.session.loadString("<label><input type='checkbox'>many option</label>", "text/html")
sessionRule.session.loadString("<label><input type='checkbox' aria-describedby='desc'>many option</label><div id='desc'>description</div>", "text/html")
waitForInitialFocus(true)
sessionRule.waitUntilCalled(object : EventDelegate {
@ -527,6 +527,11 @@ class AccessibilityTest : BaseSessionTest() {
assertThat("Checkbox node is focusable", node.isFocusable, equalTo(true))
assertThat("Checkbox node is not checked", node.isChecked, equalTo(false))
assertThat("Checkbox node has correct role", node.text.toString(), equalTo("many option"))
if (Build.VERSION.SDK_INT >= 19) {
assertThat("Hint has description", node.extras.getString("AccessibilityNodeInfo.hint"),
equalTo("description"))
}
}
})