]> source.dussan.org Git - vaadin-framework.git/commitdiff
Prevent dispatching GridKeyEvents when target is not grid (#13334)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Mon, 15 Sep 2014 08:22:32 +0000 (11:22 +0300)
committerJohannes Dahlström <johannesd@vaadin.com>
Mon, 15 Sep 2014 19:58:46 +0000 (19:58 +0000)
Change-Id: I2efd6d48502360d14d21456077d50b37fa8a4be6

client/src/com/vaadin/client/ui/grid/Grid.java
client/src/com/vaadin/client/ui/grid/events/GridKeyDownEvent.java
client/src/com/vaadin/client/ui/grid/events/GridKeyPressEvent.java
client/src/com/vaadin/client/ui/grid/events/GridKeyUpEvent.java
uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java

index a667bfa8dd97fbe968ede53ae5b3dde4baa2ba51..5221284c3c1f53eda5b82537aeede5d5096f9f12 100644 (file)
@@ -135,7 +135,6 @@ public class Grid<T> extends Composite implements
 
         private Grid<?> grid;
         protected Cell activeCell;
-        protected GridSection activeSection;
         private final Type<HANDLER> associatedType = new Type<HANDLER>(
                 getBrowserEventType(), this);
 
@@ -165,16 +164,25 @@ public class Grid<T> extends Composite implements
 
         @Override
         protected void dispatch(HANDLER handler) {
-            activeCell = grid.activeCellHandler.getActiveCell();
-            activeSection = GridSection.FOOTER;
-            final RowContainer container = grid.activeCellHandler.container;
-            if (container == grid.escalator.getHeader()) {
-                activeSection = GridSection.HEADER;
-            } else if (container == grid.escalator.getBody()) {
-                activeSection = GridSection.BODY;
+            EventTarget target = getNativeEvent().getEventTarget();
+            if (Element.is(target)
+                    && Util.findWidget(Element.as(target), null) == grid) {
+
+                activeCell = grid.activeCellHandler.getActiveCell();
+                GridSection section = GridSection.FOOTER;
+                final RowContainer container = grid.activeCellHandler.container;
+                if (container == grid.escalator.getHeader()) {
+                    section = GridSection.HEADER;
+                } else if (container == grid.escalator.getBody()) {
+                    section = GridSection.BODY;
+                }
+
+                doDispatch(handler, section);
             }
         }
 
+        protected abstract void doDispatch(HANDLER handler, GridSection seciton);
+
         @Override
         public Type<HANDLER> getAssociatedType() {
             return associatedType;
index 2fab683bb037291affda24d0c9d3499d63d3e8b6..81ff0e0a19d0f1343e28f99e2da50e671320b699 100644 (file)
@@ -33,11 +33,10 @@ public class GridKeyDownEvent extends AbstractGridKeyEvent<GridKeyDownHandler> {
     }
 
     @Override
-    protected void dispatch(GridKeyDownHandler handler) {
-        super.dispatch(handler);
-        if ((activeSection == GridSection.BODY && handler instanceof BodyKeyDownHandler)
-                || (activeSection == GridSection.HEADER && handler instanceof HeaderKeyDownHandler)
-                || (activeSection == GridSection.FOOTER && handler instanceof FooterKeyDownHandler)) {
+    protected void doDispatch(GridKeyDownHandler handler, GridSection section) {
+        if ((section == GridSection.BODY && handler instanceof BodyKeyDownHandler)
+                || (section == GridSection.HEADER && handler instanceof HeaderKeyDownHandler)
+                || (section == GridSection.FOOTER && handler instanceof FooterKeyDownHandler)) {
             handler.onKeyDown(this);
         }
     }
index 112200b03a29589f180128834d769a387b7248b5..9033344597498ce38b58ded1544a753b32174655 100644 (file)
@@ -34,11 +34,10 @@ public class GridKeyPressEvent extends
     }
 
     @Override
-    protected void dispatch(GridKeyPressHandler handler) {
-        super.dispatch(handler);
-        if ((activeSection == GridSection.BODY && handler instanceof BodyKeyPressHandler)
-                || (activeSection == GridSection.HEADER && handler instanceof HeaderKeyPressHandler)
-                || (activeSection == GridSection.FOOTER && handler instanceof FooterKeyPressHandler)) {
+    protected void doDispatch(GridKeyPressHandler handler, GridSection section) {
+        if ((section == GridSection.BODY && handler instanceof BodyKeyPressHandler)
+                || (section == GridSection.HEADER && handler instanceof HeaderKeyPressHandler)
+                || (section == GridSection.FOOTER && handler instanceof FooterKeyPressHandler)) {
             handler.onKeyPress(this);
         }
     }
index 9aa8ce70844251a9fdf2cd762723fc604952a8cf..623f3d5ed88095b2c60cacf842711c7deb67696e 100644 (file)
@@ -33,11 +33,10 @@ public class GridKeyUpEvent extends AbstractGridKeyEvent<GridKeyUpHandler> {
     }
 
     @Override
-    protected void dispatch(GridKeyUpHandler handler) {
-        super.dispatch(handler);
-        if ((activeSection == GridSection.BODY && handler instanceof BodyKeyUpHandler)
-                || (activeSection == GridSection.HEADER && handler instanceof HeaderKeyUpHandler)
-                || (activeSection == GridSection.FOOTER && handler instanceof FooterKeyUpHandler)) {
+    protected void doDispatch(GridKeyUpHandler handler, GridSection section) {
+        if ((section == GridSection.BODY && handler instanceof BodyKeyUpHandler)
+                || (section == GridSection.HEADER && handler instanceof HeaderKeyUpHandler)
+                || (section == GridSection.FOOTER && handler instanceof FooterKeyUpHandler)) {
             handler.onKeyUp(this);
         }
     }
index fe81380296b4da84b6fcc19846ccfe7448a663be..47bd9f6cb7ca613ff38e56e79bc02c38deadefa6 100644 (file)
@@ -27,6 +27,7 @@ import org.openqa.selenium.Keys;
 import org.openqa.selenium.interactions.Actions;
 
 import com.vaadin.testbench.By;
+import com.vaadin.tests.components.grid.GridElement.GridCellElement;
 import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
 
 public class GridClientKeyEventsTest extends GridBasicClientFeaturesTest {
@@ -105,4 +106,22 @@ public class GridClientKeyEventsTest extends GridBasicClientFeaturesTest {
         }
     }
 
+    @Test
+    public void testNoKeyEventsFromWidget() {
+        openTestURL();
+
+        selectMenuPath("Component", "Columns", "Column 2", "Header Type",
+                "Widget Header");
+        GridCellElement header = getGridElement().getHeaderCell(0, 2);
+        header.findElement(By.tagName("button")).click();
+        new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
+
+        for (int i = 0; i < 3; ++i) {
+            assertTrue("Header key event handler got called unexpectedly.",
+                    findElements(By.className("v-label")).get(i * 3 + 1)
+                            .getText().isEmpty());
+
+        }
+    }
+
 }