HTMLDetailsElement.h (2984B)
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 mozilla_dom_HTMLDetailsElement_h 8 #define mozilla_dom_HTMLDetailsElement_h 9 10 #include "mozilla/AsyncEventDispatcher.h" 11 #include "mozilla/Attributes.h" 12 #include "nsGenericHTMLElement.h" 13 14 namespace mozilla::dom { 15 16 class HTMLSummaryElement; 17 18 // HTMLDetailsElement implements the <details> tag, which is used as a 19 // disclosure widget from which the user can obtain additional information or 20 // controls. Please see the spec for more information. 21 // https://html.spec.whatwg.org/multipage/forms.html#the-details-element 22 // 23 class HTMLDetailsElement final : public nsGenericHTMLElement { 24 public: 25 using NodeInfo = mozilla::dom::NodeInfo; 26 using Element::Command; 27 28 explicit HTMLDetailsElement(already_AddRefed<NodeInfo>&& aNodeInfo); 29 30 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLDetailsElement, details) 31 32 HTMLSummaryElement* GetFirstSummary() const; 33 34 nsresult Clone(NodeInfo* aNodeInfo, nsINode** aResult) const override; 35 36 void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, 37 const nsAttrValue* aValue, const nsAttrValue* aOldValue, 38 nsIPrincipal* aMaybeScriptedPrincipal, 39 bool aNotify) override; 40 41 nsresult BindToTree(BindContext&, nsINode& aParent) override; 42 43 bool IsInteractiveHTMLContent() const override { return true; } 44 45 // HTMLDetailsElement WebIDL 46 47 void SetName(const nsAString& aName, ErrorResult& aRv) { 48 SetHTMLAttr(nsGkAtoms::name, aName, aRv); 49 } 50 51 void GetName(nsAString& aName) { GetHTMLAttr(nsGkAtoms::name, aName); } 52 53 bool Open() const { return GetBoolAttr(nsGkAtoms::open); } 54 55 void SetOpen(bool aOpen, ErrorResult& aError) { 56 SetHTMLBoolAttr(nsGkAtoms::open, aOpen, aError); 57 } 58 59 void ToggleOpen() { SetOpen(!Open(), IgnoreErrors()); } 60 61 void AsyncEventRunning(AsyncEventDispatcher* aEvent) override; 62 63 bool IsValidCommandAction(Command aCommand) const override; 64 MOZ_CAN_RUN_SCRIPT bool HandleCommandInternal(Element* aSource, 65 Command aCommand, 66 ErrorResult& aRv) override; 67 68 protected: 69 virtual ~HTMLDetailsElement(); 70 void SetupShadowTree(); 71 72 // https://html.spec.whatwg.org/#ensure-details-exclusivity-by-closing-the-given-element-if-needed 73 void CloseElementIfNeeded(); 74 75 // https://html.spec.whatwg.org/#ensure-details-exclusivity-by-closing-other-elements-if-needed 76 void CloseOtherElementsIfNeeded(); 77 78 JSObject* WrapNode(JSContext* aCx, 79 JS::Handle<JSObject*> aGivenProto) override; 80 81 RefPtr<AsyncEventDispatcher> mToggleEventDispatcher; 82 }; 83 84 } // namespace mozilla::dom 85 86 #endif /* mozilla_dom_HTMLDetailsElement_h */