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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to