]> source.dussan.org Git - vaadin-framework.git/commitdiff
Drop size calculations from Embeddable (#8312)
authorLeif Åstrand <leif@vaadin.com>
Mon, 27 Feb 2012 13:47:30 +0000 (15:47 +0200)
committerLeif Åstrand <leif@vaadin.com>
Mon, 27 Feb 2012 13:47:30 +0000 (15:47 +0200)
src/com/vaadin/terminal/gwt/client/ui/VEmbedded.java
src/com/vaadin/terminal/gwt/client/ui/VEmbeddedPaintable.java

index e2247b627d31f1726b589c79bd8d8d874a76002f..95ffb8076b36a5345770a5d2f7ea9df22b3623a8 100644 (file)
@@ -8,7 +8,6 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
-import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
@@ -17,12 +16,13 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.BrowserInfo;
 import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.Util;
+import com.vaadin.terminal.gwt.client.VConsole;
+import com.vaadin.terminal.gwt.client.VPaintableMap;
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
 
 public class VEmbedded extends HTML {
     public static String CLASSNAME = "v-embedded";
 
-    protected String height;
-    protected String width;
     protected Element browserElement;
 
     protected String type;
@@ -84,6 +84,11 @@ public class VEmbedded extends HTML {
             html.append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ");
         }
 
+        VPaintableWidget paintable = VPaintableMap.get(client).getPaintable(
+                this);
+        String height = paintable.getDeclaredHeight();
+        String width = paintable.getDeclaredWidth();
+
         // Add width and height
         html.append("width=\"" + Util.escapeAttribute(width) + "\" ");
         html.append("height=\"" + Util.escapeAttribute(height) + "\" ");
@@ -196,40 +201,6 @@ public class VEmbedded extends HTML {
         return url;
     }
 
-    @Override
-    public void setWidth(String width) {
-        this.width = width;
-        if (isDynamicHeight()) {
-            int oldHeight = getOffsetHeight();
-            super.setWidth(width);
-            int newHeight = getOffsetHeight();
-            /*
-             * Must notify parent if the height changes as a result of a width
-             * change
-             */
-            if (oldHeight != newHeight) {
-                Util.notifyParentOfSizeChange(this, false);
-            }
-        } else {
-            super.setWidth(width);
-        }
-
-    }
-
-    private boolean isDynamicWidth() {
-        return width == null || width.equals("");
-    }
-
-    private boolean isDynamicHeight() {
-        return height == null || height.equals("");
-    }
-
-    @Override
-    public void setHeight(String height) {
-        this.height = height;
-        super.setHeight(height);
-    }
-
     @Override
     protected void onDetach() {
         if (BrowserInfo.get().isIE()) {
@@ -247,30 +218,11 @@ public class VEmbedded extends HTML {
     public void onBrowserEvent(Event event) {
         super.onBrowserEvent(event);
         if (DOM.eventGetType(event) == Event.ONLOAD) {
-            if ("image".equals(type)) {
-                updateElementDynamicSizeFromImage();
-            }
+            VConsole.log("Embeddable onload");
             Util.notifyParentOfSizeChange(this, true);
         }
 
         client.handleTooltipEvent(event, this);
     }
 
-    /**
-     * Updates the size of the embedded component's element if size is
-     * undefined. Without this embeddeds containing images will remain the wrong
-     * size in certain cases (e.g. #6304).
-     */
-    private void updateElementDynamicSizeFromImage() {
-        if (isDynamicWidth()) {
-            getElement().getStyle().setWidth(
-                    getElement().getFirstChildElement().getOffsetWidth(),
-                    Unit.PX);
-        }
-        if (isDynamicHeight()) {
-            getElement().getStyle().setHeight(
-                    getElement().getFirstChildElement().getOffsetHeight(),
-                    Unit.PX);
-        }
-    }
 }
index 585241ef21f1c6d3bcde5a67b7121865baf8861f..6a538319a2635ba0c4cf4c397ab58d58a9936b22 100644 (file)
@@ -128,10 +128,10 @@ public class VEmbeddedPaintable extends VAbstractPaintableWidget {
                 ObjectElement obj = Document.get().createObjectElement();
                 obj.setType(mime);
                 obj.setData(data);
-                if (getWidgetForPaintable().width != null) {
+                if (!isUndefinedWidth()) {
                     obj.getStyle().setProperty("width", "100%");
                 }
-                if (getWidgetForPaintable().height != null) {
+                if (!isUndefinedHeight()) {
                     obj.getStyle().setProperty("height", "100%");
                 }
                 if (uidl.hasAttribute("classid")) {