throw createEventException
(DOMException.NOT_SUPPORTED_ERR,
"unsupported.event",
new Object[] {});
}
AbstractEvent e = (AbstractEvent) evt;
String type = e.getType();
if (type == null || type.length() == 0) {
throw createEventException
(EventException.UNSPECIFIED_EVENT_TYPE_ERR,
"unspecified.event",
new Object[] {});
}
// fix event status
setTarget(e, target);
stopPropagation(e, false);
stopImmediatePropagation(e, false);
preventDefault(e, false);
// dump the tree hierarchy from top to the target
NodeEventTarget[] ancestors = getAncestors(target);
int bubbleLimit = e.getBubbleLimit();
int minAncestor = 0;
if (isSingleScopeEvent(e)) {
// DOM Mutation events are dispatched only within the
// one shadow scope
AbstractNode targetNode = (AbstractNode) target;
Node boundElement = targetNode.getXblBoundElement();
if (boundElement != null) {
minAncestor = ancestors.length;
while (minAncestor > 0) {
AbstractNode ancestorNode =
(AbstractNode) ancestors[minAncestor - 1];
if (ancestorNode.getXblBoundElement() != boundElement) {
break;
}
minAncestor--;
}
}
} else if (bubbleLimit != 0) {
// Other events may have a bubble limit (such as UI events)
minAncestor = ancestors.length - bubbleLimit + 1;
if (minAncestor < 0) {
minAncestor = 0;
}
}
// System.err.println("\t== ancestors:");
// for (int i = 0; i < ancestors.length; i++) {
// if (i < minAncestor) {
// System.err.print("\t ");
// } else {
// System.err.print("\t * ");
// }
// System.err.println(((Node) ancestors[i]).getNodeName());
// }
AbstractEvent[] es = getRetargettedEvents(target, ancestors, e);
boolean preventDefault = false;
// CAPTURING_PHASE : fire event listeners from top to EventTarget
HashSet stoppedGroups = new HashSet();
HashSet toBeStoppedGroups = new HashSet();
for (int i = 0; i < minAncestor; i++) {
NodeEventTarget node = ancestors[i];
// System.err.println("\t-- CAPTURING " + e.getType() + " " + ((Node) node).getNodeName());
setCurrentTarget(es[i], node);
setEventPhase(es[i], Event.CAPTURING_PHASE);
fireImplementationEventListeners(node, es[i], true);
}
for (int i = minAncestor; i < ancestors.length; i++) {
NodeEventTarget node = ancestors[i];
// System.err.println("\t-- * CAPTURING " + e.getType() + " " + ((Node) node).getNodeName());
setCurrentTarget(es[i], node);
setEventPhase(es[i], Event.CAPTURING_PHASE);
fireImplementationEventListeners(node, es[i], true);
fireEventListeners(node, es[i], true, stoppedGroups,
toBeStoppedGroups);
fireHandlerGroupEventListeners(node, es[i], true, stoppedGroups,
toBeStoppedGroups);
preventDefault = preventDefault || es[i].getDefaultPrevented();
stoppedGroups.addAll(toBeStoppedGroups);
toBeStoppedGroups.clear();
}
// AT_TARGET : fire local event listeners
// System.err.println("\t-- * AT_TARGET " + e.getType() + " " + ((Node) target).getNodeName());
setEventPhase(e, Event.AT_TARGET);
setCurrentTarget(e, target);
fireImplementationEventListeners(target, e, false);
fireEventListeners(target, e, false, stoppedGroups,
toBeStoppedGroups);
fireHandlerGroupEventListeners(node, e, false, stoppedGroups,
toBeStoppedGroups);
stoppedGroups.addAll(toBeStoppedGroups);
toBeStoppedGroups.clear();
preventDefault = preventDefault || e.getDefaultPrevented();
// BUBBLING_PHASE : fire event listeners from target to top
if (e.getBubbles()) {
for (int i = ancestors.length - 1; i >= minAncestor; i--) {
NodeEventTarget node = ancestors[i];
// System.err.println("\t-- * BUBBLING " + e.getType() + " " + ((Node) node).getNodeName());
setCurrentTarget(es[i], node);
setEventPhase(es[i], Event.BUBBLING_PHASE);