in view/src/main/java/jetbrains/jetpad/projectional/view/toGwt/ViewContainerToElementMapper.java [136:301]
private void registerListeners(SynchronizersConfiguration conf) {
final Value<Boolean> pressed = new Value<>(false);
final Value<Boolean> pressedOutside = new Value<>(false);
conf.add(Synchronizers.forRegistration(new Supplier<Registration>() {
@Override
public Registration get() {
CompositeRegistration reg = new CompositeRegistration();
reg.add(eventRegistration(Event.ONMOUSEDOWN, myRootDiv, new Function() {
@Override
public boolean f(Event e) {
myRootDiv.focus();
MouseEvent me = toMouseEvent(e);
if (isDomViewEvent(me)) return true;
pressed.set(true);
getSource().mousePressed(me);
pressedOutside.set(false);
return false;
}
}));
reg.add(eventRegistration(Event.ONMOUSEDOWN, Document.get(), new Function() {
@Override
public boolean f(Event e) {
pressed.set(true);
MouseEvent evt = toMouseEvent(e);
if (!isContainerEvent(evt)) {
pressedOutside.set(true);
}
return true;
}
}));
reg.add(eventRegistration(Event.ONMOUSEUP, Document.get(), new Function() {
@Override
public boolean f(Event e) {
pressed.set(false);
pressedOutside.set(false);
return true;
}
}));
reg.add(eventRegistration(Event.ONMOUSEUP, myRootDiv, new Function() {
@Override
public boolean f(Event e) {
pressed.set(false);
MouseEvent me = toMouseEvent(e);
if (isDomViewEvent(me)) return true;
getSource().mouseReleased(me);
return false;
}
}));
reg.add(eventRegistration(Event.ONMOUSEMOVE, Document.get(), new Function() {
@Override
public boolean f(Event e) {
MouseEvent evt = toMouseEvent(e);
if (pressed.get() && !pressedOutside.get()) {
getSource().mouseDragged(evt);
}
return true;
}
}));
reg.add(eventRegistration(Event.ONMOUSEMOVE, myRootDiv, new Function() {
@Override
public boolean f(Event e) {
MouseEvent evt = toMouseEvent(e);
if (pressed.get() && !pressedOutside.get()) {
getSource().mouseDragged(evt);
} else {
getSource().mouseMoved(evt);
}
return true;
}
}));
reg.add(eventRegistration(Event.ONMOUSEOVER, myRootDiv, new Function() {
@Override
public boolean f(Event e) {
MouseEvent me = toMouseEvent(e);
getSource().mouseEntered(me);
return false;
}
}));
reg.add(eventRegistration(Event.ONMOUSEOUT, myRootDiv, new Function() {
@Override
public boolean f(Event e) {
getSource().mouseLeft(toMouseEvent(e));
return false;
}
}));
final ClipboardSupport clipboardSupport = new ClipboardSupport(myRootDiv);
reg.add(eventRegistration(Event.ONKEYDOWN, myRootDiv, new Function() {
@Override
public boolean f(Event e) {
return EventTranslator.dispatchKeyPress(e, new Handler<KeyEvent>() {
@Override
public void handle(final KeyEvent e) {
if (e.is(Key.SPACE)) {
getSource().keyPressed(e);
getSource().keyTyped(new KeyEvent(Key.SPACE, ' ', Collections.<ModifierKey>emptySet()));
return;
}
if (e.is(KeyStrokeSpecs.PASTE)) {
clipboardSupport.pasteContent(new Handler<String>() {
@Override
public void handle(String text) {
if (Strings.isNullOrEmpty(text)) {
getSource().keyPressed(e.copy());
} else {
getSource().paste(new PasteEvent(TextContentHelper.createClipboardContent(text)));
}
}
});
return;
}
if (e.is(KeyStrokeSpecs.COPY) || e.is(KeyStrokeSpecs.CUT)) {
CopyCutEvent copyEvent;
if (e.is(KeyStrokeSpecs.CUT)) {
getSource().cut(copyEvent = new CopyCutEvent(true));
} else {
getSource().copy(copyEvent = new CopyCutEvent(false));
}
ClipboardContent content = copyEvent.getResult();
if (content != null) {
clipboardSupport.copyContent(content);
}
return;
}
getSource().keyPressed(e);
}
});
}
}));
reg.add(eventRegistration(Event.ONKEYUP, myRootDiv, new Function() {
@Override
public boolean f(Event e) {
return EventTranslator.dispatchKeyRelease(e, new Handler<KeyEvent>() {
@Override
public void handle(KeyEvent e) {
getSource().keyReleased(e);
}
});
}
}));
reg.add(eventRegistration(Event.ONKEYPRESS, myRootDiv, new Function() {
@Override
public boolean f(Event e) {
return EventTranslator.dispatchKeyType(e, new Handler<KeyEvent>() {
@Override
public void handle(KeyEvent e) {
//Space is a special key in Chrome. We emulate its typing in keydown
if (e.getKeyChar() == ' ') return;
getSource().keyTyped(e);
}
});
}
}));
return reg;
}
}));
}