OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "core/html/HTMLCanvasElement.h" | 35 #include "core/html/HTMLCanvasElement.h" |
36 #include "core/html/canvas/CanvasGradient.h" | 36 #include "core/html/canvas/CanvasGradient.h" |
37 #include "core/html/canvas/CanvasPattern.h" | 37 #include "core/html/canvas/CanvasPattern.h" |
38 #include "platform/graphics/GraphicsContext.h" | 38 #include "platform/graphics/GraphicsContext.h" |
39 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
40 | 40 |
41 namespace WebCore { | 41 namespace WebCore { |
42 | 42 |
43 enum ColorParseResult { ParsedRGBA, ParsedCurrentColor, ParsedSystemColor, Parse
Failed }; | 43 enum ColorParseResult { ParsedRGBA, ParsedCurrentColor, ParsedSystemColor, Parse
Failed }; |
44 | 44 |
45 static ColorParseResult parseColor(RGBA32& parsedColor, const String& colorStrin
g, Document* document = 0) | 45 static ColorParseResult parseColor(RGBA32& parsedColor, const String& colorStrin
g) |
46 { | 46 { |
47 if (equalIgnoringCase(colorString, "currentcolor")) | 47 if (equalIgnoringCase(colorString, "currentcolor")) |
48 return ParsedCurrentColor; | 48 return ParsedCurrentColor; |
49 if (BisonCSSParser::parseColor(parsedColor, colorString)) | 49 if (BisonCSSParser::parseColor(parsedColor, colorString)) |
50 return ParsedRGBA; | 50 return ParsedRGBA; |
51 if (BisonCSSParser::parseSystemColor(parsedColor, colorString, document)) | 51 if (BisonCSSParser::parseSystemColor(parsedColor, colorString)) |
52 return ParsedSystemColor; | 52 return ParsedSystemColor; |
53 return ParseFailed; | 53 return ParseFailed; |
54 } | 54 } |
55 | 55 |
56 RGBA32 currentColor(HTMLCanvasElement* canvas) | 56 RGBA32 currentColor(HTMLCanvasElement* canvas) |
57 { | 57 { |
58 if (!canvas || !canvas->inDocument() || !canvas->inlineStyle()) | 58 if (!canvas || !canvas->inDocument() || !canvas->inlineStyle()) |
59 return Color::black; | 59 return Color::black; |
60 RGBA32 rgba = Color::black; | 60 RGBA32 rgba = Color::black; |
61 BisonCSSParser::parseColor(rgba, canvas->inlineStyle()->getPropertyValue(CSS
PropertyColor)); | 61 BisonCSSParser::parseColor(rgba, canvas->inlineStyle()->getPropertyValue(CSS
PropertyColor)); |
62 return rgba; | 62 return rgba; |
63 } | 63 } |
64 | 64 |
65 bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HT
MLCanvasElement* canvas) | 65 bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HT
MLCanvasElement* canvas) |
66 { | 66 { |
67 ColorParseResult parseResult = parseColor(parsedColor, colorString, canvas ?
&canvas->document() : 0); | 67 ColorParseResult parseResult = parseColor(parsedColor, colorString); |
68 switch (parseResult) { | 68 switch (parseResult) { |
69 case ParsedRGBA: | 69 case ParsedRGBA: |
70 case ParsedSystemColor: | 70 case ParsedSystemColor: |
71 return true; | 71 return true; |
72 case ParsedCurrentColor: | 72 case ParsedCurrentColor: |
73 parsedColor = currentColor(canvas); | 73 parsedColor = currentColor(canvas); |
74 return true; | 74 return true; |
75 case ParseFailed: | 75 case ParseFailed: |
76 return false; | 76 return false; |
77 default: | 77 default: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 , m_gradient(gradient) | 116 , m_gradient(gradient) |
117 { | 117 { |
118 } | 118 } |
119 | 119 |
120 CanvasStyle::CanvasStyle(PassRefPtr<CanvasPattern> pattern) | 120 CanvasStyle::CanvasStyle(PassRefPtr<CanvasPattern> pattern) |
121 : m_type(ImagePattern) | 121 : m_type(ImagePattern) |
122 , m_pattern(pattern) | 122 , m_pattern(pattern) |
123 { | 123 { |
124 } | 124 } |
125 | 125 |
126 PassRefPtr<CanvasStyle> CanvasStyle::createFromString(const String& color, Docum
ent* document) | 126 PassRefPtr<CanvasStyle> CanvasStyle::createFromString(const String& color) |
127 { | 127 { |
128 RGBA32 rgba; | 128 RGBA32 rgba; |
129 ColorParseResult parseResult = parseColor(rgba, color, document); | 129 ColorParseResult parseResult = parseColor(rgba, color); |
130 switch (parseResult) { | 130 switch (parseResult) { |
131 case ParsedRGBA: | 131 case ParsedRGBA: |
132 case ParsedSystemColor: | 132 case ParsedSystemColor: |
133 return adoptRef(new CanvasStyle(rgba)); | 133 return adoptRef(new CanvasStyle(rgba)); |
134 case ParsedCurrentColor: | 134 case ParsedCurrentColor: |
135 return adoptRef(new CanvasStyle(CurrentColor)); | 135 return adoptRef(new CanvasStyle(CurrentColor)); |
136 case ParseFailed: | 136 case ParseFailed: |
137 return nullptr; | 137 return nullptr; |
138 default: | 138 default: |
139 ASSERT_NOT_REACHED(); | 139 ASSERT_NOT_REACHED(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 context->setFillPattern(canvasPattern()->pattern()); | 265 context->setFillPattern(canvasPattern()->pattern()); |
266 break; | 266 break; |
267 case CurrentColor: | 267 case CurrentColor: |
268 case CurrentColorWithOverrideAlpha: | 268 case CurrentColorWithOverrideAlpha: |
269 ASSERT_NOT_REACHED(); | 269 ASSERT_NOT_REACHED(); |
270 break; | 270 break; |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 } | 274 } |
OLD | NEW |