Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "mozilla/dom/HTMLDialogElement.h"
8 : #include "mozilla/dom/HTMLDialogElementBinding.h"
9 : #include "mozilla/dom/HTMLUnknownElement.h"
10 : #include "mozilla/Preferences.h"
11 :
12 : // Expand NS_IMPL_NS_NEW_HTML_ELEMENT(Dialog) with pref check
13 : nsGenericHTMLElement*
14 0 : NS_NewHTMLDialogElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
15 : mozilla::dom::FromParser aFromParser)
16 : {
17 0 : if (!mozilla::dom::HTMLDialogElement::IsDialogEnabled()) {
18 0 : return new mozilla::dom::HTMLUnknownElement(aNodeInfo);
19 : }
20 :
21 0 : return new mozilla::dom::HTMLDialogElement(aNodeInfo);
22 : }
23 :
24 : namespace mozilla {
25 : namespace dom {
26 :
27 0 : HTMLDialogElement::~HTMLDialogElement()
28 : {
29 0 : }
30 :
31 0 : NS_IMPL_ELEMENT_CLONE(HTMLDialogElement)
32 :
33 : bool
34 0 : HTMLDialogElement::IsDialogEnabled()
35 : {
36 : static bool isDialogEnabled = false;
37 : static bool added = false;
38 :
39 0 : if (!added) {
40 : Preferences::AddBoolVarCache(&isDialogEnabled,
41 0 : "dom.dialog_element.enabled");
42 0 : added = true;
43 : }
44 :
45 0 : return isDialogEnabled;
46 : }
47 :
48 : void
49 0 : HTMLDialogElement::Close(const mozilla::dom::Optional<nsAString>& aReturnValue)
50 : {
51 0 : if (!Open()) {
52 0 : return;
53 : }
54 0 : if (aReturnValue.WasPassed()) {
55 0 : SetReturnValue(aReturnValue.Value());
56 : }
57 0 : ErrorResult ignored;
58 0 : SetOpen(false, ignored);
59 0 : ignored.SuppressException();
60 : RefPtr<AsyncEventDispatcher> eventDispatcher =
61 0 : new AsyncEventDispatcher(this, NS_LITERAL_STRING("close"), false);
62 0 : eventDispatcher->PostDOMEvent();
63 : }
64 :
65 : void
66 0 : HTMLDialogElement::Show()
67 : {
68 0 : if (Open()) {
69 0 : return;
70 : }
71 0 : ErrorResult ignored;
72 0 : SetOpen(true, ignored);
73 0 : ignored.SuppressException();
74 : }
75 :
76 : void
77 0 : HTMLDialogElement::ShowModal(ErrorResult& aError)
78 : {
79 0 : if (!IsInComposedDoc() || Open()) {
80 0 : aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
81 0 : return;
82 : }
83 :
84 0 : SetOpen(true, aError);
85 0 : aError.SuppressException();
86 : }
87 :
88 : JSObject*
89 0 : HTMLDialogElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
90 : {
91 0 : return HTMLDialogElementBinding::Wrap(aCx, this, aGivenProto);
92 : }
93 :
94 : } // namespace dom
95 : } // namespace mozilla
|