Changeset 59768 in webkit
- Timestamp:
- May 19, 2010 9:11:08 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r59767 r59768 1 2010-05-19 Andreas Kling <andreas.kling@nokia.com> 2 3 Reviewed by Darin Adler. 4 5 Added a test to verify proper color serialization in CanvasRenderingContext2D's getters. 6 https://bugs.webkit.org/show_bug.cgi?id=38845 7 8 Spec link: 9 http://www.whatwg.org/specs/web-apps/current-work/#serialization-of-a-color 10 11 * fast/canvas/canvas-color-serialization-expected.txt: Added. 12 * fast/canvas/canvas-color-serialization.html: Added. 13 * fast/canvas/canvas-set-properties-with-non-invertible-ctm-expected.txt: Updated baseline. 14 * fast/canvas/script-tests/canvas-color-serialization.js: Added. 15 (trySettingStrokeStyle): 16 (trySettingFillStyle): 17 (trySettingShadowColor): 18 (trySettingColor): 19 (trySettingStrokeColorWithSetter): 20 (trySettingFillColorWithSetter): 21 (trySettingShadowWithSetter): 22 (trySettingColorWithSetter): 23 (trySettingFillColorRGBA): 24 (trySettingStrokeColorRGBA): 25 (trySettingShadowRGBA): 26 (trySettingRGBA): 27 (trySettingFillColorCMYKA): 28 (trySettingStrokeColorCMYKA): 29 (trySettingShadowCMYKA): 30 (trySettingCMYKA): 31 (trySettingFillColorWithOverrideAlpha): 32 (trySettingStrokeColorWithOverrideAlpha): 33 (trySettingShadowWithOverrideAlpha): 34 (trySettingColorWithOverrideAlpha): 35 (trySettingFillColorGrayLevel): 36 (trySettingStrokeColorGrayLevel): 37 (trySettingShadowGrayLevel): 38 (trySettingGrayLevel): 39 (trySettingFillColorGrayLevelWithAlpha): 40 (trySettingStrokeColorGrayLevelWithAlpha): 41 (trySettingShadowGrayLevelWithAlpha): 42 (trySettingGrayLevelWithAlpha): 43 (tryClearShadowAfterSettingColor): 44 (checkDefaultValue): 45 * fast/canvas/script-tests/canvas-set-properties-with-non-invertible-ctm.js: 46 * fast/dom/canvasContext2d-element-attribute-js-null-expected.txt: Updated baseline. 47 * fast/dom/canvasContext2d-element-attribute-js-null.html: 48 1 49 2010-05-19 Andreas Kling <andreas.kling@nokia.com> 2 50 -
trunk/LayoutTests/fast/canvas/canvas-set-properties-with-non-invertible-ctm-expected.txt
r39508 r59768 4 4 5 5 6 PASS ctx.fillStyle is " green"6 PASS ctx.fillStyle is "#008000" 7 7 PASS imageData.data[0] is 0 8 8 PASS imageData.data[1] is 128 9 9 PASS imageData.data[2] is 0 10 PASS ctx.strokeStyle is " green"10 PASS ctx.strokeStyle is "#008000" 11 11 PASS imageData.data[0] is 0 12 12 PASS imageData.data[1] is 128 -
trunk/LayoutTests/fast/canvas/script-tests/canvas-set-properties-with-non-invertible-ctm.js
r48550 r59768 17 17 ctx.scale(0, 0); 18 18 ctx.fillStyle = "green"; 19 shouldBe('ctx.fillStyle', '" green"');19 shouldBe('ctx.fillStyle', '"#008000"'); 20 20 ctx.setTransform(1, 0, 0, 1, 0, 0); 21 21 ctx.fillRect(0,0,100,100); … … 29 29 ctx.scale(0, 0); 30 30 ctx.strokeStyle = "green"; 31 shouldBe('ctx.strokeStyle', '" green"');31 shouldBe('ctx.strokeStyle', '"#008000"'); 32 32 ctx.lineWidth = 100; 33 33 ctx.setTransform(1, 0, 0, 1, 0, 0); -
trunk/LayoutTests/fast/dom/canvasContext2d-element-attribute-js-null-expected.txt
r30635 r59768 4 4 TEST SUCCEEDED: The value was the string 'butt'. [tested CanvasRenderingContext2D.lineCap] 5 5 TEST SUCCEEDED: The value was the string 'miter'. [tested CanvasRenderingContext2D.lineJoin] 6 TEST SUCCEEDED: The value was the empty string. [tested CanvasRenderingContext2D.shadowColor]6 TEST SUCCEEDED: The value was the string 'rgba(0, 0, 0, 0.0)'. [tested CanvasRenderingContext2D.shadowColor] 7 7 8 8 -
trunk/LayoutTests/fast/dom/canvasContext2d-element-attribute-js-null.html
r21504 r59768 55 55 {name: 'lineCap', expectedNull: 'butt'}, 56 56 {name: 'lineJoin', expectedNull: 'miter'}, 57 {name: 'shadowColor', expectedNull: ' '}57 {name: 'shadowColor', expectedNull: 'rgba(0, 0, 0, 0.0)'} 58 58 ] 59 59 } -
trunk/WebCore/ChangeLog
r59767 r59768 1 2010-05-19 Andreas Kling <andreas.kling@nokia.com> 2 3 Reviewed by Darin Adler. 4 5 CanvasRenderingContext2D's property getters that return colors should 6 serialize them in accordance with the HTML5 spec (4.8.11.1.4) 7 Setters should ignore invalid colors. 8 9 Also, shadowColor should initially be transparent black (4.8.11.1.6) 10 11 https://bugs.webkit.org/show_bug.cgi?id=38845 12 13 Refactored CanvasStyle to store an RGBA32 instead of RGBA components and/or the color string. 14 15 Spec links: 16 http://www.whatwg.org/specs/web-apps/current-work/#serialization-of-a-color 17 http://www.whatwg.org/specs/web-apps/current-work/#dom-context-2d-shadowcolor 18 19 * html/canvas/CanvasRenderingContext2D.cpp: 20 (WebCore::CanvasRenderingContext2D::State::State): 21 (WebCore::CanvasRenderingContext2D::shadowColor): 22 (WebCore::CanvasRenderingContext2D::setShadowColor): 23 (WebCore::CanvasRenderingContext2D::setShadow): 24 (WebCore::CanvasRenderingContext2D::clearShadow): 25 (WebCore::CanvasRenderingContext2D::applyShadow): 26 * html/canvas/CanvasRenderingContext2D.h: 27 * html/canvas/CanvasStyle.cpp: 28 (WebCore::CanvasStyle::CanvasStyle): 29 (WebCore::CanvasStyle::create): 30 (WebCore::CanvasStyle::applyStrokeColor): 31 (WebCore::CanvasStyle::applyFillColor): 32 * html/canvas/CanvasStyle.h: 33 (WebCore::CanvasStyle::create): 34 (WebCore::CanvasStyle::color): 35 (WebCore::CanvasStyle::): 36 (WebCore::CanvasStyle::CMYKAValues::CMYKAValues): 37 * platform/graphics/Color.cpp: 38 (WebCore::Color::serialized): 39 * platform/graphics/Color.h: 40 1 41 2010-05-19 Andreas Kling <andreas.kling@nokia.com> 2 42 -
trunk/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r59613 r59768 1 1 /* 2 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 4 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 5 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> … … 119 119 120 120 CanvasRenderingContext2D::State::State() 121 : m_strokeStyle(CanvasStyle::create( "#000000"))122 , m_fillStyle(CanvasStyle::create( "#000000"))121 : m_strokeStyle(CanvasStyle::create(Color::black)) 122 , m_fillStyle(CanvasStyle::create(Color::black)) 123 123 , m_lineWidth(1) 124 124 , m_lineCap(ButtCap) … … 126 126 , m_miterLimit(10) 127 127 , m_shadowBlur(0) 128 , m_shadowColor( "black")128 , m_shadowColor(Color::transparent) 129 129 , m_globalAlpha(1) 130 130 , m_globalComposite(CompositeSourceOver) … … 316 316 String CanvasRenderingContext2D::shadowColor() const 317 317 { 318 // FIXME: What should this return if you called setShadow with a non-string color? 319 return state().m_shadowColor; 318 return Color(state().m_shadowColor).serialized(); 320 319 } 321 320 322 321 void CanvasRenderingContext2D::setShadowColor(const String& color) 323 322 { 324 state().m_shadowColor = color; 323 if (!CSSParser::parseColor(state().m_shadowColor, color)) 324 return; 325 325 326 applyShadow(); 326 327 } … … 815 816 state().m_shadowOffset = FloatSize(width, height); 816 817 state().m_shadowBlur = blur; 817 state().m_shadowColor = "";818 state().m_shadowColor = Color::transparent; 818 819 applyShadow(); 819 820 } … … 821 822 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color) 822 823 { 824 if (!CSSParser::parseColor(state().m_shadowColor, color)) 825 return; 826 823 827 state().m_shadowOffset = FloatSize(width, height); 824 828 state().m_shadowBlur = blur; 825 state().m_shadowColor = color;826 829 applyShadow(); 827 830 } … … 831 834 state().m_shadowOffset = FloatSize(width, height); 832 835 state().m_shadowBlur = blur; 833 state().m_shadowColor = ""; 834 835 GraphicsContext* c = drawingContext(); 836 if (!c) 837 return; 838 839 RGBA32 rgba = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1.0f); 840 c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); 836 state().m_shadowColor = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1.0f); 837 838 GraphicsContext* c = drawingContext(); 839 if (!c) 840 return; 841 842 c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); 841 843 } 842 844 843 845 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, float alpha) 844 846 { 847 RGBA32 rgba; 848 849 if (!CSSParser::parseColor(rgba, color)) 850 return; 851 852 state().m_shadowColor = colorWithOverrideAlpha(rgba, alpha); 845 853 state().m_shadowOffset = FloatSize(width, height); 846 854 state().m_shadowBlur = blur; 847 state().m_shadowColor = color; 848 849 GraphicsContext* c = drawingContext(); 850 if (!c) 851 return; 852 853 RGBA32 rgba = 0; // default is transparent black 854 if (!state().m_shadowColor.isEmpty()) 855 CSSParser::parseColor(rgba, state().m_shadowColor); 856 c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(colorWithOverrideAlpha(rgba, alpha)), DeviceColorSpace); 855 856 GraphicsContext* c = drawingContext(); 857 if (!c) 858 return; 859 860 c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); 857 861 } 858 862 … … 861 865 state().m_shadowOffset = FloatSize(width, height); 862 866 state().m_shadowBlur = blur; 863 state().m_shadowColor = ""; 864 865 GraphicsContext* c = drawingContext(); 866 if (!c) 867 return; 868 869 RGBA32 rgba = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, alpha); 870 c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); 867 state().m_shadowColor = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, alpha); 868 869 GraphicsContext* c = drawingContext(); 870 if (!c) 871 return; 872 873 c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); 871 874 } 872 875 … … 875 878 state().m_shadowOffset = FloatSize(width, height); 876 879 state().m_shadowBlur = blur; 877 state().m_shadowColor = ""; 878 879 GraphicsContext* c = drawingContext(); 880 if (!c) 881 return; 882 883 RGBA32 rgba = makeRGBA32FromFloats(r, g, b, a); // default is transparent black 884 c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); 880 state().m_shadowColor = makeRGBA32FromFloats(r, g, b, a); 881 882 GraphicsContext* c = drawingContext(); 883 if (!c) 884 return; 885 886 c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); 885 887 } 886 888 … … 889 891 state().m_shadowOffset = FloatSize(width, height); 890 892 state().m_shadowBlur = blur; 891 state().m_shadowColor = "";893 state().m_shadowColor = makeRGBAFromCMYKA(c, m, y, k, a); 892 894 893 895 GraphicsContext* dc = drawingContext(); … … 902 904 CGColorRelease(shadowColor); 903 905 #else 904 dc->setShadow(IntSize(width, -height), blur, Color(c, m, y, k, a), DeviceColorSpace);906 dc->setShadow(IntSize(width, -height), blur, state().m_shadowColor, DeviceColorSpace); 905 907 #endif 906 908 } … … 910 912 state().m_shadowOffset = FloatSize(); 911 913 state().m_shadowBlur = 0; 912 state().m_shadowColor = "";914 state().m_shadowColor = Color::transparent; 913 915 applyShadow(); 914 916 } … … 920 922 return; 921 923 922 RGBA32 rgba = 0; // default is transparent black923 if (!state().m_shadowColor.isEmpty())924 CSSParser::parseColor(rgba, state().m_shadowColor);925 924 float width = state().m_shadowOffset.width(); 926 925 float height = state().m_shadowOffset.height(); 927 c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace);926 c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); 928 927 } 929 928 -
trunk/WebCore/html/canvas/CanvasRenderingContext2D.h
r59613 r59768 29 29 #include "AffineTransform.h" 30 30 #include "CanvasRenderingContext.h" 31 #include "Color.h" 31 32 #include "FloatSize.h" 32 33 #include "Font.h" … … 220 221 FloatSize m_shadowOffset; 221 222 float m_shadowBlur; 222 Stringm_shadowColor;223 RGBA32 m_shadowColor; 223 224 float m_globalAlpha; 224 225 CompositeOperator m_globalComposite; -
trunk/WebCore/html/canvas/CanvasStyle.cpp
r56155 r59768 1 1 /* 2 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 4 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 5 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> … … 49 49 namespace WebCore { 50 50 51 CanvasStyle::CanvasStyle( const String& color)52 : m_type( ColorString)53 , m_ color(color)51 CanvasStyle::CanvasStyle(RGBA32 rgba) 52 : m_type(RGBA) 53 , m_rgba(rgba) 54 54 { 55 55 } 56 56 57 57 CanvasStyle::CanvasStyle(float grayLevel) 58 : m_type(GrayLevel) 59 , m_alpha(1) 60 , m_grayLevel(grayLevel) 61 { 62 } 63 64 CanvasStyle::CanvasStyle(const String& color, float alpha) 65 : m_type(ColorStringWithAlpha) 66 , m_color(color) 67 , m_alpha(alpha) 58 : m_type(RGBA) 59 , m_rgba(makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1.0f)) 68 60 { 69 61 } 70 62 71 63 CanvasStyle::CanvasStyle(float grayLevel, float alpha) 72 : m_type(GrayLevel) 73 , m_alpha(alpha) 74 , m_grayLevel(grayLevel) 64 : m_type(RGBA) 65 , m_rgba(makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, alpha)) 75 66 { 76 67 } … … 78 69 CanvasStyle::CanvasStyle(float r, float g, float b, float a) 79 70 : m_type(RGBA) 80 , m_alpha(a) 81 , m_red(r) 82 , m_green(g) 83 , m_blue(b) 71 , m_rgba(makeRGBA32FromFloats(r, g, b, a)) 84 72 { 85 73 } … … 87 75 CanvasStyle::CanvasStyle(float c, float m, float y, float k, float a) 88 76 : m_type(CMYKA) 89 , m_alpha(a) 90 , m_cyan(c) 91 , m_magenta(m) 92 , m_yellow(y) 93 , m_black(k) 77 , m_rgba(makeRGBAFromCMYKA(c, m, y, k, a)) 78 , m_cmyka(c, m, y, k, a) 94 79 { 95 80 } 96 81 97 82 CanvasStyle::CanvasStyle(PassRefPtr<CanvasGradient> gradient) 98 : m_type( gradient ? Gradient : ColorString)83 : m_type(Gradient) 99 84 , m_gradient(gradient) 100 85 { … … 102 87 103 88 CanvasStyle::CanvasStyle(PassRefPtr<CanvasPattern> pattern) 104 : m_type( pattern ? ImagePattern : ColorString)89 : m_type(ImagePattern) 105 90 , m_pattern(pattern) 106 91 { 92 } 93 94 PassRefPtr<CanvasStyle> CanvasStyle::create(const String& color) 95 { 96 RGBA32 rgba; 97 if (!CSSParser::parseColor(rgba, color)) 98 return 0; 99 return adoptRef(new CanvasStyle(rgba)); 100 } 101 102 PassRefPtr<CanvasStyle> CanvasStyle::create(const String& color, float alpha) 103 { 104 RGBA32 rgba; 105 if (!CSSParser::parseColor(rgba, color)) 106 return 0; 107 return adoptRef(new CanvasStyle(colorWithOverrideAlpha(rgba, alpha))); 108 } 109 110 PassRefPtr<CanvasStyle> CanvasStyle::create(PassRefPtr<CanvasGradient> gradient) 111 { 112 if (!gradient) 113 return 0; 114 return adoptRef(new CanvasStyle(gradient)); 115 } 116 PassRefPtr<CanvasStyle> CanvasStyle::create(PassRefPtr<CanvasPattern> pattern) 117 { 118 if (!pattern) 119 return 0; 120 return adoptRef(new CanvasStyle(pattern)); 107 121 } 108 122 … … 112 126 return; 113 127 switch (m_type) { 114 case ColorString: { 115 Color c = Color(m_color); 116 if (c.isValid()) { 117 context->setStrokeColor(c.rgb(), DeviceColorSpace); 118 break; 119 } 120 RGBA32 color = 0; // default is transparent black 121 if (CSSParser::parseColor(color, m_color)) 122 context->setStrokeColor(color, DeviceColorSpace); 123 break; 124 } 125 case ColorStringWithAlpha: { 126 Color c = Color(m_color); 127 if (c.isValid()) { 128 context->setStrokeColor(colorWithOverrideAlpha(c.rgb(), m_alpha), DeviceColorSpace); 129 break; 130 } 131 RGBA32 color = 0; // default is transparent black 132 if (CSSParser::parseColor(color, m_color)) 133 context->setStrokeColor(colorWithOverrideAlpha(color, m_alpha), DeviceColorSpace); 134 break; 135 } 136 case GrayLevel: 137 // We're only supporting 255 levels of gray here. Since this isn't 138 // even part of HTML5, I don't expect anyone will care. If they do 139 // we'll make a fancier Color abstraction. 140 context->setStrokeColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha), DeviceColorSpace); 141 break; 142 case RGBA: 143 context->setStrokeColor(Color(m_red, m_green, m_blue, m_alpha), DeviceColorSpace); 144 break; 145 case CMYKA: { 146 // FIXME: Do this through platform-independent GraphicsContext API. 147 // We'll need a fancier Color abstraction to support CYMKA correctly 128 case RGBA: 129 context->setStrokeColor(m_rgba, DeviceColorSpace); 130 break; 131 case CMYKA: { 132 // FIXME: Do this through platform-independent GraphicsContext API. 133 // We'll need a fancier Color abstraction to support CMYKA correctly 148 134 #if PLATFORM(CG) 149 CGContextSetCMYKStrokeColor(context->platformContext(), m_cyan, m_magenta, m_yellow, m_black, m_alpha);135 CGContextSetCMYKStrokeColor(context->platformContext(), m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a); 150 136 #elif PLATFORM(QT) 151 152 153 clr.setCmykF(m_cyan, m_magenta, m_yellow, m_black, m_alpha);154 155 137 QPen currentPen = context->platformContext()->pen(); 138 QColor clr; 139 clr.setCmykF(m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a); 140 currentPen.setColor(clr); 141 context->platformContext()->setPen(currentPen); 156 142 #else 157 context->setStrokeColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha), DeviceColorSpace);143 context->setStrokeColor(m_rgba, DeviceColorSpace); 158 144 #endif 159 160 161 162 163 164 165 166 145 break; 146 } 147 case Gradient: 148 context->setStrokeGradient(canvasGradient()->gradient()); 149 break; 150 case ImagePattern: 151 context->setStrokePattern(canvasPattern()->pattern()); 152 break; 167 153 } 168 154 } … … 173 159 return; 174 160 switch (m_type) { 175 case ColorString: { 176 RGBA32 rgba = 0; // default is transparent black 177 if (CSSParser::parseColor(rgba, m_color)) 178 context->setFillColor(rgba, DeviceColorSpace); 179 break; 180 } 181 case ColorStringWithAlpha: { 182 RGBA32 color = 0; // default is transparent black 183 if (CSSParser::parseColor(color, m_color)) 184 context->setFillColor(colorWithOverrideAlpha(color, m_alpha), DeviceColorSpace); 185 break; 186 } 187 case GrayLevel: 188 // We're only supporting 255 levels of gray here. Since this isn't 189 // even part of HTML5, I don't expect anyone will care. If they do 190 // we'll make a fancier Color abstraction. 191 context->setFillColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha), DeviceColorSpace); 192 break; 193 case RGBA: 194 context->setFillColor(Color(m_red, m_green, m_blue, m_alpha), DeviceColorSpace); 195 break; 196 case CMYKA: { 197 // FIXME: Do this through platform-independent GraphicsContext API. 198 // We'll need a fancier Color abstraction to support CYMKA correctly 161 case RGBA: 162 context->setFillColor(m_rgba, DeviceColorSpace); 163 break; 164 case CMYKA: { 165 // FIXME: Do this through platform-independent GraphicsContext API. 166 // We'll need a fancier Color abstraction to support CMYKA correctly 199 167 #if PLATFORM(CG) 200 CGContextSetCMYKFillColor(context->platformContext(), m_cyan, m_magenta, m_yellow, m_black, m_alpha);168 CGContextSetCMYKFillColor(context->platformContext(), m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a); 201 169 #elif PLATFORM(QT) 202 203 204 clr.setCmykF(m_cyan, m_magenta, m_yellow, m_black, m_alpha);205 206 170 QBrush currentBrush = context->platformContext()->brush(); 171 QColor clr; 172 clr.setCmykF(m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a); 173 currentBrush.setColor(clr); 174 context->platformContext()->setBrush(currentBrush); 207 175 #else 208 context->setFillColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha), DeviceColorSpace);176 context->setFillColor(m_rgba, DeviceColorSpace); 209 177 #endif 210 211 212 213 214 215 216 217 178 break; 179 } 180 case Gradient: 181 context->setFillGradient(canvasGradient()->gradient()); 182 break; 183 case ImagePattern: 184 context->setFillPattern(canvasPattern()->pattern()); 185 break; 218 186 } 219 187 } -
trunk/WebCore/html/canvas/CanvasStyle.h
r49734 r59768 1 1 /* 2 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 27 28 #define CanvasStyle_h 28 29 30 #include "Color.h" 29 31 #include "PlatformString.h" 30 32 … … 37 39 class CanvasStyle : public RefCounted<CanvasStyle> { 38 40 public: 39 static PassRefPtr<CanvasStyle> create(const String& color) { return adoptRef(new CanvasStyle(color)); } 41 static PassRefPtr<CanvasStyle> create(RGBA32 rgba) { return adoptRef(new CanvasStyle(rgba)); } 42 static PassRefPtr<CanvasStyle> create(const String& color); 43 static PassRefPtr<CanvasStyle> create(const String& color, float alpha); 40 44 static PassRefPtr<CanvasStyle> create(float grayLevel) { return adoptRef(new CanvasStyle(grayLevel)); } 41 static PassRefPtr<CanvasStyle> create(const String& color, float alpha) { return adoptRef(new CanvasStyle(color, alpha)); }42 45 static PassRefPtr<CanvasStyle> create(float grayLevel, float alpha) { return adoptRef(new CanvasStyle(grayLevel, alpha)); } 43 46 static PassRefPtr<CanvasStyle> create(float r, float g, float b, float a) { return adoptRef(new CanvasStyle(r, g, b, a)); } 44 47 static PassRefPtr<CanvasStyle> create(float c, float m, float y, float k, float a) { return adoptRef(new CanvasStyle(c, m, y, k, a)); } 45 static PassRefPtr<CanvasStyle> create(PassRefPtr<CanvasGradient> gradient) { return adoptRef(new CanvasStyle(gradient)); }46 static PassRefPtr<CanvasStyle> create(PassRefPtr<CanvasPattern> pattern) { return adoptRef(new CanvasStyle(pattern)); }48 static PassRefPtr<CanvasStyle> create(PassRefPtr<CanvasGradient> gradient); 49 static PassRefPtr<CanvasStyle> create(PassRefPtr<CanvasPattern> pattern); 47 50 48 String color() const { return m_color; }51 String color() const { return Color(m_rgba).serialized(); } 49 52 CanvasGradient* canvasGradient() const { return m_gradient.get(); } 50 53 CanvasPattern* canvasPattern() const { return m_pattern.get(); } … … 54 57 55 58 private: 56 CanvasStyle( const String& color);59 CanvasStyle(RGBA32 rgba); 57 60 CanvasStyle(float grayLevel); 58 CanvasStyle(const String& color, float alpha);59 61 CanvasStyle(float grayLevel, float alpha); 60 62 CanvasStyle(float r, float g, float b, float a); … … 63 65 CanvasStyle(PassRefPtr<CanvasPattern>); 64 66 65 enum Type { ColorString, ColorStringWithAlpha, GrayLevel,RGBA, CMYKA, Gradient, ImagePattern };67 enum Type { RGBA, CMYKA, Gradient, ImagePattern }; 66 68 67 69 Type m_type; 68 70 69 String m_color; 71 RGBA32 m_rgba; 72 70 73 RefPtr<CanvasGradient> m_gradient; 71 74 RefPtr<CanvasPattern> m_pattern; 72 75 73 float m_alpha; 74 75 float m_grayLevel; 76 77 float m_red; 78 float m_green; 79 float m_blue; 80 81 float m_cyan; 82 float m_magenta; 83 float m_yellow; 84 float m_black; 76 struct CMYKAValues { 77 CMYKAValues() {} 78 CMYKAValues(float cyan, float magenta, float yellow, float black, float alpha) : c(cyan), m(magenta), y(yellow), k(black), a(alpha) {} 79 float c; 80 float m; 81 float y; 82 float k; 83 float a; 84 } m_cmyka; 85 85 }; 86 86 -
trunk/WebCore/platform/graphics/Color.cpp
r44503 r59768 179 179 } 180 180 181 String Color::serialized() const 182 { 183 if (alpha() == 0xFF) 184 return String::format("#%02x%02x%02x", red(), green(), blue()); 185 186 // Match Gecko ("0.0" for zero, 5 decimals for anything else) 187 if (!alpha()) 188 return String::format("rgba(%u, %u, %u, 0.0)", red(), green(), blue()); 189 190 return String::format("rgba(%u, %u, %u, %.5f)", red(), green(), blue(), alpha() / 255.0f); 191 } 192 181 193 String Color::name() const 182 194 { -
trunk/WebCore/platform/graphics/Color.h
r55633 r59768 81 81 explicit Color(const String&); 82 82 explicit Color(const char*); 83 83 84 // Returns the color serialized according to HTML5 85 // - http://www.whatwg.org/specs/web-apps/current-work/#serialization-of-a-color 86 String serialized() const; 87 84 88 String name() const; 85 89 void setNamedColor(const String&);
Note: See TracChangeset
for help on using the changeset viewer.