Example usage for com.google.gwt.dom.client SpanElement getAbsoluteTop

List of usage examples for com.google.gwt.dom.client SpanElement getAbsoluteTop

Introduction

In this page you can find the example usage for com.google.gwt.dom.client SpanElement getAbsoluteTop.

Prototype

@Override
    public int getAbsoluteTop() 

Source Link

Usage

From source file:org.rstudio.core.client.dom.impl.DomUtilsStandardImpl.java

License:Open Source License

public Rectangle getCursorBounds(Document doc) {

    Selection sel = Selection.get(NativeWindow.get(doc));
    Range selRng = sel.getRangeAt(0);/*from  w ww  .j av  a2  s . c o  m*/
    if (selRng == null)
        return null;
    sel.removeAllRanges();
    SpanElement span = doc.createSpanElement();

    Range rng = selRng.cloneRange();
    rng.collapse(true);
    rng.insertNode(span);

    int x = span.getAbsoluteLeft();
    int y = span.getAbsoluteTop();
    int w = 0;
    int h = span.getOffsetHeight();
    Rectangle result = new Rectangle(x, y, w, h);

    ElementEx parent = (ElementEx) span.getParentElement();
    parent.removeChild(span);
    parent.normalize();
    sel.setRange(selRng);
    return result;
}