1 : /*
2 : * Copyright (c) 2007 Henri Sivonen
3 : * Copyright (c) 2008-2011 Mozilla Foundation
4 : *
5 : * Permission is hereby granted, free of charge, to any person obtaining a
6 : * copy of this software and associated documentation files (the "Software"),
7 : * to deal in the Software without restriction, including without limitation
8 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 : * and/or sell copies of the Software, and to permit persons to whom the
10 : * Software is furnished to do so, subject to the following conditions:
11 : *
12 : * The above copyright notice and this permission notice shall be included in
13 : * all copies or substantial portions of the Software.
14 : *
15 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 : * DEALINGS IN THE SOFTWARE.
22 : */
23 :
24 : /*
25 : * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
26 : * Please edit HtmlAttributes.java instead and regenerate.
27 : */
28 :
29 : #define nsHtml5HtmlAttributes_cpp__
30 :
31 : #include "prtypes.h"
32 : #include "nsIAtom.h"
33 : #include "nsHtml5AtomTable.h"
34 : #include "nsString.h"
35 : #include "nsINameSpaceManager.h"
36 : #include "nsIContent.h"
37 : #include "nsTraceRefcnt.h"
38 : #include "jArray.h"
39 : #include "nsHtml5ArrayCopy.h"
40 : #include "nsAHtml5TreeBuilderState.h"
41 : #include "nsHtml5Atoms.h"
42 : #include "nsHtml5ByteReadable.h"
43 : #include "nsIUnicodeDecoder.h"
44 : #include "nsHtml5Macros.h"
45 :
46 : #include "nsHtml5Tokenizer.h"
47 : #include "nsHtml5TreeBuilder.h"
48 : #include "nsHtml5MetaScanner.h"
49 : #include "nsHtml5AttributeName.h"
50 : #include "nsHtml5ElementName.h"
51 : #include "nsHtml5StackNode.h"
52 : #include "nsHtml5UTF16Buffer.h"
53 : #include "nsHtml5StateSnapshot.h"
54 : #include "nsHtml5Portability.h"
55 :
56 : #include "nsHtml5HtmlAttributes.h"
57 :
58 : nsHtml5HtmlAttributes* nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES = nsnull;
59 :
60 1404 : nsHtml5HtmlAttributes::nsHtml5HtmlAttributes(PRInt32 mode)
61 : : mode(mode),
62 : length(0),
63 : names(jArray<nsHtml5AttributeName*,PRInt32>::newJArray(5)),
64 1404 : values(jArray<nsString*,PRInt32>::newJArray(5))
65 : {
66 1404 : MOZ_COUNT_CTOR(nsHtml5HtmlAttributes);
67 1404 : }
68 :
69 :
70 2806 : nsHtml5HtmlAttributes::~nsHtml5HtmlAttributes()
71 : {
72 1403 : MOZ_COUNT_DTOR(nsHtml5HtmlAttributes);
73 1403 : clear(0);
74 1403 : }
75 :
76 : PRInt32
77 234 : nsHtml5HtmlAttributes::getIndex(nsHtml5AttributeName* name)
78 : {
79 234 : for (PRInt32 i = 0; i < length; i++) {
80 0 : if (names[i] == name) {
81 0 : return i;
82 : }
83 : }
84 234 : return -1;
85 : }
86 :
87 : PRInt32
88 3 : nsHtml5HtmlAttributes::getLength()
89 : {
90 3 : return length;
91 : }
92 :
93 : nsIAtom*
94 0 : nsHtml5HtmlAttributes::getLocalName(PRInt32 index)
95 : {
96 0 : if (index < length && index >= 0) {
97 0 : return names[index]->getLocal(mode);
98 : } else {
99 0 : return nsnull;
100 : }
101 : }
102 :
103 : nsHtml5AttributeName*
104 0 : nsHtml5HtmlAttributes::getAttributeName(PRInt32 index)
105 : {
106 0 : if (index < length && index >= 0) {
107 0 : return names[index];
108 : } else {
109 0 : return nsnull;
110 : }
111 : }
112 :
113 : PRInt32
114 0 : nsHtml5HtmlAttributes::getURI(PRInt32 index)
115 : {
116 0 : if (index < length && index >= 0) {
117 0 : return names[index]->getUri(mode);
118 : } else {
119 0 : return nsnull;
120 : }
121 : }
122 :
123 : nsIAtom*
124 0 : nsHtml5HtmlAttributes::getPrefix(PRInt32 index)
125 : {
126 0 : if (index < length && index >= 0) {
127 0 : return names[index]->getPrefix(mode);
128 : } else {
129 0 : return nsnull;
130 : }
131 : }
132 :
133 : nsString*
134 0 : nsHtml5HtmlAttributes::getValue(PRInt32 index)
135 : {
136 0 : if (index < length && index >= 0) {
137 0 : return values[index];
138 : } else {
139 0 : return nsnull;
140 : }
141 : }
142 :
143 : nsString*
144 234 : nsHtml5HtmlAttributes::getValue(nsHtml5AttributeName* name)
145 : {
146 234 : PRInt32 index = getIndex(name);
147 234 : if (index == -1) {
148 234 : return nsnull;
149 : } else {
150 0 : return getValue(index);
151 : }
152 : }
153 :
154 : void
155 0 : nsHtml5HtmlAttributes::addAttribute(nsHtml5AttributeName* name, nsString* value)
156 : {
157 0 : if (names.length == length) {
158 0 : PRInt32 newLen = length << 1;
159 0 : jArray<nsHtml5AttributeName*,PRInt32> newNames = jArray<nsHtml5AttributeName*,PRInt32>::newJArray(newLen);
160 0 : nsHtml5ArrayCopy::arraycopy(names, newNames, names.length);
161 0 : names = newNames;
162 0 : jArray<nsString*,PRInt32> newValues = jArray<nsString*,PRInt32>::newJArray(newLen);
163 0 : nsHtml5ArrayCopy::arraycopy(values, newValues, values.length);
164 0 : values = newValues;
165 : }
166 0 : names[length] = name;
167 0 : values[length] = value;
168 0 : length++;
169 0 : }
170 :
171 : void
172 1403 : nsHtml5HtmlAttributes::clear(PRInt32 m)
173 : {
174 1403 : for (PRInt32 i = 0; i < length; i++) {
175 0 : names[i]->release();
176 0 : names[i] = nsnull;
177 0 : nsHtml5Portability::releaseString(values[i]);
178 0 : values[i] = nsnull;
179 : }
180 1403 : length = 0;
181 1403 : mode = m;
182 1403 : }
183 :
184 : void
185 0 : nsHtml5HtmlAttributes::releaseValue(PRInt32 i)
186 : {
187 0 : nsHtml5Portability::releaseString(values[i]);
188 0 : }
189 :
190 : void
191 0 : nsHtml5HtmlAttributes::clearWithoutReleasingContents()
192 : {
193 0 : for (PRInt32 i = 0; i < length; i++) {
194 0 : names[i] = nsnull;
195 0 : values[i] = nsnull;
196 : }
197 0 : length = 0;
198 0 : }
199 :
200 : bool
201 0 : nsHtml5HtmlAttributes::contains(nsHtml5AttributeName* name)
202 : {
203 0 : for (PRInt32 i = 0; i < length; i++) {
204 0 : if (name->equalsAnother(names[i])) {
205 0 : return true;
206 : }
207 : }
208 0 : return false;
209 : }
210 :
211 : void
212 0 : nsHtml5HtmlAttributes::adjustForMath()
213 : {
214 0 : mode = NS_HTML5ATTRIBUTE_NAME_MATHML;
215 0 : }
216 :
217 : void
218 0 : nsHtml5HtmlAttributes::adjustForSvg()
219 : {
220 0 : mode = NS_HTML5ATTRIBUTE_NAME_SVG;
221 0 : }
222 :
223 : nsHtml5HtmlAttributes*
224 0 : nsHtml5HtmlAttributes::cloneAttributes(nsHtml5AtomTable* interner)
225 : {
226 :
227 0 : nsHtml5HtmlAttributes* clone = new nsHtml5HtmlAttributes(0);
228 0 : for (PRInt32 i = 0; i < length; i++) {
229 0 : clone->addAttribute(names[i]->cloneAttributeName(interner), nsHtml5Portability::newStringFromString(values[i]));
230 : }
231 0 : return clone;
232 : }
233 :
234 : bool
235 0 : nsHtml5HtmlAttributes::equalsAnother(nsHtml5HtmlAttributes* other)
236 : {
237 :
238 0 : PRInt32 otherLength = other->getLength();
239 0 : if (length != otherLength) {
240 0 : return false;
241 : }
242 0 : for (PRInt32 i = 0; i < length; i++) {
243 0 : bool found = false;
244 0 : nsIAtom* ownLocal = names[i]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML);
245 0 : for (PRInt32 j = 0; j < otherLength; j++) {
246 0 : if (ownLocal == other->names[j]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML)) {
247 0 : found = true;
248 0 : if (!nsHtml5Portability::stringEqualsString(values[i], other->values[j])) {
249 0 : return false;
250 : }
251 : }
252 : }
253 0 : if (!found) {
254 0 : return false;
255 : }
256 : }
257 0 : return true;
258 : }
259 :
260 : void
261 1404 : nsHtml5HtmlAttributes::initializeStatics()
262 : {
263 1404 : EMPTY_ATTRIBUTES = new nsHtml5HtmlAttributes(NS_HTML5ATTRIBUTE_NAME_HTML);
264 1404 : }
265 :
266 : void
267 1403 : nsHtml5HtmlAttributes::releaseStatics()
268 : {
269 1403 : delete EMPTY_ATTRIBUTES;
270 1403 : }
271 :
272 :
|