From c8e04dc5b30f8967c58df928872ca2e5e2be5c5b Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Fri, 18 Dec 2020 13:16:26 +0200 Subject: Fix to LayoutManager size calculations during transform. (#12138) * Fix to LayoutManager size calculations during transform. - ComputedStyle is slower but more reliable than using getBoundingClientRect, which does not work as expected if a transform has been applied to the element or one of its parents. This is a problem e.g. with PopupView, where getBoundingClientRect will return too small size (or even zero size) for all the popup contents while the opening animation is active. ComputedStyle ignores the transform and returns the expected value. - The presence of the element in DOM must be checked before the size is requested from ComputedStyle, if the element has disappeared from DOM without a warning and calculation is attempted anyway, the browser gets stuck. - Possibility to configure LayoutManager to use the less reliable calculations for applications where the slight performance difference is more important than layout issues within elements that have transform animations. - Manual test, problem isn't reproducible by TestBench. Fixes: #11187 --- server/src/main/java/com/vaadin/ui/UI.java | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'server') diff --git a/server/src/main/java/com/vaadin/ui/UI.java b/server/src/main/java/com/vaadin/ui/UI.java index 7430c04bb9..e291952f85 100644 --- a/server/src/main/java/com/vaadin/ui/UI.java +++ b/server/src/main/java/com/vaadin/ui/UI.java @@ -2021,6 +2021,40 @@ public abstract class UI extends AbstractSingleComponentContainer getRpcProxy(PageClientRpc.class).initializeMobileHtml5DndPolyfill(); } + /** + * Returns whether LayoutManager uses thorough size check that evaluates the + * presence of the element and uses calculated size, or defaults to a + * slightly faster check that can result in incorrect size information if + * the check is triggered while a transform animation is ongoing. This can + * happen e.g. when a PopupView is opened. + *

+ * By default, the thorough size check is enabled. + * + * @return {@code true} if thorough size check enabled, {@code false} if not + * @since + */ + public boolean isUsingThoroughSizeCheck() { + return getState(false).thoroughSizeCheck; + } + + /** + * Set whether LayoutManager should use thorough size check that evaluates + * the presence of the element and uses calculated size, or default to a + * slightly faster check that can result in incorrect size information if + * the check is triggered while a transform animation is ongoing. This can + * happen e.g. when a PopupView is opened. + *

+ * By default, the thorough size check is enabled. + * + * @param thoroughSizeCheck + * {@code true} if thorough size check enabled, {@code false} if + * not + * @since + */ + public void setUsingThoroughSizeCheck(boolean thoroughSizeCheck) { + getState().thoroughSizeCheck = thoroughSizeCheck; + } + /** * Event which is fired when the ordering of the windows is updated. *

-- cgit v1.2.3