/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
void HTMLElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) { if (IsDisabledForEvents(aVisitor.mEvent)) { // Do not process any DOM events if the element is disabled
aVisitor.mCanHandle = false; return;
}
void HTMLElement::DoneCreatingElement() { if (MOZ_UNLIKELY(IsFormAssociatedElement())) {
MaybeRestoreFormAssociatedCustomElementState();
}
}
void HTMLElement::SaveState() { if (MOZ_LIKELY(!IsFormAssociatedElement())) { return;
}
auto* internals = GetElementInternals();
nsCString stateKey = internals->GetStateKey(); if (stateKey.IsEmpty()) { return;
}
nsCOMPtr<nsILayoutHistoryState> history = GetLayoutHistory(false); if (!history) { return;
}
// Get the pres state for this key, if it doesn't exist, create one.
PresState* result = history->GetState(stateKey); if (!result) {
UniquePtr<PresState> newState = NewPresState();
result = newState.get();
history->AddState(stateKey, std::move(newState));
}
constauto& state = internals->GetFormState(); constauto& value = internals->GetFormSubmissionValue();
result->contentData() = CustomElementTuple(
nsContentUtils::ConvertToCustomElementFormValue(value),
nsContentUtils::ConvertToCustomElementFormValue(state));
}
void HTMLElement::SetCustomElementDefinition(
CustomElementDefinition* aDefinition) {
nsGenericHTMLFormElement::SetCustomElementDefinition(aDefinition); // Always create an ElementInternal for form-associated custom element as the // Form related implementation lives in ElementInternal which implements // nsIFormControl. It is okay for the attachElementInternal API as there is a // separated flag for whether attachElementInternal is called. if (aDefinition && !aDefinition->IsCustomBuiltIn() &&
aDefinition->mFormAssociated) {
CustomElementData* data = GetCustomElementData();
MOZ_ASSERT(data); auto* internals = data->GetOrCreateElementInternals(this);
// This is for the case that script constructs a custom element directly, // e.g. via new MyCustomElement(), where the upgrade steps won't be ran to // update the disabled state in UpdateFormOwner(). if (data->mState == CustomElementData::State::eCustom) {
UpdateDisabledState(true);
} elseif (!HasFlag(HTML_ELEMENT_INHIBIT_RESTORATION)) {
internals->InitializeControlNumber();
}
}
}
// 1. If element's is value is not null, then throw a "NotSupportedError" // DOMException. if (nsAtom* isAtom = ceData ? ceData->GetIs(this) : nullptr) {
aRv.ThrowNotSupportedError(nsPrintfCString( "Cannot attach ElementInternals to a customized built-in element " "'%s'",
NS_ConvertUTF16toUTF8(isAtom->GetUTF16String()).get())); return nullptr;
}
// 2. Let definition be the result of looking up a custom element definition // given element's node document, its namespace, its local name, and null // as is value.
nsAtom* nameAtom = NodeInfo()->NameAtom();
CustomElementDefinition* definition = nullptr; if (ceData) {
definition = ceData->GetCustomElementDefinition();
// If the definition is null, the element possible hasn't yet upgraded. // Fallback to use LookupCustomElementDefinition to find its definition. if (!definition) {
definition = nsContentUtils::LookupCustomElementDefinition(
NodeInfo()->GetDocument(), nameAtom, NodeInfo()->NamespaceID(),
ceData->GetCustomElementType());
}
}
// 3. If definition is null, then throw an "NotSupportedError" DOMException. if (!definition) {
aRv.ThrowNotSupportedError(nsPrintfCString( "Cannot attach ElementInternals to a non-custom element '%s'",
NS_ConvertUTF16toUTF8(nameAtom->GetUTF16String()).get())); return nullptr;
}
// 4. If definition's disable internals is true, then throw a // "NotSupportedError" DOMException. if (definition->mDisableInternals) {
aRv.ThrowNotSupportedError(nsPrintfCString( "AttachInternal() to '%s' is disabled by disabledFeatures",
NS_ConvertUTF16toUTF8(nameAtom->GetUTF16String()).get())); return nullptr;
}
// If this is not a custom element, i.e. ceData is nullptr, we are unable to // find a definition and should return earlier above.
MOZ_ASSERT(ceData);
// 5. If element's attached internals is true, then throw an // "NotSupportedError" DOMException. if (ceData->HasAttachedInternals()) {
aRv.ThrowNotSupportedError(nsPrintfCString( "AttachInternals() has already been called from '%s'",
NS_ConvertUTF16toUTF8(nameAtom->GetUTF16String()).get())); return nullptr;
}
// 6. If element's custom element state is not "precustomized" or "custom", // then throw a "NotSupportedError" DOMException. if (ceData->mState != CustomElementData::State::ePrecustomized &&
ceData->mState != CustomElementData::State::eCustom) {
aRv.ThrowNotSupportedError(
R"(Custom element state is not "precustomized" or "custom".)"); return nullptr;
}
// 7. Set element's attached internals to true.
ceData->AttachedInternals();
// 8. Create a new ElementInternals instance targeting element, and return it. return do_AddRef(ceData->GetOrCreateElementInternals(this));
}
void HTMLElement::AfterClearForm(bool aUnbindOrDelete) { // No need to enqueue formAssociated callback if we aren't releasing or // unbinding from tree, UpdateFormOwner() will handle it. if (aUnbindOrDelete) {
MOZ_ASSERT(IsFormAssociatedElement());
nsContentUtils::EnqueueLifecycleCallback(
ElementCallbackType::eFormAssociated, this, {});
}
}
// If @form is set, the element *has* to be in a composed document, // otherwise it wouldn't be possible to find an element with the // corresponding id. If @form isn't set, the element *has* to have a parent, // otherwise it wouldn't be possible to find a form ancestor. We should not // call UpdateFormOwner if none of these conditions are fulfilled. if (HasAttr(nsGkAtoms::form) ? IsInComposedDoc() : !!GetParent()) {
UpdateFormOwner(true, nullptr);
}
UpdateFieldSet(true);
UpdateDisabledState(true);
UpdateBarredFromConstraintValidation();
UpdateValidityElementStates(true);
bool HTMLElement::IsFormAssociatedElement() const {
CustomElementData* data = GetCustomElementData(); return data && data->IsFormAssociated();
}
void HTMLElement::FieldSetDisabledChanged(bool aNotify) { // This *has* to be called *before* UpdateBarredFromConstraintValidation // because this function depend on our disabled state.
nsGenericHTMLFormElement::FieldSetDisabledChanged(aNotify);
ElementInternals* HTMLElement::GetElementInternals() const {
CustomElementData* data = GetCustomElementData(); if (!data || !data->IsFormAssociated()) { // If the element is not a form associated custom element, it should not be // able to be QueryInterfaced to nsIFormControl and could not perform // the form operation, either, so we return nullptr here. return nullptr;
}
void HTMLElement::UpdateBarredFromConstraintValidation() {
CustomElementData* data = GetCustomElementData(); if (data && data->IsFormAssociated()) {
ElementInternals* internals = data->GetElementInternals();
MOZ_ASSERT(internals);
internals->UpdateBarredFromConstraintValidation();
}
}
} // namespace mozilla::dom
// Here, we expand 'NS_IMPL_NS_NEW_HTML_ELEMENT()' by hand. // (Calling the macro directly (with no args) produces compiler warnings.)
nsGenericHTMLElement* NS_NewHTMLElement(
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
mozilla::dom::FromParser aFromParser) {
RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo); auto* nim = nodeInfo->NodeInfoManager(); returnnew (nim) mozilla::dom::HTMLElement(nodeInfo.forget(), aFromParser);
}
// Distinct from the above in order to have function pointer that compared // unequal to a function pointer to the above.
nsGenericHTMLElement* NS_NewCustomElement(
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
mozilla::dom::FromParser aFromParser) {
RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo); auto* nim = nodeInfo->NodeInfoManager(); returnnew (nim) mozilla::dom::HTMLElement(nodeInfo.forget(), aFromParser);
}
¤ Dauer der Verarbeitung: 0.34 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.