From 2e3b937f4ee13e70584c881e0c65200e439ff7fa Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Tue, 7 Jan 2020 08:22:36 -0500 Subject: Bug 1322938 - Basic implementation of HTMLDialogElement. Tag #1343 --- dom/html/HTMLDialogElement.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 dom/html/HTMLDialogElement.cpp (limited to 'dom/html/HTMLDialogElement.cpp') diff --git a/dom/html/HTMLDialogElement.cpp b/dom/html/HTMLDialogElement.cpp new file mode 100644 index 000000000..1f796f9a6 --- /dev/null +++ b/dom/html/HTMLDialogElement.cpp @@ -0,0 +1,65 @@ +/* -*- 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/. */ + +#include "mozilla/dom/HTMLDialogElement.h" +#include "mozilla/dom/HTMLDialogElementBinding.h" + +NS_IMPL_NS_NEW_HTML_ELEMENT(Dialog) + +namespace mozilla { +namespace dom { + +HTMLDialogElement::~HTMLDialogElement() +{ +} + +NS_IMPL_ELEMENT_CLONE(HTMLDialogElement) + +void +HTMLDialogElement::Close(const mozilla::dom::Optional& aReturnValue) +{ + if (!Open()) { + return; + } + if (aReturnValue.WasPassed()) { + SetReturnValue(aReturnValue.Value()); + } + ErrorResult ignored; + SetOpen(false, ignored); + ignored.SuppressException(); +} + +void +HTMLDialogElement::Show() +{ + if (Open()) { + return; + } + ErrorResult ignored; + SetOpen(true, ignored); + ignored.SuppressException(); +} + +void +HTMLDialogElement::ShowModal(ErrorResult& aError) +{ + if (!IsInComposedDoc() || Open()) { + aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return; + } + + SetOpen(true, aError); + aError.SuppressException(); +} + +JSObject* +HTMLDialogElement::WrapNode(JSContext* aCx, JS::Handle aGivenProto) +{ + return HTMLDialogElementBinding::Wrap(aCx, this, aGivenProto); +} + +} // namespace dom +} // namespace mozilla -- cgit v1.2.3 From ef2cd8749ff41c3d87a19b598d8d3be1430b75bf Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Tue, 7 Jan 2020 08:27:34 -0500 Subject: Bug 1322938 - Emit close event when HTMLDialogElement.prototype.close() is called. Tag #1343 --- dom/html/HTMLDialogElement.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'dom/html/HTMLDialogElement.cpp') diff --git a/dom/html/HTMLDialogElement.cpp b/dom/html/HTMLDialogElement.cpp index 1f796f9a6..1f65b602f 100644 --- a/dom/html/HTMLDialogElement.cpp +++ b/dom/html/HTMLDialogElement.cpp @@ -30,6 +30,9 @@ HTMLDialogElement::Close(const mozilla::dom::Optional& aReturnValue) ErrorResult ignored; SetOpen(false, ignored); ignored.SuppressException(); + RefPtr eventDispatcher = + new AsyncEventDispatcher(this, NS_LITERAL_STRING("close"), false); + eventDispatcher->PostDOMEvent(); } void -- cgit v1.2.3 From b91b0c37eb6cab1e179252692ad7e7a60606efa3 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Tue, 7 Jan 2020 09:10:56 -0500 Subject: Bug 1322938 - Put element behind preference. Tag #1343 --- dom/html/HTMLDialogElement.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'dom/html/HTMLDialogElement.cpp') diff --git a/dom/html/HTMLDialogElement.cpp b/dom/html/HTMLDialogElement.cpp index 1f65b602f..48666628e 100644 --- a/dom/html/HTMLDialogElement.cpp +++ b/dom/html/HTMLDialogElement.cpp @@ -6,8 +6,20 @@ #include "mozilla/dom/HTMLDialogElement.h" #include "mozilla/dom/HTMLDialogElementBinding.h" +#include "mozilla/dom/HTMLUnknownElement.h" +#include "mozilla/Preferences.h" -NS_IMPL_NS_NEW_HTML_ELEMENT(Dialog) +// Expand NS_IMPL_NS_NEW_HTML_ELEMENT(Dialog) with pref check +nsGenericHTMLElement* +NS_NewHTMLDialogElement(already_AddRefed&& aNodeInfo, + mozilla::dom::FromParser aFromParser) +{ + if (!mozilla::dom::HTMLDialogElement::IsDialogEnabled()) { + return new mozilla::dom::HTMLUnknownElement(aNodeInfo); + } + + return new mozilla::dom::HTMLDialogElement(aNodeInfo); +} namespace mozilla { namespace dom { @@ -18,6 +30,21 @@ HTMLDialogElement::~HTMLDialogElement() NS_IMPL_ELEMENT_CLONE(HTMLDialogElement) +bool +HTMLDialogElement::IsDialogEnabled() +{ + static bool isDialogEnabled = false; + static bool added = false; + + if (!added) { + Preferences::AddBoolVarCache(&isDialogEnabled, + "dom.dialog_element.enabled"); + added = true; + } + + return isDialogEnabled; +} + void HTMLDialogElement::Close(const mozilla::dom::Optional& aReturnValue) { -- cgit v1.2.3