From 159dcf5e9407d37d49647cf88afa1a1e0969a2bc Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 21 Apr 2011 07:27:37 +0000 Subject: [PATCH] #6787 Use document mode in IE to detect browser version svn changeset:18425/svn branch:6.6 --- .../terminal/gwt/client/BrowserInfo.java | 18 ++++++++------- .../terminal/gwt/client/VBrowserDetails.java | 23 ++++++++++--------- .../tests/server/BrowserUserAgentParser.java | 2 +- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java index 141a05ffdb..8c80f1f530 100644 --- a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java +++ b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java @@ -55,20 +55,22 @@ public class BrowserInfo { private BrowserInfo() { browserDetails = new VBrowserDetails(getBrowserString()); - if (browserDetails.isIE() - && browserDetails.getBrowserMajorVersion() == 8 - && isIE8InIE7CompatibilityMode()) { - browserDetails.setIE8InCompatibilityMode(); + if (browserDetails.isIE()) { + // Use document mode instead user agent to accurately detect how we + // are rendering + int documentMode = getIEDocumentMode(); + if (documentMode != -1) { + browserDetails.setIEMode(documentMode); + } } - } - private native boolean isIE8InIE7CompatibilityMode() + private native int getIEDocumentMode() /*-{ var mode = $wnd.document.documentMode; if (!mode) - return false; - return (mode == 7); + return -1; + return mode; }-*/; /** diff --git a/src/com/vaadin/terminal/gwt/client/VBrowserDetails.java b/src/com/vaadin/terminal/gwt/client/VBrowserDetails.java index 92b3dedf1f..2b55c96125 100644 --- a/src/com/vaadin/terminal/gwt/client/VBrowserDetails.java +++ b/src/com/vaadin/terminal/gwt/client/VBrowserDetails.java @@ -237,10 +237,10 @@ public class VBrowserDetails implements Serializable { /** * Returns the browser major version e.g., 3 for Firefox 3.5, 4 for Chrome * 4, 8 for Internet Explorer 8. - * - *
-     * Note that Internet Explorer 8 in compatibility mode will return 7.
-     * 
+ *

+ * Note that Internet Explorer 8 and newer will return the document mode so + * IE8 rendering as IE7 will return 7. + *

* * @return The major version of the browser. */ @@ -260,15 +260,16 @@ public class VBrowserDetails implements Serializable { } /** - * Marks that IE8 is used in compatibility mode. This forces the browser - * version to 7 even if it otherwise was detected as 8. + * Sets the version for IE based on the documentMode. This is used to return + * the correct the correct IE version when the version from the user agent + * string and the value of the documentMode property do not match. * + * @param documentMode + * The current document mode */ - public void setIE8InCompatibilityMode() { - if (isIE && browserMajorVersion == 8) { - browserMajorVersion = 7; - browserMinorVersion = 0; - } + public void setIEMode(int documentMode) { + browserMajorVersion = documentMode; + browserMinorVersion = 0; } /** diff --git a/tests/src/com/vaadin/tests/server/BrowserUserAgentParser.java b/tests/src/com/vaadin/tests/server/BrowserUserAgentParser.java index 97d8143038..e5ce882ffd 100644 --- a/tests/src/com/vaadin/tests/server/BrowserUserAgentParser.java +++ b/tests/src/com/vaadin/tests/server/BrowserUserAgentParser.java @@ -217,7 +217,7 @@ public class BrowserUserAgentParser extends TestCase { public void testIE8CompatibilityMode() { VBrowserDetails bd = new VBrowserDetails(IE8_IN_IE7_MODE_WINDOWS); - bd.setIE8InCompatibilityMode(); + bd.setIEMode(7); // assertTrident(bd); assertIE(bd); -- 2.39.5