in cell/src/main/java/jetbrains/jetpad/cell/toDom/CellContainerToDomMapper.java [338:437]
private CellContainerPeer createCellContainerPeer() {
return new CellContainerPeer() {
@Override
public int getCaretAt(TextCell tv, int x) {
TextCellMapper textMapper = (TextCellMapper) getMapper(tv);
if (textMapper == null) {
throw new IllegalStateException("Can't find a mapper for " + tv);
}
return textMapper.getCaretAt(x);
}
@Override
public int getCaretOffset(TextCell tv, int caret) {
TextCellMapper textMapper = (TextCellMapper) getMapper(tv);
if (textMapper == null) {
throw new IllegalStateException("Can't find a mapper for " + tv);
}
return textMapper.getCaretOffset(caret);
}
@Override
public Rectangle getBounds(Cell cell) {
Rectangle result = getBaseBounds(cell);
if (result == null) {
result = new Rectangle(Vector.ZERO, Vector.ZERO);
}
return result;
}
private Rectangle getBaseBounds(Cell cell) {
Mapper<? extends Cell, ? extends Element> mapper = getMapper(cell);
if (mapper == null) {
if (cell instanceof NewLineCell) {
return null;
} else if (cell instanceof IndentCell) {
return Cells.indentBounds((IndentCell) cell);
} else {
throw new IllegalStateException("Can't find a mapper for " + cell);
}
} else {
Element target = getElement(cell);
if (cell instanceof ScrollCell) {
return new Rectangle(
target.getAbsoluteLeft(),
target.getAbsoluteRight(),
target.getOffsetWidth(),
target.getOffsetHeight()
);
} else {
return new Rectangle(
target.getAbsoluteLeft(),
target.getAbsoluteTop(),
target.getScrollWidth(),
target.getScrollHeight());
}
}
}
@Override
public void scrollTo(Rectangle rect, Cell cell) {
Scrolling.scrollTo(rect, getElement(cell));
}
@Override
public Cell findCell(Cell root, Vector loc) {
Element e = elementAt(loc.x - myScrollLeft, loc.y - myScrollTop);
if (e == null) return null;
Cell result = findCellFor(e);
if (result == null) return null;
if (Composites.isDescendant(root, result)) {
return result;
}
return null;
}
private native Element elementAt(int x, int y) /*-{
return $doc.elementFromPoint(x, y);
}-*/;
@Override
public Rectangle visibleRect() {
return DomUtil.visiblePart(getTarget());
}
@Override
public void requestFocus() {
getFocusTarget().focus();
}
@Override
public ReadableProperty<Boolean> focused() {
return myCellToDomContext.focused;
}
@Override
public EventDispatchThread getEdt() {
return JsEventDispatchThread.INSTANCE;
}
};
}