From 7d21df4669ca7572f0622d9fa542bfbccc675d74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Tue, 19 Jun 2012 18:23:10 +0300 Subject: [PATCH] Ensure widgets are scrollable after a state change (see also #8994) --- .../gwt/client/ui/panel/PanelConnector.java | 2 ++ .../terminal/gwt/client/ui/panel/VPanel.java | 14 +++++++++++--- .../gwt/client/ui/root/RootConnector.java | 2 ++ .../terminal/gwt/client/ui/root/VRoot.java | 14 +++++++++++++- .../splitpanel/AbstractSplitPanelConnector.java | 2 +- .../ui/splitpanel/VAbstractSplitPanel.java | 16 +++++++++------- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/panel/PanelConnector.java b/src/com/vaadin/terminal/gwt/client/ui/panel/PanelConnector.java index 5b97fc110f..d9096526f3 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/panel/PanelConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/panel/PanelConnector.java @@ -111,6 +111,8 @@ public class PanelConnector extends AbstractComponentContainerConnector getWidget().captionNode.setClassName(captionClass); getWidget().contentNode.setClassName(contentClass); getWidget().bottomDecoration.setClassName(decoClass); + + getWidget().makeScrollable(); } if (!isRealUpdate(uidl)) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/panel/VPanel.java b/src/com/vaadin/terminal/gwt/client/ui/panel/VPanel.java index 623ecb3cf8..6a06367acd 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/panel/VPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/panel/VPanel.java @@ -45,7 +45,7 @@ public class VPanel extends SimplePanel implements ShortcutActionHandlerOwner, int scrollLeft; - private final TouchScrollHandler touchScrollHandler; + private TouchScrollHandler touchScrollHandler; public VPanel() { super(); @@ -77,8 +77,7 @@ public class VPanel extends SimplePanel implements ShortcutActionHandlerOwner, contentNode.getStyle().setProperty("position", "relative"); getElement().getStyle().setProperty("overflow", "hidden"); - touchScrollHandler = TouchScrollDelegate.enableTouchScrolling(this, - contentNode); + makeScrollable(); } /** @@ -179,4 +178,13 @@ public class VPanel extends SimplePanel implements ShortcutActionHandlerOwner, return shortcutHandler; } + /** + * Ensures the panel is scrollable eg. after style name changes + */ + void makeScrollable() { + if (touchScrollHandler == null) { + touchScrollHandler = TouchScrollDelegate.enableTouchScrolling(this); + } + touchScrollHandler.addElement(contentNode); + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java b/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java index 5184f38ed9..1a62e566ad 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java @@ -98,6 +98,8 @@ public class RootConnector extends AbstractComponentContainerConnector } getWidget().setStyleName(styles.trim()); + getWidget().makeScrollable(); + clickEventHandler.handleEventHandlerRegistration(); // Process children diff --git a/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java b/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java index d2fca72a75..0af8919280 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java +++ b/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java @@ -28,6 +28,7 @@ import com.vaadin.terminal.gwt.client.VConsole; import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler; import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; import com.vaadin.terminal.gwt.client.ui.TouchScrollDelegate; +import com.vaadin.terminal.gwt.client.ui.TouchScrollDelegate.TouchScrollHandler; import com.vaadin.terminal.gwt.client.ui.VLazyExecutor; import com.vaadin.terminal.gwt.client.ui.textfield.VTextField; @@ -108,6 +109,8 @@ public class VRoot extends SimplePanel implements ResizeHandler, private HandlerRegistration historyHandlerRegistration; + private TouchScrollHandler touchScrollHandler; + /** * The current URI fragment, used to avoid sending updates if nothing has * changed. @@ -148,7 +151,7 @@ public class VRoot extends SimplePanel implements ResizeHandler, // Allow focusing the view by using the focus() method, the view // should not be in the document focus flow getElement().setTabIndex(-1); - TouchScrollDelegate.enableTouchScrolling(this, getElement()); + makeScrollable(); } /** @@ -440,4 +443,13 @@ public class VRoot extends SimplePanel implements ResizeHandler, getElement().focus(); } + /** + * Ensures the root is scrollable eg. after style name changes. + */ + void makeScrollable() { + if (touchScrollHandler == null) { + touchScrollHandler = TouchScrollDelegate.enableTouchScrolling(this); + } + touchScrollHandler.addElement(getElement()); + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java b/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java index d5198838d3..e33755bc9b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java @@ -142,7 +142,7 @@ public abstract class AbstractSplitPanelConnector extends getLayoutManager().setNeedsLayout(this); - getWidget().ensureScrollable(); + getWidget().makeScrollable(); } public void layout() { diff --git a/src/com/vaadin/terminal/gwt/client/ui/splitpanel/VAbstractSplitPanel.java b/src/com/vaadin/terminal/gwt/client/ui/splitpanel/VAbstractSplitPanel.java index e6b2321988..e2f30c6676 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/splitpanel/VAbstractSplitPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/splitpanel/VAbstractSplitPanel.java @@ -93,7 +93,7 @@ public class VAbstractSplitPanel extends ComplexPanel { String minimumPosition; - private final TouchScrollHandler touchScrollHandler; + private TouchScrollHandler touchScrollHandler; protected Element scrolledContainer; @@ -122,8 +122,7 @@ public class VAbstractSplitPanel extends ComplexPanel { setOrientation(orientation); sinkEvents(Event.MOUSEEVENTS); - touchScrollHandler = TouchScrollDelegate.enableTouchScrolling(this, - firstContainer, secondContainer); + makeScrollable(); addDomHandler(new TouchCancelHandler() { public void onTouchCancel(TouchCancelEvent event) { @@ -758,10 +757,13 @@ public class VAbstractSplitPanel extends ComplexPanel { } /** - * Ensures the panels are still scrollable eg. after style sheet changes + * Ensures the panels are scrollable eg. after style name changes */ - void ensureScrollable() { - touchScrollHandler.setElements(firstContainer, secondContainer); + void makeScrollable() { + if (touchScrollHandler == null) { + touchScrollHandler = TouchScrollDelegate.enableTouchScrolling(this); + } + touchScrollHandler.addElement(firstContainer); + touchScrollHandler.addElement(secondContainer); } - } -- 2.39.5