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