PageRenderTime 32ms CodeModel.GetById 15ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/parser/html/nsHtml5HtmlAttributes.cpp

http://github.com/zpao/v8monkey
C++ | 272 lines | 214 code | 32 blank | 26 comment | 36 complexity | cbe8dbe9b95274afeda29d62ff233746 MD5 | raw file
  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
 58nsHtml5HtmlAttributes* nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES = nsnull;
 59
 60nsHtml5HtmlAttributes::nsHtml5HtmlAttributes(PRInt32 mode)
 61  : mode(mode),
 62    length(0),
 63    names(jArray<nsHtml5AttributeName*,PRInt32>::newJArray(5)),
 64    values(jArray<nsString*,PRInt32>::newJArray(5))
 65{
 66  MOZ_COUNT_CTOR(nsHtml5HtmlAttributes);
 67}
 68
 69
 70nsHtml5HtmlAttributes::~nsHtml5HtmlAttributes()
 71{
 72  MOZ_COUNT_DTOR(nsHtml5HtmlAttributes);
 73  clear(0);
 74}
 75
 76PRInt32 
 77nsHtml5HtmlAttributes::getIndex(nsHtml5AttributeName* name)
 78{
 79  for (PRInt32 i = 0; i < length; i++) {
 80    if (names[i] == name) {
 81      return i;
 82    }
 83  }
 84  return -1;
 85}
 86
 87PRInt32 
 88nsHtml5HtmlAttributes::getLength()
 89{
 90  return length;
 91}
 92
 93nsIAtom* 
 94nsHtml5HtmlAttributes::getLocalName(PRInt32 index)
 95{
 96  if (index < length && index >= 0) {
 97    return names[index]->getLocal(mode);
 98  } else {
 99    return nsnull;
100  }
101}
102
103nsHtml5AttributeName* 
104nsHtml5HtmlAttributes::getAttributeName(PRInt32 index)
105{
106  if (index < length && index >= 0) {
107    return names[index];
108  } else {
109    return nsnull;
110  }
111}
112
113PRInt32 
114nsHtml5HtmlAttributes::getURI(PRInt32 index)
115{
116  if (index < length && index >= 0) {
117    return names[index]->getUri(mode);
118  } else {
119    return nsnull;
120  }
121}
122
123nsIAtom* 
124nsHtml5HtmlAttributes::getPrefix(PRInt32 index)
125{
126  if (index < length && index >= 0) {
127    return names[index]->getPrefix(mode);
128  } else {
129    return nsnull;
130  }
131}
132
133nsString* 
134nsHtml5HtmlAttributes::getValue(PRInt32 index)
135{
136  if (index < length && index >= 0) {
137    return values[index];
138  } else {
139    return nsnull;
140  }
141}
142
143nsString* 
144nsHtml5HtmlAttributes::getValue(nsHtml5AttributeName* name)
145{
146  PRInt32 index = getIndex(name);
147  if (index == -1) {
148    return nsnull;
149  } else {
150    return getValue(index);
151  }
152}
153
154void 
155nsHtml5HtmlAttributes::addAttribute(nsHtml5AttributeName* name, nsString* value)
156{
157  if (names.length == length) {
158    PRInt32 newLen = length << 1;
159    jArray<nsHtml5AttributeName*,PRInt32> newNames = jArray<nsHtml5AttributeName*,PRInt32>::newJArray(newLen);
160    nsHtml5ArrayCopy::arraycopy(names, newNames, names.length);
161    names = newNames;
162    jArray<nsString*,PRInt32> newValues = jArray<nsString*,PRInt32>::newJArray(newLen);
163    nsHtml5ArrayCopy::arraycopy(values, newValues, values.length);
164    values = newValues;
165  }
166  names[length] = name;
167  values[length] = value;
168  length++;
169}
170
171void 
172nsHtml5HtmlAttributes::clear(PRInt32 m)
173{
174  for (PRInt32 i = 0; i < length; i++) {
175    names[i]->release();
176    names[i] = nsnull;
177    nsHtml5Portability::releaseString(values[i]);
178    values[i] = nsnull;
179  }
180  length = 0;
181  mode = m;
182}
183
184void 
185nsHtml5HtmlAttributes::releaseValue(PRInt32 i)
186{
187  nsHtml5Portability::releaseString(values[i]);
188}
189
190void 
191nsHtml5HtmlAttributes::clearWithoutReleasingContents()
192{
193  for (PRInt32 i = 0; i < length; i++) {
194    names[i] = nsnull;
195    values[i] = nsnull;
196  }
197  length = 0;
198}
199
200bool 
201nsHtml5HtmlAttributes::contains(nsHtml5AttributeName* name)
202{
203  for (PRInt32 i = 0; i < length; i++) {
204    if (name->equalsAnother(names[i])) {
205      return true;
206    }
207  }
208  return false;
209}
210
211void 
212nsHtml5HtmlAttributes::adjustForMath()
213{
214  mode = NS_HTML5ATTRIBUTE_NAME_MATHML;
215}
216
217void 
218nsHtml5HtmlAttributes::adjustForSvg()
219{
220  mode = NS_HTML5ATTRIBUTE_NAME_SVG;
221}
222
223nsHtml5HtmlAttributes* 
224nsHtml5HtmlAttributes::cloneAttributes(nsHtml5AtomTable* interner)
225{
226
227  nsHtml5HtmlAttributes* clone = new nsHtml5HtmlAttributes(0);
228  for (PRInt32 i = 0; i < length; i++) {
229    clone->addAttribute(names[i]->cloneAttributeName(interner), nsHtml5Portability::newStringFromString(values[i]));
230  }
231  return clone;
232}
233
234bool 
235nsHtml5HtmlAttributes::equalsAnother(nsHtml5HtmlAttributes* other)
236{
237
238  PRInt32 otherLength = other->getLength();
239  if (length != otherLength) {
240    return false;
241  }
242  for (PRInt32 i = 0; i < length; i++) {
243    bool found = false;
244    nsIAtom* ownLocal = names[i]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML);
245    for (PRInt32 j = 0; j < otherLength; j++) {
246      if (ownLocal == other->names[j]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML)) {
247        found = true;
248        if (!nsHtml5Portability::stringEqualsString(values[i], other->values[j])) {
249          return false;
250        }
251      }
252    }
253    if (!found) {
254      return false;
255    }
256  }
257  return true;
258}
259
260void
261nsHtml5HtmlAttributes::initializeStatics()
262{
263  EMPTY_ATTRIBUTES = new nsHtml5HtmlAttributes(NS_HTML5ATTRIBUTE_NAME_HTML);
264}
265
266void
267nsHtml5HtmlAttributes::releaseStatics()
268{
269  delete EMPTY_ATTRIBUTES;
270}
271
272