Skip to content

Commit

Permalink
Fix to LayoutManager size calculations during transform.
Browse files Browse the repository at this point in the history
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 0 for all the popup content sizes while the opening animation is
active. ComputedStyle ignores the transform and returns the expected
value.

Fixes: #11187
  • Loading branch information
Ansku committed Dec 8, 2020
1 parent 49f7039 commit 655ee07
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
12 changes: 12 additions & 0 deletions client/src/main/java/com/vaadin/client/MeasuredSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ public MeasureResult measure(Element element) {

Profiler.enter("Measure height");
double requiredHeight = WidgetUtil.getRequiredHeightDouble(element);
if (requiredHeight == 0 && element.getOffsetHeight() > 0) {
requiredHeight = computedStyle.getHeightIncludingBorderPadding();
if (Double.isNaN(requiredHeight)) {
requiredHeight = 0;
}
}
double outerHeight = requiredHeight + sumHeights(margins);
double oldHeight = height;
if (setOuterHeight(outerHeight)) {
Expand All @@ -250,6 +256,12 @@ public MeasureResult measure(Element element) {

Profiler.enter("Measure width");
double requiredWidth = WidgetUtil.getRequiredWidthDouble(element);
if (requiredWidth == 0 && element.getOffsetWidth() > 0) {
requiredWidth = computedStyle.getWidthIncludingBorderPadding();
if (Double.isNaN(requiredWidth)) {
requiredWidth = 0;
}
}
double outerWidth = requiredWidth + sumWidths(margins);
double oldWidth = width;
if (setOuterWidth(outerWidth)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class FrontendInitialResourceUI extends AbstractTestUIWithLog {

@Override
protected void setup(VaadinRequest request) {
getPage().getJavaScript()
.execute("document.body.innerHTML=window.jsFile;\n");
getLayout().setId("layout");
getPage().getJavaScript().execute("layout.innerHTML=window.jsFile;\n");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public static class MyButton extends Button {

@Override
protected void setup(VaadinRequest request) {
getLayout().setId("layout");
Button b = new MyButton();
b.addClickListener(event -> getPage().getJavaScript()
.execute("document.body.innerHTML=window.jsFile;\n"));
.execute("layout.innerHTML=window.jsFile;\n"));
addComponent(b);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void correctEs5Es6FileImportedThroughFrontend() {
}

assertEquals("/VAADIN/frontend/" + es + "/logFilename.js",
findElement(By.tagName("body")).getText());
findElement(By.id("layout")).getText());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void correctEs5Es6FileImportedThroughFrontend() {
}

assertEquals("/VAADIN/frontend/" + es + "/logFilename.js",
findElement(By.tagName("body")).getText());
findElement(By.id("layout")).getText());
}

}

0 comments on commit 655ee07

Please sign in to comment.