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 "nsGenericHTMLElement.h"
12 #include "nsIConstraintValidation.h"
13 #include "mozilla/dom/HTMLFormElement.h"
14 #include "mozilla/dom/ValidityState.h"
17 class EventChainPreVisitor
;
20 class HTMLFieldSetElement final
: public nsGenericHTMLFormElement
,
21 public nsIConstraintValidation
{
23 using nsGenericHTMLFormElement::GetForm
;
24 using nsIConstraintValidation::GetValidationMessage
;
25 using nsIConstraintValidation::SetCustomValidity
;
27 explicit HTMLFieldSetElement(
28 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
30 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLFieldSetElement
, fieldset
)
33 NS_DECL_ISUPPORTS_INHERITED
36 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
37 virtual nsresult
AfterSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
38 const nsAttrValue
* aValue
,
39 const nsAttrValue
* aOldValue
,
40 nsIPrincipal
* aSubjectPrincipal
,
41 bool aNotify
) override
;
43 virtual nsresult
InsertChildBefore(nsIContent
* aChild
,
44 nsIContent
* aBeforeThis
,
45 bool aNotify
) override
;
46 virtual void RemoveChildNode(nsIContent
* aKid
, bool aNotify
) override
;
49 NS_IMETHOD
Reset() override
;
50 NS_IMETHOD
SubmitNamesValues(HTMLFormSubmission
* aFormSubmission
) override
;
51 virtual bool IsDisabledForEvents(WidgetEvent
* aEvent
) override
;
52 virtual nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
54 const nsIContent
* GetFirstLegend() const { return mFirstLegend
; }
56 void AddElement(nsGenericHTMLFormElement
* aElement
);
58 void RemoveElement(nsGenericHTMLFormElement
* aElement
);
60 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLFieldSetElement
,
61 nsGenericHTMLFormElement
)
64 bool Disabled() const { return GetBoolAttr(nsGkAtoms::disabled
); }
65 void SetDisabled(bool aValue
, ErrorResult
& aRv
) {
66 SetHTMLBoolAttr(nsGkAtoms::disabled
, aValue
, aRv
);
69 void GetName(nsAString
& aValue
) { GetHTMLAttr(nsGkAtoms::name
, aValue
); }
71 void SetName(const nsAString
& aValue
, ErrorResult
& aRv
) {
72 SetHTMLAttr(nsGkAtoms::name
, aValue
, aRv
);
75 void GetType(nsAString
& aType
) const;
77 nsIHTMLCollection
* Elements();
79 // XPCOM WillValidate is OK for us
81 // XPCOM Validity is OK for us
83 // XPCOM GetValidationMessage is OK for us
85 // XPCOM CheckValidity is OK for us
87 // XPCOM SetCustomValidity is OK for us
89 virtual EventStates
IntrinsicState() const override
;
92 * This method will update the fieldset's validity. This method has to be
93 * called by fieldset elements whenever their validity state or status
94 * regarding constraint validation changes.
96 * @note If an element becomes barred from constraint validation, it has to
97 * be considered as valid.
99 * @param aElementValidityState the new validity state of the element
101 void UpdateValidity(bool aElementValidityState
);
104 virtual ~HTMLFieldSetElement();
106 virtual JSObject
* WrapNode(JSContext
* aCx
,
107 JS::Handle
<JSObject
*> aGivenProto
) override
;
111 * Notify all elements (in mElements) that the first legend of the fieldset
114 void NotifyElementsForFirstLegendChange(bool aNotify
);
116 // This function is used to generate the nsContentList (listed form elements).
117 static bool MatchListedElements(Element
* aElement
, int32_t aNamespaceID
,
118 nsAtom
* aAtom
, void* aData
);
120 // listed form controls elements.
121 RefPtr
<nsContentList
> mElements
;
123 // List of elements which have this fieldset as first fieldset ancestor.
124 nsTArray
<nsGenericHTMLFormElement
*> mDependentElements
;
126 nsIContent
* mFirstLegend
;
129 * Number of invalid and candidate for constraint validation
130 * elements in the fieldSet the last time UpdateValidity has been called.
132 * @note Should only be used by UpdateValidity() and IntrinsicState()!
134 int32_t mInvalidElementsCount
;
138 } // namespace mozilla
140 #endif /* mozilla_dom_HTMLFieldSetElement_h */