Commit 745cedc5 authored by aroben@apple.com's avatar aroben@apple.com

Fix <rdar://5483519> Pressing Enter on selected buttons should fire onclick

 LayoutTests:

         Add a test for <rdar://5483519> Pressing Enter on selected buttons should fire onclick

         Reviewed by Adele.

         * fast/forms/enter-clicks-buttons-expected.txt: Added.
         * fast/forms/enter-clicks-buttons.html: Added.

 WebCore:

         Fix <rdar://5483519> Pressing Enter on selected buttons should fire onclick

         We now match the behavior of Firefox and IE, which is to always just
         send a click event to the focused button when the Enter key is pressed
         (previously we were submitting forms directly in some cases).

         Reviewed by Adele.

         Test: fast/forms/enter-clicks-buttons.html

         * html/HTMLButtonElement.cpp:
         (WebCore::HTMLButtonElement::defaultEventHandler): Don't do anything
         fancy when Enter is pressed on a <button type=button> -- just send a
         click event like we do for other button types.
         * html/HTMLInputElement.cpp:
         (WebCore::HTMLInputElement::defaultEventHandler): Treat type=button
         the same way we treat type=submit and type=reset: just send a click
         event when Enter is pressed.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27652 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5a4bdf3e
2007-11-08 Adam Roben <aroben@apple.com>
Add a test for <rdar://5483519> Pressing Enter on selected buttons should fire onclick
Reviewed by Adele.
* fast/forms/enter-clicks-buttons-expected.txt: Added.
* fast/forms/enter-clicks-buttons.html: Added.
2007-11-09 Dan Bernstein <mitz@apple.com>
Reviewed by Antti Koivisto.
......
Test for <rdar://5483519> Pressing Enter on selected buttons should fire onclick
In a form:
button type="button" button type="submit" button type="reset"
Outside a form:
button type="button" button type="submit" button type="reset"
Sending Enter keypresses...
Looping over 6 button elements...
click: BUTTON type=button in form
click: BUTTON type=submit in form
submit: FORM
click: BUTTON type=reset in form
click: BUTTON type=button
click: BUTTON type=submit
click: BUTTON type=reset
Looping over 8 input elements...
click: INPUT type=submit in form
submit: FORM
click: INPUT type=button in form
click: INPUT type=submit in form
submit: FORM
click: INPUT type=reset in form
click: INPUT type=button
click: INPUT type=submit
click: INPUT type=reset
Sending U+0020 keypresses...
Looping over 6 button elements...
click: BUTTON type=button in form
click: BUTTON type=submit in form
submit: FORM
click: BUTTON type=reset in form
click: BUTTON type=button
click: BUTTON type=submit
click: BUTTON type=reset
Looping over 8 input elements...
click: INPUT type=checkbox in form
click: INPUT type=button in form
click: INPUT type=submit in form
submit: FORM
click: INPUT type=reset in form
click: INPUT type=checkbox
click: INPUT type=button
click: INPUT type=submit
click: INPUT type=reset
<script>
function log(msg)
{
document.getElementById('console').appendChild(document.createTextNode(msg + '\n'));
}
function nodeIsChildOfForm(node)
{
return node.parentNode && node.parentNode.tagName == 'FORM';
}
function description(node)
{
return node.nodeName + (node.type ? ' type=' + node.type : '') + (nodeIsChildOfForm(node) ? ' in form' : '');
}
function logEvent(event)
{
var type = event.target.type;
log(event.type + ': ' + description(event.target));
}
function loaded()
{
if (window.layoutTestController)
layoutTestController.dumpAsText();
var keys = ['Enter', 'U+0020'];
var tagNames = ['button', 'input'];
for (var i in keys) {
log('\n\nSending ' + keys[i] + ' keypresses...\n');
for (var j in tagNames) {
var elements = document.getElementsByTagName(tagNames[j]);
log('\nLooping over ' + elements.length + ' ' + tagNames[j] + ' elements...\n');
for (var k = 0; k < elements.length; ++k) {
var event = elements[k].ownerDocument.createEvent("KeyboardEvent");
event.initKeyboardEvent("keypress", true, true, elements[k].ownerDocument.defaultView, keys[i], 0, false, false, false, false, false);
elements[k].dispatchEvent(event);
}
}
}
}
</script>
<body onload="loaded()">
<p>Test for &lt;<a href="rdar://5483519">rdar://5483519</a>&gt; Pressing Enter on selected buttons should fire onclick</p>
<p>In a form:</p>
<form onsubmit="logEvent(event); return false">
<button type="button" onclick="logEvent(event)">button type="button"</button>
<button type="submit" onclick="logEvent(event)">button type="submit"</button>
<button type="reset" onclick="logEvent(event)">button type="reset"</button>
<input type="checkbox" onclick="logEvent(event)" value="input type='checkbox'">
<input type="button" onclick="logEvent(event)" value="input type='button'">
<input type="submit" onclick="logEvent(event)" value="input type='submit'">
<input type="reset" onclick="logEvent(event)" value="input type='reset'">
</form>
<p>Outside a form:</p>
<button type="button" onclick="logEvent(event)">button type="button"</button>
<button type="submit" onclick="logEvent(event)">button type="submit"</button>
<button type="reset" onclick="logEvent(event)">button type="reset"</button>
<input type="checkbox" onclick="logEvent(event)" value="input type='checkbox'">
<input type="button" onclick="logEvent(event)" value="input type='button'">
<input type="submit" onclick="logEvent(event)" value="input type='submit'">
<input type="reset" onclick="logEvent(event)" value="input type='reset'">
<pre id='console'></pre>
2007-11-08 Adam Roben <aroben@apple.com>
Fix <rdar://5483519> Pressing Enter on selected buttons should fire onclick
We now match the behavior of Firefox and IE, which is to always just
send a click event to the focused button when the Enter key is pressed
(previously we were submitting forms directly in some cases).
Reviewed by Adele.
Test: fast/forms/enter-clicks-buttons.html
* html/HTMLButtonElement.cpp:
(WebCore::HTMLButtonElement::defaultEventHandler): Don't do anything
fancy when Enter is pressed on a <button type=button> -- just send a
click event like we do for other button types.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::defaultEventHandler): Treat type=button
the same way we treat type=submit and type=reset: just send a click
event when Enter is pressed.
2007-11-09 Dan Bernstein <mitz@apple.com>
Reviewed by Antti Koivisto.
......
......@@ -94,13 +94,6 @@ void HTMLButtonElement::defaultEventHandler(Event* evt)
if (evt->type() == keypressEvent && evt->isKeyboardEvent()) {
String key = static_cast<KeyboardEvent*>(evt)->keyIdentifier();
// Do the same things <input type=button/reset/submit> would do.
if (key == "Enter" && m_type == BUTTON) {
if (form())
form()->submitClick(evt);
evt->setDefaultHandled();
return;
}
if (key == "Enter" || key == "U+0020") {
dispatchSimulatedClick(evt);
evt->setDefaultHandled();
......
......@@ -1202,7 +1202,6 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
if (key == "Enter") {
switch (inputType()) {
case BUTTON:
case CHECKBOX:
case HIDDEN:
case ISINDEX:
......@@ -1213,6 +1212,7 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
// Simulate mouse click on the default form button for enter for these types of elements.
clickDefaultFormButton = true;
break;
case BUTTON:
case FILE:
case IMAGE:
case RESET:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment