michael@0: /* michael@0: * Copyright (c) 2007 Henri Sivonen michael@0: * Copyright (c) 2008-2011 Mozilla Foundation michael@0: * michael@0: * Permission is hereby granted, free of charge, to any person obtaining a michael@0: * copy of this software and associated documentation files (the "Software"), michael@0: * to deal in the Software without restriction, including without limitation michael@0: * the rights to use, copy, modify, merge, publish, distribute, sublicense, michael@0: * and/or sell copies of the Software, and to permit persons to whom the michael@0: * Software is furnished to do so, subject to the following conditions: michael@0: * michael@0: * The above copyright notice and this permission notice shall be included in michael@0: * all copies or substantial portions of the Software. michael@0: * michael@0: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR michael@0: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, michael@0: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL michael@0: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER michael@0: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING michael@0: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER michael@0: * DEALINGS IN THE SOFTWARE. michael@0: */ michael@0: michael@0: /* michael@0: * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT. michael@0: * Please edit HtmlAttributes.java instead and regenerate. michael@0: */ michael@0: michael@0: #define nsHtml5HtmlAttributes_cpp__ michael@0: michael@0: #include "nsIAtom.h" michael@0: #include "nsHtml5AtomTable.h" michael@0: #include "nsString.h" michael@0: #include "nsNameSpaceManager.h" michael@0: #include "nsIContent.h" michael@0: #include "nsTraceRefcnt.h" michael@0: #include "jArray.h" michael@0: #include "nsHtml5ArrayCopy.h" michael@0: #include "nsAHtml5TreeBuilderState.h" michael@0: #include "nsHtml5Atoms.h" michael@0: #include "nsHtml5ByteReadable.h" michael@0: #include "nsIUnicodeDecoder.h" michael@0: #include "nsHtml5Macros.h" michael@0: #include "nsIContentHandle.h" michael@0: michael@0: #include "nsHtml5Tokenizer.h" michael@0: #include "nsHtml5TreeBuilder.h" michael@0: #include "nsHtml5MetaScanner.h" michael@0: #include "nsHtml5AttributeName.h" michael@0: #include "nsHtml5ElementName.h" michael@0: #include "nsHtml5StackNode.h" michael@0: #include "nsHtml5UTF16Buffer.h" michael@0: #include "nsHtml5StateSnapshot.h" michael@0: #include "nsHtml5Portability.h" michael@0: michael@0: #include "nsHtml5HtmlAttributes.h" michael@0: michael@0: nsHtml5HtmlAttributes* nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES = nullptr; michael@0: michael@0: nsHtml5HtmlAttributes::nsHtml5HtmlAttributes(int32_t mode) michael@0: : mode(mode), michael@0: length(0), michael@0: names(jArray::newJArray(5)), michael@0: values(jArray::newJArray(5)) michael@0: { michael@0: MOZ_COUNT_CTOR(nsHtml5HtmlAttributes); michael@0: } michael@0: michael@0: michael@0: nsHtml5HtmlAttributes::~nsHtml5HtmlAttributes() michael@0: { michael@0: MOZ_COUNT_DTOR(nsHtml5HtmlAttributes); michael@0: clear(0); michael@0: } michael@0: michael@0: int32_t michael@0: nsHtml5HtmlAttributes::getIndex(nsHtml5AttributeName* name) michael@0: { michael@0: for (int32_t i = 0; i < length; i++) { michael@0: if (names[i] == name) { michael@0: return i; michael@0: } michael@0: } michael@0: return -1; michael@0: } michael@0: michael@0: nsString* michael@0: nsHtml5HtmlAttributes::getValue(nsHtml5AttributeName* name) michael@0: { michael@0: int32_t index = getIndex(name); michael@0: if (index == -1) { michael@0: return nullptr; michael@0: } else { michael@0: return getValueNoBoundsCheck(index); michael@0: } michael@0: } michael@0: michael@0: int32_t michael@0: nsHtml5HtmlAttributes::getLength() michael@0: { michael@0: return length; michael@0: } michael@0: michael@0: nsIAtom* michael@0: nsHtml5HtmlAttributes::getLocalNameNoBoundsCheck(int32_t index) michael@0: { michael@0: MOZ_ASSERT(index < length && index >= 0, "Index out of bounds"); michael@0: return names[index]->getLocal(mode); michael@0: } michael@0: michael@0: int32_t michael@0: nsHtml5HtmlAttributes::getURINoBoundsCheck(int32_t index) michael@0: { michael@0: MOZ_ASSERT(index < length && index >= 0, "Index out of bounds"); michael@0: return names[index]->getUri(mode); michael@0: } michael@0: michael@0: nsIAtom* michael@0: nsHtml5HtmlAttributes::getPrefixNoBoundsCheck(int32_t index) michael@0: { michael@0: MOZ_ASSERT(index < length && index >= 0, "Index out of bounds"); michael@0: return names[index]->getPrefix(mode); michael@0: } michael@0: michael@0: nsString* michael@0: nsHtml5HtmlAttributes::getValueNoBoundsCheck(int32_t index) michael@0: { michael@0: MOZ_ASSERT(index < length && index >= 0, "Index out of bounds"); michael@0: return values[index]; michael@0: } michael@0: michael@0: nsHtml5AttributeName* michael@0: nsHtml5HtmlAttributes::getAttributeNameNoBoundsCheck(int32_t index) michael@0: { michael@0: MOZ_ASSERT(index < length && index >= 0, "Index out of bounds"); michael@0: return names[index]; michael@0: } michael@0: michael@0: void michael@0: nsHtml5HtmlAttributes::addAttribute(nsHtml5AttributeName* name, nsString* value) michael@0: { michael@0: if (names.length == length) { michael@0: int32_t newLen = length << 1; michael@0: jArray newNames = jArray::newJArray(newLen); michael@0: nsHtml5ArrayCopy::arraycopy(names, newNames, names.length); michael@0: names = newNames; michael@0: jArray newValues = jArray::newJArray(newLen); michael@0: nsHtml5ArrayCopy::arraycopy(values, newValues, values.length); michael@0: values = newValues; michael@0: } michael@0: names[length] = name; michael@0: values[length] = value; michael@0: length++; michael@0: } michael@0: michael@0: void michael@0: nsHtml5HtmlAttributes::clear(int32_t m) michael@0: { michael@0: for (int32_t i = 0; i < length; i++) { michael@0: names[i]->release(); michael@0: names[i] = nullptr; michael@0: nsHtml5Portability::releaseString(values[i]); michael@0: values[i] = nullptr; michael@0: } michael@0: length = 0; michael@0: mode = m; michael@0: } michael@0: michael@0: void michael@0: nsHtml5HtmlAttributes::releaseValue(int32_t i) michael@0: { michael@0: nsHtml5Portability::releaseString(values[i]); michael@0: } michael@0: michael@0: void michael@0: nsHtml5HtmlAttributes::clearWithoutReleasingContents() michael@0: { michael@0: for (int32_t i = 0; i < length; i++) { michael@0: names[i] = nullptr; michael@0: values[i] = nullptr; michael@0: } michael@0: length = 0; michael@0: } michael@0: michael@0: bool michael@0: nsHtml5HtmlAttributes::contains(nsHtml5AttributeName* name) michael@0: { michael@0: for (int32_t i = 0; i < length; i++) { michael@0: if (name->equalsAnother(names[i])) { michael@0: return true; michael@0: } michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: void michael@0: nsHtml5HtmlAttributes::adjustForMath() michael@0: { michael@0: mode = NS_HTML5ATTRIBUTE_NAME_MATHML; michael@0: } michael@0: michael@0: void michael@0: nsHtml5HtmlAttributes::adjustForSvg() michael@0: { michael@0: mode = NS_HTML5ATTRIBUTE_NAME_SVG; michael@0: } michael@0: michael@0: nsHtml5HtmlAttributes* michael@0: nsHtml5HtmlAttributes::cloneAttributes(nsHtml5AtomTable* interner) michael@0: { michael@0: MOZ_ASSERT((!length) || !mode || mode == 3); michael@0: nsHtml5HtmlAttributes* clone = new nsHtml5HtmlAttributes(0); michael@0: for (int32_t i = 0; i < length; i++) { michael@0: clone->addAttribute(names[i]->cloneAttributeName(interner), nsHtml5Portability::newStringFromString(values[i])); michael@0: } michael@0: return clone; michael@0: } michael@0: michael@0: bool michael@0: nsHtml5HtmlAttributes::equalsAnother(nsHtml5HtmlAttributes* other) michael@0: { michael@0: MOZ_ASSERT(!mode || mode == 3, "Trying to compare attributes in foreign content."); michael@0: int32_t otherLength = other->getLength(); michael@0: if (length != otherLength) { michael@0: return false; michael@0: } michael@0: for (int32_t i = 0; i < length; i++) { michael@0: bool found = false; michael@0: nsIAtom* ownLocal = names[i]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML); michael@0: for (int32_t j = 0; j < otherLength; j++) { michael@0: if (ownLocal == other->names[j]->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML)) { michael@0: found = true; michael@0: if (!nsHtml5Portability::stringEqualsString(values[i], other->values[j])) { michael@0: return false; michael@0: } michael@0: } michael@0: } michael@0: if (!found) { michael@0: return false; michael@0: } michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: void michael@0: nsHtml5HtmlAttributes::initializeStatics() michael@0: { michael@0: EMPTY_ATTRIBUTES = new nsHtml5HtmlAttributes(NS_HTML5ATTRIBUTE_NAME_HTML); michael@0: } michael@0: michael@0: void michael@0: nsHtml5HtmlAttributes::releaseStatics() michael@0: { michael@0: delete EMPTY_ATTRIBUTES; michael@0: } michael@0: michael@0: