]> source.dussan.org Git - vaadin-framework.git/commitdiff
Calculate Grid sidebar button height when closed #17412
authorPekka Hyvönen <pekka@vaadin.com>
Tue, 14 Apr 2015 12:39:18 +0000 (15:39 +0300)
committerVaadin Code Review <review@vaadin.com>
Thu, 16 Apr 2015 08:44:32 +0000 (08:44 +0000)
+ contains Valo theming fixes for all browsers.
+ includes screenshot test for sidebar in Valo

Change-Id: Ic6401057efff7e4d4ab65c46885dda2d995bce5d

WebContent/VAADIN/themes/base/grid/grid.scss
WebContent/VAADIN/themes/reindeer/grid/grid.scss
WebContent/VAADIN/themes/valo/components/_grid.scss
client/src/com/vaadin/client/widgets/Grid.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridColumnHidingTest.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSidebarThemeTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/LoadingIndicatorTest.java
uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java

index 0e1dee2b996266527a05da2a93de27fcef62db38..d6509c12163adffd36ba286bf58c8c288ab5ab1e 100644 (file)
@@ -85,9 +85,9 @@ $v-grid-details-border-bottom-stripe: 1px solid darken($v-grid-row-background-co
       }
     }
   }
-  
+
   // Sidebar
-  
+
   .#{$primaryStyleName}-sidebar.v-contextmenu {
     @include box-shadow(none);
     position: absolute;
@@ -103,32 +103,44 @@ $v-grid-details-border-bottom-stripe: 1px solid darken($v-grid-row-background-co
       background: transparent;
       border: none;
       cursor: pointer;
-      height: $v-grid-header-row-height;
       outline: none;
       padding: 0 4px;
       text-align: right;
 
+      &::-moz-focus-inner {
+        border: 0;
+      }
+
       &:after {
         content: "\f0c9";
+        display: block;
         font-family: FontAwesome, sans-serif;
         font-size: $v-grid-header-font-size;
-        line-height: $v-grid-header-row-height;
       }
     }
 
     &.closed {
       border-radius: 0;
     }
-    
+
     &.opened {
       .#{$primaryStyleName}-sidebar-button {
         width: 100%;
-      
         &:after {
           content: "\00d7";
           font-size: 16px;
+          line-height: 1;
         }
       }
+    }      
+
+    .v-ie &.opened .#{$primaryStyleName}-sidebar-button {
+      vertical-align: middle;
+    }
+
+    .v-ie8 &.opened .#{$primaryStyleName}-sidebar-button:after {
+      display: inline;
     }
 
     .#{$primaryStyleName}-sidebar-content {
index f9b966096acf946f71468172da1ac4c2e8e265ae..7ae0f402aa74572f77da0593b40823c391cb8b60 100644 (file)
       border-color: #b1cde4;
     }
   }
-  
+
   // Sidebar
   .#{$primaryStyleName}-sidebar.v-contextmenu {
-    &.closed {
-      .#{$primaryStyleName}-sidebar-button:after {
-        line-height: 20px;
-      }
-    }
-    
     .#{$primaryStyleName}-sidebar-content {
       background-color: #f8f8f9;
     }
index c1862c82093467d089e92ab0e29fc3485a8e3eaa..c07d330410261df2b9fd55433c881ca6916774ed 100644 (file)
@@ -193,24 +193,19 @@ $v-grid-details-border-bottom-stripe: $v-grid-cell-horizontal-border !default;
     &.opened {
       .#{$primary-stylename}-sidebar-button:after {
         font-size: 20px;
-        line-height: 20px;
       }
-      
+
       .#{$primary-stylename}-sidebar-content {
         margin: 0 0 2px;
         padding: 4px 4px 2px;
       }
     }
-    
+
     &.closed {
       @include valo-gradient($v-grid-header-background-color);
-      
-      .#{$primary-stylename}-sidebar-button {
-        line-height: 36px;
-      }
     }
   }
-  
+
   // Customize scrollbars
   .#{$primary-stylename}-scroller {
     &::-webkit-scrollbar {
index f45d8ef3b4a8323b23545f76ac07eef888b6e50e..220e83257b61d475b64a4e6ce515998251cc1697 100644 (file)
@@ -3080,6 +3080,7 @@ public class Grid<T> extends ResizeComposite implements
                 removeStyleName("closed");
                 rootContainer.add(content);
             }
+            openCloseButton.setHeight("");
         }
 
         /**
@@ -3090,6 +3091,8 @@ public class Grid<T> extends ResizeComposite implements
                 removeStyleName("opened");
                 addStyleName("closed");
                 content.removeFromParent();
+                // adjust open button to header height when closed
+                setHeightToHeaderCellHeight();
             }
         }
 
@@ -3156,6 +3159,23 @@ public class Grid<T> extends ResizeComposite implements
             }
         }
 
+        private void setHeightToHeaderCellHeight() {
+            try {
+                double height = WidgetUtil
+                        .getRequiredHeightBoundingClientRectDouble(grid.escalator
+                                .getHeader().getRowElement(0)
+                                .getFirstChildElement())
+                        - (WidgetUtil.measureVerticalBorder(getElement()) / 2);
+                openCloseButton.setHeight(height + "px");
+            } catch (NullPointerException npe) {
+                getLogger()
+                        .warning(
+                                "Got null header first row or first row cell when calculating sidebar button height");
+                openCloseButton.setHeight(grid.escalator.getHeader()
+                        .getDefaultRowHeight() + "px");
+            }
+        }
+
         private void updateVisibility() {
             final boolean hasWidgets = content.getWidgetCount() > 0;
             final boolean isVisible = isInDOM();
@@ -3166,6 +3186,8 @@ public class Grid<T> extends ResizeComposite implements
                 close();
                 grid.getElement().appendChild(getElement());
                 Grid.setParent(this, grid);
+                // border calculation won't work until attached
+                setHeightToHeaderCellHeight();
             }
         }
 
index ca8ea9fd75514c0f3577943eb15a2171ffc43434..469bf37c2f1e10925876fa025e5490960619ed98 100644 (file)
@@ -233,4 +233,31 @@ public abstract class GridBasicFeaturesTest extends MultiBrowserTest {
         assertTrue(getGridElement().getCell(row, column).getAttribute("class")
                 .contains("focused"));
     }
+
+    protected WebElement getSidebar() {
+        List<WebElement> elements = findElements(By.className("v-grid-sidebar"));
+        return elements.isEmpty() ? null : elements.get(0);
+    }
+
+    protected WebElement getSidebarOpenButton() {
+        List<WebElement> elements = findElements(By
+                .className("v-grid-sidebar-button"));
+        return elements.isEmpty() ? null : elements.get(0);
+    }
+
+    /**
+     * Returns the toggle inside the sidebar for hiding the column at the given
+     * index, or null if not found.
+     */
+    protected WebElement getColumnHidingToggle(int columnIndex) {
+        WebElement sidebar = getSidebar();
+        List<WebElement> elements = sidebar.findElements(By
+                .className("column-hiding-toggle"));
+        for (WebElement e : elements) {
+            if ((e.getText().toLowerCase()).startsWith("column " + columnIndex)) {
+                return e;
+            }
+        }
+        return null;
+    }
 }
index 1213e027995cd58c6aef8075fce4e1d89e7727cd..b446bdef48a16ebe9b2349ce9f97b1e350e376b3 100644 (file)
@@ -921,12 +921,14 @@ public class GridColumnHidingTest extends GridBasicClientFeaturesTest {
         assertNotNull(sidebar);
     }
 
-    private WebElement getSidebar() {
+    @Override
+    protected WebElement getSidebar() {
         List<WebElement> elements = findElements(By.className("v-grid-sidebar"));
         return elements.isEmpty() ? null : elements.get(0);
     }
 
-    private WebElement getSidebarOpenButton() {
+    @Override
+    protected WebElement getSidebarOpenButton() {
         List<WebElement> elements = findElements(By
                 .className("v-grid-sidebar-button"));
         return elements.isEmpty() ? null : elements.get(0);
@@ -936,7 +938,8 @@ public class GridColumnHidingTest extends GridBasicClientFeaturesTest {
      * Returns the toggle inside the sidebar for hiding the column at the given
      * index, or null if not found.
      */
-    private WebElement getColumnHidingToggle(int columnIndex) {
+    @Override
+    protected WebElement getColumnHidingToggle(int columnIndex) {
         WebElement sidebar = getSidebar();
         List<WebElement> elements = sidebar.findElements(By
                 .className("column-hiding-toggle"));
index 794265057643491841c44c8a0257a35d8cd86a93..d01e689b7230ccc9a3123da66f7a1154157ed8d9 100644 (file)
@@ -21,12 +21,8 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.List;
-
 import org.junit.Before;
 import org.junit.Test;
-import org.openqa.selenium.By;
-import org.openqa.selenium.WebElement;
 
 import com.vaadin.testbench.parallel.TestCategory;
 import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
@@ -281,31 +277,4 @@ public class GridColumnVisibilityTest extends GridBasicFeaturesTest {
         selectMenuPath("Component", "Columns", "Column " + index,
                 "Add / Remove");
     }
-
-    private WebElement getSidebar() {
-        List<WebElement> elements = findElements(By.className("v-grid-sidebar"));
-        return elements.isEmpty() ? null : elements.get(0);
-    }
-
-    private WebElement getSidebarOpenButton() {
-        List<WebElement> elements = findElements(By
-                .className("v-grid-sidebar-button"));
-        return elements.isEmpty() ? null : elements.get(0);
-    }
-
-    /**
-     * Returns the toggle inside the sidebar for hiding the column at the given
-     * index, or null if not found.
-     */
-    private WebElement getColumnHidingToggle(int columnIndex) {
-        WebElement sidebar = getSidebar();
-        List<WebElement> elements = sidebar.findElements(By
-                .className("column-hiding-toggle"));
-        for (WebElement e : elements) {
-            if ((e.getText().toLowerCase()).startsWith("column " + columnIndex)) {
-                return e;
-            }
-        }
-        return null;
-    }
 }
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSidebarThemeTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSidebarThemeTest.java
new file mode 100644 (file)
index 0000000..7932799
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2000-2014 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.grid.basicfeatures.server;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+
+import com.vaadin.testbench.parallel.Browser;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+
+public class GridSidebarThemeTest extends GridBasicFeaturesTest {
+
+    @Test
+    public void testValo() throws Exception {
+        runTestSequence("valo");
+    }
+
+    private void runTestSequence(String theme) throws IOException {
+        openTestURL("theme=" + theme);
+        if (getDesiredCapabilities().getBrowserName().equals(
+                Browser.CHROME.getDesiredCapabilities().getBrowserName())) {
+            waitUntil(ExpectedConditions.elementToBeClickable(By.id("menu")), 2);
+            getDriver().findElement(By.id("menu")).click();
+            selectMenu("Columns");
+            selectMenu("All columns hidable");
+            waitUntilLoadingIndicatorNotVisible();
+        } else {
+            selectMenuPath("Component", "Columns", "All columns hidable");
+        }
+
+        compareScreen(theme + "|SidebarClosed");
+        getSidebarOpenButton().click();
+
+        compareScreen(theme + "|SidebarOpen");
+
+        new Actions(getDriver()).moveToElement(getColumnHidingToggle(2), 5, 5)
+                .perform();
+
+        compareScreen(theme + "|OnMouseOverNotHiddenToggle");
+
+        getColumnHidingToggle(2).click();
+        getColumnHidingToggle(3).click();
+        getColumnHidingToggle(6).click();
+
+        new Actions(getDriver()).moveToElement(getSidebarOpenButton())
+                .perform();
+        ;
+
+        compareScreen(theme + "|TogglesTriggered");
+
+        new Actions(getDriver()).moveToElement(getColumnHidingToggle(2))
+                .perform();
+        ;
+
+        compareScreen(theme + "|OnMouseOverHiddenToggle");
+
+        getSidebarOpenButton().click();
+
+        compareScreen(theme + "|SidebarClosed2");
+    }
+
+    @Override
+    public List<DesiredCapabilities> getBrowsersToTest() {
+        // phantom JS looks wrong from the beginning, so not tested
+        return getBrowsersExcludingPhantomJS();
+    }
+}
index f25131310000f6ce61cbe5afee17c36462b7d13b..f4771b90679b9ba0ba17b26dc6a19d93c54c60d4 100644 (file)
@@ -19,7 +19,6 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.openqa.selenium.By;
 import org.openqa.selenium.WebDriver;
-import org.openqa.selenium.WebElement;
 import org.openqa.selenium.support.ui.ExpectedCondition;
 import org.openqa.selenium.support.ui.ExpectedConditions;
 
@@ -83,10 +82,4 @@ public class LoadingIndicatorTest extends GridBasicFeaturesTest {
         });
     }
 
-    private boolean isLoadingIndicatorVisible() {
-        WebElement loadingIndicator = findElement(By
-                .className("v-loading-indicator"));
-
-        return loadingIndicator.isDisplayed();
-    }
 }
index 2d032ecd9eb8c280ac52d53399677aedf2b087fa..48f99e5057b7c6f12b4bcd682649da2abd35a628 100644 (file)
@@ -938,4 +938,24 @@ public abstract class AbstractTB3Test extends ParallelTest {
     protected void click(CheckBoxElement checkbox) {
         checkbox.findElement(By.xpath("input")).click();
     }
+
+    protected boolean isLoadingIndicatorVisible() {
+        WebElement loadingIndicator = findElement(By
+                .className("v-loading-indicator"));
+
+        return loadingIndicator.isDisplayed();
+    }
+
+    protected void waitUntilLoadingIndicatorNotVisible() {
+        waitUntil(new ExpectedCondition<Boolean>() {
+
+            @Override
+            public Boolean apply(WebDriver input) {
+                WebElement loadingIndicator = input.findElement(By
+                        .className("v-loading-indicator"));
+
+                return !loadingIndicator.isDisplayed();
+            }
+        });
+    }
 }