HTMLFieldSetElement.h (4837B)
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_HTMLFieldSetElement_h 8 #define mozilla_dom_HTMLFieldSetElement_h 9 10 #include "mozilla/dom/ConstraintValidation.h" 11 #include "mozilla/dom/ValidityState.h" 12 #include "nsGenericHTMLElement.h" 13 14 namespace mozilla { 15 class ErrorResult; 16 class EventChainPreVisitor; 17 namespace dom { 18 class FormData; 19 20 class HTMLFieldSetElement final : public nsGenericHTMLFormControlElement, 21 public ConstraintValidation { 22 public: 23 using ConstraintValidation::GetValidationMessage; 24 using ConstraintValidation::SetCustomValidity; 25 26 explicit HTMLFieldSetElement( 27 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 28 29 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLFieldSetElement, fieldset) 30 31 // nsISupports 32 NS_DECL_ISUPPORTS_INHERITED 33 34 // nsINode 35 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 36 37 // nsIContent 38 void GetEventTargetParent(EventChainPreVisitor& aVisitor) override; 39 void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, 40 const nsAttrValue* aValue, const nsAttrValue* aOldValue, 41 nsIPrincipal* aSubjectPrincipal, bool aNotify) override; 42 43 void InsertChildBefore( 44 nsIContent* aChild, nsIContent* aBeforeThis, bool aNotify, 45 ErrorResult& aRv, nsINode* aOldParent = nullptr, 46 MutationEffectOnScript aMutationEffectOnScript = 47 MutationEffectOnScript::DropTrustWorthiness) override; 48 void RemoveChildNode( 49 nsIContent* aKid, bool aNotify, const BatchRemovalState* aState, 50 nsINode* aNewParent = nullptr, 51 MutationEffectOnScript aMutationEffectOnScript = 52 MutationEffectOnScript::DropTrustWorthiness) override; 53 54 // nsGenericHTMLElement 55 bool IsDisabledForEvents(WidgetEvent* aEvent) override; 56 57 // nsIFormControl 58 NS_IMETHOD Reset() override; 59 NS_IMETHOD SubmitNamesValues(FormData* aFormData) override { return NS_OK; } 60 61 const nsIContent* GetFirstLegend() const { return mFirstLegend; } 62 63 void AddElement(nsGenericHTMLFormElement* aElement); 64 65 void RemoveElement(nsGenericHTMLFormElement* aElement); 66 67 // nsGenericHTMLFormElement 68 void UpdateDisabledState(bool aNotify) override; 69 70 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLFieldSetElement, 71 nsGenericHTMLFormControlElement) 72 73 // WebIDL 74 bool Disabled() const { return GetBoolAttr(nsGkAtoms::disabled); } 75 void SetDisabled(bool aValue, ErrorResult& aRv) { 76 SetHTMLBoolAttr(nsGkAtoms::disabled, aValue, aRv); 77 } 78 79 void GetName(nsAString& aValue) { GetHTMLAttr(nsGkAtoms::name, aValue); } 80 81 void SetName(const nsAString& aValue, ErrorResult& aRv) { 82 SetHTMLAttr(nsGkAtoms::name, aValue, aRv); 83 } 84 85 void GetType(nsAString& aType) const; 86 87 nsIHTMLCollection* Elements(); 88 89 // XPCOM WillValidate is OK for us 90 91 // XPCOM Validity is OK for us 92 93 // XPCOM GetValidationMessage is OK for us 94 95 // XPCOM CheckValidity is OK for us 96 97 // XPCOM SetCustomValidity is OK for us 98 99 /* 100 * This method will update the fieldset's validity. This method has to be 101 * called by fieldset elements whenever their validity state or status 102 * regarding constraint validation changes. 103 * 104 * @note If an element becomes barred from constraint validation, it has to 105 * be considered as valid. 106 * 107 * @param aElementValidityState the new validity state of the element 108 */ 109 void UpdateValidity(bool aElementValidityState); 110 111 protected: 112 virtual ~HTMLFieldSetElement(); 113 114 JSObject* WrapNode(JSContext* aCx, 115 JS::Handle<JSObject*> aGivenProto) override; 116 117 private: 118 /** 119 * Notify all elements (in mElements) that the first legend of the fieldset 120 * has now changed. 121 */ 122 void NotifyElementsForFirstLegendChange(bool aNotify); 123 124 // This function is used to generate the nsContentList (listed form elements). 125 static bool MatchListedElements(Element* aElement, int32_t aNamespaceID, 126 nsAtom* aAtom, void* aData); 127 128 // listed form controls elements. 129 RefPtr<nsContentList> mElements; 130 131 // List of elements which have this fieldset as first fieldset ancestor. 132 nsTArray<nsGenericHTMLFormElement*> mDependentElements; 133 134 nsIContent* mFirstLegend; 135 136 /** 137 * Number of invalid and candidate for constraint validation 138 * elements in the fieldSet the last time UpdateValidity has been called. 139 * 140 * @note Should only be used by UpdateValidity() 141 */ 142 int32_t mInvalidElementsCount; 143 }; 144 145 } // namespace dom 146 } // namespace mozilla 147 148 #endif /* mozilla_dom_HTMLFieldSetElement_h */