Bug 245370. Make autocomplete dropdowns accessible. r=neil, sr=alecf

This commit is contained in:
aaronleventhal%moonset.net 2004-06-08 13:59:11 +00:00
parent 008c9751ac
commit 593684a98a
3 changed files with 63 additions and 42 deletions

View File

@ -50,6 +50,7 @@
#include "nsIDOMHTMLSelectElement.h"
#include "nsIDOMNSEvent.h"
#include "nsIDOMWindow.h"
#include "nsIDOMXULMultSelectCntrlEl.h"
#include "nsIDOMXULSelectCntrlEl.h"
#include "nsIDOMXULSelectCntrlItemEl.h"
#include "nsIDocument.h"
@ -65,7 +66,6 @@
#include "nsRootAccessible.h"
#ifdef MOZ_XUL
#include "nsXULTreeAccessible.h"
#include "nsITreeSelection.h"
#include "nsIXULDocument.h"
#endif
#include "nsAccessibilityService.h"
@ -296,6 +296,9 @@ void nsRootAccessible::GetEventShell(nsIDOMNode *aNode, nsIPresShell **aEventShe
NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
{
// Turn DOM events in accessibility events
// Get info about event and target
// optionTargetNode is set to current option for HTML selects
nsCOMPtr<nsIDOMNode> targetNode, optionTargetNode;
GetTargetNode(aEvent, getter_AddRefs(targetNode));
@ -304,11 +307,16 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
nsAutoString eventType;
aEvent->GetType(eventType);
nsAutoString localName;
targetNode->GetLocalName(localName);
#ifdef DEBUG_aleventhal
// Very useful for debugging, please leave this here.
if (eventType.EqualsIgnoreCase("DOMMenuItemActive")) {
printf("debugging events");
}
if (localName.EqualsIgnoreCase("tree")) {
printf("debugging events");
}
#endif
// Check to see if it's a select element. If so, need the currently focused option
@ -345,27 +353,22 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
#ifdef MOZ_XUL
// If it's a tree element, need the currently selected item
PRInt32 treeIndex = -1;
nsCOMPtr<nsITreeBoxObject> treeBox;
nsCOMPtr<nsIAccessible> treeItemAccessible;
nsXULTreeAccessible::GetTreeBoxObject(targetNode, getter_AddRefs(treeBox));
if (treeBox) {
nsCOMPtr<nsITreeView> view;
treeBox->GetView(getter_AddRefs(view));
if (view) {
nsCOMPtr<nsITreeSelection> selection;
view->GetSelection(getter_AddRefs(selection));
if (selection) {
selection->GetCurrentIndex(&treeIndex);
if (treeIndex >= 0) {
// XXX todo Kyle - fix bug 201922 so that tree is responsible for keeping track
// of it's own accessibles. Then we'll ask the tree so we can reuse
// the accessibles already created.
nsCOMPtr<nsIWeakReference> weakEventShell(do_GetWeakReference(eventShell));
treeItemAccessible = new nsXULTreeitemAccessible(accessible, targetNode,
weakEventShell, treeIndex);
if (!treeItemAccessible)
return NS_ERROR_OUT_OF_MEMORY;
if (localName.EqualsLiteral("tree")) {
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
do_QueryInterface(targetNode);
if (multiSelect) {
PRInt32 treeIndex = -1;
multiSelect->GetCurrentIndex(&treeIndex);
if (treeIndex >= 0) {
// XXX todo Kyle - fix bug 201922 so that tree is responsible for keeping track
// of it's own accessibles. Then we'll ask the tree so we can reuse
// the accessibles already created.
nsCOMPtr<nsIWeakReference> weakEventShell(do_GetWeakReference(eventShell));
treeItemAccessible = new nsXULTreeitemAccessible(accessible, targetNode,
weakEventShell, treeIndex);
if (!treeItemAccessible) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
}
@ -493,7 +496,7 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
FireAccessibleFocusEvent(accessible, targetNode);
}
else if (eventType.EqualsIgnoreCase("select")) {
if (treeBox && treeIndex >= 0) { // it's a XUL <tree>
if (treeItemAccessible) { // it's a XUL <tree>
// use EVENT_FOCUS instead of EVENT_ATK_SELECTION_CHANGE
privAcc = do_QueryInterface(treeItemAccessible);
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_FOCUS,

View File

@ -236,8 +236,17 @@
<!-- =================== PUBLIC MEMBERS =================== -->
<property name="value"
onget="return this.mInputElt.value;"
onset="this.mIgnoreInput = true; this.mInputElt.value = val; this.mIgnoreInput = false; return val;"/>
onget="return this.mInputElt.value;">
<setter><![CDATA[
this.mIgnoreInput = true;
this.mInputElt.value = val;
this.mIgnoreInput = false;
var event = document.createEvent('Events');
event.initEvent('ValueChange', true, true);
this.mInputElt.dispatchEvent(event);
return val;
]]></setter>
</property>
<property name="focused" readonly="true"
onget="return this.getAttribute('focused') == 'true';"/>
@ -465,6 +474,11 @@
this.tree.view.selection.select(val);
if (this.tree.treeBoxObject.height > 0)
this.tree.treeBoxObject.ensureRowIsVisible(val < 0 ? 0 : val);
// Fire select event on xul:tree so that accessibility API
// support layer can fire appropriate accessibility events.
var event = document.createEvent('Events');
event.initEvent("select", true, true);
this.tree.dispatchEvent(event);
return val;
]]></setter>
</property>

View File

@ -66,11 +66,17 @@
<!-- =================== PUBLIC PROPERTIES =================== -->
<property name="value"
onset="this.ignoreInputEvent = true;
this.mInputElt.value = val;
this.ignoreInputEvent = false;
return val;"
onget="return this.mInputElt ? this.mInputElt.value : null;"/>
onget="return this.mInputElt.value;">
<setter><![CDATA[
this.ignoreInputEvent = true;
this.mInputElt.value = val;
this.ignoreInputEvent = false;
var event = document.createEvent('Events');
event.initEvent('ValueChange', true, true);
this.mInputElt.dispatchEvent(event);
return val;
]]></setter>
</property>
<property name="focused"
onget="return this.getAttribute('focused') == 'true';"/>
@ -1175,6 +1181,12 @@
if (aRow != null)
this.mBoxObject.ensureRowIsVisible(aRow);
// Fire select event on xul:tree so that accessibility API
// support layer can fire appropriate accessibility events.
var event = document.createEvent('Events');
event.initEvent("select", true, true);
this.mTree.element.dispatchEvent(event);
},
get selectedIndex()
@ -1357,19 +1369,9 @@
<property name="pageCount"
onget="return this.tree.treeBoxObject.getPageLength();"/>
<property name="selectedIndex"
onget="return this.textbox.view.selectedIndex">
<setter><![CDATA[
this.textbox.view.selectedIndex = val;
// Fire DOM events necessary for translation into accessibility events
var event = document.createEvent("Events");
event.initEvent("ValueChange", true, true);
this.textbox.dispatchEvent(event);
event.initEvent("DOMMenuItemActive", true, true);
this.textbox.resultsPopup.tree.dispatchEvent(event);
return val;
]]></setter>
</property>
<property name="selectedIndex"
onget="return this.textbox.view.selectedIndex"
onset="this.textbox.view.selectedIndex = val; return val;"/>
<field name="mLastRows">0</field>
@ -1510,6 +1512,8 @@
<implementation>
<property name="textbox"
onget="return this.__AUTOCOMPLETE_BOX__;"/>
<property name="currentIndex" onget="return this.textbox.view.selectedIndex;"
onset="this.textbox.view.selectedIndex = val; return val;"/>
</implementation>
</binding>