summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Murtojarvi <mika@vaadin.com>2013-10-29 15:22:45 +0200
committerVaadin Code Review <review@vaadin.com>2013-10-30 13:39:05 +0000
commit017bd0684c7d6c8475c8b43514e6f3998095c8d6 (patch)
treef421a4ae7e4b10e7339f6f1acc56b66aa0f0b15a
parent878c2bd4643c9cf08fb0ed2da8bae7f7a626ce8b (diff)
downloadvaadin-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
-rw-r--r--client/src/com/vaadin/client/Util.java55
-rw-r--r--client/src/com/vaadin/client/ui/VPanel.java44
-rw-r--r--client/src/com/vaadin/client/ui/VWindow.java32
-rw-r--r--uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindow.java66
-rw-r--r--uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindowTest.java57
5 files changed, 183 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();
}
}
diff --git a/uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindow.java b/uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindow.java
new file mode 100644
index 0000000000..6347ff9a76
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindow.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.window;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+/**
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ComboboxScrollableWindow extends AbstractTestUI {
+
+ static final String WINDOW_ID = "window";
+ static final String COMBOBOX_ID = "combobox";
+
+ @Override
+ protected void setup(VaadinRequest request) {
+
+ Window w = new Window();
+ w.setId(WINDOW_ID);
+ w.setWidth("300px");
+ w.setHeight("300px");
+ w.center();
+
+ VerticalLayout content = new VerticalLayout();
+ w.setContent(content);
+ content.setHeight("1000px");
+ ComboBox cb = new ComboBox();
+ cb.setId(COMBOBOX_ID);
+ content.addComponent(cb);
+ content.setComponentAlignment(cb, Alignment.BOTTOM_CENTER);
+
+ addWindow(w);
+
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "The combo box in the bottom of the scrollable window should remain visible when it is clicked.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 12736;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindowTest.java b/uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindowTest.java
new file mode 100644
index 0000000000..665e175f2c
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/window/ComboboxScrollableWindowTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.window;
+
+import static com.vaadin.tests.components.window.ComboboxScrollableWindow.COMBOBOX_ID;
+import static com.vaadin.tests.components.window.ComboboxScrollableWindow.WINDOW_ID;
+
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.commands.TestBenchElementCommands;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ComboboxScrollableWindowTest extends MultiBrowserTest {
+
+ @Test
+ public void testWindowScrollbars() throws Exception {
+ openTestURL();
+ com.vaadin.testbench.Parameters
+ .setScreenshotComparisonCursorDetection(true);
+
+ WebElement window = driver.findElement(By.id(WINDOW_ID));
+ WebElement scrollableElement = window.findElement(By
+ .className("v-scrollable"));
+ TestBenchElementCommands scrollable = testBenchElement(scrollableElement);
+ scrollable.scroll(1000);
+ WebElement comboBox = driver.findElement(By.id(COMBOBOX_ID));
+ WebElement selectButton = driver.findElement(By
+ .className("v-filterselect-button"));
+ selectButton.click();
+
+ // Wait for the browser before taking a screenshot
+ Thread.sleep(1000);
+ compareScreen(getScreenshotBaseName());
+
+ }
+
+}