From: Juho Nurminen Date: Thu, 20 Mar 2014 14:16:41 +0000 (+0200) Subject: Made Window z-indices update when windows are closed (#13174) X-Git-Tag: 7.2.0.beta1~63^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5b3ae6d62e5ff49ef0b204ed27b1004399a19aac;p=vaadin-framework.git Made Window z-indices update when windows are closed (#13174) Change-Id: I2fa7566ec4788893d1d99440a7ca2d014c9a8f13 --- diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index f83bc83c8d..6afb6c2d8a 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -487,9 +487,14 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, } super.hide(); + int curIndex = windowOrder.indexOf(this); // Remove window from windowOrder to avoid references being left // hanging. - windowOrder.remove(this); + windowOrder.remove(curIndex); + // Update the z-indices of any remaining windows + while (curIndex < windowOrder.size()) { + windowOrder.get(curIndex).setWindowOrder(curIndex++); + } } private void fixIE8FocusCaptureIssue() { diff --git a/uitest/src/com/vaadin/tests/components/window/WindowZIndex.java b/uitest/src/com/vaadin/tests/components/window/WindowZIndex.java new file mode 100644 index 0000000000..5d1a2540b8 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/WindowZIndex.java @@ -0,0 +1,56 @@ +package com.vaadin.tests.components.window; + +import java.util.ArrayDeque; +import java.util.NoSuchElementException; +import java.util.Queue; + +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.Label; +import com.vaadin.ui.Window; + +public class WindowZIndex extends AbstractTestUI { + + @Override + protected String getTestDescription() { + return "Windows should stack correctly when adding new windows, closing opened ones and switching focus."; + } + + @Override + protected Integer getTicketNumber() { + return 13174; + } + + int windowCount = 0; + Queue windows = new ArrayDeque(); + + @Override + protected void setup(VaadinRequest request) { + addComponent(new Button("Add window", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + Window window = new Window(); + window.setPositionX(100 + 20 * windowCount); + window.setPositionY(100 + 20 * windowCount); + window.setHeight(200, Unit.PIXELS); + window.setWidth(200, Unit.PIXELS); + window.setContent(new Label("Window " + ++windowCount)); + addWindow(window); + windows.add(window); + } + })); + addComponent(new Button("Close window", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + try { + windows.remove().close(); + } catch (NoSuchElementException e) { + } + } + })); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/window/WindowZIndexTest.java b/uitest/src/com/vaadin/tests/components/window/WindowZIndexTest.java new file mode 100644 index 0000000000..38254cf6f3 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/window/WindowZIndexTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2013 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 java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class WindowZIndexTest extends MultiBrowserTest { + + @Test + public void removingUpdatesZIndices() throws IOException { + openTestURL(); + + WebElement addButton = driver.findElement(By + .xpath("//span[contains(text(),'Add window')]")); + WebElement closeButton = driver.findElement(By + .xpath("//span[contains(text(),'Close window')]")); + + addButton.click(); + addButton.click(); + addButton.click(); + addButton.click(); + addButton.click(); + + closeButton.click(); + closeButton.click(); + closeButton.click(); + + addButton.click(); + addButton.click(); + addButton.click(); + addButton.click(); + + compareScreen("stacked"); + + WebElement window4 = driver.findElement(By + .xpath("//*[contains(text(), 'Window 4')]")); + new Actions(driver).moveToElement(window4, 1, 9).click().perform(); + + compareScreen("win4-on-top"); + } +}