Bug 601299: Find RegExpStatics in cx->globalObject if necessary. (r=mrbkap)
[mozilla-central.git] / parser / html / nsHtml5HtmlAttributes.cpp
blobe31d668bf5d78c134bb80a56e345f6fdda5bd51d
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"
63 nsHtml5HtmlAttributes::nsHtml5HtmlAttributes(PRInt32 mode)
64 : mode(mode),
65 length(0),
66 names(jArray<nsHtml5AttributeName*,PRInt32>(5)),
67 values(jArray<nsString*,PRInt32>(5))
69 MOZ_COUNT_CTOR(nsHtml5HtmlAttributes);
73 nsHtml5HtmlAttributes::~nsHtml5HtmlAttributes()
75 MOZ_COUNT_DTOR(nsHtml5HtmlAttributes);
76 clear(0);
77 names.release();
78 values.release();
81 PRInt32
82 nsHtml5HtmlAttributes::getIndex(nsHtml5AttributeName* name)
84 for (PRInt32 i = 0; i < length; i++) {
85 if (names[i] == name) {
86 return i;
89 return -1;
92 PRInt32
93 nsHtml5HtmlAttributes::getLength()
95 return length;
98 nsIAtom*
99 nsHtml5HtmlAttributes::getLocalName(PRInt32 index)
101 if (index < length && index >= 0) {
102 return names[index]->getLocal(mode);
103 } else {
104 return nsnull;
108 nsHtml5AttributeName*
109 nsHtml5HtmlAttributes::getAttributeName(PRInt32 index)
111 if (index < length && index >= 0) {
112 return names[index];
113 } else {
114 return nsnull;
118 PRInt32
119 nsHtml5HtmlAttributes::getURI(PRInt32 index)
121 if (index < length && index >= 0) {
122 return names[index]->getUri(mode);
123 } else {
124 return nsnull;
128 nsIAtom*
129 nsHtml5HtmlAttributes::getPrefix(PRInt32 index)
131 if (index < length && index >= 0) {
132 return names[index]->getPrefix(mode);
133 } else {
134 return nsnull;
138 nsString*
139 nsHtml5HtmlAttributes::getValue(PRInt32 index)
141 if (index < length && index >= 0) {
142 return values[index];
143 } else {
144 return nsnull;
148 nsString*
149 nsHtml5HtmlAttributes::getValue(nsHtml5AttributeName* name)
151 PRInt32 index = getIndex(name);
152 if (index == -1) {
153 return nsnull;
154 } else {
155 return getValue(index);
159 void
160 nsHtml5HtmlAttributes::addAttribute(nsHtml5AttributeName* name, nsString* value)
162 if (names.length == length) {
163 PRInt32 newLen = length << 1;
164 jArray<nsHtml5AttributeName*,PRInt32> newNames = jArray<nsHtml5AttributeName*,PRInt32>(newLen);
165 nsHtml5ArrayCopy::arraycopy(names, newNames, names.length);
166 names.release();
167 names = newNames;
168 jArray<nsString*,PRInt32> newValues = jArray<nsString*,PRInt32>(newLen);
169 nsHtml5ArrayCopy::arraycopy(values, newValues, values.length);
170 values.release();
171 values = newValues;
173 names[length] = name;
174 values[length] = value;
175 length++;
178 void
179 nsHtml5HtmlAttributes::clear(PRInt32 m)
181 for (PRInt32 i = 0; i < length; i++) {
182 names[i]->release();
183 names[i] = nsnull;
184 nsHtml5Portability::releaseString(values[i]);
185 values[i] = nsnull;
187 length = 0;
188 mode = m;
191 void
192 nsHtml5HtmlAttributes::releaseValue(PRInt32 i)
194 nsHtml5Portability::releaseString(values[i]);
197 void
198 nsHtml5HtmlAttributes::clearWithoutReleasingContents()
200 for (PRInt32 i = 0; i < length; i++) {
201 names[i] = nsnull;
202 values[i] = nsnull;
204 length = 0;
207 PRBool
208 nsHtml5HtmlAttributes::contains(nsHtml5AttributeName* name)
210 for (PRInt32 i = 0; i < length; i++) {
211 if (name->equalsAnother(names[i])) {
212 return PR_TRUE;
215 return PR_FALSE;
218 void
219 nsHtml5HtmlAttributes::adjustForMath()
221 mode = NS_HTML5ATTRIBUTE_NAME_MATHML;
224 void
225 nsHtml5HtmlAttributes::adjustForSvg()
227 mode = NS_HTML5ATTRIBUTE_NAME_SVG;
230 nsHtml5HtmlAttributes*
231 nsHtml5HtmlAttributes::cloneAttributes(nsHtml5AtomTable* interner)
234 nsHtml5HtmlAttributes* clone = new nsHtml5HtmlAttributes(0);
235 for (PRInt32 i = 0; i < length; i++) {
236 clone->addAttribute(names[i]->cloneAttributeName(interner), nsHtml5Portability::newStringFromString(values[i]));
238 return clone;
241 void
242 nsHtml5HtmlAttributes::initializeStatics()
244 EMPTY_ATTRIBUTES = new nsHtml5HtmlAttributes(NS_HTML5ATTRIBUTE_NAME_HTML);
247 void
248 nsHtml5HtmlAttributes::releaseStatics()
250 delete EMPTY_ATTRIBUTES;