Color handling with the new CSS parser

Lars Knoll khtml-devel@kde.org
Mon, 24 Feb 2003 08:13:00 +0100


--Boundary-00=_8XcW+KjYvk4ZRVQ
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


> So I could refine the patch to parseColor that I sent out to only check
> for NUMBER/DIMENSIOn in quirks mode.

Yes. The attached patch should do this correctly.

Cheers,
Lars


>
> dave
>
> On Friday, February 21, 2003, at 12:51 PM, Dirk Mueller wrote:
> > However, in fact Mozilla parses above as color in compat parsing mode
> > (however not in transitional or strict).
> >
> > --
> > Dirk (received 776 mails today)
> > _______________________________________________
> > Khtml-devel@mail.kde.org
> > http://mail.kde.org/mailman/listinfo/khtml-devel
>
> _______________________________________________
> Khtml-devel@mail.kde.org
> http://mail.kde.org/mailman/listinfo/khtml-devel

--Boundary-00=_8XcW+KjYvk4ZRVQ
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="cssparser.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cssparser.diff"

Index: cssparser.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/css/cssparser.cpp,v
retrieving revision 1.259
diff -u -b -p -r1.259 cssparser.cpp
--- cssparser.cpp	21 Feb 2003 15:28:37 -0000	1.259
+++ cssparser.cpp	24 Feb 2003 07:18:20 -0000
@@ -1492,8 +1492,15 @@ CSSPrimitiveValueImpl *CSSParser::parseC
     QRgb c = khtml::invalidColor;
     Value *value = valueList->current();
     if ( value->unit == CSSPrimitiveValue::CSS_RGBCOLOR ||
-         value->unit == CSSPrimitiveValue::CSS_IDENT )
+         value->unit == CSSPrimitiveValue::CSS_IDENT ||
+	 (!strict && value->unit == CSSPrimitiveValue::CSS_DIMENSION ) )
 	c = ::parseColor( qString( value->string ));
+    else if ( !strict && value->unit == CSSPrimitiveValue::CSS_NUMBER &&
+	      value->fValue >= 0. && value->fValue < 1000000. ) {
+	QString str;
+	str.sprintf( "%06d", (int)(value->fValue+.5) );
+	c = ::parseColor( str );
+    }
     else if ( value->unit == Value::Function &&
 		value->function->args->numValues == 5 /* rgb + two commas */ &&
 		qString( value->function->name ).lower() == "rgb(" ) {

--Boundary-00=_8XcW+KjYvk4ZRVQ--