parser/html/nsHtml5HtmlAttributes.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/html/nsHtml5HtmlAttributes.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,257 @@
     1.4 +/*
     1.5 + * Copyright (c) 2007 Henri Sivonen
     1.6 + * Copyright (c) 2008-2011 Mozilla Foundation
     1.7 + *
     1.8 + * Permission is hereby granted, free of charge, to any person obtaining a 
     1.9 + * copy of this software and associated documentation files (the "Software"), 
    1.10 + * to deal in the Software without restriction, including without limitation 
    1.11 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
    1.12 + * and/or sell copies of the Software, and to permit persons to whom the 
    1.13 + * Software is furnished to do so, subject to the following conditions:
    1.14 + *
    1.15 + * The above copyright notice and this permission notice shall be included in 
    1.16 + * all copies or substantial portions of the Software.
    1.17 + *
    1.18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
    1.19 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    1.20 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
    1.21 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
    1.22 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
    1.23 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
    1.24 + * DEALINGS IN THE SOFTWARE.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
    1.29 + * Please edit HtmlAttributes.java instead and regenerate.
    1.30 + */
    1.31 +
    1.32 +#define nsHtml5HtmlAttributes_cpp__
    1.33 +
    1.34 +#include "nsIAtom.h"
    1.35 +#include "nsHtml5AtomTable.h"
    1.36 +#include "nsString.h"
    1.37 +#include "nsNameSpaceManager.h"
    1.38 +#include "nsIContent.h"
    1.39 +#include "nsTraceRefcnt.h"
    1.40 +#include "jArray.h"
    1.41 +#include "nsHtml5ArrayCopy.h"
    1.42 +#include "nsAHtml5TreeBuilderState.h"
    1.43 +#include "nsHtml5Atoms.h"
    1.44 +#include "nsHtml5ByteReadable.h"
    1.45 +#include "nsIUnicodeDecoder.h"
    1.46 +#include "nsHtml5Macros.h"
    1.47 +#include "nsIContentHandle.h"
    1.48 +
    1.49 +#include "nsHtml5Tokenizer.h"
    1.50 +#include "nsHtml5TreeBuilder.h"
    1.51 +#include "nsHtml5MetaScanner.h"
    1.52 +#include "nsHtml5AttributeName.h"
    1.53 +#include "nsHtml5ElementName.h"
    1.54 +#include "nsHtml5StackNode.h"
    1.55 +#include "nsHtml5UTF16Buffer.h"
    1.56 +#include "nsHtml5StateSnapshot.h"
    1.57 +#include "nsHtml5Portability.h"
    1.58 +
    1.59 +#include "nsHtml5HtmlAttributes.h"
    1.60 +
    1.61 +nsHtml5HtmlAttributes* nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES = nullptr;
    1.62 +
    1.63 +nsHtml5HtmlAttributes::nsHtml5HtmlAttributes(int32_t mode)
    1.64 +  : mode(mode),
    1.65 +    length(0),
    1.66 +    names(jArray<nsHtml5AttributeName*,int32_t>::newJArray(5)),
    1.67 +    values(jArray<nsString*,int32_t>::newJArray(5))
    1.68 +{
    1.69 +  MOZ_COUNT_CTOR(nsHtml5HtmlAttributes);
    1.70 +}
    1.71 +
    1.72 +
    1.73 +nsHtml5HtmlAttributes::~nsHtml5HtmlAttributes()
    1.74 +{
    1.75 +  MOZ_COUNT_DTOR(nsHtml5HtmlAttributes);
    1.76 +  clear(0);
    1.77 +}
    1.78 +
    1.79 +int32_t 
    1.80 +nsHtml5HtmlAttributes::getIndex(nsHtml5AttributeName* name)
    1.81 +{
    1.82 +  for (int32_t i = 0; i < length; i++) {
    1.83 +    if (names[i] == name) {
    1.84 +      return i;
    1.85 +    }
    1.86 +  }
    1.87 +  return -1;
    1.88 +}
    1.89 +
    1.90 +nsString* 
    1.91 +nsHtml5HtmlAttributes::getValue(nsHtml5AttributeName* name)
    1.92 +{
    1.93 +  int32_t index = getIndex(name);
    1.94 +  if (index == -1) {
    1.95 +    return nullptr;
    1.96 +  } else {
    1.97 +    return getValueNoBoundsCheck(index);
    1.98 +  }
    1.99 +}
   1.100 +
   1.101 +int32_t 
   1.102 +nsHtml5HtmlAttributes::getLength()
   1.103 +{
   1.104 +  return length;
   1.105 +}
   1.106 +
   1.107 +nsIAtom* 
   1.108 +nsHtml5HtmlAttributes::getLocalNameNoBoundsCheck(int32_t index)
   1.109 +{
   1.110 +  MOZ_ASSERT(index < length && index >= 0, "Index out of bounds");
   1.111 +  return names[index]->getLocal(mode);
   1.112 +}
   1.113 +
   1.114 +int32_t 
   1.115 +nsHtml5HtmlAttributes::getURINoBoundsCheck(int32_t index)
   1.116 +{
   1.117 +  MOZ_ASSERT(index < length && index >= 0, "Index out of bounds");
   1.118 +  return names[index]->getUri(mode);
   1.119 +}
   1.120 +
   1.121 +nsIAtom* 
   1.122 +nsHtml5HtmlAttributes::getPrefixNoBoundsCheck(int32_t index)
   1.123 +{
   1.124 +  MOZ_ASSERT(index < length && index >= 0, "Index out of bounds");
   1.125 +  return names[index]->getPrefix(mode);
   1.126 +}
   1.127 +
   1.128 +nsString* 
   1.129 +nsHtml5HtmlAttributes::getValueNoBoundsCheck(int32_t index)
   1.130 +{
   1.131 +  MOZ_ASSERT(index < length && index >= 0, "Index out of bounds");
   1.132 +  return values[index];
   1.133 +}
   1.134 +
   1.135 +nsHtml5AttributeName* 
   1.136 +nsHtml5HtmlAttributes::getAttributeNameNoBoundsCheck(int32_t index)
   1.137 +{
   1.138 +  MOZ_ASSERT(index < length && index >= 0, "Index out of bounds");
   1.139 +  return names[index];
   1.140 +}
   1.141 +
   1.142 +void 
   1.143 +nsHtml5HtmlAttributes::addAttribute(nsHtml5AttributeName* name, nsString* value)
   1.144 +{
   1.145 +  if (names.length == length) {
   1.146 +    int32_t newLen = length << 1;
   1.147 +    jArray<nsHtml5AttributeName*,int32_t> newNames = jArray<nsHtml5AttributeName*,int32_t>::newJArray(newLen);
   1.148 +    nsHtml5ArrayCopy::arraycopy(names, newNames, names.length);
   1.149 +    names = newNames;
   1.150 +    jArray<nsString*,int32_t> newValues = jArray<nsString*,int32_t>::newJArray(newLen);
   1.151 +    nsHtml5ArrayCopy::arraycopy(values, newValues, values.length);
   1.152 +    values = newValues;
   1.153 +  }
   1.154 +  names[length] = name;
   1.155 +  values[length] = value;
   1.156 +  length++;
   1.157 +}
   1.158 +
   1.159 +void 
   1.160 +nsHtml5HtmlAttributes::clear(int32_t m)
   1.161 +{
   1.162 +  for (int32_t i = 0; i < length; i++) {
   1.163 +    names[i]->release();
   1.164 +    names[i] = nullptr;
   1.165 +    nsHtml5Portability::releaseString(values[i]);
   1.166 +    values[i] = nullptr;
   1.167 +  }
   1.168 +  length = 0;
   1.169 +  mode = m;
   1.170 +}
   1.171 +
   1.172 +void 
   1.173 +nsHtml5HtmlAttributes::releaseValue(int32_t i)
   1.174 +{
   1.175 +  nsHtml5Portability::releaseString(values[i]);
   1.176 +}
   1.177 +
   1.178 +void 
   1.179 +nsHtml5HtmlAttributes::clearWithoutReleasingContents()
   1.180 +{
   1.181 +  for (int32_t i = 0; i < length; i++) {
   1.182 +    names[i] = nullptr;
   1.183 +    values[i] = nullptr;
   1.184 +  }
   1.185 +  length = 0;
   1.186 +}
   1.187 +
   1.188 +bool 
   1.189 +nsHtml5HtmlAttributes::contains(nsHtml5AttributeName* name)
   1.190 +{
   1.191 +  for (int32_t i = 0; i < length; i++) {
   1.192 +    if (name->equalsAnother(names[i])) {
   1.193 +      return true;
   1.194 +    }
   1.195 +  }
   1.196 +  return false;
   1.197 +}
   1.198 +
   1.199 +void 
   1.200 +nsHtml5HtmlAttributes::adjustForMath()
   1.201 +{
   1.202 +  mode = NS_HTML5ATTRIBUTE_NAME_MATHML;
   1.203 +}
   1.204 +
   1.205 +void 
   1.206 +nsHtml5HtmlAttributes::adjustForSvg()
   1.207 +{
   1.208 +  mode = NS_HTML5ATTRIBUTE_NAME_SVG;
   1.209 +}
   1.210 +
   1.211 +nsHtml5HtmlAttributes* 
   1.212 +nsHtml5HtmlAttributes::cloneAttributes(nsHtml5AtomTable* interner)
   1.213 +{
   1.214 +  MOZ_ASSERT((!length) || !mode || mode == 3);
   1.215 +  nsHtml5HtmlAttributes* clone = new nsHtml5HtmlAttributes(0);
   1.216 +  for (int32_t i = 0; i < length; i++) {
   1.217 +    clone->addAttribute(names[i]->cloneAttributeName(interner), nsHtml5Portability::newStringFromString(values[i]));
   1.218 +  }
   1.219 +  return clone;
   1.220 +}
   1.221 +
   1.222 +bool 
   1.223 +nsHtml5HtmlAttributes::equalsAnother(nsHtml5HtmlAttributes* other)
   1.224 +{
   1.225 +  MOZ_ASSERT(!mode || mode == 3, "Trying to compare attributes in foreign content.");
   1.226 +  int32_t otherLength = other->getLength();
   1.227 +  if (length != otherLength) {
   1.228 +    return false;
   1.229 +  }
   1.230 +  for (int32_t i = 0; i < length; i++) {
   1.231 +    bool found = false;
   1.232 +    nsIAtom* ownLocal = names[i]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML);
   1.233 +    for (int32_t j = 0; j < otherLength; j++) {
   1.234 +      if (ownLocal == other->names[j]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML)) {
   1.235 +        found = true;
   1.236 +        if (!nsHtml5Portability::stringEqualsString(values[i], other->values[j])) {
   1.237 +          return false;
   1.238 +        }
   1.239 +      }
   1.240 +    }
   1.241 +    if (!found) {
   1.242 +      return false;
   1.243 +    }
   1.244 +  }
   1.245 +  return true;
   1.246 +}
   1.247 +
   1.248 +void
   1.249 +nsHtml5HtmlAttributes::initializeStatics()
   1.250 +{
   1.251 +  EMPTY_ATTRIBUTES = new nsHtml5HtmlAttributes(NS_HTML5ATTRIBUTE_NAME_HTML);
   1.252 +}
   1.253 +
   1.254 +void
   1.255 +nsHtml5HtmlAttributes::releaseStatics()
   1.256 +{
   1.257 +  delete EMPTY_ATTRIBUTES;
   1.258 +}
   1.259 +
   1.260 +

mercurial