From 977c8b01c042f2ffec36e3cb5c7ad517b738d06e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Fri, 16 Nov 2012 15:34:23 +0200 Subject: [PATCH] Read browser width and height from request in Page.init (#9073) * Also change default screen width and height in WebBrowser to -1 for consistency * Test for reading browser details in UI.init Change-Id: I24339fd3742857392e1fc768696eeb2fb5551a90 --- server/src/com/vaadin/server/Page.java | 18 ++- server/src/com/vaadin/server/WebBrowser.java | 6 +- .../components/ui/UIInitBrowserDetails.html | 112 ++++++++++++++++++ .../components/ui/UIInitBrowserDetails.java | 56 +++++++++ 4 files changed, 186 insertions(+), 6 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.html create mode 100644 uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index cf77c09324..501172f80a 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -436,15 +436,27 @@ public class Page implements Serializable { public void init(VaadinRequest request) { // Extract special parameter sent by vaadinBootstrap.js - String loc = request.getParameter("loc"); - if (loc != null) { + String location = request.getParameter("loc"); + String clientWidth = request.getParameter("cw"); + String clientHeight = request.getParameter("ch"); + + if (location != null) { try { - location = new URI(loc); + this.location = new URI(location); } catch (URISyntaxException e) { throw new RuntimeException( "Invalid location URI received from client", e); } } + if (clientWidth != null && clientHeight != null) { + try { + browserWindowWidth = Integer.parseInt(clientWidth); + browserWindowHeight = Integer.parseInt(clientHeight); + } catch (NumberFormatException e) { + throw new RuntimeException( + "Invalid window size received from client", e); + } + } } public WebBrowser getWebBrowser() { diff --git a/server/src/com/vaadin/server/WebBrowser.java b/server/src/com/vaadin/server/WebBrowser.java index 676375a693..4df535a39a 100644 --- a/server/src/com/vaadin/server/WebBrowser.java +++ b/server/src/com/vaadin/server/WebBrowser.java @@ -32,8 +32,8 @@ import com.vaadin.shared.VBrowserDetails; */ public class WebBrowser implements Serializable { - private int screenHeight = 0; - private int screenWidth = 0; + private int screenHeight = -1; + private int screenWidth = -1; private String browserApplication = null; private Locale locale; private String address; @@ -364,7 +364,7 @@ public class WebBrowser implements Serializable { screenHeight = Integer.parseInt(sh); screenWidth = Integer.parseInt(sw); } catch (final NumberFormatException e) { - screenHeight = screenWidth = 0; + screenHeight = screenWidth = -1; } } if (tzo != null) { diff --git a/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.html b/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.html new file mode 100644 index 0000000000..3fd7a0d560 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.html @@ -0,0 +1,112 @@ + + + + + + +UIInitBrowserDetails + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
UIInitBrowserDetails
open/run/UIInitBrowserDetails?restartApplication
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[4]null
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[2]null
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[4]null
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[5]-1
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[10]null
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[8]-1
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[10]null
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[11]-1
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[13]null
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[14]-1
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[16]null
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[19]null
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[22]null
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[25]null
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[28]null
assertNotTextvaadin=runUIInitBrowserDetails::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VGridLayout[0]/VLabel[29]null
+ + diff --git a/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java b/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java new file mode 100644 index 0000000000..587c9f0f9b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIInitBrowserDetails.java @@ -0,0 +1,56 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.components.ui; + +import com.vaadin.server.Page; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.WebBrowser; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Label; + +public class UIInitBrowserDetails extends AbstractTestUI { + + private GridLayout l = new GridLayout(3, 1); + private VaadinRequest r; + + @Override + protected void setup(VaadinRequest request) { + r = request; + l.setWidth("100%"); + addComponent(l); + + Page p = getPage(); + WebBrowser wb = p.getWebBrowser(); + + addDetail("location", "loc", p.getLocation()); + + addDetail("browser window width", "cw", p.getBrowserWindowWidth()); + addDetail("browser window height", "ch", p.getBrowserWindowHeight()); + addDetail("screen width", "sw", wb.getScreenWidth()); + addDetail("screen height", "sh", wb.getScreenHeight()); + + addDetail("timezone offset", "tzo", wb.getTimezoneOffset()); + addDetail("raw timezone offset", "rtzo", wb.getRawTimezoneOffset()); + addDetail("dst saving", "dstd", wb.getDSTSavings()); + addDetail("dst in effect", "dston", wb.isDSTInEffect()); + addDetail("current date", "curdate", wb.getCurrentDate()); + } + + @Override + public String getTestDescription() { + return "Browser details should be available in UI init"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(9037); + } + + private void addDetail(String name, String param, Object value) { + l.addComponents(new Label(name), new Label(r.getParameter(param)), + new Label("" + value)); + } +} -- 2.39.5