Changeset 6730 in webkit
- Timestamp:
- May 28, 2004, 2:40:42 PM (21 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog-2005-08-23
r6728 r6730 1 2004-05-28 Richard Williamson <rjw@apple.com> 2 3 setStrokeColor and setFillColor now support 4 old school web color string, oswcs+alpha, gray, gray+alpha, 5 rgba, and cmyka. 6 7 Reviewed by jay-lo. 8 9 * khtml/css/cssparser.cpp: 10 (CSSParser::parseColor): 11 (CSSParser::parseColorFromValue): 12 * khtml/css/cssparser.h: Made parseColor static public class method 13 * khtml/ecma/kjs_html.cpp: 14 (KJS::Context2DFunction::tryCall): 15 1 16 2004-05-28 David Hyatt <hyatt@apple.com> 2 17 -
trunk/WebCore/khtml/css/cssparser.cpp
r6728 r6730 1663 1663 1664 1664 1665 static boolparseColor(const QString &name, QRgb& rgb)1665 bool CSSParser::parseColor(const QString &name, QRgb& rgb) 1666 1666 { 1667 1667 int len = name.length(); … … 1715 1715 QString str; 1716 1716 str.sprintf( "%06d", (int)(value->fValue+.5) ); 1717 if (! ::parseColor( str, c ))1717 if (!CSSParser::parseColor( str, c )) 1718 1718 return 0; 1719 1719 } else if ( value->unit == CSSPrimitiveValue::CSS_RGBCOLOR || 1720 1720 value->unit == CSSPrimitiveValue::CSS_IDENT || 1721 1721 value->unit == CSSPrimitiveValue::CSS_DIMENSION ) { 1722 if (! ::parseColor( qString( value->string ), c))1722 if (!CSSParser::parseColor( qString( value->string ), c)) 1723 1723 return 0; 1724 1724 } -
trunk/WebCore/khtml/css/cssparser.h
r6037 r6730 25 25 26 26 #include <qstring.h> 27 #include <qcolor.h> 27 28 #include <dom/dom_string.h> 28 29 #include "xml/dom_atomicstring.h" … … 132 133 CSSPrimitiveValueImpl *parseColorFromValue(Value* val); 133 134 135 static bool parseColor(const QString &name, QRgb& rgb); 136 134 137 // CSS3 Parsing Routines (for properties specific to CSS3) 135 138 bool parseShadow(int propId, bool important); -
trunk/WebCore/khtml/ecma/kjs_html.cpp
r6727 r6730 52 52 53 53 #include <kdebug.h> 54 55 #include "cssparser.h" 54 56 55 57 #include "qcolor.h" … … 3385 3387 } 3386 3388 case Context2D::SetStrokeColor: { 3387 if (args.size() < 1 || args.size() > 2) { 3388 Object err = Error::create(exec,SyntaxError); 3389 exec->setException(err); 3390 return err; 3389 // string arg = named color 3390 // string arg, number arg = named color, alpha 3391 // number arg = gray color 3392 // number arg, number arg = gray color, alpha 3393 // 4 args (string or number) = r, g, b, a 3394 // 5 args (string or number) = c, m, y, k, a 3395 int numArgs = args.size(); 3396 switch (numArgs) { 3397 case 1: { 3398 if (args[0].type() == StringType) { 3399 QRgb rgb = 0; 3400 DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb); 3401 QColor color(rgb); 3402 CGContextSetRGBStrokeColor(drawingContext, color.red(), color.green(), color.blue(), 1.); 3403 } 3404 else { 3405 float g = (float)args[0].toNumber(exec); 3406 CGContextSetGrayStrokeColor(drawingContext, g, 1.); 3407 } 3408 } 3409 break; 3410 case 2: { 3411 float a = args[1].toNumber(exec); 3412 if (args[0].type() == StringType) { 3413 QRgb rgb = 0; 3414 DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb); 3415 QColor color(rgb); 3416 CGContextSetRGBStrokeColor(drawingContext, color.red(), color.green(), color.blue(), a); 3417 } 3418 else { 3419 float g = (float)args[0].toNumber(exec); 3420 CGContextSetGrayStrokeColor(drawingContext, g, a); 3421 } 3422 } 3423 break; 3424 case 4: { 3425 float r = (float)args[0].toNumber(exec); 3426 float g = (float)args[1].toNumber(exec); 3427 float b = (float)args[2].toNumber(exec); 3428 float a = (float)args[3].toNumber(exec); 3429 CGContextSetRGBStrokeColor(drawingContext, r, g, b, a); 3430 } 3431 break; 3432 case 5: { 3433 float c = (float)args[0].toNumber(exec); 3434 float m = (float)args[1].toNumber(exec); 3435 float y = (float)args[2].toNumber(exec); 3436 float k = (float)args[3].toNumber(exec); 3437 float a = (float)args[4].toNumber(exec); 3438 CGContextSetCMYKStrokeColor(drawingContext, c, m, y, k, a); 3439 } 3440 default: { 3441 Object err = Error::create(exec,SyntaxError); 3442 exec->setException(err); 3443 return err; 3444 } 3391 3445 } 3392 QColor color;3393 if (args.size() > 0)3394 color = QColor(args[0].toString(exec).ascii());3395 float alpha;3396 if (args.size() > 1)3397 alpha = (float)args[1].toNumber(exec);3398 else3399 alpha = 1.;3400 CGContextSetRGBStrokeColor(drawingContext, color.red(), color.green(), color.blue(), alpha);3401 3446 break; 3402 3447 } 3403 3448 case Context2D::SetFillColor: { 3404 if (args.size() < 1 || args.size() > 2) { 3405 Object err = Error::create(exec,SyntaxError); 3406 exec->setException(err); 3407 return err; 3449 // string arg = named color 3450 // string arg, number arg = named color, alpha 3451 // number arg = gray color 3452 // number arg, number arg = gray color, alpha 3453 // 4 args (string or number) = r, g, b, a 3454 // 5 args (string or number) = c, m, y, k, a 3455 int numArgs = args.size(); 3456 switch (numArgs) { 3457 case 1: { 3458 if (args[0].type() == StringType) { 3459 QRgb rgb = 0; 3460 DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb); 3461 QColor color(rgb); 3462 CGContextSetRGBFillColor(drawingContext, color.red(), color.green(), color.blue(), 1.); 3463 } 3464 else { 3465 float g = (float)args[0].toNumber(exec); 3466 CGContextSetGrayFillColor(drawingContext, g, 1.); 3467 } 3468 } 3469 break; 3470 case 2: { 3471 float a = args[1].toNumber(exec); 3472 if (args[0].type() == StringType) { 3473 QRgb rgb = 0; 3474 DOM::CSSParser::parseColor(args[0].toString(exec).qstring(), rgb); 3475 QColor color(rgb); 3476 CGContextSetRGBFillColor(drawingContext, color.red(), color.green(), color.blue(), a); 3477 } 3478 else { 3479 float g = (float)args[0].toNumber(exec); 3480 CGContextSetGrayFillColor(drawingContext, g, a); 3481 } 3482 } 3483 break; 3484 case 4: { 3485 float r = (float)args[0].toNumber(exec); 3486 float g = (float)args[1].toNumber(exec); 3487 float b = (float)args[2].toNumber(exec); 3488 float a = (float)args[3].toNumber(exec); 3489 CGContextSetRGBFillColor(drawingContext, r, g, b, a); 3490 } 3491 break; 3492 case 5: { 3493 float c = (float)args[0].toNumber(exec); 3494 float m = (float)args[1].toNumber(exec); 3495 float y = (float)args[2].toNumber(exec); 3496 float k = (float)args[3].toNumber(exec); 3497 float a = (float)args[4].toNumber(exec); 3498 CGContextSetCMYKStrokeColor(drawingContext, c, m, y, k, a); 3499 } 3500 default: { 3501 Object err = Error::create(exec,SyntaxError); 3502 exec->setException(err); 3503 return err; 3504 } 3408 3505 } 3409 QColor color;3410 if (args.size() > 0)3411 color = QColor(args[0].toString(exec).ascii());3412 float alpha;3413 if (args.size() > 1)3414 alpha = (float)args[1].toNumber(exec);3415 else3416 alpha = 1.;3417 CGContextSetRGBFillColor(drawingContext, color.red(), color.green(), color.blue(), alpha);3418 3506 break; 3419 3507 }
Note:
See TracChangeset
for help on using the changeset viewer.