Browse Source

Make browser window size available in Window (#5655)

svn changeset:23790/svn branch:6.8
tags/7.0.0.alpha3
Leif Åstrand 12 years ago
parent
commit
e085efa417

+ 15
- 16
src/com/vaadin/terminal/gwt/client/ui/VView.java View 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)

+ 49
- 0
src/com/vaadin/ui/Window.java View 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;
}
}

+ 4
- 2
tests/testbench/com/vaadin/tests/integration/EmbedSizeTest.java View 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());
}
});
}

Loading…
Cancel
Save