package com.akjava.gwt.html5.client.pointerlock;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.RootPanel;

public class PointerLock {

	public final static  native boolean havePointerLock()/*-{
	return 'pointerLockElement' in $wnd.document || 'mozPointerLockElement' in $wnd.document || 'webkitPointerLockElement' in $wnd.document;
	}-*/;
	
	public final static  native boolean isPointerLockElement(Element element)/*-{
	//	console.log($wnd.document.pointerLockElement);
	return $wnd.document.pointerLockElement === element || $wnd.document.mozPointerLockElement === element || $wnd.document.webkitPointerLockElement === element;
	}-*/;
	
	public final static  native boolean isPointerLock()/*-{
	//	console.log($wnd.document.pointerLockElement);
	return $wnd.document.pointerLockElement  || $wnd.document.mozPointerLockElement || $wnd.document.webkitPointerLockElement ;
	}-*/;
	
	public final static  native boolean requestPointerLock(Element element)/*-{
	element.requestPointerLock();
	}-*/;
	
	public final static void addPointerLockChange(PointerLockListener listener){
		_addPointerLockChange(wrapPointerLockListener(listener));
	}
	
	private final static  native void _addPointerLockChange(JavaScriptObject jsfunction)/*-{
				$wnd.document.addEventListener( 'pointerlockchange', jsfunction, false );
				$wnd.document.addEventListener( 'mozpointerlockchange', jsfunction, false );
				$wnd.document.addEventListener( 'webkitpointerlockchange', jsfunction, false );
	}-*/;
	
	public static interface PointerLockListener {
	    void pointerLockChanged(NativeEvent event);
	}
	
	private native static JavaScriptObject wrapPointerLockListener(PointerLockListener callback) /*-{
    return function(event)
    {
        callback.@com.akjava.gwt.html5.client.pointerlock.PointerLock.PointerLockListener::pointerLockChanged(Lcom/google/gwt/dom/client/NativeEvent;)(event);
    };
}-*/;
	
	//TODO error
}
	
@@ -131,24 +131,20 @@
 .client.
-NativeEv
+Elem
 ent;%0D%0Aim
@@ -178,67 +178,145 @@
 ent.
-Element;%0D%0Aimport com.google.gwt.user.client.ui.RootPanel;%0D%0A
+NativeEvent;%0D%0A%0D%0A/**%0D%0A * Pointer Lock API%0D%0A * see %0D%0A * https://developer.mozilla.org/ja/docs/API/Pointer_Lock_API%0D%0A * @author aki%0D%0A *%0D%0A */
 %0D%0Apu
@@ -637,60 +637,8 @@
 -%7B%0D%0A
-%09//%09console.log($wnd.document.pointerLockElement);%0D%0A
 %09ret
@@ -854,24 +854,26 @@
 nterLock
+ed
 ()/*-%7B%0D%0A
 %09//%09cons
@@ -868,60 +868,8 @@
 -%7B%0D%0A
-%09//%09console.log($wnd.document.pointerLockElement);%0D%0A
 %09ret
@@ -993,32 +993,92 @@
 t ;%0D%0A%09%7D-*/;%0D%0A%09%0D%0A
+%09/*%0D%0A%09 * usually Body as  RootPanel.getBodyElement()%0D%0A%09 */%0D%0A
 %09public final st

add comment