]> source.dussan.org Git - vaadin-framework.git/commitdiff
Made Window z-indices update when windows are closed (#13174)
authorJuho Nurminen <juho@vaadin.com>
Thu, 20 Mar 2014 14:16:41 +0000 (16:16 +0200)
committerVaadin Code Review <review@vaadin.com>
Fri, 28 Mar 2014 12:23:14 +0000 (12:23 +0000)
Change-Id: I2fa7566ec4788893d1d99440a7ca2d014c9a8f13

client/src/com/vaadin/client/ui/VWindow.java
uitest/src/com/vaadin/tests/components/window/WindowZIndex.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/window/WindowZIndexTest.java [new file with mode: 0644]

index f83bc83c8d8334ec639b400505c7ce4cc373f8f5..6afb6c2d8ad72a4b561f3fc957a34822d1a70056 100644 (file)
@@ -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 (file)
index 0000000..5d1a254
--- /dev/null
@@ -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<Window> windows = new ArrayDeque<Window>();
+
+    @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 (file)
index 0000000..38254cf
--- /dev/null
@@ -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");
+    }
+}