]> source.dussan.org Git - vaadin-framework.git/commitdiff
Communicate component width and height only via shared state (#8304).
authorHenri Sara <hesara@vaadin.com>
Thu, 16 Feb 2012 14:23:33 +0000 (16:23 +0200)
committerHenri Sara <hesara@vaadin.com>
Thu, 16 Feb 2012 14:23:33 +0000 (16:23 +0200)
Also removes old fix for #4608, needs to be redesigned together with
layout changes.

12 files changed:
src/com/vaadin/terminal/gwt/client/Util.java
src/com/vaadin/terminal/gwt/client/VUIDLBrowser.java
src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
src/com/vaadin/terminal/gwt/client/ui/VEmbeddedPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VOrderedLayoutPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java
src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java
src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java
src/com/vaadin/ui/AbstractComponent.java

index 27717ad63a387d62a48637020b7d9c8073b90aff..591016d54d0dbc5aef6debd14919634a8c1e8891 100644 (file)
@@ -32,6 +32,7 @@ import com.google.gwt.user.client.ui.RootPanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;
 import com.vaadin.terminal.gwt.client.communication.MethodInvocation;
+import com.vaadin.terminal.gwt.client.communication.SharedState;
 
 public class Util {
 
@@ -563,25 +564,30 @@ public class Util {
     }
 
     /**
-     * Parses the UIDL parameter and fetches the relative size of the component.
-     * If a dimension is not specified as relative it will return -1. If the
-     * UIDL does not contain width or height specifications this will return
+     * Parses shared state and fetches the relative size of the component. If a
+     * dimension is not specified as relative it will return -1. If the shared
+     * state does not contain width or height specifications this will return
      * null.
      * 
-     * @param uidl
+     * @param state
      * @return
      */
-    public static FloatSize parseRelativeSize(UIDL uidl) {
+    public static FloatSize parseRelativeSize(SharedState state) {
+        if (null == state) {
+            return null;
+        }
+
         boolean hasAttribute = false;
         String w = "";
         String h = "";
-        if (uidl.hasAttribute("width")) {
+        Map<String, Object> stateMap = state.getState();
+        if (stateMap.containsKey("width")) {
             hasAttribute = true;
-            w = uidl.getStringAttribute("width");
+            w = String.valueOf(stateMap.get("width"));
         }
-        if (uidl.hasAttribute("height")) {
+        if (stateMap.containsKey("height")) {
             hasAttribute = true;
-            h = uidl.getStringAttribute("height");
+            h = String.valueOf(stateMap.get("height"));
         }
 
         if (!hasAttribute) {
index e63bcf98d904d29c647c81d155d17ab1ca1e03b1..e83cfcc4fe00740aed54282a387a6302a1915347 100644 (file)
@@ -46,7 +46,9 @@ public class VUIDLBrowser extends SimpleTree {
         }
         Set<String> keySet = u.getKeySet();
         for (String key : keySet) {
-            if (key.equals("changes")) {
+            if (key.equals("state")) {
+                // TODO print updated shared states
+            } else if (key.equals("changes")) {
                 JsArray<UIDL> jsValueMapArray = u.getJSValueMapArray("changes")
                         .cast();
                 for (int i = 0; i < jsValueMapArray.length(); i++) {
index 3cbe8da00f8a82859539d7680fda99d67dddc919..3d186d2759f9b6419b5527f32169c2f668188a87 100644 (file)
@@ -151,6 +151,10 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
             return;
         }
 
+        if (!isRealUpdate(uidl)) {
+            return;
+        }
+
         /*
          * Disabled state may affect (override) tabindex so the order must be
          * first setting tabindex, then enabled state.
index f4a3df7615b0662f69470a424d02b04b0449cf94..0c64b28ab1c51b044fc59be3911ca38a7dfdc038 100644 (file)
@@ -20,6 +20,7 @@ import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ComponentState;
 import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.VConsole;
 import com.vaadin.terminal.gwt.client.VTooltip;
@@ -69,18 +70,23 @@ public class VEmbeddedPaintable extends VAbstractPaintableWidget {
 
                 // Set attributes
                 Style style = el.getStyle();
-                String w = uidl.getStringAttribute("width");
-                if (w != null) {
-                    style.setProperty("width", w);
-                } else {
-                    style.setProperty("width", "");
-                }
-                String h = uidl.getStringAttribute("height");
-                if (h != null) {
-                    style.setProperty("height", h);
-                } else {
-                    style.setProperty("height", "");
+                String w = "";
+                String h = "";
+                if (null != getState()) {
+                    if (getState().getState().containsKey(
+                            ComponentState.STATE_WIDTH)) {
+                        w = String.valueOf(getState().getState().get(
+                                ComponentState.STATE_WIDTH));
+                    }
+                    if (getState().getState().containsKey(
+                            ComponentState.STATE_HEIGHT)) {
+                        h = String.valueOf(getState().getState().get(
+                                ComponentState.STATE_HEIGHT));
+                    }
                 }
+                style.setProperty("width", w);
+                style.setProperty("height", h);
+
                 DOM.setElementProperty(el, "src", getWidgetForPaintable()
                         .getSrc(uidl, client));
 
index 5302fa6f671d96214b64b1376aa0c63d5292e64e..f894b49d87704672f0f8b80f49ca29bd21deea80 100644 (file)
@@ -26,6 +26,7 @@ import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.Util;
 import com.vaadin.terminal.gwt.client.VPaintableMap;
 import com.vaadin.terminal.gwt.client.VPaintableWidget;
+import com.vaadin.terminal.gwt.client.communication.SharedState;
 import com.vaadin.terminal.gwt.client.ui.layout.CellBasedLayout;
 import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer;
 
@@ -928,25 +929,29 @@ public class VGridLayout extends SimplePanel implements Container {
                 }
             }
             childUidl = c;
-            updateRelSizeStatus(c);
+            updateRelSizeStatus(client.getPaintable(c).getState(),
+                    c.getBooleanAttribute("cached"));
         }
 
-        protected void updateRelSizeStatus(UIDL uidl) {
-            if (uidl != null && !uidl.getBooleanAttribute("cached")) {
-                if (uidl.hasAttribute("height")
-                        && uidl.getStringAttribute("height").contains("%")) {
+        protected void updateRelSizeStatus(SharedState state, boolean cached) {
+            if (state != null && !cached) {
+                boolean widthDefined = state.getState().containsKey("width");
+                boolean heightDefined = state.getState().containsKey("height");
+                if (heightDefined
+                        && String.valueOf(state.getState().get("height"))
+                                .contains("%")) {
                     relHeight = true;
                 } else {
                     relHeight = false;
                 }
-                if (uidl.hasAttribute("width")) {
-                    widthCanAffectHeight = relWidth = uidl.getStringAttribute(
-                            "width").contains("%");
-                    if (uidl.hasAttribute("height")) {
+                if (widthDefined) {
+                    widthCanAffectHeight = relWidth = String.valueOf(
+                            state.getState().get("width")).contains("%");
+                    if (heightDefined) {
                         widthCanAffectHeight = false;
                     }
                 } else {
-                    widthCanAffectHeight = !uidl.hasAttribute("height");
+                    widthCanAffectHeight = !heightDefined;
                     relWidth = false;
                 }
             }
index c7e9f79d9a9391dabe2d31dfc55fec4e462800f2..0df932a45b8c0ecb48a0c8448756040f510c3eda 100644 (file)
@@ -175,8 +175,9 @@ public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer {
         }
         if (!getWidgetForPaintable().rendering) {
             // ensure rel size details are updated
+            boolean cached = uidl.getBooleanAttribute("cached");
             getWidgetForPaintable().widgetToCell.get(widget)
-                    .updateRelSizeStatus(uidl);
+                    .updateRelSizeStatus(paintable.getState(), cached);
             /*
              * This was a component-only update and the possible size change
              * must be propagated to the layout
index f3e4609540a4bb9a9b97ad0e70f266553ef677a1..4b2fdff819690ca4f867cd5cab8e9a22d740261c 100644 (file)
@@ -10,6 +10,7 @@ import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ComponentState;
 import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.Util;
 import com.vaadin.terminal.gwt.client.ui.VMenuBar.CustomMenuItem;
@@ -50,7 +51,9 @@ public class VMenuBarPaintable extends VAbstractPaintableWidget {
 
         UIDL options = uidl.getChildUIDL(0);
 
-        if (uidl.hasAttribute("width")) {
+        if (null != getState()
+                && getState().getState()
+                        .containsKey(ComponentState.STATE_WIDTH)) {
             UIDL moreItemUIDL = options.getChildUIDL(0);
             StringBuffer itemHTML = new StringBuffer();
 
index 0d9f5c6263cb300a1cce57fed5aee7a7a28f2e70..58d93fccc6900d730c8616783eaceef1a892623b 100644 (file)
@@ -105,8 +105,9 @@ public abstract class VOrderedLayoutPaintable extends CellBasedLayoutPaintable {
              * the layout are rendered later when it is clear how much space
              * they can use
              */
-            if (isRealUpdate(childUIDL)) {
-                FloatSize relativeSize = Util.parseRelativeSize(childUIDL);
+            if (null != childPaintable.getState()) {
+                FloatSize relativeSize = Util.parseRelativeSize(childPaintable
+                        .getState());
                 childComponentContainer.setRelativeSize(relativeSize);
             }
 
index e77aefc25b19e01825763b6b372d8968b44f0d33..afcd95a48bbaa8cf0dd6cb6d63122caf59110020 100644 (file)
@@ -3,6 +3,8 @@
  */
 package com.vaadin.terminal.gwt.client.ui;
 
+import java.util.Map;
+
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.event.dom.client.DomEvent.Type;
 import com.google.gwt.event.shared.EventHandler;
@@ -13,6 +15,7 @@ import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.Frame;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ComponentState;
 import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.Util;
 import com.vaadin.terminal.gwt.client.VPaintableWidget;
@@ -151,8 +154,16 @@ public class VWindowPaintable extends VAbstractPaintableWidgetContainer
             getWidgetForPaintable().layout = lo;
         }
 
-        getWidgetForPaintable().dynamicWidth = !uidl.hasAttribute("width");
-        getWidgetForPaintable().dynamicHeight = !uidl.hasAttribute("height");
+        if (null != getState()) {
+            Map<String, Object> state = getState().getState();
+            getWidgetForPaintable().dynamicWidth = !state
+                    .containsKey(ComponentState.STATE_WIDTH);
+            getWidgetForPaintable().dynamicHeight = !state
+                    .containsKey(ComponentState.STATE_HEIGHT);
+        } else {
+            getWidgetForPaintable().dynamicWidth = true;
+            getWidgetForPaintable().dynamicHeight = true;
+        }
 
         getWidgetForPaintable().layoutRelativeWidth = uidl
                 .hasAttribute("layoutRelativeWidth");
index 3a5030e606c76eae96f6d3b12def9a6655765ed4..819ac90cdf8eb744756e660947e18182715eb468 100644 (file)
@@ -4,6 +4,7 @@
 package com.vaadin.terminal.gwt.client.ui.layout;
 
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ComponentState;
 import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidgetContainer;
 import com.vaadin.terminal.gwt.client.ui.VMarginInfo;
@@ -31,16 +32,23 @@ public abstract class CellBasedLayoutPaintable extends
         super.updateFromUIDL(uidl, client);
 
         if (isRealUpdate(uidl)) {
-            handleDynamicDimensions(uidl);
+            handleDynamicDimensions();
         }
     }
 
-    private void handleDynamicDimensions(UIDL uidl) {
-        String w = uidl.hasAttribute("width") ? uidl
-                .getStringAttribute("width") : "";
-
-        String h = uidl.hasAttribute("height") ? uidl
-                .getStringAttribute("height") : "";
+    private void handleDynamicDimensions() {
+        String w = "";
+        String h = "";
+        if (null != getState()) {
+            if (getState().getState().containsKey(ComponentState.STATE_WIDTH)) {
+                w = String.valueOf(getState().getState().get(
+                        ComponentState.STATE_WIDTH));
+            }
+            if (getState().getState().containsKey(ComponentState.STATE_HEIGHT)) {
+                h = String.valueOf(getState().getState().get(
+                        ComponentState.STATE_HEIGHT));
+            }
+        }
 
         if (w.equals("")) {
             getWidgetForPaintable().dynamicWidth = true;
index 92464cd4593aea1e77dab437c60ce8cf632ba0e6..3cba88b30d7a5789ae7a3755230ad211b17fbd4b 100644 (file)
@@ -438,18 +438,6 @@ public class ChildComponentContainer extends Panel {
         }
 
         updateCaptionSize();
-
-        if (relativeSize == null) {
-            /*
-             * relativeSize may be null if component is updated via independent
-             * update, after it has initially been hidden. See #4608
-             * 
-             * It might also change in which case there would be similar issues.
-             * 
-             * Yes, it is an ugly hack. Don't come telling me about it.
-             */
-            setRelativeSize(Util.parseRelativeSize(uidl));
-        }
     }
 
     public void updateCaptionSize() {
index 8d9e3be93266c15edf71a1984337fd21c9192f50..122a6bd4707508676bba87aa14d9ee13fb95b1d8 100644 (file)
@@ -768,17 +768,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource
 
             // Only paint content of visible components.
             if (isVisible()) {
-                if (getHeight() >= 0
-                        && (getHeightUnits() != Unit.PERCENTAGE || ComponentSizeValidator
-                                .parentCanDefineHeight(this))) {
-                    target.addAttribute("height", "" + getCSSHeight());
-                }
+                // width and height are only in shared state
 
-                if (getWidth() >= 0
-                        && (getWidthUnits() != Unit.PERCENTAGE || ComponentSizeValidator
-                                .parentCanDefineWidth(this))) {
-                    target.addAttribute("width", "" + getCSSWidth());
-                }
                 if (styles != null && styles.size() > 0) {
                     target.addAttribute("style", getStyle());
                 }
@@ -902,6 +893,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource
             state.put(ComponentState.STATE_WIDTH, "" + getCSSWidth());
         }
 
+        // TODO use the rest on the client side
+
         if (styles != null && styles.size() > 0) {
             state.put(ComponentState.STATE_STYLE, getStyle());
         }