Move HTMLValue parsing methods to HTMLValue (bug 159757), r=bugmail@sicking.cc, sr=jst@netscape.com

This commit is contained in:
jkeiser%netscape.com 2003-01-21 21:24:16 +00:00
parent 37c6a110c6
commit d73be72429
41 changed files with 938 additions and 691 deletions

View File

@ -43,6 +43,10 @@
#include "nsUnicharUtils.h"
#include "nsCRT.h"
#include "nsMemory.h"
#include "nsIDocument.h"
#include "nsIHTMLDocument.h"
#include "nsUnitConversion.h"
#include "prprf.h"
nsHTMLValue::nsHTMLValue(nsHTMLUnit aUnit)
: mUnit(aUnit)
@ -378,3 +382,221 @@ nsHTMLValue::InitializeFrom(const nsHTMLValue& aCopy)
NS_ERROR("Unknown HTMLValue type!");
}
}
//
// Parsing methods
//
PRBool
nsHTMLValue::ParseEnumValue(const nsAString& aValue,
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(EnumTable* aTable,
nsAString& aResult) const
{
if (GetUnit() == eHTMLUnit_Enumerated) {
PRInt32 v = GetIntValue();
while (aTable->tag) {
if (aTable->value == v) {
CopyASCIItoUCS2(nsDependentCString(aTable->tag), aResult);
return PR_TRUE;
}
aTable++;
}
}
aResult.Truncate();
return PR_FALSE;
}
/* used to parse attribute values that could be either:
* integer (n),
* percent (n%),
* or proportional (n*)
*/
PRBool
nsHTMLValue::ParseIntValue(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
if (aDefaultUnit == eHTMLUnit_Pixel) {
SetPixelValue(val);
} else {
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.Last() == '*' && tmp.Length() == 1) {
// 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_Pixel:
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();
char buf[10];
PR_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
NS_GET_R(v), NS_GET_G(v), NS_GET_B(v));
aResult.Assign(NS_ConvertASCIItoUCS2(buf));
return PR_TRUE;
}
case eHTMLUnit_ColorName:
case eHTMLUnit_String:
GetStringValue(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);
if (aDefaultUnit == eHTMLUnit_Pixel) {
SetPixelValue(val);
} else {
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_ColorName);
return PR_TRUE;
}
// Check if we are in compatibility mode
PRBool inNavQuirksMode;
{
nsCOMPtr<nsIHTMLDocument> doc(do_QueryInterface(aDocument));
if (doc) {
nsCompatibility mode;
doc->GetCompatibilityMode(mode);
inNavQuirksMode = (mode == 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;
}

View File

@ -47,6 +47,8 @@
#include "nsReadableUtils.h"
#include "nsCRT.h"
class nsIDocument;
class nsCheapStringBufferUtils {
public:
/**
@ -216,16 +218,109 @@ public:
void SetColorValue(nscolor aValue);
void SetEmptyValue(void);
/**
* 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;
#ifdef DEBUG
void AppendToString(nsAString& aBuffer) const;
#endif
/**
* Structure for a mapping from int (enum) values to strings. When you use
* it you generally create an array of them.
* Instantiate like this:
* EnumTable myTable[] = {
* { "string1", 1 },
* { "string2", 2 },
* { 0 }
* }
*/
struct EnumTable {
/** The string the value maps to */
const char* tag;
/** The enum value that maps to this string */
PRInt32 value;
};
/**
* Parse and output this HTMLValue in a variety of ways
*/
// 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,
EnumTable* aTable,
PRBool aCaseSensitive = PR_FALSE);
/**
* Map an enum HTMLValue to its string
*
* @param aValue the HTMLValue with the int in it
* @param aTable the enumeration to map with
* @param aResult the string the value maps to [OUT]
* @return whether the enum value was found or not
*/
PRBool EnumValueToString(EnumTable* aTable,
nsAString& aResult) const;
/**
* Parse a string value into an int or pixel HTMLValue with minimum
* value and maximum value (can optionally parse percent (n%) and
* proportional (n%)
*
* @param aString the string to parse
* @param aDefaultUnit the unit to use (eHTMLUnit_Pixel or Integer)
* @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 ParseIntValue(const nsAString& aString, nsHTMLUnit aDefaultUnit,
PRBool aCanBePercent = PR_FALSE,
PRBool aCanBeProportional = PR_FALSE);
/**
* Parse a string value into an int or pixel 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 (eHTMLUnit_Pixel or Integer)
* @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
* @see nsHTMLUnit
*/
PRUint32 mUnit;
/**
* The actual value. Please to not be adding more-than-4-byte things to this
* union.
@ -242,6 +337,7 @@ protected:
/** Color. */
nscolor mColor;
} mValue;
private:
/**
* Copy into this HTMLValue from aCopy. Please be aware that if this is an

View File

@ -457,7 +457,7 @@ nsGenericHTMLElement::SetLang(const nsAString& aLang)
return NS_OK;
}
static nsGenericHTMLElement::EnumTable kDirTable[] = {
static nsHTMLValue::EnumTable kDirTable[] = {
{ "ltr", NS_STYLE_DIRECTION_LTR },
{ "rtl", NS_STYLE_DIRECTION_RTL },
{ 0 }
@ -470,7 +470,7 @@ nsGenericHTMLElement::GetDir(nsAString& aDir)
nsresult result = GetHTMLAttribute(nsHTMLAtoms::dir, value);
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
EnumValueToString(value, kDirTable, aDir);
value.EnumValueToString(kDirTable, aDir);
}
return NS_OK;
@ -2547,7 +2547,7 @@ nsGenericHTMLElement::AttributeToString(nsIAtom* aAttribute,
nsresult result = GetHTMLAttribute(nsHTMLAtoms::dir, value);
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
EnumValueToString(value, kDirTable, aResult);
value.EnumValueToString(kDirTable, aResult);
return NS_OK;
}
@ -2592,309 +2592,6 @@ nsGenericHTMLElement::GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMa
return NS_OK;
}
PRBool
nsGenericHTMLElement::ParseEnumValue(const nsAString& aValue,
EnumTable* aTable,
nsHTMLValue& aResult)
{
nsAutoString val(aValue);
while (nsnull != aTable->tag) {
if (val.EqualsIgnoreCase(aTable->tag)) {
aResult.SetIntValue(aTable->value, eHTMLUnit_Enumerated);
return PR_TRUE;
}
aTable++;
}
return PR_FALSE;
}
PRBool
nsGenericHTMLElement::ParseCaseSensitiveEnumValue(const nsAString& aValue,
EnumTable* aTable,
nsHTMLValue& aResult)
{
nsAutoString val(aValue);
while (nsnull != aTable->tag) {
if (val.EqualsWithConversion(aTable->tag)) {
aResult.SetIntValue(aTable->value, eHTMLUnit_Enumerated);
return PR_TRUE;
}
aTable++;
}
return PR_FALSE;
}
PRBool
nsGenericHTMLElement::EnumValueToString(const nsHTMLValue& aValue,
EnumTable* aTable,
nsAString& aResult)
{
if (aValue.GetUnit() == eHTMLUnit_Enumerated) {
PRInt32 v = aValue.GetIntValue();
while (nsnull != aTable->tag) {
if (aTable->value == v) {
CopyASCIItoUCS2(nsDependentCString(aTable->tag), aResult);
return PR_TRUE;
}
aTable++;
}
}
aResult.Truncate();
return PR_FALSE;
}
PRBool
nsGenericHTMLElement::ParseValueOrPercent(const nsAString& aString,
nsHTMLValue& aResult,
nsHTMLUnit aValueUnit)
{
nsAutoString tmp(aString);
PRInt32 ec, val = tmp.ToInteger(&ec);
if (NS_OK == ec) {
if (val < 0) {
val = 0;
}
if (tmp.RFindChar('%') != kNotFound) {
if (val > 100) {
val = 100;
}
aResult.SetPercentValue(float(val)/100.0f);
} else {
if (eHTMLUnit_Pixel == aValueUnit) {
aResult.SetPixelValue(val);
}
else {
aResult.SetIntValue(val, aValueUnit);
}
}
return PR_TRUE;
}
return PR_FALSE;
}
/* used to parse attribute values that could be either:
* integer (n),
* percent (n%),
* or proportional (n*)
*/
PRBool
nsGenericHTMLElement::ParseValueOrPercentOrProportional(const nsAString& aString,
nsHTMLValue& aResult,
nsHTMLUnit aValueUnit)
{
nsAutoString tmp(aString);
tmp.CompressWhitespace(PR_TRUE, PR_TRUE);
PRInt32 ec, val = tmp.ToInteger(&ec);
if (NS_OK == ec) {
if (val < 0) val = 0;
if (!tmp.IsEmpty() && tmp.RFindChar('%') >= 0) {/* XXX not 100% compatible with ebina's code */
if (val > 100) val = 100;
aResult.SetPercentValue(float(val)/100.0f);
} else if (!tmp.IsEmpty() && tmp.Last() == '*') {
if (tmp.Length() == 1) {
// special case: HTML spec says a value '*' == '1*'
// see http://www.w3.org/TR/html4/types.html#type-multi-length
// b=29061
val = 1;
}
aResult.SetIntValue(val, eHTMLUnit_Proportional); // proportional values are integers
} else if (eHTMLUnit_Pixel == aValueUnit) {
aResult.SetPixelValue(val);
}
else {
aResult.SetIntValue(val, aValueUnit);
}
return PR_TRUE;
} else if (tmp.Length()==1 && tmp.Last()== '*') {
aResult.SetIntValue(1, eHTMLUnit_Proportional);
return PR_TRUE;
}
return PR_FALSE;
}
PRBool
nsGenericHTMLElement::ValueOrPercentToString(const nsHTMLValue& aValue,
nsAString& aResult)
{
nsAutoString intStr;
aResult.Truncate(0);
switch (aValue.GetUnit()) {
case eHTMLUnit_Integer:
intStr.AppendInt(aValue.GetIntValue());
aResult.Append(intStr);
return PR_TRUE;
case eHTMLUnit_Pixel:
intStr.AppendInt(aValue.GetPixelValue());
aResult.Append(intStr);
return PR_TRUE;
case eHTMLUnit_Percent:
{
float percentVal = aValue.GetPercentValue() * 100.0f;
intStr.AppendInt(NSToCoordRoundExclusive(percentVal));
aResult.Append(intStr);
aResult.Append(PRUnichar('%'));
return PR_TRUE;
}
default:
break;
}
return PR_FALSE;
}
PRBool
nsGenericHTMLElement::ValueOrPercentOrProportionalToString(const nsHTMLValue& aValue,
nsAString& aResult)
{
nsAutoString intStr;
aResult.Truncate(0);
switch (aValue.GetUnit()) {
case eHTMLUnit_Integer:
intStr.AppendInt(aValue.GetIntValue());
aResult.Append(intStr);
return PR_TRUE;
case eHTMLUnit_Pixel:
intStr.AppendInt(aValue.GetPixelValue());
aResult.Append(intStr);
return PR_TRUE;
case eHTMLUnit_Percent:
{
float percentVal = aValue.GetPercentValue() * 100.0f;
intStr.AppendInt(NSToCoordRoundExclusive(percentVal));
aResult.Append(intStr);
aResult.Append(NS_LITERAL_STRING("%"));
return PR_TRUE;
}
case eHTMLUnit_Proportional:
intStr.AppendInt(aValue.GetIntValue());
aResult.Append(intStr);
aResult.Append(NS_LITERAL_STRING("*"));
return PR_TRUE;
default:
break;
}
return PR_FALSE;
}
PRBool
nsGenericHTMLElement::ParseValue(const nsAString& aString, PRInt32 aMin,
PRInt32 aMax,
nsHTMLValue& aResult, nsHTMLUnit aValueUnit)
{
nsAutoString str(aString);
PRInt32 ec, val = str.ToInteger(&ec);
if (NS_OK == ec) {
if (val < aMin) val = aMin;
if (val > aMax) val = aMax;
if (eHTMLUnit_Pixel == aValueUnit) {
aResult.SetPixelValue(val);
}
else {
aResult.SetIntValue(val, aValueUnit);
}
return PR_TRUE;
}
return PR_FALSE;
}
PRBool
nsGenericHTMLElement::ParseColor(const nsAString& aString,
nsIDocument* aDocument,
nsHTMLValue& aResult)
{
if (aString.IsEmpty()) {
return PR_FALSE;
}
// All color strings are one single word so we just strip
// leading and trailing whitespace before checking.
// We need a string to remove cruft from
nsAString::const_iterator iter, end_iter;
aString.BeginReading(iter);
aString.EndReading(end_iter);
PRUnichar the_char;
// Skip whitespace in the beginning
while ((iter != end_iter) &&
(((the_char = *iter) == ' ') ||
(the_char == '\r') ||
(the_char == '\t') ||
(the_char == '\n') ||
(the_char == '\b')))
++iter;
if (iter == end_iter) {
// Nothing left
return PR_FALSE;
}
--end_iter; // So that it points on a character
// This will stop at a charater. At very least the same character
// that stopped the forward iterator.
while (((the_char = *end_iter)== ' ') ||
(the_char == '\r') ||
(the_char == '\t') ||
(the_char == '\n') ||
(the_char == '\b'))
--end_iter;
nsAutoString colorStr;
colorStr = Substring(iter, ++end_iter);
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)) {
aResult.SetStringValue(colorStr, eHTMLUnit_ColorName);
return PR_TRUE;
}
if (!InNavQuirksMode(aDocument)) {
if (colorStr.CharAt(0) == '#') {
colorStr.Cut(0, 1);
if (NS_HexToRGB(colorStr, &color)) {
aResult.SetColorValue(color);
return PR_TRUE;
}
}
}
else {
if (NS_LooseHexToRGB(colorStr, &color)) {
aResult.SetColorValue(color);
return PR_TRUE;
}
}
return PR_FALSE;
}
PRBool
nsGenericHTMLElement::ColorToString(const nsHTMLValue& aValue,
nsAString& aResult)
{
if (aValue.GetUnit() == eHTMLUnit_Color) {
nscolor v = aValue.GetColorValue();
char buf[10];
PR_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
NS_GET_R(v), NS_GET_G(v), NS_GET_B(v));
aResult.Assign(NS_ConvertASCIItoUCS2(buf));
return PR_TRUE;
}
if ((aValue.GetUnit() == eHTMLUnit_ColorName) ||
(aValue.GetUnit() == eHTMLUnit_String)) {
aValue.GetStringValue(aResult);
return PR_TRUE;
}
return PR_FALSE;
}
// static
nsIFrame *
nsGenericHTMLElement::GetPrimaryFrameFor(nsIContent* aContent,
@ -3061,7 +2758,7 @@ nsGenericHTMLElement::GetPresContext(nsIHTMLContent* aContent,
}
// XXX check all mappings against ebina's usage
static nsGenericHTMLElement::EnumTable kAlignTable[] = {
static nsHTMLValue::EnumTable kAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
@ -3079,7 +2776,7 @@ static nsGenericHTMLElement::EnumTable kAlignTable[] = {
// Elements that should return vertical align values "middle", "bottom", and "top"
// instead of "center", "baseline", and "texttop" from GetAttribute() should use this
static nsGenericHTMLElement::EnumTable kVAlignTable[] = {
static nsHTMLValue::EnumTable kVAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
{ "top", NS_STYLE_VERTICAL_ALIGN_TOP },//verified
@ -3094,7 +2791,7 @@ static nsGenericHTMLElement::EnumTable kVAlignTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kDivAlignTable[] = {
static nsHTMLValue::EnumTable kDivAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
@ -3103,7 +2800,7 @@ static nsGenericHTMLElement::EnumTable kDivAlignTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kFrameborderTable[] = {
static nsHTMLValue::EnumTable kFrameborderTable[] = {
{ "yes", NS_STYLE_FRAME_YES },
{ "no", NS_STYLE_FRAME_NO },
{ "1", NS_STYLE_FRAME_1 },
@ -3111,7 +2808,7 @@ static nsGenericHTMLElement::EnumTable kFrameborderTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kScrollingTable[] = {
static nsHTMLValue::EnumTable kScrollingTable[] = {
{ "yes", NS_STYLE_FRAME_YES },
{ "no", NS_STYLE_FRAME_NO },
{ "on", NS_STYLE_FRAME_ON },
@ -3122,7 +2819,7 @@ static nsGenericHTMLElement::EnumTable kScrollingTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kTableVAlignTable[] = {
static nsHTMLValue::EnumTable kTableVAlignTable[] = {
{ "top", NS_STYLE_VERTICAL_ALIGN_TOP },
{ "middle", NS_STYLE_VERTICAL_ALIGN_MIDDLE },
{ "bottom", NS_STYLE_VERTICAL_ALIGN_BOTTOM },
@ -3136,7 +2833,7 @@ nsGenericHTMLElement::ParseCommonAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (nsHTMLAtoms::dir == aAttribute) {
return ParseEnumValue(aValue, kDirTable, aResult);
return aResult.ParseEnumValue(aValue, kDirTable);
}
else if (nsHTMLAtoms::lang == aAttribute) {
aResult.SetStringValue(aValue);
@ -3149,13 +2846,13 @@ PRBool
nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
nsHTMLValue& aResult)
{
return ParseEnumValue(aString, kAlignTable, aResult);
return aResult.ParseEnumValue(aString, kAlignTable);
}
//----------------------------------------
// Vanilla table as defined by the html4 spec...
static nsGenericHTMLElement::EnumTable kTableHAlignTable[] = {
static nsHTMLValue::EnumTable kTableHAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_CENTER },
@ -3165,7 +2862,7 @@ static nsGenericHTMLElement::EnumTable kTableHAlignTable[] = {
};
// This table is used for TABLE when in compatability mode
static nsGenericHTMLElement::EnumTable kCompatTableHAlignTable[] = {
static nsHTMLValue::EnumTable kCompatTableHAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_CENTER },
@ -3182,9 +2879,9 @@ nsGenericHTMLElement::ParseTableHAlignValue(const nsAString& aString,
nsHTMLValue& aResult) const
{
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatTableHAlignTable, aResult);
return aResult.ParseEnumValue(aString, kCompatTableHAlignTable);
}
return ParseEnumValue(aString, kTableHAlignTable, aResult);
return aResult.ParseEnumValue(aString, kTableHAlignTable);
}
PRBool
@ -3192,15 +2889,15 @@ nsGenericHTMLElement::TableHAlignValueToString(const nsHTMLValue& aValue,
nsAString& aResult) const
{
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatTableHAlignTable, aResult);
return aValue.EnumValueToString(kCompatTableHAlignTable, aResult);
}
return EnumValueToString(aValue, kTableHAlignTable, aResult);
return aValue.EnumValueToString(kTableHAlignTable, aResult);
}
//----------------------------------------
// These tables are used for TD,TH,TR, etc (but not TABLE)
static nsGenericHTMLElement::EnumTable kTableCellHAlignTable[] = {
static nsHTMLValue::EnumTable kTableCellHAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
@ -3209,7 +2906,7 @@ static nsGenericHTMLElement::EnumTable kTableCellHAlignTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kCompatTableCellHAlignTable[] = {
static nsHTMLValue::EnumTable kCompatTableCellHAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
@ -3231,9 +2928,9 @@ nsGenericHTMLElement::ParseTableCellHAlignValue(const nsAString& aString,
nsHTMLValue& aResult) const
{
if (InNavQuirksMode(mDocument)) {
return ParseEnumValue(aString, kCompatTableCellHAlignTable, aResult);
return aResult.ParseEnumValue(aString, kCompatTableCellHAlignTable);
}
return ParseEnumValue(aString, kTableCellHAlignTable, aResult);
return aResult.ParseEnumValue(aString, kTableCellHAlignTable);
}
PRBool
@ -3241,9 +2938,9 @@ nsGenericHTMLElement::TableCellHAlignValueToString(const nsHTMLValue& aValue,
nsAString& aResult) const
{
if (InNavQuirksMode(mDocument)) {
return EnumValueToString(aValue, kCompatTableCellHAlignTable, aResult);
return aValue.EnumValueToString(kCompatTableCellHAlignTable, aResult);
}
return EnumValueToString(aValue, kTableCellHAlignTable, aResult);
return aValue.EnumValueToString(kTableCellHAlignTable, aResult);
}
//----------------------------------------
@ -3252,42 +2949,42 @@ PRBool
nsGenericHTMLElement::ParseTableVAlignValue(const nsAString& aString,
nsHTMLValue& aResult)
{
return ParseEnumValue(aString, kTableVAlignTable, aResult);
return aResult.ParseEnumValue(aString, kTableVAlignTable);
}
PRBool
nsGenericHTMLElement::AlignValueToString(const nsHTMLValue& aValue,
nsAString& aResult)
{
return EnumValueToString(aValue, kAlignTable, aResult);
return aValue.EnumValueToString(kAlignTable, aResult);
}
PRBool
nsGenericHTMLElement::VAlignValueToString(const nsHTMLValue& aValue,
nsAString& aResult)
{
return EnumValueToString(aValue, kVAlignTable, aResult);
return aValue.EnumValueToString(kVAlignTable, aResult);
}
PRBool
nsGenericHTMLElement::TableVAlignValueToString(const nsHTMLValue& aValue,
nsAString& aResult)
{
return EnumValueToString(aValue, kTableVAlignTable, aResult);
return aValue.EnumValueToString(kTableVAlignTable, aResult);
}
PRBool
nsGenericHTMLElement::ParseDivAlignValue(const nsAString& aString,
nsHTMLValue& aResult) const
{
return ParseEnumValue(aString, kDivAlignTable, aResult);
return aResult.ParseEnumValue(aString, kDivAlignTable);
}
PRBool
nsGenericHTMLElement::DivAlignValueToString(const nsHTMLValue& aValue,
nsAString& aResult) const
{
return EnumValueToString(aValue, kDivAlignTable, aResult);
return aValue.EnumValueToString(kDivAlignTable, aResult);
}
PRBool
@ -3297,12 +2994,12 @@ nsGenericHTMLElement::ParseImageAttribute(nsIAtom* aAttribute,
{
if ((aAttribute == nsHTMLAtoms::width) ||
(aAttribute == nsHTMLAtoms::height)) {
return ParseValueOrPercent(aString, aResult, eHTMLUnit_Pixel);
return aResult.ParseIntValue(aString, eHTMLUnit_Pixel, PR_TRUE);
}
else if ((aAttribute == nsHTMLAtoms::hspace) ||
(aAttribute == nsHTMLAtoms::vspace) ||
(aAttribute == nsHTMLAtoms::border)) {
return ParseValue(aString, 0, aResult, eHTMLUnit_Pixel);
return aResult.ParseIntWithBounds(aString, eHTMLUnit_Pixel, 0);
}
return PR_FALSE;
}
@ -3317,7 +3014,7 @@ nsGenericHTMLElement::ImageAttributeToString(nsIAtom* aAttribute,
(aAttribute == nsHTMLAtoms::border) ||
(aAttribute == nsHTMLAtoms::hspace) ||
(aAttribute == nsHTMLAtoms::vspace)) {
return ValueOrPercentToString(aValue, aResult);
return aValue.ToString(aResult);
}
return PR_FALSE;
}
@ -3326,28 +3023,28 @@ PRBool
nsGenericHTMLElement::ParseFrameborderValue(const nsAString& aString,
nsHTMLValue& aResult)
{
return ParseEnumValue(aString, kFrameborderTable, aResult);
return aResult.ParseEnumValue(aString, kFrameborderTable);
}
PRBool
nsGenericHTMLElement::FrameborderValueToString(const nsHTMLValue& aValue,
nsAString& aResult)
{
return EnumValueToString(aValue, kFrameborderTable, aResult);
return aValue.EnumValueToString(kFrameborderTable, aResult);
}
PRBool
nsGenericHTMLElement::ParseScrollingValue(const nsAString& aString,
nsHTMLValue& aResult)
{
return ParseEnumValue(aString, kScrollingTable, aResult);
return aResult.ParseEnumValue(aString, kScrollingTable);
}
PRBool
nsGenericHTMLElement::ScrollingValueToString(const nsHTMLValue& aValue,
nsAString& aResult)
{
return EnumValueToString(aValue, kScrollingTable, aResult);
return aValue.EnumValueToString(kScrollingTable, aResult);
}
nsresult

View File

@ -265,173 +265,6 @@ public:
//----------------------------------------
// Attribute parsing utilities
/**
* Structure for a mapping from int (enum) values to strings. When you use
* it you generally create an array of them.
* Instantiate like this:
* EnumTable myTable[] = {
* { "string1", 1 },
* { "string2", 2 },
* { 0 }
* }
*/
struct EnumTable {
/** The string the value maps to */
const char* tag;
/** The enum value that maps to this string */
PRInt32 value;
};
/**
* 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
*/
static PRBool ParseEnumValue(const nsAString& aValue,
EnumTable* aTable,
nsHTMLValue& aResult);
/**
* Map a string to its enum value and return result as HTMLValue
*
* @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
*/
static PRBool ParseCaseSensitiveEnumValue(const nsAString& aValue,
EnumTable* aTable,
nsHTMLValue& aResult);
/**
* Map an enum HTMLValue to its string
*
* @param aValue the HTMLValue with the int in it
* @param aTable the enumeration to map with
* @param aResult the string the value maps to [OUT]
* @return whether the enum value was found or not
*/
static PRBool EnumValueToString(const nsHTMLValue& aValue,
EnumTable* aTable,
nsAString& aResult);
/**
* Parse a string into an integer or a percentage (n or n%)
*
* @param aString the string to convert
* @param aResult the resulting HTMLValue [OUT]
* @param aValueUnit the unit to use if it is not a percentage
* (eHTMLUnit_Pixel or an integer type)
*/
static PRBool ParseValueOrPercent(const nsAString& aString,
nsHTMLValue& aResult,
nsHTMLUnit aValueUnit);
/**
* Parse a string into an integer, proportional or a percentage (n, n* or n%)
*
* @param aString the string to convert
* @param aResult the resulting HTMLValue [OUT]
* @param aValueUnit the unit to use if it is not a percentage / proportional
* (eHTMLUnit_Pixel or an integer type)
*/
static PRBool ParseValueOrPercentOrProportional(const nsAString& aString,
nsHTMLValue& aResult,
nsHTMLUnit aValueUnit);
/**
* Convert an integer, pixel or percent to string (n, n or n%)
* @param aValue the value to convert
* @param aResult the resulting string [OUT]
* @return whether it was able to be converted (if it was the proper type)
* XXX It is absolutely pointless to have this when we have
* ValueOrPercentOrProportionalToString.
*/
static PRBool ValueOrPercentToString(const nsHTMLValue& aValue,
nsAString& aResult);
/**
* Convert an integer, pixel percent or proportional to string
* (n, n, n% or n*)
* @param aValue the value to convert
* @param aResult the resulting string [OUT]
* @return whether it was able to be converted (if it was the proper type)
*/
static PRBool ValueOrPercentOrProportionalToString(const nsHTMLValue& aValue,
nsAString& aResult);
/**
* Parse a string value into an int or pixel HTMLValue
*
* @param aString the string to parse
* @param aResult the resulting HTMLValue [OUT]
* @param aValueUnit the unit to use (eHTMLUnit_Pixel or Integer)
* @return whether the value could be parsed
*/
static PRBool ParseValue(const nsAString& aString, nsHTMLValue& aResult,
nsHTMLUnit aValueUnit)
{
return ParseValue(aString, PR_INT32_MIN, PR_INT32_MAX, aResult, aValueUnit);
}
/**
* Parse a string value into an int or pixel HTMLValue with minimum value
*
* @param aString the string to parse
* @param aMin the minimum value (if value is less it will be bumped up)
* @param aResult the resulting HTMLValue [OUT]
* @param aValueUnit the unit to use (eHTMLUnit_Pixel or Integer)
* @return whether the value could be parsed
*/
static PRBool ParseValue(const nsAString& aString, PRInt32 aMin,
nsHTMLValue& aResult, nsHTMLUnit aValueUnit)
{
return ParseValue(aString, aMin, PR_INT32_MAX, aResult, aValueUnit);
}
/**
* Parse a string value into an int or pixel 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 aResult the resulting HTMLValue [OUT]
* @param aValueUnit the unit to use (eHTMLUnit_Pixel or Integer)
* @return whether the value could be parsed
*/
static PRBool ParseValue(const nsAString& aString, PRInt32 aMin,
PRInt32 aMax, nsHTMLValue& aResult,
nsHTMLUnit aValueUnit);
/**
* 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
*/
static PRBool ParseColor(const nsAString& aString,
nsIDocument* aDocument, nsHTMLValue& aResult);
/**
* Parse a color into a string value (hex or color name)
*
* @param aValue the HTMLValue to parse
* @param aResult the resulting string
* @return whether the value could be converted
*/
static PRBool ColorToString(const nsHTMLValue& aValue,
nsAString& aResult);
/**
* Parse common attributes (currently dir and lang, may be more)
*

View File

@ -332,7 +332,7 @@ nsHTMLAnchorElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::tabindex) {
if (ParseValue(aValue, 0, 32767, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0, 32767)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -213,7 +213,7 @@ nsHTMLAreaElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::tabindex) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -159,7 +159,7 @@ nsHTMLBRElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
NS_IMPL_STRING_ATTR(nsHTMLBRElement, Clear, clear)
static nsGenericHTMLElement::EnumTable kClearTable[] = {
static nsHTMLValue::EnumTable kClearTable[] = {
{ "left", NS_STYLE_CLEAR_LEFT },
{ "right", NS_STYLE_CLEAR_RIGHT },
{ "all", NS_STYLE_CLEAR_LEFT_AND_RIGHT },
@ -173,7 +173,7 @@ nsHTMLBRElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::clear) {
if (ParseEnumValue(aValue, kClearTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kClearTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -187,7 +187,7 @@ nsHTMLBRElement::AttributeToString(nsIAtom* aAttribute,
{
if (aAttribute == nsHTMLAtoms::clear) {
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
EnumValueToString(aValue, kClearTable, aResult);
aValue.EnumValueToString(kClearTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -406,43 +406,123 @@ nsHTMLBodyElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
NS_IMPL_STRING_ATTR(nsHTMLBodyElement, Background, background)
#define NS_IMPL_HTMLBODY_COLOR_ATTR(attr_, func_, default_) \
NS_IMETHODIMP \
nsHTMLBodyElement::Get##func_(nsAString& aColor) \
{ \
aColor.Truncate(); \
nsAutoString color; \
nscolor attrColor; \
if (NS_CONTENT_ATTR_NOT_THERE == \
GetAttr(kNameSpaceID_None, nsHTMLAtoms::attr_, color)) { \
\
nsCOMPtr<nsIPresContext> presContext; \
GetPresContext(this, getter_AddRefs(presContext)); \
\
if (presContext) { \
presContext->GetDefault##default_(&attrColor); \
ColorToString(attrColor, aColor); \
} \
} else if (NS_ColorNameToRGB(color, &attrColor)) { \
ColorToString(attrColor, aColor); \
} else { \
aColor.Assign(color); \
} \
return NS_OK; \
} \
NS_IMETHODIMP \
nsHTMLBodyElement::Set##func_(const nsAString& aColor) \
{ \
return SetAttr(kNameSpaceID_None, nsHTMLAtoms::attr_, aColor, \
PR_TRUE); \
NS_IMETHODIMP
nsHTMLBodyElement::GetVLink(nsAString& aVlinkColor)
{
nsresult rv = GetAttr(kNameSpaceID_None, nsHTMLAtoms::vlink, aVlinkColor);
// If we don't have an attribute, find the default color from the
// UA stylesheet.
if (rv == NS_CONTENT_ATTR_NOT_THERE) {
nsCOMPtr<nsIPresContext> context;
GetPresContext(this, getter_AddRefs(context));
if (context) {
nscolor vlinkColor;
context->GetDefaultVisitedLinkColor(&vlinkColor);
nsHTMLValue value(vlinkColor);
value.ToString(aVlinkColor);
}
}
return NS_OK;
}
NS_IMPL_HTMLBODY_COLOR_ATTR(vlink, VLink, VisitedLinkColor)
NS_IMPL_HTMLBODY_COLOR_ATTR(alink, ALink, LinkColor)
NS_IMPL_HTMLBODY_COLOR_ATTR(link, Link, LinkColor)
// XXX Should text check the body frame's style struct for color,
// like we do for bgColor?
NS_IMPL_HTMLBODY_COLOR_ATTR(text, Text, Color)
NS_IMETHODIMP
nsHTMLBodyElement::SetVLink(const nsAString& aVlinkColor)
{
return SetAttr(kNameSpaceID_None, nsHTMLAtoms::vlink, aVlinkColor, PR_TRUE);
}
NS_IMETHODIMP
nsHTMLBodyElement::GetALink(nsAString& aAlinkColor)
{
nsresult rv = GetAttr(kNameSpaceID_None, nsHTMLAtoms::alink, aAlinkColor);
// If we don't have an attribute, find the default color from the
// UA stylesheet.
if (rv == NS_CONTENT_ATTR_NOT_THERE) {
nsCOMPtr<nsIPresContext> context;
GetPresContext(this, getter_AddRefs(context));
if (context) {
// XXX We don't have the backend or the UI to get ALINKs from the
// UA stylesheet yet, so we'll piggyback to the default link color like IE.
nscolor alinkColor;
context->GetDefaultLinkColor(&alinkColor);
nsHTMLValue value(alinkColor);
value.ToString(aAlinkColor);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsHTMLBodyElement::SetALink(const nsAString& aAlinkColor)
{
return SetAttr(kNameSpaceID_None, nsHTMLAtoms::alink, aAlinkColor, PR_TRUE);
}
NS_IMETHODIMP
nsHTMLBodyElement::GetLink(nsAString& aLinkColor)
{
nsresult rv = GetAttr(kNameSpaceID_None, nsHTMLAtoms::link, aLinkColor);
// If we don't have an attribute, find the default color from the
// UA stylesheet.
if (rv == NS_CONTENT_ATTR_NOT_THERE) {
nsCOMPtr<nsIPresContext> context;
GetPresContext(this, getter_AddRefs(context));
if (context) {
nscolor linkColor;
context->GetDefaultLinkColor(&linkColor);
nsHTMLValue value(linkColor);
value.ToString(aLinkColor);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsHTMLBodyElement::SetLink(const nsAString& aLinkColor)
{
return SetAttr(kNameSpaceID_None, nsHTMLAtoms::link, aLinkColor, PR_TRUE);
}
NS_IMETHODIMP
nsHTMLBodyElement::GetText(nsAString& aTextColor)
{
nsresult rv = GetAttr(kNameSpaceID_None, nsHTMLAtoms::text, aTextColor);
// If we don't have an attribute, find the default color from the
// UA stylesheet.
if (rv == NS_CONTENT_ATTR_NOT_THERE) {
nsCOMPtr<nsIPresContext> context;
GetPresContext(this, getter_AddRefs(context));
if (context) {
nscolor textColor;
context->GetDefaultColor(&textColor);
nsHTMLValue value(textColor);
value.ToString(aTextColor);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsHTMLBodyElement::SetText(const nsAString& aTextColor)
{
return SetAttr(kNameSpaceID_None, nsHTMLAtoms::text, aTextColor, PR_TRUE);
}
NS_IMETHODIMP
nsHTMLBodyElement::GetBgColor(nsAString& aBgColor)
@ -482,14 +562,14 @@ nsHTMLBodyElement::GetBgColor(nsAString& aBgColor)
NS_ENSURE_SUCCESS(rv, rv);
bgcolor = StyleBackground->mBackgroundColor;
ColorToString(bgcolor, aBgColor);
nsHTMLValue(bgcolor).ToString(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.
ColorToString(bgcolor, aBgColor);
nsHTMLValue(bgcolor).ToString(aBgColor);
}
else {
// Otherwise, just assign whatever the attribute value is.
@ -515,7 +595,7 @@ nsHTMLBodyElement::StringToAttribute(nsIAtom* aAttribute,
(aAttribute == nsHTMLAtoms::link) ||
(aAttribute == nsHTMLAtoms::alink) ||
(aAttribute == nsHTMLAtoms::vlink)) {
if (ParseColor(aValue, mDocument, aResult)) {
if (aResult.ParseColor(aValue, mDocument)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -523,7 +603,7 @@ nsHTMLBodyElement::StringToAttribute(nsIAtom* aAttribute,
(aAttribute == nsHTMLAtoms::marginheight) ||
(aAttribute == nsHTMLAtoms::topmargin) ||
(aAttribute == nsHTMLAtoms::leftmargin)) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -377,7 +377,7 @@ nsHTMLButtonElement::RemoveFocus(nsIPresContext* aPresContext)
return rv;
}
static nsGenericHTMLElement::EnumTable kButtonTypeTable[] = {
static nsHTMLValue::EnumTable kButtonTypeTable[] = {
{ "button", NS_FORM_BUTTON_BUTTON },
{ "reset", NS_FORM_BUTTON_RESET },
{ "submit", NS_FORM_BUTTON_SUBMIT },
@ -390,12 +390,12 @@ nsHTMLButtonElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::tabindex) {
if (ParseValue(aValue, 0, 32767, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0, 32767)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::type) {
nsGenericHTMLElement::EnumTable *table = kButtonTypeTable;
nsHTMLValue::EnumTable *table = kButtonTypeTable;
nsAutoString val(aValue);
while (nsnull != table->tag) {
if (val.EqualsIgnoreCase(table->tag)) {
@ -421,7 +421,7 @@ nsHTMLButtonElement::AttributeToString(nsIAtom* aAttribute,
{
if (aAttribute == nsHTMLAtoms::type) {
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
EnumValueToString(aValue, kButtonTypeTable, aResult);
aValue.EnumValueToString(kButtonTypeTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -47,7 +47,7 @@
// XXX nav4 has type= start= (same as OL/UL)
extern nsGenericHTMLElement::EnumTable kListTypeTable[];
extern nsHTMLValue::EnumTable kListTypeTable[];
class nsHTMLDirectoryElement : public nsGenericHTMLContainerElement,
@ -171,12 +171,12 @@ nsHTMLDirectoryElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::type) {
if (ParseEnumValue(aValue, kListTypeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kListTypeTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::start) {
if (ParseValue(aValue, 1, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 1)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -193,7 +193,7 @@ nsHTMLDirectoryElement::AttributeToString(nsIAtom* aAttribute,
nsAString& aResult) const
{
if (aAttribute == nsHTMLAtoms::type) {
EnumValueToString(aValue, kListTypeTable, aResult);
aValue.EnumValueToString(kListTypeTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
return nsGenericHTMLContainerElement::AttributeToString(aAttribute, aValue,

View File

@ -176,17 +176,17 @@ nsHTMLDivElement::StringToAttribute(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::cols) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::gutter) {
if (ParseValue(aValue, 1, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, 1)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::width) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -186,7 +186,7 @@ nsHTMLFontElement::StringToAttribute(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::color) {
if (ParseColor(aValue, mDocument, aResult)) {
if (aResult.ParseColor(aValue, mDocument)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -627,13 +627,13 @@ nsHTMLFormElement::Reset()
return rv;
}
static nsGenericHTMLElement::EnumTable kFormMethodTable[] = {
static nsHTMLValue::EnumTable kFormMethodTable[] = {
{ "get", NS_FORM_METHOD_GET },
{ "post", NS_FORM_METHOD_POST },
{ 0 }
};
static nsGenericHTMLElement::EnumTable kFormEnctypeTable[] = {
static nsHTMLValue::EnumTable kFormEnctypeTable[] = {
{ "multipart/form-data", NS_FORM_ENCTYPE_MULTIPART },
{ "application/x-www-form-urlencoded", NS_FORM_ENCTYPE_URLENCODED },
{ "text/plain", NS_FORM_ENCTYPE_TEXTPLAIN },
@ -646,12 +646,12 @@ nsHTMLFormElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::method) {
if (ParseEnumValue(aValue, kFormMethodTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kFormMethodTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::enctype) {
if (ParseEnumValue(aValue, kFormEnctypeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kFormEnctypeTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -665,13 +665,13 @@ nsHTMLFormElement::AttributeToString(nsIAtom* aAttribute,
{
if (aAttribute == nsHTMLAtoms::method) {
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
EnumValueToString(aValue, kFormMethodTable, aResult);
aValue.EnumValueToString(kFormMethodTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::enctype) {
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
EnumValueToString(aValue, kFormEnctypeTable, aResult);
aValue.EnumValueToString(kFormEnctypeTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -237,7 +237,7 @@ nsHTMLFrameElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::bordercolor) {
if (ParseColor(aValue, mDocument, aResult)) {
if (aResult.ParseColor(aValue, mDocument)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -247,12 +247,12 @@ nsHTMLFrameElement::StringToAttribute(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::marginwidth) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::marginheight) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -352,7 +352,7 @@ nsHTMLFrameSetElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::bordercolor) {
if (nsGenericHTMLElement::ParseColor(aValue, mDocument, aResult)) {
if (aResult.ParseColor(aValue, mDocument)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -362,7 +362,7 @@ nsHTMLFrameSetElement::StringToAttribute(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::border) {
if (nsGenericHTMLElement::ParseValue(aValue, 0, 100, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, 0, 100)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -163,7 +163,7 @@ NS_IMPL_BOOL_ATTR(nsHTMLHRElement, NoShade, noshade)
NS_IMPL_STRING_ATTR(nsHTMLHRElement, Size, size)
NS_IMPL_STRING_ATTR(nsHTMLHRElement, Width, width)
static nsGenericHTMLElement::EnumTable kAlignTable[] = {
static nsHTMLValue::EnumTable kAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_CENTER },
@ -176,12 +176,12 @@ nsHTMLHRElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::width) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::size) {
if (ParseValue(aValue, 1, 1000, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, 1, 1000)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -190,7 +190,7 @@ nsHTMLHRElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::align) {
if (ParseEnumValue(aValue, kAlignTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kAlignTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -205,7 +205,7 @@ nsHTMLHRElement::AttributeToString(nsIAtom* aAttribute,
{
if (aAttribute == nsHTMLAtoms::align) {
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
EnumValueToString(aValue, kAlignTable, aResult);
aValue.EnumValueToString(kAlignTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -376,22 +376,22 @@ nsHTMLIFrameElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::marginwidth) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::marginheight) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::width) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::height) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -1819,7 +1819,7 @@ nsHTMLInputElement::SetDocument(nsIDocument* aDocument, PRBool aDeep,
// nsIHTMLContent
static nsGenericHTMLElement::EnumTable kInputTypeTable[] = {
static nsHTMLValue::EnumTable kInputTypeTable[] = {
{ "browse", NS_FORM_BROWSE }, // XXX not valid html, but it is convenient
{ "button", NS_FORM_INPUT_BUTTON },
{ "checkbox", NS_FORM_INPUT_CHECKBOX },
@ -1840,7 +1840,7 @@ nsHTMLInputElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::type) {
nsGenericHTMLElement::EnumTable *table = kInputTypeTable;
nsHTMLValue::EnumTable *table = kInputTypeTable;
nsAutoString valueStr(aValue);
while (nsnull != table->tag) {
if (valueStr.EqualsIgnoreCase(table->tag)) {
@ -1869,40 +1869,40 @@ nsHTMLInputElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::width) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::height) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::maxlength) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::size) {
if (mType == NS_FORM_INPUT_TEXT ||
mType == NS_FORM_INPUT_PASSWORD) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
}
else if (aAttribute == nsHTMLAtoms::tabindex) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::border) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -1936,7 +1936,7 @@ nsHTMLInputElement::AttributeToString(nsIAtom* aAttribute,
// http://bugzilla.mozilla.org/show_bug.cgi?id=113174#c12
// -- bzbarsky@mit.edu
EnumValueToString(aValue, kInputTypeTable, aResult);
aValue.EnumValueToString(kInputTypeTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}

View File

@ -162,7 +162,7 @@ NS_IMPL_STRING_ATTR(nsHTMLLIElement, Type, type)
NS_IMPL_INT_ATTR(nsHTMLLIElement, Value, value)
static nsGenericHTMLElement::EnumTable kUnorderedListItemTypeTable[] = {
static nsHTMLValue::EnumTable kUnorderedListItemTypeTable[] = {
{ "disc", NS_STYLE_LIST_STYLE_DISC },
{ "circle", NS_STYLE_LIST_STYLE_CIRCLE },
{ "round", NS_STYLE_LIST_STYLE_CIRCLE },
@ -170,7 +170,7 @@ static nsGenericHTMLElement::EnumTable kUnorderedListItemTypeTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kOrderedListItemTypeTable[] = {
static nsHTMLValue::EnumTable kOrderedListItemTypeTable[] = {
{ "A", NS_STYLE_LIST_STYLE_OLD_UPPER_ALPHA },
{ "a", NS_STYLE_LIST_STYLE_OLD_LOWER_ALPHA },
{ "I", NS_STYLE_LIST_STYLE_OLD_UPPER_ROMAN },
@ -185,15 +185,15 @@ nsHTMLLIElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::type) {
if (ParseCaseSensitiveEnumValue(aValue, kOrderedListItemTypeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kOrderedListItemTypeTable, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
if (ParseEnumValue(aValue, kUnorderedListItemTypeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kUnorderedListItemTypeTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::value) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -207,8 +207,8 @@ nsHTMLLIElement::AttributeToString(nsIAtom* aAttribute,
nsAString& aResult) const
{
if (aAttribute == nsHTMLAtoms::type) {
if (!EnumValueToString(aValue, kOrderedListItemTypeTable, aResult)) {
EnumValueToString(aValue, kUnorderedListItemTypeTable, aResult);
if (!aValue.EnumValueToString(kOrderedListItemTypeTable, aResult)) {
aValue.EnumValueToString(kUnorderedListItemTypeTable, aResult);
}
return NS_CONTENT_ATTR_HAS_VALUE;

View File

@ -176,7 +176,7 @@ NS_IMPL_STRING_ATTR(nsHTMLLegendElement, AccessKey, accesskey)
NS_IMPL_STRING_ATTR(nsHTMLLegendElement, Align, align)
// this contains center, because IE4 does
static nsGenericHTMLElement::EnumTable kAlignTable[] = {
static nsHTMLValue::EnumTable kAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
{ "center", NS_STYLE_TEXT_ALIGN_CENTER },
@ -191,7 +191,7 @@ nsHTMLLegendElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::align) {
if (ParseEnumValue(aValue, kAlignTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kAlignTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -206,7 +206,7 @@ nsHTMLLegendElement::AttributeToString(nsIAtom* aAttribute,
{
if (aAttribute == nsHTMLAtoms::align) {
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
EnumValueToString(aValue, kAlignTable, aResult);
aValue.EnumValueToString(kAlignTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -47,7 +47,7 @@
// XXX nav4 has type= start= (same as OL/UL)
extern nsGenericHTMLElement::EnumTable kListTypeTable[];
extern nsHTMLValue::EnumTable kListTypeTable[];
class nsHTMLMenuElement : public nsGenericHTMLContainerElement,
@ -173,12 +173,12 @@ nsHTMLMenuElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::type) {
if (ParseEnumValue(aValue, kListTypeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kListTypeTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::start) {
if (ParseValue(aValue, 1, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 1)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -192,7 +192,7 @@ nsHTMLMenuElement::AttributeToString(nsIAtom* aAttribute,
nsAString& aResult) const
{
if (aAttribute == nsHTMLAtoms::type) {
EnumValueToString(aValue, kListTypeTable, aResult);
aValue.EnumValueToString(kListTypeTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}

View File

@ -163,7 +163,7 @@ NS_IMPL_INT_ATTR(nsHTMLOListElement, Start, start)
NS_IMPL_STRING_ATTR(nsHTMLOListElement, Type, type)
nsGenericHTMLElement::EnumTable kListTypeTable[] = {
nsHTMLValue::EnumTable kListTypeTable[] = {
{ "none", NS_STYLE_LIST_STYLE_NONE },
{ "disc", NS_STYLE_LIST_STYLE_DISC },
{ "circle", NS_STYLE_LIST_STYLE_CIRCLE },
@ -177,7 +177,7 @@ nsGenericHTMLElement::EnumTable kListTypeTable[] = {
{ 0 }
};
nsGenericHTMLElement::EnumTable kOldListTypeTable[] = {
nsHTMLValue::EnumTable kOldListTypeTable[] = {
{ "1", NS_STYLE_LIST_STYLE_OLD_DECIMAL },
{ "A", NS_STYLE_LIST_STYLE_OLD_UPPER_ALPHA },
{ "a", NS_STYLE_LIST_STYLE_OLD_LOWER_ALPHA },
@ -192,16 +192,16 @@ nsHTMLOListElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::type) {
if (ParseEnumValue(aValue, kListTypeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kListTypeTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
if (ParseCaseSensitiveEnumValue(aValue, kOldListTypeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kOldListTypeTable, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::start) {
if (ParseValue(aValue, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Integer)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -222,10 +222,10 @@ nsHTMLOListElement::AttributeToString(nsIAtom* aAttribute,
case NS_STYLE_LIST_STYLE_OLD_UPPER_ROMAN:
case NS_STYLE_LIST_STYLE_OLD_LOWER_ALPHA:
case NS_STYLE_LIST_STYLE_OLD_UPPER_ALPHA:
EnumValueToString(aValue, kOldListTypeTable, aResult);
aValue.EnumValueToString(kOldListTypeTable, aResult);
break;
default:
EnumValueToString(aValue, kListTypeTable, aResult);
aValue.EnumValueToString(kListTypeTable, aResult);
break;
}

View File

@ -256,7 +256,7 @@ nsHTMLObjectElement::StringToAttribute(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::tabindex) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -169,12 +169,12 @@ nsHTMLPreElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::cols) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::width) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -1843,12 +1843,12 @@ nsHTMLSelectElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::size) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::tabindex) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -214,7 +214,7 @@ NS_IMPL_STRING_ATTR(nsHTMLSharedContainerElement, Type, type)
NS_IMPL_STRING_ATTR(nsHTMLSharedContainerElement, Align, align)
nsGenericHTMLElement::EnumTable kListTypeTable[] = {
nsHTMLValue::EnumTable kListTypeTable[] = {
{ "none", NS_STYLE_LIST_STYLE_NONE },
{ "disc", NS_STYLE_LIST_STYLE_DISC },
{ "circle", NS_STYLE_LIST_STYLE_CIRCLE },
@ -228,7 +228,7 @@ nsGenericHTMLElement::EnumTable kListTypeTable[] = {
{ 0 }
};
nsGenericHTMLElement::EnumTable kOldListTypeTable[] = {
nsHTMLValue::EnumTable kOldListTypeTable[] = {
{ "1", NS_STYLE_LIST_STYLE_OLD_DECIMAL },
{ "A", NS_STYLE_LIST_STYLE_OLD_UPPER_ALPHA },
{ "a", NS_STYLE_LIST_STYLE_OLD_LOWER_ALPHA },
@ -237,7 +237,7 @@ nsGenericHTMLElement::EnumTable kOldListTypeTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kCaptionAlignTable[] = {
static nsHTMLValue::EnumTable kCaptionAlignTable[] = {
{ "left", NS_SIDE_LEFT },
{ "right", NS_SIDE_RIGHT },
{ "top", NS_SIDE_TOP},
@ -255,17 +255,17 @@ nsHTMLSharedContainerElement::StringToAttribute(nsIAtom* aAttribute,
mNodeInfo->Equals(nsHTMLAtoms::menu) ||
mNodeInfo->Equals(nsHTMLAtoms::ol)) {
if (aAttribute == nsHTMLAtoms::type) {
if (ParseEnumValue(aValue, kListTypeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kListTypeTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
if (mNodeInfo->Equals(nsHTMLAtoms::ol)) {
if (ParseCaseSensitiveEnumValue(aValue, kOldListTypeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kOldListTypeTable, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
} else if (aAttribute == nsHTMLAtoms::start) {
if (ParseValue(aValue, 1, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 1)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
} else if (mNodeInfo->Equals(nsHTMLAtoms::dir) &&
@ -275,7 +275,7 @@ nsHTMLSharedContainerElement::StringToAttribute(nsIAtom* aAttribute,
}
} else if (mNodeInfo->Equals(nsHTMLAtoms::caption)) {
if (aAttribute == nsHTMLAtoms::align) {
if (ParseEnumValue(aValue, kCaptionAlignTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kCaptionAlignTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -293,7 +293,7 @@ nsHTMLSharedContainerElement::AttributeToString(nsIAtom* aAttribute,
if (mNodeInfo->Equals(nsHTMLAtoms::dir) ||
mNodeInfo->Equals(nsHTMLAtoms::menu)) {
if (aAttribute == nsHTMLAtoms::type) {
EnumValueToString(aValue, kListTypeTable, aResult);
aValue.EnumValueToString(kListTypeTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
} else if (mNodeInfo->Equals(nsHTMLAtoms::ol)) {
@ -305,10 +305,10 @@ nsHTMLSharedContainerElement::AttributeToString(nsIAtom* aAttribute,
case NS_STYLE_LIST_STYLE_OLD_UPPER_ROMAN:
case NS_STYLE_LIST_STYLE_OLD_LOWER_ALPHA:
case NS_STYLE_LIST_STYLE_OLD_UPPER_ALPHA:
EnumValueToString(aValue, kOldListTypeTable, aResult);
aValue.EnumValueToString(kOldListTypeTable, aResult);
break;
default:
EnumValueToString(aValue, kListTypeTable, aResult);
aValue.EnumValueToString(kListTypeTable, aResult);
break;
}
@ -317,7 +317,7 @@ nsHTMLSharedContainerElement::AttributeToString(nsIAtom* aAttribute,
} else if (mNodeInfo->Equals(nsHTMLAtoms::caption)) {
if (aAttribute == nsHTMLAtoms::align) {
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
EnumValueToString(aValue, kCaptionAlignTable, aResult);
aValue.EnumValueToString(kCaptionAlignTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}

View File

@ -246,7 +246,7 @@ nsHTMLSharedLeafElement::StringToAttribute(nsIAtom* aAttribute,
}
} else if (mNodeInfo->Equals(nsHTMLAtoms::spacer)) {
if (aAttribute == nsHTMLAtoms::size) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
} else if (aAttribute == nsHTMLAtoms::align) {
@ -255,7 +255,7 @@ nsHTMLSharedLeafElement::StringToAttribute(nsIAtom* aAttribute,
}
} else if ((aAttribute == nsHTMLAtoms::width) ||
(aAttribute == nsHTMLAtoms::height)) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -246,7 +246,7 @@ nsHTMLSharedLeafElement::StringToAttribute(nsIAtom* aAttribute,
}
} else if (mNodeInfo->Equals(nsHTMLAtoms::spacer)) {
if (aAttribute == nsHTMLAtoms::size) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
} else if (aAttribute == nsHTMLAtoms::align) {
@ -255,7 +255,7 @@ nsHTMLSharedLeafElement::StringToAttribute(nsIAtom* aAttribute,
}
} else if ((aAttribute == nsHTMLAtoms::width) ||
(aAttribute == nsHTMLAtoms::height)) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -256,7 +256,7 @@ nsHTMLObjectElement::StringToAttribute(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::tabindex) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -161,7 +161,7 @@ nsHTMLTableCaptionElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
NS_IMPL_STRING_ATTR(nsHTMLTableCaptionElement, Align, align)
static nsGenericHTMLElement::EnumTable kCaptionAlignTable[] = {
static nsHTMLValue::EnumTable kCaptionAlignTable[] = {
{ "left", NS_SIDE_LEFT },
{ "right", NS_SIDE_RIGHT },
{ "top", NS_SIDE_TOP},
@ -175,7 +175,7 @@ nsHTMLTableCaptionElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::align) {
if (ParseEnumValue(aValue, kCaptionAlignTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kCaptionAlignTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -189,7 +189,7 @@ nsHTMLTableCaptionElement::AttributeToString(nsIAtom* aAttribute,
{
if (aAttribute == nsHTMLAtoms::align) {
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
EnumValueToString(aValue, kCaptionAlignTable, aResult);
aValue.EnumValueToString(kCaptionAlignTable, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}

View File

@ -318,7 +318,7 @@ nsHTMLTableCellElement::SetAlign(const nsAString& aValue)
}
static nsGenericHTMLElement::EnumTable kCellScopeTable[] = {
static nsHTMLValue::EnumTable kCellScopeTable[] = {
{ "row", NS_STYLE_CELL_SCOPE_ROW },
{ "col", NS_STYLE_CELL_SCOPE_COL },
{ "rowgroup", NS_STYLE_CELL_SCOPE_ROWGROUP },
@ -340,15 +340,15 @@ nsHTMLTableCellElement::StringToAttribute(nsIAtom* aAttribute,
if (aAttribute == nsHTMLAtoms::charoff) {
/* attributes that resolve to integers with a min of 0 */
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if ((aAttribute == nsHTMLAtoms::colspan) ||
(aAttribute == nsHTMLAtoms::rowspan)) {
PRBool parsed = (aAttribute == nsHTMLAtoms::colspan)
? ParseValue(aValue, -1, MAX_COLSPAN, aResult, eHTMLUnit_Integer)
: ParseValue(aValue, -1, MAX_ROWSPAN, aResult, eHTMLUnit_Integer);
? aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, -1, MAX_COLSPAN)
: aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, -1, MAX_ROWSPAN);
if (parsed) {
PRInt32 val = aResult.GetIntValue();
// quirks mode does not honor the special html 4 value of 0
@ -363,14 +363,14 @@ nsHTMLTableCellElement::StringToAttribute(nsIAtom* aAttribute,
else if (aAttribute == nsHTMLAtoms::height) {
/* attributes that resolve to integers or percents */
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::width) {
/* attributes that resolve to integers or percents */
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -382,12 +382,12 @@ nsHTMLTableCellElement::StringToAttribute(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
if (ParseColor(aValue, mDocument, aResult)) {
if (aResult.ParseColor(aValue, mDocument)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::scope) {
if (ParseEnumValue(aValue, kCellScopeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kCellScopeTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -417,7 +417,7 @@ nsHTMLTableCellElement::AttributeToString(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::scope) {
if (EnumValueToString(aValue, kCellScopeTable, aResult)) {
if (aValue.EnumValueToString(kCellScopeTable, aResult)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -184,20 +184,20 @@ nsHTMLTableColElement::StringToAttribute(nsIAtom* aAttribute,
/* ignore these attributes, stored simply as strings ch */
/* attributes that resolve to integers */
if (aAttribute == nsHTMLAtoms::charoff) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::span) {
/* protection from unrealistic large colspan values */
if (ParseValue(aValue, 1, MAX_COLSPAN, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 1, MAX_COLSPAN)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::width) {
/* attributes that resolve to integers or percents or proportions */
if (ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -239,7 +239,7 @@ nsHTMLTableColElement::AttributeToString(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::width) {
if (ValueOrPercentOrProportionalToString(aValue, aResult)) {
if (aValue.ToString(aResult)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -941,7 +941,7 @@ nsHTMLTableElement::DeleteRow(PRInt32 aValue)
return parent->RemoveChild(row, getter_AddRefs(deleted_row));
}
static nsGenericHTMLElement::EnumTable kFrameTable[] = {
static nsHTMLValue::EnumTable kFrameTable[] = {
{ "void", NS_STYLE_TABLE_FRAME_NONE },
{ "above", NS_STYLE_TABLE_FRAME_ABOVE },
{ "below", NS_STYLE_TABLE_FRAME_BELOW },
@ -954,7 +954,7 @@ static nsGenericHTMLElement::EnumTable kFrameTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kRulesTable[] = {
static nsHTMLValue::EnumTable kRulesTable[] = {
{ "none", NS_STYLE_TABLE_RULES_NONE },
{ "groups", NS_STYLE_TABLE_RULES_GROUPS },
{ "rows", NS_STYLE_TABLE_RULES_ROWS },
@ -963,7 +963,7 @@ static nsGenericHTMLElement::EnumTable kRulesTable[] = {
{ 0 }
};
static nsGenericHTMLElement::EnumTable kLayoutTable[] = {
static nsHTMLValue::EnumTable kLayoutTable[] = {
{ "auto", NS_STYLE_TABLE_LAYOUT_AUTO },
{ "fixed", NS_STYLE_TABLE_LAYOUT_FIXED },
{ 0 }
@ -979,14 +979,14 @@ nsHTMLTableElement::StringToAttribute(nsIAtom* aAttribute,
/* attributes that resolve to pixels, with min=0 */
if ((aAttribute == nsHTMLAtoms::cellspacing) ||
(aAttribute == nsHTMLAtoms::cellpadding)) {
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::cols) {
/* attributes that are either empty, or integers, with min=0 */
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -994,7 +994,7 @@ nsHTMLTableElement::StringToAttribute(nsIAtom* aAttribute,
/* attributes that are either empty, or pixels */
PRInt32 min = (aValue.IsEmpty()) ? 1 : 0;
if (ParseValue(aValue, min, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, min)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
else {
@ -1006,14 +1006,14 @@ nsHTMLTableElement::StringToAttribute(nsIAtom* aAttribute,
else if (aAttribute == nsHTMLAtoms::height) {
/* attributes that resolve to integers or percents */
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::width) {
/* attributes that resolve to integers or percents or proportions */
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
// treat 0 width as auto
nsHTMLUnit unit = aResult.GetUnit();
if ((eHTMLUnit_Pixel == unit) && (0 == aResult.GetPixelValue())) {
@ -1036,37 +1036,37 @@ nsHTMLTableElement::StringToAttribute(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
if (ParseColor(aValue, mDocument, aResult)) {
if (aResult.ParseColor(aValue, mDocument)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::bordercolor) {
if (ParseColor(aValue, mDocument, aResult)) {
if (aResult.ParseColor(aValue, mDocument)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::frame) {
if (ParseEnumValue(aValue, kFrameTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kFrameTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::layout) {
if (ParseEnumValue(aValue, kLayoutTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kLayoutTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::rules) {
if (ParseEnumValue(aValue, kRulesTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kRulesTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::hspace) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::vspace) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Pixel, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -1088,17 +1088,17 @@ nsHTMLTableElement::AttributeToString(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::frame) {
if (EnumValueToString(aValue, kFrameTable, aResult)) {
if (aValue.EnumValueToString(kFrameTable, aResult)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::layout) {
if (EnumValueToString(aValue, kLayoutTable, aResult)) {
if (aValue.EnumValueToString(kLayoutTable, aResult)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::rules) {
if (EnumValueToString(aValue, kRulesTable, aResult)) {
if (aValue.EnumValueToString(kRulesTable, aResult)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -531,21 +531,21 @@ nsHTMLTableRowElement::StringToAttribute(nsIAtom* aAttribute,
/* attributes that resolve to integers with default = 0 */
if (aAttribute == nsHTMLAtoms::charoff) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::height) {
/* attributes that resolve to integers or percents */
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::width) {
/* attributes that resolve to integers or percents */
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -557,7 +557,7 @@ nsHTMLTableRowElement::StringToAttribute(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
if (ParseColor(aValue, mDocument, aResult)) {
if (aResult.ParseColor(aValue, mDocument)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -295,14 +295,14 @@ nsHTMLTableSectionElement::StringToAttribute(nsIAtom* aAttribute,
*/
/* attributes that resolve to integers */
if (aAttribute == nsHTMLAtoms::charoff) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::height) {
/* attributes that resolve to integers or percents */
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
if (aResult.ParseIntValue(aValue, eHTMLUnit_Pixel, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -314,7 +314,7 @@ nsHTMLTableSectionElement::StringToAttribute(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
if (ParseColor(aValue, mDocument, aResult)) {
if (aResult.ParseColor(aValue, mDocument)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -596,7 +596,7 @@ nsHTMLTextAreaElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::cols) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -605,12 +605,12 @@ nsHTMLTextAreaElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::rows) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::tabindex) {
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 0)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

View File

@ -45,8 +45,8 @@
#include "nsHTMLAttributes.h"
#include "nsRuleNode.h"
extern nsGenericHTMLElement::EnumTable kListTypeTable[];
extern nsGenericHTMLElement::EnumTable kOldListTypeTable[];
extern nsHTMLValue::EnumTable kListTypeTable[];
extern nsHTMLValue::EnumTable kOldListTypeTable[];
class nsHTMLUListElement : public nsGenericHTMLContainerElement,
public nsIDOMHTMLUListElement
@ -171,17 +171,17 @@ nsHTMLUListElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::type) {
if (ParseEnumValue(aValue, kListTypeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kListTypeTable)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
if (ParseCaseSensitiveEnumValue(aValue, kOldListTypeTable, aResult)) {
if (aResult.ParseEnumValue(aValue, kOldListTypeTable, PR_TRUE)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
if (aAttribute == nsHTMLAtoms::start) {
if (ParseValue(aValue, 1, aResult, eHTMLUnit_Integer)) {
if (aResult.ParseIntWithBounds(aValue, eHTMLUnit_Integer, 1)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
@ -201,11 +201,11 @@ nsHTMLUListElement::AttributeToString(nsIAtom* aAttribute,
case NS_STYLE_LIST_STYLE_OLD_UPPER_ROMAN:
case NS_STYLE_LIST_STYLE_OLD_LOWER_ALPHA:
case NS_STYLE_LIST_STYLE_OLD_UPPER_ALPHA:
EnumValueToString(aValue, kOldListTypeTable, aResult);
aValue.EnumValueToString(kOldListTypeTable, aResult);
break;
default:
EnumValueToString(aValue, kListTypeTable, aResult);
aValue.EnumValueToString(kListTypeTable, aResult);
break;
}

View File

@ -3086,7 +3086,7 @@ nsHTMLDocument::GetAlinkColor(nsAString& aAlinkColor)
result = mAttrStyleSheet->GetActiveLinkColor(color);
if (NS_OK == result) {
nsHTMLValue value(color);
nsGenericHTMLElement::ColorToString(value, aAlinkColor);
value.ToString(aAlinkColor);
}
}
@ -3107,7 +3107,7 @@ nsHTMLDocument::SetAlinkColor(const nsAString& aAlinkColor)
else if (mAttrStyleSheet) {
nsHTMLValue value;
if (nsGenericHTMLElement::ParseColor(aAlinkColor, this, value)) {
if (value.ParseColor(aAlinkColor, this)) {
mAttrStyleSheet->SetActiveLinkColor(value.GetColorValue());
}
}
@ -3132,7 +3132,7 @@ nsHTMLDocument::GetLinkColor(nsAString& aLinkColor)
result = mAttrStyleSheet->GetLinkColor(color);
if (NS_OK == result) {
nsHTMLValue value(color);
nsGenericHTMLElement::ColorToString(value, aLinkColor);
value.ToString(aLinkColor);
}
}
@ -3152,7 +3152,7 @@ nsHTMLDocument::SetLinkColor(const nsAString& aLinkColor)
}
else if (mAttrStyleSheet) {
nsHTMLValue value;
if (nsGenericHTMLElement::ParseColor(aLinkColor, this, value)) {
if (value.ParseColor(aLinkColor, this)) {
mAttrStyleSheet->SetLinkColor(value.GetColorValue());
}
}
@ -3177,7 +3177,7 @@ nsHTMLDocument::GetVlinkColor(nsAString& aVlinkColor)
result = mAttrStyleSheet->GetVisitedLinkColor(color);
if (NS_OK == result) {
nsHTMLValue value(color);
nsGenericHTMLElement::ColorToString(value, aVlinkColor);
value.ToString(aVlinkColor);
}
}
@ -3197,7 +3197,7 @@ nsHTMLDocument::SetVlinkColor(const nsAString& aVlinkColor)
}
else if (mAttrStyleSheet) {
nsHTMLValue value;
if (nsGenericHTMLElement::ParseColor(aVlinkColor, this, value)) {
if (value.ParseColor(aVlinkColor, this)) {
mAttrStyleSheet->SetVisitedLinkColor(value.GetColorValue());
}
}

View File

@ -47,6 +47,8 @@
#include "nsReadableUtils.h"
#include "nsCRT.h"
class nsIDocument;
class nsCheapStringBufferUtils {
public:
/**
@ -216,16 +218,109 @@ public:
void SetColorValue(nscolor aValue);
void SetEmptyValue(void);
/**
* 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;
#ifdef DEBUG
void AppendToString(nsAString& aBuffer) const;
#endif
/**
* Structure for a mapping from int (enum) values to strings. When you use
* it you generally create an array of them.
* Instantiate like this:
* EnumTable myTable[] = {
* { "string1", 1 },
* { "string2", 2 },
* { 0 }
* }
*/
struct EnumTable {
/** The string the value maps to */
const char* tag;
/** The enum value that maps to this string */
PRInt32 value;
};
/**
* Parse and output this HTMLValue in a variety of ways
*/
// 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,
EnumTable* aTable,
PRBool aCaseSensitive = PR_FALSE);
/**
* Map an enum HTMLValue to its string
*
* @param aValue the HTMLValue with the int in it
* @param aTable the enumeration to map with
* @param aResult the string the value maps to [OUT]
* @return whether the enum value was found or not
*/
PRBool EnumValueToString(EnumTable* aTable,
nsAString& aResult) const;
/**
* Parse a string value into an int or pixel HTMLValue with minimum
* value and maximum value (can optionally parse percent (n%) and
* proportional (n%)
*
* @param aString the string to parse
* @param aDefaultUnit the unit to use (eHTMLUnit_Pixel or Integer)
* @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 ParseIntValue(const nsAString& aString, nsHTMLUnit aDefaultUnit,
PRBool aCanBePercent = PR_FALSE,
PRBool aCanBeProportional = PR_FALSE);
/**
* Parse a string value into an int or pixel 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 (eHTMLUnit_Pixel or Integer)
* @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
* @see nsHTMLUnit
*/
PRUint32 mUnit;
/**
* The actual value. Please to not be adding more-than-4-byte things to this
* union.
@ -242,6 +337,7 @@ protected:
/** Color. */
nscolor mColor;
} mValue;
private:
/**
* Copy into this HTMLValue from aCopy. Please be aware that if this is an

View File

@ -43,6 +43,10 @@
#include "nsUnicharUtils.h"
#include "nsCRT.h"
#include "nsMemory.h"
#include "nsIDocument.h"
#include "nsIHTMLDocument.h"
#include "nsUnitConversion.h"
#include "prprf.h"
nsHTMLValue::nsHTMLValue(nsHTMLUnit aUnit)
: mUnit(aUnit)
@ -378,3 +382,221 @@ nsHTMLValue::InitializeFrom(const nsHTMLValue& aCopy)
NS_ERROR("Unknown HTMLValue type!");
}
}
//
// Parsing methods
//
PRBool
nsHTMLValue::ParseEnumValue(const nsAString& aValue,
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(EnumTable* aTable,
nsAString& aResult) const
{
if (GetUnit() == eHTMLUnit_Enumerated) {
PRInt32 v = GetIntValue();
while (aTable->tag) {
if (aTable->value == v) {
CopyASCIItoUCS2(nsDependentCString(aTable->tag), aResult);
return PR_TRUE;
}
aTable++;
}
}
aResult.Truncate();
return PR_FALSE;
}
/* used to parse attribute values that could be either:
* integer (n),
* percent (n%),
* or proportional (n*)
*/
PRBool
nsHTMLValue::ParseIntValue(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
if (aDefaultUnit == eHTMLUnit_Pixel) {
SetPixelValue(val);
} else {
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.Last() == '*' && tmp.Length() == 1) {
// 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_Pixel:
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();
char buf[10];
PR_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
NS_GET_R(v), NS_GET_G(v), NS_GET_B(v));
aResult.Assign(NS_ConvertASCIItoUCS2(buf));
return PR_TRUE;
}
case eHTMLUnit_ColorName:
case eHTMLUnit_String:
GetStringValue(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);
if (aDefaultUnit == eHTMLUnit_Pixel) {
SetPixelValue(val);
} else {
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_ColorName);
return PR_TRUE;
}
// Check if we are in compatibility mode
PRBool inNavQuirksMode;
{
nsCOMPtr<nsIHTMLDocument> doc(do_QueryInterface(aDocument));
if (doc) {
nsCompatibility mode;
doc->GetCompatibilityMode(mode);
inNavQuirksMode = (mode == 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;
}

View File

@ -38,6 +38,7 @@
#define nsUnitConversion_h__
#include "nscore.h"
#include "nsCoord.h"
#include <math.h>
/// handy constants