From be552340eec864492a021f2d0b3e5cfb07e08471 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 16 Nov 2012 17:38:59 +0200 Subject: [PATCH] Added possibility to more easily debug layout loops (#10222) Change-Id: Id7a1e7590d0a35a8e9051acab043d7a26293637a --- .../src/com/vaadin/client/MeasuredSize.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/client/src/com/vaadin/client/MeasuredSize.java b/client/src/com/vaadin/client/MeasuredSize.java index 48585ae7c5..ccc8a5058c 100644 --- a/client/src/com/vaadin/client/MeasuredSize.java +++ b/client/src/com/vaadin/client/MeasuredSize.java @@ -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]; } -- 2.39.5