Bug 93674 - change event is sent to <input type=radio> before click event
Summary: change event is sent to <input type=radio> before click event
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL: https://zewt.org/~glenn/test-webkit-r...
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-09 18:39 PDT by Glenn Maynard
Modified: 2019-02-06 09:19 PST (History)
9 users (show)

See Also:


Attachments
Patch (4.99 KB, patch)
2015-05-26 02:04 PDT, Rohit
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews101 for mac-mavericks (573.12 KB, application/zip)
2015-05-26 02:56 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews106 for mac-mavericks-wk2 (591.83 KB, application/zip)
2015-05-26 03:02 PDT, Build Bot
no flags Details
Patch (10.13 KB, patch)
2015-05-26 03:37 PDT, Rohit
no flags Details | Formatted Diff | Diff
Patch (10.11 KB, patch)
2015-05-26 23:42 PDT, Rohit
no flags Details | Formatted Diff | Diff
Patch (10.38 KB, patch)
2015-06-12 04:36 PDT, Rohit
tkent: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Glenn Maynard 2012-08-09 18:39:35 PDT
When a radio button (or checkbox) is clicked, the onchange event is sent before onclick instead of after.

If onclick is defaultPrevented, the page has now received onchange in the temporary checked state, even though the "canceled activation steps" reset the checked state to false.

Opera and Firefox behave per spec: onclick is sent before onchange, and if onclick is stopped, the onchange event is never fired.  (Firing onclick is the activation behavior of the element, which happens after an uncancelled click.)

IE9 matches what WebKit is doing.
Comment 1 Alexey Proskuryakov 2012-08-10 11:19:47 PDT
Weird! But if IE and WebKit are doing the same thing, then nearly every browser works like that.
Comment 2 Glenn Maynard 2012-08-10 11:20:45 PDT
Opera and Firefox don't.
Comment 3 Alexey Proskuryakov 2012-08-10 13:05:19 PDT
Got that, I was counting not by browser name, but by installed base.

That's just a data point - Firefox behavior seems much more logical, unless there is an explanation for IE behavior that I don't know.
Comment 4 Glenn Maynard 2012-08-10 14:44:47 PDT
At least, since cancelling onchange doesn't do anything, people aren't expecting preventDefault on onchange to prevent onclick.  I wonder if Mozilla has received any bug reports for following the spec.
Comment 5 Alexey Proskuryakov 2012-08-13 09:57:16 PDT
See also: bug 93760.
Comment 6 Rohit 2015-05-26 02:04:44 PDT
Created attachment 253697 [details]
Patch
Comment 7 WebKit Commit Bot 2015-05-26 02:05:52 PDT
Attachment 253697 [details] did not pass style-queue:


ERROR: Source/WebCore/ChangeLog:8:  You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible.  [changelog/nonewtests] [5]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 8 Build Bot 2015-05-26 02:56:01 PDT
Comment on attachment 253697 [details]
Patch

Attachment 253697 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/6352494187773952

New failing tests:
fast/forms/radio/radio-group-keyboard-change-event.html
Comment 9 Build Bot 2015-05-26 02:56:04 PDT
Created attachment 253700 [details]
Archive of layout-test-results from ews101 for mac-mavericks

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-mavericks  Platform: Mac OS X 10.9.5
Comment 10 Build Bot 2015-05-26 03:02:12 PDT
Comment on attachment 253697 [details]
Patch

Attachment 253697 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/6332516818485248

New failing tests:
fast/forms/radio/radio-group-keyboard-change-event.html
Comment 11 Build Bot 2015-05-26 03:02:16 PDT
Created attachment 253701 [details]
Archive of layout-test-results from ews106 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 12 Rohit 2015-05-26 03:37:43 PDT
Created attachment 253702 [details]
Patch
Comment 13 Ryosuke Niwa 2015-05-26 13:36:26 PDT
Comment on attachment 253702 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253702&action=review

> Source/WebCore/html/CheckboxInputType.cpp:86
> +    } else {
> +        element().dispatchChangeEventIfNeeded(); 
>      }

nit: No curly braces arouns a single line statement.

> Source/WebCore/html/HTMLInputElement.cpp:862
> +        setTextAsOfLastFormControlChangeEvent(String());

Why is this call to setTextAsOfLastFormControlChangeEvent necessary even we've already called it in HTMLInputElement::setChecked?
It seems strange that we need to call it in both places.

> Source/WebCore/html/RadioInputType.cpp:184
> +    } else {
> +        element().dispatchChangeEventIfNeeded();
>      }

nit: No curly braces around a single line statement.
Comment 14 Rohit 2015-05-26 23:42:31 PDT
Created attachment 253780 [details]
Patch
Comment 15 Rohit 2015-05-26 23:48:28 PDT
Comment on attachment 253702 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253702&action=review

>> Source/WebCore/html/CheckboxInputType.cpp:86
>>      }
> 
> nit: No curly braces arouns a single line statement.

Done.

>> Source/WebCore/html/HTMLInputElement.cpp:862
>> +        setTextAsOfLastFormControlChangeEvent(String());
> 
> Why is this call to setTextAsOfLastFormControlChangeEvent necessary even we've already called it in HTMLInputElement::setChecked?
> It seems strange that we need to call it in both places.

Removed.
I added setTextAsOfLastFormControlChangeEvent(String()) in both as setChecked() and dispatchChangeEventIfNeeded() are getting called in if-else statements. But as setChecked() is already getting called in willDispatchClick for both radio and checkbox, it makes more sense to remove it from dispatchChangeEventIfNeeded().

>> Source/WebCore/html/RadioInputType.cpp:184
>>      }
> 
> nit: No curly braces around a single line statement.

Done.
Comment 16 Antonio Gomes 2015-06-10 09:32:17 PDT
Comment on attachment 253780 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253780&action=review

code looks reasonable, but you need to add some background/context to your commit message.

> Source/WebCore/ChangeLog:5
> +

please
- add the motivation of the spec (match the spec, add an url)
- any possible real world web site behavior that the patch fixes
- also mention that webkit now matches firefox and open (presto or chromium?) behavior?, and does not match IE anymore.
Comment 17 Rohit 2015-06-12 04:36:39 PDT
Created attachment 254793 [details]
Patch
Comment 18 Csaba Osztrogonác 2015-09-14 10:54:58 PDT
Comment on attachment 253702 [details]
Patch

Cleared review? from obsolete attachment 253702 [details] so that this bug does not appear in http://webkit.org/pending-review.  If you would like this patch reviewed, please attach it to a new bug (or re-open this bug before marking it for review again).
Comment 19 Kent Tamura 2015-09-14 14:10:53 PDT
Comment on attachment 254793 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=254793&action=review

> Source/WebCore/html/HTMLInputElement.cpp:862
> +        dispatchFormControlChangeEvent();

This causes a regression.  See https://code.google.com/p/chromium/issues/detail?id=528985
Comment 20 Chris Dumez 2015-09-14 14:14:37 PDT
(In reply to comment #19)
> Comment on attachment 254793 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=254793&action=review
> 
> > Source/WebCore/html/HTMLInputElement.cpp:862
> > +        dispatchFormControlChangeEvent();
> 
> This causes a regression.  See
> https://code.google.com/p/chromium/issues/detail?id=528985

Thanks Tamura.
Comment 21 Chris Rebert 2015-10-02 16:32:57 PDT
See also HTML spec bug:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=28985
Comment 22 Chris Rebert 2016-02-02 15:41:38 PST
(In reply to comment #19)
> Comment on attachment 254793 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=254793&action=review
> 
> > Source/WebCore/html/HTMLInputElement.cpp:862
> > +        dispatchFormControlChangeEvent();
> 
> This causes a regression.  See
> https://code.google.com/p/chromium/issues/detail?id=528985

The regression was subsequently fixed:
https://code.google.com/p/chromium/issues/detail?id=528985#c4
https://src.chromium.org/viewvc/blink?view=revision&revision=202190
Comment 23 Lucas Forschler 2019-02-06 09:19:17 PST
Mass move bugs into the DOM component.