From: Risto Yrjänä Date: Fri, 9 Jan 2009 08:04:46 +0000 (+0000) Subject: Fixed problems with textfields reintroduced in [6470] X-Git-Tag: 6.7.0.beta1~3379 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9b5131c8fcb74823908d6757998bbb77d787a3b7;p=vaadin-framework.git Fixed problems with textfields reintroduced in [6470] svn changeset:6472/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupView.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupView.java index efe742c89e..b47c5ecb98 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupView.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupView.java @@ -1,5 +1,7 @@ package com.itmill.toolkit.terminal.gwt.client.ui; +import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import com.google.gwt.user.client.DOM; @@ -7,6 +9,7 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.ClickListener; import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HasFocus; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.PopupListener; import com.google.gwt.user.client.ui.PopupPanel; @@ -60,12 +63,12 @@ public class IPopupView extends HTML implements Paintable { // ..and when we close it popup.addPopupListener(new PopupListener() { public void onPopupClosed(PopupPanel sender, boolean autoClosed) { + ((CustomPopup) sender).syncChildren(); updateState(false); } }); popup.setAnimationEnabled(true); - } /** @@ -172,6 +175,13 @@ public class IPopupView extends HTML implements Paintable { super.onDetach(); } + private static native void nativeBlur(Element e) + /*-{ + if(e.focus) { + e.blur(); + } + }-*/; + private class CustomPopup extends IToolkitOverlay implements Container { private Paintable popupComponentPaintable = null; @@ -180,9 +190,11 @@ public class IPopupView extends HTML implements Paintable { private boolean hasHadMouseOver = false; private boolean hideOnMouseOut = true; + private final Set activeChildren; public CustomPopup() { super(true, false, true); // autoHide, not modal, dropshadow + activeChildren = new HashSet(); } // For some reason ONMOUSEOUT events are not always recieved, so we have @@ -193,6 +205,12 @@ public class IPopupView extends HTML implements Paintable { boolean eventTargetsPopup = DOM.isOrHasChild(getElement(), target); int type = DOM.eventGetType(event); + // Catch children that use keyboard, so we can unfocus them when + // hiding + if (eventTargetsPopup && type == Event.ONKEYPRESS) { + activeChildren.add(target); + } + if (eventTargetsPopup && type == Event.ONMOUSEMOVE) { hasHadMouseOver = true; } @@ -218,6 +236,26 @@ public class IPopupView extends HTML implements Paintable { super.hide(); } + /** + * Try to sync all known active child widgets to server + */ + public void syncChildren() { + // Notify children with focus + if ((popupComponentWidget instanceof HasFocus)) { + ((HasFocus) popupComponentWidget).setFocus(false); + } + + // Notify children that have used the keyboard + for (Iterator iterator = activeChildren.iterator(); iterator + .hasNext();) { + try { + nativeBlur(iterator.next()); + } catch (Exception ignored) { + } + } + activeChildren.clear(); + } + @Override public boolean remove(Widget w) {