Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/HTMLFieldSetElement.h
Line
Count
Source (jump to first uncovered line)
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 "nsIConstraintValidation.h"
13
#include "mozilla/dom/HTMLFormElement.h"
14
#include "mozilla/dom/ValidityState.h"
15
16
namespace mozilla {
17
class EventChainPreVisitor;
18
namespace dom {
19
20
class HTMLFieldSetElement final : public nsGenericHTMLFormElement,
21
                                  public nsIConstraintValidation
22
{
23
public:
24
  using nsGenericHTMLFormElement::GetForm;
25
  using nsIConstraintValidation::GetValidationMessage;
26
  using nsIConstraintValidation::SetCustomValidity;
27
28
  explicit HTMLFieldSetElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
29
30
  NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLFieldSetElement, fieldset)
31
32
  // nsISupports
33
  NS_DECL_ISUPPORTS_INHERITED
34
35
  // nsIContent
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;
42
43
  virtual nsresult InsertChildBefore(nsIContent* aChild, nsIContent* aBeforeThis,
44
                                     bool aNotify) override;
45
  virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
46
47
  // nsIFormControl
48
  NS_IMETHOD Reset() override;
49
  NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
50
  virtual bool IsDisabledForEvents(EventMessage aMessage) override;
51
  virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
52
53
0
  const nsIContent* GetFirstLegend() const { return mFirstLegend; }
54
55
  void AddElement(nsGenericHTMLFormElement* aElement);
56
57
  void RemoveElement(nsGenericHTMLFormElement* aElement);
58
59
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLFieldSetElement,
60
                                           nsGenericHTMLFormElement)
61
62
  // WebIDL
63
  bool Disabled() const
64
0
  {
65
0
    return GetBoolAttr(nsGkAtoms::disabled);
66
0
  }
67
  void SetDisabled(bool aValue, ErrorResult& aRv)
68
0
  {
69
0
    SetHTMLBoolAttr(nsGkAtoms::disabled, aValue, aRv);
70
0
  }
71
72
  void GetName(nsAString& aValue)
73
0
  {
74
0
    GetHTMLAttr(nsGkAtoms::name, aValue);
75
0
  }
76
77
  void SetName(const nsAString& aValue, ErrorResult& aRv)
78
0
  {
79
0
    SetHTMLAttr(nsGkAtoms::name, aValue, aRv);
80
0
  }
81
82
  void GetType(nsAString & aType) const;
83
84
  nsIHTMLCollection* Elements();
85
86
  // XPCOM WillValidate is OK for us
87
88
  // XPCOM Validity is OK for us
89
90
  // XPCOM GetValidationMessage is OK for us
91
92
  // XPCOM CheckValidity is OK for us
93
94
  // XPCOM SetCustomValidity is OK for us
95
96
  virtual EventStates IntrinsicState() const override;
97
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 regarding
102
   * 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
  virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
115
116
private:
117
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() and IntrinsicState()!
141
   */
142
  int32_t mInvalidElementsCount;
143
};
144
145
} // namespace dom
146
} // namespace mozilla
147
148
#endif /* mozilla_dom_HTMLFieldSetElement_h */