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