]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added possibility to more easily debug layout loops (#10222) 86/286/4
authorArtur Signell <artur@vaadin.com>
Fri, 16 Nov 2012 15:38:59 +0000 (17:38 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 20 Nov 2012 09:36:53 +0000 (09:36 +0000)
Change-Id: Id7a1e7590d0a35a8e9051acab043d7a26293637a

client/src/com/vaadin/client/MeasuredSize.java

index 48585ae7c51d1cfe5a41aaf7e13b0e93db32963a..ccc8a5058c5ad887dbcfd401a34ff98f92bb5120 100644 (file)
@@ -19,6 +19,8 @@ import com.google.gwt.core.client.JsArrayString;
 import com.google.gwt.dom.client.Element;
 
 public class MeasuredSize {
+    private final static boolean debugSizeChanges = false;
+
     public static class MeasureResult {
         private final boolean widthChanged;
         private final boolean heightChanged;
@@ -189,46 +191,79 @@ public class MeasuredSize {
         ComputedStyle computedStyle = new ComputedStyle(element);
         int[] paddings = computedStyle.getPadding();
         if (!heightChanged && hasHeightChanged(this.paddings, paddings)) {
+            debugSizeChange(element, "Height (padding)", this.paddings,
+                    paddings);
             heightChanged = true;
         }
         if (!widthChanged && hasWidthChanged(this.paddings, paddings)) {
+            debugSizeChange(element, "Width (padding)", this.paddings, paddings);
             widthChanged = true;
         }
         this.paddings = paddings;
 
         int[] margins = computedStyle.getMargin();
         if (!heightChanged && hasHeightChanged(this.margins, margins)) {
+            debugSizeChange(element, "Height (margins)", this.margins, margins);
             heightChanged = true;
         }
         if (!widthChanged && hasWidthChanged(this.margins, margins)) {
+            debugSizeChange(element, "Width (margins)", this.margins, margins);
             widthChanged = true;
         }
         this.margins = margins;
 
         int[] borders = computedStyle.getBorder();
         if (!heightChanged && hasHeightChanged(this.borders, borders)) {
+            debugSizeChange(element, "Height (borders)", this.borders, borders);
             heightChanged = true;
         }
         if (!widthChanged && hasWidthChanged(this.borders, borders)) {
+            debugSizeChange(element, "Width (borders)", this.borders, borders);
             widthChanged = true;
         }
         this.borders = borders;
 
         int requiredHeight = Util.getRequiredHeight(element);
         int marginHeight = sumHeights(margins);
+        int oldHeight = height;
+        int oldWidth = width;
         if (setOuterHeight(requiredHeight + marginHeight)) {
+            debugSizeChange(element, "Height (outer)", oldHeight, height);
             heightChanged = true;
         }
 
         int requiredWidth = Util.getRequiredWidth(element);
         int marginWidth = sumWidths(margins);
         if (setOuterWidth(requiredWidth + marginWidth)) {
+            debugSizeChange(element, "Width (outer)", oldWidth, width);
             widthChanged = true;
         }
 
         return new MeasureResult(widthChanged, heightChanged);
     }
 
+    private void debugSizeChange(Element element, String sizeChangeType,
+            int[] changedFrom, int[] changedTo) {
+        debugSizeChange(element, sizeChangeType,
+                java.util.Arrays.asList(changedFrom).toString(),
+                java.util.Arrays.asList(changedTo).toString());
+    }
+
+    private void debugSizeChange(Element element, String sizeChangeType,
+            int changedFrom, int changedTo) {
+        debugSizeChange(element, sizeChangeType, String.valueOf(changedFrom),
+                String.valueOf(changedTo));
+    }
+
+    private void debugSizeChange(Element element, String sizeChangeType,
+            String changedFrom, String changedTo) {
+        if (debugSizeChanges) {
+            VConsole.log(sizeChangeType + " has changed for "
+                    + element.toString() + " from " + changedFrom + " to "
+                    + changedTo);
+        }
+    }
+
     private static boolean hasWidthChanged(int[] sizes1, int[] sizes2) {
         return sizes1[1] != sizes2[1] || sizes1[3] != sizes2[3];
     }