/src/mozilla-central/dom/html/HTMLTableSectionElement.cpp
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 | | #include "mozilla/dom/HTMLTableSectionElement.h" |
8 | | #include "mozilla/MappedDeclarations.h" |
9 | | #include "nsMappedAttributes.h" |
10 | | #include "nsAttrValueInlines.h" |
11 | | #include "mozilla/dom/BindingUtils.h" |
12 | | #include "mozilla/dom/HTMLTableSectionElementBinding.h" |
13 | | #include "nsContentUtils.h" |
14 | | |
15 | | NS_IMPL_NS_NEW_HTML_ELEMENT(TableSection) |
16 | | |
17 | | namespace mozilla { |
18 | | namespace dom { |
19 | | |
20 | | // you will see the phrases "rowgroup" and "section" used interchangably |
21 | | |
22 | | HTMLTableSectionElement::~HTMLTableSectionElement() |
23 | 0 | { |
24 | 0 | } |
25 | | |
26 | | JSObject* |
27 | | HTMLTableSectionElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) |
28 | 0 | { |
29 | 0 | return HTMLTableSectionElement_Binding::Wrap(aCx, this, aGivenProto); |
30 | 0 | } |
31 | | |
32 | | NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTableSectionElement) |
33 | | |
34 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTableSectionElement, |
35 | 0 | nsGenericHTMLElement) |
36 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRows) |
37 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
38 | | |
39 | | NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLTableSectionElement, |
40 | | nsGenericHTMLElement) |
41 | | |
42 | | NS_IMPL_ELEMENT_CLONE(HTMLTableSectionElement) |
43 | | |
44 | | nsIHTMLCollection* |
45 | | HTMLTableSectionElement::Rows() |
46 | 0 | { |
47 | 0 | if (!mRows) { |
48 | 0 | mRows = new nsContentList(this, |
49 | 0 | mNodeInfo->NamespaceID(), |
50 | 0 | nsGkAtoms::tr, |
51 | 0 | nsGkAtoms::tr, |
52 | 0 | false); |
53 | 0 | } |
54 | 0 |
|
55 | 0 | return mRows; |
56 | 0 | } |
57 | | |
58 | | already_AddRefed<nsGenericHTMLElement> |
59 | | HTMLTableSectionElement::InsertRow(int32_t aIndex, ErrorResult& aError) |
60 | 0 | { |
61 | 0 | if (aIndex < -1) { |
62 | 0 | aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); |
63 | 0 | return nullptr; |
64 | 0 | } |
65 | 0 | |
66 | 0 | nsIHTMLCollection* rows = Rows(); |
67 | 0 |
|
68 | 0 | uint32_t rowCount = rows->Length(); |
69 | 0 | if (aIndex > (int32_t)rowCount) { |
70 | 0 | aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); |
71 | 0 | return nullptr; |
72 | 0 | } |
73 | 0 | |
74 | 0 | bool doInsert = (aIndex < int32_t(rowCount)) && (aIndex != -1); |
75 | 0 |
|
76 | 0 | // create the row |
77 | 0 | RefPtr<mozilla::dom::NodeInfo> nodeInfo; |
78 | 0 | nsContentUtils::QNameChanged(mNodeInfo, nsGkAtoms::tr, |
79 | 0 | getter_AddRefs(nodeInfo)); |
80 | 0 |
|
81 | 0 | RefPtr<nsGenericHTMLElement> rowContent = |
82 | 0 | NS_NewHTMLTableRowElement(nodeInfo.forget()); |
83 | 0 | if (!rowContent) { |
84 | 0 | aError.Throw(NS_ERROR_OUT_OF_MEMORY); |
85 | 0 | return nullptr; |
86 | 0 | } |
87 | 0 | |
88 | 0 | if (doInsert) { |
89 | 0 | nsCOMPtr<nsINode> refNode = rows->Item(aIndex); |
90 | 0 | nsINode::InsertBefore(*rowContent, refNode, aError); |
91 | 0 | } else { |
92 | 0 | nsINode::AppendChild(*rowContent, aError); |
93 | 0 | } |
94 | 0 | return rowContent.forget(); |
95 | 0 | } |
96 | | |
97 | | void |
98 | | HTMLTableSectionElement::DeleteRow(int32_t aValue, ErrorResult& aError) |
99 | 0 | { |
100 | 0 | if (aValue < -1) { |
101 | 0 | aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); |
102 | 0 | return; |
103 | 0 | } |
104 | 0 | |
105 | 0 | nsIHTMLCollection* rows = Rows(); |
106 | 0 |
|
107 | 0 | uint32_t refIndex; |
108 | 0 | if (aValue == -1) { |
109 | 0 | refIndex = rows->Length(); |
110 | 0 | if (refIndex == 0) { |
111 | 0 | return; |
112 | 0 | } |
113 | 0 | |
114 | 0 | --refIndex; |
115 | 0 | } |
116 | 0 | else { |
117 | 0 | refIndex = (uint32_t)aValue; |
118 | 0 | } |
119 | 0 |
|
120 | 0 | nsINode* row = rows->Item(refIndex); |
121 | 0 | if (!row) { |
122 | 0 | aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); |
123 | 0 | return; |
124 | 0 | } |
125 | 0 | |
126 | 0 | nsINode::RemoveChild(*row, aError); |
127 | 0 | } |
128 | | |
129 | | bool |
130 | | HTMLTableSectionElement::ParseAttribute(int32_t aNamespaceID, |
131 | | nsAtom* aAttribute, |
132 | | const nsAString& aValue, |
133 | | nsIPrincipal* aMaybeScriptedPrincipal, |
134 | | nsAttrValue& aResult) |
135 | 0 | { |
136 | 0 | if (aNamespaceID == kNameSpaceID_None) { |
137 | 0 | /* ignore these attributes, stored simply as strings |
138 | 0 | ch |
139 | 0 | */ |
140 | 0 | if (aAttribute == nsGkAtoms::charoff) { |
141 | 0 | return aResult.ParseIntWithBounds(aValue, 0); |
142 | 0 | } |
143 | 0 | if (aAttribute == nsGkAtoms::height) { |
144 | 0 | return aResult.ParseSpecialIntValue(aValue); |
145 | 0 | } |
146 | 0 | if (aAttribute == nsGkAtoms::align) { |
147 | 0 | return ParseTableCellHAlignValue(aValue, aResult); |
148 | 0 | } |
149 | 0 | if (aAttribute == nsGkAtoms::bgcolor) { |
150 | 0 | return aResult.ParseColor(aValue); |
151 | 0 | } |
152 | 0 | if (aAttribute == nsGkAtoms::valign) { |
153 | 0 | return ParseTableVAlignValue(aValue, aResult); |
154 | 0 | } |
155 | 0 | } |
156 | 0 | |
157 | 0 | return nsGenericHTMLElement::ParseBackgroundAttribute(aNamespaceID, |
158 | 0 | aAttribute, aValue, |
159 | 0 | aResult) || |
160 | 0 | nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue, |
161 | 0 | aMaybeScriptedPrincipal, aResult); |
162 | 0 | } |
163 | | |
164 | | void |
165 | | HTMLTableSectionElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes, |
166 | | MappedDeclarations& aDecls) |
167 | 0 | { |
168 | 0 | // height: value |
169 | 0 | if (!aDecls.PropertyIsSet(eCSSProperty_height)) { |
170 | 0 | const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::height); |
171 | 0 | if (value && value->Type() == nsAttrValue::eInteger) |
172 | 0 | aDecls.SetPixelValue(eCSSProperty_height, (float)value->GetIntegerValue()); |
173 | 0 | } |
174 | 0 | nsGenericHTMLElement::MapDivAlignAttributeInto(aAttributes, aDecls); |
175 | 0 | nsGenericHTMLElement::MapVAlignAttributeInto(aAttributes, aDecls); |
176 | 0 | nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aDecls); |
177 | 0 | nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls); |
178 | 0 | } |
179 | | |
180 | | NS_IMETHODIMP_(bool) |
181 | | HTMLTableSectionElement::IsAttributeMapped(const nsAtom* aAttribute) const |
182 | 0 | { |
183 | 0 | static const MappedAttributeEntry attributes[] = { |
184 | 0 | { &nsGkAtoms::align }, |
185 | 0 | { &nsGkAtoms::valign }, |
186 | 0 | { &nsGkAtoms::height }, |
187 | 0 | { nullptr } |
188 | 0 | }; |
189 | 0 |
|
190 | 0 | static const MappedAttributeEntry* const map[] = { |
191 | 0 | attributes, |
192 | 0 | sCommonAttributeMap, |
193 | 0 | sBackgroundAttributeMap, |
194 | 0 | }; |
195 | 0 |
|
196 | 0 | return FindAttributeDependence(aAttribute, map); |
197 | 0 | } |
198 | | |
199 | | |
200 | | nsMapRuleToAttributesFunc |
201 | | HTMLTableSectionElement::GetAttributeMappingFunction() const |
202 | 0 | { |
203 | 0 | return &MapAttributesIntoRule; |
204 | 0 | } |
205 | | |
206 | | } // namespace dom |
207 | | } // namespace mozilla |