diff options
author | Artur Signell <artur@vaadin.com> | 2016-04-17 18:29:08 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-04-28 15:18:34 +0000 |
commit | c9b1df6d5e9847ef4d5a6e810df22612ecbddca6 (patch) | |
tree | 4161ae80a84f7a77e0c74e8e33b3daf7869e6ce2 | |
parent | 6b9d5161dab6a02601ab11903d55718c8e9239cf (diff) | |
download | vaadin-framework-c9b1df6d5e9847ef4d5a6e810df22612ecbddca6.tar.gz vaadin-framework-c9b1df6d5e9847ef4d5a6e810df22612ecbddca6.zip |
Double check table focus in IE (#19676)
Change-Id: I46d95e0b198dd4594e5c84dda9b6c462d4a7bf51
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/VScrollTable.java | 27 | ||||
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/table/TableJumpUI.java | 135 |
2 files changed, 158 insertions, 4 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VScrollTable.java b/client/src/main/java/com/vaadin/client/ui/VScrollTable.java index 5e5ae8a259..8bdafb9073 100644 --- a/client/src/main/java/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/main/java/com/vaadin/client/ui/VScrollTable.java @@ -569,7 +569,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // Cancel default keyboard events on a disabled Table // (prevents scrolling) event.preventDefault(); - } else if (hasFocus) { + } else if (hasFocus()) { // Key code in Firefox/onKeyPress is present only for // special keys, otherwise 0 is returned int keyCode = event.getKeyCode(); @@ -633,7 +633,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // Cancel default keyboard events on a disabled Table // (prevents scrolling) event.preventDefault(); - } else if (hasFocus) { + } else if (hasFocus()) { if (handleNavigation(event.getKeyCode(), event.getCtrlKey() || event.getMetaKey(), event.getShiftKey())) { navKeyDown = true; @@ -6780,7 +6780,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, * focus only if not currently focused. */ protected void ensureFocus() { - if (!hasFocus) { + if (!hasFocus()) { scrollBodyPanel.setFocus(true); } @@ -7673,7 +7673,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // Set new focused row focusedRow = row; - if (hasFocus) { + if (hasFocus()) { ensureRowIsVisible(row); } @@ -7991,6 +7991,10 @@ public class VScrollTable extends FlowPanel implements HasWidgets, @Override public void onBlur(BlurEvent event) { + onBlur(); + } + + private void onBlur() { hasFocus = false; navKeyDown = false; @@ -8367,4 +8371,19 @@ public class VScrollTable extends FlowPanel implements HasWidgets, public void setChildMeasurementHint(ChildMeasurementHint hint) { childMeasurementHint = hint; } + + private boolean hasFocus() { + if (hasFocus && BrowserInfo.get().isIE()) { + com.google.gwt.user.client.Element focusedElement = Util + .getIEFocusedElement(); + if (!getElement().isOrHasChild(focusedElement)) { + // Does not really have focus but a blur event has been lost + getLogger().warning( + "IE did not send a blur event, firing manually"); + onBlur(); + } + } + return hasFocus; + } + } diff --git a/uitest/src/main/java/com/vaadin/tests/components/table/TableJumpUI.java b/uitest/src/main/java/com/vaadin/tests/components/table/TableJumpUI.java new file mode 100644 index 0000000000..9718236c42 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/table/TableJumpUI.java @@ -0,0 +1,135 @@ +/* + * 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.table; + +import com.vaadin.annotations.Theme; +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.event.FieldEvents.BlurEvent; +import com.vaadin.event.FieldEvents.BlurListener; +import com.vaadin.event.FieldEvents.FocusEvent; +import com.vaadin.event.FieldEvents.FocusListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Table; +import com.vaadin.ui.TextField; +import com.vaadin.ui.themes.ValoTheme; + +/** + * Test for ensuring page doesn't jump up to the Table selection on IE with + * these steps: + * + * <p> + * 1. refresh page <br> + * 2. click within URL bar <br> + * 3. click a table row to select it <br> + * 4. click within one of the text fields <br> + * 5. scroll down <br> + * 6. click the button + * </p> + * The problem is that IE for some reason does not fire a blur event for the + * table at step 4, leading to table thinking it is focused when it is updated + * in step 6. + * + * @author Vaadin Ltd + */ +@Theme(ValoTheme.THEME_NAME) +public class TableJumpUI extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + + BeanItemContainer<TestObj> container = new BeanItemContainer<TestObj>( + TestObj.class); + for (int i = 0; i < 2; i++) { + container.addBean(new TestObj(i)); + } + + final Table table = new Table(); + table.setPageLength(2); + table.setContainerDataSource(container); + table.setSelectable(true); + addComponent(table); + + // After the table we have a lot of textfields so that we have to scroll + // down to the button + for (int i = 0; i < 40; i++) { + TextField tf = new TextField(); + tf.setValue(String.valueOf(i)); + final int j = i; + tf.addFocusListener(new FocusListener() { + @Override + public void focus(FocusEvent event) { + log("Tf " + j + " focus"); + } + }); + tf.addBlurListener(new BlurListener() { + @Override + public void blur(BlurEvent event) { + log("Tf " + j + " Blur"); + } + }); + addComponent(tf); + } + + addButton("refresh row cache", new ClickListener() { + + @Override + public void buttonClick(final ClickEvent event) { + table.refreshRowCache(); + } + }); + } + + @Override + protected String getTestDescription() { + return "Page shouldn't scroll up to Table selection when the button is clicked."; + } + + @Override + protected Integer getTicketNumber() { + return 19676; + } + + public static class TestObj { + int i; + String text; + + public TestObj(final int i) { + this.i = i; + text = "Object " + i; + } + + public int getI() { + return i; + } + + public void setI(final int i) { + this.i = i; + } + + public String getText() { + return text; + } + + public void setText(final String text) { + this.text = text; + } + + } + +}
\ No newline at end of file |