private boolean isCapturing;
/**
- * If <code>true</code>, this widget has focus with the space bar down.
+ * If <code>true</code>, this widget has focus with the space bar down. This
+ * means that we will get events when the button is released, but we should
+ * trigger the button only if the button is still focused at that point.
*/
private boolean isFocusing;
private HandlerRegistration focusHandlerRegistration;
private HandlerRegistration blurHandlerRegistration;
- private int clickShortcut = 0;
-
/**
* If caption should be rendered in HTML
*/
icon = null;
}
}
-
- if (uidl.hasAttribute("keycode")) {
- clickShortcut = uidl.getIntAttribute("keycode");
- }
}
public void setText(String text) {
if ((event.getTypeInt() & Event.KEYEVENTS) != 0) {
switch (type) {
case Event.ONKEYDOWN:
+ // Stop propagation when the user starts pressing a button that
+ // we are handling to prevent actions from getting triggered
if (event.getKeyCode() == 32 /* space */) {
isFocusing = true;
event.preventDefault();
+ event.stopPropagation();
+ } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
+ event.stopPropagation();
}
break;
case Event.ONKEYUP:
if (isFocusing && event.getKeyCode() == 32 /* space */) {
isFocusing = false;
-
- /*
- * If click shortcut is space then the shortcut handler will
- * take care of the click.
- */
- if (clickShortcut != 32 /* space */) {
- onClick();
- }
-
+ onClick();
+ event.stopPropagation();
event.preventDefault();
}
break;
case Event.ONKEYPRESS:
if (event.getKeyCode() == KeyCodes.KEY_ENTER) {
-
- /*
- * If click shortcut is enter then the shortcut handler will
- * take care of the click.
- */
- if (clickShortcut != KeyCodes.KEY_ENTER) {
- onClick();
- }
-
+ onClick();
+ event.stopPropagation();
event.preventDefault();
}
break;
if (isDisableOnClick()) {
target.addAttribute(VButton.ATTR_DISABLE_ON_CLICK, true);
}
- if (clickShortcut != null) {
- target.addAttribute("keycode", clickShortcut.getKeyCode());
- }
if (isHtmlContentAllowed()) {
target.addAttribute("html-caption", true);
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.button.ButtonEnterWithWindowShortcut?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtonEnterWithWindowShortcut::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]</td>
+ <td>enter</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtonEnterWithWindowShortcut::PID_SLog_row_0</td>
+ <td>1. button click listener fired</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtonEnterWithWindowShortcut::</td>
+ <td>enter</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtonEnterWithWindowShortcut::PID_SLog_row_0</td>
+ <td>2. enter pressed in window</td>
+</tr>
+<!-- Can't test using space because of #8827 -->
+<!-- <tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtonEnterWithWindowShortcut::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]</td>
+ <td>space</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtonEnterWithWindowShortcut::PID_SLog_row_0</td>
+ <td>3. button click listener fired</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtonEnterWithWindowShortcut::</td>
+ <td>space</td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtonEnterWithWindowShortcut::PID_SLog_row_0</td>
+ <td>4. space pressed in window</td>
+</tr> -->
+</tbody></table>
+</body>
+</html>
--- /dev/null
+package com.vaadin.tests.components.button;
+
+import com.vaadin.event.Action;
+import com.vaadin.event.Action.Handler;
+import com.vaadin.event.ShortcutAction;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.util.Log;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+
+public class ButtonEnterWithWindowShortcut extends TestBase {
+ Log log = new Log(5);
+
+ @Override
+ protected void setup() {
+ getMainWindow().addActionHandler(new Handler() {
+ private static final long serialVersionUID = -4976129418325394913L;
+
+ public void handleAction(Action action, Object sender, Object target) {
+ log.log(action.getCaption() + " pressed in window");
+ }
+
+ public Action[] getActions(Object target, Object sender) {
+ ShortcutAction enter = new ShortcutAction("enter",
+ ShortcutAction.KeyCode.ENTER, null);
+ ShortcutAction space = new ShortcutAction("space",
+ ShortcutAction.KeyCode.SPACEBAR, null);
+ return new Action[] { enter, space };
+ }
+ });
+
+ Button button = new Button("Focus me and press enter",
+ new ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ log.log("button click listener fired");
+ }
+ });
+ button.focus();
+
+ addComponent(log);
+ addComponent(button);
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Pressing enter or space with the button focused should trigger the button click listener and not the shortcut action on the window.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return Integer.valueOf(5433);
+ }
+
+}