From ab5b20cf502f99944c82f619ffef387f0525e8ba Mon Sep 17 00:00:00 2001 From: Felype Santiago Ferreira Date: Fri, 18 Oct 2013 10:44:35 +0300 Subject: [PATCH] Ticket #12727 - Panels get unnecessary scroll bars in WebKit when content is 100% wide. Change-Id: Ia34e7c3ce755556460d237fb3489501274ced39f --- client/src/com/vaadin/client/ui/VPanel.java | 35 +++++++++++ .../components/panel/WebkitScrollbarTest.html | 27 ++++++++ .../components/panel/WebkitScrollbarTest.java | 63 +++++++++++++++++++ .../com/vaadin/tests/tickets/Ticket12727.java | 51 +++++++++++++++ 4 files changed, 176 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/panel/WebkitScrollbarTest.html create mode 100644 uitest/src/com/vaadin/tests/components/panel/WebkitScrollbarTest.java create mode 100644 uitest/src/com/vaadin/tests/tickets/Ticket12727.java diff --git a/client/src/com/vaadin/client/ui/VPanel.java b/client/src/com/vaadin/client/ui/VPanel.java index 6b02f079d1..1a87362fea 100644 --- a/client/src/com/vaadin/client/ui/VPanel.java +++ b/client/src/com/vaadin/client/ui/VPanel.java @@ -16,13 +16,17 @@ 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.ui.ShortcutActionHandler.ShortcutActionHandlerOwner; import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler; @@ -206,5 +210,36 @@ 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 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(); + 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); + } + }); + } + } } diff --git a/uitest/src/com/vaadin/tests/components/panel/WebkitScrollbarTest.html b/uitest/src/com/vaadin/tests/components/panel/WebkitScrollbarTest.html new file mode 100644 index 0000000000..ee33ee2bf0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/panel/WebkitScrollbarTest.html @@ -0,0 +1,27 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.panel.WebkitScrollbarTest?restartApplication
screenCapturepanelShouldNotHaveScrollbars
+ + diff --git a/uitest/src/com/vaadin/tests/components/panel/WebkitScrollbarTest.java b/uitest/src/com/vaadin/tests/components/panel/WebkitScrollbarTest.java new file mode 100644 index 0000000000..8981f52f12 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/panel/WebkitScrollbarTest.java @@ -0,0 +1,63 @@ +/* + * 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.panel; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.ListSelect; +import com.vaadin.ui.Panel; +import com.vaadin.ui.VerticalLayout; + +@SuppressWarnings("serial") +public class WebkitScrollbarTest extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Panel panel = new Panel(); + + VerticalLayout content = new VerticalLayout(); + panel.setContent(content); + + GridLayout gridLayout = new GridLayout(); + gridLayout.setHeight(null); + gridLayout.setWidth(100, Unit.PERCENTAGE); + content.addComponent(gridLayout); + + ListSelect listSelect = new ListSelect(); + + listSelect.setWidth(100, Unit.PERCENTAGE); + listSelect.setHeight(300, Unit.PIXELS); + + gridLayout.addComponent(listSelect); + + gridLayout.setMargin(true); + + setContent(panel); + } + + @Override + protected String getTestDescription() { + return "When opening the window, it should NOT contain a horizontal"; + } + + @Override + protected Integer getTicketNumber() { + return 12727; + } + +} diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket12727.java b/uitest/src/com/vaadin/tests/tickets/Ticket12727.java new file mode 100644 index 0000000000..40711c6b7f --- /dev/null +++ b/uitest/src/com/vaadin/tests/tickets/Ticket12727.java @@ -0,0 +1,51 @@ +package com.vaadin.tests.tickets; + +import java.util.ArrayList; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.ListSelect; +import com.vaadin.ui.Panel; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +/** + * Test for #12727: Panels get unnecessary scroll bars in WebKit when content is + * 100% wide. + */ +@SuppressWarnings("serial") +public class Ticket12727 extends UI { + + @Override + protected void init(VaadinRequest request) { + Panel panel = new Panel(); + + VerticalLayout content = new VerticalLayout(); + panel.setContent(content); + + GridLayout gridLayout = new GridLayout(); + gridLayout.setHeight(null); + gridLayout.setWidth(100, Unit.PERCENTAGE); + content.addComponent(gridLayout); + + ListSelect listSelect = new ListSelect(); + + listSelect.setWidth(100, Unit.PERCENTAGE); + listSelect.setHeight(500, Unit.PIXELS); + + gridLayout.addComponent(listSelect); + + ArrayList values = new ArrayList(); + values.add("Value 1"); + values.add("Value 2"); + values.add("Value 3"); + + ComboBox comboBox = new ComboBox(null, values); + gridLayout.addComponent(comboBox); + + gridLayout.setMargin(true); + + setContent(panel); + } +} -- 2.39.5