From e085efa41793fc68d455fa5d718bbfc1309296b9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 22 May 2012 12:53:06 +0000 Subject: [PATCH] Make browser window size available in Window (#5655) svn changeset:23790/svn branch:6.8 --- .../vaadin/terminal/gwt/client/ui/VView.java | 31 ++++++------ src/com/vaadin/ui/Window.java | 49 +++++++++++++++++++ .../tests/integration/EmbedSizeTest.java | 6 ++- 3 files changed, 68 insertions(+), 18 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VView.java b/src/com/vaadin/terminal/gwt/client/ui/VView.java index ec4c5d9cba..e544a56190 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VView.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VView.java @@ -47,6 +47,10 @@ import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHan public class VView extends SimplePanel implements Container, ResizeHandler, Window.ClosingHandler, ShortcutActionHandlerOwner, Focusable { + public static final String BROWSER_HEIGHT_VAR = "browserHeight"; + + public static final String BROWSER_WIDTH_VAR = "browserWidth"; + private static final String CLASSNAME = "v-view"; public static final String NOTIFICATION_HTML_CONTENT_NOT_ALLOWED = "useplain"; @@ -69,13 +73,6 @@ public class VView extends SimplePanel implements Container, ResizeHandler, private int windowWidth; private int windowHeight; - /* - * Last know view size used to detect whether new dimensions should be sent - * to the server. - */ - private int viewWidth; - private int viewHeight; - private ApplicationConnection connection; /** @@ -547,16 +544,18 @@ public class VView extends SimplePanel implements Container, ResizeHandler, */ private void sendClientResized() { Element parentElement = getElement().getParentElement(); - int newViewHeight = parentElement.getClientHeight(); - int newViewWidth = parentElement.getClientWidth(); + int viewHeight = parentElement.getClientHeight(); + int viewWidth = parentElement.getClientWidth(); - // Send the view dimensions if they have changed - if (newViewHeight != viewHeight || newViewWidth != viewWidth) { - viewHeight = newViewHeight; - viewWidth = newViewWidth; - connection.updateVariable(id, "height", newViewHeight, false); - connection.updateVariable(id, "width", newViewWidth, immediate); - } + connection.updateVariable(id, "height", viewHeight, false); + connection.updateVariable(id, "width", viewWidth, false); + + int windowWidth = Window.getClientWidth(); + int windowHeight = Window.getClientHeight(); + + connection.updateVariable(id, BROWSER_WIDTH_VAR, windowWidth, false); + connection.updateVariable(id, BROWSER_HEIGHT_VAR, windowHeight, + immediate); } public native static void goTo(String url) diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java index 5f6c29f182..f20090fead 100644 --- a/src/com/vaadin/ui/Window.java +++ b/src/com/vaadin/ui/Window.java @@ -223,6 +223,10 @@ public class Window extends Panel implements URIHandler, ParameterHandler, */ private Component scrollIntoView; + private int browserWindowWidth = -1; + + private int browserWindowHeight = -1; + /** * Creates a new unnamed window with a default layout. */ @@ -1081,6 +1085,20 @@ public class Window extends Panel implements URIHandler, ParameterHandler, .get("width") != getWidth())) { sizeHasChanged = true; } + Integer browserHeightVar = (Integer) variables + .get(VView.BROWSER_HEIGHT_VAR); + if (browserHeightVar != null + && browserHeightVar.intValue() != browserWindowHeight) { + browserWindowHeight = browserHeightVar.intValue(); + sizeHasChanged = true; + } + Integer browserWidthVar = (Integer) variables + .get(VView.BROWSER_WIDTH_VAR); + if (browserWidthVar != null + && browserWidthVar.intValue() != browserWindowWidth) { + browserWindowWidth = browserWidthVar.intValue(); + sizeHasChanged = true; + } super.changeVariables(source, variables); @@ -2380,4 +2398,35 @@ public class Window extends Panel implements URIHandler, ParameterHandler, } } + /** + * Gets the height of the viewport area of the browser window where this + * window is displayed. + * + * @return the browser viewport height in pixels + */ + public int getBrowserWindowHeight() { + // Size only reported by VView -> data only available from application + // level window + if (getParent() != null) { + return (getParent()).getBrowserWindowHeight(); + } + + return browserWindowHeight; + } + + /** + * Gets the width of the viewport area of the browser window where this + * window is displayed. + * + * @return the browser viewport width in pixels + */ + public int getBrowserWindowWidth() { + // Size only reported by VView -> data only available from application + // level window + if (getParent() != null) { + return (getParent()).getBrowserWindowWidth(); + } + + return browserWindowWidth; + } } diff --git a/tests/testbench/com/vaadin/tests/integration/EmbedSizeTest.java b/tests/testbench/com/vaadin/tests/integration/EmbedSizeTest.java index 479af4aa87..3524b3fce3 100644 --- a/tests/testbench/com/vaadin/tests/integration/EmbedSizeTest.java +++ b/tests/testbench/com/vaadin/tests/integration/EmbedSizeTest.java @@ -36,8 +36,10 @@ public class EmbedSizeTest extends TestBase { mainWindow.addListener(new Window.ResizeListener() { public void windowResized(ResizeEvent e) { Window window = e.getWindow(); - log.log("Resize event: " + window.getWidth() + " x " - + window.getHeight()); + log.log("App: " + window.getWidth() + " x " + + window.getHeight() + ", Browser window: " + + window.getBrowserWindowWidth() + " x " + + window.getBrowserWindowHeight()); } }); } -- 2.39.5