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 17 matching lines...) Expand all Loading... |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "core/html/canvas/CanvasStyle.h" | 30 #include "core/html/canvas/CanvasStyle.h" |
31 | 31 |
32 #include "core/CSSPropertyNames.h" | 32 #include "core/CSSPropertyNames.h" |
33 #include "core/css/StylePropertySet.h" | 33 #include "core/css/StylePropertySet.h" |
34 #include "core/css/parser/CSSParser.h" | 34 #include "core/css/parser/CSSParser.h" |
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" | |
39 #include "wtf/PassRefPtr.h" | 38 #include "wtf/PassRefPtr.h" |
40 | 39 |
41 namespace blink { | 40 namespace blink { |
42 | 41 |
43 enum ColorParseResult { ParsedRGBA, ParsedCurrentColor, ParsedSystemColor, Parse
Failed }; | 42 enum ColorParseResult { ParsedRGBA, ParsedCurrentColor, ParsedSystemColor, Parse
Failed }; |
44 | 43 |
45 static ColorParseResult parseColor(RGBA32& parsedColor, const String& colorStrin
g) | 44 static ColorParseResult parseColor(RGBA32& parsedColor, const String& colorStrin
g) |
46 { | 45 { |
47 if (equalIgnoringCase(colorString, "currentcolor")) | 46 if (equalIgnoringCase(colorString, "currentcolor")) |
48 return ParsedCurrentColor; | 47 return ParsedCurrentColor; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 ASSERT(gradient); | 103 ASSERT(gradient); |
105 return adoptRefWillBeNoop(new CanvasStyle(gradient)); | 104 return adoptRefWillBeNoop(new CanvasStyle(gradient)); |
106 } | 105 } |
107 | 106 |
108 PassRefPtrWillBeRawPtr<CanvasStyle> CanvasStyle::createFromPattern(PassRefPtrWil
lBeRawPtr<CanvasPattern> pattern) | 107 PassRefPtrWillBeRawPtr<CanvasStyle> CanvasStyle::createFromPattern(PassRefPtrWil
lBeRawPtr<CanvasPattern> pattern) |
109 { | 108 { |
110 ASSERT(pattern); | 109 ASSERT(pattern); |
111 return adoptRefWillBeNoop(new CanvasStyle(pattern)); | 110 return adoptRefWillBeNoop(new CanvasStyle(pattern)); |
112 } | 111 } |
113 | 112 |
114 void CanvasStyle::applyStrokeColor(GraphicsContext* context) | |
115 { | |
116 if (!context) | |
117 return; | |
118 switch (m_type) { | |
119 case ColorRGBA: | |
120 context->setStrokeColor(m_rgba); | |
121 break; | |
122 case Gradient: | |
123 context->setStrokeGradient(canvasGradient()->gradient()); | |
124 break; | |
125 case ImagePattern: | |
126 context->setStrokePattern(canvasPattern()->pattern()); | |
127 break; | |
128 } | |
129 } | |
130 | |
131 void CanvasStyle::applyFillColor(GraphicsContext* context) | |
132 { | |
133 if (!context) | |
134 return; | |
135 switch (m_type) { | |
136 case ColorRGBA: | |
137 context->setFillColor(m_rgba); | |
138 break; | |
139 case Gradient: | |
140 context->setFillGradient(canvasGradient()->gradient()); | |
141 break; | |
142 case ImagePattern: | |
143 context->setFillPattern(canvasPattern()->pattern()); | |
144 break; | |
145 } | |
146 } | |
147 | |
148 SkShader* CanvasStyle::shader() const | 113 SkShader* CanvasStyle::shader() const |
149 { | 114 { |
150 switch (m_type) { | 115 switch (m_type) { |
151 case ColorRGBA: | 116 case ColorRGBA: |
152 return nullptr; | 117 return nullptr; |
153 case Gradient: | 118 case Gradient: |
154 return canvasGradient()->gradient()->shader(); | 119 return canvasGradient()->gradient()->shader(); |
155 case ImagePattern: | 120 case ImagePattern: |
156 return canvasPattern()->pattern()->shader(); | 121 return canvasPattern()->pattern()->shader(); |
157 default: | 122 default: |
(...skipping 10 matching lines...) Expand all Loading... |
168 return Color::black; | 133 return Color::black; |
169 } | 134 } |
170 | 135 |
171 DEFINE_TRACE(CanvasStyle) | 136 DEFINE_TRACE(CanvasStyle) |
172 { | 137 { |
173 visitor->trace(m_gradient); | 138 visitor->trace(m_gradient); |
174 visitor->trace(m_pattern); | 139 visitor->trace(m_pattern); |
175 } | 140 } |
176 | 141 |
177 } | 142 } |
OLD | NEW |