summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-02-08 16:37:41 +0200
committerLeif Åstrand <leif@vaadin.com>2012-02-08 16:37:41 +0200
commitcfe6e9b760b34ebb2ea1bbaf9531cbba2dc2ac5c (patch)
tree8e9dfaefc0c16d4c194b169b28ebecebd1cb231f /src
parent2be547521ac5497e15fc8f2b997611e8f8dfd9fe (diff)
downloadvaadin-framework-cfe6e9b760b34ebb2ea1bbaf9531cbba2dc2ac5c.tar.gz
vaadin-framework-cfe6e9b760b34ebb2ea1bbaf9531cbba2dc2ac5c.zip
Provide sizing information for paintables (#8313)
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/VPaintableWidget.java54
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java57
2 files changed, 109 insertions, 2 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java b/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java
index a66129fd87..6b9e97b2de 100644
--- a/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java
+++ b/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java
@@ -31,4 +31,58 @@ public interface VPaintableWidget extends VPaintable {
public VPaintableWidgetContainer getParent();
public MeasuredSize getMeasuredSize();
+
+ /**
+ * Returns <code>true</code> if the width of this paintable is currently
+ * undefined. If the width is undefined, the actual width of the paintable
+ * is defined by its contents.
+ *
+ * @return <code>true</code> if the width is undefined, else
+ * <code>false</code>
+ */
+ public boolean isUndefinedWidth();
+
+ /**
+ * Returns <code>true</code> if the height of this paintable is currently
+ * undefined. If the height is undefined, the actual height of the paintable
+ * is defined by its contents.
+ *
+ * @return <code>true</code> if the height is undefined, else
+ * <code>false</code>
+ */
+ public boolean isUndefinedHeight();
+
+ /**
+ * Returns <code>true</code> if the width of this paintable is currently
+ * relative. If the width is relative, the actual width of the paintable is
+ * a percentage of the size allocated to it by its parent.
+ *
+ * @return <code>true</code> if the width is undefined, else
+ * <code>false</code>
+ */
+ public boolean isRelativeWidth();
+
+ /**
+ * Returns <code>true</code> if the height of this paintable is currently
+ * relative. If the height is relative, the actual height of the paintable
+ * is a percentage of the size allocated to it by its parent.
+ *
+ * @return <code>true</code> if the width is undefined, else
+ * <code>false</code>
+ */
+ public boolean isRelativeHeight();
+
+ /**
+ * Gets the width of this paintable as defined on the server.
+ *
+ * @return the server side width definition
+ */
+ public String getDefinedWidth();
+
+ /**
+ * Gets the height of this paintable as defined on the server.
+ *
+ * @return the server side height definition
+ */
+ public String getDefinedHeight();
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
index e45387a116..7941da04b7 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
@@ -8,6 +8,7 @@ import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.MeasureManager;
import com.vaadin.terminal.gwt.client.MeasureManager.MeasuredSize;
import com.vaadin.terminal.gwt.client.TooltipInfo;
import com.vaadin.terminal.gwt.client.UIDL;
@@ -24,12 +25,15 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
private ApplicationConnection connection;
private String id;
- private final MeasuredSize measuredSize = new MeasuredSize();
+ private final MeasuredSize measuredSize = new MeasuredSize(this);
/* State variables */
private boolean enabled = true;
private boolean visible = true;
+ private String definedWidth = "";
+ private String definedHeight = "";
+
/**
* Default constructor
*/
@@ -183,7 +187,56 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
* taken into account
*/
- getConnection().updateComponentSize(this, uidl);
+ updateComponentSize(uidl);
+ }
+
+ private void updateComponentSize(UIDL uidl) {
+ String w = uidl.hasAttribute("width") ? uidl
+ .getStringAttribute("width") : "";
+
+ String h = uidl.hasAttribute("height") ? uidl
+ .getStringAttribute("height") : "";
+
+ // Dirty if either dimension changed between relative and non-relative
+ MeasureManager.MeasuredSize measuredSize = getMeasuredSize();
+ if (!measuredSize.isDirty()
+ && (w.endsWith("%") != definedWidth.endsWith("%") || h
+ .endsWith("%") != definedHeight.endsWith("%"))) {
+ measuredSize.setDirty(true);
+ }
+
+ definedWidth = w;
+ definedHeight = h;
+
+ // Set defined sizes
+ Widget component = getWidgetForPaintable();
+
+ component.setHeight(h);
+ component.setWidth(w);
+ }
+
+ public boolean isRelativeHeight() {
+ return definedHeight.endsWith("%");
+ }
+
+ public boolean isRelativeWidth() {
+ return definedWidth.endsWith("%");
+ }
+
+ public boolean isUndefinedHeight() {
+ return definedHeight.length() == 0;
+ }
+
+ public boolean isUndefinedWidth() {
+ return definedWidth.length() == 0;
+ }
+
+ public String getDefinedHeight() {
+ return definedHeight;
+ }
+
+ public String getDefinedWidth() {
+ return definedWidth;
}
/**