Bug 1518054: Move a11y focus event firing from richlistitem.current to richlistbox.currentItem to fix the All Downloads view. r=paolo

The All Downloads view removes and re-adds its richlistbox for performance reasons.
However, after bug 1492326, this causes the richlistitem's .current property to be assigned before its binding is applied.
Since the .current property fires a11y focus events, this means this property is overridden and thus the events never get fired for that item.
To fix this, move a11y focus event firing into richlistbox.currentItem.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
James Teh 2019-01-22 02:08:26 +00:00
parent cfd37ea8ea
commit ee1ef24296
3 changed files with 20 additions and 20 deletions

View File

@ -1496,7 +1496,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
// the input, since the user is editing.
if (!this.popup.richlistbox.suppressMenuItemEvent &&
this.popup.richlistbox.currentItem) {
this.popup.richlistbox.currentItem._fireEvent("DOMMenuItemInactive");
this.popup.richlistbox._fireEvent(
this.popup.richlistbox.currentItem, "DOMMenuItemInactive");
}
// The user is typing, so don't give accessibility focus to the
// popup, even if an item gets automatically selected.
@ -2226,7 +2227,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
// but because the popup isn't open yet, accessibility will ignore
// it. Therefore, fire it again once the popup opens.
this.addEventListener("popupshown", () => {
this.richlistbox.currentItem._fireEvent("DOMMenuItemActive");
this.richlistbox._fireEvent(this.richlistbox.currentItem,
"DOMMenuItemActive");
}, {once: true});
}

View File

@ -112,7 +112,7 @@ MozElements.RichListBox = class RichListBox extends MozElements.BaseControl {
this.selectItem(currentItem);
}
} else {
this.currentItem._fireEvent("DOMMenuItemActive");
this._fireEvent(this.currentItem, "DOMMenuItemActive");
}
}
this._lastKeyTime = 0;
@ -217,11 +217,20 @@ MozElements.RichListBox = class RichListBox extends MozElements.BaseControl {
if (this._currentItem) {
this._currentItem.current = false;
if (!val && !this.suppressMenuItemEvent) {
// An item is losing focus and there is no new item to focus.
// Notify a11y that there is no focused item.
this._fireEvent(this._currentItem, "DOMMenuItemInactive");
}
}
this._currentItem = val;
if (val) {
val.current = true;
if (!this.suppressMenuItemEvent) {
// Notify a11y that this item got focus.
this._fireEvent(val, "DOMMenuItemActive");
}
}
return val;
@ -815,6 +824,12 @@ MozElements.RichListBox = class RichListBox extends MozElements.BaseControl {
ensureSelectedElementIsVisible() {
return this.ensureElementIsVisible(this.selectedItem);
}
_fireEvent(aTarget, aName) {
let event = document.createEvent("Events");
event.initEvent(aName, true, true);
aTarget.dispatchEvent(event);
}
};
MozXULElement.implementCustomInterface(MozElements.RichListBox, [

View File

@ -105,26 +105,9 @@
this.setAttribute("current", "true");
else
this.removeAttribute("current");
let control = this.control;
if (!control || !control.suppressMenuItemEvent) {
this._fireEvent(val ? "DOMMenuItemActive" : "DOMMenuItemInactive");
}
return val;
]]></setter>
</property>
<method name="_fireEvent">
<parameter name="name"/>
<body>
<![CDATA[
var event = document.createEvent("Events");
event.initEvent(name, true, true);
this.dispatchEvent(event);
]]>
</body>
</method>
</implementation>
<handlers>