Bug 1880216 - Migrate Fenix docs into Sphinx. r=owlish,geckoview-reviewers,android...
[gecko.git] / dom / html / HTMLTableElement.h
blob9c9d59084c3190c1adf119989bda54c481ffdec5
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
9 #include "mozilla/Attributes.h"
10 #include "nsGenericHTMLElement.h"
11 #include "mozilla/dom/HTMLTableCaptionElement.h"
12 #include "mozilla/dom/HTMLTableSectionElement.h"
14 namespace mozilla::dom {
16 class TableRowsCollection;
18 class HTMLTableElement final : public nsGenericHTMLElement {
19 public:
20 explicit HTMLTableElement(
21 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
23 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLTableElement, table)
25 // nsISupports
26 NS_DECL_ISUPPORTS_INHERITED
28 HTMLTableCaptionElement* GetCaption() const {
29 return static_cast<HTMLTableCaptionElement*>(GetChild(nsGkAtoms::caption));
31 void SetCaption(HTMLTableCaptionElement* aCaption, ErrorResult& aError) {
32 DeleteCaption();
33 if (aCaption) {
34 nsCOMPtr<nsINode> firstChild = nsINode::GetFirstChild();
35 nsINode::InsertBefore(*aCaption, firstChild, aError);
39 void DeleteTFoot();
41 already_AddRefed<nsGenericHTMLElement> CreateCaption();
43 void DeleteCaption();
45 HTMLTableSectionElement* GetTHead() const {
46 return static_cast<HTMLTableSectionElement*>(GetChild(nsGkAtoms::thead));
48 void SetTHead(HTMLTableSectionElement* aTHead, ErrorResult& aError) {
49 if (aTHead && !aTHead->IsHTMLElement(nsGkAtoms::thead)) {
50 aError.ThrowHierarchyRequestError("New value must be a thead element.");
51 return;
54 DeleteTHead();
55 if (aTHead) {
56 nsCOMPtr<nsIContent> refNode = nullptr;
57 for (refNode = nsINode::GetFirstChild(); refNode;
58 refNode = refNode->GetNextSibling()) {
59 if (refNode->IsHTMLElement() &&
60 !refNode->IsHTMLElement(nsGkAtoms::caption) &&
61 !refNode->IsHTMLElement(nsGkAtoms::colgroup)) {
62 break;
66 nsINode::InsertBefore(*aTHead, refNode, aError);
69 already_AddRefed<nsGenericHTMLElement> CreateTHead();
71 void DeleteTHead();
73 HTMLTableSectionElement* GetTFoot() const {
74 return static_cast<HTMLTableSectionElement*>(GetChild(nsGkAtoms::tfoot));
76 void SetTFoot(HTMLTableSectionElement* aTFoot, ErrorResult& aError) {
77 if (aTFoot && !aTFoot->IsHTMLElement(nsGkAtoms::tfoot)) {
78 aError.ThrowHierarchyRequestError("New value must be a tfoot element.");
79 return;
82 DeleteTFoot();
83 if (aTFoot) {
84 nsINode::AppendChild(*aTFoot, aError);
87 already_AddRefed<nsGenericHTMLElement> CreateTFoot();
89 nsIHTMLCollection* TBodies();
91 already_AddRefed<nsGenericHTMLElement> CreateTBody();
93 nsIHTMLCollection* Rows();
95 already_AddRefed<nsGenericHTMLElement> InsertRow(int32_t aIndex,
96 ErrorResult& aError);
97 void DeleteRow(int32_t aIndex, ErrorResult& aError);
99 void GetAlign(DOMString& aAlign) { GetHTMLAttr(nsGkAtoms::align, aAlign); }
100 void SetAlign(const nsAString& aAlign, ErrorResult& aError) {
101 SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
103 void GetBorder(DOMString& aBorder) {
104 GetHTMLAttr(nsGkAtoms::border, aBorder);
106 void SetBorder(const nsAString& aBorder, ErrorResult& aError) {
107 SetHTMLAttr(nsGkAtoms::border, aBorder, aError);
109 void GetFrame(DOMString& aFrame) { GetHTMLAttr(nsGkAtoms::frame, aFrame); }
110 void SetFrame(const nsAString& aFrame, ErrorResult& aError) {
111 SetHTMLAttr(nsGkAtoms::frame, aFrame, aError);
113 void GetRules(DOMString& aRules) { GetHTMLAttr(nsGkAtoms::rules, aRules); }
114 void SetRules(const nsAString& aRules, ErrorResult& aError) {
115 SetHTMLAttr(nsGkAtoms::rules, aRules, aError);
117 void GetSummary(nsString& aSummary) {
118 GetHTMLAttr(nsGkAtoms::summary, aSummary);
120 void GetSummary(DOMString& aSummary) {
121 GetHTMLAttr(nsGkAtoms::summary, aSummary);
123 void SetSummary(const nsAString& aSummary, ErrorResult& aError) {
124 SetHTMLAttr(nsGkAtoms::summary, aSummary, aError);
126 void GetWidth(DOMString& aWidth) { GetHTMLAttr(nsGkAtoms::width, aWidth); }
127 void SetWidth(const nsAString& aWidth, ErrorResult& aError) {
128 SetHTMLAttr(nsGkAtoms::width, aWidth, aError);
130 void GetBgColor(DOMString& aBgColor) {
131 GetHTMLAttr(nsGkAtoms::bgcolor, aBgColor);
133 void SetBgColor(const nsAString& aBgColor, ErrorResult& aError) {
134 SetHTMLAttr(nsGkAtoms::bgcolor, aBgColor, aError);
136 void GetCellPadding(DOMString& aCellPadding) {
137 GetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding);
139 void SetCellPadding(const nsAString& aCellPadding, ErrorResult& aError) {
140 SetHTMLAttr(nsGkAtoms::cellpadding, aCellPadding, aError);
142 void GetCellSpacing(DOMString& aCellSpacing) {
143 GetHTMLAttr(nsGkAtoms::cellspacing, aCellSpacing);
145 void SetCellSpacing(const nsAString& aCellSpacing, ErrorResult& aError) {
146 SetHTMLAttr(nsGkAtoms::cellspacing, aCellSpacing, aError);
149 bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
150 const nsAString& aValue,
151 nsIPrincipal* aMaybeScriptedPrincipal,
152 nsAttrValue& aResult) override;
153 nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
154 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
156 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
158 nsresult BindToTree(BindContext&, nsINode& aParent) override;
159 void UnbindFromTree(UnbindContext&) override;
161 * Called when an attribute is about to be changed
163 void BeforeSetAttr(int32_t aNameSpaceID, nsAtom* aName,
164 const nsAttrValue* aValue, bool aNotify) override;
166 * Called when an attribute has just been changed
168 void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
169 const nsAttrValue* aValue, const nsAttrValue* aOldValue,
170 nsIPrincipal* aSubjectPrincipal, bool aNotify) override;
172 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTableElement,
173 nsGenericHTMLElement)
174 StyleLockedDeclarationBlock* GetAttributesMappedForCell() const {
175 return mTableInheritedAttributes;
178 protected:
179 virtual ~HTMLTableElement();
181 JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
183 nsIContent* GetChild(nsAtom* aTag) const {
184 for (nsIContent* cur = nsINode::GetFirstChild(); cur;
185 cur = cur->GetNextSibling()) {
186 if (cur->IsHTMLElement(aTag)) {
187 return cur;
190 return nullptr;
193 RefPtr<nsContentList> mTBodies;
194 RefPtr<TableRowsCollection> mRows;
195 RefPtr<StyleLockedDeclarationBlock> mTableInheritedAttributes;
196 void BuildInheritedAttributes();
197 void ReleaseInheritedAttributes();
199 private:
200 static void MapAttributesIntoRule(MappedDeclarationsBuilder&);
203 } // namespace mozilla::dom
205 #endif /* mozilla_dom_HTMLTableElement_h */