Bug 1610821 - Part 2: Ensure most of event handling works on input elements which are disconnected from a document; r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D60672

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2020-02-10 22:35:44 +00:00
Родитель a848f5fbdd
Коммит 74836fb7e5
3 изменённых файлов: 9 добавлений и 28 удалений

Просмотреть файл

@ -3116,11 +3116,6 @@ void HTMLInputElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
if (textControlFrame) textControlFrame->EnsureEditorInitialized();
}
// FIXME Allow submission etc. also when there is no prescontext, Bug 329509.
if (!aVisitor.mPresContext) {
nsGenericHTMLFormElementWithState::GetEventTargetParent(aVisitor);
return;
}
//
// Web pages expect the value of a radio button or checkbox to be set
// *before* onclick and DOMActivate fire, and they expect that if they set
@ -3316,9 +3311,6 @@ void HTMLInputElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
}
nsresult HTMLInputElement::PreHandleEvent(EventChainVisitor& aVisitor) {
if (!aVisitor.mPresContext) {
return nsGenericHTMLFormElementWithState::PreHandleEvent(aVisitor);
}
nsresult rv;
if (aVisitor.mItemFlags & NS_PRE_HANDLE_BLUR_EVENT) {
MOZ_ASSERT(aVisitor.mEvent->mMessage == eBlur);
@ -3594,12 +3586,6 @@ static bool IgnoreInputEventWithModifier(WidgetInputEvent* aEvent,
}
nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
if (!aVisitor.mPresContext) {
// Hack alert! In order to open file picker even in case the element isn't
// in document, try to init picker even without PresContext.
return MaybeInitPickers(aVisitor);
}
if (aVisitor.mEvent->mMessage == eFocus ||
aVisitor.mEvent->mMessage == eBlur) {
if (aVisitor.mEvent->mMessage == eBlur) {
@ -3638,7 +3624,9 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
InternalUIEvent actEvent(true, eLegacyDOMActivate, mouseEvent);
actEvent.mDetail = 1;
if (RefPtr<PresShell> presShell = aVisitor.mPresContext->GetPresShell()) {
if (RefPtr<PresShell> presShell =
aVisitor.mPresContext ? aVisitor.mPresContext->GetPresShell()
: nullptr) {
nsEventStatus status = nsEventStatus_eIgnore;
mInInternalActivate = true;
rv = presShell->HandleDOMEventWithTarget(this, &actEvent, &status);
@ -3782,7 +3770,8 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
case NS_FORM_INPUT_CHECKBOX:
case NS_FORM_INPUT_RADIO: {
// Checkbox and Radio try to submit on Enter press
if (keyEvent->mKeyCode != NS_VK_SPACE) {
if (keyEvent->mKeyCode != NS_VK_SPACE &&
aVisitor.mPresContext) {
MaybeSubmitForm(MOZ_KnownLive(aVisitor.mPresContext));
break; // If we are submitting, do not send click event
@ -3861,8 +3850,10 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
mType == NS_FORM_INPUT_NUMBER ||
IsExperimentalMobileType(mType) || IsDateTimeInputType(mType))) {
FireChangeEventIfNeeded();
rv = MaybeSubmitForm(MOZ_KnownLive(aVisitor.mPresContext));
NS_ENSURE_SUCCESS(rv, rv);
if (aVisitor.mPresContext) {
rv = MaybeSubmitForm(MOZ_KnownLive(aVisitor.mPresContext));
NS_ENSURE_SUCCESS(rv, rv);
}
}
if (aVisitor.mEvent->mMessage == eKeyPress &&

Просмотреть файл

@ -14,9 +14,3 @@
[disabled checkbox still has activation behavior, part 2]
expected: FAIL
[disconnected checkbox should be checked]
expected: FAIL
[disconnected radio should be checked]
expected: FAIL

Просмотреть файл

@ -1,4 +0,0 @@
[checkbox-click-events.html]
[clicking and preventDefaulting a checkbox causes the checkbox to be checked during the click handler but reverted]
expected: FAIL