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 : #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 0 : NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLTableElement, table)
25 :
26 : // nsISupports
27 : NS_DECL_ISUPPORTS_INHERITED
28 :
29 0 : HTMLTableCaptionElement* GetCaption() const
30 : {
31 0 : return static_cast<HTMLTableCaptionElement*>(GetChild(nsGkAtoms::caption));
32 : }
33 0 : void SetCaption(HTMLTableCaptionElement* aCaption, ErrorResult& aError)
34 : {
35 0 : DeleteCaption();
36 0 : if (aCaption) {
37 0 : nsCOMPtr<nsINode> firstChild = nsINode::GetFirstChild();
38 0 : nsINode::InsertBefore(*aCaption, firstChild, aError);
39 : }
40 0 : }
41 :
42 : void DeleteTFoot();
43 :
44 : already_AddRefed<nsGenericHTMLElement> CreateCaption();
45 :
46 : void DeleteCaption();
47 :
48 0 : HTMLTableSectionElement* GetTHead() const
49 : {
50 0 : return static_cast<HTMLTableSectionElement*>(GetChild(nsGkAtoms::thead));
51 : }
52 0 : void SetTHead(HTMLTableSectionElement* aTHead, ErrorResult& aError)
53 : {
54 0 : if (aTHead && !aTHead->IsHTMLElement(nsGkAtoms::thead)) {
55 0 : aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
56 0 : return;
57 : }
58 :
59 0 : DeleteTHead();
60 0 : if (aTHead) {
61 :
62 0 : nsCOMPtr<nsIContent> refNode = nullptr;
63 0 : for (refNode = nsINode::GetFirstChild();
64 : 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 : }
71 : }
72 :
73 0 : nsINode::InsertBefore(*aTHead, refNode, aError);
74 : }
75 : }
76 : already_AddRefed<nsGenericHTMLElement> CreateTHead();
77 :
78 : void DeleteTHead();
79 :
80 0 : HTMLTableSectionElement* GetTFoot() const
81 : {
82 0 : return static_cast<HTMLTableSectionElement*>(GetChild(nsGkAtoms::tfoot));
83 : }
84 0 : void SetTFoot(HTMLTableSectionElement* aTFoot, ErrorResult& aError)
85 : {
86 0 : if (aTFoot && !aTFoot->IsHTMLElement(nsGkAtoms::tfoot)) {
87 0 : aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
88 0 : return;
89 : }
90 :
91 0 : DeleteTFoot();
92 0 : if (aTFoot) {
93 0 : nsINode::AppendChild(*aTFoot, aError);
94 : }
95 : }
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 0 : void GetAlign(DOMString& aAlign)
109 : {
110 0 : GetHTMLAttr(nsGkAtoms::align, aAlign);
111 0 : }
112 0 : void SetAlign(const nsAString& aAlign, ErrorResult& aError)
113 : {
114 0 : SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
115 0 : }
116 0 : void GetBorder(DOMString& aBorder)
117 : {
118 0 : GetHTMLAttr(nsGkAtoms::border, aBorder);
119 0 : }
120 0 : void SetBorder(const nsAString& aBorder, ErrorResult& aError)
121 : {
122 0 : SetHTMLAttr(nsGkAtoms::border, aBorder, aError);
123 0 : }
124 0 : void GetFrame(DOMString& aFrame)
125 : {
126 0 : GetHTMLAttr(nsGkAtoms::frame, aFrame);
127 0 : }
128 0 : void SetFrame(const nsAString& aFrame, ErrorResult& aError)
129 : {
130 0 : SetHTMLAttr(nsGkAtoms::frame, aFrame, aError);
131 0 : }
132 0 : void GetRules(DOMString& aRules)
133 : {
134 0 : GetHTMLAttr(nsGkAtoms::rules, aRules);
135 0 : }
136 0 : void SetRules(const nsAString& aRules, ErrorResult& aError)
137 : {
138 0 : SetHTMLAttr(nsGkAtoms::rules, aRules, aError);
139 0 : }
140 0 : void GetSummary(nsString& aSummary)
141 : {
142 0 : GetHTMLAttr(nsGkAtoms::summary, aSummary);
143 0 : }
144 0 : void GetSummary(DOMString& aSummary)
145 : {
146 0 : GetHTMLAttr(nsGkAtoms::summary, aSummary);
147 0 : }
148 0 : void SetSummary(const nsAString& aSummary, ErrorResult& aError)
149 : {
150 0 : SetHTMLAttr(nsGkAtoms::summary, aSummary, aError);
151 0 : }
152 0 : void GetWidth(DOMString& aWidth)
153 : {
154 0 : GetHTMLAttr(nsGkAtoms::width, aWidth);
155 0 : }
156 0 : void SetWidth(const nsAString& aWidth, ErrorResult& aError)
157 : {
158 0 : SetHTMLAttr(nsGkAtoms::width, aWidth, aError);
159 0 : }
160 0 : void GetBgColor(DOMString& aBgColor)
161 : {
162 0 : GetHTMLAttr(nsGkAtoms::bgcolor, aBgColor);
163 0 : }
164 0 : void SetBgColor(const nsAString& aBgColor, ErrorResult& aError)
165 : {
166 0 : SetHTMLAttr(nsGkAtoms::bgcolor, aBgColor, aError);
167 0 : }
168 0 : void GetCellPadding(DOMString& aCellPadding)
169 : {
170 0 : GetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding);
171 0 : }
172 0 : void SetCellPadding(const nsAString& aCellPadding, ErrorResult& aError)
173 : {
174 0 : SetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding, aError);
175 0 : }
176 0 : void GetCellSpacing(DOMString& aCellSpacing)
177 : {
178 0 : GetHTMLAttr(nsGkAtoms::cellspacing, aCellSpacing);
179 0 : }
180 0 : void SetCellSpacing(const nsAString& aCellSpacing, ErrorResult& aError)
181 : {
182 0 : SetHTMLAttr(nsGkAtoms::cellspacing, aCellSpacing, aError);
183 0 : }
184 :
185 : virtual bool ParseAttribute(int32_t aNamespaceID,
186 : nsIAtom* aAttribute,
187 : const nsAString& aValue,
188 : nsAttrValue& aResult) override;
189 : virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
190 : NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const override;
191 :
192 : virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
193 : bool aPreallocateChildren) const override;
194 :
195 : virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
196 : nsIContent* aBindingParent,
197 : bool aCompileEventHandlers) override;
198 : virtual void UnbindFromTree(bool aDeep = true,
199 : bool aNullParent = true) override;
200 : /**
201 : * Called when an attribute is about to be changed
202 : */
203 : virtual nsresult BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
204 : const nsAttrValueOrString* aValue,
205 : bool aNotify) override;
206 : /**
207 : * Called when an attribute has just been changed
208 : */
209 : virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
210 : const nsAttrValue* aValue,
211 : const nsAttrValue* aOldValue,
212 : bool aNotify) override;
213 :
214 0 : 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 0 : nsIContent* GetChild(nsIAtom *aTag) const
224 : {
225 0 : for (nsIContent* cur = nsINode::GetFirstChild(); cur;
226 0 : cur = cur->GetNextSibling()) {
227 0 : if (cur->IsHTMLElement(aTag)) {
228 0 : return cur;
229 : }
230 : }
231 0 : return nullptr;
232 : }
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 : GenericSpecifiedValues* aGenericData);
243 : };
244 :
245 : } // namespace dom
246 : } // namespace mozilla
247 :
248 : #endif /* mozilla_dom_HTMLTableElement_h */
|