This commit is contained in:
peterl%netscape.com 1999-07-18 00:20:27 +00:00
Родитель 47ad552cb6
Коммит 22a8e415fc
21 изменённых файлов: 61 добавлений и 57 удалений

Просмотреть файл

@ -395,6 +395,9 @@ static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument)
nsresult
nsGenericHTMLElement::SetDocument(nsIDocument* aDocument, PRBool aDeep)
{
if (aDocument == mDocument) {
return NS_OK; // short circuit useless work
}
nsresult result = nsGenericElement::SetDocument(aDocument, aDeep);
if (NS_OK != result) {
@ -791,12 +794,13 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
// Provide default conversions for most everything
switch (value.GetUnit()) {
case eHTMLUnit_Null:
case eHTMLUnit_Empty:
aResult.Truncate();
break;
case eHTMLUnit_String:
case eHTMLUnit_Null:
case eHTMLUnit_ColorName:
value.GetStringValue(aResult);
break;
@ -811,7 +815,7 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
break;
case eHTMLUnit_Percent:
aResult.Truncate(0);
aResult.Truncate();
aResult.Append(PRInt32(value.GetPercentValue() * 100.0f), 10);
aResult.Append('%');
break;
@ -820,7 +824,7 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
color = nscolor(value.GetColorValue());
PR_snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x",
NS_GET_R(color), NS_GET_G(color), NS_GET_B(color));
aResult.Truncate(0);
aResult.Truncate();
aResult.Append(cbuf);
break;
@ -989,7 +993,6 @@ nsresult
nsGenericHTMLElement::GetBaseTarget(nsString& aBaseTarget) const
{
nsresult result = NS_OK;
PRBool hasLocal = PR_FALSE;
if (nsnull != mAttributes) {
nsHTMLValue value;
@ -1392,24 +1395,22 @@ nsGenericHTMLElement::ParseValue(const nsString& aString, PRInt32 aMin,
PRBool
nsGenericHTMLElement::ParseColor(const nsString& aString,
nsIDocument* aDocument,
nsHTMLValue& aResult)
{
if (aString.Length() > 0) {
nsAutoString colorStr (aString);
colorStr.CompressWhitespace();
char cbuf[40];
colorStr.ToCString(cbuf, sizeof(cbuf));
nscolor color = 0;
if (NS_ColorNameToRGB(cbuf, &color)) {
if (NS_ColorNameToRGB(colorStr, &color)) {
aResult.SetStringValue(colorStr, eHTMLUnit_ColorName);
return PR_TRUE;
}
#if 0
nsDTDMode mode = eDTDMode_NoQuirks;
if (mDocument) {
if (aDocument) {
nsIHTMLDocument* htmlDoc;
nsresult result;
result = mDocument->QueryInterface(kIHTMLDocumentIID, (void**)&htmlDoc);
result = aDocument->QueryInterface(kIHTMLDocumentIID, (void**)&htmlDoc);
if (NS_SUCCEEDED(result)) {
// Check the compatibility mode
result = htmlDoc->GetDTDMode(mode);
@ -1418,21 +1419,20 @@ nsGenericHTMLElement::ParseColor(const nsString& aString,
}
if (eDTDMode_NoQuirks == mode) {
if (('#' == cbuf[0]) && NS_HexToRGB(&(cbuf[1]), &color)) {
aResult.SetColorValue(color);
return PR_TRUE;
if (colorStr.CharAt(0) == '#') {
colorStr.Cut(0, 1);
if (NS_HexToRGB(colorStr, &color)) {
aResult.SetColorValue(color);
return PR_TRUE;
}
}
}
else {
#endif
aString.ToCString(cbuf, sizeof(cbuf)); // no space compression
if (NS_LooseHexToRGB(cbuf, &color)) {
if (NS_LooseHexToRGB(aString, &color)) { // no space compression
aResult.SetColorValue(color);
return PR_TRUE;
}
#if 0
}
#endif
}
// Illegal values are mapped to empty
@ -1453,7 +1453,8 @@ nsGenericHTMLElement::ColorToString(const nsHTMLValue& aValue,
aResult.Append(buf);
return PR_TRUE;
}
if (aValue.GetUnit() == eHTMLUnit_String) {
if ((aValue.GetUnit() == eHTMLUnit_ColorName) ||
(aValue.GetUnit() == eHTMLUnit_String)) {
aValue.GetStringValue(aResult);
return PR_TRUE;
}

Просмотреть файл

@ -167,7 +167,8 @@ public:
static PRBool ParseValue(const nsString& aString, PRInt32 aMin, PRInt32 aMax,
nsHTMLValue& aResult, nsHTMLUnit aValueUnit);
static PRBool ParseColor(const nsString& aString, nsHTMLValue& aResult);
static PRBool ParseColor(const nsString& aString, nsIDocument* aDocument,
nsHTMLValue& aResult);
static PRBool ColorToString(const nsHTMLValue& aValue,
nsString& aResult);

Просмотреть файл

@ -600,7 +600,7 @@ nsHTMLBodyElement::StringToAttribute(nsIAtom* aAttribute,
(aAttribute == nsHTMLAtoms::link) ||
(aAttribute == nsHTMLAtoms::alink) ||
(aAttribute == nsHTMLAtoms::vlink)) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
if ((aAttribute == nsHTMLAtoms::marginwidth) ||

Просмотреть файл

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

Просмотреть файл

@ -151,7 +151,7 @@ nsHTMLFrameElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::bordercolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::frameborder) {

Просмотреть файл

@ -133,7 +133,7 @@ nsHTMLFrameSetElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::bordercolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::frameborder) {

Просмотреть файл

@ -371,7 +371,7 @@ nsHTMLTableCellElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::nowrap) {

Просмотреть файл

@ -898,7 +898,7 @@ nsHTMLTableElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::frame) {

Просмотреть файл

@ -524,7 +524,7 @@ nsHTMLTableRowElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::valign) {

Просмотреть файл

@ -246,7 +246,7 @@ nsHTMLTableSectionElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::valign) {

Просмотреть файл

@ -395,6 +395,9 @@ static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument)
nsresult
nsGenericHTMLElement::SetDocument(nsIDocument* aDocument, PRBool aDeep)
{
if (aDocument == mDocument) {
return NS_OK; // short circuit useless work
}
nsresult result = nsGenericElement::SetDocument(aDocument, aDeep);
if (NS_OK != result) {
@ -791,12 +794,13 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
// Provide default conversions for most everything
switch (value.GetUnit()) {
case eHTMLUnit_Null:
case eHTMLUnit_Empty:
aResult.Truncate();
break;
case eHTMLUnit_String:
case eHTMLUnit_Null:
case eHTMLUnit_ColorName:
value.GetStringValue(aResult);
break;
@ -811,7 +815,7 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
break;
case eHTMLUnit_Percent:
aResult.Truncate(0);
aResult.Truncate();
aResult.Append(PRInt32(value.GetPercentValue() * 100.0f), 10);
aResult.Append('%');
break;
@ -820,7 +824,7 @@ nsGenericHTMLElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute,
color = nscolor(value.GetColorValue());
PR_snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x",
NS_GET_R(color), NS_GET_G(color), NS_GET_B(color));
aResult.Truncate(0);
aResult.Truncate();
aResult.Append(cbuf);
break;
@ -989,7 +993,6 @@ nsresult
nsGenericHTMLElement::GetBaseTarget(nsString& aBaseTarget) const
{
nsresult result = NS_OK;
PRBool hasLocal = PR_FALSE;
if (nsnull != mAttributes) {
nsHTMLValue value;
@ -1392,24 +1395,22 @@ nsGenericHTMLElement::ParseValue(const nsString& aString, PRInt32 aMin,
PRBool
nsGenericHTMLElement::ParseColor(const nsString& aString,
nsIDocument* aDocument,
nsHTMLValue& aResult)
{
if (aString.Length() > 0) {
nsAutoString colorStr (aString);
colorStr.CompressWhitespace();
char cbuf[40];
colorStr.ToCString(cbuf, sizeof(cbuf));
nscolor color = 0;
if (NS_ColorNameToRGB(cbuf, &color)) {
if (NS_ColorNameToRGB(colorStr, &color)) {
aResult.SetStringValue(colorStr, eHTMLUnit_ColorName);
return PR_TRUE;
}
#if 0
nsDTDMode mode = eDTDMode_NoQuirks;
if (mDocument) {
if (aDocument) {
nsIHTMLDocument* htmlDoc;
nsresult result;
result = mDocument->QueryInterface(kIHTMLDocumentIID, (void**)&htmlDoc);
result = aDocument->QueryInterface(kIHTMLDocumentIID, (void**)&htmlDoc);
if (NS_SUCCEEDED(result)) {
// Check the compatibility mode
result = htmlDoc->GetDTDMode(mode);
@ -1418,21 +1419,20 @@ nsGenericHTMLElement::ParseColor(const nsString& aString,
}
if (eDTDMode_NoQuirks == mode) {
if (('#' == cbuf[0]) && NS_HexToRGB(&(cbuf[1]), &color)) {
aResult.SetColorValue(color);
return PR_TRUE;
if (colorStr.CharAt(0) == '#') {
colorStr.Cut(0, 1);
if (NS_HexToRGB(colorStr, &color)) {
aResult.SetColorValue(color);
return PR_TRUE;
}
}
}
else {
#endif
aString.ToCString(cbuf, sizeof(cbuf)); // no space compression
if (NS_LooseHexToRGB(cbuf, &color)) {
if (NS_LooseHexToRGB(aString, &color)) { // no space compression
aResult.SetColorValue(color);
return PR_TRUE;
}
#if 0
}
#endif
}
// Illegal values are mapped to empty
@ -1453,7 +1453,8 @@ nsGenericHTMLElement::ColorToString(const nsHTMLValue& aValue,
aResult.Append(buf);
return PR_TRUE;
}
if (aValue.GetUnit() == eHTMLUnit_String) {
if ((aValue.GetUnit() == eHTMLUnit_ColorName) ||
(aValue.GetUnit() == eHTMLUnit_String)) {
aValue.GetStringValue(aResult);
return PR_TRUE;
}

Просмотреть файл

@ -167,7 +167,8 @@ public:
static PRBool ParseValue(const nsString& aString, PRInt32 aMin, PRInt32 aMax,
nsHTMLValue& aResult, nsHTMLUnit aValueUnit);
static PRBool ParseColor(const nsString& aString, nsHTMLValue& aResult);
static PRBool ParseColor(const nsString& aString, nsIDocument* aDocument,
nsHTMLValue& aResult);
static PRBool ColorToString(const nsHTMLValue& aValue,
nsString& aResult);

Просмотреть файл

@ -600,7 +600,7 @@ nsHTMLBodyElement::StringToAttribute(nsIAtom* aAttribute,
(aAttribute == nsHTMLAtoms::link) ||
(aAttribute == nsHTMLAtoms::alink) ||
(aAttribute == nsHTMLAtoms::vlink)) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
if ((aAttribute == nsHTMLAtoms::marginwidth) ||

Просмотреть файл

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

Просмотреть файл

@ -151,7 +151,7 @@ nsHTMLFrameElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::bordercolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::frameborder) {

Просмотреть файл

@ -133,7 +133,7 @@ nsHTMLFrameSetElement::StringToAttribute(nsIAtom* aAttribute,
nsHTMLValue& aResult)
{
if (aAttribute == nsHTMLAtoms::bordercolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::frameborder) {

Просмотреть файл

@ -209,7 +209,7 @@ nsHTMLLayerElement::StringToAttribute(nsIAtom* aAttribute,
}
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
if (nsGenericHTMLElement::ParseColor(aValue, aResult)) {
if (nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
}

Просмотреть файл

@ -371,7 +371,7 @@ nsHTMLTableCellElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::nowrap) {

Просмотреть файл

@ -898,7 +898,7 @@ nsHTMLTableElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::frame) {

Просмотреть файл

@ -524,7 +524,7 @@ nsHTMLTableRowElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::valign) {

Просмотреть файл

@ -246,7 +246,7 @@ nsHTMLTableSectionElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::bgcolor) {
nsGenericHTMLElement::ParseColor(aValue, aResult);
nsGenericHTMLElement::ParseColor(aValue, mInner.mDocument, aResult);
return NS_CONTENT_ATTR_HAS_VALUE;
}
else if (aAttribute == nsHTMLAtoms::valign) {