}
}
private static EventListenerRemover addEventListeners() {
final JSOArray<Handler> stack = JSOArray.create();
final EventListenerRemover downRemover = Event.addEventListener(
KeyDownEvent.NAME, Document.get(), new EventListener() {
public void handleEvent(Event event) {
final Data data = handlers.get(event.getKeyCode());
if (data == null || !event.getCtrlKey()) {
return;
}
Handler handler = data.getHandler();
handler.onKeyDown(new KeyDownEvent(handler, event));
stack.push(handler);
event.preventDefault();
}
});
final EventListenerRemover upRemover = Event.addEventListener(
KeyUpEvent.NAME, Document.get(), new EventListener() {
public void handleEvent(Event event) {
if (stack.peek() == null) {
return;
}
final Handler handler = stack.pop();
handler.onKeyUp(new KeyUpEvent(handler, event));
}
});
return new EventListenerRemover() {
public void remove() {
downRemover.remove();
upRemover.remove();
}
};
}