Bug 1578140: Use nsXULElement::Click for DoAction on XULLabelAccessible so it works for labels inside buttons. r=eeejay

For labels inside buttons, The base implementation of DispatchClickEvent doesn't fire a command event on the button.
To fix this, override DispatchClickEvent to use nsXULElement::Click, which does fire a command event on the button.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
James Teh 2019-09-03 19:11:35 +00:00
Родитель 4b6fa71ccf
Коммит 187e20b6ae
4 изменённых файлов: 52 добавлений и 0 удалений

Просмотреть файл

@ -35,6 +35,10 @@ const XUL_EVENTS = CLICK_EVENTS | COMMAND_EVENT;
* // used with 'events', if missing then 'ID' is used instead.
* get targetID() {},
*
* // [optional] true to match DOM events bubbled up to the target,
* // false (default) to only match events fired directly on the target.
* get allowBubbling() {},
*
* // [optional] perform checks when 'click' event is handled if 'events'
* // is used.
* checkOnClickEvent: function() {},
@ -182,6 +186,17 @@ function checkerOfActionInvoker(aType, aTarget, aActionObj) {
this.eventTarget = aActionObj.eventTarget;
}
if (aActionObj && aActionObj.allowBubbling) {
// Normally, we add event listeners on the document. To catch bubbled
// events, we need to add the listener on the target itself.
this.eventTarget = "element";
// Normally, we only match an event fired directly on the target. Override
// this to match a bubbled event.
this.match = function(aEvent) {
return aEvent.currentTarget == aTarget;
};
}
this.phase = false;
this.getID = function getID() {

Просмотреть файл

@ -17,6 +17,10 @@
src="../events.js" />
<script type="application/javascript"
src="../actions.js" />
<script type="application/javascript"
src="../role.js" />
<script type="application/javascript"
src="../states.js" />
<script type="application/javascript">
<![CDATA[
@ -71,6 +75,19 @@
ID: "labelWithPopup",
actionName: "click",
events: CLICK_EVENTS
},
{
ID: "toolbarbutton_label",
actionName: "click",
targetID: "toolbarbutton",
events: XUL_EVENTS,
allowBubbling: true
},
{
ID: "menulist_label",
actionName: "click",
targetID: "menulist",
events: FOCUS_EVENT
}/*, // XXX: bug 490288
{
ID: "buttonmenu_item",
@ -138,6 +155,13 @@
<label id="name_entry_label" value="Name" control="name_entry"/>
<textbox id="name_entry"/>
</hbox>
<toolbarbutton id="toolbarbutton">
<label id="toolbarbutton_label">toolbarbutton</label>
</toolbarbutton>
<hbox>
<label id="menulist_label" control="menulist">menulist</label>
<menulist id="menulist"/>
</hbox>
</vbox>
</hbox>
</window>

Просмотреть файл

@ -24,6 +24,7 @@
#include "nsNetUtil.h"
#include "nsString.h"
#include "nsTextBoxFrame.h"
#include "nsXULElement.h"
using namespace mozilla::a11y;
@ -57,6 +58,16 @@ void XULLabelAccessible::Shutdown() {
HyperTextAccessibleWrap::Shutdown();
}
void XULLabelAccessible::DispatchClickEvent(nsIContent* aContent,
uint32_t aActionIndex) const {
// Bug 1578140: For labels inside buttons, The base implementation of
// DispatchClickEvent doesn't fire a command event on the button.
RefPtr<nsXULElement> el = nsXULElement::FromNodeOrNull(aContent);
if (el) {
el->Click(mozilla::dom::CallerType::System);
}
}
ENameValueFlag XULLabelAccessible::NativeName(nsString& aName) const {
// if the value attr doesn't exist, the screen reader must get the accessible
// text from the accessible text interface or from the children

Просмотреть файл

@ -32,6 +32,8 @@ class XULLabelAccessible : public HyperTextAccessibleWrap {
protected:
// Accessible
virtual ENameValueFlag NativeName(nsString& aName) const override;
virtual void DispatchClickEvent(nsIContent* aContent,
uint32_t aActionIndex) const override;
private:
RefPtr<XULLabelTextLeafAccessible> mValueTextLeaf;