diff options
author | Mikael Grankvist <mgrankvi@vaadin.com> | 2012-12-17 08:35:53 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-12-19 12:56:53 +0000 |
commit | 8a264ec4052cbee467269824e6e9e7c76efd1d07 (patch) | |
tree | 4a3750f6d1fd40fbef384af679b0c72ced7f56ef /client | |
parent | f4dd107919715cf18c92709de1909315de92934a (diff) | |
download | vaadin-framework-8a264ec4052cbee467269824e6e9e7c76efd1d07.tar.gz vaadin-framework-8a264ec4052cbee467269824e6e9e7c76efd1d07.zip |
(#9949) Flush focused connector on historyChange
Change-Id: Ia0f41220a038a83fcbcbbe9feebe066cbc626e27
Diffstat (limited to 'client')
7 files changed, 74 insertions, 4 deletions
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 2e8387c5da..4a625383a5 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -3271,4 +3271,30 @@ public class ApplicationConnection { GwtEvent.Type<H> type, H handler) { return eventBus.addHandler(type, handler); } + + /** + * Calls {@link ComponentConnector#flush()} on the active connector. Does + * nothing if there is no active (focused) connector. + */ + public void flushActiveConnector() { + ComponentConnector activeConnector = getActiveConnector(); + if (activeConnector == null) { + return; + } + activeConnector.flush(); + } + + /** + * Gets the active connector for focused element in browser. + * + * @return Connector for focused element or null. + */ + private ComponentConnector getActiveConnector() { + Element focusedElement = Util.getFocusedElement(); + if (focusedElement == null) { + return null; + } + return Util.getConnectorForElement(this, getUIConnector().getWidget(), + focusedElement); + } } diff --git a/client/src/com/vaadin/client/ComponentConnector.java b/client/src/com/vaadin/client/ComponentConnector.java index 63e55153b6..db3cc25c56 100644 --- a/client/src/com/vaadin/client/ComponentConnector.java +++ b/client/src/com/vaadin/client/ComponentConnector.java @@ -127,4 +127,16 @@ public interface ComponentConnector extends ServerConnector { */ public TooltipInfo getTooltipInfo(Element element); + /** + * Called for the active (focused) connector when a situation occurs that + * the focused connector might have buffered changes which need to be + * processed before other activity takes place. + * <p> + * This is currently called when the user changes the fragment using the + * back/forward button in the browser and allows the focused field to submit + * its value to the server before the fragment change event takes place. + * </p> + */ + public void flush(); + } diff --git a/client/src/com/vaadin/client/Util.java b/client/src/com/vaadin/client/Util.java index 0df8bfb90f..3d6f64d4d5 100644 --- a/client/src/com/vaadin/client/Util.java +++ b/client/src/com/vaadin/client/Util.java @@ -1059,11 +1059,11 @@ public class Util { } /** - * Gets the currently focused element for Internet Explorer. + * Gets the currently focused element. * - * @return The currently focused element + * @return The active element or null if no active element could be found. */ - public native static Element getIEFocusedElement() + public native static Element getFocusedElement() /*-{ if ($wnd.document.activeElement) { return $wnd.document.activeElement; @@ -1072,6 +1072,17 @@ public class Util { return null; }-*/ ; + + /** + * Gets the currently focused element for Internet Explorer. + * + * @return The currently focused element + * @deprecated Use #getFocusedElement instead + */ + @Deprecated + public static Element getIEFocusedElement() { + return getFocusedElement(); + } /** * Kind of stronger version of isAttached(). In addition to std isAttached, diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index f8088d63a2..2c599743e4 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -426,4 +426,13 @@ public abstract class AbstractComponentConnector extends AbstractConnector protected String getIcon() { return getResourceUrl(ComponentConstants.ICON_RESOURCE); } + + /* + * (non-Javadoc) + * + * @see com.vaadin.client.ComponentConnector#flush() + */ + public void flush() { + // No generic implementation. Override if needed + } } diff --git a/client/src/com/vaadin/client/ui/VUI.java b/client/src/com/vaadin/client/ui/VUI.java index cbfbda813e..a21397c060 100644 --- a/client/src/com/vaadin/client/ui/VUI.java +++ b/client/src/com/vaadin/client/ui/VUI.java @@ -129,8 +129,10 @@ public class VUI extends SimplePanel implements ResizeHandler, String newFragment = event.getValue(); // Send the location to the server if the fragment has changed + // and flush active connectors in UI. if (!newFragment.equals(currentFragment) && connection != null) { currentFragment = newFragment; + connection.flushActiveConnector(); connection.updateVariable(id, UIConstants.LOCATION_VARIABLE, Window.Location.getHref(), true); } diff --git a/client/src/com/vaadin/client/ui/richtextarea/RichTextAreaConnector.java b/client/src/com/vaadin/client/ui/richtextarea/RichTextAreaConnector.java index afcf479499..8875fc421b 100644 --- a/client/src/com/vaadin/client/ui/richtextarea/RichTextAreaConnector.java +++ b/client/src/com/vaadin/client/ui/richtextarea/RichTextAreaConnector.java @@ -75,12 +75,17 @@ public class RichTextAreaConnector extends AbstractFieldConnector implements @Override public void onBeforeShortcutAction(Event e) { - getWidget().synchronizeContentToServer(); + flush(); } @Override public VRichTextArea getWidget() { return (VRichTextArea) super.getWidget(); + } + + @Override + public void flush() { + getWidget().synchronizeContentToServer(); }; } diff --git a/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java b/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java index c653b06cf9..bedcd5f936 100644 --- a/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java +++ b/client/src/com/vaadin/client/ui/textfield/TextFieldConnector.java @@ -114,6 +114,11 @@ public class TextFieldConnector extends AbstractFieldConnector implements @Override public void onBeforeShortcutAction(Event e) { + flush(); + } + + @Override + public void flush() { getWidget().valueChange(false); } |