diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2021-02-05 14:55:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 14:55:00 +0200 |
commit | be23b014866160cb4bc3af8ed808c6f749270dce (patch) | |
tree | 276475400b8c19def317f43f21de41e42d81db37 /client | |
parent | c6c17e0f1fb46fc73bff59e9306b964ca588e4ef (diff) | |
download | vaadin-framework-be23b014866160cb4bc3af8ed808c6f749270dce.tar.gz vaadin-framework-be23b014866160cb4bc3af8ed808c6f749270dce.zip |
Re-use ComputedStyles in Escalator when possible. (#12186)
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/widgets/Escalator.java | 39 | ||||
-rwxr-xr-x | client/src/main/java/com/vaadin/client/widgets/Grid.java | 8 |
2 files changed, 38 insertions, 9 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java index a5046ce970..a9f8e0862c 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -7160,6 +7160,8 @@ public class Escalator extends Widget private final ElementPositionBookkeeper positions = new ElementPositionBookkeeper(); + private Map<Element, ComputedStyle> computedStyleMap = new HashMap<>(); + /** * Creates a new Escalator widget instance. */ @@ -7249,14 +7251,28 @@ public class Escalator extends Widget private double getBoundingWidth(Element element) { // Gets the current width, including border and padding, for the element // while ignoring any transforms applied to the element (e.g. scale) - return new ComputedStyle(element).getWidthIncludingBorderPadding(); + if (!computedStyleMap.containsKey(element)) { + if (computedStyleMap.isEmpty()) { + // ensure the next event loop calculates the sizes anew + Scheduler.get().scheduleDeferred(() -> clearComputedStyles()); + } + computedStyleMap.put(element, new ComputedStyle(element)); + } + return computedStyleMap.get(element).getWidthIncludingBorderPadding(); } private double getBoundingHeight(Element element) { // Gets the current height, including border and padding, for the // element while ignoring any transforms applied to the element (e.g. // scale) - return new ComputedStyle(element).getHeightIncludingBorderPadding(); + if (!computedStyleMap.containsKey(element)) { + if (computedStyleMap.isEmpty()) { + // ensure the next event loop calculates the sizes anew + Scheduler.get().scheduleDeferred(() -> clearComputedStyles()); + } + computedStyleMap.put(element, new ComputedStyle(element)); + } + return computedStyleMap.get(element).getHeightIncludingBorderPadding(); } private int getBodyRowCount() { @@ -8306,6 +8322,25 @@ public class Escalator extends Widget } /** + * Gets the escalator's inner height. This is the entire height in pixels, + * without the horizontal scrollbar. + * + * @return escalator's inner height + */ + public double getInnerHeight() { + return getBoundingHeight(tableWrapper); + } + + /** + * FOR INTERNAL USE ONLY, MAY GET REMOVED OR MODIFIED AT ANY TIME! + * <p> + * Clears the computed styles. + */ + void clearComputedStyles() { + computedStyleMap.clear(); + } + + /** * Resets all cached pixel sizes and reads new values from the DOM. This * methods should be used e.g. when styles affecting the dimensions of * elements in this escalator have been changed. diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index d4c93751ea..99a4a269bd 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -77,7 +77,6 @@ import com.google.gwt.user.client.ui.PopupPanel; import com.google.gwt.user.client.ui.ResizeComposite; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.BrowserInfo; -import com.vaadin.client.ComputedStyle; import com.vaadin.client.DeferredWorker; import com.vaadin.client.Focusable; import com.vaadin.client.WidgetUtil; @@ -3456,7 +3455,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, // Update latest width to prevent recalculate on height change. lastCalculatedInnerWidth = escalator.getInnerWidth(); - lastCalculatedInnerHeight = getEscalatorInnerHeight(); + lastCalculatedInnerHeight = escalator.getInnerHeight(); } private boolean columnsAreGuaranteedToBeWiderThanGrid() { @@ -9404,11 +9403,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, }); } - private double getEscalatorInnerHeight() { - return new ComputedStyle(getEscalator().getTableWrapper()) - .getHeightIncludingBorderPadding(); - } - /** * Grid does not support adding Widgets this way. * <p> |