]> source.dussan.org Git - vaadin-framework.git/commitdiff
Ticket #12727 - Panels get unnecessary scroll bars in WebKit when content is 100...
authorFelype Santiago Ferreira <felype@vaadin.com>
Fri, 18 Oct 2013 07:44:35 +0000 (10:44 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 21 Oct 2013 12:25:17 +0000 (12:25 +0000)
Change-Id: Ia34e7c3ce755556460d237fb3489501274ced39f

client/src/com/vaadin/client/ui/VPanel.java
uitest/src/com/vaadin/tests/components/panel/WebkitScrollbarTest.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/panel/WebkitScrollbarTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/tickets/Ticket12727.java [new file with mode: 0644]

index 6b02f079d17a7cce5de163ad3bde2f8e7320f8d0..1a87362fea6bcbd8b7d989622dabfe261d4de8a0 100644 (file)
 
 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 (file)
index 0000000..ee33ee2
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+    <td>open</td>
+    <td>/run/com.vaadin.tests.components.panel.WebkitScrollbarTest?restartApplication</td>
+    <td></td>
+</tr>
+<tr>
+    <td>screenCapture</td>
+    <td></td>
+    <td>panelShouldNotHaveScrollbars</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
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 (file)
index 0000000..8981f52
--- /dev/null
@@ -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 (file)
index 0000000..40711c6
--- /dev/null
@@ -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<String> values = new ArrayList<String>();
+        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);
+    }
+}