]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make browser window size available in Window (#5655)
authorLeif Åstrand <leif@vaadin.com>
Tue, 22 May 2012 12:53:06 +0000 (12:53 +0000)
committerLeif Åstrand <leif@vaadin.com>
Tue, 22 May 2012 12:53:06 +0000 (12:53 +0000)
svn changeset:23790/svn branch:6.8

src/com/vaadin/terminal/gwt/client/ui/VView.java
src/com/vaadin/ui/Window.java
tests/testbench/com/vaadin/tests/integration/EmbedSizeTest.java

index ec4c5d9cba917ff8d04c7ec463e7964a172f9880..e544a561901032ac9ac397a26d42324d11671c00 100644 (file)
@@ -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)
index 5f6c29f182d68e6034a14e94bb6700a2b9ddf06a..f20090feade975255968f3cba8c849342005e745 100644 (file)
@@ -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;
+    }
 }
index 479af4aa87553e505aec23c53100ade11d14d14d..3524b3fce390b3444316e9a4cc2d2208f52be2e2 100644 (file)
@@ -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());
             }
         });
     }