From 0a12a21fcc4b49e4e7845400bca3acd3a18f7dd5 Mon Sep 17 00:00:00 2001 From: "aaronleventhal%moonset.net" Date: Mon, 21 May 2007 13:53:57 +0000 Subject: [PATCH] Bug 381229. Incorrect accessible role and events for XUL autocomplete and combobox (menulist) popup lists. r=ginn.chen --- accessible/src/base/nsRootAccessible.cpp | 41 +++++++++++----------- accessible/src/xul/nsXULMenuAccessible.cpp | 8 ++++- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/accessible/src/base/nsRootAccessible.cpp b/accessible/src/base/nsRootAccessible.cpp index d29e29eca62..f06499523a6 100644 --- a/accessible/src/base/nsRootAccessible.cpp +++ b/accessible/src/base/nsRootAccessible.cpp @@ -606,25 +606,6 @@ nsresult nsRootAccessible::HandleEventWithTarget(nsIDOMEvent* aEvent, return NS_OK; } - if (eventType.EqualsLiteral("popupshown")) { - // Fire menupopupstart events after a delay so that ancestor views - // are visible, otherwise an accessible cannot be created for the - // popup and the accessibility toolkit event can't be fired. - nsCOMPtr popup(do_QueryInterface(aTargetNode)); - if (popup) { - PRInt32 event = nsIAccessibleEvent::EVENT_MENUPOPUP_START; - nsCOMPtr content(do_QueryInterface(aTargetNode)); - if (content->NodeInfo()->Equals(nsAccessibilityAtoms::tooltip, kNameSpaceID_XUL)) { - // There is a single node which Mozilla moves around. - // The accessible for it stays the same no matter where it moves. - // AT's expect to get an EVENT_SHOW for the tooltip. - // In event callback the tooltip's accessible will be ready. - event = nsIAccessibleEvent::EVENT_SHOW; - } - return FireDelayedToolkitEvent(event, aTargetNode, nsnull); - } - } - if (eventType.EqualsLiteral("DOMContentLoaded")) { // Don't create the doc accessible until load scripts have a chance to set // role attribute for or element, because the value of @@ -780,6 +761,25 @@ nsresult nsRootAccessible::HandleEventWithTarget(nsIDOMEvent* aEvent, privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_ALERT, accessible, nsnull); } + if (eventType.EqualsLiteral("popupshown")) { + // Don't fire menupopup events for combobox and autocomplete lists + PRUint32 role = Role(accessible); + PRInt32 event = 0; + if (role == nsIAccessibleRole::ROLE_MENUPOPUP) { + event = nsIAccessibleEvent::EVENT_MENUPOPUP_START; + } + else if (role == nsIAccessibleRole::ROLE_TOOLTIP) { + // There is a single node which Mozilla moves around. + // The accessible for it stays the same no matter where it moves. + // AT's expect to get an EVENT_SHOW for the tooltip. + // In event callback the tooltip's accessible will be ready. + event = nsIAccessibleEvent::EVENT_SHOW; + } + if (event) { + privAcc->FireToolkitEvent(event, accessible, nsnull); + } + } + else if (eventType.EqualsLiteral("popuphiding")) { // If accessible focus was on or inside popup that closes, // then restore it to true current focus. @@ -802,8 +802,7 @@ nsresult nsRootAccessible::HandleEventWithTarget(nsIDOMEvent* aEvent, FireCurrentFocusEvent(); } else if (eventType.EqualsLiteral("DOMMenuInactive")) { - nsCOMPtr popup(do_QueryInterface(aTargetNode)); - if (popup) { + if (Role(accessible) == nsIAccessibleRole::ROLE_MENUPOPUP) { privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_MENUPOPUP_END, accessible, nsnull); } diff --git a/accessible/src/xul/nsXULMenuAccessible.cpp b/accessible/src/xul/nsXULMenuAccessible.cpp index 47e36a03537..c63a10a4bba 100644 --- a/accessible/src/xul/nsXULMenuAccessible.cpp +++ b/accessible/src/xul/nsXULMenuAccessible.cpp @@ -637,7 +637,13 @@ NS_IMETHODIMP nsXULMenupopupAccessible::GetName(nsAString& _retval) NS_IMETHODIMP nsXULMenupopupAccessible::GetRole(PRUint32 *aRole) { - if (mParent && Role(mParent) == nsIAccessibleRole::ROLE_COMBOBOX) { + nsCOMPtr content(do_QueryInterface(mDOMNode)); + if (!content) { + return NS_ERROR_FAILURE; + } + if ((mParent && Role(mParent) == nsIAccessibleRole::ROLE_COMBOBOX) || + content->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::type, + nsAccessibilityAtoms::autocomplete, eIgnoreCase)) { *aRole = nsIAccessibleRole::ROLE_COMBOBOX_LIST; } else {