Re: jsinterop with browser-specific api

2016-09-12 Thread Thomas Broyer
I suppose it'll eventually be in a jsinterop util class but for now you 
have to use JSNI: https://github.com/gwtproject/gwt/issues/9364

On Monday, September 12, 2016 at 11:03:31 PM UTC+2, Zufar Fakhurtdinov 
wrote:
>
> Thank you for answer! Writing it by hand is annoying, but maybe later it 
> will be generated.
> Maybe you know.. How can I use 'in' operator?
>
> protected static native boolean pointerLockSupported() /*-{
>   return 'pointerLockElement' in $wnd.document ||
>   'mozPointerLockElement' in $wnd.document ||
>   'webkitPointerLockElement' in $wnd.document;
> }-*/;
>
>

-- 
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+unsubscr...@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.


Re: jsinterop with browser-specific api

2016-09-12 Thread Zufar Fakhurtdinov
Thank you for answer! Writing it by hand is annoying, but maybe later it 
will be generated.
Maybe you know.. How can I use 'in' operator?

protected static native boolean pointerLockSupported() /*-{
  return 'pointerLockElement' in $wnd.document ||
  'mozPointerLockElement' in $wnd.document ||
  'webkitPointerLockElement' in $wnd.document;
}-*/;

-- 
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+unsubscr...@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.


Re: jsinterop with browser-specific api

2016-09-10 Thread Thomas Broyer
Actually, in this case, you could also do it like this:

@JsOverlay
public void exitFullScreen() {
  ExitFullScreen exitFullScreen = getExitFullScreen();
  if (exitFullScreen == null) {
exitFullScreen = getWebkitExitFullscreen();
if (exitFullScreen == null) {
  exitFullScreen = getMozCancelFullScreen();
  if (exitFullScreen == null) {
exitFullScreen = getMsExitFullscreen();
if (exitFullScreen == null) {
  throw new UnsupportedOperationException();
}
  }
}
  }
  exitFullScreen.justDoIt();
}

@JsFunction
interface ExitFullScreen {
  void justDoIt();
}

@JsProperty(name = "exitFullScreen") private 
native ExitFullScreen getExitFullScreen();
@JsProperty(name = "webkitExitFullscreen") private 
native ExitFullScreen getWebkitExitFullscreen();
@JsProperty(name = "mozCancelFullScreen") private 
native ExitFullScreen getMozCancelFullScreen();
@JsProperty(name = "msExitFullscreen") private 
native ExitFullScreen getMsExitFullscreen();


On Friday, September 9, 2016 at 11:16:05 PM UTC+2, Thomas Broyer wrote:
>
>
> On Friday, September 9, 2016 at 8:32:08 PM UTC+2, Zufar Fakhurtdinov wrote:
>>
>> Hi all. I'm trying to understand how can I effective work with jsinterop 
>> and browser-specific api.
>> For example Fullscreen api is mostly work in latest browsers, but methods 
>> are prefixed.
>>
>> Before jsinterop I was write something like this:
>>
>>
>> public static native void leaveFullscreen() /*-{
>>   if ($doc.cancelFullscreen) {
>> $doc.cancelFullscreen();
>>   } else if ($doc.mozCancelFullScreen) {
>> $doc.mozCancelFullScreen();
>>   } else if ($doc.webkitCancelFullScreen) {
>> $doc.webkitCancelFullScreen();
>>   }
>>
>> }-*/; 
>>
>> What should I do now? Add mozCancelFullScreen, webkitCancelFullScreen 
>> methods to my jsinteropped Document interface? And then add static jsni 
>> method 
>> boolean exists(Object a)/*-{return a;}-*/; and add java method with "if 
>> (exists(..))"  chain. 
>> It looks very verbose and inefficiently.
>>
>
> Have a look at https://github.com/gwtproject/gwt/issues/9327
>
> I'd do it like:
>
> @JsOverlay
> public void exitFullScreen() {
>   if (getExitFullScreen() != null) {
> nativeExitFullScreen();
>   } else if (getMozCancelFullScreen() != null) {
> mozCancelFullScreen();
>   } else if (getWebkitExitFullscreen() != null) {
> webkitExitFullscreen();
>   } else if (getMsExitFullscreen() != null) {
> msExitFullscreen();
>   } else {
> throw new UnsupportedOperationException();
>   }
> }
>
> @JsMethod(name = "exitFullScreen") private native void 
> nativeExitFullScreen();
> @JsProperty(name = "exitFullScreen") private native Object 
> getExitFullScreen();
> @JsMethod private native void webkitExitFullscreen();
> @JsProperty(name = "webkitExitFullscreen") private native Object 
> getWebkitExitFullscreen();
> @JsMethod private native void mozCancelFullScreen();
> @JsProperty(name = "mozCancelFullScreen") private native Object 
> getMozCancelFullScreen();
> @JsMethod private native void msExitFullscreen();
> @JsProperty(name = "msExitFullscreen") private native Object 
> getMsExitFullscreen();
>
> It's a bit verbose in the method declarations (but the idea of JsInterop 
> is that this could be somehow generated; 
> https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API has the 
> info in wiki format, there probably is a machine-readable format somewhere, 
> from Closure externs 
> <https://github.com/google/closure-compiler/blob/cf3c1f5ba45d3154c80ce5eecbec45549e8641f6/externs/browser/html5.js#L3125-L3213>
>  
> or DefinitelyTyped; an equivalence table like in the MDN wiki could even 
> allow generating that @JsOverlay method),
> but the if-cascade is otherwise the same as the original JSNI method.
>

-- 
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+unsubscr...@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.


Re: jsinterop with browser-specific api

2016-09-09 Thread Thomas Broyer

On Friday, September 9, 2016 at 8:32:08 PM UTC+2, Zufar Fakhurtdinov wrote:
>
> Hi all. I'm trying to understand how can I effective work with jsinterop 
> and browser-specific api.
> For example Fullscreen api is mostly work in latest browsers, but methods 
> are prefixed.
>
> Before jsinterop I was write something like this:
>
>
> public static native void leaveFullscreen() /*-{
>   if ($doc.cancelFullscreen) {
> $doc.cancelFullscreen();
>   } else if ($doc.mozCancelFullScreen) {
> $doc.mozCancelFullScreen();
>   } else if ($doc.webkitCancelFullScreen) {
> $doc.webkitCancelFullScreen();
>   }
>
> }-*/; 
>
> What should I do now? Add mozCancelFullScreen, webkitCancelFullScreen 
> methods to my jsinteropped Document interface? And then add static jsni 
> method 
> boolean exists(Object a)/*-{return a;}-*/; and add java method with "if 
> (exists(..))"  chain. 
> It looks very verbose and inefficiently.
>

Have a look at https://github.com/gwtproject/gwt/issues/9327

I'd do it like:

@JsOverlay
public void exitFullScreen() {
  if (getExitFullScreen() != null) {
nativeExitFullScreen();
  } else if (getMozCancelFullScreen() != null) {
mozCancelFullScreen();
  } else if (getWebkitExitFullscreen() != null) {
webkitExitFullscreen();
  } else if (getMsExitFullscreen() != null) {
msExitFullscreen();
  } else {
throw new UnsupportedOperationException();
  }
}

@JsMethod(name = "exitFullScreen") private native void 
nativeExitFullScreen();
@JsProperty(name = "exitFullScreen") private native Object 
getExitFullScreen();
@JsMethod private native void webkitExitFullscreen();
@JsProperty(name = "webkitExitFullscreen") private native Object 
getWebkitExitFullscreen();
@JsMethod private native void mozCancelFullScreen();
@JsProperty(name = "mozCancelFullScreen") private native Object 
getMozCancelFullScreen();
@JsMethod private native void msExitFullscreen();
@JsProperty(name = "msExitFullscreen") private native Object 
getMsExitFullscreen();

It's a bit verbose in the method declarations (but the idea of JsInterop is 
that this could be somehow 
generated; https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API 
has the info in wiki format, there probably is a machine-readable format 
somewhere, from Closure externs 
<https://github.com/google/closure-compiler/blob/cf3c1f5ba45d3154c80ce5eecbec45549e8641f6/externs/browser/html5.js#L3125-L3213>
 
or DefinitelyTyped; an equivalence table like in the MDN wiki could even 
allow generating that @JsOverlay method),
but the if-cascade is otherwise the same as the original JSNI method.

-- 
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+unsubscr...@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.


jsinterop with browser-specific api

2016-09-09 Thread Kirill Prazdnikov
Doing the same

-- 
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+unsubscr...@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.


jsinterop with browser-specific api

2016-09-09 Thread Kirill Prazdnikov
But above sample doing the name. Or you can create a baseclss and  3 impl and 
instantiate the correct one.

-- 
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+unsubscr...@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.


jsinterop with browser-specific api

2016-09-09 Thread Zufar Fakhurtdinov
Hi all. I'm trying to understand how can I effective work with jsinterop 
and browser-specific api.
For example Fullscreen api is mostly work in latest browsers, but methods 
are prefixed.

Before jsinterop I was write something like this:


public static native void leaveFullscreen() /*-{
  if ($doc.cancelFullscreen) {
$doc.cancelFullscreen();
  } else if ($doc.mozCancelFullScreen) {
$doc.mozCancelFullScreen();
  } else if ($doc.webkitCancelFullScreen) {
$doc.webkitCancelFullScreen();
  }

}-*/; 

What should I do now? Add mozCancelFullScreen, webkitCancelFullScreen 
methods to my jsinteropped Document interface? And then add static jsni 
method 
boolean exists(Object a)/*-{return a;}-*/; and add java method with "if 
(exists(..))"  chain. 
It looks very verbose and inefficiently.

-- 
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+unsubscr...@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.