diff options
author | Artur Signell <artur@vaadin.com> | 2016-03-08 08:37:21 +0200 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2016-05-06 10:14:46 +0300 |
commit | c0cf0f93f0d8097fa5c5d88b4439552b73c688e8 (patch) | |
tree | f10f49fdde704e66ded060913d3e706d98d99dd2 | |
parent | 82ef007b2be716193f38fe5646149bd5b3258f94 (diff) | |
download | vaadin-framework-c0cf0f93f0d8097fa5c5d88b4439552b73c688e8.tar.gz vaadin-framework-c0cf0f93f0d8097fa5c5d88b4439552b73c688e8.zip |
Take transition into account for Window layout (#15192, #19525, #19415)
Change-Id: Id23424e1380ea9115f8a345579fccc7c8c89fa1a
5 files changed, 241 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index 2d2d6ecee1..f037d74f91 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -220,6 +220,10 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, contentPanel.addKeyDownHandler(this); contentPanel.addFocusHandler(this); contentPanel.addBlurHandler(this); + if (!BrowserInfo.get().isIE8() && !BrowserInfo.get().isIE9()) { + addTransitionEndLayoutListener(getElement()); + } + } @Override @@ -1173,6 +1177,18 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, layoutManager.layoutNow(); } + private native void addTransitionEndLayoutListener(Element e) + /*-{ + var self = this; + e.addEventListener("transitionend", function(e) { + if (e.propertyName == "width" || e.propertyName == 'height') { + $entry(function() { + self.@com.vaadin.client.ui.VWindow::updateContentsSize()(); + })(); + } + }); + }-*/; + @Override public void setWidth(String width) { // Override PopupPanel which sets the width to the contents diff --git a/uitest/src/com/vaadin/tests/components/grid/GridInWindowResize.java b/uitest/src/com/vaadin/tests/components/grid/GridInWindowResize.java new file mode 100644 index 0000000000..967e29e134 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridInWindowResize.java @@ -0,0 +1,72 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import com.vaadin.annotations.Theme; +import com.vaadin.data.Item; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Grid; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; + +@Theme("valo") +public class GridInWindowResize extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid g = new Grid(); + IndexedContainer cont = new IndexedContainer(); + for (int j = 0; j < 3; j++) { + cont.addContainerProperty("" + j, String.class, ""); + } + + for (int k = 0; k < 100; k++) { + Item addItem = cont.addItem(k); + for (int j = 0; j < 3; j++) { + addItem.getItemProperty("" + j).setValue(1 + ""); + } + } + g.setContainerDataSource(cont); + g.setSizeFull(); + + VerticalLayout vl = new VerticalLayout(g); + vl.setSizeFull(); + Button resize = new Button("resize"); + VerticalLayout vl2 = new VerticalLayout(vl, resize); + vl2.setSizeFull(); + + final Window w = new Window(null, vl2); + addWindow(w); + + w.center(); + w.setModal(true); + w.setWidth("600px"); + w.setHeight("400px"); + + resize.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + w.setWidth("400px"); + } + }); + + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridInWindowResizeTest.java b/uitest/src/com/vaadin/tests/components/grid/GridInWindowResizeTest.java new file mode 100644 index 0000000000..ae4914bf1c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridInWindowResizeTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import java.util.Collections; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridInWindowResizeTest extends MultiBrowserTest { + @Override + public List<DesiredCapabilities> getBrowsersToTest() { + // Must test on a browser with animations + return Collections.singletonList(Browser.CHROME + .getDesiredCapabilities()); + } + + @Test + public void resizeWindow() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + int col1WidthBefore = grid.getCell(0, 0).getSize().getWidth(); + $(ButtonElement.class).caption("resize").first().click(); + int col1WidthAfter = grid.getCell(0, 0).getSize().getWidth(); + + Assert.assertTrue(col1WidthAfter < col1WidthBefore); + } +} diff --git a/uitest/src/com/vaadin/tests/components/window/MaximizeRestoreWindowWithManagedLayout.java b/uitest/src/com/vaadin/tests/components/window/MaximizeRestoreWindowWithManagedLayout.java new file mode 100644 index 0000000000..2cbd154dbf --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/MaximizeRestoreWindowWithManagedLayout.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.window; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.TextField; +import com.vaadin.ui.Window; + +@Theme("valo") +public class MaximizeRestoreWindowWithManagedLayout extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + GridLayout gridLayout = new GridLayout(1, 2); + TextField textField = new TextField(); + textField.setCaption("textfield"); + textField.setWidth("100%"); + gridLayout.addComponent(textField, 0, 1); + gridLayout.setSizeFull(); + + Window window = new Window(); + window.setWidth("400px"); + window.setHeight("300px"); + window.center(); + window.setResizable(true); + window.setContent(gridLayout); + addWindow(window); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/window/MaximizeRestoreWindowWithManagedLayoutTest.java b/uitest/src/com/vaadin/tests/components/window/MaximizeRestoreWindowWithManagedLayoutTest.java new file mode 100644 index 0000000000..17d4cf80e7 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/MaximizeRestoreWindowWithManagedLayoutTest.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.window; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Dimension; + +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.tb3.newelements.WindowElement; + +public class MaximizeRestoreWindowWithManagedLayoutTest extends + MultiBrowserTest { + + // This tests a timing issue so if this test fails randomly, it is + // likely that something is broken + @Test + public void contentSizeCorrectAfterMaximizeRestore() + throws InterruptedException { + openTestURL(); + WindowElement window = $(WindowElement.class).first(); + TextFieldElement field = $(TextFieldElement.class).first(); + + // Sleeps are here as there is no server request while resizing the + // window so we must wait until the animation is done before measuring + // and comparing + assertSameWidth(window, field); + window.maximize(); + sleep(200); + assertSameWidth(window, field); + window.restore(); + sleep(200); + assertSameWidth(window, field); + window.maximize(); + sleep(200); + assertSameWidth(window, field); + + } + + private void assertSameWidth(WindowElement window, TextFieldElement field) { + Dimension windowSize = window.getSize(); + Dimension fieldSize = field.getSize(); + Assert.assertEquals(windowSize.getWidth(), fieldSize.getWidth()); + } +} |