Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / parser / html / nsHtml5HtmlAttributes.cpp
blob290fa752ede62823d4df348067481f96a22ec02d
1 /*
2 * Copyright (c) 2007 Henri Sivonen
3 * Copyright (c) 2008-2009 Mozilla Foundation
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
25 * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
26 * Please edit HtmlAttributes.java instead and regenerate.
29 #define nsHtml5HtmlAttributes_cpp__
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 "nsIDocument.h"
38 #include "nsTraceRefcnt.h"
39 #include "jArray.h"
40 #include "nsHtml5DocumentMode.h"
41 #include "nsHtml5ArrayCopy.h"
42 #include "nsHtml5NamedCharacters.h"
43 #include "nsHtml5NamedCharactersAccel.h"
44 #include "nsHtml5Atoms.h"
45 #include "nsHtml5ByteReadable.h"
46 #include "nsIUnicodeDecoder.h"
47 #include "nsAHtml5TreeBuilderState.h"
48 #include "nsHtml5Macros.h"
50 #include "nsHtml5Tokenizer.h"
51 #include "nsHtml5TreeBuilder.h"
52 #include "nsHtml5MetaScanner.h"
53 #include "nsHtml5AttributeName.h"
54 #include "nsHtml5ElementName.h"
55 #include "nsHtml5StackNode.h"
56 #include "nsHtml5UTF16Buffer.h"
57 #include "nsHtml5StateSnapshot.h"
58 #include "nsHtml5Portability.h"
60 #include "nsHtml5HtmlAttributes.h"
62 nsHtml5HtmlAttributes* nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES = nsnull;
64 nsHtml5HtmlAttributes::nsHtml5HtmlAttributes(PRInt32 mode)
65 : mode(mode),
66 length(0),
67 names(jArray<nsHtml5AttributeName*,PRInt32>::newJArray(5)),
68 values(jArray<nsString*,PRInt32>::newJArray(5))
70 MOZ_COUNT_CTOR(nsHtml5HtmlAttributes);
74 nsHtml5HtmlAttributes::~nsHtml5HtmlAttributes()
76 MOZ_COUNT_DTOR(nsHtml5HtmlAttributes);
77 clear(0);
80 PRInt32
81 nsHtml5HtmlAttributes::getIndex(nsHtml5AttributeName* name)
83 for (PRInt32 i = 0; i < length; i++) {
84 if (names[i] == name) {
85 return i;
88 return -1;
91 PRInt32
92 nsHtml5HtmlAttributes::getLength()
94 return length;
97 nsIAtom*
98 nsHtml5HtmlAttributes::getLocalName(PRInt32 index)
100 if (index < length && index >= 0) {
101 return names[index]->getLocal(mode);
102 } else {
103 return nsnull;
107 nsHtml5AttributeName*
108 nsHtml5HtmlAttributes::getAttributeName(PRInt32 index)
110 if (index < length && index >= 0) {
111 return names[index];
112 } else {
113 return nsnull;
117 PRInt32
118 nsHtml5HtmlAttributes::getURI(PRInt32 index)
120 if (index < length && index >= 0) {
121 return names[index]->getUri(mode);
122 } else {
123 return nsnull;
127 nsIAtom*
128 nsHtml5HtmlAttributes::getPrefix(PRInt32 index)
130 if (index < length && index >= 0) {
131 return names[index]->getPrefix(mode);
132 } else {
133 return nsnull;
137 nsString*
138 nsHtml5HtmlAttributes::getValue(PRInt32 index)
140 if (index < length && index >= 0) {
141 return values[index];
142 } else {
143 return nsnull;
147 nsString*
148 nsHtml5HtmlAttributes::getValue(nsHtml5AttributeName* name)
150 PRInt32 index = getIndex(name);
151 if (index == -1) {
152 return nsnull;
153 } else {
154 return getValue(index);
158 void
159 nsHtml5HtmlAttributes::addAttribute(nsHtml5AttributeName* name, nsString* value)
161 if (names.length == length) {
162 PRInt32 newLen = length << 1;
163 jArray<nsHtml5AttributeName*,PRInt32> newNames = jArray<nsHtml5AttributeName*,PRInt32>::newJArray(newLen);
164 nsHtml5ArrayCopy::arraycopy(names, newNames, names.length);
165 names = newNames;
166 jArray<nsString*,PRInt32> newValues = jArray<nsString*,PRInt32>::newJArray(newLen);
167 nsHtml5ArrayCopy::arraycopy(values, newValues, values.length);
168 values = newValues;
170 names[length] = name;
171 values[length] = value;
172 length++;
175 void
176 nsHtml5HtmlAttributes::clear(PRInt32 m)
178 for (PRInt32 i = 0; i < length; i++) {
179 names[i]->release();
180 names[i] = nsnull;
181 nsHtml5Portability::releaseString(values[i]);
182 values[i] = nsnull;
184 length = 0;
185 mode = m;
188 void
189 nsHtml5HtmlAttributes::releaseValue(PRInt32 i)
191 nsHtml5Portability::releaseString(values[i]);
194 void
195 nsHtml5HtmlAttributes::clearWithoutReleasingContents()
197 for (PRInt32 i = 0; i < length; i++) {
198 names[i] = nsnull;
199 values[i] = nsnull;
201 length = 0;
204 PRBool
205 nsHtml5HtmlAttributes::contains(nsHtml5AttributeName* name)
207 for (PRInt32 i = 0; i < length; i++) {
208 if (name->equalsAnother(names[i])) {
209 return PR_TRUE;
212 return PR_FALSE;
215 void
216 nsHtml5HtmlAttributes::adjustForMath()
218 mode = NS_HTML5ATTRIBUTE_NAME_MATHML;
221 void
222 nsHtml5HtmlAttributes::adjustForSvg()
224 mode = NS_HTML5ATTRIBUTE_NAME_SVG;
227 nsHtml5HtmlAttributes*
228 nsHtml5HtmlAttributes::cloneAttributes(nsHtml5AtomTable* interner)
231 nsHtml5HtmlAttributes* clone = new nsHtml5HtmlAttributes(0);
232 for (PRInt32 i = 0; i < length; i++) {
233 clone->addAttribute(names[i]->cloneAttributeName(interner), nsHtml5Portability::newStringFromString(values[i]));
235 return clone;
238 PRBool
239 nsHtml5HtmlAttributes::equalsAnother(nsHtml5HtmlAttributes* other)
242 PRInt32 otherLength = other->getLength();
243 if (length != otherLength) {
244 return PR_FALSE;
246 for (PRInt32 i = 0; i < length; i++) {
247 PRBool found = PR_FALSE;
248 nsIAtom* ownLocal = names[i]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML);
249 for (PRInt32 j = 0; j < otherLength; j++) {
250 if (ownLocal == other->names[j]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML)) {
251 found = PR_TRUE;
252 if (!nsHtml5Portability::stringEqualsString(values[i], other->values[j])) {
253 return PR_FALSE;
257 if (!found) {
258 return PR_FALSE;
261 return PR_TRUE;
264 void
265 nsHtml5HtmlAttributes::initializeStatics()
267 EMPTY_ATTRIBUTES = new nsHtml5HtmlAttributes(NS_HTML5ATTRIBUTE_NAME_HTML);
270 void
271 nsHtml5HtmlAttributes::releaseStatics()
273 delete EMPTY_ATTRIBUTES;