/src/mozilla-central/dom/html/HTMLDialogElement.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | NS_NewHTMLDialogElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, |
15 | | mozilla::dom::FromParser aFromParser) |
16 | 0 | { |
17 | 0 | if (!mozilla::dom::HTMLDialogElement::IsDialogEnabled()) { |
18 | 0 | return new mozilla::dom::HTMLUnknownElement(std::move(aNodeInfo)); |
19 | 0 | } |
20 | 0 | |
21 | 0 | return new mozilla::dom::HTMLDialogElement(std::move(aNodeInfo)); |
22 | 0 | } |
23 | | |
24 | | namespace mozilla { |
25 | | namespace dom { |
26 | | |
27 | | HTMLDialogElement::~HTMLDialogElement() |
28 | 0 | { |
29 | 0 | } |
30 | | |
31 | | NS_IMPL_ELEMENT_CLONE(HTMLDialogElement) |
32 | | |
33 | | bool |
34 | | HTMLDialogElement::IsDialogEnabled() |
35 | 0 | { |
36 | 0 | static bool isDialogEnabled = false; |
37 | 0 | static bool added = false; |
38 | 0 |
|
39 | 0 | if (!added) { |
40 | 0 | Preferences::AddBoolVarCache(&isDialogEnabled, |
41 | 0 | "dom.dialog_element.enabled"); |
42 | 0 | added = true; |
43 | 0 | } |
44 | 0 |
|
45 | 0 | return isDialogEnabled; |
46 | 0 | } |
47 | | |
48 | | void |
49 | | HTMLDialogElement::Close(const mozilla::dom::Optional<nsAString>& aReturnValue) |
50 | 0 | { |
51 | 0 | if (!Open()) { |
52 | 0 | return; |
53 | 0 | } |
54 | 0 | if (aReturnValue.WasPassed()) { |
55 | 0 | SetReturnValue(aReturnValue.Value()); |
56 | 0 | } |
57 | 0 | ErrorResult ignored; |
58 | 0 | SetOpen(false, ignored); |
59 | 0 | ignored.SuppressException(); |
60 | 0 | RefPtr<AsyncEventDispatcher> eventDispatcher = |
61 | 0 | new AsyncEventDispatcher(this, NS_LITERAL_STRING("close"), CanBubble::eNo); |
62 | 0 | eventDispatcher->PostDOMEvent(); |
63 | 0 | } |
64 | | |
65 | | void |
66 | | HTMLDialogElement::Show() |
67 | 0 | { |
68 | 0 | if (Open()) { |
69 | 0 | return; |
70 | 0 | } |
71 | 0 | ErrorResult ignored; |
72 | 0 | SetOpen(true, ignored); |
73 | 0 | ignored.SuppressException(); |
74 | 0 | } |
75 | | |
76 | | void |
77 | | HTMLDialogElement::ShowModal(ErrorResult& aError) |
78 | 0 | { |
79 | 0 | if (!IsInComposedDoc() || Open()) { |
80 | 0 | aError.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); |
81 | 0 | return; |
82 | 0 | } |
83 | 0 | |
84 | 0 | SetOpen(true, aError); |
85 | 0 | aError.SuppressException(); |
86 | 0 | } |
87 | | |
88 | | JSObject* |
89 | | HTMLDialogElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
90 | 0 | { |
91 | 0 | return HTMLDialogElement_Binding::Wrap(aCx, this, aGivenProto); |
92 | 0 | } |
93 | | |
94 | | } // namespace dom |
95 | | } // namespace mozilla |