Make nsHTMLValue store embedded nulls (r=sicking@netscape.com, sr=bzbarsky@mit.edu, sr=jaggernaut@netscape.com
git-svn-id: svn://10.0.0.236/trunk@130511 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -42,12 +42,13 @@
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsMemory.h"
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nsHTMLUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
NS_ASSERTION((aUnit <= eHTMLUnit_Empty), "not a valueless unit");
|
||||
if (aUnit > eHTMLUnit_Empty) {
|
||||
NS_ASSERTION(GetUnitClass() == HTMLUNIT_NOSTORE, "not a valueless unit");
|
||||
if (GetUnitClass() != HTMLUNIT_NOSTORE) {
|
||||
mUnit = eHTMLUnit_Null;
|
||||
}
|
||||
mValue.mString = nsnull;
|
||||
@@ -56,19 +57,14 @@ nsHTMLValue::nsHTMLValue(nsHTMLUnit aUnit)
|
||||
nsHTMLValue::nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
NS_ASSERTION((eHTMLUnit_Integer == aUnit) ||
|
||||
(eHTMLUnit_Enumerated == aUnit) ||
|
||||
(eHTMLUnit_Proportional == aUnit) ||
|
||||
(eHTMLUnit_Pixel == aUnit), "not an integer value");
|
||||
if ((eHTMLUnit_Integer == aUnit) ||
|
||||
(eHTMLUnit_Enumerated == aUnit) ||
|
||||
(eHTMLUnit_Proportional == aUnit) ||
|
||||
(eHTMLUnit_Pixel == aUnit)) {
|
||||
NS_ASSERTION(GetUnitClass() == HTMLUNIT_INTEGER ||
|
||||
GetUnitClass() == HTMLUNIT_PIXEL, "unit not an integer unit");
|
||||
if (GetUnitClass() == HTMLUNIT_INTEGER ||
|
||||
GetUnitClass() == HTMLUNIT_PIXEL) {
|
||||
mValue.mInt = aValue;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mUnit = eHTMLUnit_Null;
|
||||
mValue.mInt = 0;
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,16 +77,7 @@ nsHTMLValue::nsHTMLValue(float aValue)
|
||||
nsHTMLValue::nsHTMLValue(const nsAString& aValue, nsHTMLUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
NS_ASSERTION((eHTMLUnit_String == aUnit) ||
|
||||
(eHTMLUnit_ColorName == aUnit), "not a string value");
|
||||
if ((eHTMLUnit_String == aUnit) ||
|
||||
(eHTMLUnit_ColorName == aUnit)) {
|
||||
mValue.mString = ToNewUnicode(aValue);
|
||||
}
|
||||
else {
|
||||
mUnit = eHTMLUnit_Null;
|
||||
mValue.mInt = 0;
|
||||
}
|
||||
SetStringValueInternal(aValue, aUnit);
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nsISupports* aValue)
|
||||
@@ -107,29 +94,8 @@ nsHTMLValue::nsHTMLValue(nscolor aValue)
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(const nsHTMLValue& aCopy)
|
||||
: mUnit(aCopy.mUnit)
|
||||
{
|
||||
if ((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) {
|
||||
if (nsnull != aCopy.mValue.mString) {
|
||||
mValue.mString = nsCRT::strdup(aCopy.mValue.mString);
|
||||
}
|
||||
else {
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
mValue.mISupports = aCopy.mValue.mISupports;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
mValue.mColor = aCopy.mValue.mColor;
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
mValue.mFloat = aCopy.mValue.mFloat;
|
||||
}
|
||||
else {
|
||||
mValue.mInt = aCopy.mValue.mInt;
|
||||
}
|
||||
InitializeFrom(aCopy);
|
||||
}
|
||||
|
||||
nsHTMLValue::~nsHTMLValue(void)
|
||||
@@ -140,76 +106,69 @@ nsHTMLValue::~nsHTMLValue(void)
|
||||
nsHTMLValue& nsHTMLValue::operator=(const nsHTMLValue& aCopy)
|
||||
{
|
||||
Reset();
|
||||
mUnit = aCopy.mUnit;
|
||||
if ((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) {
|
||||
if (nsnull != aCopy.mValue.mString) {
|
||||
mValue.mString = nsCRT::strdup(aCopy.mValue.mString);
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
mValue.mISupports = aCopy.mValue.mISupports;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
mValue.mColor = aCopy.mValue.mColor;
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
mValue.mFloat = aCopy.mValue.mFloat;
|
||||
}
|
||||
else {
|
||||
mValue.mInt = aCopy.mValue.mInt;
|
||||
}
|
||||
InitializeFrom(aCopy);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PRBool nsHTMLValue::operator==(const nsHTMLValue& aOther) const
|
||||
{
|
||||
if (mUnit == aOther.mUnit) {
|
||||
if ((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) {
|
||||
if (nsnull == mValue.mString) {
|
||||
if (nsnull == aOther.mValue.mString) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
else if (nsnull != aOther.mValue.mString) {
|
||||
return nsDependentString(mValue.mString).Equals(nsDependentString(aOther.mValue.mString),
|
||||
nsCaseInsensitiveStringComparator());
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
return PRBool(mValue.mISupports == aOther.mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
return PRBool(mValue.mColor == aOther.mValue.mColor);
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
return PRBool(mValue.mFloat == aOther.mValue.mFloat);
|
||||
}
|
||||
else {
|
||||
return PRBool(mValue.mInt == aOther.mValue.mInt);
|
||||
}
|
||||
if (mUnit != aOther.mUnit) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
// Call GetUnitClass() so that we turn StringWithLength into String
|
||||
PRUint32 unitClass = GetUnitClass();
|
||||
switch (unitClass) {
|
||||
case HTMLUNIT_NOSTORE:
|
||||
return PR_TRUE;
|
||||
|
||||
case HTMLUNIT_STRING:
|
||||
if (mValue.mString && aOther.mValue.mString) {
|
||||
return GetDependentString().Equals(aOther.GetDependentString(),
|
||||
nsCaseInsensitiveStringComparator());
|
||||
}
|
||||
// One of them is null. An == check will see if they are both null.
|
||||
return mValue.mString == aOther.mValue.mString;
|
||||
|
||||
case HTMLUNIT_INTEGER:
|
||||
case HTMLUNIT_PIXEL:
|
||||
return mValue.mInt == aOther.mValue.mInt;
|
||||
|
||||
case HTMLUNIT_COLOR:
|
||||
return mValue.mColor == aOther.mValue.mColor;
|
||||
|
||||
case HTMLUNIT_ISUPPORTS:
|
||||
return mValue.mISupports == aOther.mValue.mISupports;
|
||||
|
||||
case HTMLUNIT_PERCENT:
|
||||
return mValue.mFloat == aOther.mValue.mFloat;
|
||||
|
||||
default:
|
||||
NS_WARNING("Unknown unit");
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRUint32 nsHTMLValue::HashValue(void) const
|
||||
{
|
||||
return PRUint32(mUnit) ^
|
||||
((((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) &&
|
||||
(nsnull != mValue.mString)) ?
|
||||
nsCRT::HashCode(mValue.mString) :
|
||||
mValue.mInt);
|
||||
PRUint32 retval;
|
||||
if (GetUnitClass() == HTMLUNIT_STRING) {
|
||||
retval = mValue.mString ? nsCheapStringBufferUtils::HashCode(mValue.mString)
|
||||
: 0;
|
||||
} else {
|
||||
retval = mValue.mInt;
|
||||
}
|
||||
return retval ^ PRUint32(mUnit);
|
||||
}
|
||||
|
||||
|
||||
void nsHTMLValue::Reset(void)
|
||||
{
|
||||
if ((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) {
|
||||
if (nsnull != mValue.mString) {
|
||||
nsCRT::free(mValue.mString);
|
||||
if (GetUnitClass() == HTMLUNIT_STRING) {
|
||||
if (mValue.mString) {
|
||||
nsCheapStringBufferUtils::Free(mValue.mString);
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
else if (mUnit == eHTMLUnit_ISupports) {
|
||||
NS_IF_RELEASE(mValue.mISupports);
|
||||
}
|
||||
mUnit = eHTMLUnit_Null;
|
||||
@@ -220,14 +179,12 @@ void nsHTMLValue::Reset(void)
|
||||
void nsHTMLValue::SetIntValue(PRInt32 aValue, nsHTMLUnit aUnit)
|
||||
{
|
||||
Reset();
|
||||
NS_ASSERTION((eHTMLUnit_Integer == aUnit) ||
|
||||
(eHTMLUnit_Enumerated == aUnit) ||
|
||||
(eHTMLUnit_Proportional == aUnit), "not an int value");
|
||||
if ((eHTMLUnit_Integer == aUnit) ||
|
||||
(eHTMLUnit_Enumerated == aUnit) ||
|
||||
(eHTMLUnit_Proportional == aUnit)) {
|
||||
mUnit = aUnit;
|
||||
mUnit = aUnit;
|
||||
NS_ASSERTION(GetUnitClass() == HTMLUNIT_INTEGER, "not an int value");
|
||||
if (GetUnitClass() == HTMLUNIT_INTEGER) {
|
||||
mValue.mInt = aValue;
|
||||
} else {
|
||||
mUnit = eHTMLUnit_Null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,14 +202,29 @@ void nsHTMLValue::SetPercentValue(float aValue)
|
||||
mValue.mFloat = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::SetStringValueInternal(const nsAString& aValue,
|
||||
nsHTMLUnit aUnit)
|
||||
{
|
||||
NS_ASSERTION(GetUnitClass() == HTMLUNIT_STRING, "unit not a string unit!");
|
||||
if (GetUnitClass() == HTMLUNIT_STRING) {
|
||||
// Remember the length of the string if necessary
|
||||
if (aValue.IsEmpty()) {
|
||||
mValue.mString = nsnull;
|
||||
} else {
|
||||
nsCheapStringBufferUtils::CopyToBuffer(mValue.mString, aValue);
|
||||
}
|
||||
} else {
|
||||
mUnit = eHTMLUnit_Null;
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
void nsHTMLValue::SetStringValue(const nsAString& aValue,
|
||||
nsHTMLUnit aUnit)
|
||||
{
|
||||
Reset();
|
||||
if ((eHTMLUnit_String == aUnit) || (eHTMLUnit_ColorName == aUnit)) {
|
||||
mUnit = aUnit;
|
||||
mValue.mString = ToNewUnicode(aValue);
|
||||
}
|
||||
mUnit = aUnit;
|
||||
SetStringValueInternal(aValue, aUnit);
|
||||
}
|
||||
|
||||
void nsHTMLValue::SetISupportsValue(nsISupports* aValue)
|
||||
@@ -279,70 +251,130 @@ void nsHTMLValue::SetEmptyValue(void)
|
||||
#ifdef DEBUG
|
||||
void nsHTMLValue::AppendToString(nsAString& aBuffer) const
|
||||
{
|
||||
if (eHTMLUnit_Null == mUnit) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (eHTMLUnit_Empty == mUnit) {
|
||||
}
|
||||
else if ((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) {
|
||||
if (nsnull != mValue.mString) {
|
||||
switch (GetUnitClass()) {
|
||||
case HTMLUNIT_NOSTORE:
|
||||
break;
|
||||
case HTMLUNIT_STRING:
|
||||
aBuffer.Append(PRUnichar('"'));
|
||||
aBuffer.Append(mValue.mString);
|
||||
aBuffer.Append(GetDependentString());
|
||||
aBuffer.Append(PRUnichar('"'));
|
||||
}
|
||||
else {
|
||||
aBuffer.Append(NS_LITERAL_STRING("null str"));
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
aBuffer.Append(NS_LITERAL_STRING("0x"));
|
||||
nsAutoString intStr;
|
||||
intStr.AppendInt(NS_PTR_TO_INT32(mValue.mISupports), 16);
|
||||
aBuffer.Append(intStr);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
nsAutoString intStr;
|
||||
intStr.Append(NS_LITERAL_STRING("(0x"));
|
||||
intStr.AppendInt(NS_GET_R(mValue.mColor), 16);
|
||||
intStr.Append(NS_LITERAL_STRING(" 0x"));
|
||||
intStr.AppendInt(NS_GET_G(mValue.mColor), 16);
|
||||
intStr.Append(NS_LITERAL_STRING(" 0x"));
|
||||
intStr.AppendInt(NS_GET_B(mValue.mColor), 16);
|
||||
intStr.Append(NS_LITERAL_STRING(" 0x"));
|
||||
intStr.AppendInt(NS_GET_A(mValue.mColor), 16);
|
||||
intStr.Append(PRUnichar(')'));
|
||||
break;
|
||||
case HTMLUNIT_INTEGER:
|
||||
case HTMLUNIT_PIXEL:
|
||||
{
|
||||
nsAutoString intStr;
|
||||
intStr.AppendInt(mValue.mInt, 10);
|
||||
intStr.Append(NS_LITERAL_STRING("[0x"));
|
||||
intStr.AppendInt(mValue.mInt, 16);
|
||||
intStr.Append(PRUnichar(']'));
|
||||
|
||||
aBuffer.Append(intStr);
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
nsAutoString floatStr;
|
||||
floatStr.AppendFloat(mValue.mFloat * 100.0f);
|
||||
aBuffer.Append(floatStr);
|
||||
}
|
||||
else {
|
||||
nsAutoString intStr;
|
||||
intStr.AppendInt(mValue.mInt, 10);
|
||||
intStr.Append(NS_LITERAL_STRING("[0x"));
|
||||
intStr.AppendInt(mValue.mInt, 16);
|
||||
intStr.Append(PRUnichar(']'));
|
||||
aBuffer.Append(intStr);
|
||||
}
|
||||
break;
|
||||
case HTMLUNIT_COLOR:
|
||||
{
|
||||
nsAutoString intStr;
|
||||
intStr.Append(NS_LITERAL_STRING("(0x"));
|
||||
intStr.AppendInt(NS_GET_R(mValue.mColor), 16);
|
||||
intStr.Append(NS_LITERAL_STRING(" 0x"));
|
||||
intStr.AppendInt(NS_GET_G(mValue.mColor), 16);
|
||||
intStr.Append(NS_LITERAL_STRING(" 0x"));
|
||||
intStr.AppendInt(NS_GET_B(mValue.mColor), 16);
|
||||
intStr.Append(NS_LITERAL_STRING(" 0x"));
|
||||
intStr.AppendInt(NS_GET_A(mValue.mColor), 16);
|
||||
intStr.Append(PRUnichar(')'));
|
||||
|
||||
aBuffer.Append(intStr);
|
||||
aBuffer.Append(intStr);
|
||||
}
|
||||
break;
|
||||
case HTMLUNIT_ISUPPORTS:
|
||||
{
|
||||
aBuffer.Append(NS_LITERAL_STRING("0x"));
|
||||
nsAutoString intStr;
|
||||
intStr.AppendInt(NS_PTR_TO_INT32(mValue.mISupports), 16);
|
||||
aBuffer.Append(intStr);
|
||||
}
|
||||
break;
|
||||
case HTMLUNIT_PERCENT:
|
||||
{
|
||||
nsAutoString floatStr;
|
||||
floatStr.AppendFloat(mValue.mFloat * 100.0f);
|
||||
aBuffer.Append(floatStr);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
NS_ERROR("Unknown HTMLValue type!");
|
||||
}
|
||||
|
||||
//
|
||||
// Append the type name for types that are ambiguous
|
||||
//
|
||||
switch (mUnit) {
|
||||
case eHTMLUnit_Null: break;
|
||||
case eHTMLUnit_Empty: break;
|
||||
case eHTMLUnit_String: break;
|
||||
case eHTMLUnit_ColorName: break;
|
||||
case eHTMLUnit_ISupports: aBuffer.Append(NS_LITERAL_STRING("ptr")); break;
|
||||
case eHTMLUnit_Integer: break;
|
||||
case eHTMLUnit_Enumerated: aBuffer.Append(NS_LITERAL_STRING("enum")); break;
|
||||
case eHTMLUnit_Proportional: aBuffer.Append(NS_LITERAL_STRING("*")); break;
|
||||
case eHTMLUnit_Color: aBuffer.Append(NS_LITERAL_STRING("rbga")); break;
|
||||
case eHTMLUnit_Percent: aBuffer.Append(NS_LITERAL_STRING("%")); break;
|
||||
case eHTMLUnit_Pixel: aBuffer.Append(NS_LITERAL_STRING("px")); break;
|
||||
case eHTMLUnit_Null:
|
||||
aBuffer.Append(NS_LITERAL_STRING("null"));
|
||||
break;
|
||||
case eHTMLUnit_Empty:
|
||||
aBuffer.Append(NS_LITERAL_STRING("empty"));
|
||||
break;
|
||||
case eHTMLUnit_ISupports:
|
||||
aBuffer.Append(NS_LITERAL_STRING("ptr"));
|
||||
break;
|
||||
case eHTMLUnit_Enumerated:
|
||||
aBuffer.Append(NS_LITERAL_STRING("enum"));
|
||||
break;
|
||||
case eHTMLUnit_Proportional:
|
||||
aBuffer.Append(NS_LITERAL_STRING("*"));
|
||||
break;
|
||||
case eHTMLUnit_Color:
|
||||
aBuffer.Append(NS_LITERAL_STRING("rbga"));
|
||||
break;
|
||||
case eHTMLUnit_Percent:
|
||||
aBuffer.Append(NS_LITERAL_STRING("%"));
|
||||
break;
|
||||
case eHTMLUnit_Pixel:
|
||||
aBuffer.Append(NS_LITERAL_STRING("px"));
|
||||
break;
|
||||
}
|
||||
aBuffer.Append(PRUnichar(' '));
|
||||
}
|
||||
#endif // DEBUG
|
||||
|
||||
void
|
||||
nsHTMLValue::InitializeFrom(const nsHTMLValue& aCopy)
|
||||
{
|
||||
mUnit = aCopy.mUnit;
|
||||
switch (GetUnitClass()) {
|
||||
case HTMLUNIT_NOSTORE:
|
||||
mValue.mString = nsnull;
|
||||
break;
|
||||
|
||||
case HTMLUNIT_STRING:
|
||||
if (aCopy.mValue.mString) {
|
||||
nsCheapStringBufferUtils::Clone(mValue.mString, aCopy.mValue.mString);
|
||||
} else {
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
break;
|
||||
|
||||
case HTMLUNIT_INTEGER:
|
||||
case HTMLUNIT_PIXEL:
|
||||
mValue.mInt = aCopy.mValue.mInt;
|
||||
break;
|
||||
|
||||
case HTMLUNIT_COLOR:
|
||||
mValue.mColor = aCopy.mValue.mColor;
|
||||
break;
|
||||
|
||||
case HTMLUNIT_ISUPPORTS:
|
||||
mValue.mISupports = aCopy.mValue.mISupports;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
break;
|
||||
|
||||
case HTMLUNIT_PERCENT:
|
||||
mValue.mFloat = aCopy.mValue.mFloat;
|
||||
break;
|
||||
|
||||
default:
|
||||
NS_ERROR("Unknown HTMLValue type!");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user