]> source.dussan.org Git - vaadin-framework.git/commitdiff
Check class name type on Grid cell mouse over (#10194)
authorAdam Wagner <wbadam@users.noreply.github.com>
Fri, 20 Oct 2017 08:14:33 +0000 (10:14 +0200)
committerPéter Török <31210544+torok-peter@users.noreply.github.com>
Fri, 20 Oct 2017 08:14:33 +0000 (11:14 +0300)
* Check whether className is of type string

* Move string type checker method to widget util

* Fix formatting of WidgetUtil

* Break svg into lines

client/src/main/java/com/vaadin/client/WidgetUtil.java
client/src/main/java/com/vaadin/client/widgets/Grid.java
uitest/src/main/java/com/vaadin/tests/components/grid/GridSvgInCell.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/grid/GridSvgInCellTest.java [new file with mode: 0644]

index 94439dc945963f220c9da8d8b1b8a1121839c90c..e6304343aac0ca4451726b45e1cd314e5d399883 100644 (file)
@@ -1866,6 +1866,19 @@ public class WidgetUtil {
         return WidgetUtil.getTouchOrMouseClientY(event) - relativeTop;
     }
 
+    /**
+     * Returns whether the given object is a string.
+     *
+     * @param obj
+     *            the object of which the type is examined
+     * @return {@code true} if the object is a string; {@code false} if not
+     * @since
+     */
+    public static native boolean isString(Object obj)
+    /*-{
+        return typeof obj === 'string' || obj instanceof String;
+    }-*/;
+
     /**
      * Utility methods for displaying error message on components.
      *
index 43f85a98483c1da0962c9cb243f8b2dd9bd19a3c..4651c534dc4a749139a4750901ac4f7002eb18c1 100755 (executable)
@@ -7528,7 +7528,12 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
             boolean isElement = Element.is(n);
             if (isElement) {
                 String className = Element.as(n).getClassName();
-                if (className.contains(getStylePrimaryName() + "-spacer")) {
+
+                // Also check whether className is indeed a string. For
+                // SVGElement it may be of type SVGAnimatedString.
+                // https://developer.mozilla.org/en-US/docs/Web/API/Element/className#Notes
+                if (WidgetUtil.isString(className) && className
+                        .contains(getStylePrimaryName() + "-spacer")) {
                     return true;
                 }
             }
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSvgInCell.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSvgInCell.java
new file mode 100644 (file)
index 0000000..fbe59b8
--- /dev/null
@@ -0,0 +1,40 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.renderers.HtmlRenderer;
+
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class GridSvgInCell extends AbstractTestUI {
+
+    private static class DataObject {
+        private String svg;
+
+        public String getSvg() {
+            return svg;
+        }
+
+        public void setSvg(String svg) {
+            this.svg = svg;
+        }
+    }
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        Grid<DataObject> grid = new Grid<>();
+        grid.addColumn(DataObject::getSvg).setCaption("SVG")
+                .setRenderer(new HtmlRenderer(""));
+
+        DataObject data = new DataObject();
+        data.setSvg(
+            "<svg width=\"100%\" height=\"20px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">"
+                + "<polygon id=\"bar_background_blue\" stroke=\"gray\" fill=\"#D6D6D6\" points=\"0 0,59 0,66 7,59 14,0 14\"></polygon>"
+                + "<rect id=\"bar_blue\" x=\"1\" y=\"1\" width=\"0px\" height=\"13\" fill=\"#7298C0\"></rect>"
+                + "</svg>");
+        grid.setItems(data);
+
+        addComponent(grid);
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSvgInCellTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSvgInCellTest.java
new file mode 100644 (file)
index 0000000..ae71746
--- /dev/null
@@ -0,0 +1,24 @@
+package com.vaadin.tests.components.grid;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class GridSvgInCellTest extends SingleBrowserTest {
+
+    @Before
+    public void before() {
+        setDebug(true);
+        openTestURL();
+    }
+
+    @Test
+    public void moveMouseOverSvgInCell() {
+        GridElement grid = $(GridElement.class).first();
+        new Actions(driver).moveToElement(grid.getCell(0, 0)).perform();
+        assertNoErrorNotifications();
+    }
+}