diff options
author | Mehdi Javan <32511762+mehdi-vaadin@users.noreply.github.com> | 2018-09-19 09:20:04 +0300 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2018-09-19 09:20:04 +0300 |
commit | 269ce1beac0fb164cada94342654e96ccfe0425f (patch) | |
tree | b3900abbd88c1563b8e1ab97271bad75017312db /client | |
parent | 663f12b7f6b6da213ce94c48aef1e789669eb22a (diff) | |
download | vaadin-framework-269ce1beac0fb164cada94342654e96ccfe0425f.tar.gz vaadin-framework-269ce1beac0fb164cada94342654e96ccfe0425f.zip |
Fix/focus inside window chrome (#11142)
Fixes #11087
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java | 85 |
1 files changed, 48 insertions, 37 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java b/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java index adb06a450a..5630cfab3c 100644 --- a/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java @@ -15,16 +15,6 @@ */ package com.vaadin.client.ui.ui; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; - import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; @@ -101,9 +91,18 @@ import com.vaadin.shared.ui.ui.UIServerRpc; import com.vaadin.shared.ui.ui.UIState; import com.vaadin.shared.util.SharedUtil; import com.vaadin.ui.UI; - import elemental.client.Browser; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + @Connect(value = UI.class, loadStyle = LoadStyle.EAGER) public class UIConnector extends AbstractSingleComponentContainerConnector implements Paintable, MayScrollChildren { @@ -375,34 +374,18 @@ public class UIConnector extends AbstractSingleComponentContainerConnector if (uidl.hasAttribute("focused")) { // set focused component when render phase is finished Scheduler.get().scheduleDeferred(() -> { - ComponentConnector connector = (ComponentConnector) uidl - .getPaintableAttribute("focused", getConnection()); + Timer timer = new Timer() { + @Override + public void run() { + ComponentConnector connector = (ComponentConnector) uidl + .getPaintableAttribute("focused", + getConnection()); - if (connector == null) { - // Do not try to focus invisible components which not - // present in UIDL - return; - } + focus(connector); + } + }; - final Widget toBeFocused = connector.getWidget(); - /* - * Two types of Widgets can be focused, either implementing GWT - * Focusable of a thinner Vaadin specific Focusable interface. - */ - if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { - final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; - toBeFocusedWidget.setFocus(true); - } else if (toBeFocused instanceof Focusable) { - ((Focusable) toBeFocused).focus(); - } else { - getLogger().severe( - "Server is trying to set focus to the widget of connector " - + Util.getConnectorString(connector) - + " but it is not focusable. The widget should implement either " - + com.google.gwt.user.client.ui.Focusable.class - .getName() - + " or " + Focusable.class.getName()); - } + timer.schedule(0); }); } @@ -437,6 +420,34 @@ public class UIConnector extends AbstractSingleComponentContainerConnector } } + private void focus(ComponentConnector connector) { + if (connector == null) { + // Do not try to focus invisible components which not + // present in UIDL + return; + } + + final Widget toBeFocused = connector.getWidget(); + /* + * Two types of Widgets can be focused, either implementing GWT + * Focusable of a thinner Vaadin specific Focusable interface. + */ + if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { + final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; + toBeFocusedWidget.setFocus(true); + } else if (toBeFocused instanceof Focusable) { + ((Focusable) toBeFocused).focus(); + } else { + getLogger().severe( + "Server is trying to set focus to the widget of connector " + + Util.getConnectorString(connector) + + " but it is not focusable. The widget should implement either " + + com.google.gwt.user.client.ui.Focusable.class + .getName() + + " or " + Focusable.class.getName()); + } + } + /** * Reads CSS strings and resources injected by {@link Styles#inject} from * the UIDL stream. |