diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 40ce12f807dc..bb40df61ab5e 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -3568,10 +3568,12 @@ bool HTMLInputElement::StepsInputValue( return true; } -static bool ActivatesWithKeyboard(FormControlType aType) { +static bool ActivatesWithKeyboard(FormControlType aType, uint32_t aKeyCode) { switch (aType) { case FormControlType::InputCheckbox: case FormControlType::InputRadio: + // Checkbox and Radio try to submit on Enter press + return aKeyCode != NS_VK_RETURN; case FormControlType::InputButton: case FormControlType::InputReset: case FormControlType::InputSubmit: @@ -3728,14 +3730,8 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) { FireChangeEventIfNeeded(); aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault; } else if (!preventDefault) { - // Checkbox and Radio try to submit on Enter press - if (aVisitor.mEvent->mMessage == eKeyPress && - (mType == FormControlType::InputCheckbox || - mType == FormControlType::InputRadio) && - keyEvent->mKeyCode == NS_VK_RETURN && aVisitor.mPresContext) { - MaybeSubmitForm(aVisitor.mPresContext); - } else if (ActivatesWithKeyboard(mType)) { - // Otherwise we maybe dispatch a synthesized click. + if (keyEvent && ActivatesWithKeyboard(mType, keyEvent->mKeyCode)) { + // We maybe dispatch a synthesized click for keyboard activation. HandleKeyboardActivation(aVisitor); } @@ -3829,9 +3825,14 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) { if (keyEvent->mKeyCode == NS_VK_RETURN && (IsSingleLineTextControl(false, mType) || - mType == FormControlType::InputNumber || - IsDateTimeInputType(mType))) { - FireChangeEventIfNeeded(); + IsDateTimeInputType(mType) || + mType == FormControlType::InputCheckbox || + mType == FormControlType::InputRadio)) { + if (IsSingleLineTextControl(false, mType) || + IsDateTimeInputType(mType)) { + FireChangeEventIfNeeded(); + } + if (aVisitor.mPresContext) { MaybeSubmitForm(aVisitor.mPresContext); }