summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2011-06-01 14:12:29 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2011-06-01 14:12:29 +0000
commit29905ccfa27dfa7d984f08623551952745800d20 (patch)
treeb2b60e4f9ef52f97a89dce8af2d1124c580adb8d /src/com
parent3656a1a264b4d00e9dc6c4390dd40462febeefa5 (diff)
downloadvaadin-framework-29905ccfa27dfa7d984f08623551952745800d20.tar.gz
vaadin-framework-29905ccfa27dfa7d984f08623551952745800d20.zip
fixes #7106 (touch device detection) and #7107 (client time issue)
svn changeset:19203/svn branch:6.6
Diffstat (limited to 'src/com')
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java22
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java16
-rw-r--r--src/com/vaadin/terminal/gwt/server/WebBrowser.java200
3 files changed, 136 insertions, 102 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
index cb4ba16f65..b4f194c7f7 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
@@ -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
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
index f274a474dd..c394e8ae6a 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
@@ -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 {
diff --git a/src/com/vaadin/terminal/gwt/server/WebBrowser.java b/src/com/vaadin/terminal/gwt/server/WebBrowser.java
index 1b0d7fe986..5968588019 100644
--- a/src/com/vaadin/terminal/gwt/server/WebBrowser.java
+++ b/src/com/vaadin/terminal/gwt/server/WebBrowser.java
@@ -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.
@@ -71,91 +72,6 @@ public class WebBrowser implements Terminal {
}
/**
- * 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);
+ }
+
}
}