diff options
author | Anna Koskinen <anna@vaadin.com> | 2014-10-16 13:37:48 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2015-01-30 13:12:14 +0000 |
commit | e88f71dd6d1d7634e3a90a7e53859ff6dc028e21 (patch) | |
tree | 8ac7f9b413734fdc7a223ae919ba416f70b57fe0 /server/src/com/vaadin/event | |
parent | 6f0817fbe7ad064b4a7d38db341575f02efc193b (diff) | |
download | vaadin-framework-e88f71dd6d1d7634e3a90a7e53859ff6dc028e21.tar.gz vaadin-framework-e88f71dd6d1d7634e3a90a7e53859ff6dc028e21.zip |
Moved accessibility shortcut handling to server-side. [#14843]
Also allowed multiple shortcuts for closing Window.
Change-Id: I35280ad1553af10ae54bc001e5707357f206b0ee
Diffstat (limited to 'server/src/com/vaadin/event')
-rw-r--r-- | server/src/com/vaadin/event/ShortcutAction.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/server/src/com/vaadin/event/ShortcutAction.java b/server/src/com/vaadin/event/ShortcutAction.java index 09accae1c7..32b909e9f2 100644 --- a/server/src/com/vaadin/event/ShortcutAction.java +++ b/server/src/com/vaadin/event/ShortcutAction.java @@ -17,6 +17,8 @@ package com.vaadin.event; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -237,6 +239,42 @@ public class ShortcutAction extends Action { } /** + * Checks whether the shortcut can be triggered with the given combination + * of keys. + * + * @param keyCode + * potential match for the {@link KeyCode} that this shortcut + * reacts to + * @param modifierKeys + * (optional) potential matches for the {@link ModifierKey}s + * required for this shortcut to react + * @return <code>true</code> if keyCode and modifierKeys are a match, + * <code>false</code> otherwise + */ + public boolean isTriggeredBy(int keyCode, int... modifierKeys) { + boolean result = false; + if (keyCode == this.keyCode) { + if (modifierKeys == null) { + result = (modifiers == null); + } else if (modifiers != null) { + List<Integer> modifierList = new ArrayList<Integer>(); + for (int modifier : modifiers) { + modifierList.add(modifier); + } + for (int modifierKey : modifierKeys) { + if (modifierList.contains(modifierKey)) { + modifierList.remove(modifierKey); + } else { + return false; + } + } + result = modifierList.isEmpty(); + } + } + return result; + } + + /** * Key codes that can be used for shortcuts * */ |