From 080ab9869d8b7a83349b5eb4255140fb40ee9bed Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 21 Aug 2009 11:47:17 +0000 Subject: [PATCH] #3222 - Add functionality for embedded Vaadin application to resize parent frame svn changeset:8521/svn branch:6.1 --- .../vaadin/terminal/gwt/client/ui/VView.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VView.java b/src/com/vaadin/terminal/gwt/client/ui/VView.java index 00ed1e935c..98b64f7c72 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VView.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VView.java @@ -78,6 +78,12 @@ public class VView extends SimplePanel implements Container, private boolean immediate; + /** + * Reference to the parent frame/iframe. Null if there is no parent (i)frame + * or if the application and parent frame are in different domains. + */ + private Element parentFrame; + public VView(String elementId) { super(); setStyleName(CLASSNAME); @@ -114,6 +120,7 @@ public class VView extends SimplePanel implements Container, focus(getElement()); } + parentFrame = getParentFrame(); } private static native void focus(Element el) @@ -232,6 +239,9 @@ public class VView extends SimplePanel implements Container, } layout.updateFromUIDL(childUidl, client); + if (!childUidl.getBooleanAttribute("cached")) { + updateParentFrameSize(); + } // Update subwindows final HashSet removedSubWindows = new HashSet( @@ -551,10 +561,39 @@ public class VView extends SimplePanel implements Container, * Can never propagate further and we do not want need to re-layout the * layout which has caused this request. */ + updateParentFrameSize(); + return true; } + private void updateParentFrameSize() { + if (parentFrame == null) { + return; + } + + int childHeight = Util.getRequiredHeight(getWidget().getElement()); + int childWidth = Util.getRequiredWidth(getWidget().getElement()); + + parentFrame.getStyle().setPropertyPx("width", childWidth); + parentFrame.getStyle().setPropertyPx("height", childHeight); + } + + private static native Element getParentFrame() + /*-{ + try { + var frameElement = $wnd.frameElement; + if (frameElement == null) { + return null; + } + if (frameElement.getAttribute("autoResize") == "true") { + return frameElement; + } + } catch (e) { + } + return null; + }-*/; + public void updateCaption(Paintable component, UIDL uidl) { // NOP Subwindows never draw caption for their first child (layout) } -- 2.39.5