зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1695636 - Part 2: Handle form submission for keypress event in a central place; r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D135675
This commit is contained in:
Родитель
6123594d4f
Коммит
a7a61c5630
|
@ -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))) {
|
||||
IsDateTimeInputType(mType) ||
|
||||
mType == FormControlType::InputCheckbox ||
|
||||
mType == FormControlType::InputRadio)) {
|
||||
if (IsSingleLineTextControl(false, mType) ||
|
||||
IsDateTimeInputType(mType)) {
|
||||
FireChangeEventIfNeeded();
|
||||
}
|
||||
|
||||
if (aVisitor.mPresContext) {
|
||||
MaybeSubmitForm(aVisitor.mPresContext);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче