2004-01-15 17:07:27 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* IBM Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2003
|
|
|
|
* IBM Corporation. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* IBM Corporation
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsAttrValue.h"
|
2004-01-26 19:22:05 +00:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2004-03-04 02:06:28 +00:00
|
|
|
#include "nsICSSStyleRule.h"
|
|
|
|
#include "nsCSSDeclaration.h"
|
|
|
|
#include "nsIHTMLDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
2004-01-26 19:22:05 +00:00
|
|
|
|
2004-03-09 08:44:53 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
#include "nsISVGValue.h"
|
|
|
|
#endif
|
|
|
|
|
2005-01-25 00:02:58 +00:00
|
|
|
nsVoidArray* nsAttrValue::sEnumTableArray = nsnull;
|
|
|
|
|
2005-02-02 22:58:01 +00:00
|
|
|
/**
|
|
|
|
* Routines for cheaply storing and accessing a string. This code leverages
|
|
|
|
* the reference counted string buffer code used by the XPCOM string classes.
|
|
|
|
*/
|
2005-01-25 00:02:58 +00:00
|
|
|
class nsCheapStringBufferUtils {
|
|
|
|
public:
|
|
|
|
/**
|
2005-02-02 22:58:01 +00:00
|
|
|
* Get a nsCheapString (a nsString really) from a nsStringBuffer
|
2005-01-25 00:02:58 +00:00
|
|
|
*
|
|
|
|
* @param aBuf the buffer to get string from
|
2005-02-02 22:58:01 +00:00
|
|
|
* @return a nsCheapString representing this string
|
2005-01-25 00:02:58 +00:00
|
|
|
*/
|
2005-02-02 22:58:01 +00:00
|
|
|
static const nsCheapString GetDependentString(nsStringBuffer* aBuf) {
|
|
|
|
return nsCheapString(aBuf);
|
2005-01-25 00:02:58 +00:00
|
|
|
}
|
2005-02-02 22:58:01 +00:00
|
|
|
|
2005-01-25 00:02:58 +00:00
|
|
|
/**
|
2005-02-02 22:58:01 +00:00
|
|
|
* Construct from an nsAString
|
|
|
|
*
|
2005-01-25 00:02:58 +00:00
|
|
|
* @param aBuf the buffer to copy to
|
|
|
|
* @param aStr the string to construct from
|
|
|
|
*/
|
2005-02-02 22:58:01 +00:00
|
|
|
static void CopyToBuffer(nsStringBuffer*& aBuf, const nsAString& aStr) {
|
2005-01-25 00:02:58 +00:00
|
|
|
PRUint32 len = aStr.Length();
|
2005-02-02 22:58:01 +00:00
|
|
|
|
|
|
|
nsStringBuffer* buf = nsStringBuffer::FromString(aStr);
|
|
|
|
if (buf) {
|
|
|
|
if (buf->StorageSize()/sizeof(PRUnichar) - 1 == len) {
|
|
|
|
buf->AddRef();
|
|
|
|
aBuf = buf;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf = nsStringBuffer::Alloc((len + 1) * sizeof(PRUnichar));
|
|
|
|
PRUnichar *data = NS_STATIC_CAST(PRUnichar*, buf->Data());
|
|
|
|
CopyUnicodeTo(aStr, 0, data, len);
|
|
|
|
data[len] = PRUnichar(0);
|
|
|
|
aBuf = buf;
|
2005-01-25 00:02:58 +00:00
|
|
|
}
|
2005-02-02 22:58:01 +00:00
|
|
|
|
2005-01-25 00:02:58 +00:00
|
|
|
/**
|
|
|
|
* Construct from an AString
|
|
|
|
* @param aBuf the buffer to copy to
|
|
|
|
* @param aStr the string to construct from
|
|
|
|
*/
|
2005-02-02 22:58:01 +00:00
|
|
|
static void CopyToExistingBuffer(nsStringBuffer*& aBuf,
|
|
|
|
nsStringBuffer* aOldBuf,
|
2005-01-25 00:02:58 +00:00
|
|
|
const nsAString& aStr) {
|
|
|
|
NS_ASSERTION(aOldBuf, "Cannot work on null buffer!");
|
2005-02-02 22:58:01 +00:00
|
|
|
// since we are using the buffer's storage size as the length, aOldBuf
|
|
|
|
// would only be usable if its storage size matched the length of aStr's
|
|
|
|
// exactly. that only matters of course if aStr is not sharable.
|
|
|
|
CopyToBuffer(aBuf, aStr);
|
|
|
|
Free(aOldBuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ToString(nsStringBuffer* aBuf, nsAString& aStr) {
|
|
|
|
aBuf->ToString(aBuf->StorageSize()/sizeof(PRUnichar) - 1, aStr);
|
2005-01-25 00:02:58 +00:00
|
|
|
}
|
2005-02-02 22:58:01 +00:00
|
|
|
|
2005-01-25 00:02:58 +00:00
|
|
|
/**
|
|
|
|
* Construct from another nsCheapStringBuffer
|
|
|
|
* @param aBuf the buffer to put into
|
|
|
|
* @param aSrc the buffer to construct from
|
|
|
|
*/
|
2005-02-02 22:58:01 +00:00
|
|
|
static void Clone(nsStringBuffer*& aBuf, nsStringBuffer* aSrc) {
|
2005-01-25 00:02:58 +00:00
|
|
|
NS_ASSERTION(aSrc, "Cannot work on null buffer!");
|
2005-02-02 22:58:01 +00:00
|
|
|
aSrc->AddRef();
|
|
|
|
aBuf = aSrc;
|
2005-01-25 00:02:58 +00:00
|
|
|
}
|
2005-02-02 22:58:01 +00:00
|
|
|
|
2005-01-25 00:02:58 +00:00
|
|
|
/**
|
|
|
|
* Free the memory for the buf
|
|
|
|
* @param aBuf the buffer to free
|
|
|
|
*/
|
2005-02-02 22:58:01 +00:00
|
|
|
static void Free(nsStringBuffer* aBuf) {
|
2005-01-25 00:02:58 +00:00
|
|
|
NS_ASSERTION(aBuf, "Cannot work on null buffer!");
|
2005-02-02 22:58:01 +00:00
|
|
|
aBuf->Release();
|
2005-01-25 00:02:58 +00:00
|
|
|
}
|
2005-02-02 22:58:01 +00:00
|
|
|
|
2005-01-25 00:02:58 +00:00
|
|
|
/**
|
|
|
|
* Get a hashcode for the buffer
|
|
|
|
* @param aBuf the buffer
|
|
|
|
* @return the hashcode
|
|
|
|
*/
|
2005-02-02 22:58:01 +00:00
|
|
|
static PRUint32 HashCode(nsStringBuffer* aBuf) {
|
2005-01-25 00:02:58 +00:00
|
|
|
NS_ASSERTION(aBuf, "Cannot work on null buffer!");
|
2005-02-02 22:58:01 +00:00
|
|
|
PRUint32 len = aBuf->StorageSize()/sizeof(PRUnichar) - 1;
|
|
|
|
return nsCRT::BufferHashCode(NS_STATIC_CAST(PRUnichar*, aBuf->Data()), len);
|
2005-01-25 00:02:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
nsAttrValue::nsAttrValue()
|
|
|
|
: mBits(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue::nsAttrValue(const nsAttrValue& aOther)
|
|
|
|
: mBits(0)
|
|
|
|
{
|
|
|
|
SetTo(aOther);
|
|
|
|
}
|
2004-01-15 17:07:27 +00:00
|
|
|
|
|
|
|
nsAttrValue::nsAttrValue(const nsAString& aValue)
|
|
|
|
: mBits(0)
|
|
|
|
{
|
|
|
|
SetTo(aValue);
|
|
|
|
}
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
nsAttrValue::nsAttrValue(nsICSSStyleRule* aValue)
|
2004-01-15 17:07:27 +00:00
|
|
|
: mBits(0)
|
|
|
|
{
|
|
|
|
SetTo(aValue);
|
|
|
|
}
|
|
|
|
|
2004-03-09 08:44:53 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
nsAttrValue::nsAttrValue(nsISVGValue* aValue)
|
|
|
|
: mBits(0)
|
|
|
|
{
|
|
|
|
SetTo(aValue);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
nsAttrValue::~nsAttrValue()
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
ResetIfSet();
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
|
|
|
|
2005-01-25 00:02:58 +00:00
|
|
|
/* static */
|
|
|
|
nsresult
|
|
|
|
nsAttrValue::Init()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!sEnumTableArray, "nsAttrValue already initialized");
|
|
|
|
|
|
|
|
sEnumTableArray = new nsVoidArray;
|
|
|
|
NS_ENSURE_TRUE(sEnumTableArray, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
nsAttrValue::Shutdown()
|
|
|
|
{
|
|
|
|
delete sEnumTableArray;
|
|
|
|
sEnumTableArray = nsnull;
|
|
|
|
}
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
nsAttrValue::ValueType
|
|
|
|
nsAttrValue::Type() const
|
2004-01-15 17:07:27 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
switch (BaseType()) {
|
|
|
|
case eIntegerBase:
|
|
|
|
{
|
|
|
|
return NS_STATIC_CAST(ValueType, mBits & NS_ATTRVALUE_INTEGERTYPE_MASK);
|
|
|
|
}
|
|
|
|
case eOtherBase:
|
|
|
|
{
|
|
|
|
return GetMiscContainer()->mType;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2004-03-04 03:00:25 +00:00
|
|
|
return NS_STATIC_CAST(ValueType, NS_STATIC_CAST(PRUint16, BaseType()));
|
2004-03-04 02:06:28 +00:00
|
|
|
}
|
|
|
|
}
|
2004-01-15 17:07:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAttrValue::Reset()
|
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
switch(BaseType()) {
|
|
|
|
case eStringBase:
|
2004-01-15 17:07:27 +00:00
|
|
|
{
|
2005-02-02 22:58:01 +00:00
|
|
|
nsStringBuffer* str = NS_STATIC_CAST(nsStringBuffer*, GetPtr());
|
2004-01-15 17:07:27 +00:00
|
|
|
if (str) {
|
|
|
|
nsCheapStringBufferUtils::Free(str);
|
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
|
2004-01-15 17:07:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
case eOtherBase:
|
2004-01-15 17:07:27 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
EnsureEmptyMiscContainer();
|
|
|
|
delete GetMiscContainer();
|
|
|
|
|
2004-01-15 17:07:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
case eAtomBase:
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
nsIAtom* atom = GetAtomValue();
|
2004-01-26 19:22:05 +00:00
|
|
|
NS_RELEASE(atom);
|
2004-03-04 02:06:28 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eIntegerBase:
|
|
|
|
{
|
2004-01-26 19:22:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-01-15 17:07:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mBits = 0;
|
|
|
|
}
|
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
void
|
|
|
|
nsAttrValue::SetTo(const nsAttrValue& aOther)
|
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
switch (aOther.BaseType()) {
|
|
|
|
case eStringBase:
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
|
|
|
SetTo(aOther.GetStringValue());
|
2004-03-04 02:06:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case eOtherBase:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eAtomBase:
|
|
|
|
{
|
|
|
|
ResetIfSet();
|
|
|
|
nsIAtom* atom = aOther.GetAtomValue();
|
|
|
|
NS_ADDREF(atom);
|
|
|
|
SetPtrValueAndType(atom, eAtomBase);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case eIntegerBase:
|
|
|
|
{
|
|
|
|
ResetIfSet();
|
|
|
|
mBits = aOther.mBits;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MiscContainer* otherCont = aOther.GetMiscContainer();
|
|
|
|
switch (otherCont->mType) {
|
|
|
|
case eColor:
|
|
|
|
{
|
|
|
|
if (EnsureEmptyMiscContainer()) {
|
|
|
|
MiscContainer* cont = GetMiscContainer();
|
|
|
|
cont->mColor = otherCont->mColor;
|
|
|
|
cont->mType = eColor;
|
|
|
|
}
|
2004-01-26 19:22:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
case eCSSStyleRule:
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
SetTo(otherCont->mCSSStyleRule);
|
2004-01-26 19:22:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
case eAtomArray:
|
|
|
|
{
|
|
|
|
if (!EnsureEmptyAtomArray() ||
|
|
|
|
!GetAtomArrayValue()->AppendObjects(*otherCont->mAtomArray)) {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-03-09 08:44:53 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
case eSVGValue:
|
|
|
|
{
|
|
|
|
SetTo(otherCont->mSVGValue);
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-04 02:06:28 +00:00
|
|
|
default:
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
NS_NOTREACHED("unknown type stored in MiscContainer");
|
2004-01-26 19:22:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-15 17:07:27 +00:00
|
|
|
void
|
|
|
|
nsAttrValue::SetTo(const nsAString& aValue)
|
|
|
|
{
|
2005-02-02 22:58:01 +00:00
|
|
|
nsStringBuffer* str = nsnull;
|
2004-01-15 17:07:27 +00:00
|
|
|
PRBool empty = aValue.IsEmpty();
|
|
|
|
void* ptr;
|
2004-03-04 02:06:28 +00:00
|
|
|
if (BaseType() == eStringBase && (ptr = GetPtr())) {
|
2004-01-15 17:07:27 +00:00
|
|
|
if (!empty) {
|
|
|
|
nsCheapStringBufferUtils::
|
2005-02-02 22:58:01 +00:00
|
|
|
CopyToExistingBuffer(str, NS_STATIC_CAST(nsStringBuffer*, ptr), aValue);
|
2004-01-15 17:07:27 +00:00
|
|
|
}
|
|
|
|
else {
|
2005-02-02 22:58:01 +00:00
|
|
|
nsCheapStringBufferUtils::Free(NS_STATIC_CAST(nsStringBuffer*, ptr));
|
2004-01-15 17:07:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2004-03-04 02:06:28 +00:00
|
|
|
ResetIfSet();
|
2004-01-15 17:07:27 +00:00
|
|
|
if (!empty) {
|
|
|
|
nsCheapStringBufferUtils::CopyToBuffer(str, aValue);
|
|
|
|
}
|
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
SetPtrValueAndType(str, eStringBase);
|
2004-01-15 17:07:27 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
void
|
2005-01-25 00:02:58 +00:00
|
|
|
nsAttrValue::SetTo(PRInt16 aInt)
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
ResetIfSet();
|
2005-01-25 00:02:58 +00:00
|
|
|
SetIntValueAndType(aInt, eInteger);
|
2004-02-10 09:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-04 02:06:28 +00:00
|
|
|
nsAttrValue::SetTo(nsICSSStyleRule* aValue)
|
2004-02-10 09:08:06 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
if (EnsureEmptyMiscContainer()) {
|
|
|
|
MiscContainer* cont = GetMiscContainer();
|
|
|
|
NS_ADDREF(cont->mCSSStyleRule = aValue);
|
|
|
|
cont->mType = eCSSStyleRule;
|
2004-02-10 09:08:06 +00:00
|
|
|
}
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
|
|
|
|
2004-03-09 08:44:53 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
void
|
|
|
|
nsAttrValue::SetTo(nsISVGValue* aValue)
|
|
|
|
{
|
|
|
|
if (EnsureEmptyMiscContainer()) {
|
|
|
|
MiscContainer* cont = GetMiscContainer();
|
|
|
|
NS_ADDREF(cont->mSVGValue = aValue);
|
|
|
|
cont->mType = eSVGValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
void
|
|
|
|
nsAttrValue::SwapValueWith(nsAttrValue& aOther)
|
|
|
|
{
|
|
|
|
PtrBits tmp = aOther.mBits;
|
|
|
|
aOther.mBits = mBits;
|
|
|
|
mBits = tmp;
|
|
|
|
}
|
|
|
|
|
2004-01-15 17:07:27 +00:00
|
|
|
void
|
|
|
|
nsAttrValue::ToString(nsAString& aResult) const
|
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
switch(Type()) {
|
2004-01-15 17:07:27 +00:00
|
|
|
case eString:
|
|
|
|
{
|
2005-02-02 22:58:01 +00:00
|
|
|
nsStringBuffer* str = NS_STATIC_CAST(nsStringBuffer*, GetPtr());
|
2004-01-15 17:07:27 +00:00
|
|
|
if (str) {
|
2005-02-02 22:58:01 +00:00
|
|
|
nsCheapStringBufferUtils::ToString(str, aResult);
|
2004-01-15 17:07:27 +00:00
|
|
|
}
|
2004-01-26 19:22:05 +00:00
|
|
|
else {
|
|
|
|
aResult.Truncate();
|
|
|
|
}
|
2004-01-15 17:07:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
case eAtom:
|
2004-01-15 17:07:27 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
NS_STATIC_CAST(nsIAtom*, GetPtr())->ToString(aResult);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eInteger:
|
|
|
|
{
|
|
|
|
nsAutoString intStr;
|
|
|
|
intStr.AppendInt(GetIntInternal());
|
|
|
|
aResult = intStr;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eColor:
|
|
|
|
{
|
|
|
|
nscolor v;
|
|
|
|
GetColorValue(v);
|
|
|
|
NS_RGBToHex(v, aResult);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eProportional:
|
|
|
|
{
|
|
|
|
nsAutoString intStr;
|
|
|
|
intStr.AppendInt(GetIntInternal());
|
|
|
|
aResult = intStr + NS_LITERAL_STRING("*");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eEnum:
|
|
|
|
{
|
2005-01-25 00:02:58 +00:00
|
|
|
PRInt16 val = GetEnumValue();
|
|
|
|
EnumTable* table = NS_STATIC_CAST(EnumTable*, sEnumTableArray->
|
|
|
|
FastElementAt(GetIntInternal() & NS_ATTRVALUE_ENUMTABLEINDEX_MASK));
|
|
|
|
while (table->tag) {
|
|
|
|
if (table->value == val) {
|
|
|
|
aResult.AssignASCII(table->tag);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
table++;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("couldn't find value in EnumTable");
|
2004-03-04 02:06:28 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ePercent:
|
|
|
|
{
|
|
|
|
nsAutoString intStr;
|
|
|
|
intStr.AppendInt(GetIntInternal());
|
|
|
|
aResult = intStr + NS_LITERAL_STRING("%");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSStyleRule:
|
|
|
|
{
|
2004-03-09 00:51:56 +00:00
|
|
|
aResult.Truncate();
|
2004-03-04 02:06:28 +00:00
|
|
|
nsCSSDeclaration* decl =
|
|
|
|
GetMiscContainer()->mCSSStyleRule->GetDeclaration();
|
|
|
|
if (decl) {
|
|
|
|
decl->ToString(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eAtomArray:
|
|
|
|
{
|
|
|
|
MiscContainer* cont = GetMiscContainer();
|
|
|
|
PRInt32 count = cont->mAtomArray->Count();
|
|
|
|
if (count) {
|
|
|
|
cont->mAtomArray->ObjectAt(0)->ToString(aResult);
|
|
|
|
nsAutoString tmp;
|
|
|
|
PRInt32 i;
|
|
|
|
for (i = 1; i < count; ++i) {
|
|
|
|
cont->mAtomArray->ObjectAt(i)->ToString(tmp);
|
|
|
|
aResult.Append(NS_LITERAL_STRING(" ") + tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aResult.Truncate();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-03-09 08:44:53 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
case eSVGValue:
|
|
|
|
{
|
|
|
|
GetMiscContainer()->mSVGValue->GetValueString(aResult);
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-04 02:06:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-02 22:58:01 +00:00
|
|
|
const nsCheapString
|
2004-01-26 19:22:05 +00:00
|
|
|
nsAttrValue::GetStringValue() const
|
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
NS_PRECONDITION(Type() == eString, "wrong type");
|
2004-01-26 19:22:05 +00:00
|
|
|
|
|
|
|
void* ptr = GetPtr();
|
2005-02-02 22:58:01 +00:00
|
|
|
return nsCheapStringBufferUtils::GetDependentString(NS_STATIC_CAST(nsStringBuffer*, ptr));
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
PRBool
|
|
|
|
nsAttrValue::GetColorValue(nscolor& aColor) const
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
NS_PRECONDITION(Type() == eColor || Type() == eString, "wrong type");
|
|
|
|
switch (BaseType()) {
|
|
|
|
case eString:
|
|
|
|
{
|
|
|
|
return GetPtr() && NS_ColorNameToRGB(GetStringValue(), &aColor);
|
|
|
|
}
|
|
|
|
case eOtherBase:
|
|
|
|
{
|
|
|
|
aColor = GetMiscContainer()->mColor;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eIntegerBase:
|
|
|
|
{
|
|
|
|
aColor = NS_STATIC_CAST(nscolor, GetIntInternal());
|
|
|
|
|
2004-03-04 18:04:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("unexpected basetype");
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-01-26 19:22:05 +00:00
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
return PR_TRUE;
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
|
|
|
|
2004-03-09 23:22:02 +00:00
|
|
|
PRInt32
|
|
|
|
nsAttrValue::GetAtomCount() const
|
|
|
|
{
|
|
|
|
ValueType type = Type();
|
|
|
|
|
|
|
|
if (type == eAtom) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == eAtomArray) {
|
|
|
|
return GetAtomArrayValue()->Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsAttrValue::AtomAt(PRInt32 aIndex) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aIndex >= 0, "Index must not be negative");
|
|
|
|
NS_PRECONDITION(GetAtomCount() > aIndex, "aIndex out of range");
|
|
|
|
|
|
|
|
if (BaseType() == eAtomBase) {
|
|
|
|
return GetAtomValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(Type() == eAtomArray, "GetAtomCount must be confused");
|
|
|
|
|
|
|
|
return GetAtomArrayValue()->ObjectAt(aIndex);
|
|
|
|
}
|
|
|
|
|
2004-01-26 19:22:05 +00:00
|
|
|
PRUint32
|
|
|
|
nsAttrValue::HashValue() const
|
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
switch(BaseType()) {
|
|
|
|
case eStringBase:
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2005-02-02 22:58:01 +00:00
|
|
|
nsStringBuffer* str = NS_STATIC_CAST(nsStringBuffer*, GetPtr());
|
2004-01-26 19:22:05 +00:00
|
|
|
return str ? nsCheapStringBufferUtils::HashCode(str) : 0;
|
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
case eOtherBase:
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
break;
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
case eAtomBase:
|
|
|
|
case eIntegerBase:
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
// mBits and PRUint32 might have different size. This should silence
|
|
|
|
// any warnings or compile-errors. This is what the implementation of
|
|
|
|
// NS_PTR_TO_INT32 does to take care of the same problem.
|
|
|
|
return mBits - 0;
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
MiscContainer* cont = GetMiscContainer();
|
|
|
|
switch (cont->mType) {
|
|
|
|
case eColor:
|
|
|
|
{
|
|
|
|
return cont->mColor;
|
|
|
|
}
|
|
|
|
case eCSSStyleRule:
|
|
|
|
{
|
|
|
|
return NS_PTR_TO_INT32(cont->mCSSStyleRule);
|
|
|
|
}
|
|
|
|
case eAtomArray:
|
|
|
|
{
|
|
|
|
PRUint32 retval = 0;
|
|
|
|
PRInt32 i, count = cont->mAtomArray->Count();
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
retval ^= NS_PTR_TO_INT32(cont->mAtomArray->ObjectAt(i));
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
2004-03-09 08:44:53 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
case eSVGValue:
|
|
|
|
{
|
|
|
|
return NS_PTR_TO_INT32(cont->mSVGValue);
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-04 02:06:28 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("unknown type stored in MiscContainer");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2004-02-02 22:00:36 +00:00
|
|
|
nsAttrValue::Equals(const nsAttrValue& aOther) const
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
if (BaseType() != aOther.BaseType()) {
|
2004-01-26 19:22:05 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
switch(BaseType()) {
|
|
|
|
case eStringBase:
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-02-02 22:00:36 +00:00
|
|
|
return GetStringValue().Equals(aOther.GetStringValue());
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
case eOtherBase:
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
break;
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
case eAtomBase:
|
|
|
|
case eIntegerBase:
|
2004-01-26 19:22:05 +00:00
|
|
|
{
|
2004-03-04 02:06:28 +00:00
|
|
|
return mBits == aOther.mBits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MiscContainer* thisCont = GetMiscContainer();
|
|
|
|
MiscContainer* otherCont = aOther.GetMiscContainer();
|
|
|
|
if (thisCont->mType != otherCont->mType) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (thisCont->mType) {
|
|
|
|
case eColor:
|
|
|
|
{
|
|
|
|
return thisCont->mColor == otherCont->mColor;
|
|
|
|
}
|
|
|
|
case eCSSStyleRule:
|
|
|
|
{
|
|
|
|
return thisCont->mCSSStyleRule == otherCont->mCSSStyleRule;
|
|
|
|
}
|
|
|
|
case eAtomArray:
|
|
|
|
{
|
|
|
|
// For classlists we could be insensitive to order, however
|
|
|
|
// classlists are never mapped attributes so they are never compared.
|
|
|
|
|
|
|
|
PRInt32 count = thisCont->mAtomArray->Count();
|
|
|
|
if (count != otherCont->mAtomArray->Count()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 i;
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
if (thisCont->mAtomArray->ObjectAt(i) !=
|
|
|
|
otherCont->mAtomArray->ObjectAt(i)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2004-03-09 08:44:53 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
case eSVGValue:
|
|
|
|
{
|
|
|
|
return thisCont->mSVGValue == otherCont->mSVGValue;
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-04 02:06:28 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("unknown type stored in MiscContainer");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAttrValue::ParseAtom(const nsAString& aValue)
|
|
|
|
{
|
|
|
|
ResetIfSet();
|
|
|
|
|
|
|
|
nsIAtom* atom = NS_NewAtom(aValue);
|
|
|
|
if (atom) {
|
|
|
|
SetPtrValueAndType(atom, eAtomBase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAttrValue::ParseAtomArray(const nsAString& aValue)
|
|
|
|
{
|
|
|
|
nsAString::const_iterator iter, end;
|
|
|
|
aValue.BeginReading(iter);
|
|
|
|
aValue.EndReading(end);
|
|
|
|
|
|
|
|
// skip initial whitespace
|
|
|
|
while (iter != end && nsCRT::IsAsciiSpace(*iter)) {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iter == end) {
|
|
|
|
ResetIfSet();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAString::const_iterator start(iter);
|
|
|
|
|
|
|
|
// get first - and often only - atom
|
|
|
|
do {
|
|
|
|
++iter;
|
|
|
|
} while (iter != end && !nsCRT::IsAsciiSpace(*iter));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> classAtom = do_GetAtom(Substring(start, iter));
|
|
|
|
if (!classAtom) {
|
|
|
|
Reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip whitespace
|
|
|
|
while (iter != end && nsCRT::IsAsciiSpace(*iter)) {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iter == end) {
|
|
|
|
// we only found one classname so don't bother storing a list
|
|
|
|
ResetIfSet();
|
|
|
|
nsIAtom* atom = nsnull;
|
|
|
|
classAtom.swap(atom);
|
|
|
|
SetPtrValueAndType(atom, eAtomBase);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureEmptyAtomArray()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMArray<nsIAtom>* array = GetAtomArrayValue();
|
|
|
|
|
|
|
|
if (!array->AppendObject(classAtom)) {
|
|
|
|
Reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the rest of the classnames
|
|
|
|
do {
|
|
|
|
start = iter;
|
|
|
|
|
|
|
|
do {
|
|
|
|
++iter;
|
|
|
|
} while (iter != end && !nsCRT::IsAsciiSpace(*iter));
|
|
|
|
|
|
|
|
classAtom = do_GetAtom(Substring(start, iter));
|
|
|
|
|
|
|
|
if (!array->AppendObject(classAtom)) {
|
|
|
|
Reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip whitespace
|
|
|
|
while (iter != end && nsCRT::IsAsciiSpace(*iter)) {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
} while (iter != end);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAttrValue::ParseStringOrAtom(const nsAString& aValue)
|
|
|
|
{
|
|
|
|
PRUint32 len = aValue.Length();
|
|
|
|
// Don't bother with atoms if it's an empty string since
|
|
|
|
// we can store those efficently anyway.
|
|
|
|
if (len && len <= NS_ATTRVALUE_MAX_STRINGLENGTH_ATOM) {
|
|
|
|
ParseAtom(aValue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SetTo(aValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsAttrValue::ParseEnumValue(const nsAString& aValue,
|
2005-01-25 00:02:58 +00:00
|
|
|
const EnumTable* aTable,
|
2004-03-04 02:06:28 +00:00
|
|
|
PRBool aCaseSensitive)
|
|
|
|
{
|
2004-04-30 22:03:09 +00:00
|
|
|
ResetIfSet();
|
|
|
|
|
2005-01-25 00:02:58 +00:00
|
|
|
// Have to const cast here since nsVoidArray can't deal with constpointers
|
|
|
|
EnumTable* tableStart = NS_CONST_CAST(EnumTable*, aTable);
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
nsAutoString val(aValue);
|
|
|
|
while (aTable->tag) {
|
2004-07-21 20:18:39 +00:00
|
|
|
if (aCaseSensitive ? val.EqualsASCII(aTable->tag) :
|
2004-03-04 02:06:28 +00:00
|
|
|
val.EqualsIgnoreCase(aTable->tag)) {
|
2005-01-25 00:02:58 +00:00
|
|
|
|
|
|
|
// Find index of EnumTable
|
|
|
|
PRInt16 index = sEnumTableArray->IndexOf(tableStart);
|
|
|
|
if (index < 0) {
|
|
|
|
index = sEnumTableArray->Count();
|
|
|
|
NS_ASSERTION(index <= NS_ATTRVALUE_ENUMTABLEINDEX_MAXVALUE,
|
|
|
|
"too many enum tables");
|
|
|
|
if (!sEnumTableArray->AppendElement(tableStart)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 value = (aTable->value << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) +
|
|
|
|
index;
|
|
|
|
|
|
|
|
SetIntValueAndType(value, eEnum);
|
|
|
|
NS_ASSERTION(GetEnumValue() == aTable->value,
|
|
|
|
"failed to store enum properly");
|
2004-03-04 02:06:28 +00:00
|
|
|
|
|
|
|
return PR_TRUE;
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
aTable++;
|
2004-01-26 19:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsAttrValue::ParseSpecialIntValue(const nsAString& aString,
|
|
|
|
PRBool aCanBePercent,
|
|
|
|
PRBool aCanBeProportional)
|
|
|
|
{
|
2004-04-30 22:03:09 +00:00
|
|
|
ResetIfSet();
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
PRInt32 ec;
|
|
|
|
nsAutoString tmp(aString);
|
|
|
|
PRInt32 val = tmp.ToInteger(&ec);
|
|
|
|
|
2004-03-26 01:44:44 +00:00
|
|
|
if (NS_FAILED(ec)) {
|
|
|
|
if (aCanBeProportional) {
|
|
|
|
// Even if the integer could not be parsed, it might just be "*"
|
|
|
|
tmp.CompressWhitespace(PR_TRUE, PR_TRUE);
|
|
|
|
if (tmp.Length() == 1 && tmp.Last() == '*') {
|
|
|
|
// special case: HTML spec says a value '*' == '1*'
|
|
|
|
// see http://www.w3.org/TR/html4/types.html#type-multi-length
|
|
|
|
// bug 29061
|
|
|
|
SetIntValueAndType(1, eProportional);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2004-03-04 02:06:28 +00:00
|
|
|
}
|
2004-03-26 01:44:44 +00:00
|
|
|
return PR_FALSE;
|
2004-03-04 02:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
val = PR_MAX(val, 0);
|
|
|
|
val = PR_MIN(val, NS_ATTRVALUE_INTEGERTYPE_MAXVALUE);
|
|
|
|
|
|
|
|
// % (percent)
|
|
|
|
// XXX RFindChar means that 5%x will be parsed!
|
|
|
|
if (aCanBePercent && tmp.RFindChar('%') >= 0) {
|
|
|
|
if (val > 100) {
|
|
|
|
val = 100;
|
|
|
|
}
|
|
|
|
SetIntValueAndType(val, ePercent);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// * (proportional)
|
|
|
|
// XXX RFindChar means that 5*x will be parsed!
|
|
|
|
if (aCanBeProportional && tmp.RFindChar('*') >= 0) {
|
|
|
|
SetIntValueAndType(val, eProportional);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Straight number is interpreted as integer
|
|
|
|
SetIntValueAndType(val, eInteger);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsAttrValue::ParseIntWithBounds(const nsAString& aString,
|
|
|
|
PRInt32 aMin, PRInt32 aMax)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aMin < aMax &&
|
|
|
|
aMin >= NS_ATTRVALUE_INTEGERTYPE_MINVALUE &&
|
|
|
|
aMax <= NS_ATTRVALUE_INTEGERTYPE_MAXVALUE, "bad boundaries");
|
|
|
|
|
2004-04-30 22:03:09 +00:00
|
|
|
ResetIfSet();
|
|
|
|
|
2004-03-04 02:06:28 +00:00
|
|
|
PRInt32 ec;
|
|
|
|
PRInt32 val = PromiseFlatString(aString).ToInteger(&ec);
|
|
|
|
if (NS_FAILED(ec)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = PR_MAX(val, aMin);
|
|
|
|
val = PR_MIN(val, aMax);
|
|
|
|
SetIntValueAndType(val, eInteger);
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsAttrValue::ParseColor(const nsAString& aString, nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
nsAutoString colorStr(aString);
|
|
|
|
colorStr.CompressWhitespace(PR_TRUE, PR_TRUE);
|
|
|
|
if (colorStr.IsEmpty()) {
|
2004-04-30 22:03:09 +00:00
|
|
|
Reset();
|
2004-03-04 02:06:28 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscolor color;
|
|
|
|
// No color names begin with a '#', but numerical colors do so
|
|
|
|
// it is a very common first char
|
|
|
|
if ((colorStr.CharAt(0) != '#') && NS_ColorNameToRGB(colorStr, &color)) {
|
|
|
|
SetTo(colorStr);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we are in compatibility mode
|
|
|
|
// XXX evil NS_HexToRGB and NS_LooseHexToRGB take nsString as argument!
|
|
|
|
nsCOMPtr<nsIHTMLDocument> doc(do_QueryInterface(aDocument));
|
|
|
|
if (doc && doc->GetCompatibilityMode() == eCompatibility_NavQuirks) {
|
|
|
|
NS_LooseHexToRGB(colorStr, &color);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (colorStr.First() != '#') {
|
2004-04-30 22:03:09 +00:00
|
|
|
Reset();
|
2004-03-04 02:06:28 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
colorStr.Cut(0, 1);
|
|
|
|
if (!NS_HexToRGB(colorStr, &color)) {
|
2004-04-30 22:03:09 +00:00
|
|
|
Reset();
|
2004-03-04 02:06:28 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 colAsInt = NS_STATIC_CAST(PRInt32, color);
|
|
|
|
PRInt32 tmp = colAsInt * NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER;
|
|
|
|
if (tmp / NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER == colAsInt) {
|
|
|
|
ResetIfSet();
|
|
|
|
SetIntValueAndType(colAsInt, eColor);
|
|
|
|
}
|
|
|
|
else if (EnsureEmptyMiscContainer()) {
|
|
|
|
MiscContainer* cont = GetMiscContainer();
|
|
|
|
cont->mColor = color;
|
|
|
|
cont->mType = eColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsAttrValue::EnsureEmptyMiscContainer()
|
|
|
|
{
|
|
|
|
MiscContainer* cont;
|
|
|
|
if (BaseType() == eOtherBase) {
|
|
|
|
cont = GetMiscContainer();
|
|
|
|
switch (cont->mType) {
|
|
|
|
case eCSSStyleRule:
|
|
|
|
{
|
|
|
|
NS_RELEASE(cont->mCSSStyleRule);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eAtomArray:
|
|
|
|
{
|
|
|
|
delete cont->mAtomArray;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-20 12:19:16 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
case eSVGValue:
|
|
|
|
{
|
|
|
|
NS_RELEASE(cont->mSVGValue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-04 02:06:28 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ResetIfSet();
|
|
|
|
|
|
|
|
cont = new MiscContainer;
|
|
|
|
NS_ENSURE_TRUE(cont, PR_FALSE);
|
|
|
|
|
|
|
|
SetPtrValueAndType(cont, eOtherBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
cont->mType = eColor;
|
|
|
|
cont->mColor = 0;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsAttrValue::EnsureEmptyAtomArray()
|
|
|
|
{
|
|
|
|
if (Type() == eAtomArray) {
|
|
|
|
GetAtomArrayValue()->Clear();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureEmptyMiscContainer()) {
|
|
|
|
// should already be reset
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMArray<nsIAtom>* array = new nsCOMArray<nsIAtom>;
|
|
|
|
if (!array) {
|
|
|
|
Reset();
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MiscContainer* cont = GetMiscContainer();
|
|
|
|
cont->mAtomArray = array;
|
|
|
|
cont->mType = eAtomArray;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|