HTMLElement.h (3316B)
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_HTMLElement_h 8 #define mozilla_dom_HTMLElement_h 9 10 #include "nsGenericHTMLElement.h" 11 12 namespace mozilla::dom { 13 14 class HTMLElement final : public nsGenericHTMLFormElement { 15 public: 16 explicit HTMLElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, 17 FromParser aFromParser = NOT_FROM_PARSER); 18 19 // nsISupports 20 NS_DECL_ISUPPORTS_INHERITED 21 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLElement, 22 nsGenericHTMLFormElement) 23 24 [[nodiscard]] nsIFormControl* GetAsFormControl() final; 25 [[nodiscard]] const nsIFormControl* GetAsFormControl() const final; 26 27 // EventTarget 28 void GetEventTargetParent(EventChainPreVisitor& aVisitor) override; 29 30 // nsINode 31 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 32 nsINode* GetScopeChainParent() const override; 33 34 // nsIContent 35 nsresult BindToTree(BindContext&, nsINode& aParent) override; 36 void UnbindFromTree(UnbindContext&) override; 37 void DoneCreatingElement() override; 38 39 // Element 40 void SetCustomElementDefinition( 41 CustomElementDefinition* aDefinition) override; 42 bool IsLabelable() const override { return IsFormAssociatedElement(); } 43 44 // nsGenericHTMLElement 45 // https://html.spec.whatwg.org/multipage/custom-elements.html#dom-attachinternals 46 already_AddRefed<mozilla::dom::ElementInternals> AttachInternals( 47 ErrorResult& aRv) override; 48 bool IsDisabledForEvents(WidgetEvent* aEvent) override; 49 50 // nsGenericHTMLFormElement 51 bool IsFormAssociatedElement() const override; 52 void AfterClearForm(bool aUnbindOrDelete) override; 53 void FieldSetDisabledChanged(bool aNotify) override; 54 void SaveState() override; 55 void UpdateValidityElementStates(bool aNotify); 56 57 void UpdateFormOwner(); 58 59 void MaybeRestoreFormAssociatedCustomElementState(); 60 61 void InhibitRestoration(bool aShouldInhibit); 62 63 protected: 64 virtual ~HTMLElement() = default; 65 66 JSObject* WrapNode(JSContext* aCx, 67 JS::Handle<JSObject*> aGivenProto) override; 68 69 // Element 70 void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, 71 const nsAttrValue* aValue, const nsAttrValue* aOldValue, 72 nsIPrincipal* aMaybeScriptedPrincipal, 73 bool aNotify) override; 74 75 // nsGenericHTMLFormElement 76 void SetFormInternal(HTMLFormElement* aForm, bool aBindToTree) override; 77 HTMLFormElement* GetFormInternal() const override; 78 void SetFieldSetInternal(HTMLFieldSetElement* aFieldset) override; 79 HTMLFieldSetElement* GetFieldSetInternal() const override; 80 bool CanBeDisabled() const override; 81 void UpdateDisabledState(bool aNotify) override; 82 void UpdateFormOwner(bool aBindToTree, Element* aFormIdElement) override; 83 84 void UpdateBarredFromConstraintValidation(); 85 86 ElementInternals* GetElementInternals() const; 87 88 MOZ_CAN_RUN_SCRIPT_BOUNDARY 89 void RestoreFormAssociatedCustomElementState(); 90 }; 91 92 } // namespace mozilla::dom 93 94 #endif // mozilla_dom_HTMLElement_h