From ff7f469f9f2a3fc72c2c17986ddfa80639cbebf6 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sun, 10 Apr 2011 22:16:28 -0400 Subject: [PATCH] Fixed: CPColor colorWithCSSString did not properly handle the alpha component of the CSS rbga() syntax. Fixes #687. --- AppKit/CPColor.j | 2 +- Tests/AppKit/CPColorTest.j | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/AppKit/CPColor.j b/AppKit/CPColor.j index b83f528b7..236af96ee 100644 --- a/AppKit/CPColor.j +++ b/AppKit/CPColor.j @@ -416,7 +416,7 @@ var cachedBlackColor, parseInt(parts[0], 10) / 255.0, parseInt(parts[1], 10) / 255.0, parseInt(parts[2], 10) / 255.0, - parts[3] ? parseInt(parts[3], 10) / 255.0 : 1.0 + parts[3] ? parseFloat(parts[3], 10) : 1.0 ]; _cssString = aString; diff --git a/Tests/AppKit/CPColorTest.j b/Tests/AppKit/CPColorTest.j index f5768a46a..c7603960e 100644 --- a/Tests/AppKit/CPColorTest.j +++ b/Tests/AppKit/CPColorTest.j @@ -11,4 +11,14 @@ [self assert: colors[i] equals: [[CPColor colorWithHexString: colors[i]] hexString]]; } +- (void)testColorWithCSSString +{ + var rgbaColour = [CPColor colorWithCSSString:@"rgba(32, 64, 128, 0.5)"]; + + [self assert:32 equals:Math.round([rgbaColour redComponent] * 255) message:"red component"]; + [self assert:64 equals:Math.round([rgbaColour greenComponent] * 255) message:"green component"]; + [self assert:128 equals:Math.round([rgbaColour blueComponent] * 255) message:"blue component"]; + [self assert:128 equals:Math.round([rgbaColour alphaComponent] * 255) message:"alpha component"]; +} + @end