/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. * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
  25. * Please edit HtmlAttributes.java instead and regenerate.
  26. */
  27. #define nsHtml5HtmlAttributes_cpp__
  28. #include "prtypes.h"
  29. #include "nsIAtom.h"
  30. #include "nsHtml5AtomTable.h"
  31. #include "nsString.h"
  32. #include "nsINameSpaceManager.h"
  33. #include "nsIContent.h"
  34. #include "nsTraceRefcnt.h"
  35. #include "jArray.h"
  36. #include "nsHtml5ArrayCopy.h"
  37. #include "nsAHtml5TreeBuilderState.h"
  38. #include "nsHtml5Atoms.h"
  39. #include "nsHtml5ByteReadable.h"
  40. #include "nsIUnicodeDecoder.h"
  41. #include "nsHtml5Macros.h"
  42. #include "nsHtml5Tokenizer.h"
  43. #include "nsHtml5TreeBuilder.h"
  44. #include "nsHtml5MetaScanner.h"
  45. #include "nsHtml5AttributeName.h"
  46. #include "nsHtml5ElementName.h"
  47. #include "nsHtml5StackNode.h"
  48. #include "nsHtml5UTF16Buffer.h"
  49. #include "nsHtml5StateSnapshot.h"
  50. #include "nsHtml5Portability.h"
  51. #include "nsHtml5HtmlAttributes.h"
  52. nsHtml5HtmlAttributes* nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES = nsnull;
  53. nsHtml5HtmlAttributes::nsHtml5HtmlAttributes(PRInt32 mode)
  54. : mode(mode),
  55. length(0),
  56. names(jArray<nsHtml5AttributeName*,PRInt32>::newJArray(5)),
  57. values(jArray<nsString*,PRInt32>::newJArray(5))
  58. {
  59. MOZ_COUNT_CTOR(nsHtml5HtmlAttributes);
  60. }
  61. nsHtml5HtmlAttributes::~nsHtml5HtmlAttributes()
  62. {
  63. MOZ_COUNT_DTOR(nsHtml5HtmlAttributes);
  64. clear(0);
  65. }
  66. PRInt32
  67. nsHtml5HtmlAttributes::getIndex(nsHtml5AttributeName* name)
  68. {
  69. for (PRInt32 i = 0; i < length; i++) {
  70. if (names[i] == name) {
  71. return i;
  72. }
  73. }
  74. return -1;
  75. }
  76. PRInt32
  77. nsHtml5HtmlAttributes::getLength()
  78. {
  79. return length;
  80. }
  81. nsIAtom*
  82. nsHtml5HtmlAttributes::getLocalName(PRInt32 index)
  83. {
  84. if (index < length && index >= 0) {
  85. return names[index]->getLocal(mode);
  86. } else {
  87. return nsnull;
  88. }
  89. }
  90. nsHtml5AttributeName*
  91. nsHtml5HtmlAttributes::getAttributeName(PRInt32 index)
  92. {
  93. if (index < length && index >= 0) {
  94. return names[index];
  95. } else {
  96. return nsnull;
  97. }
  98. }
  99. PRInt32
  100. nsHtml5HtmlAttributes::getURI(PRInt32 index)
  101. {
  102. if (index < length && index >= 0) {
  103. return names[index]->getUri(mode);
  104. } else {
  105. return nsnull;
  106. }
  107. }
  108. nsIAtom*
  109. nsHtml5HtmlAttributes::getPrefix(PRInt32 index)
  110. {
  111. if (index < length && index >= 0) {
  112. return names[index]->getPrefix(mode);
  113. } else {
  114. return nsnull;
  115. }
  116. }
  117. nsString*
  118. nsHtml5HtmlAttributes::getValue(PRInt32 index)
  119. {
  120. if (index < length && index >= 0) {
  121. return values[index];
  122. } else {
  123. return nsnull;
  124. }
  125. }
  126. nsString*
  127. nsHtml5HtmlAttributes::getValue(nsHtml5AttributeName* name)
  128. {
  129. PRInt32 index = getIndex(name);
  130. if (index == -1) {
  131. return nsnull;
  132. } else {
  133. return getValue(index);
  134. }
  135. }
  136. void
  137. nsHtml5HtmlAttributes::addAttribute(nsHtml5AttributeName* name, nsString* value)
  138. {
  139. if (names.length == length) {
  140. PRInt32 newLen = length << 1;
  141. jArray<nsHtml5AttributeName*,PRInt32> newNames = jArray<nsHtml5AttributeName*,PRInt32>::newJArray(newLen);
  142. nsHtml5ArrayCopy::arraycopy(names, newNames, names.length);
  143. names = newNames;
  144. jArray<nsString*,PRInt32> newValues = jArray<nsString*,PRInt32>::newJArray(newLen);
  145. nsHtml5ArrayCopy::arraycopy(values, newValues, values.length);
  146. values = newValues;
  147. }
  148. names[length] = name;
  149. values[length] = value;
  150. length++;
  151. }
  152. void
  153. nsHtml5HtmlAttributes::clear(PRInt32 m)
  154. {
  155. for (PRInt32 i = 0; i < length; i++) {
  156. names[i]->release();
  157. names[i] = nsnull;
  158. nsHtml5Portability::releaseString(values[i]);
  159. values[i] = nsnull;
  160. }
  161. length = 0;
  162. mode = m;
  163. }
  164. void
  165. nsHtml5HtmlAttributes::releaseValue(PRInt32 i)
  166. {
  167. nsHtml5Portability::releaseString(values[i]);
  168. }
  169. void
  170. nsHtml5HtmlAttributes::clearWithoutReleasingContents()
  171. {
  172. for (PRInt32 i = 0; i < length; i++) {
  173. names[i] = nsnull;
  174. values[i] = nsnull;
  175. }
  176. length = 0;
  177. }
  178. bool
  179. nsHtml5HtmlAttributes::contains(nsHtml5AttributeName* name)
  180. {
  181. for (PRInt32 i = 0; i < length; i++) {
  182. if (name->equalsAnother(names[i])) {
  183. return true;
  184. }
  185. }
  186. return false;
  187. }
  188. void
  189. nsHtml5HtmlAttributes::adjustForMath()
  190. {
  191. mode = NS_HTML5ATTRIBUTE_NAME_MATHML;
  192. }
  193. void
  194. nsHtml5HtmlAttributes::adjustForSvg()
  195. {
  196. mode = NS_HTML5ATTRIBUTE_NAME_SVG;
  197. }
  198. nsHtml5HtmlAttributes*
  199. nsHtml5HtmlAttributes::cloneAttributes(nsHtml5AtomTable* interner)
  200. {
  201. nsHtml5HtmlAttributes* clone = new nsHtml5HtmlAttributes(0);
  202. for (PRInt32 i = 0; i < length; i++) {
  203. clone->addAttribute(names[i]->cloneAttributeName(interner), nsHtml5Portability::newStringFromString(values[i]));
  204. }
  205. return clone;
  206. }
  207. bool
  208. nsHtml5HtmlAttributes::equalsAnother(nsHtml5HtmlAttributes* other)
  209. {
  210. PRInt32 otherLength = other->getLength();
  211. if (length != otherLength) {
  212. return false;
  213. }
  214. for (PRInt32 i = 0; i < length; i++) {
  215. bool found = false;
  216. nsIAtom* ownLocal = names[i]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML);
  217. for (PRInt32 j = 0; j < otherLength; j++) {
  218. if (ownLocal == other->names[j]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML)) {
  219. found = true;
  220. if (!nsHtml5Portability::stringEqualsString(values[i], other->values[j])) {
  221. return false;
  222. }
  223. }
  224. }
  225. if (!found) {
  226. return false;
  227. }
  228. }
  229. return true;
  230. }
  231. void
  232. nsHtml5HtmlAttributes::initializeStatics()
  233. {
  234. EMPTY_ATTRIBUTES = new nsHtml5HtmlAttributes(NS_HTML5ATTRIBUTE_NAME_HTML);
  235. }
  236. void
  237. nsHtml5HtmlAttributes::releaseStatics()
  238. {
  239. delete EMPTY_ATTRIBUTES;
  240. }