From 12b8c054a606fe310176d1e30335e9991657a06e Mon Sep 17 00:00:00 2001 From: Joonas Lehtinen Date: Fri, 22 Aug 2008 09:57:20 +0000 Subject: [PATCH] Fixed #1904 : IOrderedLayout spacing and margincs should be specifiable in CSS svn changeset:5245/svn branch:trunk --- .../default/orderedlayout/orderedlayout.css | 9 +- WebContent/ITMILL/themes/default/styles.css | 9 +- .../gwt/client/ui/IOrderedLayout.java | 105 +++++++++++++++--- 3 files changed, 92 insertions(+), 31 deletions(-) diff --git a/WebContent/ITMILL/themes/default/orderedlayout/orderedlayout.css b/WebContent/ITMILL/themes/default/orderedlayout/orderedlayout.css index cc66eda0b7..9b18933db5 100644 --- a/WebContent/ITMILL/themes/default/orderedlayout/orderedlayout.css +++ b/WebContent/ITMILL/themes/default/orderedlayout/orderedlayout.css @@ -1,9 +1,4 @@ -. -/* Ordered layout spacing and margins are currently fixed. - This is considered to be a bug. For more info, see - http://dev.itmill.com/ticket/1904 - -i-orderedlayout-margin-top { +.i-orderedlayout-margin-top { padding-top: 15px; } .i-orderedlayout-margin-right { @@ -23,8 +18,6 @@ i-orderedlayout-margin-top { padding-left: 8px; } -*/ - /* Placing error indicator right after the widget with empty caption */ .i-orderedlayout-c * { float:left; display: block;} .i-orderedlayout-w-e { float:left;} diff --git a/WebContent/ITMILL/themes/default/styles.css b/WebContent/ITMILL/themes/default/styles.css index ba97b407d1..6db00414eb 100644 --- a/WebContent/ITMILL/themes/default/styles.css +++ b/WebContent/ITMILL/themes/default/styles.css @@ -783,12 +783,7 @@ input.i-modified, .i-Notification.system p { white-space: nowrap; } -. -/* Ordered layout spacing and margins are currently fixed. - This is considered to be a bug. For more info, see - http://dev.itmill.com/ticket/1904 - -i-orderedlayout-margin-top { +.i-orderedlayout-margin-top { padding-top: 15px; } .i-orderedlayout-margin-right { @@ -808,8 +803,6 @@ i-orderedlayout-margin-top { padding-left: 8px; } -*/ - /* Placing error indicator right after the widget with empty caption */ .i-orderedlayout-c * { float:left; display: block;} .i-orderedlayout-w-e { float:left;} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java index 236e033f1f..48594a5ec9 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java @@ -4,6 +4,7 @@ package com.itmill.toolkit.terminal.gwt.client.ui; +import java.util.HashMap; import java.util.Iterator; import java.util.Vector; @@ -37,12 +38,22 @@ public class IOrderedLayout extends Panel implements Container, public static final int ORIENTATION_VERTICAL = 0; public static final int ORIENTATION_HORIZONTAL = 1; - private int hSpacing = -1; - private int vSpacing = -1; - private int marginTop = -1; - private int marginBottom = -1; - private int marginLeft = -1; - private int marginRight = -1; + /** + * If margin and spacing values has been calculated, this holds the values + * for the given UIDL style attribute . + */ + private static HashMap measuredMargins = new HashMap(); + + /** + * Spacing. Correct values will be set in + * updateMarginAndSpacingFromCSS(UIDL) + */ + private int hSpacing, vSpacing; + + /** + * Margin. Correct values will be set in updateMarginAndSpacingFromCSS(UIDL) + */ + private int marginTop, marginBottom, marginLeft, marginRight; int orientationMode = ORIENTATION_VERTICAL; @@ -318,15 +329,79 @@ public class IOrderedLayout extends Panel implements Container, } private void updateMarginAndSpacingSizesFromCSS(UIDL uidl) { - // TODO Read spacing and margins from CSS as documented in #1904. - // Somehow refresh after updates - - hSpacing = 8; - vSpacing = 8; - marginTop = 15; - marginBottom = 15; - marginLeft = 18; - marginRight = 18; + + // Style for this layout + String style = uidl.getStringAttribute("style"); + if (style == null) { + style = ""; + } + + // Try to find measured from cache + int[] r = (int[]) measuredMargins.get(style); + + // Measure from DOM + if (r == null) { + r = new int[] { 0, 0, 0, 0, 0, 0 }; + + // Construct DOM for measurements + Element e1 = DOM.createTable(); + DOM.setStyleAttribute(e1, "position", "absolute"); + DOM.setElementProperty(e1, "cellSpacing", "0"); + DOM.setElementProperty(e1, "cellPadding", "0"); + Element e11 = DOM.createTBody(); + Element e12 = DOM.createTR(); + Element e13 = DOM.createTD(); + Element e2 = DOM.createDiv(); + Element e3 = DOM.createDiv(); + DOM.setStyleAttribute(e3, "width", "100px"); + DOM.setStyleAttribute(e3, "height", "100px"); + DOM.appendChild(getElement(), e1); + DOM.appendChild(e1, e11); + DOM.appendChild(e11, e12); + DOM.appendChild(e12, e13); + DOM.appendChild(e13, e2); + DOM.appendChild(e2, e3); + DOM.setInnerText(e3, "."); + + // Measure different properties + final String[] classes = { "margin-top", "margin-right", + "margin-bottom", "margin-left", "vspacing", "hspacing" }; + for (int c = 0; c < 6; c++) { + StringBuffer styleBuf = new StringBuffer(); + final String primaryName = getStylePrimaryName(); + styleBuf.append(primaryName + "-" + classes[c]); + if (style.length() > 0) { + final String[] styles = style.split(" "); + for (int i = 0; i < styles.length; i++) { + styleBuf.append(" "); + styleBuf.append(primaryName); + styleBuf.append("-"); + styleBuf.append(styles[i]); + styleBuf.append("-"); + styleBuf.append(classes[c]); + } + } + DOM.setElementProperty(e2, "className", styleBuf.toString()); + + // Measure + r[c] = DOM.getElementPropertyInt(e1, + (c % 2) == 1 ? "offsetWidth" : "offsetHeight") - 100; + } + + // Clean-up + DOM.removeChild(getElement(), e1); + + // Cache for further use + measuredMargins.put(style, r); + } + + // Set the properties + marginTop = r[0]; + marginRight = r[1]; + marginBottom = r[2]; + marginLeft = r[3]; + vSpacing = r[4]; + hSpacing = r[5]; } /** -- 2.39.5