]> source.dussan.org Git - vaadin-framework.git/commitdiff
Removed unnessesary pixel calculations from AbsoluteLayout #11177
authorJohn Ahlroos <john@vaadin.com>
Thu, 21 Mar 2013 14:06:34 +0000 (16:06 +0200)
committerVaadin Code Review <review@vaadin.com>
Wed, 3 Apr 2013 07:57:13 +0000 (07:57 +0000)
Change-Id: Ib3f8b48e5712e895abab159616aa1b2a1ec589c8

client/src/com/vaadin/client/ui/VAbsoluteLayout.java
client/src/com/vaadin/client/ui/absolutelayout/AbsoluteLayoutConnector.java

index 88fbae6e88feca913a302bcaf290623bd12cd47e..ee5d1f039ac7240129d0c894c42b9097728f5558 100644 (file)
@@ -18,7 +18,6 @@ package com.vaadin.client.ui;
 import com.google.gwt.dom.client.DivElement;
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.Style;
-import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.ui.ComplexPanel;
@@ -304,110 +303,45 @@ public class VAbsoluteLayout extends ComplexPanel {
      * is added or removed
      */
     public void layoutVertically() {
+        layout();
+    }
+
+    /**
+     * Performs an horizontal layout. Should be called when a widget is add or
+     * removed
+     */
+    public void layoutHorizontally() {
+        layout();
+    }
+
+    private void layout() {
         for (Widget widget : getChildren()) {
             if (widget instanceof AbsoluteWrapper) {
                 AbsoluteWrapper wrapper = (AbsoluteWrapper) widget;
-
-                /*
-                 * Cleanup old wrappers which have been left empty by other
-                 * inner layouts moving the widget from the wrapper into their
-                 * own hierarchy. This usually happens when a call to
-                 * setWidget(widget) is done in an inner layout which
-                 * automatically detaches the widget from the parent, in this
-                 * case the wrapper, and re-attaches it somewhere else. This has
-                 * to be done in the layout phase since the order of the
-                 * hierarchy events are not defined.
-                 */
-                if (wrapper.getWidget() == null) {
-                    wrapper.destroy();
-                    super.remove(wrapper);
-                    continue;
-                }
-
-                Style wrapperStyle = wrapper.getElement().getStyle();
-                Style widgetStyle = wrapper.getWidget().getElement().getStyle();
-
-                // Ensure previous heights do not affect the measures
-                wrapperStyle.clearHeight();
-
-                if (widgetStyle.getHeight() != null
-                        && widgetStyle.getHeight().endsWith("%")) {
-                    int h;
-                    if (wrapper.top != null && wrapper.bottom != null) {
-                        h = wrapper.getOffsetHeight();
-                    } else if (wrapper.bottom != null) {
-                        // top not defined, available space 0... bottom of
-                        // wrapper
-                        h = wrapper.getElement().getOffsetTop()
-                                + wrapper.getOffsetHeight();
-                    } else {
-                        // top defined or both undefined, available space ==
-                        // canvas - top
-                        h = canvas.getOffsetHeight()
-                                - wrapper.getElement().getOffsetTop();
-                    }
-                    wrapperStyle.setHeight(h, Unit.PX);
-                }
-
                 wrapper.updateCaptionPosition();
             }
         }
     }
-
+    
     /**
-     * Performs an horizontal layout. Should be called when a widget is add or
-     * removed
-     */
-    public void layoutHorizontally() {
+     * Cleanup old wrappers which have been left empty by other inner layouts
+     * moving the widget from the wrapper into their own hierarchy. This usually
+     * happens when a call to setWidget(widget) is done in an inner layout which
+     * automatically detaches the widget from the parent, in this case the
+     * wrapper, and re-attaches it somewhere else. This has to be done in the
+     * layout phase since the order of the hierarchy events are not defined.
+     */           
+    public void cleanupWrappers() {
         for (Widget widget : getChildren()) {
             if (widget instanceof AbsoluteWrapper) {
                 AbsoluteWrapper wrapper = (AbsoluteWrapper) widget;
-
-                /*
-                 * Cleanup old wrappers which have been left empty by other
-                 * inner layouts moving the widget from the wrapper into their
-                 * own hierarchy. This usually happens when a call to
-                 * setWidget(widget) is done in an inner layout which
-                 * automatically detaches the widget from the parent, in this
-                 * case the wrapper, and re-attaches it somewhere else. This has
-                 * to be done in the layout phase since the order of the
-                 * hierarchy events are not defined.
-                 */
                 if (wrapper.getWidget() == null) {
                     wrapper.destroy();
                     super.remove(wrapper);
                     continue;
-                }
-
-                Style wrapperStyle = wrapper.getElement().getStyle();
-                Style widgetStyle = wrapper.getWidget().getElement().getStyle();
-
-                // Ensure previous heights do not affect the measures
-                wrapperStyle.clearWidth();
-
-                if (widgetStyle.getWidth() != null
-                        && widgetStyle.getWidth().endsWith("%")) {
-                    int w;
-                    if (wrapper.left != null && wrapper.right != null) {
-                        w = wrapper.getOffsetWidth();
-                    } else if (wrapper.right != null) {
-                        // left == null
-                        // available width == right edge == offsetleft + width
-                        w = wrapper.getOffsetWidth()
-                                + wrapper.getElement().getOffsetLeft();
-                    } else {
-                        // left != null && right == null || left == null &&
-                        // right == null
-                        // available width == canvas width - offset left
-                        w = canvas.getOffsetWidth()
-                                - wrapper.getElement().getOffsetLeft();
-                    }
-                    wrapperStyle.setWidth(w, Unit.PX);
-                }
-
-                wrapper.updateCaptionPosition();
+                }             
             }
-        }
+        }        
     }
 
     /**
index 868c14f742b87cfbf3af739329511cceba564f1f..cba9cc2fa1049236df37d087e0ca05f3ed07d28d 100644 (file)
@@ -188,6 +188,8 @@ public class AbsoluteLayoutConnector extends
                 oldChild.removeStateChangeHandler(childStateChangeHandler);
             }
         }
+
+        getWidget().cleanupWrappers();
     }
 
     /*