From ea87dcb23565b3f21631cec8875eaf634c5963ca Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 24 Aug 2015 21:13:14 +0300 Subject: [PATCH] Measure width exactly to avoid white padding at the right edge (#18648) Change-Id: Iaeb5fc84f08746967f664466c3e2e7d09d76e0cc --- .../src/com/vaadin/client/ComputedStyle.java | 27 +++++++++++++++++++ .../com/vaadin/client/ui/VFilterSelect.java | 13 ++++----- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/client/src/com/vaadin/client/ComputedStyle.java b/client/src/com/vaadin/client/ComputedStyle.java index cd90e0e78b..676d18d245 100644 --- a/client/src/com/vaadin/client/ComputedStyle.java +++ b/client/src/com/vaadin/client/ComputedStyle.java @@ -331,4 +331,31 @@ public class ComputedStyle { return paddingWidth; } + + /** + * Returns the sum of the top and bottom margin + * + * @since + * @return the sum of the top and bottom margin + */ + public double getMarginHeight() { + double marginHeight = getDoubleProperty("marginTop"); + marginHeight += getDoubleProperty("marginBottom"); + + return marginHeight; + } + + /** + * Returns the sum of the top and bottom margin + * + * @since + * @return the sum of the left and right margin + */ + public double getMarginWidth() { + double marginWidth = getDoubleProperty("marginLeft"); + marginWidth += getDoubleProperty("marginRight"); + + return marginWidth; + } + } diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java index d756c88f79..cf03382333 100644 --- a/client/src/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/VFilterSelect.java @@ -617,14 +617,15 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, // Must take margin,border,padding manually into account for // menu element as we measure the element child and set width to // the element parent - int naturalMenuOuterWidth = naturalMenuWidth + double naturalMenuOuterWidth = WidgetUtil + .getRequiredWidthDouble(menuFirstChild) + getMarginBorderPaddingWidth(menu.getElement()); /* * IE requires us to specify the width for the container * element. Otherwise it will be 100% wide */ - int rootWidth = Math.max(desiredWidth - popupOuterPadding, + double rootWidth = Math.max(desiredWidth - popupOuterPadding, naturalMenuOuterWidth); getContainerElement().getStyle().setWidth(rootWidth, Unit.PX); } @@ -1291,13 +1292,9 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, sinkEvents(Event.ONPASTE); } - private static int getMarginBorderPaddingWidth(Element element) { + private static double getMarginBorderPaddingWidth(Element element) { final ComputedStyle s = new ComputedStyle(element); - int[] margin = s.getMargin(); - int[] border = s.getBorder(); - int[] padding = s.getPadding(); - return margin[1] + margin[3] + border[1] + border[3] + padding[1] - + padding[3]; + return s.getMarginWidth() + s.getBorderWidth() + s.getPaddingWidth(); } -- 2.39.5