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 #ifndef HTMLDialogElement_h 8 #define HTMLDialogElement_h 9 10 #include "mozilla/AsyncEventDispatcher.h" 11 #include "mozilla/Attributes.h" 12 #include "nsGenericHTMLElement.h" 13 #include "nsGkAtoms.h" 14 15 namespace mozilla { 16 namespace dom { 17 18 class HTMLDialogElement final : public nsGenericHTMLElement { 19 public: HTMLDialogElement(already_AddRefed<mozilla::dom::NodeInfo> && aNodeInfo)20 explicit HTMLDialogElement( 21 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) 22 : nsGenericHTMLElement(std::move(aNodeInfo)), 23 mPreviouslyFocusedElement(nullptr) {} 24 25 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLDialogElement, dialog) 26 27 nsresult Clone(dom::NodeInfo* aNodeInfo, nsINode** aResult) const override; 28 29 static bool IsDialogEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj); 30 Open()31 bool Open() const { return GetBoolAttr(nsGkAtoms::open); } SetOpen(bool aOpen,ErrorResult & aError)32 void SetOpen(bool aOpen, ErrorResult& aError) { 33 SetHTMLBoolAttr(nsGkAtoms::open, aOpen, aError); 34 } 35 GetReturnValue(nsAString & aReturnValue)36 void GetReturnValue(nsAString& aReturnValue) { aReturnValue = mReturnValue; } SetReturnValue(const nsAString & aReturnValue)37 void SetReturnValue(const nsAString& aReturnValue) { 38 mReturnValue = aReturnValue; 39 } 40 41 void UnbindFromTree(bool aNullParent = true) override; 42 43 void Close(const mozilla::dom::Optional<nsAString>& aReturnValue); 44 void Show(); 45 void ShowModal(ErrorResult& aError); 46 47 bool IsInTopLayer() const; 48 void QueueCancelDialog(); 49 void RunCancelDialogSteps(); 50 51 nsString mReturnValue; 52 53 protected: 54 virtual ~HTMLDialogElement(); 55 void FocusDialog(); 56 JSObject* WrapNode(JSContext* aCx, 57 JS::Handle<JSObject*> aGivenProto) override; 58 59 private: 60 void AddToTopLayerIfNeeded(); 61 void RemoveFromTopLayerIfNeeded(); 62 void StorePreviouslyFocusedElement(); 63 64 nsWeakPtr mPreviouslyFocusedElement; 65 }; 66 67 } // namespace dom 68 } // namespace mozilla 69 70 #endif 71