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 ++++++++++++++++++++++++ dom/html/HTMLDialogElement.h | 58 +++++++++++++++++++++ dom/html/moz.build | 2 + dom/html/nsGenericHTMLElement.h | 1 + dom/tests/mochitest/general/test_interfaces.html | 2 + dom/webidl/HTMLDialogElement.webidl | 22 ++++++++ dom/webidl/moz.build | 1 + 7 files changed, 151 insertions(+) create mode 100644 dom/html/HTMLDialogElement.cpp create mode 100644 dom/html/HTMLDialogElement.h create mode 100644 dom/webidl/HTMLDialogElement.webidl (limited to 'dom') 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 diff --git a/dom/html/HTMLDialogElement.h b/dom/html/HTMLDialogElement.h new file mode 100644 index 000000000..7abaee81c --- /dev/null +++ b/dom/html/HTMLDialogElement.h @@ -0,0 +1,58 @@ +/* -*- 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/. */ + +#ifndef HTMLDialogElement_h +#define HTMLDialogElement_h + +#include "mozilla/Attributes.h" +#include "nsGenericHTMLElement.h" +#include "nsGkAtoms.h" + +namespace mozilla { +namespace dom { + +class HTMLDialogElement final : public nsGenericHTMLElement +{ +public: + explicit HTMLDialogElement(already_AddRefed& aNodeInfo) : nsGenericHTMLElement(aNodeInfo) + { + } + + NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLDialogElement, dialog) + + virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const override; + + bool Open() const { return GetBoolAttr(nsGkAtoms::open); } + void SetOpen(bool aOpen, ErrorResult& aError) + { + SetHTMLBoolAttr(nsGkAtoms::open, aOpen, aError); + } + + void GetReturnValue(nsAString& aReturnValue) + { + aReturnValue = mReturnValue; + } + void SetReturnValue(const nsAString& aReturnValue) + { + mReturnValue = aReturnValue; + } + + void Close(const mozilla::dom::Optional& aReturnValue); + void Show(); + void ShowModal(ErrorResult& aError); + + nsString mReturnValue; + +protected: + virtual ~HTMLDialogElement(); + JSObject* WrapNode(JSContext* aCx, + JS::Handle aGivenProto) override; +}; + +} // namespace dom +} // namespace mozilla + +#endif diff --git a/dom/html/moz.build b/dom/html/moz.build index c9879d1e6..c86c169b5 100644 --- a/dom/html/moz.build +++ b/dom/html/moz.build @@ -56,6 +56,7 @@ EXPORTS.mozilla.dom += [ 'HTMLDataElement.h', 'HTMLDataListElement.h', 'HTMLDetailsElement.h', + 'HTMLDialogElement.h', 'HTMLDivElement.h', 'HTMLFieldSetElement.h', 'HTMLFontElement.h', @@ -134,6 +135,7 @@ UNIFIED_SOURCES += [ 'HTMLDataElement.cpp', 'HTMLDataListElement.cpp', 'HTMLDetailsElement.cpp', + 'HTMLDialogElement.cpp', 'HTMLDivElement.cpp', 'HTMLElement.cpp', 'HTMLFieldSetElement.cpp', diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index 24a7a3652..72039f266 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -1654,6 +1654,7 @@ NS_DECLARE_NS_NEW_HTML_ELEMENT(Mod) NS_DECLARE_NS_NEW_HTML_ELEMENT(Data) NS_DECLARE_NS_NEW_HTML_ELEMENT(DataList) NS_DECLARE_NS_NEW_HTML_ELEMENT(Details) +NS_DECLARE_NS_NEW_HTML_ELEMENT(Dialog) NS_DECLARE_NS_NEW_HTML_ELEMENT(Div) NS_DECLARE_NS_NEW_HTML_ELEMENT(FieldSet) NS_DECLARE_NS_NEW_HTML_ELEMENT(Font) diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index 98f3ffed0..9208997be 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -442,6 +442,8 @@ var interfaceNamesInGlobalScope = "HTMLDataListElement", // IMPORTANT: Do not change this list without review from a DOM peer! "HTMLDetailsElement", +// IMPORTANT: Do not change this list without review from a DOM peer! + "HTMLDialogElement", // IMPORTANT: Do not change this list without review from a DOM peer! "HTMLDirectoryElement", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/HTMLDialogElement.webidl b/dom/webidl/HTMLDialogElement.webidl new file mode 100644 index 000000000..f4aa8484a --- /dev/null +++ b/dom/webidl/HTMLDialogElement.webidl @@ -0,0 +1,22 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. + * + * The origin of this IDL file is + * https://html.spec.whatwg.org/multipage/forms.html#the-dialog-element + * + * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and + * Opera Software ASA. You are granted a license to use, reproduce + * and create derivative works of this document. + */ + +interface HTMLDialogElement : HTMLElement { + [SetterThrows] attribute boolean open; + attribute DOMString returnValue; + + void show(); + [Throws] void showModal(); + + void close(optional DOMString returnValue); +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 172895f97..4e3b8f655 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -184,6 +184,7 @@ WEBIDL_FILES = [ 'HTMLDataElement.webidl', 'HTMLDataListElement.webidl', 'HTMLDetailsElement.webidl', + 'HTMLDialogElement.webidl', 'HTMLDirectoryElement.webidl', 'HTMLDivElement.webidl', 'HTMLDListElement.webidl', -- 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/events/EventNameList.h | 4 ++++ dom/html/HTMLDialogElement.cpp | 3 +++ dom/html/HTMLDialogElement.h | 1 + dom/webidl/EventHandler.webidl | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) (limited to 'dom') diff --git a/dom/events/EventNameList.h b/dom/events/EventNameList.h index 214b844e7..c299133e3 100644 --- a/dom/events/EventNameList.h +++ b/dom/events/EventNameList.h @@ -172,6 +172,10 @@ EVENT(click, eMouseClick, EventNameType_All, eMouseEventClass) +EVENT(close, + eClose, + EventNameType_HTML, + eBasicEventClass) EVENT(contextmenu, eContextMenu, EventNameType_HTMLXUL, 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 diff --git a/dom/html/HTMLDialogElement.h b/dom/html/HTMLDialogElement.h index 7abaee81c..2222cd2f7 100644 --- a/dom/html/HTMLDialogElement.h +++ b/dom/html/HTMLDialogElement.h @@ -7,6 +7,7 @@ #ifndef HTMLDialogElement_h #define HTMLDialogElement_h +#include "mozilla/AsyncEventDispatcher.h" #include "mozilla/Attributes.h" #include "nsGenericHTMLElement.h" #include "nsGkAtoms.h" diff --git a/dom/webidl/EventHandler.webidl b/dom/webidl/EventHandler.webidl index 1edc45ac9..b92e3a2bb 100644 --- a/dom/webidl/EventHandler.webidl +++ b/dom/webidl/EventHandler.webidl @@ -38,7 +38,7 @@ interface GlobalEventHandlers { attribute EventHandler oncanplaythrough; attribute EventHandler onchange; attribute EventHandler onclick; - //(Not implemented)attribute EventHandler onclose; + attribute EventHandler onclose; attribute EventHandler oncontextmenu; //(Not implemented)attribute EventHandler oncuechange; attribute EventHandler ondblclick; -- 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 +++++++++++++++++++++++- dom/html/HTMLDialogElement.h | 2 ++ dom/tests/mochitest/general/test_interfaces.html | 2 +- dom/webidl/HTMLDialogElement.webidl | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) (limited to 'dom') 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) { diff --git a/dom/html/HTMLDialogElement.h b/dom/html/HTMLDialogElement.h index 2222cd2f7..efa319f3c 100644 --- a/dom/html/HTMLDialogElement.h +++ b/dom/html/HTMLDialogElement.h @@ -26,6 +26,8 @@ public: virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const override; + static bool IsDialogEnabled(); + bool Open() const { return GetBoolAttr(nsGkAtoms::open); } void SetOpen(bool aOpen, ErrorResult& aError) { diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index 9208997be..eb09f5962 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -443,7 +443,7 @@ var interfaceNamesInGlobalScope = // IMPORTANT: Do not change this list without review from a DOM peer! "HTMLDetailsElement", // IMPORTANT: Do not change this list without review from a DOM peer! - "HTMLDialogElement", + {name: "HTMLDialogElement", disabled: true}, // IMPORTANT: Do not change this list without review from a DOM peer! "HTMLDirectoryElement", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/HTMLDialogElement.webidl b/dom/webidl/HTMLDialogElement.webidl index f4aa8484a..b6cdbacf6 100644 --- a/dom/webidl/HTMLDialogElement.webidl +++ b/dom/webidl/HTMLDialogElement.webidl @@ -11,6 +11,7 @@ * and create derivative works of this document. */ +[Pref="dom.dialog_element.enabled"] interface HTMLDialogElement : HTMLElement { [SetterThrows] attribute boolean open; attribute DOMString returnValue; -- cgit v1.2.3 From 52bda2a828364a9a2b3847a005587fa0ea952b30 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Tue, 7 Jan 2020 09:48:00 -0500 Subject: Bug 1379728 part 1. Remove the double-definition of the 'close' event from EventNameList.h. Tag #1343 --- dom/events/EventNameList.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'dom') diff --git a/dom/events/EventNameList.h b/dom/events/EventNameList.h index c299133e3..94e8a589b 100644 --- a/dom/events/EventNameList.h +++ b/dom/events/EventNameList.h @@ -174,7 +174,7 @@ EVENT(click, eMouseEventClass) EVENT(close, eClose, - EventNameType_HTML, + EventNameType_HTMLXUL, eBasicEventClass) EVENT(contextmenu, eContextMenu, @@ -777,10 +777,6 @@ NON_IDL_EVENT(command, eXULCommand, EventNameType_XUL, eInputEventClass) -NON_IDL_EVENT(close, - eWindowClose, - EventNameType_XUL, - eBasicEventClass) NON_IDL_EVENT(popupshowing, eXULPopupShowing, EventNameType_XUL, -- cgit v1.2.3