/* -*- 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/. */
RefPtr<AsyncEventDispatcher> eventDispatcher = new AsyncEventDispatcher(this, u"close"_ns, CanBubble::eNo);
eventDispatcher->PostDOMEvent();
if (mCloseWatcher) {
mCloseWatcher->Destroy();
mCloseWatcher = nullptr;
}
}
void HTMLDialogElement::Show(ErrorResult& aError) { if (Open()) { if (!IsInTopLayer()) { return;
} return aError.ThrowInvalidStateError( "Cannot call show() on an open modal dialog.");
}
if (StaticPrefs::dom_element_dialog_toggle_events_enabled()) { if (FireToggleEvent(u"closed"_ns, u"open"_ns, u"beforetoggle"_ns)) { return;
} if (Open()) { return;
}
QueueToggleEventTask();
}
void HTMLDialogElement::AddToTopLayerIfNeeded() {
MOZ_ASSERT(IsInComposedDoc()); if (IsInTopLayer()) { return;
}
OwnerDoc()->AddModalDialog(*this);
}
void HTMLDialogElement::RemoveFromTopLayerIfNeeded() { if (!IsInTopLayer()) { return;
}
OwnerDoc()->RemoveModalDialog(*this);
}
void HTMLDialogElement::StorePreviouslyFocusedElement() { if (Element* element = nsFocusManager::GetFocusedElementStatic()) { if (NS_SUCCEEDED(nsContentUtils::CheckSameOrigin(this, element))) {
mPreviouslyFocusedElement = do_GetWeakReference(element);
}
} elseif (Document* doc = GetComposedDoc()) { // Looks like there's a discrepancy sometimes when focus is moved // to a different in-process window. if (nsIContent* unretargetedFocus = doc->GetUnretargetedFocusedContent()) {
mPreviouslyFocusedElement = do_GetWeakReference(unretargetedFocus);
}
}
}
if (mCloseWatcher) {
mCloseWatcher->Destroy();
mCloseWatcher = nullptr;
}
nsGenericHTMLElement::UnbindFromTree(aContext);
}
void HTMLDialogElement::ShowModal(ErrorResult& aError) { if (Open()) { if (IsInTopLayer()) { return;
} return aError.ThrowInvalidStateError( "Cannot call showModal() on an open non-modal dialog.");
}
if (!IsInComposedDoc()) { return aError.ThrowInvalidStateError("Dialog element is not connected");
}
if (IsPopoverOpen()) { return aError.ThrowInvalidStateError( "Dialog element is already an open popover.");
}
if (StaticPrefs::dom_element_dialog_toggle_events_enabled()) { if (FireToggleEvent(u"closed"_ns, u"open"_ns, u"beforetoggle"_ns)) { return;
} if (Open() || !IsInComposedDoc() || IsPopoverOpen()) { return;
}
QueueToggleEventTask();
}
AddToTopLayerIfNeeded();
SetOpen(true, aError);
StorePreviouslyFocusedElement();
if (StaticPrefs::dom_closewatcher_enabled()) {
RefPtr<Document> doc = OwnerDoc(); if (doc->IsActive() && doc->IsCurrentActiveDocument()) { if (RefPtr window = OwnerDoc()->GetInnerWindow()) {
mCloseWatcher = new CloseWatcher(window);
RefPtr<DialogCloseWatcherListener> eventListener = new DialogCloseWatcherListener(this);
mCloseWatcher->AddSystemEventListener(u"cancel"_ns, eventListener, false/* aUseCapture */, false/* aWantsUntrusted */);
mCloseWatcher->AddSystemEventListener(u"close"_ns, eventListener, false/* aUseCapture */, false/* aWantsUntrusted */);
window->EnsureCloseWatcherManager()->Add(*mCloseWatcher);
}
}
}
void HTMLDialogElement::FocusDialog() { // 1) If subject is inert, return. // 2) Let control be the first descendant element of subject, in tree // order, that is not inert and has the autofocus attribute specified.
RefPtr<Document> doc = OwnerDoc(); if (IsInComposedDoc()) {
doc->FlushPendingNotifications(FlushType::Frames);
}
RefPtr<Element> control = HasAttr(nsGkAtoms::autofocus)
? this
: GetFocusDelegate(IsFocusableFlags(0));
// If there isn't one of those either, then let control be subject. if (!control) {
control = this;
}
void HTMLDialogElement::QueueCancelDialog() { // queues an element task on the user interaction task source
OwnerDoc()->Dispatch(
NewRunnableMethod("HTMLDialogElement::RunCancelDialogSteps", this,
&HTMLDialogElement::RunCancelDialogSteps));
}
void HTMLDialogElement::RunCancelDialogSteps() { // 1) Let close be the result of firing an event named cancel at dialog, with // the cancelable attribute initialized to true. bool defaultAction = true;
nsContentUtils::DispatchTrustedEvent(OwnerDoc(), this, u"cancel"_ns,
CanBubble::eNo, Cancelable::eYes,
&defaultAction);
// 2) If close is true and dialog has an open attribute, then close the dialog // with no return value. if (defaultAction) {
Optional<nsAString> retValue;
Close(retValue);
}
}
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.