Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/HTMLOptionElement.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_HTMLOptionElement_h__
8
#define mozilla_dom_HTMLOptionElement_h__
9
10
#include "mozilla/Attributes.h"
11
#include "nsGenericHTMLElement.h"
12
#include "mozilla/dom/HTMLFormElement.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
class HTMLSelectElement;
18
19
class HTMLOptionElement final : public nsGenericHTMLElement
20
{
21
public:
22
  explicit HTMLOptionElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
23
24
  static already_AddRefed<HTMLOptionElement>
25
    Option(const GlobalObject& aGlobal,
26
           const nsAString& aText,
27
           const Optional<nsAString>& aValue,
28
           bool aDefaultSelected,
29
           bool aSelected,
30
           ErrorResult& aError);
31
32
  NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLOptionElement, option)
33
34
  // nsISupports
35
  NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLOptionElement, nsGenericHTMLElement)
36
37
  using mozilla::dom::Element::GetText;
38
39
  bool Selected() const
40
0
  {
41
0
    return mIsSelected;
42
0
  }
43
  void SetSelected(bool aValue);
44
45
46
  void SetSelectedChanged(bool aValue)
47
0
  {
48
0
    mSelectedChanged = aValue;
49
0
  }
50
51
  virtual nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute,
52
                                              int32_t aModType) const override;
53
54
  virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
55
                                 const nsAttrValueOrString* aValue,
56
                                 bool aNotify) override;
57
  virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
58
                                const nsAttrValue* aValue,
59
                                const nsAttrValue* aOldValue,
60
                                nsIPrincipal* aSubjectPrincipal,
61
                                bool aNotify) override;
62
63
  void SetSelectedInternal(bool aValue, bool aNotify);
64
65
  /**
66
   * This callback is called by an optgroup on all its option elements whenever
67
   * its disabled state is changed so that option elements can know their
68
   * disabled state might have changed.
69
   */
70
  void OptGroupDisabledChanged(bool aNotify);
71
72
  /**
73
   * Check our disabled content attribute and optgroup's (if it exists) disabled
74
   * state to decide whether our disabled flag should be toggled.
75
   */
76
  void UpdateDisabledState(bool aNotify);
77
78
  virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
79
                              nsIContent* aBindingParent) override;
80
  virtual void UnbindFromTree(bool aDeep = true,
81
                              bool aNullParent = true) override;
82
83
  // nsIContent
84
  virtual EventStates IntrinsicState() const override;
85
86
  virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
87
88
  nsresult CopyInnerTo(mozilla::dom::Element* aDest);
89
90
  bool Disabled() const
91
0
  {
92
0
    return GetBoolAttr(nsGkAtoms::disabled);
93
0
  }
94
95
  void SetDisabled(bool aValue, ErrorResult& aRv)
96
0
  {
97
0
    SetHTMLBoolAttr(nsGkAtoms::disabled, aValue, aRv);
98
0
  }
99
100
  HTMLFormElement* GetForm();
101
102
  void GetLabel(DOMString& aLabel)
103
0
  {
104
0
    if (!GetAttr(kNameSpaceID_None, nsGkAtoms::label, aLabel)) {
105
0
      GetText(aLabel);
106
0
    }
107
0
  }
108
  void SetLabel(const nsAString& aLabel, ErrorResult& aError)
109
0
  {
110
0
    SetHTMLAttr(nsGkAtoms::label, aLabel, aError);
111
0
  }
112
113
  bool DefaultSelected() const
114
0
  {
115
0
    return HasAttr(kNameSpaceID_None, nsGkAtoms::selected);
116
0
  }
117
  void SetDefaultSelected(bool aValue, ErrorResult& aRv)
118
0
  {
119
0
    SetHTMLBoolAttr(nsGkAtoms::selected, aValue, aRv);
120
0
  }
121
122
  void GetValue(nsAString& aValue)
123
0
  {
124
0
    if (!GetAttr(kNameSpaceID_None, nsGkAtoms::value, aValue)) {
125
0
      GetText(aValue);
126
0
    }
127
0
  }
128
  void SetValue(const nsAString& aValue, ErrorResult& aRv)
129
0
  {
130
0
    SetHTMLAttr(nsGkAtoms::value, aValue, aRv);
131
0
  }
132
133
  void GetText(nsAString& aText);
134
  void SetText(const nsAString& aText, ErrorResult& aRv);
135
136
  int32_t Index();
137
138
protected:
139
  virtual ~HTMLOptionElement();
140
141
  virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
142
143
  /**
144
   * Get the select content element that contains this option, this
145
   * intentionally does not return nsresult, all we care about is if
146
   * there's a select associated with this option or not.
147
   */
148
  HTMLSelectElement* GetSelect();
149
150
  bool mSelectedChanged;
151
  bool mIsSelected;
152
153
  // True only while we're under the SetOptionsSelectedByIndex call when our
154
  // "selected" attribute is changing and mSelectedChanged is false.
155
  bool mIsInSetDefaultSelected;
156
};
157
158
} // namespace dom
159
} // namespace mozilla
160
161
#endif // mozilla_dom_HTMLOptionElement_h__