diff options
author | KatriHaapalinna <haapalinnakatri@gmail.com> | 2019-04-08 14:31:17 +0300 |
---|---|---|
committer | Sun Zhe <31067185+ZheSun88@users.noreply.github.com> | 2019-04-08 14:31:17 +0300 |
commit | 262863dbf6b33995d47bd9433e8f087d13a468ee (patch) | |
tree | fdb9d8fd7930d8b201e983b2cfe3541e74d66454 /client | |
parent | 7a010de76ec67362d5c9d395c79ce3e22613469f (diff) | |
download | vaadin-framework-262863dbf6b33995d47bd9433e8f087d13a468ee.tar.gz vaadin-framework-262863dbf6b33995d47bd9433e8f087d13a468ee.zip |
Use Enter and Space keys to fire Window header buttons (#11517) (#11534)
* Fixes 11517. Use ENTER and SPACE keys as shortcuts for header buttons
* Merge branch 'master' into fix-11517
* Increase sleep time for test failing in validation
* Merge branch 'master' into fix-11517
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/VWindow.java | 15 | ||||
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java | 22 |
2 files changed, 32 insertions, 5 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VWindow.java b/client/src/main/java/com/vaadin/client/ui/VWindow.java index f7fc2ba6b8..e19a13c005 100644 --- a/client/src/main/java/com/vaadin/client/ui/VWindow.java +++ b/client/src/main/java/com/vaadin/client/ui/VWindow.java @@ -434,7 +434,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, DOM.appendChild(super.getContainerElement(), wrapper); sinkEvents(Event.ONDBLCLICK | Event.MOUSEEVENTS | Event.TOUCHEVENTS - | Event.ONCLICK | Event.ONLOSECAPTURE); + | Event.ONCLICK | Event.ONLOSECAPTURE | Event.ONKEYUP); setWidget(contentPanel); @@ -1008,18 +1008,21 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, final int type = event.getTypeInt(); final Element target = DOM.eventGetTarget(event); - if (resizing || resizeBox == target) { onResizeEvent(event); bubble = false; + // if clicked or key ENTER or SPACE is pressed } else if (isClosable() && target == closeBox) { - if (type == Event.ONCLICK) { + if (type == Event.ONCLICK || (type == Event.ONKEYUP + && isKeyEnterOrSpace(event.getKeyCode()))) { onCloseClick(); } bubble = false; } else if (target == maximizeRestoreBox) { // handled in connector - if (type != Event.ONCLICK) { + // if clicked or key ENTER or SPACE is pressed + if (type != Event.ONCLICK && !(type == Event.ONKEYUP + && isKeyEnterOrSpace(event.getKeyCode()))) { bubble = false; } } else if (header.isOrHasChild(target) && !dragging) { @@ -1571,4 +1574,8 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, return Document.get().getBody() .hasClassName(MODAL_WINDOW_OPEN_CLASSNAME); } + + private boolean isKeyEnterOrSpace(int keyCode) { + return keyCode == KeyCodes.KEY_ENTER || keyCode == KeyCodes.KEY_SPACE; + } } diff --git a/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java b/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java index feb34e502e..12ce828f47 100644 --- a/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java @@ -29,6 +29,9 @@ import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.DoubleClickEvent; import com.google.gwt.event.dom.client.DoubleClickHandler; +import com.google.gwt.event.dom.client.KeyCodes; +import com.google.gwt.event.dom.client.KeyUpEvent; +import com.google.gwt.event.dom.client.KeyUpHandler; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Window; import com.vaadin.client.ApplicationConnection; @@ -67,7 +70,7 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector }; abstract class WindowEventHandler - implements ClickHandler, DoubleClickHandler { + implements ClickHandler, DoubleClickHandler, KeyUpHandler { } private WindowEventHandler maximizeRestoreClickHandler = new WindowEventHandler() { @@ -91,6 +94,18 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector onMaximizeRestore(); } } + + @Override + public void onKeyUp(KeyUpEvent event) { + final int keyCode = event.getNativeKeyCode(); + final Element target = event.getNativeEvent().getEventTarget() + .cast(); + // key ENTER or SPACE on maximize/restore box + if (target == getWidget().maximizeRestoreBox + && isKeyEnterOrSpace(keyCode)) { + onMaximizeRestore(); + } + } }; @Override @@ -115,6 +130,7 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector window.addHandler(maximizeRestoreClickHandler, ClickEvent.getType()); window.addHandler(maximizeRestoreClickHandler, DoubleClickEvent.getType()); + window.addHandler(maximizeRestoreClickHandler, KeyUpEvent.getType()); window.setOwner(getConnection().getUIConnector().getWidget()); @@ -511,4 +527,8 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector getRpcProxy(WindowServerRpc.class).windowMoved(event.getNewX(), event.getNewY()); } + + private boolean isKeyEnterOrSpace(int keyCode) { + return keyCode == KeyCodes.KEY_ENTER || keyCode == KeyCodes.KEY_SPACE; + } } |