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/. */
7 #ifndef HTMLDialogElement_h
8 #define HTMLDialogElement_h
10 #include "mozilla/AsyncEventDispatcher.h"
11 #include "mozilla/Attributes.h"
12 #include "nsGenericHTMLElement.h"
13 #include "nsGkAtoms.h"
15 namespace mozilla::dom
{
17 class HTMLDialogElement final
: public nsGenericHTMLElement
{
19 explicit HTMLDialogElement(
20 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
21 : nsGenericHTMLElement(std::move(aNodeInfo
)),
22 mPreviouslyFocusedElement(nullptr) {}
24 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLDialogElement
, dialog
)
26 nsresult
Clone(dom::NodeInfo
* aNodeInfo
, nsINode
** aResult
) const override
;
28 bool Open() const { return GetBoolAttr(nsGkAtoms::open
); }
29 void SetOpen(bool aOpen
, ErrorResult
& aError
) {
30 SetHTMLBoolAttr(nsGkAtoms::open
, aOpen
, aError
);
33 void GetReturnValue(nsAString
& aReturnValue
) { aReturnValue
= mReturnValue
; }
34 void SetReturnValue(const nsAString
& aReturnValue
) {
35 mReturnValue
= aReturnValue
;
38 void UnbindFromTree(bool aNullParent
= true) override
;
40 void Close(const mozilla::dom::Optional
<nsAString
>& aReturnValue
);
41 void Show(ErrorResult
& aError
);
42 void ShowModal(ErrorResult
& aError
);
44 bool IsInTopLayer() const;
45 void QueueCancelDialog();
46 void RunCancelDialogSteps();
48 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void FocusDialog();
50 int32_t TabIndexDefault() override
;
52 nsString mReturnValue
;
55 virtual ~HTMLDialogElement();
56 JSObject
* WrapNode(JSContext
* aCx
,
57 JS::Handle
<JSObject
*> aGivenProto
) override
;
60 void AddToTopLayerIfNeeded();
61 void RemoveFromTopLayerIfNeeded();
62 void StorePreviouslyFocusedElement();
64 nsWeakPtr mPreviouslyFocusedElement
;
67 } // namespace mozilla::dom