Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/HTMLTableElement.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
#ifndef mozilla_dom_HTMLTableElement_h
7
#define mozilla_dom_HTMLTableElement_h
8
9
#include "mozilla/Attributes.h"
10
#include "nsGenericHTMLElement.h"
11
#include "mozilla/dom/HTMLTableCaptionElement.h"
12
#include "mozilla/dom/HTMLTableSectionElement.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
class TableRowsCollection;
18
19
class HTMLTableElement final : public nsGenericHTMLElement
20
{
21
public:
22
  explicit HTMLTableElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
23
24
  NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLTableElement, table)
25
26
  // nsISupports
27
  NS_DECL_ISUPPORTS_INHERITED
28
29
  HTMLTableCaptionElement* GetCaption() const
30
0
  {
31
0
    return static_cast<HTMLTableCaptionElement*>(GetChild(nsGkAtoms::caption));
32
0
  }
33
  void SetCaption(HTMLTableCaptionElement* aCaption, ErrorResult& aError)
34
0
  {
35
0
    DeleteCaption();
36
0
    if (aCaption) {
37
0
      nsCOMPtr<nsINode> firstChild = nsINode::GetFirstChild();
38
0
      nsINode::InsertBefore(*aCaption, firstChild, aError);
39
0
    }
40
0
  }
41
42
  void DeleteTFoot();
43
44
  already_AddRefed<nsGenericHTMLElement> CreateCaption();
45
46
  void DeleteCaption();
47
48
  HTMLTableSectionElement* GetTHead() const
49
0
  {
50
0
    return static_cast<HTMLTableSectionElement*>(GetChild(nsGkAtoms::thead));
51
0
  }
52
  void SetTHead(HTMLTableSectionElement* aTHead, ErrorResult& aError)
53
0
  {
54
0
    if (aTHead && !aTHead->IsHTMLElement(nsGkAtoms::thead)) {
55
0
      aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
56
0
      return;
57
0
    }
58
0
59
0
    DeleteTHead();
60
0
    if (aTHead) {
61
0
62
0
      nsCOMPtr<nsIContent> refNode = nullptr;
63
0
      for (refNode = nsINode::GetFirstChild();
64
0
           refNode;
65
0
           refNode = refNode->GetNextSibling()) {
66
0
        if (refNode->IsHTMLElement() &&
67
0
            !refNode->IsHTMLElement(nsGkAtoms::caption) &&
68
0
            !refNode->IsHTMLElement(nsGkAtoms::colgroup)) {
69
0
          break;
70
0
        }
71
0
      }
72
0
73
0
      nsINode::InsertBefore(*aTHead, refNode, aError);
74
0
    }
75
0
  }
76
  already_AddRefed<nsGenericHTMLElement> CreateTHead();
77
78
  void DeleteTHead();
79
80
  HTMLTableSectionElement* GetTFoot() const
81
0
  {
82
0
    return static_cast<HTMLTableSectionElement*>(GetChild(nsGkAtoms::tfoot));
83
0
  }
84
  void SetTFoot(HTMLTableSectionElement* aTFoot, ErrorResult& aError)
85
0
  {
86
0
    if (aTFoot && !aTFoot->IsHTMLElement(nsGkAtoms::tfoot)) {
87
0
      aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
88
0
      return;
89
0
    }
90
0
91
0
    DeleteTFoot();
92
0
    if (aTFoot) {
93
0
      nsINode::AppendChild(*aTFoot, aError);
94
0
    }
95
0
  }
96
  already_AddRefed<nsGenericHTMLElement> CreateTFoot();
97
98
  nsIHTMLCollection* TBodies();
99
100
  already_AddRefed<nsGenericHTMLElement> CreateTBody();
101
102
  nsIHTMLCollection* Rows();
103
104
  already_AddRefed<nsGenericHTMLElement> InsertRow(int32_t aIndex,
105
                                                   ErrorResult& aError);
106
  void DeleteRow(int32_t aIndex, ErrorResult& aError);
107
108
  void GetAlign(DOMString& aAlign)
109
0
  {
110
0
    GetHTMLAttr(nsGkAtoms::align, aAlign);
111
0
  }
112
  void SetAlign(const nsAString& aAlign, ErrorResult& aError)
113
0
  {
114
0
    SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
115
0
  }
116
  void GetBorder(DOMString& aBorder)
117
0
  {
118
0
    GetHTMLAttr(nsGkAtoms::border, aBorder);
119
0
  }
120
  void SetBorder(const nsAString& aBorder, ErrorResult& aError)
121
0
  {
122
0
    SetHTMLAttr(nsGkAtoms::border, aBorder, aError);
123
0
  }
124
  void GetFrame(DOMString& aFrame)
125
0
  {
126
0
    GetHTMLAttr(nsGkAtoms::frame, aFrame);
127
0
  }
128
  void SetFrame(const nsAString& aFrame, ErrorResult& aError)
129
0
  {
130
0
    SetHTMLAttr(nsGkAtoms::frame, aFrame, aError);
131
0
  }
132
  void GetRules(DOMString& aRules)
133
0
  {
134
0
    GetHTMLAttr(nsGkAtoms::rules, aRules);
135
0
  }
136
  void SetRules(const nsAString& aRules, ErrorResult& aError)
137
0
  {
138
0
    SetHTMLAttr(nsGkAtoms::rules, aRules, aError);
139
0
  }
140
  void GetSummary(nsString& aSummary)
141
0
  {
142
0
    GetHTMLAttr(nsGkAtoms::summary, aSummary);
143
0
  }
144
  void GetSummary(DOMString& aSummary)
145
0
  {
146
0
    GetHTMLAttr(nsGkAtoms::summary, aSummary);
147
0
  }
148
  void SetSummary(const nsAString& aSummary, ErrorResult& aError)
149
0
  {
150
0
    SetHTMLAttr(nsGkAtoms::summary, aSummary, aError);
151
0
  }
152
  void GetWidth(DOMString& aWidth)
153
0
  {
154
0
    GetHTMLAttr(nsGkAtoms::width, aWidth);
155
0
  }
156
  void SetWidth(const nsAString& aWidth, ErrorResult& aError)
157
0
  {
158
0
    SetHTMLAttr(nsGkAtoms::width, aWidth, aError);
159
0
  }
160
  void GetBgColor(DOMString& aBgColor)
161
0
  {
162
0
    GetHTMLAttr(nsGkAtoms::bgcolor, aBgColor);
163
0
  }
164
  void SetBgColor(const nsAString& aBgColor, ErrorResult& aError)
165
0
  {
166
0
    SetHTMLAttr(nsGkAtoms::bgcolor, aBgColor, aError);
167
0
  }
168
  void GetCellPadding(DOMString& aCellPadding)
169
0
  {
170
0
    GetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding);
171
0
  }
172
  void SetCellPadding(const nsAString& aCellPadding, ErrorResult& aError)
173
0
  {
174
0
    SetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding, aError);
175
0
  }
176
  void GetCellSpacing(DOMString& aCellSpacing)
177
0
  {
178
0
    GetHTMLAttr(nsGkAtoms::cellspacing, aCellSpacing);
179
0
  }
180
  void SetCellSpacing(const nsAString& aCellSpacing, ErrorResult& aError)
181
0
  {
182
0
    SetHTMLAttr(nsGkAtoms::cellspacing, aCellSpacing, aError);
183
0
  }
184
185
  virtual bool ParseAttribute(int32_t aNamespaceID,
186
                                nsAtom* aAttribute,
187
                                const nsAString& aValue,
188
                                nsIPrincipal* aMaybeScriptedPrincipal,
189
                                nsAttrValue& aResult) override;
190
  virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
191
  NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
192
193
  virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
194
195
  virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
196
                              nsIContent* aBindingParent) override;
197
  virtual void UnbindFromTree(bool aDeep = true,
198
                              bool aNullParent = true) override;
199
  /**
200
   * Called when an attribute is about to be changed
201
   */
202
  virtual nsresult BeforeSetAttr(int32_t aNameSpaceID, nsAtom* aName,
203
                                 const nsAttrValueOrString* aValue,
204
                                 bool aNotify) override;
205
  /**
206
   * Called when an attribute has just been changed
207
   */
208
  virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
209
                                const nsAttrValue* aValue,
210
                                const nsAttrValue* aOldValue,
211
                                nsIPrincipal* aSubjectPrincipal,
212
                                bool aNotify) override;
213
214
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTableElement,
215
                                           nsGenericHTMLElement)
216
  nsMappedAttributes* GetAttributesMappedForCell();
217
218
protected:
219
  virtual ~HTMLTableElement();
220
221
  virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
222
223
  nsIContent* GetChild(nsAtom *aTag) const
224
0
  {
225
0
    for (nsIContent* cur = nsINode::GetFirstChild(); cur;
226
0
         cur = cur->GetNextSibling()) {
227
0
      if (cur->IsHTMLElement(aTag)) {
228
0
        return cur;
229
0
      }
230
0
    }
231
0
    return nullptr;
232
0
  }
233
234
  RefPtr<nsContentList> mTBodies;
235
  RefPtr<TableRowsCollection> mRows;
236
  nsMappedAttributes *mTableInheritedAttributes;
237
  void BuildInheritedAttributes();
238
  void ReleaseInheritedAttributes();
239
240
private:
241
  static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
242
                                    MappedDeclarations&);
243
};
244
245
} // namespace dom
246
} // namespace mozilla
247
248
#endif /* mozilla_dom_HTMLTableElement_h */