in src/Clients/Web/winjs/js/winjs.js [42869:43002]
_setupAria: function VirtualizeContentsView_setupAria(timedOut) {
if (this._listView._isZombie()) { return; }
var that = this;
function done() {
that._listView._writeProfilerMark("aria work,StopTM");
}
function calcLastRealizedIndexInGroup(groupIndex) {
var groups = that._listView._groups,
nextGroup = groups.group(groupIndex + 1);
return (nextGroup ? Math.min(nextGroup.startIndex - 1, that.end - 1) : that.end - 1);
}
this._listView._createAriaMarkers();
return this._listView._itemsCount().then(function (count) {
if (count > 0 && that.firstIndexDisplayed !== -1 && that.lastIndexDisplayed !== -1) {
that._listView._writeProfilerMark("aria work,StartTM");
var startMarker = that._listView._ariaStartMarker,
endMarker = that._listView._ariaEndMarker,
index = that.begin,
item = that.items.itemAt(that.begin),
job,
// These are only used when the ListView is using groups
groups,
startGroup,
currentGroup,
group,
lastRealizedIndexInGroup;
if (item) {
_ElementUtilities._ensureId(item);
if (that._listView._groupsEnabled()) {
groups = that._listView._groups;
startGroup = currentGroup = groups.groupFromItem(that.begin);
group = groups.group(currentGroup);
lastRealizedIndexInGroup = calcLastRealizedIndexInGroup(currentGroup);
_ElementUtilities._ensureId(group.header);
_ElementUtilities._setAttribute(group.header, "role", that._listView._headerRole);
_ElementUtilities._setAttribute(group.header, "x-ms-aria-flowfrom", startMarker.id);
setFlow(group.header, item);
_ElementUtilities._setAttribute(group.header, "tabindex", that._listView._tabIndex);
} else {
_ElementUtilities._setAttribute(item, "x-ms-aria-flowfrom", startMarker.id);
}
return new Promise(function (completeJobPromise) {
var skipWait = timedOut;
job = Scheduler.schedule(function ariaWorker(jobInfo) {
if (that._listView._isZombie()) {
done();
return;
}
for (; index < that.end; index++) {
if (!skipWait && shouldWaitForSeZo(that._listView)) {
jobInfo.setPromise(waitForSeZo(that._listView).then(function (timedOut) {
skipWait = timedOut;
return ariaWorker;
}));
return;
} else if (jobInfo.shouldYield) {
jobInfo.setWork(ariaWorker);
return;
}
item = that.items.itemAt(index);
var nextItem = that.items.itemAt(index + 1);
if (nextItem) {
_ElementUtilities._ensureId(nextItem);
}
_ElementUtilities._setAttribute(item, "role", that._listView._itemRole);
_ElementUtilities._setAttribute(item, "aria-setsize", count);
_ElementUtilities._setAttribute(item, "aria-posinset", index + 1);
_ElementUtilities._setAttribute(item, "tabindex", that._listView._tabIndex);
if (that._listView._groupsEnabled()) {
if (index === lastRealizedIndexInGroup || !nextItem) {
var nextGroup = groups.group(currentGroup + 1);
// If group is the last realized group, then nextGroup won't exist in the DOM.
// When this is the case, nextItem shouldn't exist.
if (nextGroup && nextGroup.header && nextItem) {
_ElementUtilities._setAttribute(nextGroup.header, "tabindex", that._listView._tabIndex);
_ElementUtilities._setAttribute(nextGroup.header, "role", that._listView._headerRole);
_ElementUtilities._ensureId(nextGroup.header);
setFlow(item, nextGroup.header);
setFlow(nextGroup.header, nextItem);
} else {
// We're at the last group so flow to the end marker
_ElementUtilities._setAttribute(item, "aria-flowto", endMarker.id);
}
currentGroup++;
group = nextGroup;
lastRealizedIndexInGroup = calcLastRealizedIndexInGroup(currentGroup);
} else {
// This is not the last item in the group so flow to the next item
setFlow(item, nextItem);
}
} else if (nextItem) {
// Groups are disabled so as long as we aren't at the last item, flow to the next one
setFlow(item, nextItem);
} else {
// Groups are disabled and we're at the last item, so flow to the end marker
_ElementUtilities._setAttribute(item, "aria-flowto", endMarker.id);
}
if (!nextItem) {
break;
}
}
that._listView._fireAccessibilityAnnotationCompleteEvent(that.begin, index, startGroup, currentGroup - 1);
done();
completeJobPromise();
}, Scheduler.Priority.belowNormal, null, "WinJS.UI.ListView._setupAria");
}, function () {
// Cancellation handler for promise returned by setupAria
job.cancel();
done();
});
} else {
// the first item is null
done();
}
} else {
// The count is 0
return Promise.wrap();
}
});
},