diff options
Diffstat (limited to 'WebCore/html/canvas/CanvasRenderingContext2D.cpp')
-rw-r--r-- | WebCore/html/canvas/CanvasRenderingContext2D.cpp | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/WebCore/html/canvas/CanvasRenderingContext2D.cpp index 7cdf5d6..184cc14 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.cpp +++ b/WebCore/html/canvas/CanvasRenderingContext2D.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. - * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2007 Alp Toker <alp@atoker.com> * Copyright (C) 2008 Eric Seidel <eric@webkit.org> * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> @@ -118,14 +118,14 @@ void CanvasRenderingContext2D::reset() } CanvasRenderingContext2D::State::State() - : m_strokeStyle(CanvasStyle::create("#000000")) - , m_fillStyle(CanvasStyle::create("#000000")) + : m_strokeStyle(CanvasStyle::create(Color::black)) + , m_fillStyle(CanvasStyle::create(Color::black)) , m_lineWidth(1) , m_lineCap(ButtCap) , m_lineJoin(MiterJoin) , m_miterLimit(10) , m_shadowBlur(0) - , m_shadowColor("black") + , m_shadowColor(Color::transparent) , m_globalAlpha(1) , m_globalComposite(CompositeSourceOver) , m_invertibleCTM(true) @@ -315,13 +315,14 @@ void CanvasRenderingContext2D::setShadowBlur(float blur) String CanvasRenderingContext2D::shadowColor() const { - // FIXME: What should this return if you called setShadow with a non-string color? - return state().m_shadowColor; + return Color(state().m_shadowColor).serialized(); } void CanvasRenderingContext2D::setShadowColor(const String& color) { - state().m_shadowColor = color; + if (!CSSParser::parseColor(state().m_shadowColor, color)) + return; + applyShadow(); } @@ -814,15 +815,17 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur) { state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = ""; + state().m_shadowColor = Color::transparent; applyShadow(); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color) { + if (!CSSParser::parseColor(state().m_shadowColor, color)) + return; + state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = color; applyShadow(); } @@ -830,65 +833,64 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, { state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = ""; + state().m_shadowColor = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1.0f); GraphicsContext* c = drawingContext(); if (!c) return; - RGBA32 rgba = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1.0f); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, float alpha) { + RGBA32 rgba; + + if (!CSSParser::parseColor(rgba, color)) + return; + + state().m_shadowColor = colorWithOverrideAlpha(rgba, alpha); state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = color; GraphicsContext* c = drawingContext(); if (!c) return; - RGBA32 rgba = 0; // default is transparent black - if (!state().m_shadowColor.isEmpty()) - CSSParser::parseColor(rgba, state().m_shadowColor); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(colorWithOverrideAlpha(rgba, alpha)), DeviceColorSpace); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float grayLevel, float alpha) { state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = ""; + state().m_shadowColor = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, alpha); GraphicsContext* c = drawingContext(); if (!c) return; - RGBA32 rgba = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, alpha); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float r, float g, float b, float a) { state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = ""; + state().m_shadowColor = makeRGBA32FromFloats(r, g, b, a); GraphicsContext* c = drawingContext(); if (!c) return; - RGBA32 rgba = makeRGBA32FromFloats(r, g, b, a); // default is transparent black - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float c, float m, float y, float k, float a) { state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = ""; + state().m_shadowColor = makeRGBAFromCMYKA(c, m, y, k, a); GraphicsContext* dc = drawingContext(); if (!dc) @@ -901,7 +903,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, CGContextSetShadowWithColor(dc->platformContext(), adjustedShadowSize(width, -height), blur, shadowColor); CGColorRelease(shadowColor); #else - dc->setShadow(IntSize(width, -height), blur, Color(c, m, y, k, a), DeviceColorSpace); + dc->setShadow(IntSize(width, -height), blur, state().m_shadowColor, DeviceColorSpace); #endif } @@ -909,7 +911,7 @@ void CanvasRenderingContext2D::clearShadow() { state().m_shadowOffset = FloatSize(); state().m_shadowBlur = 0; - state().m_shadowColor = ""; + state().m_shadowColor = Color::transparent; applyShadow(); } @@ -919,12 +921,9 @@ void CanvasRenderingContext2D::applyShadow() if (!c) return; - RGBA32 rgba = 0; // default is transparent black - if (!state().m_shadowColor.isEmpty()) - CSSParser::parseColor(rgba, state().m_shadowColor); float width = state().m_shadowOffset.width(); float height = state().m_shadowOffset.height(); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); } static IntSize size(HTMLImageElement* image) |