From: Artur Signell Date: Tue, 21 Oct 2008 08:24:34 +0000 (+0000) Subject: Fixed #2156 IE Panel problems X-Git-Tag: 6.7.0.beta1~3965 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e6e4c08561341cba126d680519df09ca5850408f;p=vaadin-framework.git Fixed #2156 IE Panel problems Added caption size change detection Fixed caption width calculation and clipping svn changeset:5679/svn branch:trunk --- diff --git a/WebContent/ITMILL/themes/default/styles.css b/WebContent/ITMILL/themes/default/styles.css index b069d9dd16..387f0edec9 100644 --- a/WebContent/ITMILL/themes/default/styles.css +++ b/WebContent/ITMILL/themes/default/styles.css @@ -38,6 +38,7 @@ .i-button { cursor: pointer; font-size: 13px; + white-space: nowrap; } .i-button img { @@ -108,10 +109,9 @@ } .i-errorindicator { - width: 10px; + width: 12px; height: 16px; - padding-right:13px; - display: inline; + float: left; background: transparent url(icons/16/error.png) no-repeat top right; } @@ -123,7 +123,6 @@ *+html .i-errorindicator { margin-left:-3px; } - .i-caption .i-icon { padding-right: 2px; vertical-align: middle; @@ -926,7 +925,7 @@ input.i-modified, } .i-orderedlayout-vspacing { - margin-top: 8px; + padding-top: 8px; } .i-orderedlayout-hspacing { padding-left: 8px; @@ -1219,16 +1218,13 @@ input.i-modified, .i-filterselect { height: 23px; - background: transparent url(select/img/bg-left-filter.png) no-repeat; - margin-right: 1px; white-space: nowrap; text-align: left /* Force default alignment */ } .i-filterselect-input { - width: 99%; + background: transparent url(select/img/bg-left-filter.png) no-repeat; border: none; - background: transparent; height: 20px; margin: 0; padding: 3px 0 0 4px; @@ -1241,7 +1237,7 @@ input.i-modified, .i-filterselect-button { float: right; - margin: -23px -1px 0 0; + margin-left: -23px; width: 25px; height: 23px; cursor: pointer; diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java index 00b72f9a42..28a6700bb3 100755 --- a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java @@ -121,6 +121,7 @@ public class ApplicationConnection { private int sessionExpirationInterval; private ArrayList relativeSizeChanges = new ArrayList();; + private ArrayList captionSizeChanges = new ArrayList();; public ApplicationConnection(WidgetSet widgetSet, ApplicationConfiguration cnf) { @@ -556,6 +557,7 @@ public class ApplicationConnection { Vector updatedWidgets = new Vector(); relativeSizeChanges.clear(); + captionSizeChanges.clear(); for (int i = 0; i < changes.size(); i++) { try { @@ -596,6 +598,7 @@ public class ApplicationConnection { Set sizeUpdatedWidgets = new HashSet(); updatedWidgets.addAll(relativeSizeChanges); + sizeUpdatedWidgets.addAll(captionSizeChanges); for (Widget widget : updatedWidgets) { Size oldSize = componentOffsetSizes.get(widget); @@ -1378,4 +1381,8 @@ public class ApplicationConnection { public void setWindowName(String newName) { windowName = newName; } + + public void captionSizeUpdated(Widget component) { + captionSizeChanges.add(component); + } } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ICaption.java b/src/com/itmill/toolkit/terminal/gwt/client/ICaption.java index 1033c128c2..ecfb9f0c61 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ICaption.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ICaption.java @@ -227,17 +227,33 @@ public class ICaption extends HTML { public int getWidth() { int width = 0; + if (icon != null) { width += icon.getOffsetWidth(); } - if (captionText != null) { - width += captionText.getOffsetWidth(); - } - if (requiredFieldIndicator != null) { - width += requiredFieldIndicator.getOffsetWidth(); - } - if (errorIndicatorElement != null) { - width += errorIndicatorElement.getOffsetWidth(); + + if (maxWidth >= 0) { + if (captionText != null) { + width += captionText.getOffsetWidth(); + } + if (requiredFieldIndicator != null) { + width += requiredFieldIndicator.getOffsetWidth(); + } + if (errorIndicatorElement != null) { + width += errorIndicatorElement.getOffsetWidth(); + } + + } else { + if (captionText != null) { + width += captionText.getScrollWidth(); + } + if (requiredFieldIndicator != null) { + width += requiredFieldIndicator.getScrollWidth(); + } + if (errorIndicatorElement != null) { + width += errorIndicatorElement.getScrollWidth(); + } + } return width; diff --git a/src/com/itmill/toolkit/terminal/gwt/client/Util.java b/src/com/itmill/toolkit/terminal/gwt/client/Util.java index 69b62ede74..edfae1e55e 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/Util.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/Util.java @@ -46,6 +46,8 @@ public class Util { Map> childWidgets = new HashMap>(); for (Widget widget : widgets) { +// ApplicationConnection.getConsole().log( +// "Widget " + Util.getSimpleName(widget) + " size updated"); Widget parent = widget.getParent(); while (parent != null && !(parent instanceof Container)) { parent = parent.getParent(); @@ -204,6 +206,37 @@ public class Util { return padding; } + public static int measureHorizontalBorder(Element element) { + int borders; + if (BrowserInfo.get().isIE6()) { + String originalWidth = DOM.getStyleAttribute(element, "width"); + int originalOffsetWidth = element.getOffsetWidth(); + DOM.setStyleAttribute(element, "width", originalOffsetWidth + "px"); + borders = element.getOffsetWidth() + - element.getPropertyInt("clientWidth"); + + DOM.setStyleAttribute(element, "width", originalWidth); + } else { + borders = element.getOffsetWidth() + - element.getPropertyInt("clientWidth"); + } + assert borders >= 0; + + return borders; + } + + public static int measureVerticalBorder(Element element) { + int borders = element.getOffsetHeight() + - element.getPropertyInt("clientHeight"); + assert borders >= 0; + return borders; + } + + public static int measureMarginLeft(Element element) { + return element.getAbsoluteLeft() + - element.getParentElement().getAbsoluteLeft(); + } + public static void setWidthExcludingPadding(Element element, int requestedWidth, int paddingGuess) { 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 fc6f35e7a8..7ca5f56aac 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java @@ -128,6 +128,7 @@ public class IOrderedLayout extends CellBasedLayout { /* Fetch alignments and expand ratio from UIDL */ updateAlignmentsAndExpandRatios(uidl, uidlWidgets); + // w.mark("Alignments and expand ratios updated"); /* Fetch widget sizes from rendered components */ for (ChildComponentContainer childComponentContainer : widgetToComponentContainer @@ -138,8 +139,12 @@ public class IOrderedLayout extends CellBasedLayout { */ childComponentContainer.updateWidgetSize(); } + // w.mark("Widget sizes updated"); recalculateLayout(); + // w.mark("Layout size calculated (" + activeLayoutSize + + // ") offsetSize: " + // + getOffsetWidth() + "," + getOffsetHeight()); /* Render relative size components */ for (int i = 0; i < relativeSizeComponents.size(); i++) { @@ -151,6 +156,9 @@ public class IOrderedLayout extends CellBasedLayout { // childComponentContainer.updateWidgetSize(); } + // w.mark("Rendering of " + (relativeSizeComponents.size()) + // + " relative size components done"); + /* Fetch widget sizes for relative size components */ for (ChildComponentContainer childComponentContainer : widgetToComponentContainer .values()) { @@ -159,8 +167,10 @@ public class IOrderedLayout extends CellBasedLayout { childComponentContainer.updateWidgetSize(); } - // w.mark("Rendering of " + (relativeSizeComponents.size()) - // + " relative size components done"); + // w.mark("Widget sizes updated"); + + /* Update component spacing */ + updateContainerMargins(); /* Recalculate component sizes and alignments */ recalculateComponentSizesAndAlignments(); @@ -241,8 +251,6 @@ public class IOrderedLayout extends CellBasedLayout { return; } - updateContainerMargins(); - /* * Update the height of relative height components in a horizontal * layout or the width for relative width components in a vertical @@ -286,17 +294,18 @@ public class IOrderedLayout extends CellBasedLayout { int widgetWidth = s.getWidth() + childComponentContainer.getCaptionWidthAfterComponent(); - if (isDynamicWidth()) { - /* - * For a dynamic width layout the max of caption/widget defines - * the required size - */ + /* + * If the component does not have a specified size in the main + * direction the caption may determine the space used by the + * component + */ + if (!childComponentContainer.widgetHasSizeSpecified(orientation)) { int captionWidth = childComponentContainer.getCaptionWidth(); if (captionWidth > widgetWidth) { widgetWidth = captionWidth; } } - + int widgetHeight = s.getHeight() + childComponentContainer.getCaptionHeightAboveComponent(); @@ -383,10 +392,19 @@ public class IOrderedLayout extends CellBasedLayout { width = childComponentContainer.getWidgetSize().getWidth() + childComponentContainer .getCaptionWidthAfterComponent(); - int captionWidth = childComponentContainer - .getCaptionWidth(); - if (captionWidth > width) { - width = captionWidth; + + /* + * If the component does not have a specified size in the + * main direction the caption may determine the space used + * by the component + */ + if (!childComponentContainer + .widgetHasSizeSpecified(orientation)) { + int captionWidth = childComponentContainer + .getCaptionWidth(); + if (captionWidth > width) { + width = captionWidth; + } } } else { width = 0; @@ -484,6 +502,10 @@ public class IOrderedLayout extends CellBasedLayout { } + /** + * Updates the spacing between components. Needs to be done only when + * components are added/removed. + */ private void updateContainerMargins() { ChildComponentContainer firstChildComponent = getFirstChildComponentContainer(); @@ -636,4 +658,16 @@ public class IOrderedLayout extends CellBasedLayout { } } + public void updateCaption(Paintable component, UIDL uidl) { + ChildComponentContainer componentContainer = getComponentContainer((Widget) component); + componentContainer.updateCaption(uidl, client); + if (!isRendering) { + /* + * This was a component-only update and the possible size change + * must be propagated to the layout + */ + client.captionSizeUpdated((Widget) component); + } + } + } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java index 2847900a88..546d481ec5 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java @@ -65,6 +65,10 @@ public class IPanel extends SimplePanel implements Container, private int borderPaddingVertical = -1; + private int captionPaddingHorizontal = -1; + + private int captionMarginLeft = -1; + public IPanel() { super(); DOM.appendChild(getElement(), captionNode); @@ -166,9 +170,9 @@ public class IPanel extends SimplePanel implements Container, } layout.updateFromUIDL(layoutUidl, client); - - if (BrowserInfo.get().isIE7()) { - // IE is not able to make the offsetWidth for contentNode correct for some reason... + if (BrowserInfo.get().isIE()) { + // IE is not able to make the offsetWidth for contentNode correct + // for some reason... iLayout(false); } // We may have actions attached to this panel @@ -249,8 +253,6 @@ public class IPanel extends SimplePanel implements Container, } public void iLayout(boolean runGeckoFix) { - renderInformation.updateSize(getElement()); - if (BrowserInfo.get().isIE6() && width != null && !width.equals("")) { /* * IE6 requires overflow-hidden elements to have a width specified @@ -271,10 +273,8 @@ public class IPanel extends SimplePanel implements Container, int parentWidthExcludingPadding = getElement().getOffsetWidth() - parentPadding; - int captionMarginLeft = captionNode.getAbsoluteLeft() - - getElement().getAbsoluteLeft(); Util.setWidthExcludingPadding(captionNode, - parentWidthExcludingPadding - captionMarginLeft, 26); + parentWidthExcludingPadding - getCaptionMarginLeft(), 26); int contentMarginLeft = contentNode.getAbsoluteLeft() - getElement().getAbsoluteLeft(); @@ -284,21 +284,15 @@ public class IPanel extends SimplePanel implements Container, } - if (BrowserInfo.get().isIE7() && (width == null || width.equals(""))) { - //FIXME This won't work if the panel's content gets narrower later on... - int captionMarginLeft = captionNode.getAbsoluteLeft() - - getElement().getAbsoluteLeft(); - int captionWidth = captionNode.getOffsetWidth() + captionMarginLeft; - int contentWidth = contentNode.getOffsetWidth(); + if (BrowserInfo.get().isIE() && (width == null || width.equals(""))) { + int captionWidth = captionText.getOffsetWidth() + + getCaptionMarginLeft() + getCaptionPaddingHorizontal(); int layoutWidth = ((Widget) layout).getOffsetWidth() + getContainerBorderWidth(); - int width = contentWidth; + int width = layoutWidth; if (captionWidth > width) { width = captionWidth; } - if (layoutWidth > width) { - width = layoutWidth; - } super.setWidth(width + "px"); } @@ -396,6 +390,20 @@ public class IPanel extends SimplePanel implements Container, } } + private int getCaptionMarginLeft() { + if (captionMarginLeft < 0) { + detectContainerBorders(); + } + return captionMarginLeft; + } + + private int getCaptionPaddingHorizontal() { + if (captionPaddingHorizontal < 0) { + detectContainerBorders(); + } + return captionPaddingHorizontal; + } + private int getContainerBorderHeight() { if (borderPaddingVertical < 0) { detectContainerBorders(); @@ -420,14 +428,17 @@ public class IPanel extends SimplePanel implements Container, private void detectContainerBorders() { DOM.setStyleAttribute(contentNode, "overflow", "hidden"); - borderPaddingHorizontal = contentNode.getOffsetWidth() - - contentNode.getPropertyInt("clientWidth"); - assert borderPaddingHorizontal >= 0; - borderPaddingVertical = contentNode.getOffsetHeight() - - contentNode.getPropertyInt("clientHeight"); - assert borderPaddingVertical >= 0; + + borderPaddingHorizontal = Util.measureHorizontalBorder(contentNode); + borderPaddingVertical = Util.measureVerticalBorder(contentNode); DOM.setStyleAttribute(contentNode, "overflow", "auto"); + + captionPaddingHorizontal = Util.measureHorizontalPadding(captionNode, + 26); + + captionMarginLeft = Util.measureMarginLeft(captionNode); + } public boolean hasChildComponent(Widget component) { @@ -478,6 +489,7 @@ public class IPanel extends SimplePanel implements Container, */ return true; } + iLayout(false); return !renderInformation.updateSize(getElement()); } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/CellBasedLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/CellBasedLayout.java index 121cdf9ad8..47c96f3522 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/CellBasedLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/CellBasedLayout.java @@ -9,7 +9,6 @@ import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.Widget; import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; import com.itmill.toolkit.terminal.gwt.client.Container; -import com.itmill.toolkit.terminal.gwt.client.Paintable; import com.itmill.toolkit.terminal.gwt.client.UIDL; import com.itmill.toolkit.terminal.gwt.client.ui.MarginInfo; @@ -91,11 +90,6 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container throw new UnsupportedOperationException(); } - public void updateCaption(Paintable component, UIDL uidl) { - ChildComponentContainer componentContainer = getComponentContainer((Widget) component); - componentContainer.updateCaption(uidl, client); - } - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { this.client = client; @@ -253,8 +247,8 @@ public abstract class CellBasedLayout extends ComplexPanel implements Container spacingFromCSS.vSpacing = measurement.getOffsetHeight() - 1; spacingFromCSS.hSpacing = measurement.getOffsetWidth() - 1; - ApplicationConnection.getConsole().log("Margins: " + marginsFromCSS); - ApplicationConnection.getConsole().log("Spacing: " + spacingFromCSS); + // ApplicationConnection.getConsole().log("Margins: " + marginsFromCSS); + // ApplicationConnection.getConsole().log("Spacing: " + spacingFromCSS); root.removeChild(measurement); diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/ChildComponentContainer.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/ChildComponentContainer.java index 81c41a5949..dc381227f7 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/ChildComponentContainer.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/layout/ChildComponentContainer.java @@ -29,6 +29,10 @@ public class ChildComponentContainer extends Panel { * Size of the widget inside the container DIV */ private Size widgetSize = new Size(0, 0); + /** + * Size of the caption + */ + private Size captionSize = new Size(0, 0); /** * Padding added to the container when it is larger than the component. @@ -208,7 +212,7 @@ public class ChildComponentContainer extends Panel { return 0; } - return caption.getWidth(); + return captionSize.getWidth(); } public int getCaptionHeight() { @@ -216,7 +220,7 @@ public class ChildComponentContainer extends Panel { return 0; } - return caption.getHeight(); + return captionSize.getHeight(); } public int getCaptionWidthAfterComponent() { @@ -224,7 +228,7 @@ public class ChildComponentContainer extends Panel { return 0; } - return caption.getWidth(); + return getCaptionWidth(); } public int getCaptionHeightAboveComponent() { @@ -232,7 +236,7 @@ public class ChildComponentContainer extends Panel { return 0; } - return caption.getHeight(); + return getCaptionHeight(); } public int calculateVerticalAlignmentTopOffset(int emptySpace) { @@ -250,7 +254,7 @@ public class ChildComponentContainer extends Panel { .getHeight()); } else { emptySpace -= widgetSize.getHeight(); - emptySpace -= caption.getHeight(); + emptySpace -= getCaptionHeight(); } } else { /* @@ -293,14 +297,14 @@ public class ChildComponentContainer extends Panel { */ captionSpace = 0; widgetSpace -= widgetSize.getWidth(); - widgetSpace -= caption.getWidth(); + widgetSpace -= getCaptionWidth(); } else { /* * The caption is above the component. Caption and widget needs * separate alignment offsets. */ widgetSpace -= widgetSize.getWidth(); - captionSpace -= caption.getWidth(); + captionSpace -= getCaptionWidth(); } } else { /* @@ -361,6 +365,16 @@ public class ChildComponentContainer extends Panel { } + int w = 0; + int h = 0; + + if (caption != null) { + w = caption.getWidth(); + h = caption.getHeight(); + } + + captionSize.setWidth(w); + captionSize.setHeight(h); } private void setCaption(ICaption newCaption) { @@ -501,6 +515,22 @@ public class ChildComponentContainer extends Panel { return widget; } + /** + * Return true if the size of the widget has been specified in the selected + * orientation. + * + * @return + */ + public boolean widgetHasSizeSpecified(int orientation) { + String size; + if (orientation == CellBasedLayout.ORIENTATION_HORIZONTAL) { + size = widget.getElement().getStyle().getProperty("width"); + } else { + size = widget.getElement().getStyle().getProperty("height"); + } + return (size != null && !size.equals("")); + } + public boolean isComponentRelativeSized(int orientation) { if (relativeSize == null) { return false; @@ -606,6 +636,8 @@ public class ChildComponentContainer extends Panel { // Also update caption max width if (caption != null) { caption.setMaxWidth(width); + + captionSize.setWidth(caption.getWidth()); } }