]> source.dussan.org Git - vaadin-framework.git/commitdiff
Restoring overflow-x and overflow-y in runWebkitOverflowAutoFix (#16650)
authorAlexey Fansky <alexey.fansky@effective-soft.com>
Sat, 21 Feb 2015 01:13:55 +0000 (17:13 -0800)
committerVaadin Code Review <review@vaadin.com>
Tue, 3 Mar 2015 08:24:00 +0000 (08:24 +0000)
Change-Id: I7be1c1571ee5ede0ce481faf823f5f271a280a8a

client/src/com/vaadin/client/WidgetUtil.java
uitest/src/com/vaadin/tests/components/customlayout/OverflowAutoFix.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/customlayout/OverflowAutoFixTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/widgetset/client/RunOverflowFixConnector.java [new file with mode: 0644]

index 4c991b2c3d3ec6f9190de4a0fc24ef15e22b1821..5f88f6da46689eb9b2a69b9bfeb77986b7ab141e 100644 (file)
@@ -439,7 +439,13 @@ public class WidgetUtil {
         if (BrowserInfo.get().requiresOverflowAutoFix()) {
             final String originalOverflow = elem.getStyle().getProperty(
                     "overflow");
-            if ("hidden".equals(originalOverflow)) {
+            final String originalOverflowX = elem.getStyle().getProperty(
+                    "overflowX");
+            final String originalOverflowY = elem.getStyle().getProperty(
+                    "overflowY");
+            if ("hidden".equals(originalOverflow)
+                    || "hidden".equals(originalOverflowX)
+                    || "hidden".equals(originalOverflowY)) {
                 return;
             }
 
@@ -453,6 +459,14 @@ public class WidgetUtil {
                 public void execute() {
                     // Dough, Safari scroll auto means actually just a moped
                     elem.getStyle().setProperty("overflow", originalOverflow);
+                    if (!originalOverflowX.isEmpty()) {
+                        elem.getStyle().setProperty("overflowX",
+                                originalOverflowX);
+                    }
+                    if (!originalOverflowY.isEmpty()) {
+                        elem.getStyle().setProperty("overflowY",
+                                originalOverflowY);
+                    }
 
                     if (scrolltop > 0 || elem.getScrollTop() > 0) {
                         int scrollvalue = scrolltop;
diff --git a/uitest/src/com/vaadin/tests/components/customlayout/OverflowAutoFix.java b/uitest/src/com/vaadin/tests/components/customlayout/OverflowAutoFix.java
new file mode 100644 (file)
index 0000000..d6d4bdb
--- /dev/null
@@ -0,0 +1,29 @@
+package com.vaadin.tests.components.customlayout;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.ui.AbstractComponent;
+
+@Widgetset(TestingWidgetSet.NAME)
+public class OverflowAutoFix extends AbstractTestUI {
+    @Override
+    protected void setup(VaadinRequest request) {
+        addComponent(new RunOverflowFix());
+    }
+
+    public class RunOverflowFix extends AbstractComponent {
+    }
+
+    @Override
+    public String getTestDescription() {
+        return "Overflow-x and overflow-y should be restored when using runWebkitOverflowAutoFix.<br>"
+                + "Outer size: 300x200px, inner size: 350x250px";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 16650;
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/components/customlayout/OverflowAutoFixTest.java b/uitest/src/com/vaadin/tests/components/customlayout/OverflowAutoFixTest.java
new file mode 100644 (file)
index 0000000..d56e07f
--- /dev/null
@@ -0,0 +1,43 @@
+package com.vaadin.tests.components.customlayout;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class OverflowAutoFixTest extends MultiBrowserTest {
+    @Test
+    public void testRestoreOverflowHidden() throws InterruptedException {
+        openTestURL();
+
+        click("run-button-one");
+
+        assertElementCssValueEquals("first-scrollbar", "overflow", "scroll");
+        assertElementCssValueEquals("second-scrollbar", "overflow-x", "hidden");
+        assertElementCssValueEquals("third-scrollbar", "overflow-y", "hidden");
+    }
+
+    @Test
+    public void testRestoreOverflowOther() throws InterruptedException {
+        openTestURL();
+
+        click("run-button-two");
+
+        assertElementCssValueEquals("first-scrollbar", "overflow", "visible");
+        assertElementCssValueEquals("second-scrollbar", "overflow-x", "scroll");
+        assertElementCssValueEquals("third-scrollbar", "overflow-y", "auto");
+    }
+
+    private void click(String className) {
+        findElement(By.className(className)).click();
+    }
+
+    private void assertElementCssValueEquals(String className,
+            String propertyName, String expected) {
+        Assert.assertEquals(String.format(
+                "Unexpected value for property '%s' on element '%s',",
+                propertyName, className), expected,
+                findElement(By.className(className)).getCssValue(propertyName));
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/RunOverflowFixConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/RunOverflowFixConnector.java
new file mode 100644 (file)
index 0000000..a6789eb
--- /dev/null
@@ -0,0 +1,137 @@
+package com.vaadin.tests.widgetset.client;
+
+import com.google.gwt.dom.client.Style;
+import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.Panel;
+import com.vaadin.client.ComponentConnector;
+import com.vaadin.client.ConnectorHierarchyChangeEvent;
+import com.vaadin.client.WidgetUtil;
+import com.vaadin.client.ui.AbstractComponentContainerConnector;
+import com.vaadin.client.ui.VVerticalLayout;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.orderedlayout.VerticalLayoutState;
+import com.vaadin.tests.components.customlayout.OverflowAutoFix;
+
+@SuppressWarnings("deprecation")
+@Connect(OverflowAutoFix.RunOverflowFix.class)
+public class RunOverflowFixConnector extends
+        AbstractComponentContainerConnector {
+
+    private static final String CONTENT1 = "Overflow:<br>Fix1 (scroll): Both scrollbars should be shown<br>Fix2 (visible): no scrollbars should be shown";
+    private static final String CONTENT2 = "OverflowX:<br>Fix1 (hidden): Horizontal scrollbar should be hidden, vertical shown<br>Fix2 (scroll): Both scrollbars should be shown";
+    private static final String CONTENT3 = "OverflowY:<br>Fix1 (hidden): Vertical scrollbar should be hidden, horizontal shown<br>Fix2 (auto): Both scrollbars should be shown";
+    private static final String BACKGROUND = "#ddd";
+
+    @Override
+    public void init() {
+        super.init();
+
+        final Panel overflow = createScrollPanel(CONTENT1);
+        overflow.addStyleName("first-scrollbar");
+        final Panel overflowX = createScrollPanel(CONTENT2);
+        overflowX.addStyleName("second-scrollbar");
+        final Panel overflowY = createScrollPanel(CONTENT3);
+        overflowY.addStyleName("third-scrollbar");
+
+        Button runFix = new Button("Click to runWebkitOverflowAutoFix",
+                new ClickHandler() {
+                    @Override
+                    public void onClick(ClickEvent event) {
+                        overflow.getElement().getStyle()
+                                .setOverflow(Style.Overflow.SCROLL);
+                        WidgetUtil.runWebkitOverflowAutoFix(overflow
+                                .getElement());
+
+                        overflowX.getElement().getStyle()
+                                .setOverflowX(Style.Overflow.HIDDEN);
+                        WidgetUtil.runWebkitOverflowAutoFix(overflowX
+                                .getElement());
+
+                        overflowY.getElement().getStyle()
+                                .setOverflowY(Style.Overflow.HIDDEN);
+                        WidgetUtil.runWebkitOverflowAutoFix(overflowY
+                                .getElement());
+                    }
+                });
+        runFix.addStyleName("run-button-one");
+        getWidget().add(runFix);
+
+        Button runFix2 = new Button("Click to runWebkitOverflowAutoFix 2",
+                new ClickHandler() {
+                    @Override
+                    public void onClick(ClickEvent event) {
+                        overflow.getElement().getStyle()
+                                .setOverflow(Style.Overflow.VISIBLE);
+                        WidgetUtil.runWebkitOverflowAutoFix(overflow
+                                .getElement());
+
+                        overflowX.getElement().getStyle()
+                                .setOverflowX(Style.Overflow.SCROLL);
+                        WidgetUtil.runWebkitOverflowAutoFix(overflowX
+                                .getElement());
+
+                        overflowY.getElement().getStyle()
+                                .setOverflowY(Style.Overflow.AUTO);
+                        WidgetUtil.runWebkitOverflowAutoFix(overflowY
+                                .getElement());
+                    }
+                });
+        runFix2.addStyleName("run-button-two");
+        getWidget().add(runFix2);
+
+        addSpacer(10);
+        getWidget().add(overflow);
+        addSpacer(60);
+        getWidget().add(overflowX);
+        addSpacer(60);
+        getWidget().add(overflowY);
+    }
+
+    private void addSpacer(double height) {
+        Element spacer = DOM.createDiv();
+        spacer.getStyle().setHeight(height, Unit.PX);
+        spacer.getStyle().setWidth(10, Unit.PX);
+        getWidget().getElement().appendChild(spacer);
+    }
+
+    private Panel createScrollPanel(String info) {
+        FlowPanel outer = new FlowPanel();
+        outer.setPixelSize(300, 200);
+        getWidget().add(outer);
+
+        HTML inner = new HTML(info);
+        inner.setPixelSize(350, 250);
+        inner.getElement().getStyle().setBackgroundColor(BACKGROUND);
+        // for some reason theme sets size to 0
+        inner.getElement().getStyle().setFontSize(12, Style.Unit.PX);
+        outer.add(inner);
+
+        return outer;
+    }
+
+    @Override
+    public VVerticalLayout getWidget() {
+        return (VVerticalLayout) super.getWidget();
+    }
+
+    @Override
+    public VerticalLayoutState getState() {
+        return (VerticalLayoutState) super.getState();
+    }
+
+    @Override
+    public void updateCaption(ComponentConnector connector) {
+    }
+
+    @Override
+    public void onConnectorHierarchyChange(
+            ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {
+    }
+}
\ No newline at end of file