Bug 1809689 - Activate first checkbox with activation behaviour. r=edgar

Differential Revision: https://phabricator.services.mozilla.com/D166569
This commit is contained in:
Adam Vandolder
2023-01-16 15:32:17 +00:00
parent b19d6e8e3d
commit 817af689cd
3 changed files with 68 additions and 9 deletions

View File

@@ -3133,8 +3133,10 @@ void HTMLInputElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
bool originalCheckedValue = false;
if (outerActivateEvent) {
if (outerActivateEvent &&
!aVisitor.mEvent->mFlags.mMultiplePreActionsPrevented) {
mCheckedIsToggled = false;
aVisitor.mEvent->mFlags.mMultiplePreActionsPrevented = true;
switch (mType) {
case FormControlType::InputCheckbox: {
@@ -3147,6 +3149,10 @@ void HTMLInputElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
originalCheckedValue = Checked();
DoSetChecked(!originalCheckedValue, true, true);
mCheckedIsToggled = true;
if (aVisitor.mEventStatus != nsEventStatus_eConsumeNoDefault) {
aVisitor.mEventStatus = nsEventStatus_eConsumeDoDefault;
}
} break;
case FormControlType::InputRadio: {
@@ -3158,13 +3164,16 @@ void HTMLInputElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
DoSetChecked(true, true, true);
mCheckedIsToggled = true;
}
if (aVisitor.mEventStatus != nsEventStatus_eConsumeNoDefault) {
aVisitor.mEventStatus = nsEventStatus_eConsumeDoDefault;
}
} break;
case FormControlType::InputSubmit:
case FormControlType::InputImage:
if (mForm && !aVisitor.mEvent->mFlags.mMultiplePreActionsPrevented) {
if (mForm) {
// Make sure other submit elements don't try to trigger submission.
aVisitor.mEvent->mFlags.mMultiplePreActionsPrevented = true;
aVisitor.mItemFlags |= NS_IN_SUBMIT_CLICK;
aVisitor.mItemData = static_cast<Element*>(mForm);
// tell the form that we are about to enter a click handler.

View File

@@ -4,14 +4,8 @@
[look at parents only when event bubbles]
expected: FAIL
[pick the first with activation behavior <input type=checkbox>]
expected: FAIL
[event state during post-click handling]
expected: FAIL
[redispatch during post-click handling]
expected: FAIL
[disabled checkbox still has activation behavior, part 2]
expected: FAIL

View File

@@ -87,6 +87,22 @@ async_test(function(t) { // as above with <a>
child.dispatchEvent(new MouseEvent("click", {bubbles:true}))
}, "pick the first with activation behavior <a href>")
async_test(function(t) {
var input = document.createElement("input")
input.type = "radio"
dump.appendChild(input)
input.onclick = t.step_func(function() {
assert_false(input.checked, "input pre-click must not be triggered")
})
var child = input.appendChild(document.createElement("input"))
child.type = "radio"
child.onclick = t.step_func(function() {
assert_true(child.checked, "child pre-click must be triggered")
})
child.dispatchEvent(new MouseEvent("click", {bubbles:true}))
t.done()
}, "pick the first with activation behavior <input type=radio>")
async_test(function(t) {
var input = document.createElement("input")
input.type = "checkbox"
@@ -173,6 +189,46 @@ async_test(function(t) {
t.done()
}, "disabled checkbox still has activation behavior, part 2")
async_test(function(t) {
var state = "start"
var form = document.createElement("form")
form.onsubmit = t.step_func(() => {
if(state == "start" || state == "radio") {
state = "failure"
} else if(state == "form") {
state = "done"
}
return false
})
dump.appendChild(form)
var button = form.appendChild(document.createElement("button"))
button.type = "submit"
var radio = button.appendChild(document.createElement("input"))
radio.type = "radio"
radio.onclick = t.step_func(() => {
if(state == "start") {
assert_unreached()
} else if(state == "radio") {
assert_true(radio.checked)
}
})
radio.disabled = true
radio.click()
assert_equals(state, "start")
state = "radio"
radio.disabled = false
radio.click()
assert_equals(state, "radio")
state = "form"
button.click()
assert_equals(state, "done")
t.done()
}, "disabled radio still has activation behavior")
async_test(function(t) {
var input = document.createElement("input")
input.type = "checkbox"