summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-01-01 11:53:42 +0200
committerVaadin Code Review <review@vaadin.com>2016-01-04 09:02:13 +0000
commit82d009eb17da0b089535161833ab646566d8f2c5 (patch)
tree05066bf21ec3191e14250a2cc8433b0ced1eec58
parentbc6a82ea2b31a3b2d0e4c79eec3032878598bf0b (diff)
downloadvaadin-framework-82d009eb17da0b089535161833ab646566d8f2c5.tar.gz
vaadin-framework-82d009eb17da0b089535161833ab646566d8f2c5.zip
Listen to body for shortcut actions for standalone apps (#19392)
Change-Id: I48cc4884fce984354dafa2096e488c3c6dec141c
-rw-r--r--client/src/com/vaadin/client/ui/VUI.java12
-rw-r--r--client/src/com/vaadin/client/ui/ui/UIConnector.java21
-rw-r--r--uitest/src/com/vaadin/tests/components/abstractfield/ShortcutWhenBodyFocused.java40
-rw-r--r--uitest/src/com/vaadin/tests/components/abstractfield/ShortcutWhenBodyFocusedTest.java42
4 files changed, 101 insertions, 14 deletions
diff --git a/client/src/com/vaadin/client/ui/VUI.java b/client/src/com/vaadin/client/ui/VUI.java
index 963d83a6e6..08641ad6ba 100644
--- a/client/src/com/vaadin/client/ui/VUI.java
+++ b/client/src/com/vaadin/client/ui/VUI.java
@@ -30,8 +30,6 @@ import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.http.client.URL;
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
@@ -349,16 +347,6 @@ public class VUI extends SimplePanel implements ResizeHandler,
return isEmbedded();
}
- @Override
- public void onBrowserEvent(Event event) {
- super.onBrowserEvent(event);
- int type = DOM.eventGetType(event);
- if (type == Event.ONKEYDOWN && actionHandler != null) {
- actionHandler.handleKeyboardEvent(event);
- return;
- }
- }
-
/*
* (non-Javadoc)
*
diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java
index f5656dfdc4..9ffb9cfba9 100644
--- a/client/src/com/vaadin/client/ui/ui/UIConnector.java
+++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java
@@ -32,6 +32,8 @@ import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.dom.client.StyleElement;
import com.google.gwt.dom.client.StyleInjector;
+import com.google.gwt.event.dom.client.KeyDownEvent;
+import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.dom.client.ScrollEvent;
import com.google.gwt.event.dom.client.ScrollHandler;
import com.google.gwt.event.logical.shared.ResizeEvent;
@@ -495,8 +497,23 @@ public class UIConnector extends AbstractSingleComponentContainerConnector
getHead().appendChild(style);
}
- DOM.sinkEvents(getWidget().getElement(), Event.ONKEYDOWN
- | Event.ONSCROLL);
+ Widget shortcutContextWidget = getWidget();
+ if (applicationConnection.getConfiguration().isStandalone()) {
+ // Listen to body for standalone apps (#19392)
+ shortcutContextWidget = RootPanel.get(); // document body
+ }
+
+ shortcutContextWidget.addDomHandler(new KeyDownHandler() {
+ @Override
+ public void onKeyDown(KeyDownEvent event) {
+ if (getWidget().actionHandler != null) {
+ getWidget().actionHandler.handleKeyboardEvent((Event) event
+ .getNativeEvent().cast());
+ }
+ }
+ }, KeyDownEvent.getType());
+
+ DOM.sinkEvents(getWidget().getElement(), Event.ONSCROLL);
RootPanel root = RootPanel.get(rootPanelId);
diff --git a/uitest/src/com/vaadin/tests/components/abstractfield/ShortcutWhenBodyFocused.java b/uitest/src/com/vaadin/tests/components/abstractfield/ShortcutWhenBodyFocused.java
new file mode 100644
index 0000000000..41a5febc16
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/abstractfield/ShortcutWhenBodyFocused.java
@@ -0,0 +1,40 @@
+/*
+ * 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.abstractfield;
+
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+
+public class ShortcutWhenBodyFocused extends AbstractTestUIWithLog {
+ @Override
+ protected void setup(VaadinRequest request) {
+ Button b = new Button("Hello", new ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log("Hello clicked");
+ }
+ });
+ b.setClickShortcut(KeyCode.A);
+ addComponent(b);
+
+ getPage().getStyles().add("body { width: 50% !important}");
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/abstractfield/ShortcutWhenBodyFocusedTest.java b/uitest/src/com/vaadin/tests/components/abstractfield/ShortcutWhenBodyFocusedTest.java
new file mode 100644
index 0000000000..2d9c9a494b
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/abstractfield/ShortcutWhenBodyFocusedTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.abstractfield;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class ShortcutWhenBodyFocusedTest extends SingleBrowserTest {
+
+ @Test
+ public void triggerShortcutOnBody() {
+ openTestURL();
+ ButtonElement b = $(ButtonElement.class).caption("Hello").first();
+ b.click();
+ Assert.assertEquals("1. Hello clicked", getLogRow(0));
+
+ b.sendKeys("A");
+ Assert.assertEquals("2. Hello clicked", getLogRow(0));
+
+ WebElement body = findElement(By.xpath("//body"));
+ body.sendKeys("A");
+ Assert.assertEquals("3. Hello clicked", getLogRow(0));
+ }
+}