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) 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 10 matching lines...) Expand all Loading... |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #ifndef CanvasStyle_h | 27 #ifndef CanvasStyle_h |
28 #define CanvasStyle_h | 28 #define CanvasStyle_h |
29 | 29 |
30 #include "platform/graphics/Color.h" | 30 #include "platform/graphics/Color.h" |
| 31 #include "platform/heap/Handle.h" |
31 #include "wtf/Assertions.h" | 32 #include "wtf/Assertions.h" |
32 #include "wtf/RefCounted.h" | 33 #include "wtf/RefCounted.h" |
33 #include "wtf/text/WTFString.h" | 34 #include "wtf/text/WTFString.h" |
34 | 35 |
35 namespace WebCore { | 36 namespace WebCore { |
36 | 37 |
37 class CanvasGradient; | 38 class CanvasGradient; |
38 class CanvasPattern; | 39 class CanvasPattern; |
39 class GraphicsContext; | 40 class GraphicsContext; |
40 class HTMLCanvasElement; | 41 class HTMLCanvasElement; |
41 | 42 |
42 class CanvasStyle : public RefCounted<CanvasStyle> { | 43 class CanvasStyle FINAL : public RefCountedWillBeGarbageCollected<CanvasStyl
e> { |
43 public: | 44 public: |
44 static PassRefPtr<CanvasStyle> createFromRGBA(RGBA32 rgba) { return adop
tRef(new CanvasStyle(rgba)); } | 45 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromRGBA(RGBA32 rgba) {
return adoptRefWillBeNoop(new CanvasStyle(rgba)); } |
45 static PassRefPtr<CanvasStyle> createFromString(const String& color); | 46 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromString(const String
& color); |
46 static PassRefPtr<CanvasStyle> createFromStringWithOverrideAlpha(const S
tring& color, float alpha); | 47 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromStringWithOverrideA
lpha(const String& color, float alpha); |
47 static PassRefPtr<CanvasStyle> createFromGrayLevelWithAlpha(float grayLe
vel, float alpha) { return adoptRef(new CanvasStyle(grayLevel, alpha)); } | 48 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromGrayLevelWithAlpha(
float grayLevel, float alpha) { return adoptRefWillBeNoop(new CanvasStyle(grayLe
vel, alpha)); } |
48 static PassRefPtr<CanvasStyle> createFromRGBAChannels(float r, float g,
float b, float a) { return adoptRef(new CanvasStyle(r, g, b, a)); } | 49 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromRGBAChannels(float
r, float g, float b, float a) { return adoptRefWillBeNoop(new CanvasStyle(r, g,
b, a)); } |
49 static PassRefPtr<CanvasStyle> createFromCMYKAChannels(float c, float m,
float y, float k, float a) { return adoptRef(new CanvasStyle(c, m, y, k, a)); } | 50 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromCMYKAChannels(float
c, float m, float y, float k, float a) { return adoptRefWillBeNoop(new CanvasSt
yle(c, m, y, k, a)); } |
50 static PassRefPtr<CanvasStyle> createFromGradient(PassRefPtr<CanvasGradi
ent>); | 51 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromGradient(PassRefPtr
WillBeRawPtr<CanvasGradient>); |
51 static PassRefPtr<CanvasStyle> createFromPattern(PassRefPtr<CanvasPatter
n>); | 52 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromPattern(PassRefPtrW
illBeRawPtr<CanvasPattern>); |
52 | 53 |
53 bool isCurrentColor() const { return m_type == CurrentColor || m_type ==
CurrentColorWithOverrideAlpha; } | 54 bool isCurrentColor() const { return m_type == CurrentColor || m_type ==
CurrentColorWithOverrideAlpha; } |
54 bool hasOverrideAlpha() const { return m_type == CurrentColorWithOverrid
eAlpha; } | 55 bool hasOverrideAlpha() const { return m_type == CurrentColorWithOverrid
eAlpha; } |
55 float overrideAlpha() const { ASSERT(m_type == CurrentColorWithOverrideA
lpha); return m_overrideAlpha; } | 56 float overrideAlpha() const { ASSERT(m_type == CurrentColorWithOverrideA
lpha); return m_overrideAlpha; } |
56 | 57 |
57 String color() const { ASSERT(m_type == RGBA || m_type == CMYKA); return
Color(m_rgba).serialized(); } | 58 String color() const { ASSERT(m_type == RGBA || m_type == CMYKA); return
Color(m_rgba).serialized(); } |
58 CanvasGradient* canvasGradient() const { return m_gradient.get(); } | 59 CanvasGradient* canvasGradient() const { return m_gradient.get(); } |
59 CanvasPattern* canvasPattern() const { return m_pattern.get(); } | 60 CanvasPattern* canvasPattern() const { return m_pattern.get(); } |
60 | 61 |
61 void applyFillColor(GraphicsContext*); | 62 void applyFillColor(GraphicsContext*); |
62 void applyStrokeColor(GraphicsContext*); | 63 void applyStrokeColor(GraphicsContext*); |
63 | 64 |
64 bool isEquivalentColor(const CanvasStyle&) const; | 65 bool isEquivalentColor(const CanvasStyle&) const; |
65 bool isEquivalentRGBA(float r, float g, float b, float a) const; | 66 bool isEquivalentRGBA(float r, float g, float b, float a) const; |
66 bool isEquivalentCMYKA(float c, float m, float y, float k, float a) cons
t; | 67 bool isEquivalentCMYKA(float c, float m, float y, float k, float a) cons
t; |
67 | 68 |
| 69 void trace(Visitor*); |
| 70 |
68 private: | 71 private: |
69 enum Type { RGBA, CMYKA, Gradient, ImagePattern, CurrentColor, CurrentCo
lorWithOverrideAlpha }; | 72 enum Type { RGBA, CMYKA, Gradient, ImagePattern, CurrentColor, CurrentCo
lorWithOverrideAlpha }; |
70 | 73 |
71 CanvasStyle(Type, float overrideAlpha = 0); | 74 CanvasStyle(Type, float overrideAlpha = 0); |
72 CanvasStyle(RGBA32 rgba); | 75 CanvasStyle(RGBA32 rgba); |
73 CanvasStyle(float grayLevel, float alpha); | 76 CanvasStyle(float grayLevel, float alpha); |
74 CanvasStyle(float r, float g, float b, float a); | 77 CanvasStyle(float r, float g, float b, float a); |
75 CanvasStyle(float c, float m, float y, float k, float a); | 78 CanvasStyle(float c, float m, float y, float k, float a); |
76 CanvasStyle(PassRefPtr<CanvasGradient>); | 79 CanvasStyle(PassRefPtrWillBeRawPtr<CanvasGradient>); |
77 CanvasStyle(PassRefPtr<CanvasPattern>); | 80 CanvasStyle(PassRefPtrWillBeRawPtr<CanvasPattern>); |
78 | 81 |
79 Type m_type; | 82 Type m_type; |
80 | 83 |
81 union { | 84 union { |
82 RGBA32 m_rgba; | 85 RGBA32 m_rgba; |
83 float m_overrideAlpha; | 86 float m_overrideAlpha; |
84 }; | 87 }; |
85 | 88 |
86 RefPtr<CanvasGradient> m_gradient; | 89 RefPtrWillBeMember<CanvasGradient> m_gradient; |
87 RefPtr<CanvasPattern> m_pattern; | 90 RefPtrWillBeMember<CanvasPattern> m_pattern; |
88 | 91 |
89 struct CMYKAValues { | 92 struct CMYKAValues { |
90 CMYKAValues() : c(0), m(0), y(0), k(0), a(0) { } | 93 CMYKAValues() : c(0), m(0), y(0), k(0), a(0) { } |
91 CMYKAValues(float cyan, float magenta, float yellow, float black, fl
oat alpha) : c(cyan), m(magenta), y(yellow), k(black), a(alpha) { } | 94 CMYKAValues(float cyan, float magenta, float yellow, float black, fl
oat alpha) : c(cyan), m(magenta), y(yellow), k(black), a(alpha) { } |
92 float c; | 95 float c; |
93 float m; | 96 float m; |
94 float y; | 97 float y; |
95 float k; | 98 float k; |
96 float a; | 99 float a; |
97 } m_cmyka; | 100 } m_cmyka; |
98 }; | 101 }; |
99 | 102 |
100 RGBA32 currentColor(HTMLCanvasElement*); | 103 RGBA32 currentColor(HTMLCanvasElement*); |
101 bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString
, HTMLCanvasElement*); | 104 bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString
, HTMLCanvasElement*); |
102 | 105 |
103 } // namespace WebCore | 106 } // namespace WebCore |
104 | 107 |
105 #endif | 108 #endif |
OLD | NEW |