diff options
author | Henri Sara <hesara@vaadin.com> | 2013-05-17 09:10:31 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2013-05-17 09:10:31 +0300 |
commit | 145a3e3dad46e1aa04e4c8166e309ee8aaa8deeb (patch) | |
tree | 58b475a7224a6c932f77819b5c7a599749832499 /server/src | |
parent | b79c0aa5bec3cf294dbc58ff66dbaa8686229654 (diff) | |
download | vaadin-framework-145a3e3dad46e1aa04e4c8166e309ee8aaa8deeb.tar.gz vaadin-framework-145a3e3dad46e1aa04e4c8166e309ee8aaa8deeb.zip |
Send browser window resizes if there is a listener (#10055)
This also introduces PageState, which is at the moment a part of
UIState.
Change-Id: I4f927e6b8217fa789d83ce5e0d8254b141f485c7
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/com/vaadin/server/Page.java | 53 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/UI.java | 12 |
2 files changed, 55 insertions, 10 deletions
diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index a7e0f7dcb3..d4c16fe7f7 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -30,7 +30,9 @@ import java.util.Map; import com.vaadin.event.EventRouter; import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.ui.PageClientRpc; +import com.vaadin.shared.ui.ui.PageState; import com.vaadin.shared.ui.ui.UIConstants; +import com.vaadin.shared.ui.ui.UIState; import com.vaadin.ui.JavaScript; import com.vaadin.ui.LegacyWindow; import com.vaadin.ui.Link; @@ -220,7 +222,7 @@ public class Page implements Serializable { } } - private static final Method BROWSWER_RESIZE_METHOD = ReflectTools + private static final Method BROWSER_RESIZE_METHOD = ReflectTools .findMethod(BrowserWindowResizeListener.class, "browserWindowResized", BrowserWindowResizeEvent.class); @@ -417,8 +419,11 @@ public class Page implements Serializable { */ private URI location; - public Page(UI uI) { + private final PageState state; + + public Page(UI uI, PageState state) { this.uI = uI; + this.state = state; } private void addListener(Class<?> eventType, Object target, Method method) { @@ -604,20 +609,27 @@ public class Page implements Serializable { } /** - * Adds a new {@link BrowserWindowResizeListener} to this uI. The listener - * will be notified whenever the browser window within which this uI resides + * Adds a new {@link BrowserWindowResizeListener} to this UI. The listener + * will be notified whenever the browser window within which this UI resides * is resized. + * <p> + * In most cases, the UI should be in lazy resize mode when using browser + * window resize listeners. Otherwise, a large number of events can be + * received while a resize is being performed. Use + * {@link UI#setResizeLazy(boolean)}. + * </p> * * @param resizeListener * the listener to add * * @see BrowserWindowResizeListener#browserWindowResized(BrowserWindowResizeEvent) - * @see #setResizeLazy(boolean) + * @see UI#setResizeLazy(boolean) */ public void addBrowserWindowResizeListener( BrowserWindowResizeListener resizeListener) { addListener(BrowserWindowResizeEvent.class, resizeListener, - BROWSWER_RESIZE_METHOD); + BROWSER_RESIZE_METHOD); + getState(true).hasResizeListeners = true; } /** @@ -639,7 +651,9 @@ public class Page implements Serializable { public void removeBrowserWindowResizeListener( BrowserWindowResizeListener resizeListener) { removeListener(BrowserWindowResizeEvent.class, resizeListener, - BROWSWER_RESIZE_METHOD); + BROWSER_RESIZE_METHOD); + getState(true).hasResizeListeners = eventRouter + .hasListeners(BrowserWindowResizeEvent.class); } /** @@ -1038,4 +1052,29 @@ public class Page implements Serializable { uI.getRpcProxy(PageClientRpc.class).reload(); } + /** + * Returns the page state. + * <p> + * The page state is transmitted to UIConnector together with + * {@link UIState} rather than as an individual entity. + * </p> + * <p> + * The state should be considered an internal detail of Page. Classes + * outside of Page should not access it directly but only through public + * APIs provided by Page. + * </p> + * + * @since 7.1 + * @param markAsDirty + * true to mark the state as dirty + * @return PageState object that can be read in any case and modified if + * markAsDirty is true + */ + protected PageState getState(boolean markAsDirty) { + if (markAsDirty) { + uI.markAsDirty(); + } + return state; + } + } diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index 6433bebbe4..2e9570fa09 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -117,7 +117,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements /** Identifies the click event */ private ConnectorTracker connectorTracker = new ConnectorTracker(this); - private Page page = new Page(this); + private Page page = new Page(this, getState(false).pageState); private LoadingIndicatorConfiguration loadingIndicatorConfiguration = new LoadingIndicatorConfigurationImpl( this); @@ -686,10 +686,16 @@ public abstract class UI extends AbstractSingleComponentContainer implements /** * Should resize operations be lazy, i.e. should there be a delay before - * layout sizes are recalculated. Speeds up resize operations in slow UIs - * with the penalty of slightly decreased usability. + * layout sizes are recalculated and resize events are sent to the server. + * Speeds up resize operations in slow UIs with the penalty of slightly + * decreased usability. * <p> * Default value: <code>false</code> + * </p> + * <p> + * When there are active window resize listeners, lazy resize mode should be + * used to avoid a large number of events during resize. + * </p> * * @param resizeLazy * true to use a delay before recalculating sizes, false to |