]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #7106 (touch device detection) and #7107 (client time issue)
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 1 Jun 2011 14:12:29 +0000 (14:12 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Wed, 1 Jun 2011 14:12:29 +0000 (14:12 +0000)
svn changeset:19203/svn branch:6.6

src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/WebBrowser.java

index cb4ba16f65553e9c92a19532d2a4ad30cfe35f25..b4f194c7f7a0499e0167dd9329194dcfd3eaa0ad 100644 (file)
@@ -561,15 +561,19 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
     private void updateBrowserProperties(WebBrowser browser,
             PortletRequest request) {
         String userAgent = getHTTPHeader(request, "user-agent");
-        browser.updateBrowserProperties(request.getLocale(), null,
-                request.isSecure(), userAgent,
-                getHTTPRequestParameter(request, "sw"),
-                getHTTPRequestParameter(request, "sh"),
-                getHTTPRequestParameter(request, "tzo"),
-                getHTTPRequestParameter(request, "rtzo"),
-                getHTTPRequestParameter(request, "dstd"),
-                getHTTPRequestParameter(request, "dstActive"),
-                getHTTPRequestParameter(request, "curdate"));
+        browser.updateRequestDetails(request.getLocale(), null,
+                request.isSecure(), userAgent);
+        if (getHTTPRequestParameter(request, "repaintAll") != null) {
+            browser.updateClientSideDetails(
+                    getHTTPRequestParameter(request, "sw"),
+                    getHTTPRequestParameter(request, "sh"),
+                    getHTTPRequestParameter(request, "tzo"),
+                    getHTTPRequestParameter(request, "rtzo"),
+                    getHTTPRequestParameter(request, "dstd"),
+                    getHTTPRequestParameter(request, "dstActive"),
+                    getHTTPRequestParameter(request, "curdate"),
+                    getHTTPRequestParameter(request, "td") != null);
+        }
     }
 
     @Override
index f274a474dd62c9f3b01f00541650f7d0c0d9b544..c394e8ae6a867ad1abec796a46bf479eb95c0cb2 100644 (file)
@@ -589,12 +589,18 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     private void updateBrowserProperties(WebBrowser browser,
             HttpServletRequest request) {
-        browser.updateBrowserProperties(request.getLocale(),
+        // request based details updated always
+        browser.updateRequestDetails(request.getLocale(),
                 request.getRemoteAddr(), request.isSecure(),
-                request.getHeader("user-agent"), request.getParameter("sw"),
-                request.getParameter("sh"), request.getParameter("tzo"),
-                request.getParameter("rtzo"), request.getParameter("dstd"),
-                request.getParameter("dston"), request.getParameter("curdate"));
+                request.getHeader("user-agent"));
+        if (request.getParameter("repaintAll") != null) {
+            browser.updateClientSideDetails(request.getParameter("sw"),
+                    request.getParameter("sh"), request.getParameter("tzo"),
+                    request.getParameter("rtzo"), request.getParameter("dstd"),
+                    request.getParameter("dston"),
+                    request.getParameter("curdate"),
+                    request.getParameter("td") != null);
+        }
     }
 
     protected ClassLoader getClassLoader() throws ServletException {
index 1b0d7fe9867fc5e2f4f8997d89f6f078dc4ff01f..5968588019ec2b386b8dabbaa0206098fb7a206a 100644 (file)
@@ -30,9 +30,10 @@ public class WebBrowser implements Terminal {
     private int rawTimezoneOffset = 0;
     private int dstSavings;
     private boolean dstInEffect;
-    private Date currentDate;
+    private boolean touchDevice;
 
     private VBrowserDetails browserDetails;
+    private long clientServerTimeDelta;
 
     /**
      * There is no default-theme for this terminal type.
@@ -70,91 +71,6 @@ public class WebBrowser implements Terminal {
         return browserApplication;
     }
 
-    /**
-     * For internal use by AbstractApplicationServlet/AbstractApplicationPortlet
-     * only. Updates all properties in the class according to the given
-     * information.
-     * 
-     * @param locale
-     *            The browser primary locale
-     * @param address
-     *            The browser ip address
-     * @param secureConnection
-     *            true if using an https connection
-     * @param agent
-     *            Raw userAgent string from the browser
-     * @param sw
-     *            Screen width
-     * @param sh
-     *            Screen height
-     * @param tzo
-     *            TimeZone offset in minutes from GMT
-     * @param rtzo
-     *            raw TimeZone offset in minutes from GMT (w/o DST adjustment)
-     * @param dstSavings
-     *            the difference between the raw TimeZone and DST in minutes
-     * @param dstInEffect
-     *            is DST currently active in the region or not?
-     * @param curDate
-     *            the current date in milliseconds since the epoch
-     */
-    void updateBrowserProperties(Locale locale, String address,
-            boolean secureConnection, String agent, String sw, String sh,
-            String tzo, String rtzo, String dstSavings, String dstInEffect,
-            String curDate) {
-        this.locale = locale;
-        this.address = address;
-        this.secureConnection = secureConnection;
-        if (agent != null) {
-            browserApplication = agent;
-            browserDetails = new VBrowserDetails(agent);
-        }
-
-        if (sw != null) {
-            try {
-                screenHeight = Integer.parseInt(sh);
-                screenWidth = Integer.parseInt(sw);
-            } catch (final NumberFormatException e) {
-                screenHeight = screenWidth = 0;
-            }
-        }
-        if (tzo != null) {
-            try {
-                // browser->java conversion: min->ms, reverse sign
-                timezoneOffset = -Integer.parseInt(tzo) * 60 * 1000;
-            } catch (final NumberFormatException e) {
-                timezoneOffset = 0; // default gmt+0
-            }
-        }
-        if (rtzo != null) {
-            try {
-                // browser->java conversion: min->ms, reverse sign
-                rawTimezoneOffset = -Integer.parseInt(rtzo) * 60 * 1000;
-            } catch (final NumberFormatException e) {
-                rawTimezoneOffset = 0; // default gmt+0
-            }
-        }
-        if (dstSavings != null) {
-            try {
-                // browser->java conversion: min->ms
-                this.dstSavings = Integer.parseInt(dstSavings) * 60 * 1000;
-            } catch (final NumberFormatException e) {
-                this.dstSavings = 0; // default no savings
-            }
-        }
-        if (dstInEffect != null) {
-            this.dstInEffect = Boolean.parseBoolean(dstInEffect);
-        }
-        if (curDate != null) {
-            try {
-                long curTime = Long.parseLong(curDate);
-                currentDate = new Date(curTime);
-            } catch (final NumberFormatException e) {
-                currentDate = new Date();
-            }
-        }
-    }
-
     /**
      * Gets the IP-address of the web browser. If the application is running
      * inside a portlet, this method will return null.
@@ -368,12 +284,120 @@ public class WebBrowser implements Terminal {
     /**
      * Returns the current date and time of the browser. This will not be
      * entirely accurate due to varying network latencies, but should provide a
-     * close-enough value for most cases.
+     * close-enough value for most cases. Also not that the returned Date object
+     * uses servers default time zone, not the clients.
      * 
      * @return the current date and time of the browser.
+     * @see #isDSTInEffect()
+     * @see #getDSTSavings()
+     * @see #getTimezoneOffset()
      */
     public Date getCurrentDate() {
-        return currentDate;
+        return new Date(new Date().getTime() + clientServerTimeDelta);
+    }
+
+    /**
+     * @return true if the browser is detected to support touch events
+     */
+    public boolean isTouchDevice() {
+        return touchDevice;
+    }
+
+    /**
+     * For internal use by AbstractApplicationServlet/AbstractApplicationPortlet
+     * only. Updates all properties in the class according to the given
+     * information.
+     * 
+     * @param sw
+     *            Screen width
+     * @param sh
+     *            Screen height
+     * @param tzo
+     *            TimeZone offset in minutes from GMT
+     * @param rtzo
+     *            raw TimeZone offset in minutes from GMT (w/o DST adjustment)
+     * @param dstSavings
+     *            the difference between the raw TimeZone and DST in minutes
+     * @param dstInEffect
+     *            is DST currently active in the region or not?
+     * @param curDate
+     *            the current date in milliseconds since the epoch
+     * @param touchDevice
+     */
+    void updateClientSideDetails(String sw, String sh, String tzo, String rtzo,
+            String dstSavings, String dstInEffect, String curDate,
+            boolean touchDevice) {
+        if (sw != null) {
+            try {
+                screenHeight = Integer.parseInt(sh);
+                screenWidth = Integer.parseInt(sw);
+            } catch (final NumberFormatException e) {
+                screenHeight = screenWidth = 0;
+            }
+        }
+        if (tzo != null) {
+            try {
+                // browser->java conversion: min->ms, reverse sign
+                timezoneOffset = -Integer.parseInt(tzo) * 60 * 1000;
+            } catch (final NumberFormatException e) {
+                timezoneOffset = 0; // default gmt+0
+            }
+        }
+        if (rtzo != null) {
+            try {
+                // browser->java conversion: min->ms, reverse sign
+                rawTimezoneOffset = -Integer.parseInt(rtzo) * 60 * 1000;
+            } catch (final NumberFormatException e) {
+                rawTimezoneOffset = 0; // default gmt+0
+            }
+        }
+        if (dstSavings != null) {
+            try {
+                // browser->java conversion: min->ms
+                this.dstSavings = Integer.parseInt(dstSavings) * 60 * 1000;
+            } catch (final NumberFormatException e) {
+                this.dstSavings = 0; // default no savings
+            }
+        }
+        if (dstInEffect != null) {
+            this.dstInEffect = Boolean.parseBoolean(dstInEffect);
+        }
+        if (curDate != null) {
+            try {
+                long curTime = Long.parseLong(curDate);
+                clientServerTimeDelta = curTime - new Date().getTime();
+            } catch (final NumberFormatException e) {
+                clientServerTimeDelta = 0;
+            }
+        }
+        this.touchDevice = touchDevice;
+
+    }
+
+    /**
+     * For internal use by AbstractApplicationServlet/AbstractApplicationPortlet
+     * only. Updates all properties in the class according to the given
+     * information.
+     * 
+     * @param locale
+     *            The browser primary locale
+     * @param address
+     *            The browser ip address
+     * @param secureConnection
+     *            true if using an https connection
+     * @param agent
+     *            Raw userAgent string from the browser
+     */
+    void updateRequestDetails(Locale locale, String address,
+            boolean secureConnection, String agent) {
+        this.locale = locale;
+        this.address = address;
+        this.secureConnection = secureConnection;
+        if (agent != null) {
+            browserApplication = agent;
+            browserDetails = new VBrowserDetails(agent);
+        }
+
     }
 
 }