2009-02-19 07:06:14 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constants
|
|
|
|
|
2009-07-28 02:28:06 +00:00
|
|
|
const EVENT_DOCUMENT_LOAD_COMPLETE =
|
|
|
|
nsIAccessibleEvent.EVENT_DOCUMENT_LOAD_COMPLETE;
|
2009-02-19 07:06:14 +00:00
|
|
|
const EVENT_DOM_DESTROY = nsIAccessibleEvent.EVENT_DOM_DESTROY;
|
2009-05-11 01:32:09 +00:00
|
|
|
const EVENT_FOCUS = nsIAccessibleEvent.EVENT_FOCUS;
|
2009-02-27 10:45:21 +00:00
|
|
|
const EVENT_NAME_CHANGE = nsIAccessibleEvent.EVENT_NAME_CHANGE;
|
2009-09-01 02:49:15 +00:00
|
|
|
const EVENT_SCROLLING_START = nsIAccessibleEvent.EVENT_SCROLLING_START;
|
2009-08-20 06:45:19 +00:00
|
|
|
const EVENT_STATE_CHANGE = nsIAccessibleEvent.EVENT_STATE_CHANGE;
|
2009-02-27 10:45:21 +00:00
|
|
|
const EVENT_REORDER = nsIAccessibleEvent.EVENT_REORDER;
|
2009-02-19 07:06:14 +00:00
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// General
|
|
|
|
|
2009-02-05 06:23:18 +00:00
|
|
|
/**
|
|
|
|
* Set up this variable to dump events into DOM.
|
|
|
|
*/
|
|
|
|
var gA11yEventDumpID = "";
|
|
|
|
|
2009-02-19 07:06:14 +00:00
|
|
|
/**
|
|
|
|
* Executes the function when requested event is handled.
|
|
|
|
*
|
|
|
|
* @param aEventType [in] event type
|
|
|
|
* @param aTarget [in] event target
|
|
|
|
* @param aFunc [in] function to call when event is handled
|
|
|
|
* @param aContext [in, optional] object in which context the function is
|
|
|
|
* called
|
|
|
|
* @param aArg1 [in, optional] argument passed into the function
|
|
|
|
* @param aArg2 [in, optional] argument passed into the function
|
|
|
|
*/
|
|
|
|
function waitForEvent(aEventType, aTarget, aFunc, aContext, aArg1, aArg2)
|
|
|
|
{
|
|
|
|
var handler = {
|
|
|
|
handleEvent: function handleEvent(aEvent) {
|
|
|
|
if (!aTarget || aTarget == aEvent.DOMNode) {
|
|
|
|
unregisterA11yEventListener(aEventType, this);
|
|
|
|
|
|
|
|
window.setTimeout(
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
aFunc.call(aContext, aArg1, aArg2);
|
|
|
|
},
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
registerA11yEventListener(aEventType, handler);
|
|
|
|
}
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
/**
|
|
|
|
* Register accessibility event listener.
|
|
|
|
*
|
|
|
|
* @param aEventType the accessible event type (see nsIAccessibleEvent for
|
|
|
|
* available constants).
|
|
|
|
* @param aEventHandler event listener object, when accessible event of the
|
|
|
|
* given type is handled then 'handleEvent' method of
|
|
|
|
* this object is invoked with nsIAccessibleEvent object
|
|
|
|
* as the first argument.
|
|
|
|
*/
|
|
|
|
function registerA11yEventListener(aEventType, aEventHandler)
|
|
|
|
{
|
|
|
|
listenA11yEvents(true);
|
|
|
|
|
|
|
|
gA11yEventApplicantsCount++;
|
|
|
|
addA11yEventListener(aEventType, aEventHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister accessibility event listener. Must be called for every registered
|
|
|
|
* event listener (see registerA11yEventListener() function) when the listener
|
|
|
|
* is not needed.
|
|
|
|
*/
|
|
|
|
function unregisterA11yEventListener(aEventType, aEventHandler)
|
|
|
|
{
|
|
|
|
removeA11yEventListener(aEventType, aEventHandler);
|
|
|
|
|
|
|
|
gA11yEventApplicantsCount--;
|
|
|
|
listenA11yEvents(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Event queue
|
|
|
|
|
2009-05-11 01:32:09 +00:00
|
|
|
/**
|
|
|
|
* Return value of invoke method of invoker object. Indicates invoker was unable
|
|
|
|
* to prepare action.
|
|
|
|
*/
|
|
|
|
const INVOKER_ACTION_FAILED = 1;
|
|
|
|
|
2009-07-28 02:28:06 +00:00
|
|
|
/**
|
|
|
|
* Common invoker checker (see eventSeq of eventQueue).
|
|
|
|
*/
|
|
|
|
function invokerChecker(aEventType, aTarget)
|
|
|
|
{
|
|
|
|
this.type = aEventType;
|
|
|
|
this.target = aTarget;
|
|
|
|
}
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
/**
|
|
|
|
* Creates event queue for the given event type. The queue consists of invoker
|
|
|
|
* objects, each of them generates the event of the event type. When queue is
|
|
|
|
* started then every invoker object is asked to generate event after timeout.
|
2009-06-11 19:57:29 +00:00
|
|
|
* When event is caught then current invoker object is asked to check whether
|
2009-01-25 04:42:21 +00:00
|
|
|
* event was handled correctly.
|
|
|
|
*
|
|
|
|
* Invoker interface is:
|
|
|
|
*
|
|
|
|
* var invoker = {
|
2009-05-11 01:32:09 +00:00
|
|
|
* // Generates accessible event or event sequence. If returns
|
|
|
|
* // INVOKER_ACTION_FAILED constant then stop tests.
|
2009-01-25 04:42:21 +00:00
|
|
|
* invoke: function(){},
|
|
|
|
*
|
2009-02-27 10:45:21 +00:00
|
|
|
* // [optional] Invoker's check of handled event for correctness.
|
2009-01-25 04:42:21 +00:00
|
|
|
* check: function(aEvent){},
|
|
|
|
*
|
2009-02-27 10:45:21 +00:00
|
|
|
* // [optional] Is called when event of registered type is handled.
|
2009-01-25 04:42:21 +00:00
|
|
|
* debugCheck: function(aEvent){},
|
|
|
|
*
|
2009-02-27 10:45:21 +00:00
|
|
|
* // [ignored if 'eventSeq' is defined] DOM node event is generated for
|
|
|
|
* // (used in the case when invoker expects single event).
|
|
|
|
* DOMNode getter: function() {},
|
2009-01-25 04:42:21 +00:00
|
|
|
*
|
|
|
|
* // Array of items defining events expected (or not expected, see
|
2009-02-27 10:45:21 +00:00
|
|
|
* // 'doNotExpectEvents' property) on invoker's action.
|
|
|
|
* //
|
|
|
|
* // Every array item should be either
|
|
|
|
* // 1) an array consisted from two elements, the first element is DOM or
|
|
|
|
* // a11y event type, second element is event target (DOM node or
|
|
|
|
* // accessible).
|
|
|
|
* //
|
|
|
|
* // 2) object (invoker's checker object) like
|
|
|
|
* // var checker = {
|
|
|
|
* // type getter: function() {}, // DOM or a11y event type
|
|
|
|
* // target getter: function() {}, // DOM node or accessible
|
2009-08-20 06:45:19 +00:00
|
|
|
* // phase getter: function() {}, // DOM event phase (false - bubbling)
|
2009-02-27 10:45:21 +00:00
|
|
|
* // check: function(aEvent) {},
|
|
|
|
* // getID: function() {}
|
|
|
|
* // };
|
2009-01-25 04:42:21 +00:00
|
|
|
* eventSeq getter() {},
|
|
|
|
*
|
2009-02-27 10:45:21 +00:00
|
|
|
* // [optional, used together with 'eventSeq'] Boolean indicates if events
|
|
|
|
* // specified by 'eventSeq' property shouldn't be triggerd by invoker.
|
2009-01-25 04:42:21 +00:00
|
|
|
* doNotExpectEvents getter() {},
|
|
|
|
*
|
|
|
|
* // The ID of invoker.
|
|
|
|
* getID: function(){} // returns invoker ID
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* @param aEventType [optional] the default event type (isn't used if
|
|
|
|
* invoker defines eventSeq property).
|
|
|
|
*/
|
|
|
|
function eventQueue(aEventType)
|
|
|
|
{
|
|
|
|
// public
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add invoker object into queue.
|
|
|
|
*/
|
|
|
|
this.push = function eventQueue_push(aEventInvoker)
|
|
|
|
{
|
|
|
|
this.mInvokers.push(aEventInvoker);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the queue processing.
|
|
|
|
*/
|
|
|
|
this.invoke = function eventQueue_invoke()
|
|
|
|
{
|
|
|
|
listenA11yEvents(true);
|
|
|
|
gA11yEventApplicantsCount++;
|
|
|
|
|
|
|
|
// XXX: Intermittent test_events_caretmove.html fails withouth timeout,
|
|
|
|
// see bug 474952.
|
|
|
|
window.setTimeout(function(aQueue) { aQueue.processNextInvoker(); }, 500,
|
|
|
|
this);
|
|
|
|
}
|
|
|
|
|
2009-08-21 13:20:18 +00:00
|
|
|
/**
|
|
|
|
* This function is called when all events in the queue were handled.
|
|
|
|
* Override it if you need to be notified of this.
|
|
|
|
*/
|
|
|
|
this.onFinish = function eventQueue_finish()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
// private
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process next invoker.
|
|
|
|
*/
|
|
|
|
this.processNextInvoker = function eventQueue_processNextInvoker()
|
|
|
|
{
|
|
|
|
// Finish rocessing of the current invoker.
|
|
|
|
var testFailed = false;
|
|
|
|
|
|
|
|
var invoker = this.getInvoker();
|
|
|
|
if (invoker) {
|
|
|
|
if (invoker.wasCaught) {
|
2009-02-27 10:45:21 +00:00
|
|
|
for (var idx = 0; idx < invoker.wasCaught.length; idx++) {
|
|
|
|
var id = this.getEventID(idx);
|
|
|
|
var type = this.getEventType(idx);
|
|
|
|
var typeStr = (typeof type == "string") ?
|
|
|
|
type : gAccRetrieval.getStringEventType(type);
|
2009-01-25 04:42:21 +00:00
|
|
|
|
|
|
|
var msg = "test with ID = '" + id + "' failed. ";
|
|
|
|
if (invoker.doNotExpectEvents) {
|
2009-02-27 10:45:21 +00:00
|
|
|
var wasCaught = invoker.wasCaught[idx];
|
2009-01-25 04:42:21 +00:00
|
|
|
if (!testFailed)
|
|
|
|
testFailed = wasCaught;
|
|
|
|
|
|
|
|
ok(!wasCaught,
|
|
|
|
msg + "There is unexpected " + typeStr + " event.");
|
|
|
|
|
|
|
|
} else {
|
2009-02-27 10:45:21 +00:00
|
|
|
var wasCaught = invoker.wasCaught[idx];
|
2009-01-25 04:42:21 +00:00
|
|
|
if (!testFailed)
|
|
|
|
testFailed = !wasCaught;
|
|
|
|
|
|
|
|
ok(wasCaught,
|
|
|
|
msg + "No " + typeStr + " event.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
testFailed = true;
|
2009-02-27 10:45:21 +00:00
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
var id = this.getEventID(idx);
|
|
|
|
ok(false,
|
|
|
|
"test with ID = '" + id + "' failed. No events were registered.");
|
|
|
|
}
|
2009-01-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.clearEventHandler();
|
|
|
|
|
|
|
|
// Check if need to stop the test.
|
|
|
|
if (testFailed || this.mIndex == this.mInvokers.length - 1) {
|
|
|
|
gA11yEventApplicantsCount--;
|
|
|
|
listenA11yEvents(false);
|
|
|
|
|
2009-08-21 13:20:18 +00:00
|
|
|
this.onFinish();
|
2009-01-25 04:42:21 +00:00
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start processing of next invoker.
|
|
|
|
invoker = this.getNextInvoker();
|
|
|
|
|
|
|
|
this.setEventHandler(invoker);
|
|
|
|
|
2009-05-11 01:32:09 +00:00
|
|
|
if (invoker.invoke() == INVOKER_ACTION_FAILED) {
|
|
|
|
// Invoker failed to prepare action, fail and finish tests.
|
|
|
|
this.processNextInvoker();
|
|
|
|
return;
|
|
|
|
}
|
2009-01-25 04:42:21 +00:00
|
|
|
|
|
|
|
if (invoker.doNotExpectEvents) {
|
|
|
|
// Check in timeout invoker didn't fire registered events.
|
|
|
|
window.setTimeout(function(aQueue) { aQueue.processNextInvoker(); }, 500,
|
|
|
|
this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle events for the current invoker.
|
|
|
|
*/
|
|
|
|
this.handleEvent = function eventQueue_handleEvent(aEvent)
|
|
|
|
{
|
|
|
|
var invoker = this.getInvoker();
|
|
|
|
if (!invoker) // skip events before test was started
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!this.mEventSeq) {
|
|
|
|
// Bad invoker object, error will be reported before processing of next
|
|
|
|
// invoker in the queue.
|
|
|
|
this.processNextInvoker();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("debugCheck" in invoker)
|
|
|
|
invoker.debugCheck(aEvent);
|
|
|
|
|
|
|
|
if (invoker.doNotExpectEvents) {
|
|
|
|
// Search through event sequence to ensure it doesn't contain handled
|
|
|
|
// event.
|
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
2009-02-27 10:45:21 +00:00
|
|
|
if (this.compareEvents(idx, aEvent))
|
2009-01-25 04:42:21 +00:00
|
|
|
invoker.wasCaught[idx] = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We wait for events in order specified by eventSeq variable.
|
|
|
|
var idx = this.mEventSeqIdx + 1;
|
|
|
|
|
2009-08-20 06:45:19 +00:00
|
|
|
var matched = this.compareEvents(idx, aEvent);
|
|
|
|
this.dumpEventToDOM(aEvent, idx, matched);
|
2009-02-05 06:23:18 +00:00
|
|
|
|
2009-08-20 06:45:19 +00:00
|
|
|
if (matched) {
|
2009-02-27 10:45:21 +00:00
|
|
|
this.checkEvent(idx, aEvent);
|
2009-01-25 04:42:21 +00:00
|
|
|
invoker.wasCaught[idx] = true;
|
|
|
|
|
|
|
|
if (idx == this.mEventSeq.length - 1) {
|
|
|
|
// We need delay to avoid events coalesce from different invokers.
|
|
|
|
var queue = this;
|
|
|
|
SimpleTest.executeSoon(function() { queue.processNextInvoker(); });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mEventSeqIdx = idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helpers
|
|
|
|
this.getInvoker = function eventQueue_getInvoker()
|
|
|
|
{
|
|
|
|
return this.mInvokers[this.mIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getNextInvoker = function eventQueue_getNextInvoker()
|
|
|
|
{
|
|
|
|
return this.mInvokers[++this.mIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setEventHandler = function eventQueue_setEventHandler(aInvoker)
|
|
|
|
{
|
|
|
|
this.mEventSeq = ("eventSeq" in aInvoker) ?
|
2009-07-28 02:28:06 +00:00
|
|
|
aInvoker.eventSeq :
|
|
|
|
[ new invokerChecker(this.mDefEventType, aInvoker.DOMNode) ];
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
this.mEventSeqIdx = -1;
|
|
|
|
|
|
|
|
if (this.mEventSeq) {
|
|
|
|
aInvoker.wasCaught = new Array(this.mEventSeq.length);
|
2009-02-05 06:23:18 +00:00
|
|
|
|
2009-02-27 10:45:21 +00:00
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
var eventType = this.getEventType(idx);
|
2009-08-21 13:20:18 +00:00
|
|
|
if (typeof eventType == "string") {
|
|
|
|
// DOM event
|
|
|
|
var target = this.getEventTarget(idx);
|
|
|
|
var phase = this.getEventPhase(idx);
|
|
|
|
target.ownerDocument.addEventListener(eventType, this, phase);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// A11y event
|
2009-02-27 10:45:21 +00:00
|
|
|
addA11yEventListener(eventType, this);
|
2009-08-21 13:20:18 +00:00
|
|
|
}
|
2009-02-27 10:45:21 +00:00
|
|
|
}
|
2009-01-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.clearEventHandler = function eventQueue_clearEventHandler()
|
|
|
|
{
|
|
|
|
if (this.mEventSeq) {
|
2009-02-27 10:45:21 +00:00
|
|
|
for (var idx = 0; idx < this.mEventSeq.length; idx++) {
|
|
|
|
var eventType = this.getEventType(idx);
|
2009-08-21 13:20:18 +00:00
|
|
|
if (typeof eventType == "string") {
|
|
|
|
// DOM event
|
|
|
|
var target = this.getEventTarget(idx);
|
|
|
|
var phase = this.getEventPhase(idx);
|
|
|
|
target.ownerDocument.removeEventListener(eventType, this, phase);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// A11y event
|
2009-02-27 10:45:21 +00:00
|
|
|
removeA11yEventListener(eventType, this);
|
2009-08-21 13:20:18 +00:00
|
|
|
}
|
2009-02-27 10:45:21 +00:00
|
|
|
}
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
this.mEventSeq = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-27 10:45:21 +00:00
|
|
|
this.getEventType = function eventQueue_getEventType(aIdx)
|
|
|
|
{
|
2009-07-28 02:28:06 +00:00
|
|
|
return this.mEventSeq[aIdx].type;
|
2009-02-27 10:45:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.getEventTarget = function eventQueue_getEventTarget(aIdx)
|
|
|
|
{
|
2009-07-28 02:28:06 +00:00
|
|
|
return this.mEventSeq[aIdx].target;
|
2009-02-27 10:45:21 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 06:45:19 +00:00
|
|
|
this.getEventPhase = function eventQueue_getEventPhase(aIdx)
|
|
|
|
{
|
|
|
|
var eventItem = this.mEventSeq[aIdx];
|
|
|
|
if ("phase" in eventItem)
|
|
|
|
return eventItem.phase;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-02-27 10:45:21 +00:00
|
|
|
this.compareEvents = function eventQueue_compareEvents(aIdx, aEvent)
|
|
|
|
{
|
|
|
|
var eventType1 = this.getEventType(aIdx);
|
|
|
|
|
|
|
|
var eventType2 = (aEvent instanceof nsIDOMEvent) ?
|
|
|
|
aEvent.type : aEvent.eventType;
|
|
|
|
|
|
|
|
if (eventType1 != eventType2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var target1 = this.getEventTarget(aIdx);
|
|
|
|
if (target1 instanceof nsIAccessible) {
|
|
|
|
var target2 = (aEvent instanceof nsIDOMEvent) ?
|
|
|
|
getAccessible(aEvent.target) : aEvent.accessible;
|
|
|
|
|
|
|
|
return target1 == target2;
|
|
|
|
}
|
|
|
|
|
2009-05-11 01:32:09 +00:00
|
|
|
// If original target isn't suitable then extend interface to support target
|
|
|
|
// (original target is used in test_elm_media.html).
|
2009-02-27 10:45:21 +00:00
|
|
|
var target2 = (aEvent instanceof nsIDOMEvent) ?
|
2009-05-11 01:32:09 +00:00
|
|
|
aEvent.originalTarget : aEvent.DOMNode;
|
2009-02-27 10:45:21 +00:00
|
|
|
return target1 == target2;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.checkEvent = function eventQueue_checkEvent(aIdx, aEvent)
|
|
|
|
{
|
|
|
|
var eventItem = this.mEventSeq[aIdx];
|
|
|
|
if ("check" in eventItem)
|
|
|
|
eventItem.check(aEvent);
|
|
|
|
|
|
|
|
var invoker = this.getInvoker();
|
|
|
|
if ("check" in invoker)
|
|
|
|
invoker.check(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getEventID = function eventQueue_getEventID(aIdx)
|
|
|
|
{
|
|
|
|
var eventItem = this.mEventSeq[aIdx];
|
|
|
|
if ("getID" in eventItem)
|
|
|
|
return eventItem.getID();
|
|
|
|
|
|
|
|
var invoker = this.getInvoker();
|
|
|
|
return invoker.getID();
|
|
|
|
}
|
|
|
|
|
2009-08-20 06:45:19 +00:00
|
|
|
this.dumpEventToDOM = function eventQueue_dumpEventToDOM(aOrigEvent,
|
|
|
|
aExpectedEventIdx,
|
|
|
|
aMatch)
|
|
|
|
{
|
|
|
|
if (!gA11yEventDumpID) // debug stuff
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Dump DOM event information. Skip a11y event since it is dumped by
|
|
|
|
// gA11yEventObserver.
|
|
|
|
if (aOrigEvent instanceof nsIDOMEvent) {
|
|
|
|
var info = "Event type: " + aOrigEvent.type;
|
|
|
|
info += ". Target: " + prettyName(aOrigEvent.originalTarget);
|
|
|
|
dumpInfoToDOM(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
var currType = this.getEventType(aExpectedEventIdx);
|
|
|
|
var currTarget = this.getEventTarget(aExpectedEventIdx);
|
|
|
|
|
|
|
|
var info = "EQ: " + (aMatch ? "matched" : "expected") + " event, type: ";
|
|
|
|
info += (typeof currType == "string") ?
|
|
|
|
currType : eventTypeToString(currType);
|
|
|
|
info += ". Target: " + prettyName(currTarget);
|
|
|
|
|
|
|
|
dumpInfoToDOM(info);
|
|
|
|
}
|
|
|
|
|
2009-01-25 04:42:21 +00:00
|
|
|
this.mDefEventType = aEventType;
|
|
|
|
|
|
|
|
this.mInvokers = new Array();
|
|
|
|
this.mIndex = -1;
|
|
|
|
|
|
|
|
this.mEventSeq = null;
|
|
|
|
this.mEventSeqIdx = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private implementation details.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// General
|
|
|
|
|
|
|
|
var gObserverService = null;
|
|
|
|
|
|
|
|
var gA11yEventListeners = {};
|
|
|
|
var gA11yEventApplicantsCount = 0;
|
|
|
|
|
|
|
|
var gA11yEventObserver =
|
|
|
|
{
|
|
|
|
observe: function observe(aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
if (aTopic != "accessible-event")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var event = aSubject.QueryInterface(nsIAccessibleEvent);
|
|
|
|
var listenersArray = gA11yEventListeners[event.eventType];
|
|
|
|
|
|
|
|
if (gA11yEventDumpID) { // debug stuff
|
|
|
|
var target = event.DOMNode;
|
2009-02-05 06:23:18 +00:00
|
|
|
var dumpElm = document.getElementById(gA11yEventDumpID);
|
2009-01-25 04:42:21 +00:00
|
|
|
|
|
|
|
var parent = target;
|
|
|
|
while (parent && parent != dumpElm)
|
|
|
|
parent = parent.parentNode;
|
|
|
|
|
|
|
|
if (parent != dumpElm) {
|
2009-02-27 10:45:21 +00:00
|
|
|
var type = eventTypeToString(event.eventType);
|
|
|
|
var info = "Event type: " + type;
|
|
|
|
info += ". Target: " + prettyName(event.accessible);
|
2009-01-25 04:42:21 +00:00
|
|
|
|
2009-02-05 06:23:18 +00:00
|
|
|
if (listenersArray)
|
|
|
|
info += ". Listeners count: " + listenersArray.length;
|
|
|
|
|
|
|
|
dumpInfoToDOM(info);
|
2009-01-25 04:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!listenersArray)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (var index = 0; index < listenersArray.length; index++)
|
|
|
|
listenersArray[index].handleEvent(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function listenA11yEvents(aStartToListen)
|
|
|
|
{
|
|
|
|
if (aStartToListen && !gObserverService) {
|
|
|
|
gObserverService = Components.classes["@mozilla.org/observer-service;1"].
|
|
|
|
getService(nsIObserverService);
|
|
|
|
|
|
|
|
gObserverService.addObserver(gA11yEventObserver, "accessible-event",
|
|
|
|
false);
|
|
|
|
} else if (!gA11yEventApplicantsCount) {
|
|
|
|
gObserverService.removeObserver(gA11yEventObserver,
|
|
|
|
"accessible-event");
|
|
|
|
gObserverService = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addA11yEventListener(aEventType, aEventHandler)
|
|
|
|
{
|
|
|
|
if (!(aEventType in gA11yEventListeners))
|
|
|
|
gA11yEventListeners[aEventType] = new Array();
|
|
|
|
|
|
|
|
gA11yEventListeners[aEventType].push(aEventHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeA11yEventListener(aEventType, aEventHandler)
|
|
|
|
{
|
|
|
|
var listenersArray = gA11yEventListeners[aEventType];
|
|
|
|
if (!listenersArray)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var index = listenersArray.indexOf(aEventHandler);
|
|
|
|
if (index == -1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
listenersArray.splice(index, 1);
|
|
|
|
|
|
|
|
if (!listenersArray.length) {
|
|
|
|
gA11yEventListeners[aEventType] = null;
|
|
|
|
delete gA11yEventListeners[aEventType];
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-02-05 06:23:18 +00:00
|
|
|
|
2009-05-11 01:32:09 +00:00
|
|
|
/**
|
|
|
|
* Dumps message to DOM.
|
|
|
|
*
|
|
|
|
* @param aInfo [in] the message to dump
|
|
|
|
* @param aDumpNode [in, optional] host DOM node for dumped message, if ommited
|
|
|
|
* then global variable gA11yEventDumpID is used
|
|
|
|
*/
|
|
|
|
function dumpInfoToDOM(aInfo, aDumpNode)
|
2009-02-05 06:23:18 +00:00
|
|
|
{
|
2009-05-11 01:32:09 +00:00
|
|
|
var dumpID = gA11yEventDumpID ? gA11yEventDumpID : aDumpNode;
|
|
|
|
if (!dumpID)
|
2009-02-19 07:06:14 +00:00
|
|
|
return;
|
|
|
|
|
2009-05-11 01:32:09 +00:00
|
|
|
var dumpElm = document.getElementById(dumpID);
|
2009-02-27 10:45:21 +00:00
|
|
|
|
|
|
|
var containerTagName = document instanceof nsIDOMHTMLDocument ?
|
|
|
|
"div" : "description";
|
|
|
|
var container = document.createElement(containerTagName);
|
|
|
|
|
|
|
|
container.textContent = aInfo;
|
|
|
|
dumpElm.appendChild(container);
|
2009-02-05 06:23:18 +00:00
|
|
|
}
|