From 492ba61dbc51aaa036ef904f6e7fbf94e9a8c1a0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Wed, 11 Apr 2012 10:22:04 +0300 Subject: [PATCH] Check for appeared or disappeared scrollbars when sizes have changed --- .../terminal/gwt/client/LayoutManager.java | 4 +-- .../gwt/client/ui/AccordionConnector.java | 4 +-- .../gwt/client/ui/PanelConnector.java | 4 +-- .../terminal/gwt/client/ui/RootConnector.java | 4 +-- .../gwt/client/ui/TabsheetConnector.java | 4 +-- .../gwt/client/ui/WindowConnector.java | 4 +-- .../ui/layout/LayoutDependencyTree.java | 35 +++++++++++++++++++ ...lowAutoFix.java => MayScrollChildren.java} | 2 +- 8 files changed, 48 insertions(+), 13 deletions(-) rename src/com/vaadin/terminal/gwt/client/ui/layout/{RequiresOverflowAutoFix.java => MayScrollChildren.java} (67%) diff --git a/src/com/vaadin/terminal/gwt/client/LayoutManager.java b/src/com/vaadin/terminal/gwt/client/LayoutManager.java index 2ad2c95b6e..09c811a2de 100644 --- a/src/com/vaadin/terminal/gwt/client/LayoutManager.java +++ b/src/com/vaadin/terminal/gwt/client/LayoutManager.java @@ -22,7 +22,7 @@ import com.vaadin.terminal.gwt.client.ui.VNotification; import com.vaadin.terminal.gwt.client.ui.layout.ElementResizeEvent; import com.vaadin.terminal.gwt.client.ui.layout.ElementResizeListener; import com.vaadin.terminal.gwt.client.ui.layout.LayoutDependencyTree; -import com.vaadin.terminal.gwt.client.ui.layout.RequiresOverflowAutoFix; +import com.vaadin.terminal.gwt.client.ui.layout.MayScrollChildren; public class LayoutManager { private static final String LOOP_ABORT_MESSAGE = "Aborting layout after 100 passes. This would probably be an infinite loop."; @@ -425,7 +425,7 @@ public class LayoutManager { } private void doOverflowAutoFix(ComponentConnector connector) { - if (connector.getParent() instanceof RequiresOverflowAutoFix + if (connector.getParent() instanceof MayScrollChildren && BrowserInfo.get().requiresOverflowAutoFix() && !"absolute".equals(connector.getWidget().getElement() .getStyle().getPosition())) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/AccordionConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AccordionConnector.java index 454e698ef1..f6d3a4c869 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AccordionConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AccordionConnector.java @@ -11,12 +11,12 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.ui.VAccordion.StackItem; -import com.vaadin.terminal.gwt.client.ui.layout.RequiresOverflowAutoFix; +import com.vaadin.terminal.gwt.client.ui.layout.MayScrollChildren; import com.vaadin.ui.Accordion; @Component(Accordion.class) public class AccordionConnector extends TabsheetBaseConnector implements - SimpleManagedLayout, RequiresOverflowAutoFix { + SimpleManagedLayout, MayScrollChildren { @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/PanelConnector.java b/src/com/vaadin/terminal/gwt/client/ui/PanelConnector.java index ebfdcbcfa2..c40f5baa3a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/PanelConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/PanelConnector.java @@ -18,13 +18,13 @@ import com.vaadin.terminal.gwt.client.Paintable; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.communication.RpcProxy; import com.vaadin.terminal.gwt.client.communication.ServerRpc; -import com.vaadin.terminal.gwt.client.ui.layout.RequiresOverflowAutoFix; +import com.vaadin.terminal.gwt.client.ui.layout.MayScrollChildren; import com.vaadin.ui.Panel; @Component(Panel.class) public class PanelConnector extends AbstractComponentContainerConnector implements Paintable, SimpleManagedLayout, PostLayoutListener, - RequiresOverflowAutoFix { + MayScrollChildren { public interface PanelServerRPC extends ClickRPC, ServerRpc { diff --git a/src/com/vaadin/terminal/gwt/client/ui/RootConnector.java b/src/com/vaadin/terminal/gwt/client/ui/RootConnector.java index c1603097cc..e800ffd685 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/RootConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/RootConnector.java @@ -34,12 +34,12 @@ import com.vaadin.terminal.gwt.client.communication.ServerRpc; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent.StateChangeHandler; import com.vaadin.terminal.gwt.client.ui.Component.LoadStyle; -import com.vaadin.terminal.gwt.client.ui.layout.RequiresOverflowAutoFix; +import com.vaadin.terminal.gwt.client.ui.layout.MayScrollChildren; import com.vaadin.ui.Root; @Component(value = Root.class, loadStyle = LoadStyle.EAGER) public class RootConnector extends AbstractComponentContainerConnector - implements Paintable, RequiresOverflowAutoFix { + implements Paintable, MayScrollChildren { public interface RootServerRPC extends ClickRPC, ServerRpc { diff --git a/src/com/vaadin/terminal/gwt/client/ui/TabsheetConnector.java b/src/com/vaadin/terminal/gwt/client/ui/TabsheetConnector.java index fa8f57edb2..6b798752a4 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/TabsheetConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/TabsheetConnector.java @@ -9,12 +9,12 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.ui.layout.RequiresOverflowAutoFix; +import com.vaadin.terminal.gwt.client.ui.layout.MayScrollChildren; import com.vaadin.ui.TabSheet; @Component(TabSheet.class) public class TabsheetConnector extends TabsheetBaseConnector implements - SimpleManagedLayout, RequiresOverflowAutoFix { + SimpleManagedLayout, MayScrollChildren { @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/WindowConnector.java b/src/com/vaadin/terminal/gwt/client/ui/WindowConnector.java index 043c3ee041..6dcd3e71e4 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/WindowConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/WindowConnector.java @@ -24,12 +24,12 @@ import com.vaadin.terminal.gwt.client.communication.RpcProxy; import com.vaadin.terminal.gwt.client.communication.ServerRpc; import com.vaadin.terminal.gwt.client.ui.PanelConnector.PanelState; import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener; -import com.vaadin.terminal.gwt.client.ui.layout.RequiresOverflowAutoFix; +import com.vaadin.terminal.gwt.client.ui.layout.MayScrollChildren; @Component(value = com.vaadin.ui.Window.class) public class WindowConnector extends AbstractComponentContainerConnector implements Paintable, BeforeShortcutActionListener, - SimpleManagedLayout, PostLayoutListener, RequiresOverflowAutoFix { + SimpleManagedLayout, PostLayoutListener, MayScrollChildren { public interface WindowServerRPC extends ClickRPC, ServerRpc { } diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/LayoutDependencyTree.java b/src/com/vaadin/terminal/gwt/client/ui/layout/LayoutDependencyTree.java index 2e6dc34a49..52b530823a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/layout/LayoutDependencyTree.java +++ b/src/com/vaadin/terminal/gwt/client/ui/layout/LayoutDependencyTree.java @@ -221,6 +221,41 @@ public class LayoutDependencyTree { layoutDependency.propagatePostLayoutMeasure(); } } + + // Should also go through the hierarchy to discover appeared or + // disappeared scrollbars + LayoutDependency potentiallyChangedScrollbar = findPotentiallyChangedScrollbar(); + if (potentiallyChangedScrollbar != null) { + potentiallyChangedScrollbar.setNeedsMeasure(true); + } + + } + + /** + * Go up the hierarchy to find a component whose size might have changed + * in the other direction because changes to this component causes + * scrollbars to appear or disappear. + * + * @return + */ + private LayoutDependency findPotentiallyChangedScrollbar() { + ComponentConnector currentConnector = connector; + while (true) { + ComponentContainerConnector parent = currentConnector + .getParent(); + if (parent == null) { + return null; + } + if (parent instanceof MayScrollChildren) { + return getDependency(currentConnector, + getOppositeDirection()); + } + currentConnector = parent; + } + } + + private int getOppositeDirection() { + return direction == HORIZONTAL ? VERTICAL : HORIZONTAL; } public void markAsLayouted() { diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/RequiresOverflowAutoFix.java b/src/com/vaadin/terminal/gwt/client/ui/layout/MayScrollChildren.java similarity index 67% rename from src/com/vaadin/terminal/gwt/client/ui/layout/RequiresOverflowAutoFix.java rename to src/com/vaadin/terminal/gwt/client/ui/layout/MayScrollChildren.java index 18e82c8824..62c9937c4c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/layout/RequiresOverflowAutoFix.java +++ b/src/com/vaadin/terminal/gwt/client/ui/layout/MayScrollChildren.java @@ -5,6 +5,6 @@ package com.vaadin.terminal.gwt.client.ui.layout; import com.vaadin.terminal.gwt.client.ComponentContainerConnector; -public interface RequiresOverflowAutoFix extends ComponentContainerConnector { +public interface MayScrollChildren extends ComponentContainerConnector { } -- 2.39.5