From 70e58db73f06ef80b769fa30fc62ad7b70f1541c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Mon, 20 Feb 2012 16:04:06 +0200 Subject: [PATCH] PopupDateField without size calculations (#8313) --- .../themes/reindeer/datefield/datefield.css | 19 ++++- .../gwt/client/ui/VPopupCalendar.java | 14 ---- .../client/ui/VPopupCalendarPaintable.java | 9 --- .../terminal/gwt/client/ui/VTextualDate.java | 75 +------------------ 4 files changed, 16 insertions(+), 101 deletions(-) diff --git a/WebContent/VAADIN/themes/reindeer/datefield/datefield.css b/WebContent/VAADIN/themes/reindeer/datefield/datefield.css index 1dbc59257a..574a4973bf 100644 --- a/WebContent/VAADIN/themes/reindeer/datefield/datefield.css +++ b/WebContent/VAADIN/themes/reindeer/datefield/datefield.css @@ -45,6 +45,7 @@ span.v-datefield-calendarpanel-month { } .v-datefield-popupcalendar { min-width: 0; + padding-right: 24px; } .v-datefield-year .v-datefield-calendarpanel { width: 100px; @@ -224,16 +225,25 @@ td.v-datefield-calendarpanel-nextyear { .v-op .v-datefield-popup { background: rgba(255,255,255,.95); } -.v-datefield-year .v-datefield-textfield { +.v-datefield-textfield { + width: 100%; + box-sizing: border-box; + -moz-box-sizing: border-box; +} +.v-datefield.v-undefined-width > .v-datefield-textfield { + box-sizing: content-box; + -moz-box-sizing: content-box; +} +.v-datefield-year.v-undefined-width > .v-datefield-textfield { width: 4em; } -.v-datefield-month .v-datefield-textfield { +.v-datefield-month.v-undefined-width > .v-datefield-textfield { width: 5em; } -.v-datefield-day .v-datefield-textfield { +.v-datefield-day.v-undefined-width > .v-datefield-textfield { width: 5.5em; } -.v-datefield-full .v-datefield-textfield { +.v-datefield-full.v-undefined-width >.v-datefield-textfield { width: 12em; } .v-datefield-popupcalendar input.v-datefield-textfield { @@ -256,6 +266,7 @@ td.v-datefield-calendarpanel-nextyear { } .v-datefield-popupcalendar .v-datefield-button { width: 24px; + margin-right: -24px; height: 23px; background: transparent; border: none; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java index 1c0b937e05..cbd3a7af8f 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendar.java @@ -274,20 +274,6 @@ public class VPopupCalendar extends VTextualDate implements Field, calendar.setFocus(focus); } - /* - * (non-Javadoc) - * - * @see com.vaadin.terminal.gwt.client.ui.VTextualDate#getFieldExtraWidth() - */ - @Override - protected int getFieldExtraWidth() { - if (fieldExtraWidth < 0) { - fieldExtraWidth = super.getFieldExtraWidth(); - fieldExtraWidth += calendarToggle.getOffsetWidth(); - } - return fieldExtraWidth; - } - /* * (non-Javadoc) * diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendarPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendarPaintable.java index 042d730738..5beb912ff0 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendarPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupCalendarPaintable.java @@ -114,15 +114,6 @@ public class VPopupCalendarPaintable extends VTextualDatePaintable { + "-button-readonly"); } - if (lastReadOnlyState != getWidgetForPaintable().readonly - || lastEnabledState != getWidgetForPaintable().isEnabled()) { - // Enabled or readonly state changed. Differences in theming might - // affect the width (for instance if the popup button is hidden) so - // we have to recalculate the width (IF the width of the field is - // fixed) - getWidgetForPaintable().updateWidth(); - } - getWidgetForPaintable().calendarToggle.setEnabled(true); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java index bb808321b9..a19be371cf 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextualDate.java @@ -14,7 +14,6 @@ import com.google.gwt.event.dom.client.FocusEvent; import com.google.gwt.event.dom.client.FocusHandler; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.TextBox; -import com.vaadin.terminal.gwt.client.ContainerResizedListener; import com.vaadin.terminal.gwt.client.EventId; import com.vaadin.terminal.gwt.client.Focusable; import com.vaadin.terminal.gwt.client.LocaleNotLoadedException; @@ -22,7 +21,7 @@ import com.vaadin.terminal.gwt.client.LocaleService; import com.vaadin.terminal.gwt.client.VConsole; public class VTextualDate extends VDateField implements Field, ChangeHandler, - ContainerResizedListener, Focusable, SubPartAware { + Focusable, SubPartAware { private static final String PARSE_ERROR_CLASSNAME = CLASSNAME + "-parseerror"; @@ -31,12 +30,6 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, protected String formatStr; - private String width; - - private boolean needLayout; - - protected int fieldExtraWidth = -1; - protected boolean lenient; private static final String CLASSNAME_PROMPT = "prompt"; @@ -295,72 +288,6 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, return format.trim(); } - @Override - public void setWidth(String newWidth) { - if (!"".equals(newWidth) - && (isUndefinedWidth() || !newWidth.equals(width))) { - needLayout = true; - width = newWidth; - super.setWidth(width); - iLayout(); - if (newWidth.indexOf("%") < 0) { - needLayout = false; - } - } else { - if ("".equals(newWidth) && !isUndefinedWidth()) { - super.setWidth(""); - iLayout(true); - width = null; - } - } - } - - protected boolean isUndefinedWidth() { - return width == null || "".equals(width); - } - - /** - * Returns pixels in x-axis reserved for other than textfield content. - * - * @return extra width in pixels - */ - protected int getFieldExtraWidth() { - if (fieldExtraWidth < 0) { - text.setWidth("0"); - fieldExtraWidth = text.getOffsetWidth(); - } - return fieldExtraWidth; - } - - /** - * Force an recalculation of the width of the component IF the width has - * been defined. Does nothing if width is undefined as the width will be - * automatically adjusted by the browser. - */ - public void updateWidth() { - if (isUndefinedWidth()) { - return; - } - needLayout = true; - fieldExtraWidth = -1; - iLayout(true); - } - - public void iLayout() { - iLayout(false); - } - - public void iLayout(boolean force) { - if (needLayout || force) { - int textFieldWidth = getOffsetWidth() - getFieldExtraWidth(); - if (textFieldWidth < 0) { - // Field can never be smaller than 0 (causes exception in IE) - textFieldWidth = 0; - } - text.setWidth(textFieldWidth + "px"); - } - } - public void focus() { text.setFocus(true); } -- 2.39.5