From: Artur Signell Date: Tue, 7 Aug 2012 11:44:18 +0000 (+0000) Subject: Refactoring based on review (#6219) X-Git-Tag: 7.0.0.beta1~79^2~37 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=acde6c0f95a86c2819f34616d8102ade90044c3a;p=vaadin-framework.git Refactoring based on review (#6219) svn changeset:24093/svn branch:6.8 --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java index d89cec9ad6..04374f357e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java @@ -793,7 +793,7 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, contentWidth + Util.getNativeScrollbarSize(), Unit.PX); } - popup.sizeOrPositionUpdated(); + popup.positionOrSizeUpdated(); } } return top; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNotification.java b/src/com/vaadin/terminal/gwt/client/ui/VNotification.java index e56a458147..ca4c99be01 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNotification.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNotification.java @@ -154,7 +154,7 @@ public class VNotification extends VOverlay { super.show(); notifications.add(this); setPosition(position); - sizeOrPositionUpdated(); + positionOrSizeUpdated(); /** * Android 4 fails to render notifications correctly without a little * nudge (#8551) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java b/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java index f385aa0676..60829f1cc8 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java @@ -30,6 +30,14 @@ public class VOverlay extends PopupPanel implements CloseHandler { public static class PositionAndSize { private int left, top, width, height; + public PositionAndSize(int left, int top, int width, int height) { + super(); + setLeft(left); + setTop(top); + setWidth(width); + setHeight(height); + } + public int getLeft() { return left; } @@ -51,6 +59,10 @@ public class VOverlay extends PopupPanel implements CloseHandler { } public void setWidth(int width) { + if (width < 0) { + width = 0; + } + this.width = width; } @@ -59,6 +71,10 @@ public class VOverlay extends PopupPanel implements CloseHandler { } public void setHeight(int height) { + if (height < 0) { + height = 0; + } + this.height = height; } @@ -224,7 +240,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { style.setMarginLeft(-adjustByRelativeLeftBodyMargin(), Unit.PX); style.setMarginTop(-adjustByRelativeTopBodyMargin(), Unit.PX); super.setPopupPosition(left, top); - sizeOrPositionUpdated(isAnimationEnabled() ? 0 : 1); + positionOrSizeUpdated(isAnimationEnabled() ? 0 : 1); } private IFrameElement getShimElement() { @@ -316,7 +332,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { if (isAnimationEnabled()) { new ResizeAnimation().run(POPUP_PANEL_ANIMATION_DURATION); } else { - sizeOrPositionUpdated(1.0); + positionOrSizeUpdated(1.0); } Util.runIE7ZeroSizedBodyFix(); } @@ -348,13 +364,13 @@ public class VOverlay extends PopupPanel implements CloseHandler { @Override public void setWidth(String width) { super.setWidth(width); - sizeOrPositionUpdated(1.0); + positionOrSizeUpdated(1.0); } @Override public void setHeight(String height) { super.setHeight(height); - sizeOrPositionUpdated(1.0); + positionOrSizeUpdated(1.0); } /** @@ -378,15 +394,15 @@ public class VOverlay extends PopupPanel implements CloseHandler { * size of overlay without using normal 'setWidth(String)' and * 'setHeight(String)' methods (if not calling super.setWidth/Height). * - * @deprecated Call {@link #sizeOrPositionUpdated()} instead. + * @deprecated Call {@link #positionOrSizeUpdated()} instead. */ @Deprecated protected void updateShadowSizeAndPosition() { - sizeOrPositionUpdated(); + positionOrSizeUpdated(); } - protected void sizeOrPositionUpdated() { - sizeOrPositionUpdated(1.0); + protected void positionOrSizeUpdated() { + positionOrSizeUpdated(1.0); } /** @@ -399,7 +415,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { * A value between 0.0 and 1.0, indicating the progress of the * animation (0=start, 1=end). */ - private void sizeOrPositionUpdated(final double progress) { + private void positionOrSizeUpdated(final double progress) { // Don't do anything if overlay element is not attached if (!isAttached()) { return; @@ -424,18 +440,8 @@ public class VOverlay extends PopupPanel implements CloseHandler { getOffsetWidth(); } - PositionAndSize positionAndSize = new PositionAndSize(); - positionAndSize.left = getActualLeft(); - positionAndSize.top = getActualTop(); - positionAndSize.width = getOffsetWidth(); - positionAndSize.height = getOffsetHeight(); - - if (positionAndSize.width < 0) { - positionAndSize.width = 0; - } - if (positionAndSize.height < 0) { - positionAndSize.height = 0; - } + PositionAndSize positionAndSize = new PositionAndSize(getActualLeft(), + getActualTop(), getOffsetWidth(), getOffsetHeight()); // Animate the size positionAndSize.setAnimationFromCenterProgress(progress); @@ -452,12 +458,12 @@ public class VOverlay extends PopupPanel implements CloseHandler { // Update correct values if (isShadowEnabled()) { - updateSizeAndPosition(shadow, positionAndSize); + updatePositionAndSize(shadow, positionAndSize); DOM.setStyleAttribute(shadow, "zIndex", zIndex); DOM.setStyleAttribute(shadow, "display", progress < 0.9 ? "none" : ""); } - updateSizeAndPosition((Element) Element.as(getShimElement()), + updatePositionAndSize((Element) Element.as(getShimElement()), positionAndSize); // Opera fix, part 2 (ticket #2704) @@ -489,18 +495,18 @@ public class VOverlay extends PopupPanel implements CloseHandler { } - private void updateSizeAndPosition(Element e, + private void updatePositionAndSize(Element e, PositionAndSize positionAndSize) { - e.getStyle().setLeft(positionAndSize.left, Unit.PX); - e.getStyle().setTop(positionAndSize.top, Unit.PX); - e.getStyle().setWidth(positionAndSize.width, Unit.PX); - e.getStyle().setHeight(positionAndSize.height, Unit.PX); + e.getStyle().setLeft(positionAndSize.getLeft(), Unit.PX); + e.getStyle().setTop(positionAndSize.getTop(), Unit.PX); + e.getStyle().setWidth(positionAndSize.getWidth(), Unit.PX); + e.getStyle().setHeight(positionAndSize.getHeight(), Unit.PX); } protected class ResizeAnimation extends Animation { @Override protected void onUpdate(double progress) { - sizeOrPositionUpdated(progress); + positionOrSizeUpdated(progress); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java index 6a46d64c5a..280ca720fc 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java @@ -477,7 +477,7 @@ public class VPopupView extends HTML implements Container, Iterable { } public boolean requestLayout(Set child) { - popup.sizeOrPositionUpdated(); + popup.positionOrSizeUpdated(); return true; }