Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / html / HTMLFieldSetElement.h
blob4b592937b295d4a229f3cc4d970aa72dc848c278
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 mozilla_dom_HTMLFieldSetElement_h
8 #define mozilla_dom_HTMLFieldSetElement_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/ConstraintValidation.h"
12 #include "mozilla/dom/ValidityState.h"
13 #include "nsGenericHTMLElement.h"
15 namespace mozilla {
16 class ErrorResult;
17 class EventChainPreVisitor;
18 namespace dom {
19 class FormData;
21 class HTMLFieldSetElement final : public nsGenericHTMLFormControlElement,
22 public ConstraintValidation {
23 public:
24 using ConstraintValidation::GetValidationMessage;
25 using ConstraintValidation::SetCustomValidity;
27 explicit HTMLFieldSetElement(
28 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
30 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLFieldSetElement, fieldset)
32 // nsISupports
33 NS_DECL_ISUPPORTS_INHERITED
35 // nsINode
36 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
38 // nsIContent
39 void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
40 void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
41 const nsAttrValue* aValue, const nsAttrValue* aOldValue,
42 nsIPrincipal* aSubjectPrincipal, bool aNotify) override;
44 void InsertChildBefore(nsIContent* aChild, nsIContent* aBeforeThis,
45 bool aNotify, ErrorResult& aRv) override;
46 void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
48 // nsGenericHTMLElement
49 bool IsDisabledForEvents(WidgetEvent* aEvent) override;
51 // nsIFormControl
52 NS_IMETHOD Reset() override;
53 NS_IMETHOD SubmitNamesValues(FormData* aFormData) override { return NS_OK; }
55 const nsIContent* GetFirstLegend() const { return mFirstLegend; }
57 void AddElement(nsGenericHTMLFormElement* aElement);
59 void RemoveElement(nsGenericHTMLFormElement* aElement);
61 // nsGenericHTMLFormElement
62 void UpdateDisabledState(bool aNotify) override;
64 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLFieldSetElement,
65 nsGenericHTMLFormControlElement)
67 // WebIDL
68 bool Disabled() const { return GetBoolAttr(nsGkAtoms::disabled); }
69 void SetDisabled(bool aValue, ErrorResult& aRv) {
70 SetHTMLBoolAttr(nsGkAtoms::disabled, aValue, aRv);
73 void GetName(nsAString& aValue) { GetHTMLAttr(nsGkAtoms::name, aValue); }
75 void SetName(const nsAString& aValue, ErrorResult& aRv) {
76 SetHTMLAttr(nsGkAtoms::name, aValue, aRv);
79 void GetType(nsAString& aType) const;
81 nsIHTMLCollection* Elements();
83 // XPCOM WillValidate is OK for us
85 // XPCOM Validity is OK for us
87 // XPCOM GetValidationMessage is OK for us
89 // XPCOM CheckValidity is OK for us
91 // XPCOM SetCustomValidity is OK for us
94 * This method will update the fieldset's validity. This method has to be
95 * called by fieldset elements whenever their validity state or status
96 * regarding constraint validation changes.
98 * @note If an element becomes barred from constraint validation, it has to
99 * be considered as valid.
101 * @param aElementValidityState the new validity state of the element
103 void UpdateValidity(bool aElementValidityState);
105 protected:
106 virtual ~HTMLFieldSetElement();
108 JSObject* WrapNode(JSContext* aCx,
109 JS::Handle<JSObject*> aGivenProto) override;
111 private:
113 * Notify all elements (in mElements) that the first legend of the fieldset
114 * has now changed.
116 void NotifyElementsForFirstLegendChange(bool aNotify);
118 // This function is used to generate the nsContentList (listed form elements).
119 static bool MatchListedElements(Element* aElement, int32_t aNamespaceID,
120 nsAtom* aAtom, void* aData);
122 // listed form controls elements.
123 RefPtr<nsContentList> mElements;
125 // List of elements which have this fieldset as first fieldset ancestor.
126 nsTArray<nsGenericHTMLFormElement*> mDependentElements;
128 nsIContent* mFirstLegend;
131 * Number of invalid and candidate for constraint validation
132 * elements in the fieldSet the last time UpdateValidity has been called.
134 * @note Should only be used by UpdateValidity()
136 int32_t mInvalidElementsCount;
139 } // namespace dom
140 } // namespace mozilla
142 #endif /* mozilla_dom_HTMLFieldSetElement_h */