mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1206616 - Part 1: Fire input event for type=checkbox,radio,file. r=smaug
This commit is contained in:
parent
44ba33aedc
commit
9066685a11
@ -537,10 +537,20 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
|
||||
// event because it will think this is done by a script.
|
||||
// So, we can safely send one by ourself.
|
||||
mInput->SetFilesOrDirectories(newFilesOrDirectories, true);
|
||||
return nsContentUtils::DispatchTrustedEvent(mInput->OwnerDoc(),
|
||||
static_cast<nsIDOMHTMLInputElement*>(mInput.get()),
|
||||
NS_LITERAL_STRING("change"), true,
|
||||
false);
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
rv = nsContentUtils::DispatchTrustedEvent(mInput->OwnerDoc(),
|
||||
static_cast<nsIDOMHTMLInputElement*>(mInput.get()),
|
||||
NS_LITERAL_STRING("input"), true,
|
||||
false);
|
||||
NS_WARN_IF(NS_FAILED(rv));
|
||||
|
||||
rv = nsContentUtils::DispatchTrustedEvent(mInput->OwnerDoc(),
|
||||
static_cast<nsIDOMHTMLInputElement*>(mInput.get()),
|
||||
NS_LITERAL_STRING("change"), true,
|
||||
false);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(HTMLInputElement::nsFilePickerShownCallback,
|
||||
@ -3849,6 +3859,12 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
||||
DoSetChecked(originalCheckedValue, true, true);
|
||||
}
|
||||
} else {
|
||||
// Fire input event and then change event.
|
||||
nsContentUtils::DispatchTrustedEvent(OwnerDoc(),
|
||||
static_cast<nsIDOMHTMLInputElement*>(this),
|
||||
NS_LITERAL_STRING("input"), true,
|
||||
false);
|
||||
|
||||
nsContentUtils::DispatchTrustedEvent(OwnerDoc(),
|
||||
static_cast<nsIDOMHTMLInputElement*>(this),
|
||||
NS_LITERAL_STRING("change"), true,
|
||||
|
@ -166,6 +166,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=722599
|
||||
is(NonTextInputChange[i], 1, NonTextInputTypes[i] + " input element should have dispatched change event.");
|
||||
input.blur();
|
||||
is(NonTextInputChange[i], 1, "Change event shouldn't be dispatched on " + NonTextInputTypes[i] + " input element");
|
||||
|
||||
// Test that change event is not dispatched if click event is cancelled.
|
||||
function preventDefault(e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
input.addEventListener("click", preventDefault, false);
|
||||
input.click();
|
||||
is(NonTextInputChange[i], 1, "Change event shouldn't be dispatched if click event is cancelled");
|
||||
input.removeEventListener("click", preventDefault, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=851780
|
||||
input.focus();
|
||||
|
||||
input.addEventListener("input", function (aEvent) {
|
||||
ok(false, "input event doesn't apply to type='file'");
|
||||
ok(true, "input event should have been dispatched on file input.");
|
||||
}, false);
|
||||
|
||||
input.click();
|
||||
@ -135,14 +135,35 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=851780
|
||||
textarea.blur();
|
||||
is(textareaInput, 3, "input event should not have been dispatched");
|
||||
|
||||
// Some dummy tests for types that do not support the input event.
|
||||
// Non-text input tests:
|
||||
for (var i = 0; i < NonTextTypes.length; ++i) {
|
||||
input = document.getElementById("input_" + NonTextTypes[i]);
|
||||
input.focus();
|
||||
input.click();
|
||||
is(NonTextInput[i], 0, "input event doesn't apply");
|
||||
input.blur();
|
||||
is(NonTextInput[i], 0, "input event doesn't apply");
|
||||
// Button, submit, image and reset input type tests.
|
||||
if (i < 4) {
|
||||
input = document.getElementById("input_" + NonTextTypes[i]);
|
||||
input.focus();
|
||||
input.click();
|
||||
is(NonTextInput[i], 0, "input event doesn't apply");
|
||||
input.blur();
|
||||
is(NonTextInput[i], 0, "input event doesn't apply");
|
||||
}
|
||||
// For radio and checkboxes, input event should be dispatched.
|
||||
else {
|
||||
input = document.getElementById("input_" + NonTextTypes[i]);
|
||||
input.focus();
|
||||
input.click();
|
||||
is(NonTextInput[i], 1, "input event should have been dispatched");
|
||||
input.blur();
|
||||
is(NonTextInput[i], 1, "input event should not have been dispatched");
|
||||
|
||||
// Test that input event is not dispatched if click event is cancelled.
|
||||
function preventDefault(e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
input.addEventListener("click", preventDefault, false);
|
||||
input.click();
|
||||
is(NonTextInput[i], 1, "input event shouldn't be dispatched if click event is cancelled");
|
||||
input.removeEventListener("click", preventDefault, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Type changes.
|
||||
|
Loading…
Reference in New Issue
Block a user