зеркало из https://github.com/mozilla/pjs.git
Bug 232706: Make nsAttrValue able to directly store all needed datatypes without using nsHTMLValue. Move parsing of various types from nsHTMLValue to nsAttrValue. Rename StringToAttribute to ParseAttribute and make it return a PRBool, as well as make a couple of minor fixes in the ParseAttribute code.
r=caillon sr=jst
This commit is contained in:
Родитель
91b5d2801c
Коммит
050843a6e0
|
@ -40,6 +40,10 @@
|
|||
#include "nsHTMLValue.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsICSSStyleRule.h"
|
||||
#include "nsCSSDeclaration.h"
|
||||
#include "nsIHTMLDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
|
||||
nsAttrValue::nsAttrValue()
|
||||
: mBits(0)
|
||||
|
@ -58,13 +62,7 @@ nsAttrValue::nsAttrValue(const nsAString& aValue)
|
|||
SetTo(aValue);
|
||||
}
|
||||
|
||||
nsAttrValue::nsAttrValue(const nsHTMLValue& aValue)
|
||||
: mBits(0)
|
||||
{
|
||||
SetTo(aValue);
|
||||
}
|
||||
|
||||
nsAttrValue::nsAttrValue(nsIAtom* aValue)
|
||||
nsAttrValue::nsAttrValue(nsICSSStyleRule* aValue)
|
||||
: mBits(0)
|
||||
{
|
||||
SetTo(aValue);
|
||||
|
@ -72,31 +70,57 @@ nsAttrValue::nsAttrValue(nsIAtom* aValue)
|
|||
|
||||
nsAttrValue::~nsAttrValue()
|
||||
{
|
||||
Reset();
|
||||
ResetIfSet();
|
||||
}
|
||||
|
||||
nsAttrValue::ValueType
|
||||
nsAttrValue::Type() const
|
||||
{
|
||||
switch (BaseType()) {
|
||||
case eIntegerBase:
|
||||
{
|
||||
return NS_STATIC_CAST(ValueType, mBits & NS_ATTRVALUE_INTEGERTYPE_MASK);
|
||||
}
|
||||
case eOtherBase:
|
||||
{
|
||||
return GetMiscContainer()->mType;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return NS_STATIC_CAST(ValueType, BaseType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsAttrValue::Reset()
|
||||
{
|
||||
void* ptr = GetPtr();
|
||||
switch(GetType()) {
|
||||
case eString:
|
||||
switch(BaseType()) {
|
||||
case eStringBase:
|
||||
{
|
||||
PRUnichar* str = NS_STATIC_CAST(PRUnichar*, ptr);
|
||||
PRUnichar* str = NS_STATIC_CAST(PRUnichar*, GetPtr());
|
||||
if (str) {
|
||||
nsCheapStringBufferUtils::Free(str);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case eHTMLValue:
|
||||
case eOtherBase:
|
||||
{
|
||||
delete NS_STATIC_CAST(nsHTMLValue*, ptr);
|
||||
EnsureEmptyMiscContainer();
|
||||
delete GetMiscContainer();
|
||||
|
||||
break;
|
||||
}
|
||||
case eAtom:
|
||||
case eAtomBase:
|
||||
{
|
||||
nsIAtom* atom = NS_STATIC_CAST(nsIAtom*, ptr);
|
||||
nsIAtom* atom = GetAtomValue();
|
||||
NS_RELEASE(atom);
|
||||
|
||||
break;
|
||||
}
|
||||
case eIntegerBase:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -107,20 +131,59 @@ nsAttrValue::Reset()
|
|||
void
|
||||
nsAttrValue::SetTo(const nsAttrValue& aOther)
|
||||
{
|
||||
switch (aOther.GetType()) {
|
||||
case eString:
|
||||
switch (aOther.BaseType()) {
|
||||
case eStringBase:
|
||||
{
|
||||
SetTo(aOther.GetStringValue());
|
||||
return;
|
||||
}
|
||||
case eOtherBase:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case eHTMLValue:
|
||||
case eAtomBase:
|
||||
{
|
||||
SetTo(*aOther.GetHTMLValue());
|
||||
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;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case eAtom:
|
||||
case eCSSStyleRule:
|
||||
{
|
||||
SetTo(aOther.GetAtomValue());
|
||||
SetTo(otherCont->mCSSStyleRule);
|
||||
break;
|
||||
}
|
||||
case eAtomArray:
|
||||
{
|
||||
if (!EnsureEmptyAtomArray() ||
|
||||
!GetAtomArrayValue()->AppendObjects(*otherCont->mAtomArray)) {
|
||||
Reset();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
NS_NOTREACHED("unknown type stored in MiscContainer");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +195,7 @@ nsAttrValue::SetTo(const nsAString& aValue)
|
|||
PRUnichar* str = nsnull;
|
||||
PRBool empty = aValue.IsEmpty();
|
||||
void* ptr;
|
||||
if (GetType() == eString && (ptr = GetPtr())) {
|
||||
if (BaseType() == eStringBase && (ptr = GetPtr())) {
|
||||
if (!empty) {
|
||||
nsCheapStringBufferUtils::
|
||||
CopyToExistingBuffer(str, NS_STATIC_CAST(PRUnichar*, ptr), aValue);
|
||||
|
@ -142,47 +205,28 @@ nsAttrValue::SetTo(const nsAString& aValue)
|
|||
}
|
||||
}
|
||||
else {
|
||||
Reset();
|
||||
ResetIfSet();
|
||||
if (!empty) {
|
||||
nsCheapStringBufferUtils::CopyToBuffer(str, aValue);
|
||||
}
|
||||
}
|
||||
SetValueAndType(str, eString);
|
||||
SetPtrValueAndType(str, eStringBase);
|
||||
}
|
||||
|
||||
void
|
||||
nsAttrValue::SetTo(const nsHTMLValue& aValue)
|
||||
nsAttrValue::SetTo(PRInt16 aInt, ValueType aType)
|
||||
{
|
||||
Reset();
|
||||
nsHTMLValue* htmlValue = new nsHTMLValue(aValue);
|
||||
if (htmlValue) {
|
||||
SetValueAndType(htmlValue, eHTMLValue);
|
||||
}
|
||||
ResetIfSet();
|
||||
SetIntValueAndType(aInt, aType);
|
||||
}
|
||||
|
||||
void
|
||||
nsAttrValue::SetTo(nsIAtom* aValue)
|
||||
nsAttrValue::SetTo(nsICSSStyleRule* aValue)
|
||||
{
|
||||
NS_ASSERTION(aValue, "null value in nsAttrValue::SetTo");
|
||||
Reset();
|
||||
NS_ADDREF(aValue);
|
||||
SetValueAndType(aValue, eAtom);
|
||||
}
|
||||
|
||||
void
|
||||
nsAttrValue::SetToStringOrAtom(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) {
|
||||
nsCOMPtr<nsIAtom> atom = do_GetAtom(aValue);
|
||||
if (atom) {
|
||||
SetTo(atom);
|
||||
}
|
||||
}
|
||||
else {
|
||||
SetTo(aValue);
|
||||
if (EnsureEmptyMiscContainer()) {
|
||||
MiscContainer* cont = GetMiscContainer();
|
||||
NS_ADDREF(cont->mCSSStyleRule = aValue);
|
||||
cont->mType = eCSSStyleRule;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,12 +241,10 @@ nsAttrValue::SwapValueWith(nsAttrValue& aOther)
|
|||
void
|
||||
nsAttrValue::ToString(nsAString& aResult) const
|
||||
{
|
||||
void* ptr = GetPtr();
|
||||
|
||||
switch(GetType()) {
|
||||
switch(Type()) {
|
||||
case eString:
|
||||
{
|
||||
PRUnichar* str = NS_STATIC_CAST(PRUnichar*, ptr);
|
||||
PRUnichar* str = NS_STATIC_CAST(PRUnichar*, GetPtr());
|
||||
if (str) {
|
||||
aResult = nsCheapStringBufferUtils::GetDependentString(str);
|
||||
}
|
||||
|
@ -211,14 +253,136 @@ nsAttrValue::ToString(nsAString& aResult) const
|
|||
}
|
||||
break;
|
||||
}
|
||||
case eHTMLValue:
|
||||
case eAtom:
|
||||
{
|
||||
NS_STATIC_CAST(nsHTMLValue*, ptr)->ToString(aResult);
|
||||
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:
|
||||
{
|
||||
NS_NOTREACHED("trying to convert enum to string");
|
||||
|
||||
break;
|
||||
}
|
||||
case ePercent:
|
||||
{
|
||||
nsAutoString intStr;
|
||||
intStr.AppendInt(GetIntInternal());
|
||||
aResult = intStr + NS_LITERAL_STRING("%");
|
||||
|
||||
break;
|
||||
}
|
||||
case eCSSStyleRule:
|
||||
{
|
||||
nsCSSDeclaration* decl =
|
||||
GetMiscContainer()->mCSSStyleRule->GetDeclaration();
|
||||
if (decl) {
|
||||
decl->ToString(aResult);
|
||||
}
|
||||
else {
|
||||
aResult.Truncate();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsAttrValue::ToHTMLValue(nsHTMLValue& aResult) const
|
||||
{
|
||||
switch(Type()) {
|
||||
case eString:
|
||||
{
|
||||
aResult.SetStringValue(GetStringValue());
|
||||
break;
|
||||
}
|
||||
case eAtom:
|
||||
{
|
||||
NS_STATIC_CAST(nsIAtom*, ptr)->ToString(aResult);
|
||||
nsAutoString tmp;
|
||||
GetAtomValue()->ToString(tmp);
|
||||
aResult.SetStringValue(tmp);
|
||||
break;
|
||||
}
|
||||
case eInteger:
|
||||
{
|
||||
aResult.SetIntValue(GetIntInternal(), eHTMLUnit_Integer);
|
||||
break;
|
||||
}
|
||||
case eColor:
|
||||
{
|
||||
nscolor v;
|
||||
GetColorValue(v);
|
||||
aResult.SetColorValue(v);
|
||||
break;
|
||||
}
|
||||
case eProportional:
|
||||
{
|
||||
aResult.SetIntValue(GetProportionalValue(), eHTMLUnit_Proportional);
|
||||
break;
|
||||
}
|
||||
case eEnum:
|
||||
{
|
||||
aResult.SetIntValue(GetEnumValue(), eHTMLUnit_Enumerated);
|
||||
break;
|
||||
}
|
||||
case ePercent:
|
||||
{
|
||||
aResult.SetPercentValue(GetPercentValue());
|
||||
break;
|
||||
}
|
||||
case eCSSStyleRule:
|
||||
{
|
||||
aResult.SetCSSStyleRuleValue(GetCSSStyleRuleValue());
|
||||
break;
|
||||
}
|
||||
case eAtomArray:
|
||||
{
|
||||
nsCOMArray<nsIAtom>* array = new nsCOMArray<nsIAtom>(*GetAtomArrayValue());
|
||||
aResult.SetAtomArrayValue(array);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -227,8 +391,7 @@ nsAttrValue::ToString(nsAString& aResult) const
|
|||
const nsDependentSubstring
|
||||
nsAttrValue::GetStringValue() const
|
||||
{
|
||||
NS_PRECONDITION(GetType() == eString,
|
||||
"Some dork called GetStringValue() on a non-string!");
|
||||
NS_PRECONDITION(Type() == eString, "wrong type");
|
||||
|
||||
static const PRUnichar blankStr[] = { '\0' };
|
||||
void* ptr = GetPtr();
|
||||
|
@ -237,68 +400,445 @@ nsAttrValue::GetStringValue() const
|
|||
: Substring(blankStr, blankStr);
|
||||
}
|
||||
|
||||
const nsHTMLValue*
|
||||
nsAttrValue::GetHTMLValue() const
|
||||
PRBool
|
||||
nsAttrValue::GetColorValue(nscolor& aColor) const
|
||||
{
|
||||
NS_PRECONDITION(GetType() == eHTMLValue,
|
||||
"Some dork called GetHTMLValue() on a non-htmlvalue!");
|
||||
return NS_REINTERPRET_CAST(nsHTMLValue*, mBits & NS_ATTRVALUE_VALUE_MASK);
|
||||
}
|
||||
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());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nsIAtom*
|
||||
nsAttrValue::GetAtomValue() const
|
||||
{
|
||||
NS_PRECONDITION(GetType() == eAtom,
|
||||
"Some dork called GetAtomValue() on a non-atomvalue!");
|
||||
return NS_REINTERPRET_CAST(nsIAtom*, mBits & NS_ATTRVALUE_VALUE_MASK);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRUint32
|
||||
nsAttrValue::HashValue() const
|
||||
{
|
||||
void* ptr = GetPtr();
|
||||
switch(GetType()) {
|
||||
case eString:
|
||||
switch(BaseType()) {
|
||||
case eStringBase:
|
||||
{
|
||||
PRUnichar* str = NS_STATIC_CAST(PRUnichar*, ptr);
|
||||
PRUnichar* str = NS_STATIC_CAST(PRUnichar*, GetPtr());
|
||||
return str ? nsCheapStringBufferUtils::HashCode(str) : 0;
|
||||
}
|
||||
case eHTMLValue:
|
||||
case eOtherBase:
|
||||
{
|
||||
return NS_STATIC_CAST(nsHTMLValue*, ptr)->HashValue();
|
||||
break;
|
||||
}
|
||||
case eAtom:
|
||||
case eAtomBase:
|
||||
case eIntegerBase:
|
||||
{
|
||||
return NS_PTR_TO_INT32(ptr);
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
NS_NOTREACHED("unknown attrvalue type");
|
||||
return 0;
|
||||
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;
|
||||
}
|
||||
default:
|
||||
{
|
||||
NS_NOTREACHED("unknown type stored in MiscContainer");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsAttrValue::Equals(const nsAttrValue& aOther) const
|
||||
{
|
||||
if (GetType() != aOther.GetType()) {
|
||||
if (BaseType() != aOther.BaseType()) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
switch(GetType()) {
|
||||
case eString:
|
||||
switch(BaseType()) {
|
||||
case eStringBase:
|
||||
{
|
||||
return GetStringValue().Equals(aOther.GetStringValue());
|
||||
}
|
||||
case eHTMLValue:
|
||||
case eOtherBase:
|
||||
{
|
||||
return *GetHTMLValue() == *aOther.GetHTMLValue();
|
||||
break;
|
||||
}
|
||||
case eAtom:
|
||||
case eAtomBase:
|
||||
case eIntegerBase:
|
||||
{
|
||||
return GetAtomValue() == aOther.GetAtomValue();
|
||||
return mBits == aOther.mBits;
|
||||
}
|
||||
}
|
||||
|
||||
NS_NOTREACHED("unknown attrvalue type");
|
||||
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;
|
||||
}
|
||||
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,
|
||||
const nsHTMLValue::EnumTable* aTable,
|
||||
PRBool aCaseSensitive)
|
||||
{
|
||||
nsAutoString val(aValue);
|
||||
while (aTable->tag) {
|
||||
if (aCaseSensitive ? val.EqualsWithConversion(aTable->tag) :
|
||||
val.EqualsIgnoreCase(aTable->tag)) {
|
||||
SetIntValueAndType(aTable->value, eEnum);
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
aTable++;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsAttrValue::ParseSpecialIntValue(const nsAString& aString,
|
||||
PRBool aCanBePercent,
|
||||
PRBool aCanBeProportional)
|
||||
{
|
||||
PRInt32 ec;
|
||||
nsAutoString tmp(aString);
|
||||
PRInt32 val = tmp.ToInteger(&ec);
|
||||
|
||||
if (NS_FAILED(ec) && 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;
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
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()) {
|
||||
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() != '#') {
|
||||
return PR_FALSE;
|
||||
}
|
||||
colorStr.Cut(0, 1);
|
||||
if (!NS_HexToRGB(colorStr, &color)) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -41,68 +41,290 @@
|
|||
|
||||
#include "nscore.h"
|
||||
#include "nsDependentSubstring.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsHTMLValue.h"
|
||||
|
||||
typedef unsigned long PtrBits;
|
||||
class nsHTMLValue;
|
||||
class nsAString;
|
||||
class nsIAtom;
|
||||
class nsICSSStyleRule;
|
||||
|
||||
#define NS_ATTRVALUE_MAX_STRINGLENGTH_ATOM 12
|
||||
#define NS_ATTRVALUE_TYPE_MASK (PtrBits(3))
|
||||
#define NS_ATTRVALUE_VALUE_MASK (~NS_ATTRVALUE_TYPE_MASK)
|
||||
|
||||
#define NS_ATTRVALUE_BASETYPE_MASK (PtrBits(3))
|
||||
#define NS_ATTRVALUE_POINTERVALUE_MASK (~NS_ATTRVALUE_BASETYPE_MASK)
|
||||
|
||||
#define NS_ATTRVALUE_INTEGERTYPE_BITS 5
|
||||
#define NS_ATTRVALUE_INTEGERTYPE_MASK (PtrBits((1 << NS_ATTRVALUE_INTEGERTYPE_BITS) - 1))
|
||||
#define NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER (1 << NS_ATTRVALUE_INTEGERTYPE_BITS)
|
||||
#define NS_ATTRVALUE_INTEGERTYPE_MAXVALUE ((1 << (32 - NS_ATTRVALUE_INTEGERTYPE_BITS)) - 1)
|
||||
#define NS_ATTRVALUE_INTEGERTYPE_MINVALUE (-NS_ATTRVALUE_INTEGERTYPE_MAXVALUE - 1)
|
||||
|
||||
class nsAttrValue {
|
||||
public:
|
||||
nsAttrValue();
|
||||
nsAttrValue(const nsAttrValue& aOther);
|
||||
explicit nsAttrValue(const nsAString& aValue);
|
||||
explicit nsAttrValue(const nsHTMLValue& aValue);
|
||||
explicit nsAttrValue(nsIAtom* aValue);
|
||||
explicit nsAttrValue(nsICSSStyleRule* aValue);
|
||||
~nsAttrValue();
|
||||
|
||||
// This has to be the same as in ValueBaseType
|
||||
enum ValueType {
|
||||
eString = 0x00, // 00
|
||||
// 01 this value indicates an 'misc' struct
|
||||
eAtom = 0x02, // 10
|
||||
eInteger = 0x03, // 00011
|
||||
eColor = 0x07, // 00111
|
||||
eProportional = 0x0B, // 01011
|
||||
eEnum = 0x0F, // 01111 This should eventually die
|
||||
ePercent = 0x13, // 10011
|
||||
// Values below here won't matter, they'll be stored in the 'misc' struct
|
||||
// anyway
|
||||
eCSSStyleRule = 0x14,
|
||||
eAtomArray = 0x15
|
||||
};
|
||||
|
||||
ValueType Type() const;
|
||||
|
||||
void Reset();
|
||||
|
||||
void SetTo(const nsAttrValue& aOther);
|
||||
void SetTo(const nsAString& aValue);
|
||||
void SetTo(const nsHTMLValue& aValue);
|
||||
void SetTo(nsIAtom* aValue);
|
||||
void SetToStringOrAtom(const nsAString& aValue);
|
||||
void SetTo(PRInt16 aInt, ValueType aType);
|
||||
void SetTo(nsICSSStyleRule* aValue);
|
||||
|
||||
void SwapValueWith(nsAttrValue& aOther);
|
||||
|
||||
void ToString(nsAString& aResult) const;
|
||||
void ToHTMLValue(nsHTMLValue& aResult) const;
|
||||
|
||||
// Methods to get value. These methods do not convert so only use them
|
||||
// to retrieve the datatype that this nsAttrValue has.
|
||||
const nsDependentSubstring GetStringValue() const;
|
||||
const nsHTMLValue* GetHTMLValue() const;
|
||||
nsIAtom* GetAtomValue() const;
|
||||
inline nsIAtom* GetAtomValue() const;
|
||||
inline PRInt32 GetIntegerValue() const;
|
||||
PRBool GetColorValue(nscolor& aColor) const;
|
||||
inline PRInt32 GetProportionalValue() const;
|
||||
inline PRInt32 GetEnumValue() const;
|
||||
inline float GetPercentValue() const;
|
||||
inline nsCOMArray<nsIAtom>* GetAtomArrayValue() const;
|
||||
inline nsICSSStyleRule* GetCSSStyleRuleValue() const;
|
||||
|
||||
PRUint32 HashValue() const;
|
||||
PRBool Equals(const nsAttrValue& aOther) const;
|
||||
|
||||
enum Type {
|
||||
eString = 0,
|
||||
eHTMLValue = 1, // This should eventually die
|
||||
eAtom = 2
|
||||
};
|
||||
void ParseAtom(const nsAString& aValue);
|
||||
void ParseAtomArray(const nsAString& aValue);
|
||||
void ParseStringOrAtom(const nsAString& aValue);
|
||||
|
||||
Type GetType() const
|
||||
{
|
||||
return NS_STATIC_CAST(Type, mBits & NS_ATTRVALUE_TYPE_MASK);
|
||||
/**
|
||||
* Parse into an enum value.
|
||||
*
|
||||
* @param aValue the string to find the value for
|
||||
* @param aTable the enumeration to map with
|
||||
* @param aResult the enum mapping [OUT]
|
||||
* @return whether the enum value was found or not
|
||||
*/
|
||||
PRBool ParseEnumValue(const nsAString& aValue,
|
||||
const nsHTMLValue::EnumTable* aTable,
|
||||
PRBool aCaseSensitive = PR_FALSE);
|
||||
|
||||
/**
|
||||
* Parse a string into an integer. Can optionally parse percent (n%) and
|
||||
* proportional (n*). This method explicitly sets a lower bound of zero on
|
||||
* the element, whether it be proportional or percent or raw integer.
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @param aCanBePercent PR_TRUE if it can be a percent value (%)
|
||||
* @param aCanBeProportional PR_TRUE if it can be a proportional value (*)
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseSpecialIntValue(const nsAString& aString,
|
||||
PRBool aCanBePercent,
|
||||
PRBool aCanBeProportional);
|
||||
|
||||
|
||||
/**
|
||||
* Parse a string value into an integer.
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseIntValue(const nsAString& aString) {
|
||||
return ParseIntWithBounds(aString, NS_ATTRVALUE_INTEGERTYPE_MINVALUE,
|
||||
NS_ATTRVALUE_INTEGERTYPE_MAXVALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string value into an integer with minimum value and maximum value.
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @param aMin the minimum value (if value is less it will be bumped up)
|
||||
* @param aMax the maximum value (if value is greater it will be chopped down)
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseIntWithBounds(const nsAString& aString, PRInt32 aMin,
|
||||
PRInt32 aMax = NS_ATTRVALUE_INTEGERTYPE_MAXVALUE);
|
||||
|
||||
/**
|
||||
* Parse a string into a color.
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @param aDocument the document (to find out whether we're in quirks mode)
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseColor(const nsAString& aString, nsIDocument* aDocument);
|
||||
|
||||
private:
|
||||
void* GetPtr() const
|
||||
{
|
||||
return NS_REINTERPRET_CAST(void*, mBits & NS_ATTRVALUE_VALUE_MASK);
|
||||
}
|
||||
// These have to be the same as in ValueType
|
||||
enum ValueBaseType {
|
||||
eStringBase = eString, // 00
|
||||
eOtherBase = 0x01, // 01
|
||||
eAtomBase = eAtom, // 10
|
||||
eIntegerBase = 0x03, // 11
|
||||
};
|
||||
|
||||
void SetValueAndType(void* aValue, Type aType)
|
||||
struct MiscContainer
|
||||
{
|
||||
mBits = NS_REINTERPRET_CAST(PtrBits, aValue) | aType;
|
||||
}
|
||||
ValueType mType;
|
||||
union {
|
||||
nscolor mColor;
|
||||
nsICSSStyleRule* mCSSStyleRule;
|
||||
nsCOMArray<nsIAtom>* mAtomArray;
|
||||
};
|
||||
};
|
||||
|
||||
inline ValueBaseType BaseType() const;
|
||||
|
||||
inline void SetPtrValueAndType(void* aValue, ValueBaseType aType);
|
||||
inline void SetIntValueAndType(PRInt32 aValue, ValueType aType);
|
||||
inline void ResetIfSet();
|
||||
|
||||
inline void* GetPtr() const;
|
||||
inline MiscContainer* GetMiscContainer() const;
|
||||
inline PRInt32 GetIntInternal() const;
|
||||
|
||||
PRBool EnsureEmptyMiscContainer();
|
||||
PRBool EnsureEmptyAtomArray();
|
||||
|
||||
PtrBits mBits;
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of inline methods
|
||||
*/
|
||||
|
||||
inline nsIAtom*
|
||||
nsAttrValue::GetAtomValue() const
|
||||
{
|
||||
NS_PRECONDITION(Type() == eAtom, "wrong type");
|
||||
return NS_REINTERPRET_CAST(nsIAtom*, GetPtr());
|
||||
}
|
||||
|
||||
inline PRInt32
|
||||
nsAttrValue::GetIntegerValue() const
|
||||
{
|
||||
NS_PRECONDITION(Type() == eInteger, "wrong type");
|
||||
return GetIntInternal();
|
||||
}
|
||||
|
||||
inline PRInt32
|
||||
nsAttrValue::GetProportionalValue() const
|
||||
{
|
||||
NS_PRECONDITION(Type() == eProportional, "wrong type");
|
||||
return GetIntInternal();
|
||||
}
|
||||
|
||||
inline PRInt32
|
||||
nsAttrValue::GetEnumValue() const
|
||||
{
|
||||
NS_PRECONDITION(Type() == eEnum, "wrong type");
|
||||
return GetIntInternal();
|
||||
}
|
||||
|
||||
inline float
|
||||
nsAttrValue::GetPercentValue() const
|
||||
{
|
||||
NS_PRECONDITION(Type() == ePercent, "wrong type");
|
||||
return NS_STATIC_CAST(float, GetIntInternal()) /
|
||||
100.0f;
|
||||
}
|
||||
|
||||
inline nsCOMArray<nsIAtom>*
|
||||
nsAttrValue::GetAtomArrayValue() const
|
||||
{
|
||||
NS_PRECONDITION(Type() == eAtomArray, "wrong type");
|
||||
return GetMiscContainer()->mAtomArray;
|
||||
}
|
||||
|
||||
inline nsICSSStyleRule*
|
||||
nsAttrValue::GetCSSStyleRuleValue() const
|
||||
{
|
||||
NS_PRECONDITION(Type() == eCSSStyleRule, "wrong type");
|
||||
return GetMiscContainer()->mCSSStyleRule;
|
||||
}
|
||||
|
||||
inline nsAttrValue::ValueBaseType
|
||||
nsAttrValue::BaseType() const
|
||||
{
|
||||
return NS_STATIC_CAST(ValueBaseType, mBits & NS_ATTRVALUE_BASETYPE_MASK);
|
||||
}
|
||||
|
||||
inline void
|
||||
nsAttrValue::SetPtrValueAndType(void* aValue, ValueBaseType aType)
|
||||
{
|
||||
NS_ASSERTION(!(NS_PTR_TO_INT32(aValue) & ~NS_ATTRVALUE_POINTERVALUE_MASK),
|
||||
"pointer not properly aligned, this will crash");
|
||||
mBits = NS_REINTERPRET_CAST(PtrBits, aValue) | aType;
|
||||
}
|
||||
|
||||
inline void
|
||||
nsAttrValue::SetIntValueAndType(PRInt32 aValue, ValueType aType)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
{
|
||||
PRInt32 tmp = aValue * NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER;
|
||||
NS_ASSERTION(tmp / NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER == aValue,
|
||||
"Integer too big to fit");
|
||||
}
|
||||
#endif
|
||||
mBits = (aValue * NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER) | aType;
|
||||
}
|
||||
|
||||
inline void
|
||||
nsAttrValue::ResetIfSet()
|
||||
{
|
||||
if (mBits) {
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
inline void*
|
||||
nsAttrValue::GetPtr() const
|
||||
{
|
||||
NS_ASSERTION(BaseType() != eIntegerBase,
|
||||
"getting pointer from non-pointer");
|
||||
return NS_REINTERPRET_CAST(void*, mBits & NS_ATTRVALUE_POINTERVALUE_MASK);
|
||||
}
|
||||
|
||||
inline nsAttrValue::MiscContainer*
|
||||
nsAttrValue::GetMiscContainer() const
|
||||
{
|
||||
NS_ASSERTION(BaseType() == eOtherBase, "wrong type");
|
||||
return NS_STATIC_CAST(MiscContainer*, GetPtr());
|
||||
}
|
||||
|
||||
inline PRInt32
|
||||
nsAttrValue::GetIntInternal() const
|
||||
{
|
||||
NS_ASSERTION(BaseType() == eIntegerBase,
|
||||
"getting integer from non-integer");
|
||||
// Make sure we get a signed value.
|
||||
// Lets hope the optimizer optimizes this into a shift. Unfortunatly signed
|
||||
// bitshift right is implementaion dependant.
|
||||
return NS_STATIC_CAST(PRInt32, mBits & ~NS_ATTRVALUE_INTEGERTYPE_MASK) /
|
||||
NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -68,126 +68,11 @@ nsHTMLValue::nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit)
|
|||
}
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(float aValue)
|
||||
: mUnit(eHTMLUnit_Percent)
|
||||
{
|
||||
mValue.mFloat = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(const nsAString& aValue, nsHTMLUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
SetStringValueInternal(aValue, aUnit);
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nsICSSStyleRule* aValue)
|
||||
: mUnit(eHTMLUnit_CSSStyleRule)
|
||||
{
|
||||
mValue.mCSSStyleRule = aValue;
|
||||
NS_IF_ADDREF(mValue.mCSSStyleRule);
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nscolor aValue)
|
||||
: mUnit(eHTMLUnit_Color)
|
||||
{
|
||||
mValue.mColor = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nsCOMArray<nsIAtom>* aArray)
|
||||
: mUnit(eHTMLUnit_AtomArray)
|
||||
{
|
||||
mValue.mAtomArray = aArray;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(const nsHTMLValue& aCopy)
|
||||
{
|
||||
InitializeFrom(aCopy);
|
||||
}
|
||||
|
||||
nsHTMLValue::~nsHTMLValue(void)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
nsHTMLValue& nsHTMLValue::operator=(const nsHTMLValue& aCopy)
|
||||
{
|
||||
Reset();
|
||||
InitializeFrom(aCopy);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PRBool nsHTMLValue::operator==(const nsHTMLValue& aOther) const
|
||||
{
|
||||
if (mUnit != aOther.mUnit) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
// Call GetUnitClass() so that we turn StringWithLength into String
|
||||
PRUint32 unitClass = GetUnitClass();
|
||||
switch (unitClass) {
|
||||
case HTMLUNIT_STRING:
|
||||
if (mValue.mString && aOther.mValue.mString) {
|
||||
return GetDependentString().Equals(aOther.GetDependentString());
|
||||
}
|
||||
// One of them is null. An == check will see if they are both null.
|
||||
return mValue.mString == aOther.mValue.mString;
|
||||
|
||||
case HTMLUNIT_INTEGER:
|
||||
return mValue.mInt == aOther.mValue.mInt;
|
||||
|
||||
case HTMLUNIT_COLOR:
|
||||
return mValue.mColor == aOther.mValue.mColor;
|
||||
|
||||
case HTMLUNIT_CSSSTYLERULE:
|
||||
return mValue.mCSSStyleRule == aOther.mValue.mCSSStyleRule;
|
||||
|
||||
case HTMLUNIT_PERCENT:
|
||||
return mValue.mFloat == aOther.mValue.mFloat;
|
||||
|
||||
case HTMLUNIT_ATOMARRAY:
|
||||
{
|
||||
// For classlists we could be insensitive to order, however
|
||||
// classlists are never mapped attributes so they are never compared.
|
||||
|
||||
PRInt32 count = mValue.mAtomArray->Count();
|
||||
if (count != aOther.mValue.mAtomArray->Count()) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRInt32 i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
if (mValue.mAtomArray->ObjectAt(i) !=
|
||||
aOther.mValue.mAtomArray->ObjectAt(i)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
default:
|
||||
NS_WARNING("Unknown unit");
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
PRUint32 nsHTMLValue::HashValue(void) const
|
||||
{
|
||||
PRUint32 retval;
|
||||
if (GetUnitClass() == HTMLUNIT_STRING) {
|
||||
retval = mValue.mString ? nsCheapStringBufferUtils::HashCode(mValue.mString)
|
||||
: 0;
|
||||
} else if (mUnit == eHTMLUnit_AtomArray) {
|
||||
retval = 0;
|
||||
PRInt32 i, count = mValue.mAtomArray->Count();
|
||||
for (i = 0; i < count; ++i) {
|
||||
retval ^= NS_PTR_TO_INT32(mValue.mAtomArray->ObjectAt(i));
|
||||
}
|
||||
} else {
|
||||
retval = mValue.mInt;
|
||||
}
|
||||
return retval ^ PRUint32(mUnit);
|
||||
}
|
||||
|
||||
|
||||
void nsHTMLValue::Reset(void)
|
||||
{
|
||||
if (GetUnitClass() == HTMLUNIT_STRING) {
|
||||
|
@ -259,6 +144,13 @@ void nsHTMLValue::SetCSSStyleRuleValue(nsICSSStyleRule* aValue)
|
|||
NS_IF_ADDREF(mValue.mCSSStyleRule);
|
||||
}
|
||||
|
||||
void nsHTMLValue::SetAtomArrayValue(nsCOMArray<nsIAtom>* aValue)
|
||||
{
|
||||
Reset();
|
||||
mUnit = eHTMLUnit_AtomArray;
|
||||
mValue.mAtomArray = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::SetColorValue(nscolor aValue)
|
||||
{
|
||||
Reset();
|
||||
|
@ -266,71 +158,10 @@ void nsHTMLValue::SetColorValue(nscolor aValue)
|
|||
mValue.mColor = aValue;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLValue::InitializeFrom(const nsHTMLValue& aCopy)
|
||||
{
|
||||
mUnit = aCopy.mUnit;
|
||||
switch (GetUnitClass()) {
|
||||
case HTMLUNIT_STRING:
|
||||
if (aCopy.mValue.mString) {
|
||||
nsCheapStringBufferUtils::Clone(mValue.mString, aCopy.mValue.mString);
|
||||
} else {
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
break;
|
||||
|
||||
case HTMLUNIT_INTEGER:
|
||||
mValue.mInt = aCopy.mValue.mInt;
|
||||
break;
|
||||
|
||||
case HTMLUNIT_COLOR:
|
||||
mValue.mColor = aCopy.mValue.mColor;
|
||||
break;
|
||||
|
||||
case HTMLUNIT_CSSSTYLERULE:
|
||||
mValue.mCSSStyleRule = aCopy.mValue.mCSSStyleRule;
|
||||
NS_IF_ADDREF(mValue.mCSSStyleRule);
|
||||
break;
|
||||
|
||||
case HTMLUNIT_PERCENT:
|
||||
mValue.mFloat = aCopy.mValue.mFloat;
|
||||
break;
|
||||
|
||||
case HTMLUNIT_ATOMARRAY:
|
||||
mValue.mAtomArray = new nsCOMArray<nsIAtom>(*aCopy.mValue.mAtomArray);
|
||||
if (!mValue.mAtomArray) {
|
||||
mUnit = eHTMLUnit_String;
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
NS_ERROR("Unknown HTMLValue type!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Parsing methods
|
||||
//
|
||||
|
||||
PRBool
|
||||
nsHTMLValue::ParseEnumValue(const nsAString& aValue,
|
||||
const EnumTable* aTable,
|
||||
PRBool aCaseSensitive)
|
||||
{
|
||||
nsAutoString val(aValue);
|
||||
while (aTable->tag) {
|
||||
if (aCaseSensitive ? val.EqualsWithConversion(aTable->tag) :
|
||||
val.EqualsIgnoreCase(aTable->tag)) {
|
||||
SetIntValue(aTable->value, eHTMLUnit_Enumerated);
|
||||
return PR_TRUE;
|
||||
}
|
||||
aTable++;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsHTMLValue::EnumValueToString(const EnumTable* aTable,
|
||||
nsAString& aResult) const
|
||||
|
@ -349,196 +180,3 @@ nsHTMLValue::EnumValueToString(const EnumTable* aTable,
|
|||
aResult.Truncate();
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/* used to parse attribute values that could be either:
|
||||
* integer (n),
|
||||
* percent (n%),
|
||||
* or proportional (n*)
|
||||
*/
|
||||
PRBool
|
||||
nsHTMLValue::ParseSpecialIntValue(const nsAString& aString,
|
||||
nsHTMLUnit aDefaultUnit,
|
||||
PRBool aCanBePercent,
|
||||
PRBool aCanBeProportional)
|
||||
{
|
||||
nsAutoString tmp(aString);
|
||||
PRInt32 ec;
|
||||
PRInt32 val = tmp.ToInteger(&ec);
|
||||
|
||||
if (NS_SUCCEEDED(ec)) {
|
||||
if (val < 0) {
|
||||
val = 0;
|
||||
}
|
||||
// % (percent) (XXX RFindChar means that 5%x will be parsed!)
|
||||
if (aCanBePercent && tmp.RFindChar('%') >= 0) {
|
||||
if (val > 100) {
|
||||
val = 100;
|
||||
}
|
||||
SetPercentValue(float(val)/100.0f);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// * (proportional) (XXX RFindChar means that 5*x will be parsed!)
|
||||
if (aCanBeProportional && tmp.RFindChar('*') >= 0) {
|
||||
SetIntValue(val, eHTMLUnit_Proportional);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// Straight number is interpreted with the default unit
|
||||
SetIntValue(val, aDefaultUnit);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// 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
|
||||
// b=29061
|
||||
SetIntValue(1, eHTMLUnit_Proportional);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsHTMLValue::ToString(nsAString& aResult) const
|
||||
{
|
||||
nsAutoString intStr;
|
||||
aResult.Truncate();
|
||||
|
||||
switch (GetUnit()) {
|
||||
case eHTMLUnit_Integer:
|
||||
case eHTMLUnit_Proportional:
|
||||
intStr.AppendInt(GetIntValue());
|
||||
aResult.Append(intStr);
|
||||
if (GetUnit() == eHTMLUnit_Proportional) {
|
||||
aResult.Append(PRUnichar('*'));
|
||||
}
|
||||
return PR_TRUE;
|
||||
|
||||
case eHTMLUnit_Percent:
|
||||
{
|
||||
float percentVal = GetPercentValue() * 100.0f;
|
||||
intStr.AppendInt(NSToCoordRoundExclusive(percentVal));
|
||||
aResult.Append(intStr);
|
||||
aResult.Append(PRUnichar('%'));
|
||||
return PR_TRUE;
|
||||
}
|
||||
case eHTMLUnit_Color:
|
||||
{
|
||||
nscolor v;
|
||||
GetColorValue(v);
|
||||
char buf[10];
|
||||
PR_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
|
||||
NS_GET_R(v), NS_GET_G(v), NS_GET_B(v));
|
||||
AppendASCIItoUTF16(buf, aResult);
|
||||
return PR_TRUE;
|
||||
}
|
||||
case eHTMLUnit_String:
|
||||
GetStringValue(aResult);
|
||||
return PR_TRUE;
|
||||
case eHTMLUnit_AtomArray:
|
||||
{
|
||||
PRInt32 count = mValue.mAtomArray->Count();
|
||||
if (count) {
|
||||
mValue.mAtomArray->ObjectAt(0)->ToString(aResult);
|
||||
nsAutoString tmp;
|
||||
PRInt32 i;
|
||||
for (i = 1; i < count; ++i) {
|
||||
mValue.mAtomArray->ObjectAt(i)->ToString(tmp);
|
||||
aResult.Append(NS_LITERAL_STRING(" ") + tmp);
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
case eHTMLUnit_CSSStyleRule:
|
||||
{
|
||||
if (mValue.mCSSStyleRule) {
|
||||
nsCSSDeclaration* decl = mValue.mCSSStyleRule->GetDeclaration();
|
||||
if (decl) {
|
||||
decl->ToString(aResult);
|
||||
}
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
default:
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsHTMLValue::ParseIntWithBounds(const nsAString& aString,
|
||||
nsHTMLUnit aDefaultUnit,
|
||||
PRInt32 aMin, PRInt32 aMax)
|
||||
{
|
||||
nsAutoString str(aString);
|
||||
PRInt32 ec;
|
||||
PRInt32 val = str.ToInteger(&ec);
|
||||
if (NS_SUCCEEDED(ec)) {
|
||||
val = PR_MAX(val, aMin);
|
||||
val = PR_MIN(val, aMax);
|
||||
SetIntValue(val, aDefaultUnit);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsHTMLValue::ParseColor(const nsAString& aString, nsIDocument* aDocument)
|
||||
{
|
||||
if (aString.IsEmpty()) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// Previously we did a complicated algorithm to strip leading and trailing
|
||||
// whitespace; now we just use CompressWhitespace like everyone else.
|
||||
// Since all color values are just one word, this is ok.
|
||||
|
||||
nsAutoString colorStr(aString);
|
||||
colorStr.CompressWhitespace(PR_TRUE, PR_TRUE);
|
||||
if (colorStr.IsEmpty()) {
|
||||
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)) {
|
||||
SetStringValue(colorStr, eHTMLUnit_String);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// Check if we are in compatibility mode
|
||||
PRBool inNavQuirksMode;
|
||||
{
|
||||
nsCOMPtr<nsIHTMLDocument> doc(do_QueryInterface(aDocument));
|
||||
if (doc) {
|
||||
inNavQuirksMode = (doc->GetCompatibilityMode() == eCompatibility_NavQuirks);
|
||||
} else {
|
||||
inNavQuirksMode = PR_FALSE;
|
||||
}
|
||||
}
|
||||
if (!inNavQuirksMode) {
|
||||
if (colorStr.CharAt(0) == '#') {
|
||||
colorStr.Cut(0, 1);
|
||||
if (NS_HexToRGB(colorStr, &color)) {
|
||||
SetColorValue(color);
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (NS_LooseHexToRGB(colorStr, &color)) {
|
||||
SetColorValue(color);
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
|
|
@ -190,18 +190,8 @@ class nsHTMLValue {
|
|||
public:
|
||||
nsHTMLValue();
|
||||
nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit);
|
||||
nsHTMLValue(float aValue);
|
||||
nsHTMLValue(const nsAString& aValue, nsHTMLUnit aUnit = eHTMLUnit_String);
|
||||
nsHTMLValue(nsICSSStyleRule* aValue);
|
||||
nsHTMLValue(nscolor aValue);
|
||||
nsHTMLValue(nsCOMArray<nsIAtom>* aArray);
|
||||
nsHTMLValue(const nsHTMLValue& aCopy);
|
||||
~nsHTMLValue(void);
|
||||
|
||||
nsHTMLValue& operator=(const nsHTMLValue& aCopy);
|
||||
PRBool operator==(const nsHTMLValue& aOther) const;
|
||||
PRBool operator!=(const nsHTMLValue& aOther) const;
|
||||
PRUint32 HashValue(void) const;
|
||||
|
||||
/**
|
||||
* Get the unit of this HTMLValue
|
||||
|
@ -212,9 +202,7 @@ public:
|
|||
PRInt32 GetIntValue(void) const;
|
||||
float GetPercentValue(void) const;
|
||||
nsAString& GetStringValue(nsAString& aBuffer) const;
|
||||
nsICSSStyleRule* GetCSSStyleRuleValue(void) const;
|
||||
PRBool GetColorValue(nscolor& aColor) const;
|
||||
nsCOMArray<nsIAtom>* AtomArrayValue() const;
|
||||
|
||||
PRBool IsEmptyString() const;
|
||||
|
||||
|
@ -226,15 +214,9 @@ public:
|
|||
void SetPercentValue(float aValue);
|
||||
void SetStringValue(const nsAString& aValue, nsHTMLUnit aUnit = eHTMLUnit_String);
|
||||
void SetCSSStyleRuleValue(nsICSSStyleRule* aValue);
|
||||
void SetAtomArrayValue(nsCOMArray<nsIAtom>* aValue);
|
||||
void SetColorValue(nscolor aValue);
|
||||
|
||||
/**
|
||||
* Get this HTML value as a string (depends on the type)
|
||||
* @param aResult the resulting string
|
||||
* @return whether the value was successfully turned to a string
|
||||
*/
|
||||
PRBool ToString(nsAString& aResult) const;
|
||||
|
||||
/**
|
||||
* Structure for a mapping from int (enum) values to strings. When you use
|
||||
* it you generally create an array of them.
|
||||
|
@ -249,7 +231,7 @@ public:
|
|||
/** The string the value maps to */
|
||||
const char* tag;
|
||||
/** The enum value that maps to this string */
|
||||
PRInt32 value;
|
||||
PRInt16 value;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -257,19 +239,6 @@ public:
|
|||
*/
|
||||
// Attribute parsing utilities
|
||||
|
||||
/**
|
||||
* Map a string to its enum value and return result as HTMLValue
|
||||
* (case-insensitive matching)
|
||||
*
|
||||
* @param aValue the string to find the value for
|
||||
* @param aTable the enumeration to map with
|
||||
* @param aResult the enum mapping [OUT]
|
||||
* @return whether the enum value was found or not
|
||||
*/
|
||||
PRBool ParseEnumValue(const nsAString& aValue,
|
||||
const EnumTable* aTable,
|
||||
PRBool aCaseSensitive = PR_FALSE);
|
||||
|
||||
/**
|
||||
* Map an enum HTMLValue to its string
|
||||
*
|
||||
|
@ -281,57 +250,6 @@ public:
|
|||
PRBool EnumValueToString(const EnumTable* aTable,
|
||||
nsAString& aResult) const;
|
||||
|
||||
/**
|
||||
* Parse a string value into an int HTMLValue.
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @param aDefaultUnit the unit to use
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseIntValue(const nsAString& aString, nsHTMLUnit aDefaultUnit) {
|
||||
return ParseIntWithBounds(aString, aDefaultUnit, PR_INT32_MIN, PR_INT32_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string value into an int HTMLValue with minimum
|
||||
* value and maximum value (can optionally parse percent (n%) and
|
||||
* proportional (n*). This method explicitly sets a lower bound of zero on
|
||||
* the element, whether it be proportional or percent or raw integer.
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @param aDefaultUnit the unit to use
|
||||
* @param aCanBePercent true if it can be a percent value (%)
|
||||
* @param aCanBeProportional true if it can be a proportional value (*)
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseSpecialIntValue(const nsAString& aString, nsHTMLUnit aDefaultUnit,
|
||||
PRBool aCanBePercent,
|
||||
PRBool aCanBeProportional);
|
||||
|
||||
/**
|
||||
* Parse a string value into an int HTMLValue with minimum
|
||||
* value and maximum value
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @param aMin the minimum value (if value is less it will be bumped up)
|
||||
* @param aMax the maximum value (if value is greater it will be chopped down)
|
||||
* @param aValueUnit the unit to use
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseIntWithBounds(const nsAString& aString, nsHTMLUnit aValueUnit,
|
||||
PRInt32 aMin, PRInt32 aMax = PR_INT32_MAX);
|
||||
|
||||
/**
|
||||
* Parse a string into a color HTMLValue (with hexes or color names)
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @param aDocument the document (to find out whether we're in quirks mode)
|
||||
* @param aResult the resulting HTMLValue [OUT]
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseColor(const nsAString& aString, nsIDocument* aDocument);
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The unit of the value
|
||||
|
@ -359,12 +277,6 @@ protected:
|
|||
} mValue;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Copy into this HTMLValue from aCopy. Please be aware that if this is an
|
||||
* existing HTMLValue and you do not call Reset(), this will leak.
|
||||
* @param aCopy the value to copy
|
||||
*/
|
||||
void InitializeFrom(const nsHTMLValue& aCopy);
|
||||
/**
|
||||
* Helper to set string value (checks for embedded nulls or length); verifies
|
||||
* that aUnit is a string type as well.
|
||||
|
@ -385,6 +297,11 @@ private:
|
|||
* @return the unit class
|
||||
*/
|
||||
PRUint32 GetUnitClass() const { return mUnit & HTMLUNIT_CLASS_MASK; }
|
||||
|
||||
nsHTMLValue(const nsHTMLValue& aCopy); // NOT TO BE IMPLEMENTED
|
||||
PRBool operator==(const nsHTMLValue& aOther) const; // NOT TO BE IMPLEMENTED
|
||||
nsHTMLValue& operator=(const nsHTMLValue& aCopy); // NOT TO BE IMPLEMENTED
|
||||
PRBool operator!=(const nsHTMLValue& aOther) const; // NOT TO BE IMPLEMENTED
|
||||
};
|
||||
|
||||
inline nsDependentSubstring nsHTMLValue::GetDependentString() const
|
||||
|
@ -440,15 +357,6 @@ inline nsAString& nsHTMLValue::GetStringValue(nsAString& aBuffer) const
|
|||
return aBuffer;
|
||||
}
|
||||
|
||||
inline nsICSSStyleRule* nsHTMLValue::GetCSSStyleRuleValue(void) const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_CSSStyleRule, "not an CSSStyleRule value");
|
||||
if (mUnit == eHTMLUnit_CSSStyleRule) {
|
||||
return mValue.mCSSStyleRule;
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
inline PRBool nsHTMLValue::GetColorValue(nscolor& aColor) const
|
||||
{
|
||||
NS_ASSERTION((mUnit == eHTMLUnit_Color) || (mUnit == eHTMLUnit_String),
|
||||
|
@ -464,18 +372,6 @@ inline PRBool nsHTMLValue::GetColorValue(nscolor& aColor) const
|
|||
return PR_FALSE;
|
||||
}
|
||||
|
||||
inline nsCOMArray<nsIAtom>*
|
||||
nsHTMLValue::AtomArrayValue() const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_AtomArray, "not an atom array");
|
||||
return mValue.mAtomArray;
|
||||
}
|
||||
|
||||
inline PRBool nsHTMLValue::operator!=(const nsHTMLValue& aOther) const
|
||||
{
|
||||
return PRBool(! ((*this) == aOther));
|
||||
}
|
||||
|
||||
inline PRBool nsHTMLValue::IsEmptyString() const
|
||||
{
|
||||
return mUnit == eHTMLUnit_String && !mValue.mString;
|
||||
|
|
|
@ -146,14 +146,7 @@ nsMappedAttributes::GetAttribute(nsIAtom* aAttrName,
|
|||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
|
||||
if (val->GetType() == nsAttrValue::eHTMLValue) {
|
||||
aValue = *val->GetHTMLValue();
|
||||
}
|
||||
else {
|
||||
nsAutoString strVal;
|
||||
val->ToString(strVal);
|
||||
aValue.SetStringValue(strVal);
|
||||
}
|
||||
val->ToHTMLValue(aValue);
|
||||
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
|
||||
|
|
|
@ -289,25 +289,21 @@ nsGenericHTMLElement::CopyInnerTo(nsGenericContainerElement* aDst,
|
|||
// We can't just set this as a string, because that will fail
|
||||
// to reparse the string into style data until the node is
|
||||
// inserted into the document. Clone the HTMLValue instead.
|
||||
nsHTMLValue val;
|
||||
rv = GetHTMLAttribute(nsHTMLAtoms::style, val);
|
||||
if (rv == NS_CONTENT_ATTR_HAS_VALUE &&
|
||||
val.GetUnit() == eHTMLUnit_CSSStyleRule) {
|
||||
nsICSSStyleRule* rule = val.GetCSSStyleRuleValue();
|
||||
const nsAttrValue* styleVal =
|
||||
mAttrsAndChildren.GetAttr(nsHTMLAtoms::style);
|
||||
if (styleVal && styleVal->Type() == nsAttrValue::eCSSStyleRule) {
|
||||
nsCOMPtr<nsICSSRule> ruleClone;
|
||||
rv = styleVal->GetCSSStyleRuleValue()->
|
||||
Clone(*getter_AddRefs(ruleClone));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (rule) {
|
||||
nsCOMPtr<nsICSSRule> ruleClone;
|
||||
rv = rule->Clone(*getter_AddRefs(ruleClone));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsICSSStyleRule> styleRule = do_QueryInterface(ruleClone);
|
||||
NS_ENSURE_TRUE(styleRule, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsCOMPtr<nsICSSStyleRule> styleRule = do_QueryInterface(ruleClone);
|
||||
NS_ENSURE_TRUE(styleRule, NS_ERROR_UNEXPECTED);
|
||||
rv = aDst->SetInlineStyleRule(styleRule, PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = aDst->SetInlineStyleRule(styleRule, PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1541,79 +1537,6 @@ nsGenericHTMLElement::GetNameSpaceID(PRInt32* aID) const
|
|||
*aID = kNameSpaceID_XHTML;
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
nsGenericHTMLElement::ParseClassAttribute(const nsAString& aStr, nsAttrValue& aValue)
|
||||
{
|
||||
nsAString::const_iterator iter, end;
|
||||
aStr.BeginReading(iter);
|
||||
aStr.EndReading(end);
|
||||
|
||||
// skip initial whitespace
|
||||
while (iter != end && nsCRT::IsAsciiSpace(*iter)) {
|
||||
++iter;
|
||||
}
|
||||
|
||||
if (iter == end) {
|
||||
aValue.Reset();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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));
|
||||
NS_ENSURE_TRUE(classAtom, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// skip whitespace
|
||||
while (iter != end && nsCRT::IsAsciiSpace(*iter)) {
|
||||
++iter;
|
||||
}
|
||||
|
||||
if (iter == end) {
|
||||
// we only found one classname so don't bother storing a list
|
||||
aValue.SetTo(classAtom);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoPtr<nsCOMArray<nsIAtom> > array(new nsCOMArray<nsIAtom>);
|
||||
NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
if (!array->AppendObject(classAtom)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// 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)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// skip whitespace
|
||||
while (iter != end && nsCRT::IsAsciiSpace(*iter)) {
|
||||
++iter;
|
||||
}
|
||||
} while (iter != end);
|
||||
|
||||
aValue.SetTo(nsHTMLValue(array.forget()));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericHTMLElement::SetAttr(PRInt32 aNamespaceID, nsIAtom* aAttribute,
|
||||
nsIAtom* aPrefix, const nsAString& aValue,
|
||||
|
@ -1655,28 +1578,7 @@ nsGenericHTMLElement::SetAttr(PRInt32 aNamespaceID, nsIAtom* aAttribute,
|
|||
// Parse into a nsAttrValue
|
||||
nsAttrValue attrValue;
|
||||
if (aNamespaceID == kNameSpaceID_None) {
|
||||
nsHTMLValue htmlValue;
|
||||
if ((StringToAttribute(aAttribute, aValue, htmlValue) !=
|
||||
NS_CONTENT_ATTR_NOT_THERE) ||
|
||||
ParseCommonAttribute(aAttribute, aValue, htmlValue)) {
|
||||
// string value was mapped to nsHTMLValue, set it that way
|
||||
attrValue.SetTo(htmlValue);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::style) {
|
||||
ParseStyleAttribute(this, mNodeInfo->NamespaceEquals(kNameSpaceID_XHTML),
|
||||
aValue, attrValue);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::id) {
|
||||
nsCOMPtr<nsIAtom> idAtom = do_GetAtom(aValue);
|
||||
NS_ENSURE_TRUE(idAtom, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
attrValue.SetTo(idAtom);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::kClass) {
|
||||
rv = ParseClassAttribute(aValue, attrValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
else {
|
||||
if (!ParseAttribute(aAttribute, aValue, attrValue)) {
|
||||
attrValue.SetTo(aValue);
|
||||
}
|
||||
|
||||
|
@ -1859,11 +1761,11 @@ nsGenericHTMLElement::GetAttr(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
|
|||
}
|
||||
|
||||
// Use subclass to convert enums to string.
|
||||
if (attrValue->GetType() == nsAttrValue::eHTMLValue &&
|
||||
attrValue->GetHTMLValue()->GetUnit() == eHTMLUnit_Enumerated) {
|
||||
|
||||
if (attrValue->Type() == nsAttrValue::eEnum) {
|
||||
if (aNameSpaceID != kNameSpaceID_None ||
|
||||
AttributeToString(aAttribute, *attrValue->GetHTMLValue(), aResult) !=
|
||||
AttributeToString(aAttribute, nsHTMLValue(attrValue->GetEnumValue(),
|
||||
eHTMLUnit_Enumerated),
|
||||
aResult) !=
|
||||
NS_CONTENT_ATTR_HAS_VALUE) {
|
||||
NS_NOTREACHED("no enum to string conversion found");
|
||||
|
||||
|
@ -1888,25 +1790,7 @@ nsGenericHTMLElement::GetHTMLAttribute(nsIAtom* aAttribute,
|
|||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
|
||||
switch (val->GetType()) {
|
||||
case nsAttrValue::eHTMLValue:
|
||||
{
|
||||
aValue = *val->GetHTMLValue();
|
||||
break;
|
||||
}
|
||||
case nsAttrValue::eString:
|
||||
{
|
||||
aValue.SetStringValue(val->GetStringValue());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
nsAutoString str;
|
||||
val->ToString(str);
|
||||
aValue.SetStringValue(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
val->ToHTMLValue(aValue);
|
||||
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
|
@ -1917,9 +1801,12 @@ nsGenericHTMLElement::GetID(nsIAtom** aResult) const
|
|||
*aResult = nsnull;
|
||||
|
||||
const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(nsHTMLAtoms::id);
|
||||
NS_ASSERTION(!attrVal || attrVal->GetType() == nsAttrValue::eAtom,
|
||||
"attribute parsed as something other then atom");
|
||||
if (attrVal && attrVal->GetType() == nsAttrValue::eAtom) {
|
||||
NS_ASSERTION(!attrVal ||
|
||||
attrVal->Type() == nsAttrValue::eAtom ||
|
||||
(attrVal->Type() == nsAttrValue::eString &&
|
||||
attrVal->GetStringValue().IsEmpty()),
|
||||
"unexpected attribute type");
|
||||
if (attrVal && attrVal->Type() == nsAttrValue::eAtom) {
|
||||
NS_ADDREF(*aResult = attrVal->GetAtomValue());
|
||||
}
|
||||
|
||||
|
@ -1933,15 +1820,12 @@ nsGenericHTMLElement::GetClasses(nsVoidArray& aArray) const
|
|||
|
||||
const nsAttrValue* val = mAttrsAndChildren.GetAttr(nsHTMLAtoms::kClass);
|
||||
if (val) {
|
||||
const nsHTMLValue* htmlVal;
|
||||
if (val->GetType() == nsAttrValue::eAtom) {
|
||||
if (val->Type() == nsAttrValue::eAtom) {
|
||||
// NOTE atom is not addrefed
|
||||
aArray.AppendElement(val->GetAtomValue());
|
||||
}
|
||||
else if (val->GetType() == nsAttrValue::eHTMLValue &&
|
||||
(htmlVal = val->GetHTMLValue())->GetUnit() ==
|
||||
eHTMLUnit_AtomArray) {
|
||||
nsCOMArray<nsIAtom>* array = htmlVal->AtomArrayValue();
|
||||
else if (val->Type() == nsAttrValue::eAtomArray) {
|
||||
nsCOMArray<nsIAtom>* array = val->GetAtomArrayValue();
|
||||
PRInt32 i, count = array->Count();
|
||||
for (i = 0; i < count; ++i) {
|
||||
// NOTE atom is not addrefed
|
||||
|
@ -1970,8 +1854,7 @@ nsGenericHTMLElement::HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const
|
|||
{
|
||||
const nsAttrValue* val = mAttrsAndChildren.GetAttr(nsHTMLAtoms::kClass);
|
||||
if (val) {
|
||||
const nsHTMLValue* htmlVal;
|
||||
if (val->GetType() == nsAttrValue::eAtom) {
|
||||
if (val->Type() == nsAttrValue::eAtom) {
|
||||
if (aCaseSensitive) {
|
||||
return aClass == val->GetAtomValue();
|
||||
}
|
||||
|
@ -1982,10 +1865,8 @@ nsGenericHTMLElement::HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const
|
|||
|
||||
return nsCRT::strcasecmp(class1, class2) == 0;
|
||||
}
|
||||
if (val->GetType() == nsAttrValue::eHTMLValue &&
|
||||
(htmlVal = val->GetHTMLValue())->GetUnit() ==
|
||||
eHTMLUnit_AtomArray) {
|
||||
nsCOMArray<nsIAtom>* array = htmlVal->AtomArrayValue();
|
||||
if (val->Type() == nsAttrValue::eAtomArray) {
|
||||
nsCOMArray<nsIAtom>* array = val->GetAtomArrayValue();
|
||||
if (aCaseSensitive) {
|
||||
return array->IndexOf(aClass) >= 0;
|
||||
}
|
||||
|
@ -2021,17 +1902,14 @@ nsGenericHTMLElement::GetInlineStyleRule(nsICSSStyleRule** aStyleRule)
|
|||
const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(nsHTMLAtoms::style);
|
||||
|
||||
if (attrVal) {
|
||||
if (attrVal->GetType() != nsAttrValue::eHTMLValue ||
|
||||
attrVal->GetHTMLValue()->GetUnit() != eHTMLUnit_CSSStyleRule) {
|
||||
if (attrVal->Type() != nsAttrValue::eCSSStyleRule) {
|
||||
ReparseStyleAttribute();
|
||||
attrVal = mAttrsAndChildren.GetAttr(nsHTMLAtoms::style);
|
||||
// hopefully value.GetUnit() is now eHTMLUnit_CSSStyleRule
|
||||
}
|
||||
|
||||
if (attrVal->GetType() == nsAttrValue::eHTMLValue &&
|
||||
attrVal->GetHTMLValue()->GetUnit() == eHTMLUnit_CSSStyleRule) {
|
||||
NS_IF_ADDREF(*aStyleRule =
|
||||
attrVal->GetHTMLValue()->GetCSSStyleRuleValue());
|
||||
if (attrVal->Type() == nsAttrValue::eCSSStyleRule) {
|
||||
NS_ADDREF(*aStyleRule = attrVal->GetCSSStyleRuleValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2064,9 +1942,7 @@ nsGenericHTMLElement::SetInlineStyleRule(nsICSSStyleRule* aStyleRule,
|
|||
}
|
||||
}
|
||||
|
||||
// MSVC won't let me do: nsAttrValue attrValue(nsHTMLValue(aStyleRule));
|
||||
nsAttrValue attrValue;
|
||||
attrValue.SetTo(nsHTMLValue(aStyleRule));
|
||||
nsAttrValue attrValue(aStyleRule);
|
||||
|
||||
return SetAttrAndNotify(kNameSpaceID_None, nsHTMLAtoms::style, nsnull, oldValueStr,
|
||||
attrValue, modification, hasListeners, aNotify);
|
||||
|
@ -2252,12 +2128,31 @@ nsGenericHTMLElement::AttributeToString(nsIAtom* aAttribute,
|
|||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGenericHTMLElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsGenericHTMLElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (aAttribute == nsHTMLAtoms::dir) {
|
||||
return aResult.ParseEnumValue(aValue, kDirTable);
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::style) {
|
||||
ParseStyleAttribute(this, mNodeInfo->NamespaceEquals(kNameSpaceID_XHTML),
|
||||
aValue, aResult);
|
||||
return PR_TRUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::id && !aValue.IsEmpty()) {
|
||||
aResult.ParseAtom(aValue);
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::kClass) {
|
||||
aResult.ParseAtomArray(aValue);
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
@ -2278,7 +2173,7 @@ MapBdoAttributesInto(const nsMappedAttributes* aAttributes,
|
|||
nsRuleData* aData)
|
||||
{
|
||||
if (aData->mSID == eStyleStruct_TextReset &&
|
||||
aData->mTextData->mUnicodeBidi.GetUnit() == eCSSUnit_Null) {
|
||||
aData->mTextData->mUnicodeBidi.GetUnit() == eCSSUnit_Null) {
|
||||
aData->mTextData->mUnicodeBidi.SetIntValue(NS_STYLE_UNICODE_BIDI_OVERRIDE, eCSSUnit_Enumerated);
|
||||
}
|
||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
||||
|
@ -2534,24 +2429,9 @@ static const nsHTMLValue::EnumTable kTableVAlignTable[] = {
|
|||
{ 0 }
|
||||
};
|
||||
|
||||
PRBool
|
||||
nsGenericHTMLElement::ParseCommonAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
{
|
||||
if (nsHTMLAtoms::dir == aAttribute) {
|
||||
return aResult.ParseEnumValue(aValue, kDirTable);
|
||||
}
|
||||
else if (nsHTMLAtoms::lang == aAttribute) {
|
||||
aResult.SetStringValue(aValue);
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult)
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
return aResult.ParseEnumValue(aString, kAlignTable);
|
||||
}
|
||||
|
@ -2583,7 +2463,7 @@ static const nsHTMLValue::EnumTable kCompatTableHAlignTable[] = {
|
|||
|
||||
PRBool
|
||||
nsGenericHTMLElement::ParseTableHAlignValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult) const
|
||||
nsAttrValue& aResult) const
|
||||
{
|
||||
if (InNavQuirksMode(mDocument)) {
|
||||
return aResult.ParseEnumValue(aString, kCompatTableHAlignTable);
|
||||
|
@ -2632,7 +2512,7 @@ static const nsHTMLValue::EnumTable kCompatTableCellHAlignTable[] = {
|
|||
|
||||
PRBool
|
||||
nsGenericHTMLElement::ParseTableCellHAlignValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult) const
|
||||
nsAttrValue& aResult) const
|
||||
{
|
||||
if (InNavQuirksMode(mDocument)) {
|
||||
return aResult.ParseEnumValue(aString, kCompatTableCellHAlignTable);
|
||||
|
@ -2654,7 +2534,7 @@ nsGenericHTMLElement::TableCellHAlignValueToString(const nsHTMLValue& aValue,
|
|||
|
||||
PRBool
|
||||
nsGenericHTMLElement::ParseTableVAlignValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult)
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
return aResult.ParseEnumValue(aString, kTableVAlignTable);
|
||||
}
|
||||
|
@ -2682,7 +2562,7 @@ nsGenericHTMLElement::TableVAlignValueToString(const nsHTMLValue& aValue,
|
|||
|
||||
PRBool
|
||||
nsGenericHTMLElement::ParseDivAlignValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult) const
|
||||
nsAttrValue& aResult) const
|
||||
{
|
||||
return aResult.ParseEnumValue(aString, kDivAlignTable);
|
||||
}
|
||||
|
@ -2697,23 +2577,23 @@ nsGenericHTMLElement::DivAlignValueToString(const nsHTMLValue& aValue,
|
|||
PRBool
|
||||
nsGenericHTMLElement::ParseImageAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aString,
|
||||
nsHTMLValue& aResult)
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if ((aAttribute == nsHTMLAtoms::width) ||
|
||||
(aAttribute == nsHTMLAtoms::height)) {
|
||||
return aResult.ParseSpecialIntValue(aString, eHTMLUnit_Integer, PR_TRUE, PR_FALSE);
|
||||
return aResult.ParseSpecialIntValue(aString, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if ((aAttribute == nsHTMLAtoms::hspace) ||
|
||||
(aAttribute == nsHTMLAtoms::vspace) ||
|
||||
(aAttribute == nsHTMLAtoms::border)) {
|
||||
return aResult.ParseIntWithBounds(aString, eHTMLUnit_Integer, 0);
|
||||
return aResult.ParseIntWithBounds(aString, 0);
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsGenericHTMLElement::ParseFrameborderValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult)
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
return aResult.ParseEnumValue(aString, kFrameborderTable);
|
||||
}
|
||||
|
@ -2727,7 +2607,7 @@ nsGenericHTMLElement::FrameborderValueToString(const nsHTMLValue& aValue,
|
|||
|
||||
PRBool
|
||||
nsGenericHTMLElement::ParseScrollingValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult)
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
return aResult.ParseEnumValue(aString, kScrollingTable);
|
||||
}
|
||||
|
@ -2744,9 +2624,7 @@ nsGenericHTMLElement::ReparseStyleAttribute()
|
|||
{
|
||||
const nsAttrValue* oldVal = mAttrsAndChildren.GetAttr(nsHTMLAtoms::style);
|
||||
|
||||
if (oldVal &&
|
||||
(oldVal->GetType() != nsAttrValue::eHTMLValue ||
|
||||
oldVal->GetHTMLValue()->GetUnit() != eHTMLUnit_CSSStyleRule)) {
|
||||
if (oldVal && oldVal->Type() != nsAttrValue::eCSSStyleRule) {
|
||||
nsAttrValue attrValue;
|
||||
nsAutoString stringValue;
|
||||
oldVal->ToString(stringValue);
|
||||
|
@ -2810,7 +2688,7 @@ nsGenericHTMLElement::ParseStyleAttribute(nsIContent* aContent,
|
|||
}
|
||||
|
||||
if (rule) {
|
||||
aResult.SetTo(nsHTMLValue(rule));
|
||||
aResult.SetTo(rule);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -3262,9 +3140,8 @@ void
|
|||
nsGenericHTMLElement::GetIntAttr(nsIAtom* aAttr, PRInt32 aDefault, PRInt32* aResult)
|
||||
{
|
||||
const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(aAttr);
|
||||
if (attrVal && attrVal->GetType() == nsAttrValue::eHTMLValue &&
|
||||
attrVal->GetHTMLValue()->GetUnit() == eHTMLUnit_Integer) {
|
||||
*aResult = attrVal->GetHTMLValue()->GetIntValue();
|
||||
if (attrVal && attrVal->Type() == nsAttrValue::eInteger) {
|
||||
*aResult = attrVal->GetIntegerValue();
|
||||
}
|
||||
else {
|
||||
*aResult = aDefault;
|
||||
|
|
|
@ -235,14 +235,13 @@ public:
|
|||
*
|
||||
* @param aAttribute to attribute to convert
|
||||
* @param aValue the string value to convert
|
||||
* @param aResult the HTMLValue [OUT]
|
||||
* @return NS_CONTENT_ATTR_HAS_VALUE if the string was successfully converted
|
||||
* NS_CONTENT_ATTR_NOT_THERE if the string could not be converted
|
||||
* @param aResult the nsAttrValue [OUT]
|
||||
* @return PR_TRUE if the parsing was successful, PR_FALSE otherwise
|
||||
* @see nsGenericHTMLElement::SetAttr
|
||||
*/
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
|
||||
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
|
||||
|
@ -294,17 +293,6 @@ public:
|
|||
|
||||
//----------------------------------------
|
||||
|
||||
/**
|
||||
* Parse common attributes (currently dir and lang, may be more)
|
||||
*
|
||||
* @param aAttribute the attr to parse
|
||||
* @param aValue the value to parse
|
||||
* @param aResult the resulting HTMLValue
|
||||
* @return whether the value was parsed
|
||||
*/
|
||||
static PRBool ParseCommonAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
/**
|
||||
* Parse an alignment attribute (top/middle/bottom/baseline)
|
||||
*
|
||||
|
@ -313,7 +301,7 @@ public:
|
|||
* @return whether the value was parsed
|
||||
*/
|
||||
static PRBool ParseAlignValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult);
|
||||
nsAttrValue& aResult);
|
||||
|
||||
/**
|
||||
* Parse a div align string to value (left/right/center/middle/justify)
|
||||
|
@ -323,7 +311,7 @@ public:
|
|||
* @return whether the value was parsed
|
||||
*/
|
||||
PRBool ParseDivAlignValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult) const;
|
||||
nsAttrValue& aResult) const;
|
||||
/**
|
||||
* Convert a div align value to string
|
||||
*
|
||||
|
@ -342,7 +330,7 @@ public:
|
|||
* @return whether the value was parsed
|
||||
*/
|
||||
PRBool ParseTableHAlignValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult) const;
|
||||
nsAttrValue& aResult) const;
|
||||
/**
|
||||
* Convert a table halign value to string
|
||||
*
|
||||
|
@ -361,7 +349,7 @@ public:
|
|||
* @return whether the value was parsed
|
||||
*/
|
||||
PRBool ParseTableCellHAlignValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult) const;
|
||||
nsAttrValue& aResult) const;
|
||||
/**
|
||||
* Convert a table cell halign value to string
|
||||
*
|
||||
|
@ -381,7 +369,7 @@ public:
|
|||
* @return whether the value was parsed
|
||||
*/
|
||||
static PRBool ParseTableVAlignValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult);
|
||||
nsAttrValue& aResult);
|
||||
/**
|
||||
* Convert a table valign value to string
|
||||
*
|
||||
|
@ -423,7 +411,7 @@ public:
|
|||
*/
|
||||
static PRBool ParseImageAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aString,
|
||||
nsHTMLValue& aResult);
|
||||
nsAttrValue& aResult);
|
||||
/**
|
||||
* Convert a frameborder string to value (yes/no/1/0)
|
||||
*
|
||||
|
@ -432,7 +420,7 @@ public:
|
|||
* @return whether the value was parsed
|
||||
*/
|
||||
static PRBool ParseFrameborderValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult);
|
||||
nsAttrValue& aResult);
|
||||
/**
|
||||
* Convert a frameborder value to string
|
||||
*
|
||||
|
@ -451,7 +439,7 @@ public:
|
|||
* @return whether the value was parsed
|
||||
*/
|
||||
static PRBool ParseScrollingValue(const nsAString& aString,
|
||||
nsHTMLValue& aResult);
|
||||
nsAttrValue& aResult);
|
||||
/**
|
||||
* Convert a scrolling value to string
|
||||
*
|
||||
|
@ -480,18 +468,6 @@ public:
|
|||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
|
||||
/**
|
||||
* Parse a class attr value into a nsAttrValue. If there is only one class
|
||||
* the resulting type will be an atom. If there are more then one the result
|
||||
* will be an atom-array.
|
||||
* Note: this function is used by other classes than nsGenericHTMLElement
|
||||
*
|
||||
* @param aStr The attributes string-value to parse.
|
||||
* @param aValue The resulting nsAttrValue [OUT]
|
||||
*/
|
||||
static nsresult ParseClassAttribute(const nsAString& aStr,
|
||||
nsAttrValue& aValue);
|
||||
|
||||
/*
|
||||
* Attribute Mapping Helpers
|
||||
*/
|
||||
|
|
|
@ -104,9 +104,9 @@ public:
|
|||
PRBool aCompileEventHandlers);
|
||||
virtual void SetFocus(nsIPresContext* aPresContext);
|
||||
virtual void RemoveFocus(nsIPresContext* aPresContext);
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
virtual nsresult HandleDOMEvent(nsIPresContext* aPresContext,
|
||||
nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
|
@ -302,17 +302,16 @@ nsHTMLAnchorElement::RemoveFocus(nsIPresContext* aPresContext)
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLAnchorElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLAnchorElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0, 32767)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 0, 32767);
|
||||
}
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -76,9 +76,9 @@ public:
|
|||
// nsIDOMHTMLAppletElement
|
||||
NS_DECL_NSIDOMHTMLAPPLETELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -175,21 +175,20 @@ NS_IMPL_STRING_ATTR(nsHTMLAppletElement, Object, object)
|
|||
NS_IMPL_INT_ATTR(nsHTMLAppletElement, Vspace, vspace)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLAppletElement, Width, width)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLAppletElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLAppletElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (nsGenericHTMLElement::ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return nsGenericHTMLElement::ParseAlignValue(aValue, aResult);
|
||||
}
|
||||
else if (nsGenericHTMLElement::ParseImageAttribute(aAttribute,
|
||||
aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
if (nsGenericHTMLElement::ParseImageAttribute(aAttribute,
|
||||
aValue, aResult)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -84,9 +84,9 @@ public:
|
|||
NS_IMETHOD SetLinkState(nsLinkState aState);
|
||||
NS_IMETHOD GetHrefURI(nsIURI** aURI);
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
virtual nsresult HandleDOMEvent(nsIPresContext* aPresContext,
|
||||
nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
|
@ -217,18 +217,16 @@ nsHTMLAreaElement::SetTarget(const nsAString& aValue)
|
|||
return SetAttr(kNameSpaceID_None, nsHTMLAtoms::target, aValue, PR_TRUE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLAreaElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLAreaElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 0, 32767);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -255,7 +255,6 @@ HTML_ATOM(style, "style")
|
|||
HTML_ATOM(summary, "summary")
|
||||
HTML_ATOM(tabindex, "tabindex")
|
||||
HTML_ATOM(table, "table")
|
||||
HTML_ATOM(tabstop, "tabstop")
|
||||
HTML_ATOM(target, "target")
|
||||
HTML_ATOM(tbody, "tbody")
|
||||
HTML_ATOM(td, "td")
|
||||
|
|
|
@ -67,9 +67,9 @@ public:
|
|||
// nsIDOMHTMLBRElement
|
||||
NS_DECL_NSIDOMHTMLBRELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -162,17 +162,16 @@ static const nsHTMLValue::EnumTable kClearTable[] = {
|
|||
{ 0 }
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLBRElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLBRElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::clear) {
|
||||
if (aResult.ParseEnumValue(aValue, kClearTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseEnumValue(aValue, kClearTable);
|
||||
}
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -111,9 +111,9 @@ public:
|
|||
// nsIDOMHTMLBodyElement
|
||||
NS_DECL_NSIDOMHTMLBODYELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
virtual void SetDocument(nsIDocument* aDocument, PRBool aDeep,
|
||||
PRBool aCompileEventHandlers);
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
|
||||
|
@ -388,10 +388,10 @@ nsHTMLBodyElement::Get##func_(nsAString& aColor) \
|
|||
\
|
||||
if (presContext) { \
|
||||
attrColor = presContext->Default##default_(); \
|
||||
nsHTMLValue(attrColor).ToString(aColor); \
|
||||
NS_RGBToHex(attrColor, aColor); \
|
||||
} \
|
||||
} else if (NS_ColorNameToRGB(color, &attrColor)) { \
|
||||
nsHTMLValue(attrColor).ToString(aColor); \
|
||||
NS_RGBToHex(attrColor, aColor); \
|
||||
} else { \
|
||||
aColor.Assign(color); \
|
||||
} \
|
||||
|
@ -439,14 +439,14 @@ nsHTMLBodyElement::GetBgColor(nsAString& aBgColor)
|
|||
|
||||
if (frame) {
|
||||
bgcolor = frame->GetStyleBackground()->mBackgroundColor;
|
||||
nsHTMLValue(bgcolor).ToString(aBgColor);
|
||||
NS_RGBToHex(bgcolor, aBgColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (NS_ColorNameToRGB(attr, &bgcolor)) {
|
||||
// If we have a color name which we can convert to an nscolor,
|
||||
// then we should use the hex value instead of the color name.
|
||||
nsHTMLValue(bgcolor).ToString(aBgColor);
|
||||
NS_RGBToHex(bgcolor, aBgColor);
|
||||
}
|
||||
else {
|
||||
// Otherwise, just assign whatever the attribute value is.
|
||||
|
@ -462,33 +462,28 @@ nsHTMLBodyElement::SetBgColor(const nsAString& aBgColor)
|
|||
return SetAttr(kNameSpaceID_None, nsHTMLAtoms::bgcolor, aBgColor, PR_TRUE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLBodyElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLBodyElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if ((aAttribute == nsHTMLAtoms::bgcolor) ||
|
||||
(aAttribute == nsHTMLAtoms::text) ||
|
||||
(aAttribute == nsHTMLAtoms::link) ||
|
||||
(aAttribute == nsHTMLAtoms::alink) ||
|
||||
(aAttribute == nsHTMLAtoms::vlink)) {
|
||||
if (aResult.ParseColor(aValue,
|
||||
nsGenericHTMLElement::GetOwnerDocument())) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::bgcolor ||
|
||||
aAttribute == nsHTMLAtoms::text ||
|
||||
aAttribute == nsHTMLAtoms::link ||
|
||||
aAttribute == nsHTMLAtoms::alink ||
|
||||
aAttribute == nsHTMLAtoms::vlink) {
|
||||
return aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument());
|
||||
}
|
||||
else if ((aAttribute == nsHTMLAtoms::marginwidth) ||
|
||||
(aAttribute == nsHTMLAtoms::marginheight) ||
|
||||
(aAttribute == nsHTMLAtoms::topmargin) ||
|
||||
(aAttribute == nsHTMLAtoms::bottommargin) ||
|
||||
(aAttribute == nsHTMLAtoms::leftmargin) ||
|
||||
(aAttribute == nsHTMLAtoms::rightmargin)) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::marginwidth ||
|
||||
aAttribute == nsHTMLAtoms::marginheight ||
|
||||
aAttribute == nsHTMLAtoms::topmargin ||
|
||||
aAttribute == nsHTMLAtoms::bottommargin ||
|
||||
aAttribute == nsHTMLAtoms::leftmargin ||
|
||||
aAttribute == nsHTMLAtoms::rightmargin) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -100,9 +100,9 @@ public:
|
|||
// nsIContent overrides...
|
||||
virtual void SetFocus(nsIPresContext* aPresContext);
|
||||
virtual void RemoveFocus(nsIPresContext* aPresContext);
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -316,30 +316,25 @@ static const nsHTMLValue::EnumTable kButtonTypeTable[] = {
|
|||
{ 0 }
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLButtonElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLButtonElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0, 32767)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 0, 32767);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::type) {
|
||||
const nsHTMLValue::EnumTable *table = kButtonTypeTable;
|
||||
nsAutoString val(aValue);
|
||||
while (nsnull != table->tag) {
|
||||
if (val.EqualsIgnoreCase(table->tag)) {
|
||||
aResult.SetIntValue(table->value, eHTMLUnit_Enumerated);
|
||||
mType = table->value;
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
table++;
|
||||
if (aAttribute == nsHTMLAtoms::type) {
|
||||
// XXX ARG!! This is major evilness. ParseAttribute
|
||||
// shouldn't set members. Override SetAttr instead
|
||||
PRBool res = aResult.ParseEnumValue(aValue, kButtonTypeTable);
|
||||
if (res) {
|
||||
mType = aResult.GetEnumValue();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -1,237 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsIDOMHTMLDirectoryElement.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "nsRuleNode.h"
|
||||
|
||||
// XXX nav4 has type= start= (same as OL/UL)
|
||||
|
||||
extern nsHTMLValue::EnumTable kListTypeTable[];
|
||||
|
||||
|
||||
class nsHTMLDirectoryElement : public nsGenericHTMLElement,
|
||||
public nsIDOMHTMLDirectoryElement
|
||||
{
|
||||
public:
|
||||
nsHTMLDirectoryElement();
|
||||
virtual ~nsHTMLDirectoryElement();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIDOMNode
|
||||
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMElement
|
||||
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMHTMLDirectoryElement
|
||||
NS_DECL_NSIDOMHTMLDIRECTORYELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewHTMLDirectoryElement(nsIHTMLContent** aInstancePtrResult,
|
||||
nsINodeInfo *aNodeInfo)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
||||
|
||||
nsHTMLDirectoryElement* it = new nsHTMLDirectoryElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult rv = it->Init(aNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
delete it;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
||||
NS_ADDREF(*aInstancePtrResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsHTMLDirectoryElement::nsHTMLDirectoryElement()
|
||||
{
|
||||
}
|
||||
|
||||
nsHTMLDirectoryElement::~nsHTMLDirectoryElement()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsHTMLDirectoryElement, nsGenericElement)
|
||||
NS_IMPL_RELEASE_INHERITED(nsHTMLDirectoryElement, nsGenericElement)
|
||||
|
||||
|
||||
// QueryInterface implementation for nsHTMLDirectoryElement
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLDirectoryElement,
|
||||
nsGenericHTMLElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLDirectoryElement)
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDirectoryElement)
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_END
|
||||
|
||||
|
||||
nsresult
|
||||
nsHTMLDirectoryElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aReturn);
|
||||
*aReturn = nsnull;
|
||||
|
||||
nsHTMLDirectoryElement* it = new nsHTMLDirectoryElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
||||
|
||||
nsresult rv = it->Init(mNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
CopyInnerTo(it, aDeep);
|
||||
|
||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
||||
|
||||
NS_ADDREF(*aReturn);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_BOOL_ATTR(nsHTMLDirectoryElement, Compact, compact)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDirectoryElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::type) {
|
||||
if (aResult.ParseEnumValue(aValue, kListTypeTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::start) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 1)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDirectoryElement::AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::type) {
|
||||
aValue.EnumValueToString(kListTypeTable, aResult);
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return nsGenericHTMLElement::AttributeToString(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
static void
|
||||
MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
|
||||
{
|
||||
if (aData->mSID == eStyleStruct_List) {
|
||||
if (aData->mListData->mType.GetUnit() == eCSSUnit_Null) {
|
||||
nsHTMLValue value;
|
||||
// type: enum
|
||||
if (aAttributes->GetAttribute(nsHTMLAtoms::type, value) !=
|
||||
NS_CONTENT_ATTR_NOT_THERE) {
|
||||
if (value.GetUnit() == eHTMLUnit_Enumerated)
|
||||
aData->mListData->mType.SetIntValue(value.GetIntValue(), eCSSUnit_Enumerated);
|
||||
else
|
||||
aData->mListData->mType.SetIntValue(NS_STYLE_LIST_STYLE_DISC, eCSSUnit_Enumerated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsHTMLDirectoryElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
||||
{
|
||||
static const MappedAttributeEntry attributes[] = {
|
||||
{ &nsHTMLAtoms::type },
|
||||
// { &nsHTMLAtoms::compact }, // XXX
|
||||
{ nsnull}
|
||||
};
|
||||
|
||||
static const MappedAttributeEntry* const map[] = {
|
||||
attributes,
|
||||
sCommonAttributeMap,
|
||||
};
|
||||
|
||||
return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDirectoryElement::GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const
|
||||
{
|
||||
aMapRuleFunc = &MapAttributesIntoRule;
|
||||
return NS_OK;
|
||||
}
|
|
@ -70,9 +70,9 @@ public:
|
|||
// nsIDOMHTMLDivElement
|
||||
NS_DECL_NSIDOMHTMLDIVELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -160,33 +160,25 @@ nsHTMLDivElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|||
NS_IMPL_STRING_ATTR(nsHTMLDivElement, Align, align)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDivElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLDivElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseDivAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return ParseDivAlignValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::cols) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::cols) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::gutter) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 1)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::gutter) {
|
||||
return aResult.ParseIntWithBounds(aValue, 1);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::width) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::width) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -71,9 +71,9 @@ public:
|
|||
// nsIDOMHTMLFontElement
|
||||
NS_DECL_NSIDOMHTMLFONTELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -161,32 +161,32 @@ NS_IMPL_STRING_ATTR(nsHTMLFontElement, Face, face)
|
|||
NS_IMPL_STRING_ATTR(nsHTMLFontElement, Size, size)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLFontElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLFontElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if ((aAttribute == nsHTMLAtoms::size) ||
|
||||
(aAttribute == nsHTMLAtoms::pointSize) ||
|
||||
(aAttribute == nsHTMLAtoms::fontWeight)) {
|
||||
if (aAttribute == nsHTMLAtoms::size) {
|
||||
nsAutoString tmp(aValue);
|
||||
//rickg: fixed flaw where ToInteger error code was not being checked.
|
||||
// This caused wrong default value for font size.
|
||||
PRInt32 ec, v = tmp.ToInteger(&ec);
|
||||
if(NS_SUCCEEDED(ec)) {
|
||||
tmp.CompressWhitespace(PR_TRUE, PR_FALSE);
|
||||
PRUnichar ch = tmp.IsEmpty() ? 0 : tmp.First();
|
||||
aResult.SetIntValue(v, (ch == '+' || ch == '-') ?
|
||||
eHTMLUnit_Enumerated : eHTMLUnit_Integer);
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
PRUnichar ch = tmp.First();
|
||||
aResult.SetTo(v, (ch == '+' || ch == '-') ?
|
||||
nsAttrValue::eEnum : nsAttrValue::eInteger);
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::color) {
|
||||
if (aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument())) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::pointSize ||
|
||||
aAttribute == nsHTMLAtoms::fontWeight) {
|
||||
return aResult.ParseIntValue(aValue);
|
||||
}
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
if (aAttribute == nsHTMLAtoms::color) {
|
||||
return aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument());
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -164,9 +164,9 @@ public:
|
|||
nsIFormControl* aRadio);
|
||||
|
||||
// nsIContent
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -623,22 +623,19 @@ static const nsHTMLValue::EnumTable kFormEnctypeTable[] = {
|
|||
{ 0 }
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLFormElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLFormElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::method) {
|
||||
if (aResult.ParseEnumValue(aValue, kFormMethodTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseEnumValue(aValue, kFormMethodTable);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::enctype) {
|
||||
if (aResult.ParseEnumValue(aValue, kFormEnctypeTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::enctype) {
|
||||
return aResult.ParseEnumValue(aValue, kFormEnctypeTable);
|
||||
}
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -82,9 +82,9 @@ public:
|
|||
// nsIChromeEventHandler
|
||||
NS_DECL_NSICHROMEEVENTHANDLER
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -224,38 +224,28 @@ nsHTMLFrameElement::GetContentWindow(nsIDOMWindow** aContentWindow)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLFrameElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLFrameElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::bordercolor) {
|
||||
if (aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument())) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument());
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::frameborder) {
|
||||
if (ParseFrameborderValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::frameborder) {
|
||||
return ParseFrameborderValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::marginwidth) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::marginwidth) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::marginheight) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::marginheight) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::scrolling) {
|
||||
if (ParseScrollingValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::scrolling) {
|
||||
return ParseScrollingValue(aValue, aResult);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -84,9 +84,9 @@ public:
|
|||
NS_IMETHOD GetRowSpec(PRInt32 *aNumValues, const nsFramesetSpec** aSpecs);
|
||||
NS_IMETHOD GetColSpec(PRInt32 *aNumValues, const nsFramesetSpec** aSpecs);
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -334,28 +334,22 @@ nsHTMLFrameSetElement::GetColSpec(PRInt32 *aNumValues,
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLFrameSetElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLFrameSetElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::bordercolor) {
|
||||
if (aResult.ParseColor(aValue,
|
||||
nsGenericHTMLElement::GetOwnerDocument())) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument());
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::frameborder) {
|
||||
if (nsGenericHTMLElement::ParseFrameborderValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::frameborder) {
|
||||
return nsGenericHTMLElement::ParseFrameborderValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::border) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0, 100)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::border) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0, 100);
|
||||
}
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -72,9 +72,9 @@ public:
|
|||
// nsIDOMNSHTMLHRElement
|
||||
NS_DECL_NSIDOMNSHTMLHRELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -172,34 +172,25 @@ static const nsHTMLValue::EnumTable kAlignTable[] = {
|
|||
{ 0 }
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLHRElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLHRElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::width) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::size) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 1, 1000)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::size) {
|
||||
return aResult.ParseIntWithBounds(aValue, 1, 1000);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (aResult.ParseEnumValue(aValue, kAlignTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
return aResult.ParseEnumValue(aValue, kAlignTable);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::color) {
|
||||
if (aResult.ParseColor(aValue,
|
||||
nsGenericHTMLElement::GetOwnerDocument())) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::color) {
|
||||
return aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument());
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -67,9 +67,9 @@ public:
|
|||
// nsIDOMHTMLHeadingElement
|
||||
NS_DECL_NSIDOMHTMLHEADINGELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -156,18 +156,16 @@ nsHTMLHeadingElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|||
NS_IMPL_STRING_ATTR(nsHTMLHeadingElement, Align, align)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLHeadingElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLHeadingElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseDivAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return ParseDivAlignValue(aValue, aResult);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -95,9 +95,9 @@ public:
|
|||
virtual void SetDocument(nsIDocument *aDocument, PRBool aDeep,
|
||||
PRBool aCompileEventHandlers);
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -362,48 +362,34 @@ nsHTMLIFrameElement::SetDocument(nsIDocument *aDocument, PRBool aDeep,
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLIFrameElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLIFrameElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::marginwidth) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::marginheight) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::marginheight) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::width) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::width) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::height) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::height) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::frameborder) {
|
||||
if (ParseFrameborderValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::frameborder) {
|
||||
return ParseFrameborderValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::scrolling) {
|
||||
if (ParseScrollingValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::scrolling) {
|
||||
return ParseScrollingValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
return ParseAlignValue(aValue, aResult);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -116,9 +116,9 @@ public:
|
|||
PRUint32 argc, jsval *argv);
|
||||
|
||||
// nsIContent
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -475,26 +475,24 @@ nsHTMLImageElement::SetWidth(PRInt32 aWidth)
|
|||
val, PR_TRUE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLImageElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLImageElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return ParseAlignValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::src) {
|
||||
if (aAttribute == nsHTMLAtoms::src) {
|
||||
static const char* kWhitespace = " \n\r\t\b";
|
||||
aResult.SetStringValue(nsContentUtils::TrimCharsInSet(kWhitespace, aValue));
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
aResult.SetTo(nsContentUtils::TrimCharsInSet(kWhitespace, aValue));
|
||||
return PR_TRUE;
|
||||
}
|
||||
else if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -177,9 +177,9 @@ public:
|
|||
virtual void SetFocus(nsIPresContext* aPresContext);
|
||||
virtual void RemoveFocus(nsIPresContext* aPresContext);
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -1694,79 +1694,58 @@ static const nsHTMLValue::EnumTable kInputTypeTable[] = {
|
|||
{ 0 }
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLInputElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::type) {
|
||||
// XXX ARG!! This is major evilness. StringToAttribute
|
||||
// XXX ARG!! This is major evilness. ParseAttribute
|
||||
// shouldn't set members. Override SetAttr instead
|
||||
const nsHTMLValue::EnumTable *table = kInputTypeTable;
|
||||
nsAutoString valueStr(aValue);
|
||||
while (nsnull != table->tag) {
|
||||
if (valueStr.EqualsIgnoreCase(table->tag)) {
|
||||
// If the type is being changed to file, set the element value
|
||||
// to the empty string. This is for security.
|
||||
if (table->value == NS_FORM_INPUT_FILE) {
|
||||
SetValue(EmptyString());
|
||||
}
|
||||
aResult.SetIntValue(table->value, eHTMLUnit_Enumerated);
|
||||
mType = table->value; // set the type of this input
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
table++;
|
||||
if (!aResult.ParseEnumValue(aValue, kInputTypeTable)) {
|
||||
mType = NS_FORM_INPUT_TEXT;
|
||||
return PR_FALSE;
|
||||
}
|
||||
// Unknown type. We treat this as "text", but we set it as a string, not
|
||||
// as an HTMLValue.
|
||||
mType = NS_FORM_INPUT_TEXT;
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::width) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
|
||||
mType = aResult.GetEnumValue();
|
||||
if (mType == NS_FORM_INPUT_FILE) {
|
||||
// If the type is being changed to file, set the element value
|
||||
// to the empty string. This is for security.
|
||||
SetValue(EmptyString());
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::height) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::width) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::maxlength) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::height) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::size) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::maxlength) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::size) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::border) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0, 32767);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::border) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else {
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
return ParseAlignValue(aValue, aResult);
|
||||
}
|
||||
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
// We have to call |ParseImageAttribute| unconditionally since we
|
||||
// don't know if we're going to have a type="image" attribute yet,
|
||||
// (or could have it set dynamically in the future). See bug
|
||||
// 214077.
|
||||
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -67,9 +67,9 @@ public:
|
|||
// nsIDOMHTMLLIElement
|
||||
NS_DECL_NSIDOMHTMLLIELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -174,26 +174,20 @@ static const nsHTMLValue::EnumTable kOrderedListItemTypeTable[] = {
|
|||
{ 0 }
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLLIElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLLIElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::type) {
|
||||
if (aResult.ParseEnumValue(aValue, kOrderedListItemTypeTable, PR_TRUE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aResult.ParseEnumValue(aValue, kUnorderedListItemTypeTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseEnumValue(aValue, kOrderedListItemTypeTable, PR_TRUE) ||
|
||||
aResult.ParseEnumValue(aValue, kUnorderedListItemTypeTable);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::value) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::value) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -76,9 +76,9 @@ public:
|
|||
nsIContent* aSubmitElement);
|
||||
|
||||
// nsIContent
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -184,18 +184,16 @@ static const nsHTMLValue::EnumTable kAlignTable[] = {
|
|||
{ 0 }
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLLegendElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLLegendElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (aResult.ParseEnumValue(aValue, kAlignTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseEnumValue(aValue, kAlignTable);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -1,238 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsIDOMHTMLMenuElement.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "nsRuleNode.h"
|
||||
|
||||
// XXX nav4 has type= start= (same as OL/UL)
|
||||
|
||||
extern nsHTMLValue::EnumTable kListTypeTable[];
|
||||
|
||||
|
||||
class nsHTMLMenuElement : public nsGenericHTMLElement,
|
||||
public nsIDOMHTMLMenuElement
|
||||
{
|
||||
public:
|
||||
nsHTMLMenuElement();
|
||||
virtual ~nsHTMLMenuElement();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIDOMNode
|
||||
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMElement
|
||||
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMHTMLMenuElement
|
||||
NS_IMETHOD GetCompact(PRBool* aCompact);
|
||||
NS_IMETHOD SetCompact(PRBool aCompact);
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
|
||||
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewHTMLMenuElement(nsIHTMLContent** aInstancePtrResult,
|
||||
nsINodeInfo *aNodeInfo)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
||||
|
||||
nsHTMLMenuElement* it = new nsHTMLMenuElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult rv = it->Init(aNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
delete it;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
||||
NS_ADDREF(*aInstancePtrResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsHTMLMenuElement::nsHTMLMenuElement()
|
||||
{
|
||||
}
|
||||
|
||||
nsHTMLMenuElement::~nsHTMLMenuElement()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsHTMLMenuElement, nsGenericElement)
|
||||
NS_IMPL_RELEASE_INHERITED(nsHTMLMenuElement, nsGenericElement)
|
||||
|
||||
|
||||
// QueryInterface implementation for nsHTMLMenuElement
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLMenuElement, nsGenericHTMLElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLMenuElement)
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLMenuElement)
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_END
|
||||
|
||||
|
||||
nsresult
|
||||
nsHTMLMenuElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aReturn);
|
||||
*aReturn = nsnull;
|
||||
|
||||
nsHTMLMenuElement* it = new nsHTMLMenuElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
||||
|
||||
nsresult rv = it->Init(mNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
CopyInnerTo(it, aDeep);
|
||||
|
||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
||||
|
||||
NS_ADDREF(*aReturn);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_BOOL_ATTR(nsHTMLMenuElement, Compact, compact)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLMenuElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::type) {
|
||||
if (aResult.ParseEnumValue(aValue, kListTypeTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::start) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 1)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLMenuElement::AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::type) {
|
||||
aValue.EnumValueToString(kListTypeTable, aResult);
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::AttributeToString(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
static void
|
||||
MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
|
||||
{
|
||||
if (aData->mSID == eStyleStruct_List) {
|
||||
if (aData->mListData->mType.GetUnit() == eCSSUnit_Null) {
|
||||
nsHTMLValue value;
|
||||
// type: enum
|
||||
if (aAttributes->GetAttribute(nsHTMLAtoms::type, value) !=
|
||||
NS_CONTENT_ATTR_NOT_THERE) {
|
||||
if (value.GetUnit() == eHTMLUnit_Enumerated)
|
||||
aData->mListData->mType.SetIntValue(value.GetIntValue(), eCSSUnit_Enumerated);
|
||||
else
|
||||
aData->mListData->mType.SetIntValue(NS_STYLE_LIST_STYLE_DISC, eCSSUnit_Enumerated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsHTMLMenuElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
||||
{
|
||||
static const MappedAttributeEntry attributes[] = {
|
||||
{ &nsHTMLAtoms::type },
|
||||
{ nsnull }
|
||||
};
|
||||
|
||||
static const MappedAttributeEntry* const map[] = {
|
||||
attributes,
|
||||
sCommonAttributeMap,
|
||||
};
|
||||
|
||||
return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLMenuElement::GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const
|
||||
{
|
||||
aMapRuleFunc = &MapAttributesIntoRule;
|
||||
return NS_OK;
|
||||
}
|
|
@ -67,9 +67,9 @@ public:
|
|||
// nsIDOMHTMLOListElement
|
||||
NS_DECL_NSIDOMHTMLOLISTELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -181,27 +181,22 @@ nsHTMLValue::EnumTable kOldListTypeTable[] = {
|
|||
{ 0 }
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLOListElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLOListElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::type) {
|
||||
if (aResult.ParseEnumValue(aValue, kListTypeTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
|
||||
if (aResult.ParseEnumValue(aValue, kOldListTypeTable, PR_TRUE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseEnumValue(aValue, kListTypeTable) ||
|
||||
aResult.ParseEnumValue(aValue, kOldListTypeTable, PR_TRUE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::start) {
|
||||
if (aResult.ParseIntValue(aValue, eHTMLUnit_Integer)) {
|
||||
if (aAttribute == nsHTMLAtoms::start) {
|
||||
if (aResult.ParseIntValue(aValue)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -79,9 +79,9 @@ public:
|
|||
NS_IMETHOD SaveState();
|
||||
NS_IMETHOD RestoreState(nsIPresState* aState);
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -238,26 +238,22 @@ nsHTMLObjectElement::GetContentDocument(nsIDOMDocument** aContentDocument)
|
|||
return CallQueryInterface(sub_doc, aContentDocument);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLObjectElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return ParseAlignValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0, 32767);
|
||||
}
|
||||
else if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -70,9 +70,9 @@ public:
|
|||
// nsIDOMHTMLParagraphElement
|
||||
NS_DECL_NSIDOMHTMLPARAGRAPHELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -160,17 +160,16 @@ nsHTMLParagraphElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|||
NS_IMPL_STRING_ATTR(nsHTMLParagraphElement, Align, align)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLParagraphElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLParagraphElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseDivAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return ParseDivAlignValue(aValue, aResult);
|
||||
}
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -72,12 +72,9 @@ public:
|
|||
NS_IMETHOD GetWidth(PRInt32* aWidth);
|
||||
NS_IMETHOD SetWidth(PRInt32 aWidth);
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
NS_IMETHOD GetAttributeChangeHint(const nsIAtom* aAttribute,
|
||||
PRInt32 aModType,
|
||||
nsChangeHint& aHint) const;
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
|
||||
};
|
||||
|
@ -161,35 +158,19 @@ nsHTMLPreElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|||
NS_IMPL_INT_ATTR(nsHTMLPreElement, Width, width)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLPreElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLPreElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::cols) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::width) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::tabstop) {
|
||||
nsAutoString val(aValue);
|
||||
|
||||
PRInt32 ec, tabstop = val.ToInteger(&ec);
|
||||
|
||||
if (tabstop <= 0) {
|
||||
tabstop = 8;
|
||||
}
|
||||
|
||||
aResult.SetIntValue(tabstop, eHTMLUnit_Integer);
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
if (aAttribute == nsHTMLAtoms::width) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -242,19 +223,6 @@ MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
|||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLPreElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
||||
PRInt32 aModType,
|
||||
nsChangeHint& aHint) const
|
||||
{
|
||||
nsresult rv =
|
||||
nsGenericHTMLElement::GetAttributeChangeHint(aAttribute, aModType, aHint);
|
||||
if (aAttribute == nsHTMLAtoms::tabstop) {
|
||||
NS_UpdateHint(aHint, NS_STYLE_HINT_REFLOW);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsHTMLPreElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
||||
{
|
||||
|
|
|
@ -239,9 +239,9 @@ public:
|
|||
// nsISelectElement
|
||||
NS_DECL_NSISELECTELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
|
||||
NS_IMETHOD GetAttributeChangeHint(const nsIAtom* aAttribute,
|
||||
PRInt32 aModType,
|
||||
|
@ -1785,23 +1785,19 @@ nsHTMLSelectElement::DoneAddingChildren()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLSelectElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLSelectElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::size) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0, 32767);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -93,9 +93,9 @@ public:
|
|||
// nsIDOMHTMLBaseElement
|
||||
NS_DECL_NSIDOMHTMLBASEELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -224,37 +224,32 @@ NS_IMPL_STRING_ATTR(nsHTMLSharedLeafElement, Target, target)
|
|||
|
||||
// spacer element code
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLSharedLeafElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLSharedLeafElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (mNodeInfo->Equals(nsHTMLAtoms::embed)) {
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
} else if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
return ParseAlignValue(aValue, aResult);
|
||||
}
|
||||
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
} else if (mNodeInfo->Equals(nsHTMLAtoms::spacer)) {
|
||||
if (aAttribute == nsHTMLAtoms::size) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
} else if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
} else if ((aAttribute == nsHTMLAtoms::width) ||
|
||||
(aAttribute == nsHTMLAtoms::height)) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
return ParseAlignValue(aValue, aResult);
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::width ||
|
||||
aAttribute == nsHTMLAtoms::height) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::StringToAttribute(aAttribute, aValue, aResult);
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -1,440 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsIDOMHTMLEmbedElement.h"
|
||||
#include "nsIDOMHTMLIsIndexElement.h"
|
||||
#include "nsIDOMHTMLParamElement.h"
|
||||
#include "nsIDOMHTMLBaseElement.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsImageLoadingContent.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsRuleNode.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "nsStyleContext.h"
|
||||
|
||||
|
||||
class nsHTMLSharedLeafElement : public nsGenericHTMLElement,
|
||||
public nsImageLoadingContent,
|
||||
public nsIDOMHTMLEmbedElement,
|
||||
public nsIDOMHTMLIsIndexElement,
|
||||
public nsIDOMHTMLParamElement,
|
||||
public nsIDOMHTMLBaseElement
|
||||
{
|
||||
public:
|
||||
nsHTMLSharedLeafElement();
|
||||
virtual ~nsHTMLSharedLeafElement();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIDOMNode
|
||||
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMElement
|
||||
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMHTMLEmbedElement
|
||||
NS_DECL_NSIDOMHTMLEMBEDELEMENT
|
||||
|
||||
// nsIDOMHTMLIsIndexElement
|
||||
NS_DECL_NSIDOMHTMLISINDEXELEMENT
|
||||
|
||||
// nsIDOMHTMLParamElement Can't use the macro
|
||||
// NS_DECL_NSIDOMHTMLPARAMELEMENT since some of the methods in
|
||||
// nsIDOMHTMLParamElement clashes with methods in
|
||||
// nsIDOMHTMLEmbedElement
|
||||
|
||||
NS_IMETHOD GetValue(nsAString& aValue);
|
||||
NS_IMETHOD SetValue(const nsAString& aValue);
|
||||
NS_IMETHOD GetValueType(nsAString& aValueType);
|
||||
NS_IMETHOD SetValueType(const nsAString& aValueType);
|
||||
|
||||
// nsIDOMHTMLBaseElement
|
||||
NS_DECL_NSIDOMHTMLBASEELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
|
||||
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewHTMLSharedLeafElement(nsIHTMLContent** aInstancePtrResult,
|
||||
nsINodeInfo *aNodeInfo)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
||||
|
||||
nsHTMLSharedLeafElement* it = new nsHTMLSharedLeafElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult rv = it->Init(aNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
delete it;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
||||
NS_ADDREF(*aInstancePtrResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsHTMLSharedLeafElement::nsHTMLSharedLeafElement()
|
||||
{
|
||||
}
|
||||
|
||||
nsHTMLSharedLeafElement::~nsHTMLSharedLeafElement()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsHTMLSharedLeafElement, nsGenericElement)
|
||||
NS_IMPL_RELEASE_INHERITED(nsHTMLSharedLeafElement, nsGenericElement)
|
||||
|
||||
|
||||
// QueryInterface implementation for nsHTMLSharedLeafElement
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_AMBIGOUS_BEGIN(nsHTMLSharedLeafElement,
|
||||
nsGenericHTMLElement,
|
||||
nsIDOMHTMLEmbedElement)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMHTMLElement, nsIDOMHTMLEmbedElement)
|
||||
NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLEmbedElement, embed)
|
||||
NS_INTERFACE_MAP_ENTRY_IF_TAG(imgIDecoderObserver, embed)
|
||||
NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIImageLoadingContent, embed)
|
||||
NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLParamElement, param)
|
||||
NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLIsIndexElement, isindex)
|
||||
NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLBaseElement, base)
|
||||
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_IF_TAG(HTMLEmbedElement, embed)
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_IF_TAG(HTMLParamElement, param)
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_IF_TAG(HTMLWBRElement, wbr)
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_IF_TAG(HTMLIsIndexElement, isindex)
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_IF_TAG(HTMLBaseElement, base)
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO_IF_TAG(HTMLSpacerElement, spacer)
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_END
|
||||
|
||||
|
||||
nsresult
|
||||
nsHTMLSharedLeafElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aReturn);
|
||||
*aReturn = nsnull;
|
||||
|
||||
nsHTMLSharedLeafElement* it = new nsHTMLSharedLeafElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> kungFuDeathGrip =
|
||||
NS_STATIC_CAST(nsIDOMHTMLEmbedElement *, it);
|
||||
|
||||
nsresult rv = it->Init(mNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
CopyInnerTo(it, aDeep);
|
||||
|
||||
*aReturn = NS_STATIC_CAST(nsIDOMHTMLEmbedElement *, it);
|
||||
|
||||
NS_ADDREF(*aReturn);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// Implement nsIDOMHTMLEmbedElement interface
|
||||
NS_IMPL_STRING_ATTR(nsHTMLSharedLeafElement, Align, align)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLSharedLeafElement, Height, height)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLSharedLeafElement, Width, width)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLSharedLeafElement, Name, name)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLSharedLeafElement, Type, type)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLSharedLeafElement, Src, src)
|
||||
|
||||
// nsIDOMHTMLParamElement
|
||||
NS_IMPL_STRING_ATTR(nsHTMLSharedLeafElement, Value, value)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLSharedLeafElement, ValueType, valuetype)
|
||||
|
||||
// nsIDOMHTMLIsIndexElement
|
||||
NS_IMPL_STRING_ATTR(nsHTMLSharedLeafElement, Prompt, prompt)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLSharedLeafElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
||||
{
|
||||
*aForm = FindForm().get();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIDOMHTMLBaseElement
|
||||
NS_IMPL_URI_ATTR(nsHTMLSharedLeafElement, Href, href)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLSharedLeafElement, Target, target)
|
||||
|
||||
// spacer element code
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLSharedLeafElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
{
|
||||
if (mNodeInfo->Equals(nsHTMLAtoms::embed)) {
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
} else if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
} else if (mNodeInfo->Equals(nsHTMLAtoms::spacer)) {
|
||||
if (aAttribute == nsHTMLAtoms::size) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
} else if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
} else if ((aAttribute == nsHTMLAtoms::width) ||
|
||||
(aAttribute == nsHTMLAtoms::height)) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::StringToAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLSharedLeafElement::AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const
|
||||
{
|
||||
if (mNodeInfo->Equals(nsHTMLAtoms::embed)) {
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
|
||||
AlignValueToString(aValue, aResult);
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
} else if (mNodeInfo->Equals(nsHTMLAtoms::spacer)) {
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
|
||||
AlignValueToString(aValue, aResult);
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::AttributeToString(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
static void
|
||||
SpacerMapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
||||
nsRuleData* aData)
|
||||
{
|
||||
nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData);
|
||||
nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
|
||||
|
||||
if (aData->mSID == eStyleStruct_Position) {
|
||||
nsHTMLValue value;
|
||||
|
||||
const nsStyleDisplay* display = aData->mStyleContext->GetStyleDisplay();
|
||||
|
||||
PRBool typeIsBlock = (display->mDisplay == NS_STYLE_DISPLAY_BLOCK);
|
||||
|
||||
if (typeIsBlock) {
|
||||
// width: value
|
||||
if (aData->mPositionData->mWidth.GetUnit() == eCSSUnit_Null) {
|
||||
aAttributes->GetAttribute(nsHTMLAtoms::width, value);
|
||||
if (value.GetUnit() == eHTMLUnit_Integer) {
|
||||
aData->mPositionData->
|
||||
mWidth.SetFloatValue((float)value.GetIntValue(), eCSSUnit_Pixel);
|
||||
} else if (value.GetUnit() == eHTMLUnit_Percent) {
|
||||
aData->mPositionData->
|
||||
mWidth.SetPercentValue(value.GetPercentValue());
|
||||
}
|
||||
}
|
||||
|
||||
// height: value
|
||||
if (aData->mPositionData->mHeight.GetUnit() == eCSSUnit_Null) {
|
||||
aAttributes->GetAttribute(nsHTMLAtoms::height, value);
|
||||
if (value.GetUnit() == eHTMLUnit_Integer) {
|
||||
aData->mPositionData->
|
||||
mHeight.SetFloatValue((float)value.GetIntValue(),
|
||||
eCSSUnit_Pixel);
|
||||
} else if (value.GetUnit() == eHTMLUnit_Percent) {
|
||||
aData->mPositionData->
|
||||
mHeight.SetPercentValue(value.GetPercentValue());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// size: value
|
||||
if (aData->mPositionData->mWidth.GetUnit() == eCSSUnit_Null) {
|
||||
aAttributes->GetAttribute(nsHTMLAtoms::size, value);
|
||||
if (value.GetUnit() == eHTMLUnit_Integer)
|
||||
aData->mPositionData->
|
||||
mWidth.SetFloatValue((float)value.GetIntValue(),
|
||||
eCSSUnit_Pixel);
|
||||
}
|
||||
}
|
||||
} else if (aData->mSID == eStyleStruct_Display) {
|
||||
nsHTMLValue value;
|
||||
aAttributes->GetAttribute(nsHTMLAtoms::align, value);
|
||||
if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
||||
PRUint8 align = (PRUint8)(value.GetIntValue());
|
||||
if (aData->mDisplayData->mFloat.GetUnit() == eCSSUnit_Null) {
|
||||
if (align == NS_STYLE_TEXT_ALIGN_LEFT)
|
||||
aData->mDisplayData->mFloat.SetIntValue(NS_STYLE_FLOAT_LEFT,
|
||||
eCSSUnit_Enumerated);
|
||||
else if (align == NS_STYLE_TEXT_ALIGN_RIGHT)
|
||||
aData->mDisplayData->mFloat.SetIntValue(NS_STYLE_FLOAT_RIGHT,
|
||||
eCSSUnit_Enumerated);
|
||||
}
|
||||
}
|
||||
|
||||
if (aData->mDisplayData->mDisplay == eCSSUnit_Null) {
|
||||
if (aAttributes->GetAttribute(nsHTMLAtoms::type, value) !=
|
||||
NS_CONTENT_ATTR_NOT_THERE &&
|
||||
eHTMLUnit_String == value.GetUnit()) {
|
||||
nsAutoString tmp;
|
||||
value.GetStringValue(tmp);
|
||||
if (tmp.EqualsIgnoreCase("line") ||
|
||||
tmp.EqualsIgnoreCase("vert") ||
|
||||
tmp.EqualsIgnoreCase("vertical") ||
|
||||
tmp.EqualsIgnoreCase("block")) {
|
||||
// This is not strictly 100% compatible: if the spacer is given
|
||||
// a width of zero then it is basically ignored.
|
||||
aData->mDisplayData->mDisplay = NS_STYLE_DISPLAY_BLOCK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
||||
}
|
||||
|
||||
static void
|
||||
EmbedMapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
||||
nsRuleData* aData)
|
||||
{
|
||||
if (!aData)
|
||||
return;
|
||||
|
||||
nsGenericHTMLElement::MapImageBorderAttributeInto(aAttributes, aData);
|
||||
nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData);
|
||||
nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
|
||||
nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aData);
|
||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
PlainMapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
||||
nsRuleData* aData)
|
||||
{
|
||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsHTMLSharedLeafElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
||||
{
|
||||
if (mNodeInfo->Equals(nsHTMLAtoms::embed)) {
|
||||
static const MappedAttributeEntry* const map[] = {
|
||||
sCommonAttributeMap,
|
||||
sImageMarginSizeAttributeMap,
|
||||
sImageAlignAttributeMap,
|
||||
sImageBorderAttributeMap
|
||||
};
|
||||
|
||||
return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
|
||||
}
|
||||
|
||||
if (mNodeInfo->Equals(nsHTMLAtoms::spacer)) {
|
||||
static const MappedAttributeEntry attributes[] = {
|
||||
// XXXldb This is just wrong.
|
||||
{ &nsHTMLAtoms::usemap },
|
||||
{ &nsHTMLAtoms::ismap },
|
||||
{ &nsHTMLAtoms::align },
|
||||
{ nsnull }
|
||||
};
|
||||
|
||||
static const MappedAttributeEntry* const map[] = {
|
||||
attributes,
|
||||
sCommonAttributeMap,
|
||||
sImageMarginSizeAttributeMap,
|
||||
sImageBorderAttributeMap,
|
||||
};
|
||||
|
||||
return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::IsAttributeMapped(aAttribute);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLSharedLeafElement::GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const
|
||||
{
|
||||
if (mNodeInfo->Equals(nsHTMLAtoms::embed)) {
|
||||
aMapRuleFunc = &EmbedMapAttributesIntoRule;
|
||||
} else if (mNodeInfo->Equals(nsHTMLAtoms::spacer)) {
|
||||
aMapRuleFunc = &SpacerMapAttributesIntoRule;
|
||||
} else {
|
||||
aMapRuleFunc = &PlainMapAttributesIntoRule;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -79,9 +79,9 @@ public:
|
|||
NS_IMETHOD SaveState();
|
||||
NS_IMETHOD RestoreState(nsIPresState* aState);
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -238,26 +238,22 @@ nsHTMLObjectElement::GetContentDocument(nsIDOMDocument** aContentDocument)
|
|||
return CallQueryInterface(sub_doc, aContentDocument);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLObjectElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLObjectElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (ParseAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return ParseAlignValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0, 32767);
|
||||
}
|
||||
else if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -67,9 +67,9 @@ public:
|
|||
// nsIDOMHTMLTableCaptionElement
|
||||
NS_DECL_NSIDOMHTMLTABLECAPTIONELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -165,17 +165,16 @@ static const nsHTMLValue::EnumTable kCaptionAlignTable[] = {
|
|||
{ 0 }
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLTableCaptionElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLTableCaptionElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
if (aResult.ParseEnumValue(aValue, kCaptionAlignTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseEnumValue(aValue, kCaptionAlignTable);
|
||||
}
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -76,9 +76,9 @@ public:
|
|||
NS_METHOD GetColIndex (PRInt32* aColIndex);
|
||||
NS_METHOD SetColIndex (PRInt32 aColIndex);
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -334,78 +334,52 @@ static const nsHTMLValue::EnumTable kCellScopeTable[] = {
|
|||
{ 0 }
|
||||
};
|
||||
|
||||
#define MAX_COLSPAN 8190
|
||||
#define MAX_ROWSPAN 8190 // celldata.h can not handle more
|
||||
#define MAX_COLROWSPAN 8190 // celldata.h can not handle more
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLTableCellElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLTableCellElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
/* ignore these attributes, stored simply as strings
|
||||
abbr, axis, ch, headers
|
||||
*/
|
||||
if (aAttribute == nsHTMLAtoms::charoff) {
|
||||
/* attributes that resolve to integers with a min of 0 */
|
||||
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else if ((aAttribute == nsHTMLAtoms::colspan) ||
|
||||
(aAttribute == nsHTMLAtoms::rowspan)) {
|
||||
PRBool parsed = (aAttribute == nsHTMLAtoms::colspan)
|
||||
? aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, -1, MAX_COLSPAN)
|
||||
: aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, -1, MAX_ROWSPAN);
|
||||
if (parsed) {
|
||||
PRInt32 val = aResult.GetIntValue();
|
||||
PRBool res = aResult.ParseIntWithBounds(aValue, -1, MAX_COLROWSPAN);
|
||||
if (res) {
|
||||
PRInt32 val = aResult.GetIntegerValue();
|
||||
// quirks mode does not honor the special html 4 value of 0
|
||||
if ((val < 0) || ((0 == val) && InNavQuirksMode(mDocument))) {
|
||||
nsHTMLUnit unit = aResult.GetUnit();
|
||||
aResult.SetIntValue(1, unit);
|
||||
if (val < 0 || (0 == val && InNavQuirksMode(mDocument))) {
|
||||
aResult.SetTo(1, nsAttrValue::eInteger);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::height) {
|
||||
/* attributes that resolve to integers or percents */
|
||||
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::height) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::width) {
|
||||
/* attributes that resolve to integers or percents */
|
||||
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::width) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::align) {
|
||||
/* other attributes */
|
||||
|
||||
if (ParseTableCellHAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
return ParseTableCellHAlignValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::bgcolor) {
|
||||
if (aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument())) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::bgcolor) {
|
||||
return aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument());
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::scope) {
|
||||
if (aResult.ParseEnumValue(aValue, kCellScopeTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::scope) {
|
||||
return aResult.ParseEnumValue(aValue, kCellScopeTable);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
||||
if (ParseTableVAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::valign) {
|
||||
return ParseTableVAlignValue(aValue, aResult);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -76,9 +76,9 @@ public:
|
|||
// nsIHTMLTableColElement
|
||||
NS_IMETHOD GetSpanValue(PRInt32* aSpan);
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -172,45 +172,30 @@ NS_IMPL_STRING_ATTR_DEFAULT_VALUE(nsHTMLTableColElement, VAlign, valign, "middle
|
|||
NS_IMPL_STRING_ATTR(nsHTMLTableColElement, Width, width)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLTableColElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLTableColElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
/* ignore these attributes, stored simply as strings ch */
|
||||
/* attributes that resolve to integers */
|
||||
if (aAttribute == nsHTMLAtoms::charoff) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::span) {
|
||||
if (aAttribute == nsHTMLAtoms::span) {
|
||||
/* protection from unrealistic large colspan values */
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 1, MAX_COLSPAN)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 1, MAX_COLSPAN);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::width) {
|
||||
/* attributes that resolve to integers or percents or proportions */
|
||||
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_TRUE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::width) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_TRUE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::align) {
|
||||
/* other attributes */
|
||||
|
||||
if (ParseTableCellHAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
return ParseTableCellHAlignValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
||||
if (ParseTableVAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::valign) {
|
||||
return ParseTableVAlignValue(aValue, aResult);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -83,9 +83,9 @@ public:
|
|||
// nsIDOMHTMLTableElement
|
||||
NS_DECL_NSIDOMHTMLTABLEELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -941,97 +941,63 @@ static const nsHTMLValue::EnumTable kLayoutTable[] = {
|
|||
};
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLTableElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLTableElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
/* ignore summary, just a string */
|
||||
/* attributes that resolve to integer, with min=0 */
|
||||
if (aAttribute == nsHTMLAtoms::cellspacing ||
|
||||
aAttribute == nsHTMLAtoms::cellpadding) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::cols) {
|
||||
/* attributes that are either empty, or integers, with min=0 */
|
||||
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::cols) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::border) {
|
||||
/* attributes that are either empty, or integer */
|
||||
|
||||
PRInt32 min = (aValue.IsEmpty()) ? 1 : 0;
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, min)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
else {
|
||||
if (aAttribute == nsHTMLAtoms::border) {
|
||||
if (!aResult.ParseIntWithBounds(aValue, 0)) {
|
||||
// XXX this should really be NavQuirks only to allow non numeric value
|
||||
aResult.SetIntValue(1, eHTMLUnit_Integer);
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
aResult.SetTo(1, nsAttrValue::eInteger);
|
||||
}
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::height) {
|
||||
/* attributes that resolve to integers or percents */
|
||||
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::width) {
|
||||
/* attributes that resolve to integers or percents or proportions */
|
||||
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
if (aAttribute == nsHTMLAtoms::height) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::width) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE)) {
|
||||
// treat 0 width as auto
|
||||
nsHTMLUnit unit = aResult.GetUnit();
|
||||
if ((eHTMLUnit_Integer == unit) && (0 == aResult.GetIntValue())) {
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
nsAttrValue::ValueType type = aResult.Type();
|
||||
if ((type == nsAttrValue::eInteger && aResult.GetIntegerValue() == 0) ||
|
||||
(type == nsAttrValue::ePercent && aResult.GetPercentValue() == 0.0f)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
else if ((eHTMLUnit_Percent == unit) && (0.0f == aResult.GetPercentValue())) {
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::align) {
|
||||
/* other attributes */
|
||||
|
||||
if (ParseTableHAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
return ParseTableHAlignValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::bgcolor ||
|
||||
if (aAttribute == nsHTMLAtoms::bgcolor ||
|
||||
aAttribute == nsHTMLAtoms::bordercolor) {
|
||||
if (aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument())) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument());
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::frame) {
|
||||
if (aResult.ParseEnumValue(aValue, kFrameTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::frame) {
|
||||
return aResult.ParseEnumValue(aValue, kFrameTable);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::layout) {
|
||||
if (aResult.ParseEnumValue(aValue, kLayoutTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::layout) {
|
||||
return aResult.ParseEnumValue(aValue, kLayoutTable);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::rules) {
|
||||
if (aResult.ParseEnumValue(aValue, kRulesTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::rules) {
|
||||
return aResult.ParseEnumValue(aValue, kRulesTable);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::hspace ||
|
||||
if (aAttribute == nsHTMLAtoms::hspace ||
|
||||
aAttribute == nsHTMLAtoms::vspace) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -169,9 +169,9 @@ public:
|
|||
// nsIDOMHTMLTableRowElement
|
||||
NS_DECL_NSIDOMHTMLTABLEROWELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -506,10 +506,10 @@ NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, ChOff, charoff)
|
|||
NS_IMPL_STRING_ATTR_DEFAULT_VALUE(nsHTMLTableRowElement, VAlign, valign, "middle")
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLTableRowElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLTableRowElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
/*
|
||||
* ignore these attributes, stored simply as strings
|
||||
|
@ -517,45 +517,28 @@ nsHTMLTableRowElement::StringToAttribute(nsIAtom* aAttribute,
|
|||
* ch
|
||||
*/
|
||||
|
||||
/* attributes that resolve to integers with default = 0 */
|
||||
if (aAttribute == nsHTMLAtoms::charoff) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::height) {
|
||||
if (aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::height) {
|
||||
/* attributes that resolve to integers or percents */
|
||||
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::width) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::width) {
|
||||
/* attributes that resolve to integers or percents */
|
||||
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
return ParseTableCellHAlignValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::align) {
|
||||
/* other attributes */
|
||||
|
||||
if (ParseTableCellHAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::bgcolor) {
|
||||
return aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument());
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::bgcolor) {
|
||||
if (aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument())) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
||||
if (ParseTableVAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::valign) {
|
||||
return ParseTableVAlignValue(aValue, aResult);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -73,9 +73,9 @@ public:
|
|||
// nsIDOMHTMLTableSectionElement
|
||||
NS_DECL_NSIDOMHTMLTABLESECTIONELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
@ -282,46 +282,31 @@ nsHTMLTableSectionElement::DeleteRow(PRInt32 aValue)
|
|||
return RemoveChild(row, getter_AddRefs(retChild));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLTableSectionElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLTableSectionElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
/* ignore these attributes, stored simply as strings
|
||||
ch
|
||||
*/
|
||||
/* attributes that resolve to integers */
|
||||
if (aAttribute == nsHTMLAtoms::charoff) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::height) {
|
||||
/* attributes that resolve to integers or percents */
|
||||
|
||||
if (aResult.ParseSpecialIntValue(aValue, eHTMLUnit_Integer, PR_TRUE, PR_FALSE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::height) {
|
||||
return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::align) {
|
||||
/* other attributes */
|
||||
|
||||
if (ParseTableCellHAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::align) {
|
||||
return ParseTableCellHAlignValue(aValue, aResult);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::bgcolor) {
|
||||
if (aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument())) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::bgcolor) {
|
||||
return aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument());
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
||||
if (ParseTableVAlignValue(aValue, aResult)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::valign) {
|
||||
return ParseTableVAlignValue(aValue, aResult);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -125,9 +125,9 @@ public:
|
|||
virtual nsresult AppendChildTo(nsIContent* aKid, PRBool aNotify,
|
||||
PRBool aDeepSetDocument);
|
||||
virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify);
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
|
||||
NS_IMETHOD GetAttributeChangeHint(const nsIAtom* aAttribute,
|
||||
PRInt32 aModType,
|
||||
|
@ -568,28 +568,22 @@ nsHTMLTextAreaElement::RemoveChildAt(PRUint32 aIndex, PRBool aNotify)
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLTextAreaElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
PRBool
|
||||
nsHTMLTextAreaElement::ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::cols) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::rows) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::rows) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0);
|
||||
}
|
||||
else if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::tabindex) {
|
||||
return aResult.ParseIntWithBounds(aValue, 0, 32767);
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -1,256 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsIDOMHTMLUListElement.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "nsRuleNode.h"
|
||||
|
||||
extern nsHTMLValue::EnumTable kListTypeTable[];
|
||||
extern nsHTMLValue::EnumTable kOldListTypeTable[];
|
||||
|
||||
class nsHTMLUListElement : public nsGenericHTMLElement,
|
||||
public nsIDOMHTMLUListElement
|
||||
{
|
||||
public:
|
||||
nsHTMLUListElement();
|
||||
virtual ~nsHTMLUListElement();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIDOMNode
|
||||
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMElement
|
||||
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
|
||||
|
||||
// nsIDOMHTMLUListElement
|
||||
NS_DECL_NSIDOMHTMLULISTELEMENT
|
||||
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
|
||||
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewHTMLUListElement(nsIHTMLContent** aInstancePtrResult,
|
||||
nsINodeInfo *aNodeInfo)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
||||
|
||||
nsHTMLUListElement* it = new nsHTMLUListElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult rv = it->Init(aNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
delete it;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
||||
NS_ADDREF(*aInstancePtrResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsHTMLUListElement::nsHTMLUListElement()
|
||||
{
|
||||
}
|
||||
|
||||
nsHTMLUListElement::~nsHTMLUListElement()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsHTMLUListElement, nsGenericElement)
|
||||
NS_IMPL_RELEASE_INHERITED(nsHTMLUListElement, nsGenericElement)
|
||||
|
||||
|
||||
// QueryInterface implementation for nsHTMLUListElement
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLUListElement, nsGenericHTMLElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLUListElement)
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLUListElement)
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_END
|
||||
|
||||
|
||||
nsresult
|
||||
nsHTMLUListElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aReturn);
|
||||
*aReturn = nsnull;
|
||||
|
||||
nsHTMLUListElement* it = new nsHTMLUListElement();
|
||||
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
||||
|
||||
nsresult rv = it->Init(mNodeInfo);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
CopyInnerTo(it, aDeep);
|
||||
|
||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
||||
|
||||
NS_ADDREF(*aReturn);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_BOOL_ATTR(nsHTMLUListElement, Compact, compact)
|
||||
NS_IMPL_STRING_ATTR(nsHTMLUListElement, Type, type)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLUListElement::StringToAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsHTMLValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::type) {
|
||||
if (aResult.ParseEnumValue(aValue, kListTypeTable)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
|
||||
if (aResult.ParseEnumValue(aValue, kOldListTypeTable, PR_TRUE)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (aAttribute == nsHTMLAtoms::start) {
|
||||
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 1)) {
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLUListElement::AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::type) {
|
||||
PRInt32 v = aValue.GetIntValue();
|
||||
switch (v) {
|
||||
case NS_STYLE_LIST_STYLE_OLD_LOWER_ROMAN:
|
||||
case NS_STYLE_LIST_STYLE_OLD_UPPER_ROMAN:
|
||||
case NS_STYLE_LIST_STYLE_OLD_LOWER_ALPHA:
|
||||
case NS_STYLE_LIST_STYLE_OLD_UPPER_ALPHA:
|
||||
aValue.EnumValueToString(kOldListTypeTable, aResult);
|
||||
|
||||
break;
|
||||
default:
|
||||
aValue.EnumValueToString(kListTypeTable, aResult);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::AttributeToString(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
static void
|
||||
MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
|
||||
{
|
||||
if (aData->mSID == eStyleStruct_List) {
|
||||
if (aData->mListData->mType.GetUnit() == eCSSUnit_Null) {
|
||||
nsHTMLValue value;
|
||||
// type: enum
|
||||
if (aAttributes->GetAttribute(nsHTMLAtoms::type, value) !=
|
||||
NS_CONTENT_ATTR_NOT_THERE) {
|
||||
if (value.GetUnit() == eHTMLUnit_Enumerated)
|
||||
aData->mListData->mType.SetIntValue(value.GetIntValue(), eCSSUnit_Enumerated);
|
||||
else
|
||||
aData->mListData->mType.SetIntValue(NS_STYLE_LIST_STYLE_DISC, eCSSUnit_Enumerated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsHTMLUListElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
||||
{
|
||||
static const MappedAttributeEntry attributes[] = {
|
||||
{ &nsHTMLAtoms::type },
|
||||
{ nsnull }
|
||||
};
|
||||
|
||||
static const MappedAttributeEntry* const map[] = {
|
||||
attributes,
|
||||
sCommonAttributeMap,
|
||||
};
|
||||
|
||||
return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map));
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLUListElement::GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const
|
||||
{
|
||||
aMapRuleFunc = &MapAttributesIntoRule;
|
||||
return NS_OK;
|
||||
}
|
|
@ -2677,8 +2677,7 @@ nsHTMLDocument::GetAlinkColor(nsAString& aAlinkColor)
|
|||
nscolor color;
|
||||
nsresult rv = mAttrStyleSheet->GetActiveLinkColor(color);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsHTMLValue value(color);
|
||||
value.ToString(aAlinkColor);
|
||||
NS_RGBToHex(color, aAlinkColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2694,7 +2693,7 @@ nsHTMLDocument::SetAlinkColor(const nsAString& aAlinkColor)
|
|||
if (body) {
|
||||
body->SetALink(aAlinkColor);
|
||||
} else if (mAttrStyleSheet) {
|
||||
nsHTMLValue value;
|
||||
nsAttrValue value;
|
||||
if (value.ParseColor(aAlinkColor, this)) {
|
||||
nscolor color;
|
||||
value.GetColorValue(color);
|
||||
|
@ -2719,8 +2718,7 @@ nsHTMLDocument::GetLinkColor(nsAString& aLinkColor)
|
|||
nscolor color;
|
||||
nsresult rv = mAttrStyleSheet->GetLinkColor(color);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsHTMLValue value(color);
|
||||
value.ToString(aLinkColor);
|
||||
NS_RGBToHex(color, aLinkColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2736,7 +2734,7 @@ nsHTMLDocument::SetLinkColor(const nsAString& aLinkColor)
|
|||
if (body) {
|
||||
body->SetLink(aLinkColor);
|
||||
} else if (mAttrStyleSheet) {
|
||||
nsHTMLValue value;
|
||||
nsAttrValue value;
|
||||
if (value.ParseColor(aLinkColor, this)) {
|
||||
nscolor color;
|
||||
value.GetColorValue(color);
|
||||
|
@ -2761,8 +2759,7 @@ nsHTMLDocument::GetVlinkColor(nsAString& aVlinkColor)
|
|||
nscolor color;
|
||||
nsresult rv = mAttrStyleSheet->GetVisitedLinkColor(color);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsHTMLValue value(color);
|
||||
value.ToString(aVlinkColor);
|
||||
NS_RGBToHex(color, aVlinkColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2778,7 +2775,7 @@ nsHTMLDocument::SetVlinkColor(const nsAString& aVlinkColor)
|
|||
if (body) {
|
||||
body->SetVLink(aVlinkColor);
|
||||
} else if (mAttrStyleSheet) {
|
||||
nsHTMLValue value;
|
||||
nsAttrValue value;
|
||||
if (value.ParseColor(aVlinkColor, this)) {
|
||||
nscolor color;
|
||||
value.GetColorValue(color);
|
||||
|
|
|
@ -255,7 +255,6 @@ HTML_ATOM(style, "style")
|
|||
HTML_ATOM(summary, "summary")
|
||||
HTML_ATOM(tabindex, "tabindex")
|
||||
HTML_ATOM(table, "table")
|
||||
HTML_ATOM(tabstop, "tabstop")
|
||||
HTML_ATOM(target, "target")
|
||||
HTML_ATOM(tbody, "tbody")
|
||||
HTML_ATOM(td, "td")
|
||||
|
|
|
@ -190,18 +190,8 @@ class nsHTMLValue {
|
|||
public:
|
||||
nsHTMLValue();
|
||||
nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit);
|
||||
nsHTMLValue(float aValue);
|
||||
nsHTMLValue(const nsAString& aValue, nsHTMLUnit aUnit = eHTMLUnit_String);
|
||||
nsHTMLValue(nsICSSStyleRule* aValue);
|
||||
nsHTMLValue(nscolor aValue);
|
||||
nsHTMLValue(nsCOMArray<nsIAtom>* aArray);
|
||||
nsHTMLValue(const nsHTMLValue& aCopy);
|
||||
~nsHTMLValue(void);
|
||||
|
||||
nsHTMLValue& operator=(const nsHTMLValue& aCopy);
|
||||
PRBool operator==(const nsHTMLValue& aOther) const;
|
||||
PRBool operator!=(const nsHTMLValue& aOther) const;
|
||||
PRUint32 HashValue(void) const;
|
||||
|
||||
/**
|
||||
* Get the unit of this HTMLValue
|
||||
|
@ -212,9 +202,7 @@ public:
|
|||
PRInt32 GetIntValue(void) const;
|
||||
float GetPercentValue(void) const;
|
||||
nsAString& GetStringValue(nsAString& aBuffer) const;
|
||||
nsICSSStyleRule* GetCSSStyleRuleValue(void) const;
|
||||
PRBool GetColorValue(nscolor& aColor) const;
|
||||
nsCOMArray<nsIAtom>* AtomArrayValue() const;
|
||||
|
||||
PRBool IsEmptyString() const;
|
||||
|
||||
|
@ -226,15 +214,9 @@ public:
|
|||
void SetPercentValue(float aValue);
|
||||
void SetStringValue(const nsAString& aValue, nsHTMLUnit aUnit = eHTMLUnit_String);
|
||||
void SetCSSStyleRuleValue(nsICSSStyleRule* aValue);
|
||||
void SetAtomArrayValue(nsCOMArray<nsIAtom>* aValue);
|
||||
void SetColorValue(nscolor aValue);
|
||||
|
||||
/**
|
||||
* Get this HTML value as a string (depends on the type)
|
||||
* @param aResult the resulting string
|
||||
* @return whether the value was successfully turned to a string
|
||||
*/
|
||||
PRBool ToString(nsAString& aResult) const;
|
||||
|
||||
/**
|
||||
* Structure for a mapping from int (enum) values to strings. When you use
|
||||
* it you generally create an array of them.
|
||||
|
@ -249,7 +231,7 @@ public:
|
|||
/** The string the value maps to */
|
||||
const char* tag;
|
||||
/** The enum value that maps to this string */
|
||||
PRInt32 value;
|
||||
PRInt16 value;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -257,19 +239,6 @@ public:
|
|||
*/
|
||||
// Attribute parsing utilities
|
||||
|
||||
/**
|
||||
* Map a string to its enum value and return result as HTMLValue
|
||||
* (case-insensitive matching)
|
||||
*
|
||||
* @param aValue the string to find the value for
|
||||
* @param aTable the enumeration to map with
|
||||
* @param aResult the enum mapping [OUT]
|
||||
* @return whether the enum value was found or not
|
||||
*/
|
||||
PRBool ParseEnumValue(const nsAString& aValue,
|
||||
const EnumTable* aTable,
|
||||
PRBool aCaseSensitive = PR_FALSE);
|
||||
|
||||
/**
|
||||
* Map an enum HTMLValue to its string
|
||||
*
|
||||
|
@ -281,57 +250,6 @@ public:
|
|||
PRBool EnumValueToString(const EnumTable* aTable,
|
||||
nsAString& aResult) const;
|
||||
|
||||
/**
|
||||
* Parse a string value into an int HTMLValue.
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @param aDefaultUnit the unit to use
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseIntValue(const nsAString& aString, nsHTMLUnit aDefaultUnit) {
|
||||
return ParseIntWithBounds(aString, aDefaultUnit, PR_INT32_MIN, PR_INT32_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string value into an int HTMLValue with minimum
|
||||
* value and maximum value (can optionally parse percent (n%) and
|
||||
* proportional (n*). This method explicitly sets a lower bound of zero on
|
||||
* the element, whether it be proportional or percent or raw integer.
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @param aDefaultUnit the unit to use
|
||||
* @param aCanBePercent true if it can be a percent value (%)
|
||||
* @param aCanBeProportional true if it can be a proportional value (*)
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseSpecialIntValue(const nsAString& aString, nsHTMLUnit aDefaultUnit,
|
||||
PRBool aCanBePercent,
|
||||
PRBool aCanBeProportional);
|
||||
|
||||
/**
|
||||
* Parse a string value into an int HTMLValue with minimum
|
||||
* value and maximum value
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @param aMin the minimum value (if value is less it will be bumped up)
|
||||
* @param aMax the maximum value (if value is greater it will be chopped down)
|
||||
* @param aValueUnit the unit to use
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseIntWithBounds(const nsAString& aString, nsHTMLUnit aValueUnit,
|
||||
PRInt32 aMin, PRInt32 aMax = PR_INT32_MAX);
|
||||
|
||||
/**
|
||||
* Parse a string into a color HTMLValue (with hexes or color names)
|
||||
*
|
||||
* @param aString the string to parse
|
||||
* @param aDocument the document (to find out whether we're in quirks mode)
|
||||
* @param aResult the resulting HTMLValue [OUT]
|
||||
* @return whether the value could be parsed
|
||||
*/
|
||||
PRBool ParseColor(const nsAString& aString, nsIDocument* aDocument);
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* The unit of the value
|
||||
|
@ -359,12 +277,6 @@ protected:
|
|||
} mValue;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Copy into this HTMLValue from aCopy. Please be aware that if this is an
|
||||
* existing HTMLValue and you do not call Reset(), this will leak.
|
||||
* @param aCopy the value to copy
|
||||
*/
|
||||
void InitializeFrom(const nsHTMLValue& aCopy);
|
||||
/**
|
||||
* Helper to set string value (checks for embedded nulls or length); verifies
|
||||
* that aUnit is a string type as well.
|
||||
|
@ -385,6 +297,11 @@ private:
|
|||
* @return the unit class
|
||||
*/
|
||||
PRUint32 GetUnitClass() const { return mUnit & HTMLUNIT_CLASS_MASK; }
|
||||
|
||||
nsHTMLValue(const nsHTMLValue& aCopy); // NOT TO BE IMPLEMENTED
|
||||
PRBool operator==(const nsHTMLValue& aOther) const; // NOT TO BE IMPLEMENTED
|
||||
nsHTMLValue& operator=(const nsHTMLValue& aCopy); // NOT TO BE IMPLEMENTED
|
||||
PRBool operator!=(const nsHTMLValue& aOther) const; // NOT TO BE IMPLEMENTED
|
||||
};
|
||||
|
||||
inline nsDependentSubstring nsHTMLValue::GetDependentString() const
|
||||
|
@ -440,15 +357,6 @@ inline nsAString& nsHTMLValue::GetStringValue(nsAString& aBuffer) const
|
|||
return aBuffer;
|
||||
}
|
||||
|
||||
inline nsICSSStyleRule* nsHTMLValue::GetCSSStyleRuleValue(void) const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_CSSStyleRule, "not an CSSStyleRule value");
|
||||
if (mUnit == eHTMLUnit_CSSStyleRule) {
|
||||
return mValue.mCSSStyleRule;
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
inline PRBool nsHTMLValue::GetColorValue(nscolor& aColor) const
|
||||
{
|
||||
NS_ASSERTION((mUnit == eHTMLUnit_Color) || (mUnit == eHTMLUnit_String),
|
||||
|
@ -464,18 +372,6 @@ inline PRBool nsHTMLValue::GetColorValue(nscolor& aColor) const
|
|||
return PR_FALSE;
|
||||
}
|
||||
|
||||
inline nsCOMArray<nsIAtom>*
|
||||
nsHTMLValue::AtomArrayValue() const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_AtomArray, "not an atom array");
|
||||
return mValue.mAtomArray;
|
||||
}
|
||||
|
||||
inline PRBool nsHTMLValue::operator!=(const nsHTMLValue& aOther) const
|
||||
{
|
||||
return PRBool(! ((*this) == aOther));
|
||||
}
|
||||
|
||||
inline PRBool nsHTMLValue::IsEmptyString() const
|
||||
{
|
||||
return mUnit == eHTMLUnit_String && !mValue.mString;
|
||||
|
|
|
@ -68,126 +68,11 @@ nsHTMLValue::nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit)
|
|||
}
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(float aValue)
|
||||
: mUnit(eHTMLUnit_Percent)
|
||||
{
|
||||
mValue.mFloat = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(const nsAString& aValue, nsHTMLUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
SetStringValueInternal(aValue, aUnit);
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nsICSSStyleRule* aValue)
|
||||
: mUnit(eHTMLUnit_CSSStyleRule)
|
||||
{
|
||||
mValue.mCSSStyleRule = aValue;
|
||||
NS_IF_ADDREF(mValue.mCSSStyleRule);
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nscolor aValue)
|
||||
: mUnit(eHTMLUnit_Color)
|
||||
{
|
||||
mValue.mColor = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nsCOMArray<nsIAtom>* aArray)
|
||||
: mUnit(eHTMLUnit_AtomArray)
|
||||
{
|
||||
mValue.mAtomArray = aArray;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(const nsHTMLValue& aCopy)
|
||||
{
|
||||
InitializeFrom(aCopy);
|
||||
}
|
||||
|
||||
nsHTMLValue::~nsHTMLValue(void)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
nsHTMLValue& nsHTMLValue::operator=(const nsHTMLValue& aCopy)
|
||||
{
|
||||
Reset();
|
||||
InitializeFrom(aCopy);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PRBool nsHTMLValue::operator==(const nsHTMLValue& aOther) const
|
||||
{
|
||||
if (mUnit != aOther.mUnit) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
// Call GetUnitClass() so that we turn StringWithLength into String
|
||||
PRUint32 unitClass = GetUnitClass();
|
||||
switch (unitClass) {
|
||||
case HTMLUNIT_STRING:
|
||||
if (mValue.mString && aOther.mValue.mString) {
|
||||
return GetDependentString().Equals(aOther.GetDependentString());
|
||||
}
|
||||
// One of them is null. An == check will see if they are both null.
|
||||
return mValue.mString == aOther.mValue.mString;
|
||||
|
||||
case HTMLUNIT_INTEGER:
|
||||
return mValue.mInt == aOther.mValue.mInt;
|
||||
|
||||
case HTMLUNIT_COLOR:
|
||||
return mValue.mColor == aOther.mValue.mColor;
|
||||
|
||||
case HTMLUNIT_CSSSTYLERULE:
|
||||
return mValue.mCSSStyleRule == aOther.mValue.mCSSStyleRule;
|
||||
|
||||
case HTMLUNIT_PERCENT:
|
||||
return mValue.mFloat == aOther.mValue.mFloat;
|
||||
|
||||
case HTMLUNIT_ATOMARRAY:
|
||||
{
|
||||
// For classlists we could be insensitive to order, however
|
||||
// classlists are never mapped attributes so they are never compared.
|
||||
|
||||
PRInt32 count = mValue.mAtomArray->Count();
|
||||
if (count != aOther.mValue.mAtomArray->Count()) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRInt32 i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
if (mValue.mAtomArray->ObjectAt(i) !=
|
||||
aOther.mValue.mAtomArray->ObjectAt(i)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
default:
|
||||
NS_WARNING("Unknown unit");
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
PRUint32 nsHTMLValue::HashValue(void) const
|
||||
{
|
||||
PRUint32 retval;
|
||||
if (GetUnitClass() == HTMLUNIT_STRING) {
|
||||
retval = mValue.mString ? nsCheapStringBufferUtils::HashCode(mValue.mString)
|
||||
: 0;
|
||||
} else if (mUnit == eHTMLUnit_AtomArray) {
|
||||
retval = 0;
|
||||
PRInt32 i, count = mValue.mAtomArray->Count();
|
||||
for (i = 0; i < count; ++i) {
|
||||
retval ^= NS_PTR_TO_INT32(mValue.mAtomArray->ObjectAt(i));
|
||||
}
|
||||
} else {
|
||||
retval = mValue.mInt;
|
||||
}
|
||||
return retval ^ PRUint32(mUnit);
|
||||
}
|
||||
|
||||
|
||||
void nsHTMLValue::Reset(void)
|
||||
{
|
||||
if (GetUnitClass() == HTMLUNIT_STRING) {
|
||||
|
@ -259,6 +144,13 @@ void nsHTMLValue::SetCSSStyleRuleValue(nsICSSStyleRule* aValue)
|
|||
NS_IF_ADDREF(mValue.mCSSStyleRule);
|
||||
}
|
||||
|
||||
void nsHTMLValue::SetAtomArrayValue(nsCOMArray<nsIAtom>* aValue)
|
||||
{
|
||||
Reset();
|
||||
mUnit = eHTMLUnit_AtomArray;
|
||||
mValue.mAtomArray = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::SetColorValue(nscolor aValue)
|
||||
{
|
||||
Reset();
|
||||
|
@ -266,71 +158,10 @@ void nsHTMLValue::SetColorValue(nscolor aValue)
|
|||
mValue.mColor = aValue;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLValue::InitializeFrom(const nsHTMLValue& aCopy)
|
||||
{
|
||||
mUnit = aCopy.mUnit;
|
||||
switch (GetUnitClass()) {
|
||||
case HTMLUNIT_STRING:
|
||||
if (aCopy.mValue.mString) {
|
||||
nsCheapStringBufferUtils::Clone(mValue.mString, aCopy.mValue.mString);
|
||||
} else {
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
break;
|
||||
|
||||
case HTMLUNIT_INTEGER:
|
||||
mValue.mInt = aCopy.mValue.mInt;
|
||||
break;
|
||||
|
||||
case HTMLUNIT_COLOR:
|
||||
mValue.mColor = aCopy.mValue.mColor;
|
||||
break;
|
||||
|
||||
case HTMLUNIT_CSSSTYLERULE:
|
||||
mValue.mCSSStyleRule = aCopy.mValue.mCSSStyleRule;
|
||||
NS_IF_ADDREF(mValue.mCSSStyleRule);
|
||||
break;
|
||||
|
||||
case HTMLUNIT_PERCENT:
|
||||
mValue.mFloat = aCopy.mValue.mFloat;
|
||||
break;
|
||||
|
||||
case HTMLUNIT_ATOMARRAY:
|
||||
mValue.mAtomArray = new nsCOMArray<nsIAtom>(*aCopy.mValue.mAtomArray);
|
||||
if (!mValue.mAtomArray) {
|
||||
mUnit = eHTMLUnit_String;
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
NS_ERROR("Unknown HTMLValue type!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Parsing methods
|
||||
//
|
||||
|
||||
PRBool
|
||||
nsHTMLValue::ParseEnumValue(const nsAString& aValue,
|
||||
const EnumTable* aTable,
|
||||
PRBool aCaseSensitive)
|
||||
{
|
||||
nsAutoString val(aValue);
|
||||
while (aTable->tag) {
|
||||
if (aCaseSensitive ? val.EqualsWithConversion(aTable->tag) :
|
||||
val.EqualsIgnoreCase(aTable->tag)) {
|
||||
SetIntValue(aTable->value, eHTMLUnit_Enumerated);
|
||||
return PR_TRUE;
|
||||
}
|
||||
aTable++;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsHTMLValue::EnumValueToString(const EnumTable* aTable,
|
||||
nsAString& aResult) const
|
||||
|
@ -349,196 +180,3 @@ nsHTMLValue::EnumValueToString(const EnumTable* aTable,
|
|||
aResult.Truncate();
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
/* used to parse attribute values that could be either:
|
||||
* integer (n),
|
||||
* percent (n%),
|
||||
* or proportional (n*)
|
||||
*/
|
||||
PRBool
|
||||
nsHTMLValue::ParseSpecialIntValue(const nsAString& aString,
|
||||
nsHTMLUnit aDefaultUnit,
|
||||
PRBool aCanBePercent,
|
||||
PRBool aCanBeProportional)
|
||||
{
|
||||
nsAutoString tmp(aString);
|
||||
PRInt32 ec;
|
||||
PRInt32 val = tmp.ToInteger(&ec);
|
||||
|
||||
if (NS_SUCCEEDED(ec)) {
|
||||
if (val < 0) {
|
||||
val = 0;
|
||||
}
|
||||
// % (percent) (XXX RFindChar means that 5%x will be parsed!)
|
||||
if (aCanBePercent && tmp.RFindChar('%') >= 0) {
|
||||
if (val > 100) {
|
||||
val = 100;
|
||||
}
|
||||
SetPercentValue(float(val)/100.0f);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// * (proportional) (XXX RFindChar means that 5*x will be parsed!)
|
||||
if (aCanBeProportional && tmp.RFindChar('*') >= 0) {
|
||||
SetIntValue(val, eHTMLUnit_Proportional);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// Straight number is interpreted with the default unit
|
||||
SetIntValue(val, aDefaultUnit);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// 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
|
||||
// b=29061
|
||||
SetIntValue(1, eHTMLUnit_Proportional);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsHTMLValue::ToString(nsAString& aResult) const
|
||||
{
|
||||
nsAutoString intStr;
|
||||
aResult.Truncate();
|
||||
|
||||
switch (GetUnit()) {
|
||||
case eHTMLUnit_Integer:
|
||||
case eHTMLUnit_Proportional:
|
||||
intStr.AppendInt(GetIntValue());
|
||||
aResult.Append(intStr);
|
||||
if (GetUnit() == eHTMLUnit_Proportional) {
|
||||
aResult.Append(PRUnichar('*'));
|
||||
}
|
||||
return PR_TRUE;
|
||||
|
||||
case eHTMLUnit_Percent:
|
||||
{
|
||||
float percentVal = GetPercentValue() * 100.0f;
|
||||
intStr.AppendInt(NSToCoordRoundExclusive(percentVal));
|
||||
aResult.Append(intStr);
|
||||
aResult.Append(PRUnichar('%'));
|
||||
return PR_TRUE;
|
||||
}
|
||||
case eHTMLUnit_Color:
|
||||
{
|
||||
nscolor v;
|
||||
GetColorValue(v);
|
||||
char buf[10];
|
||||
PR_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
|
||||
NS_GET_R(v), NS_GET_G(v), NS_GET_B(v));
|
||||
AppendASCIItoUTF16(buf, aResult);
|
||||
return PR_TRUE;
|
||||
}
|
||||
case eHTMLUnit_String:
|
||||
GetStringValue(aResult);
|
||||
return PR_TRUE;
|
||||
case eHTMLUnit_AtomArray:
|
||||
{
|
||||
PRInt32 count = mValue.mAtomArray->Count();
|
||||
if (count) {
|
||||
mValue.mAtomArray->ObjectAt(0)->ToString(aResult);
|
||||
nsAutoString tmp;
|
||||
PRInt32 i;
|
||||
for (i = 1; i < count; ++i) {
|
||||
mValue.mAtomArray->ObjectAt(i)->ToString(tmp);
|
||||
aResult.Append(NS_LITERAL_STRING(" ") + tmp);
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
case eHTMLUnit_CSSStyleRule:
|
||||
{
|
||||
if (mValue.mCSSStyleRule) {
|
||||
nsCSSDeclaration* decl = mValue.mCSSStyleRule->GetDeclaration();
|
||||
if (decl) {
|
||||
decl->ToString(aResult);
|
||||
}
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
default:
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsHTMLValue::ParseIntWithBounds(const nsAString& aString,
|
||||
nsHTMLUnit aDefaultUnit,
|
||||
PRInt32 aMin, PRInt32 aMax)
|
||||
{
|
||||
nsAutoString str(aString);
|
||||
PRInt32 ec;
|
||||
PRInt32 val = str.ToInteger(&ec);
|
||||
if (NS_SUCCEEDED(ec)) {
|
||||
val = PR_MAX(val, aMin);
|
||||
val = PR_MIN(val, aMax);
|
||||
SetIntValue(val, aDefaultUnit);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsHTMLValue::ParseColor(const nsAString& aString, nsIDocument* aDocument)
|
||||
{
|
||||
if (aString.IsEmpty()) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// Previously we did a complicated algorithm to strip leading and trailing
|
||||
// whitespace; now we just use CompressWhitespace like everyone else.
|
||||
// Since all color values are just one word, this is ok.
|
||||
|
||||
nsAutoString colorStr(aString);
|
||||
colorStr.CompressWhitespace(PR_TRUE, PR_TRUE);
|
||||
if (colorStr.IsEmpty()) {
|
||||
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)) {
|
||||
SetStringValue(colorStr, eHTMLUnit_String);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// Check if we are in compatibility mode
|
||||
PRBool inNavQuirksMode;
|
||||
{
|
||||
nsCOMPtr<nsIHTMLDocument> doc(do_QueryInterface(aDocument));
|
||||
if (doc) {
|
||||
inNavQuirksMode = (doc->GetCompatibilityMode() == eCompatibility_NavQuirks);
|
||||
} else {
|
||||
inNavQuirksMode = PR_FALSE;
|
||||
}
|
||||
}
|
||||
if (!inNavQuirksMode) {
|
||||
if (colorStr.CharAt(0) == '#') {
|
||||
colorStr.Cut(0, 1);
|
||||
if (NS_HexToRGB(colorStr, &color)) {
|
||||
SetColorValue(color);
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (NS_LooseHexToRGB(colorStr, &color)) {
|
||||
SetColorValue(color);
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
#include "nsDOMError.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIPrivateDOMEvent.h"
|
||||
#include "nsHTMLValue.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIDOMAttr.h"
|
||||
|
@ -2089,7 +2088,6 @@ nsresult
|
|||
nsXULElement::SetAttr(PRInt32 aNamespaceID, nsIAtom* aName, nsIAtom* aPrefix,
|
||||
const nsAString& aValue, PRBool aNotify)
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoString oldValue;
|
||||
PRBool hasListeners = PR_FALSE;
|
||||
PRBool modification = PR_FALSE;
|
||||
|
@ -2150,17 +2148,13 @@ nsXULElement::SetAttr(PRInt32 aNamespaceID, nsIAtom* aName, nsIAtom* aPrefix,
|
|||
// Store id as atom.
|
||||
// id="" means that the element has no id. Not that it has
|
||||
// emptystring as id.
|
||||
nsCOMPtr<nsIAtom> idAtom = do_GetAtom(aValue);
|
||||
NS_ENSURE_TRUE(idAtom, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
attrValue.SetTo(idAtom);
|
||||
attrValue.ParseAtom(aValue);
|
||||
}
|
||||
else if (aName == nsXULAtoms::clazz) {
|
||||
rv = nsGenericHTMLElement::ParseClassAttribute(aValue, attrValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
attrValue.ParseAtomArray(aValue);
|
||||
}
|
||||
else {
|
||||
attrValue.SetToStringOrAtom(aValue);
|
||||
attrValue.ParseStringOrAtom(aValue);
|
||||
}
|
||||
|
||||
// Add popup and event listeners. We can't call AddListenerFor since
|
||||
|
@ -2180,7 +2174,7 @@ nsXULElement::SetAttr(PRInt32 aNamespaceID, nsIAtom* aName, nsIAtom* aPrefix,
|
|||
// to unhook the old one.
|
||||
}
|
||||
else {
|
||||
attrValue.SetToStringOrAtom(aValue);
|
||||
attrValue.ParseStringOrAtom(aValue);
|
||||
}
|
||||
|
||||
return SetAttrAndNotify(aNamespaceID, aName, aPrefix, oldValue,
|
||||
|
@ -3161,12 +3155,12 @@ nsXULElement::GetID(nsIAtom** aResult) const
|
|||
const nsAttrValue* attrVal = FindLocalOrProtoAttr(kNameSpaceID_None, nsXULAtoms::id);
|
||||
|
||||
NS_ASSERTION(!attrVal ||
|
||||
attrVal->GetType() == nsAttrValue::eAtom ||
|
||||
(attrVal->GetType() == nsAttrValue::eString &&
|
||||
attrVal->Type() == nsAttrValue::eAtom ||
|
||||
(attrVal->Type() == nsAttrValue::eString &&
|
||||
attrVal->GetStringValue().IsEmpty()),
|
||||
"unexpected attribute type");
|
||||
|
||||
if (attrVal && attrVal->GetType() == nsAttrValue::eAtom) {
|
||||
if (attrVal && attrVal->Type() == nsAttrValue::eAtom) {
|
||||
NS_ADDREF(*aResult = attrVal->GetAtomValue());
|
||||
}
|
||||
|
||||
|
@ -3180,15 +3174,12 @@ nsXULElement::GetClasses(nsVoidArray& aArray) const
|
|||
|
||||
const nsAttrValue* val = FindLocalOrProtoAttr(kNameSpaceID_None, nsXULAtoms::clazz);
|
||||
if (val) {
|
||||
const nsHTMLValue* htmlVal;
|
||||
if (val->GetType() == nsAttrValue::eAtom) {
|
||||
if (val->Type() == nsAttrValue::eAtom) {
|
||||
// NOTE atom is not addrefed
|
||||
aArray.AppendElement(val->GetAtomValue());
|
||||
}
|
||||
else if (val->GetType() == nsAttrValue::eHTMLValue &&
|
||||
(htmlVal = val->GetHTMLValue())->GetUnit() ==
|
||||
eHTMLUnit_AtomArray) {
|
||||
nsCOMArray<nsIAtom>* array = htmlVal->AtomArrayValue();
|
||||
else if (val->Type() == nsAttrValue::eAtomArray) {
|
||||
nsCOMArray<nsIAtom>* array = val->GetAtomArrayValue();
|
||||
PRInt32 i, count = array->Count();
|
||||
for (i = 0; i < count; ++i) {
|
||||
// NOTE atom is not addrefed
|
||||
|
@ -3205,14 +3196,11 @@ nsXULElement::HasClass(nsIAtom* aClass, PRBool /*aCaseSensitive*/) const
|
|||
{
|
||||
const nsAttrValue* val = FindLocalOrProtoAttr(kNameSpaceID_None, nsXULAtoms::clazz);
|
||||
if (val) {
|
||||
const nsHTMLValue* htmlVal;
|
||||
if (val->GetType() == nsAttrValue::eAtom) {
|
||||
if (val->Type() == nsAttrValue::eAtom) {
|
||||
return aClass == val->GetAtomValue();
|
||||
}
|
||||
if (val->GetType() == nsAttrValue::eHTMLValue &&
|
||||
(htmlVal = val->GetHTMLValue())->GetUnit() ==
|
||||
eHTMLUnit_AtomArray) {
|
||||
return htmlVal->AtomArrayValue()->IndexOf(aClass) >= 0;
|
||||
if (val->Type() == nsAttrValue::eAtomArray) {
|
||||
return val->GetAtomArrayValue()->IndexOf(aClass) >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3233,10 +3221,8 @@ nsXULElement::GetInlineStyleRule(nsICSSStyleRule** aStyleRule)
|
|||
// Fetch the cached style rule from the attributes.
|
||||
const nsAttrValue* attrVal = FindLocalOrProtoAttr(kNameSpaceID_None, nsXULAtoms::style);
|
||||
|
||||
const nsHTMLValue* htmlVal;
|
||||
if (attrVal && attrVal->GetType() == nsAttrValue::eHTMLValue &&
|
||||
(htmlVal = attrVal->GetHTMLValue())->GetUnit() == eHTMLUnit_CSSStyleRule) {
|
||||
NS_IF_ADDREF(*aStyleRule = htmlVal->GetCSSStyleRuleValue());
|
||||
if (attrVal && attrVal->Type() == nsAttrValue::eCSSStyleRule) {
|
||||
NS_ADDREF(*aStyleRule = attrVal->GetCSSStyleRuleValue());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -3261,9 +3247,7 @@ nsXULElement::SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify)
|
|||
}
|
||||
}
|
||||
|
||||
// MSVC won't let me do: nsAttrValue attrValue(nsHTMLValue(aStyleRule));
|
||||
nsAttrValue attrValue;
|
||||
attrValue.SetTo(nsHTMLValue(aStyleRule));
|
||||
nsAttrValue attrValue(aStyleRule);
|
||||
|
||||
return SetAttrAndNotify(kNameSpaceID_None, nsXULAtoms::style, nsnull,
|
||||
oldValueStr, attrValue, modification, hasListeners,
|
||||
|
@ -4434,7 +4418,7 @@ nsXULPrototypeElement::SetAttrAt(PRUint32 aPos, const nsAString& aValue,
|
|||
// Any changes should be made to both functions.
|
||||
|
||||
if (!mNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
|
||||
mAttributes[aPos].mValue.SetToStringOrAtom(aValue);
|
||||
mAttributes[aPos].mValue.ParseStringOrAtom(aValue);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -4444,17 +4428,15 @@ nsXULPrototypeElement::SetAttrAt(PRUint32 aPos, const nsAString& aValue,
|
|||
// Store id as atom.
|
||||
// id="" means that the element has no id. Not that it has
|
||||
// emptystring as id.
|
||||
nsCOMPtr<nsIAtom> atom = do_GetAtom(aValue);
|
||||
NS_ENSURE_TRUE(atom, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
mAttributes[aPos].mValue.SetTo(atom);
|
||||
mAttributes[aPos].mValue.ParseAtom(aValue);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
else if (mAttributes[aPos].mName.Equals(nsXULAtoms::clazz)) {
|
||||
// Compute the element's class list
|
||||
return nsGenericHTMLElement::ParseClassAttribute(aValue,
|
||||
mAttributes[aPos].mValue);
|
||||
mAttributes[aPos].mValue.ParseAtomArray(aValue);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
else if (mAttributes[aPos].mName.Equals(nsXULAtoms::style)) {
|
||||
// Parse the element's 'style' attribute
|
||||
|
@ -4465,14 +4447,14 @@ nsXULPrototypeElement::SetAttrAt(PRUint32 aPos, const nsAString& aValue,
|
|||
parser->ParseStyleAttribute(aValue, aDocumentURI,
|
||||
getter_AddRefs(rule));
|
||||
if (rule) {
|
||||
mAttributes[aPos].mValue.SetTo(nsHTMLValue(rule));
|
||||
mAttributes[aPos].mValue.SetTo(rule);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
// Don't abort if parsing failed, it could just be malformed css.
|
||||
}
|
||||
|
||||
mAttributes[aPos].mValue.SetToStringOrAtom(aValue);
|
||||
mAttributes[aPos].mValue.ParseStringOrAtom(aValue);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -93,6 +93,10 @@ extern "C" NS_GFX_(PRBool) NS_HexToRGB(const nsString& aBuf, nscolor* aResult);
|
|||
// This version accepts 1 to 9 digits (missing digits are 0)
|
||||
extern "C" NS_GFX_(PRBool) NS_LooseHexToRGB(const nsString& aBuf, nscolor* aResult);
|
||||
|
||||
// Translate a color to a hex string and prepend a '#'.
|
||||
// The returned string is always 7 characters including a '#' character.
|
||||
extern "C" NS_GFX_(void) NS_RGBToHex(nscolor aColor, nsAString& aResult);
|
||||
|
||||
// Translate a color name to a color. Return true if it parses ok,
|
||||
// otherwise return false.
|
||||
extern "C" NS_GFX_(PRBool) NS_ColorNameToRGB(const nsAString& aBuf, nscolor* aResult);
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include "nsIScreen.h"
|
||||
#include "nsIScreenManager.h"
|
||||
#include <math.h>
|
||||
#include "prprf.h"
|
||||
|
||||
static int ComponentValue(const char* aColorSpec, int aLen, int color, int dpc)
|
||||
{
|
||||
|
@ -158,6 +159,14 @@ extern "C" NS_GFX_(PRBool) NS_LooseHexToRGB(const nsString& aColorSpec, nscolor*
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
extern "C" NS_GFX_(void) NS_RGBToHex(nscolor aColor, nsAString& aResult)
|
||||
{
|
||||
char buf[10];
|
||||
PR_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
|
||||
NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor));
|
||||
CopyASCIItoUTF16(buf, aResult);
|
||||
}
|
||||
|
||||
extern "C" NS_GFX_(PRBool) NS_ColorNameToRGB(const nsAString& aColorName, nscolor* aResult)
|
||||
{
|
||||
nsColorName id = nsColorNames::LookupName(aColorName);
|
||||
|
|
Загрузка…
Ссылка в новой задаче