mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1556358 - Part 1: Add formStateRestore CE lifecycle callback. r=edgar
Depends on D176127 Differential Revision: https://phabricator.services.mozilla.com/D174114
This commit is contained in:
parent
03160c8ffa
commit
327c7e2b15
@ -20,6 +20,7 @@
|
||||
#include "mozilla/dom/DocGroup.h"
|
||||
#include "mozilla/dom/CustomEvent.h"
|
||||
#include "mozilla/dom/ShadowRoot.h"
|
||||
#include "mozilla/dom/UnionTypes.h"
|
||||
#include "mozilla/AutoRestore.h"
|
||||
#include "mozilla/HoldDropJSObjects.h"
|
||||
#include "mozilla/UseCounter.h"
|
||||
@ -189,6 +190,14 @@ UniquePtr<CustomElementCallback> CustomElementCallback::Create(
|
||||
}
|
||||
break;
|
||||
|
||||
case ElementCallbackType::eFormStateRestore:
|
||||
if (aDefinition->mFormAssociatedCallbacks->mFormStateRestoreCallback
|
||||
.WasPassed()) {
|
||||
func = aDefinition->mFormAssociatedCallbacks->mFormStateRestoreCallback
|
||||
.Value();
|
||||
}
|
||||
break;
|
||||
|
||||
case ElementCallbackType::eGetCustomInterface:
|
||||
MOZ_ASSERT_UNREACHABLE("Don't call GetCustomInterface through callback");
|
||||
break;
|
||||
@ -234,6 +243,27 @@ void CustomElementCallback::Call() {
|
||||
static_cast<LifecycleFormDisabledCallback*>(mCallback.get())
|
||||
->Call(mThisObject, mArgs.mDisabled);
|
||||
break;
|
||||
case ElementCallbackType::eFormStateRestore: {
|
||||
if (mArgs.mState.IsNull()) {
|
||||
MOZ_ASSERT_UNREACHABLE(
|
||||
"A null state should never be restored to a form-associated "
|
||||
"custom element");
|
||||
return;
|
||||
}
|
||||
|
||||
const OwningFileOrUSVStringOrFormData& owningValue = mArgs.mState.Value();
|
||||
Nullable<FileOrUSVStringOrFormData> value;
|
||||
if (owningValue.IsFormData()) {
|
||||
value.SetValue().SetAsFormData() = owningValue.GetAsFormData();
|
||||
} else if (owningValue.IsFile()) {
|
||||
value.SetValue().SetAsFile() = owningValue.GetAsFile();
|
||||
} else {
|
||||
value.SetValue().SetAsUSVString().ShareOrDependUpon(
|
||||
owningValue.GetAsUSVString());
|
||||
}
|
||||
static_cast<LifecycleFormStateRestoreCallback*>(mCallback.get())
|
||||
->Call(mThisObject, value, mArgs.mReason);
|
||||
} break;
|
||||
case ElementCallbackType::eGetCustomInterface:
|
||||
MOZ_ASSERT_UNREACHABLE("Don't call GetCustomInterface through callback");
|
||||
break;
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/ElementInternals.h"
|
||||
#include "mozilla/dom/ElementInternalsBinding.h"
|
||||
#include "mozilla/dom/HTMLFormElement.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
@ -43,6 +44,7 @@ enum class ElementCallbackType {
|
||||
eFormAssociated,
|
||||
eFormReset,
|
||||
eFormDisabled,
|
||||
eFormStateRestore,
|
||||
eGetCustomInterface
|
||||
};
|
||||
|
||||
@ -63,6 +65,10 @@ struct LifecycleCallbackArgs {
|
||||
// Used by the form disabled callback.
|
||||
bool mDisabled;
|
||||
|
||||
// Used by the form state restore callback.
|
||||
Nullable<OwningFileOrUSVStringOrFormData> mState;
|
||||
RestoreReason mReason;
|
||||
|
||||
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
|
||||
};
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "js/TypeDecls.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/ElementInternalsBinding.h"
|
||||
#include "mozilla/dom/UnionTypes.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsIConstraintValidation.h"
|
||||
#include "nsIFormControl.h"
|
||||
|
@ -20,6 +20,11 @@ dictionary ElementDefinitionOptions {
|
||||
DOMString extends;
|
||||
};
|
||||
|
||||
enum RestoreReason {
|
||||
"restore",
|
||||
"autocomplete",
|
||||
};
|
||||
|
||||
callback constructor CustomElementConstructor = any ();
|
||||
|
||||
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
|
||||
@ -44,6 +49,8 @@ callback LifecycleFormResetCallback = undefined();
|
||||
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
|
||||
callback LifecycleFormDisabledCallback = undefined(boolean disabled);
|
||||
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
|
||||
callback LifecycleFormStateRestoreCallback = undefined((File or USVString or FormData)? state, RestoreReason reason);
|
||||
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
|
||||
callback LifecycleGetCustomInterfaceCallback = object?(any iid);
|
||||
|
||||
// Unsorted is necessary until https://github.com/whatwg/html/issues/3580 is resolved.
|
||||
@ -61,4 +68,5 @@ dictionary FormAssociatedLifecycleCallbacks {
|
||||
LifecycleFormAssociatedCallback formAssociatedCallback;
|
||||
LifecycleFormResetCallback formResetCallback;
|
||||
LifecycleFormDisabledCallback formDisabledCallback;
|
||||
LifecycleFormStateRestoreCallback formStateRestoreCallback;
|
||||
};
|
||||
|
@ -1,4 +0,0 @@
|
||||
[CustomElementRegistry.html]
|
||||
[customElements.define must get four additional callbacks on the prototype if formAssociated is converted to true]
|
||||
expected: FAIL
|
||||
|
Loading…
Reference in New Issue
Block a user