/**
* {@inheritDoc}
*/
public void onJavaScriptEvent(String name, Event rawEvent) {
double processTiming = 0;
Duration instrumentedDuration = null;
// These events should never be stopped by the editor since other handlers
// rely on getting to handle them.
// TODO(danilatos): clean this mess up.
boolean hackEditorNeverConsumes = name.equals("contextmenu") || name.equals("click")
|| name.equals("mousedown");
try {
EditorEvent event = SignalEventImpl.create(EditorEventImpl.FACTORY,
rawEvent, !hackEditorNeverConsumes);
try {
if (UserAgent.isMac() &&
rawEvent.getCtrlKey() && rawEvent.getAltKey()
&& rawEvent.getTypeInt() == Event.ONKEYPRESS) {
// In mac safari, Ctrl+Alt+something often inserts weird invisible
// characters in the dom!!! Always cancel the event, no matter what
// (We can still handle it programmatically if we wish)
// Cancel for FF as well just in case - but if this causes an issue
// it should be OK to enable for FF. We get keypress events, but
// no dom munge.
// Don't cancel it on Windows, because that prevents AltGr combos
// from working in european languages
EditorStaticDeps.logger.trace().log("Cancelling dangerous: " + rawEvent.getType());
rawEvent.preventDefault();
}
} catch (JavaScriptException e) {
// If this fails, swallow it. Seems to cause issues with dom mutation
// events when setting contentEditable with JUnit tests.
}
if (event == null) {
if (!hackEditorNeverConsumes) {
try {
rawEvent.stopPropagation();
} catch (JavaScriptException e) {
// If this fails, swallow it. Seems to cause issues with dom mutation
// events when setting contentEditable with JUnit tests.
}
}
return;
}
boolean cancel = false;
if (!hackEditorNeverConsumes) {
if (editorRelevantEvent(event)) {
try {
event.stopPropagation();
} catch (JavaScriptException e) {
// If this fails, swallow it. Seems to cause issues with dom mutation
// events when setting contentEditable with JUnit tests.
}
} else {
return;
}
}
boolean isMutationEvent = event.isMutationEvent();
if (!isMutationEvent || !EditorStaticDeps.shouldIgnoreMutations()) {
EditorStaticDeps.startIgnoreMutations();
try {
if (debugDisabled) {
cancel = false;
} else if (!canHandleBrowserEvents()) {
// If we're too busy for it to be safe to do anything at all,
// we cancel the event altogether
EditorStaticDeps.logger.trace().log("Too busy to handle: ", event);
cancel = true;
} else {
// Cache the selection across multiple calls to Selection.get(), for the
// duration of this event handler. We turn caching off again in the finally
// block below.
NativeSelectionUtil.cacheOn();
// Normal event handling
responsibility.startDirectSequence();
try {
if (settings.getInstrumentor().shouldInstrument(event)) {
Duration timer = new Duration();
cancel = eventHandler.handleEvent(event);
processTiming = timer.elapsedMillis();
instrumentedDuration = new Duration();
} else {
cancel = eventHandler.handleEvent(event);
}
} finally {
responsibility.endDirectSequence();