Skip to content

Commit

Permalink
Refactor Color.FromKeyword.
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianLettner committed Aug 24, 2015
1 parent 5e84780 commit 56427f8
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/dotless.Core/Parser/Tree/Color.cs
Expand Up @@ -188,24 +188,17 @@ public static Color From(string keywordOrHex)
return FromKeyword(keywordOrHex) ?? FromHex(keywordOrHex);
}

// TODO(yln): Dictionary should be instance of Color, color should be immutable!
public static Color FromKeyword(string keyword)
{
if (keyword == "transparent")
{
return new Color(0, 0, 0, 0);
return new Color(0x000, 0.0, keyword);
}

int color;
if (Html4Colors.TryGetValue(keyword, out color))
int hex;
if (Html4Colors.TryGetValue(keyword, out hex))
{
var b = color & 0xff;
color >>= 8;
var g = color & 0xff;
color >>= 8;
var r = color & 0xff;

return new Color(r, g, b);
return new Color(hex, 1.0, keyword);
}

return null;
Expand Down

0 comments on commit 56427f8

Please sign in to comment.