diff options
author | Mika Murtojarvi <mika@vaadin.com> | 2013-10-29 15:22:45 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-10-30 13:39:05 +0000 |
commit | 017bd0684c7d6c8475c8b43514e6f3998095c8d6 (patch) | |
tree | f421a4ae7e4b10e7339f6f1acc56b66aa0f0b15a /client | |
parent | 878c2bd4643c9cf08fb0ed2da8bae7f7a626ce8b (diff) | |
download | vaadin-framework-017bd0684c7d6c8475c8b43514e6f3998095c8d6.tar.gz vaadin-framework-017bd0684c7d6c8475c8b43514e6f3998095c8d6.zip |
Fixes the handling of the scroll position of a Window (#12736)
After the first commit the same fix has been applied also for panels, in
addition to other suggested changes.
The scroll position of a Window is now memorized before applying
the fix for bug #11994. The position is restored after the fix.
Because the scrolling issue is known to appear also in other components,
the fix for the scrolling has been moved to the Util class.
Change-Id: I5251011b5bede77a7fb18972e1d90016c0eccc23
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/Util.java | 55 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/VPanel.java | 44 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/VWindow.java | 32 |
3 files changed, 60 insertions, 71 deletions
diff --git a/client/src/com/vaadin/client/Util.java b/client/src/com/vaadin/client/Util.java index 8972670232..8a5712215d 100644 --- a/client/src/com/vaadin/client/Util.java +++ b/client/src/com/vaadin/client/Util.java @@ -32,6 +32,7 @@ import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Display; +import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.Touch; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; @@ -518,6 +519,60 @@ public class Util { } /** + * Prevents some browsers from adding scroll bars to a component (such as a + * Window) whose contents fit in the component. + * <p> + * See: bugs #11994 and #12736. + * + * @param contentNode + * an element that contains a scrollable element as its first + * child + * + * @since 7.1.8 + */ + public static void removeUnneededScrollbars(final Element contentNode) { + if (BrowserInfo.get().isWebkit()) { + + /* + * Shake up the DOM a bit to make the window shed unnecessary + * scrollbars and resize correctly afterwards. This resulting code + * took over a week to summon forth, and involved some pretty hairy + * black magic. Don't touch it unless you know what you're doing! + * Fixes ticket #11994. Later modified to fix ticket #12736. + */ + Scheduler.get().scheduleFinally(new ScheduledCommand() { + + @Override + public void execute() { + final com.google.gwt.dom.client.Element scrollable = contentNode + .getFirstChildElement(); + + // Adjusting the width or height may change the scroll + // position, so store the current position + int horizontalScrollPosition = scrollable.getScrollLeft(); + int verticalScrollPosition = scrollable.getScrollTop(); + + final String oldWidth = scrollable.getStyle().getWidth(); + final String oldHeight = scrollable.getStyle().getHeight(); + + scrollable.getStyle().setWidth(110, Unit.PCT); + scrollable.getStyle().setHeight(110, Unit.PCT); + scrollable.getOffsetWidth(); + scrollable.getOffsetHeight(); + scrollable.getStyle().setProperty("width", oldWidth); + scrollable.getStyle().setProperty("height", oldHeight); + + // Restore the scroll position + scrollable.setScrollLeft(horizontalScrollPosition); + scrollable.setScrollTop(verticalScrollPosition); + + } + }); + + } + } + + /** * Parses shared state and fetches the relative size of the component. If a * dimension is not specified as relative it will return -1. If the shared * state does not contain width or height specifications this will return diff --git a/client/src/com/vaadin/client/ui/VPanel.java b/client/src/com/vaadin/client/ui/VPanel.java index 15c3883b11..307a2e4a91 100644 --- a/client/src/com/vaadin/client/ui/VPanel.java +++ b/client/src/com/vaadin/client/ui/VPanel.java @@ -16,18 +16,15 @@ package com.vaadin.client.ui; -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.SimplePanel; import com.vaadin.client.ApplicationConnection; -import com.vaadin.client.BrowserInfo; import com.vaadin.client.Focusable; +import com.vaadin.client.Util; import com.vaadin.client.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler; @@ -210,43 +207,6 @@ public class VPanel extends SimplePanel implements ShortcutActionHandlerOwner, touchScrollHandler = TouchScrollDelegate.enableTouchScrolling(this); } touchScrollHandler.addElement(contentNode); - - /* - * Shake up the DOM a bit to make the window shed unnecessary scroll - * bars and resize correctly afterwards. This resulting code took over a - * week to summon forth, and involved some pretty hairy black magic. - * Don't touch it unless you know what you're doing! Fixes ticket - * #12727. - * - * This solution comes from the ticket #11994: Windows get unnecessary - * scroll bars in WebKit when content is 100% wide. - */ - if (BrowserInfo.get().isWebkit()) { - Scheduler.get().scheduleFinally(new ScheduledCommand() { - @Override - public void execute() { - final com.google.gwt.dom.client.Element scrollable = contentNode - .getFirstChildElement(); - - int contentNodeScrollTop = contentNode.getScrollTop(); - int contentNodeScrollLeft = contentNode.getScrollLeft(); - - final String oldWidth = scrollable.getStyle().getWidth(); - final String oldHeight = scrollable.getStyle().getHeight(); - - scrollable.getStyle().setWidth(110, Unit.PCT); - scrollable.getOffsetWidth(); - scrollable.getStyle().setProperty("width", oldWidth); - - scrollable.getStyle().setHeight(110, Unit.PCT); - scrollable.getOffsetHeight(); - scrollable.getStyle().setProperty("height", oldHeight); - - // Recovering scroll position: - contentNode.setScrollTop(contentNodeScrollTop); - contentNode.setScrollLeft(contentNodeScrollLeft); - } - }); - } + Util.removeUnneededScrollbars(contentNode); } } diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index ff6a15e597..3e71c0af50 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -342,36 +342,10 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, if (!visibilityChangesDisabled) { super.setVisible(visible); } - if (visible && BrowserInfo.get().isWebkit()) { - - /* - * Shake up the DOM a bit to make the window shed unnecessary - * scrollbars and resize correctly afterwards. This resulting code - * took over a week to summon forth, and involved some pretty hairy - * black magic. Don't touch it unless you know what you're doing! - * Fixes ticket #11994 - */ - Scheduler.get().scheduleFinally(new ScheduledCommand() { - @Override - public void execute() { - final com.google.gwt.dom.client.Element scrollable = contents - .getFirstChildElement(); - final String oldWidth = scrollable.getStyle().getWidth(); - final String oldHeight = scrollable.getStyle().getHeight(); - - scrollable.getStyle().setWidth(110, Unit.PCT); - scrollable.getOffsetWidth(); - scrollable.getStyle().setProperty("width", oldWidth); - - scrollable.getStyle().setHeight(110, Unit.PCT); - scrollable.getOffsetHeight(); - scrollable.getStyle().setProperty("height", oldHeight); - - updateContentsSize(); - positionOrSizeUpdated(); - } - }); + Util.removeUnneededScrollbars(contents); + updateContentsSize(); + positionOrSizeUpdated(); } } |