]> source.dussan.org Git - vaadin-framework.git/commitdiff
helper to detect touch based devices, related to #6873, #6874, #6875
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 21 Apr 2011 16:52:25 +0000 (16:52 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 21 Apr 2011 16:52:25 +0000 (16:52 +0000)
svn changeset:18435/svn branch:6.6

src/com/vaadin/terminal/gwt/client/BrowserInfo.java

index 8c80f1f530ba78b80b78c7764441b440e4589682..5b6c1f8d0b9d36cad5979cfa39a493a4aeebfb87 100644 (file)
@@ -52,6 +52,7 @@ public class BrowserInfo {
     }
 
     private VBrowserDetails browserDetails;
+    private boolean touchDevice;
 
     private BrowserInfo() {
         browserDetails = new VBrowserDetails(getBrowserString());
@@ -63,8 +64,14 @@ public class BrowserInfo {
                 browserDetails.setIEMode(documentMode);
             }
         }
+        touchDevice = detectTouchDevice();
     }
 
+    private native boolean detectTouchDevice()
+    /*-{
+        try { document.createEvent("TouchEvent");return true;} catch(e){return false;};
+    }-*/;
+
     private native int getIEDocumentMode()
     /*-{
        var mode = $wnd.document.documentMode;
@@ -337,4 +344,11 @@ public class BrowserInfo {
 
     }-*/;
 
+    /**
+     * @return true if the browser runs on a touch based device.
+     */
+    public boolean isTouchDevice() {
+        return touchDevice;
+    }
+
 }