Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: Source/core/html/canvas/CanvasStyle.h

Issue 752083003: Use IDL union types for CanvasRenderingContext2D.{fill,stroke}Style (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 25 matching lines...) Expand all
36 namespace blink { 36 namespace blink {
37 37
38 class CanvasGradient; 38 class CanvasGradient;
39 class CanvasPattern; 39 class CanvasPattern;
40 class GraphicsContext; 40 class GraphicsContext;
41 class HTMLCanvasElement; 41 class HTMLCanvasElement;
42 42
43 class CanvasStyle final : public RefCountedWillBeGarbageCollected<CanvasStyl e> { 43 class CanvasStyle final : public RefCountedWillBeGarbageCollected<CanvasStyl e> {
44 public: 44 public:
45 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromRGBA(RGBA32 rgba) { return adoptRefWillBeNoop(new CanvasStyle(rgba)); } 45 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromRGBA(RGBA32 rgba) { return adoptRefWillBeNoop(new CanvasStyle(rgba)); }
46 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromString(const String & color);
47 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromStringWithOverrideA lpha(const String& color, float alpha);
48 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromGrayLevelWithAlpha( float grayLevel, float alpha) { return adoptRefWillBeNoop(new CanvasStyle(grayLe vel, alpha)); }
49 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromRGBAChannels(float r, float g, float b, float a) { return adoptRefWillBeNoop(new CanvasStyle(r, g, b, 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)); }
51 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromGradient(PassRefPtr WillBeRawPtr<CanvasGradient>); 46 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromGradient(PassRefPtr WillBeRawPtr<CanvasGradient>);
52 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromPattern(PassRefPtrW illBeRawPtr<CanvasPattern>); 47 static PassRefPtrWillBeRawPtr<CanvasStyle> createFromPattern(PassRefPtrW illBeRawPtr<CanvasPattern>);
53 48
54 bool isCurrentColor() const { return m_type == CurrentColor || m_type == CurrentColorWithOverrideAlpha; } 49 String color() const { ASSERT(m_type == ColorRGBA); return Color(m_rgba) .serialized(); }
55 bool hasOverrideAlpha() const { return m_type == CurrentColorWithOverrid eAlpha; }
56 float overrideAlpha() const { ASSERT(m_type == CurrentColorWithOverrideA lpha); return m_overrideAlpha; }
57
58 String color() const { ASSERT(m_type == RGBA || m_type == CMYKA); return Color(m_rgba).serialized(); }
59 CanvasGradient* canvasGradient() const { return m_gradient.get(); } 50 CanvasGradient* canvasGradient() const { return m_gradient.get(); }
60 CanvasPattern* canvasPattern() const { return m_pattern.get(); } 51 CanvasPattern* canvasPattern() const { return m_pattern.get(); }
61 52
62 void applyFillColor(GraphicsContext*); 53 void applyFillColor(GraphicsContext*);
63 void applyStrokeColor(GraphicsContext*); 54 void applyStrokeColor(GraphicsContext*);
64 55
65 bool isEquivalentColor(const CanvasStyle&) const; 56 bool isEquivalentRGBA(RGBA32 rgba) const { return m_type == ColorRGBA && m_rgba == rgba; }
66 bool isEquivalentRGBA(float r, float g, float b, float a) const;
67 bool isEquivalentCMYKA(float c, float m, float y, float k, float a) cons t;
68 57
69 void trace(Visitor*); 58 void trace(Visitor*);
70 59
71 private: 60 private:
72 enum Type { RGBA, CMYKA, Gradient, ImagePattern, CurrentColor, CurrentCo lorWithOverrideAlpha }; 61 enum Type { ColorRGBA, Gradient, ImagePattern };
fs 2014/11/24 13:20:24 Renamed this to make presubmit happy.
73 62
74 CanvasStyle(Type, float overrideAlpha = 0);
75 CanvasStyle(RGBA32 rgba); 63 CanvasStyle(RGBA32 rgba);
76 CanvasStyle(float grayLevel, float alpha);
77 CanvasStyle(float r, float g, float b, float a);
78 CanvasStyle(float c, float m, float y, float k, float a);
79 CanvasStyle(PassRefPtrWillBeRawPtr<CanvasGradient>); 64 CanvasStyle(PassRefPtrWillBeRawPtr<CanvasGradient>);
80 CanvasStyle(PassRefPtrWillBeRawPtr<CanvasPattern>); 65 CanvasStyle(PassRefPtrWillBeRawPtr<CanvasPattern>);
81 66
82 Type m_type; 67 Type m_type;
83 68 RGBA32 m_rgba;
84 union {
85 RGBA32 m_rgba;
86 float m_overrideAlpha;
87 };
88 69
89 RefPtrWillBeMember<CanvasGradient> m_gradient; 70 RefPtrWillBeMember<CanvasGradient> m_gradient;
90 RefPtrWillBeMember<CanvasPattern> m_pattern; 71 RefPtrWillBeMember<CanvasPattern> m_pattern;
91
92 struct CMYKAValues {
93 CMYKAValues() : c(0), m(0), y(0), k(0), a(0) { }
94 CMYKAValues(float cyan, float magenta, float yellow, float black, fl oat alpha) : c(cyan), m(magenta), y(yellow), k(black), a(alpha) { }
95 float c;
96 float m;
97 float y;
98 float k;
99 float a;
100 } m_cmyka;
101 }; 72 };
102 73
103 RGBA32 currentColor(HTMLCanvasElement*);
104 bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString , HTMLCanvasElement*); 74 bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString , HTMLCanvasElement*);
105 75
106 } // namespace blink 76 } // namespace blink
107 77
108 #endif 78 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698