GreetingsI am trying to get a DOMRect from an Element. I can do this with JSNI, but have been unable to make a JsInterop version. Here's what I have:public final class DOMRect extends JavaScriptObject{// returns DOMRect or nullpublic static native DOMRect getBoundingClientRect(Element element)/*-{return element.getBoundingClientRect && element.getBoundingClientRect();}-*/;protected DOMRect(){}public final native double getX()/*-{return this.x;}-*/;// etc.}I can make a JsType for DOMRect, no problem. The issue I'm having is with getBoundingClientRect(). This function may not exist which is why there is a null check.
@JsType(isNative=true, namespace=JsPackage.GLOBAL, name="Element")
class Element {
@JsProperty(name="getBoundingClientRect") private native Object getGetBoundingClientRect();
@JsMethod(name="getBoundingClientRect") private native DOMRect callGetBoundingClientRect();
@JsOverlay
public DOMRect getBoundingClientRect() {
return getGetBoundingClientRect() == null ? null : callGetBoundingClientRect();
}
}@JsType(isNative=true, namespace=JsPackage.GLOBAL, name="Element")
class Element {
@JsProperty(name="getBoundingClientRect") public native GetBoundingClientRect getBoundingClientRect();
@JsFunction
interface GetBoundingClientRect {
public DOMRect invoke();
}
}If I make an interface for getBoundingClientRect, I'm not allowed to cast Element to implement it.
((HasGetBoundingClientRect) (Object) elt).getBoundingClientRect()I can't extend Element, either. With JSNI, I am allowed to compile Javascript into Javascript, but I can't with JsInterop. It seems like a lot of trouble for 1 line of Javascript.How can I do this? Thanks in advance...
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
Amazing trick!Obvious if you think about it - but very difficult to think it initially (for us mere mortals).