From ae9adec0467ea88fd12e0295791b77f5ef3010ae Mon Sep 17 00:00:00 2001
From: Artur Signell <artur@vaadin.com>
Date: Wed, 15 Jul 2015 20:37:20 +0300
Subject: Ensure server side focus is applied when opening a window (#17731)

This change removes all deferred commands for handling window focus to
ensure
the focus events are triggered in the expected order

Change-Id: I46598243d1022b82cf64f0e60169f52248c3cc72
---
 client/src/com/vaadin/client/ui/VUI.java     | 10 +---------
 client/src/com/vaadin/client/ui/VWindow.java | 21 +++++++++------------
 2 files changed, 10 insertions(+), 21 deletions(-)

(limited to 'client/src')

diff --git a/client/src/com/vaadin/client/ui/VUI.java b/client/src/com/vaadin/client/ui/VUI.java
index 0c1b83ab0f..963d83a6e6 100644
--- a/client/src/com/vaadin/client/ui/VUI.java
+++ b/client/src/com/vaadin/client/ui/VUI.java
@@ -18,7 +18,6 @@ package com.vaadin.client.ui;
 
 import java.util.ArrayList;
 
-import com.google.gwt.core.client.Scheduler;
 import com.google.gwt.core.client.Scheduler.ScheduledCommand;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.event.dom.client.HasScrollHandlers;
@@ -44,8 +43,8 @@ import com.vaadin.client.ConnectorMap;
 import com.vaadin.client.Focusable;
 import com.vaadin.client.LayoutManager;
 import com.vaadin.client.Profiler;
-import com.vaadin.client.WidgetUtil;
 import com.vaadin.client.VConsole;
+import com.vaadin.client.WidgetUtil;
 import com.vaadin.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner;
 import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler;
 import com.vaadin.client.ui.ui.UIConnector;
@@ -515,13 +514,6 @@ public class VUI extends SimplePanel implements ResizeHandler,
     public void focusStoredElement() {
         if (storedFocus != null) {
             storedFocus.focus();
-
-            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
-                @Override
-                public void execute() {
-                    storedFocus.focus();
-                }
-            });
         }
     }
 
diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java
index e5e09f9f09..e34e12a20b 100644
--- a/client/src/com/vaadin/client/ui/VWindow.java
+++ b/client/src/com/vaadin/client/ui/VWindow.java
@@ -562,17 +562,10 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner,
     }
 
     private static void focusTopmostModalWindow() {
-        // If we call focus() directly without scheduling, it does not work in
-        // IE and FF.
-        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
-            @Override
-            public void execute() {
-                VWindow topmost = getTopmostWindow();
-                if ((topmost != null) && (topmost.vaadinModality)) {
-                    topmost.focus();
-                }
-            }
-        });
+        VWindow topmost = getTopmostWindow();
+        if ((topmost != null) && (topmost.vaadinModality)) {
+            topmost.focus();
+        }
     }
 
     @Override
@@ -1373,7 +1366,11 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner,
 
     @Override
     public void focus() {
-        contentPanel.focus();
+        // We don't want to use contentPanel.focus() as that will use a timer in
+        // Chrome/Safari and ultimately run focus events in the wrong order when
+        // opening a modal window and focusing some other component at the same
+        // time
+        contentPanel.getElement().focus();
     }
 
     private int getDecorationHeight() {
-- 
cgit v1.2.3