Bug 1947446 - Part 2: Input element should always defer the form submission during click event; r=smaug

As the input type can be changed to "submit" type during the click event, it may
end up triggering the form submission as the default action.

Differential Revision: https://phabricator.services.mozilla.com/D238781
This commit is contained in:
Edgar Chen
2025-02-25 22:30:48 +00:00
parent 9f0edddf04
commit 2afeef63bd
2 changed files with 45 additions and 8 deletions

View File

@@ -3323,9 +3323,7 @@ void HTMLInputElement::LegacyPreActivationBehavior(
}
// out-of-spec legacy pre-activation behavior needed because of bug 1803805
if ((mType == FormControlType::InputSubmit ||
mType == FormControlType::InputImage) &&
mForm) {
if (mForm) {
aVisitor.mItemFlags |= NS_IN_SUBMIT_CLICK;
aVisitor.mItemData = static_cast<Element*>(mForm);
// tell the form that we are about to enter a click handler.
@@ -3334,7 +3332,9 @@ void HTMLInputElement::LegacyPreActivationBehavior(
// handler.
mForm->OnSubmitClickBegin();
if (aVisitor.mDOMEvent) {
if ((mType == FormControlType::InputSubmit ||
mType == FormControlType::InputImage) &&
aVisitor.mDOMEvent) {
if (auto* mouseEvent = aVisitor.mDOMEvent->AsMouseEvent()) {
const CSSIntPoint pt = RoundedToInt(mouseEvent->OffsetPoint());
if (auto* imageClickedPoint = static_cast<CSSIntPoint*>(
@@ -4087,10 +4087,7 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
}
void EndSubmitClick(EventChainPostVisitor& aVisitor) {
auto oldType = FormControlType(NS_CONTROL_TYPE(aVisitor.mItemFlags));
if ((aVisitor.mItemFlags & NS_IN_SUBMIT_CLICK) &&
(oldType == FormControlType::InputSubmit ||
oldType == FormControlType::InputImage)) {
if (aVisitor.mItemFlags & NS_IN_SUBMIT_CLICK) {
nsCOMPtr<nsIContent> content(do_QueryInterface(aVisitor.mItemData));
RefPtr<HTMLFormElement> form = HTMLFormElement::FromNodeOrNull(content);
// Tell the form that we are about to exit a click handler,