Changeset 69755 in webkit
- Timestamp:
- Oct 14, 2010 3:47:24 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r69754 r69755 1 2010-10-14 Andreas Kling <kling@webkit.org> 2 3 Reviewed by Darin Adler. 4 5 Canvas: "currentColor" should inherit the canvas element's color 6 https://bugs.webkit.org/show_bug.cgi?id=40273 7 8 Added test to verify support for "currentColor" value in CanvasRenderingContext2D. 9 10 Also unskipped 3 tests which now pass: 11 - canvas/philip/tests/2d.fillStyle.parse.current.basic.html 12 - canvas/philip/tests/2d.fillStyle.parse.current.changed.html 13 - canvas/philip/tests/2d.fillStyle.parse.current.removed.html 14 15 Spec link: 16 http://www.whatwg.org/specs/web-apps/current-work/#2dcontext 17 18 * fast/canvas/canvas-currentColor-expected.txt: Added. 19 * fast/canvas/canvas-currentColor.html: Added. 20 * fast/canvas/script-tests/canvas-currentColor.js: Added. 21 (attachCanvasToDocument): 22 (tryLinearGradientColor): 23 (tryRadialGradientColor): 24 * platform/gtk/Skipped: 25 * platform/mac/Skipped: 26 * platform/qt/Skipped: 27 1 28 2010-10-14 Csaba Osztrogonác <ossy@webkit.org> 2 29 -
trunk/LayoutTests/platform/gtk/Skipped
r69751 r69755 5565 5565 canvas/philip/tests/2d.drawImage.incomplete.html 5566 5566 canvas/philip/tests/2d.drawImage.null.html 5567 canvas/philip/tests/2d.fillStyle.parse.current.basic.html5568 canvas/philip/tests/2d.fillStyle.parse.current.changed.html5569 canvas/philip/tests/2d.fillStyle.parse.current.removed.html5570 5567 canvas/philip/tests/2d.fillStyle.parse.system.html 5571 5568 canvas/philip/tests/2d.gradient.radial.cone.front.html -
trunk/LayoutTests/platform/mac/Skipped
r69727 r69755 170 170 canvas/philip/tests/2d.drawImage.incomplete.html 171 171 canvas/philip/tests/2d.drawImage.null.html 172 canvas/philip/tests/2d.fillStyle.parse.current.basic.html173 canvas/philip/tests/2d.fillStyle.parse.current.changed.html174 canvas/philip/tests/2d.fillStyle.parse.current.removed.html175 172 canvas/philip/tests/2d.fillStyle.parse.system.html 176 173 canvas/philip/tests/2d.gradient.radial.cone.front.html -
trunk/LayoutTests/platform/qt/Skipped
r69752 r69755 5179 5179 canvas/philip/tests/2d.drawImage.incomplete.html 5180 5180 canvas/philip/tests/2d.drawImage.null.html 5181 canvas/philip/tests/2d.fillStyle.parse.current.basic.html5182 canvas/philip/tests/2d.fillStyle.parse.current.changed.html5183 canvas/philip/tests/2d.fillStyle.parse.current.removed.html5184 5181 canvas/philip/tests/2d.fillStyle.parse.system.html 5185 5182 canvas/philip/tests/2d.gradient.radial.cone.behind.html -
trunk/WebCore/ChangeLog
r69752 r69755 1 2010-10-14 Andreas Kling <kling@webkit.org> 2 3 Reviewed by Darin Adler. 4 5 Canvas: "currentColor" should inherit the canvas element's color 6 https://bugs.webkit.org/show_bug.cgi?id=40273 7 8 Add support for "currentColor" in CanvasRenderingContext2D APIs. 9 If the canvas is in-document, "currentColor" is replaced by canvas.style.color, 10 otherwise we use fully opaque black. 11 12 For gradient addColorStop(), "currentColor" always means fully opaque black. 13 14 Spec link: 15 http://www.whatwg.org/specs/web-apps/current-work/#2dcontext 16 17 Test: fast/canvas/canvas-currentColor.html 18 19 * html/canvas/CanvasGradient.cpp: 20 (WebCore::CanvasGradient::addColorStop): 21 * html/canvas/CanvasRenderingContext2D.cpp: 22 (WebCore::CanvasRenderingContext2D::setStrokeStyle): 23 (WebCore::CanvasRenderingContext2D::setFillStyle): 24 (WebCore::CanvasRenderingContext2D::setShadowColor): 25 (WebCore::CanvasRenderingContext2D::setShadow): 26 * html/canvas/CanvasStyle.cpp: 27 (WebCore::parseColor): 28 (WebCore::currentColor): 29 (WebCore::parseColorOrCurrentColor): 30 (WebCore::CanvasStyle::CanvasStyle): 31 (WebCore::CanvasStyle::createFromString): 32 (WebCore::CanvasStyle::createFromStringWithOverrideAlpha): 33 (WebCore::CanvasStyle::isEquivalentColor): 34 (WebCore::CanvasStyle::applyStrokeColor): 35 (WebCore::CanvasStyle::applyFillColor): 36 * html/canvas/CanvasStyle.h: 37 (WebCore::CanvasStyle::isCurrentColor): 38 (WebCore::CanvasStyle::hasOverrideAlpha): 39 (WebCore::CanvasStyle::overrideAlpha): 40 1 41 2010-10-08 Yury Semikhatsky <yurys@chromium.org> 2 42 -
trunk/WebCore/html/canvas/CanvasGradient.cpp
r49734 r69755 28 28 #include "CanvasGradient.h" 29 29 30 #include "CanvasPattern.h" 31 #include "CanvasStyle.h" 30 32 #include "CSSParser.h" 31 33 #include "ExceptionCode.h" … … 53 55 54 56 RGBA32 rgba = 0; 55 if (! CSSParser::parseColor(rgba, color)) {57 if (!parseColorOrCurrentColor(rgba, color, 0 /*canvas*/)) { 56 58 if (!m_dashbardCompatibilityMode) 57 59 ec = SYNTAX_ERR; -
trunk/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r69727 r69755 250 250 return; 251 251 252 checkOrigin(style->canvasPattern()); 252 if (style->isCurrentColor()) { 253 if (style->hasOverrideAlpha()) 254 style = CanvasStyle::createFromRGBA(colorWithOverrideAlpha(currentColor(canvas()), style->overrideAlpha())); 255 else 256 style = CanvasStyle::createFromRGBA(currentColor(canvas())); 257 } else 258 checkOrigin(style->canvasPattern()); 253 259 254 260 state().m_strokeStyle = style; … … 273 279 return; 274 280 275 checkOrigin(style->canvasPattern()); 281 if (style->isCurrentColor()) { 282 if (style->hasOverrideAlpha()) 283 style = CanvasStyle::createFromRGBA(colorWithOverrideAlpha(currentColor(canvas()), style->overrideAlpha())); 284 else 285 style = CanvasStyle::createFromRGBA(currentColor(canvas())); 286 } else 287 checkOrigin(style->canvasPattern()); 276 288 277 289 state().m_fillStyle = style; … … 395 407 void CanvasRenderingContext2D::setShadowColor(const String& color) 396 408 { 397 if (! CSSParser::parseColor(state().m_shadowColor, color))409 if (!parseColorOrCurrentColor(state().m_shadowColor, color, canvas())) 398 410 return; 399 411 … … 983 995 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color) 984 996 { 985 if (! CSSParser::parseColor(state().m_shadowColor, color))997 if (!parseColorOrCurrentColor(state().m_shadowColor, color, canvas())) 986 998 return; 987 999 … … 1008 1020 RGBA32 rgba; 1009 1021 1010 if (! CSSParser::parseColor(rgba, color))1022 if (!parseColorOrCurrentColor(rgba, color, canvas())) 1011 1023 return; 1012 1024 -
trunk/WebCore/html/canvas/CanvasStyle.cpp
r67574 r69755 31 31 32 32 #include "CSSParser.h" 33 #include "CSSPropertyNames.h" 33 34 #include "CanvasGradient.h" 34 35 #include "CanvasPattern.h" 35 36 #include "GraphicsContext.h" 37 #include "HTMLCanvasElement.h" 36 38 #include <wtf/Assertions.h> 37 39 #include <wtf/PassRefPtr.h> … … 50 52 namespace WebCore { 51 53 54 enum ColorParseResult { ParsedRGBA, ParsedCurrentColor, ParseFailed }; 55 56 static ColorParseResult parseColor(RGBA32& parsedColor, const String& colorString) 57 { 58 if (equalIgnoringCase(colorString, "currentcolor")) 59 return ParsedCurrentColor; 60 if (CSSParser::parseColor(parsedColor, colorString)) 61 return ParsedRGBA; 62 return ParseFailed; 63 } 64 65 RGBA32 currentColor(HTMLCanvasElement* canvas) 66 { 67 if (!canvas || !canvas->inDocument()) 68 return Color::black; 69 RGBA32 rgba = Color::black; 70 CSSParser::parseColor(rgba, canvas->style()->getPropertyValue(CSSPropertyColor)); 71 return rgba; 72 } 73 74 bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HTMLCanvasElement* canvas) 75 { 76 ColorParseResult parseResult = parseColor(parsedColor, colorString); 77 switch (parseResult) { 78 case ParsedRGBA: 79 return true; 80 case ParsedCurrentColor: 81 parsedColor = currentColor(canvas); 82 return true; 83 case ParseFailed: 84 return false; 85 } 86 } 87 88 CanvasStyle::CanvasStyle(Type type, float overrideAlpha) 89 : m_type(type) 90 , m_overrideAlpha(overrideAlpha) 91 { 92 } 93 52 94 CanvasStyle::CanvasStyle(RGBA32 rgba) 53 95 : m_type(RGBA) … … 90 132 { 91 133 RGBA32 rgba; 92 if (!CSSParser::parseColor(rgba, color)) 93 return 0; 94 return adoptRef(new CanvasStyle(rgba)); 134 ColorParseResult parseResult = parseColor(rgba, color); 135 switch (parseResult) { 136 case ParsedRGBA: 137 return adoptRef(new CanvasStyle(rgba)); 138 case ParsedCurrentColor: 139 return adoptRef(new CanvasStyle(CurrentColor)); 140 case ParseFailed: 141 return 0; 142 } 95 143 } 96 144 … … 98 146 { 99 147 RGBA32 rgba; 100 if (!CSSParser::parseColor(rgba, color)) 101 return 0; 102 return adoptRef(new CanvasStyle(colorWithOverrideAlpha(rgba, alpha))); 148 ColorParseResult parseResult = parseColor(rgba, color); 149 switch (parseResult) { 150 case ParsedRGBA: 151 return adoptRef(new CanvasStyle(colorWithOverrideAlpha(rgba, alpha))); 152 case ParsedCurrentColor: 153 return adoptRef(new CanvasStyle(CurrentColorWithOverrideAlpha, alpha)); 154 case ParseFailed: 155 return 0; 156 } 103 157 } 104 158 … … 122 176 123 177 switch (m_type) { 124 case CanvasStyle::RGBA:178 case RGBA: 125 179 return m_rgba == other.m_rgba; 126 case C anvasStyle::CMYKA:180 case CMYKA: 127 181 return m_cmyka.c == other.m_cmyka.c 128 182 && m_cmyka.m == other.m_cmyka.m … … 130 184 && m_cmyka.k == other.m_cmyka.k 131 185 && m_cmyka.a == other.m_cmyka.a; 132 case CanvasStyle::Gradient: 133 case CanvasStyle::ImagePattern: 186 case Gradient: 187 case ImagePattern: 188 case CurrentColor: 189 case CurrentColorWithOverrideAlpha: 134 190 return false; 135 191 } … … 189 245 context->setStrokePattern(canvasPattern()->pattern()); 190 246 break; 247 case CurrentColor: 248 case CurrentColorWithOverrideAlpha: 249 ASSERT_NOT_REACHED(); 250 break; 191 251 } 192 252 } … … 222 282 context->setFillPattern(canvasPattern()->pattern()); 223 283 break; 224 } 225 } 226 227 } 284 case CurrentColor: 285 case CurrentColorWithOverrideAlpha: 286 ASSERT_NOT_REACHED(); 287 break; 288 } 289 } 290 291 } -
trunk/WebCore/html/canvas/CanvasStyle.h
r67574 r69755 30 30 #include "Color.h" 31 31 #include "PlatformString.h" 32 #include <wtf/Assertions.h> 32 33 33 34 namespace WebCore { … … 36 37 class CanvasPattern; 37 38 class GraphicsContext; 39 class HTMLCanvasElement; 38 40 39 41 class CanvasStyle : public RefCounted<CanvasStyle> { … … 48 50 static PassRefPtr<CanvasStyle> createFromPattern(PassRefPtr<CanvasPattern>); 49 51 50 String color() const { return Color(m_rgba).serialized(); } 52 bool isCurrentColor() const { return m_type == CurrentColor || m_type == CurrentColorWithOverrideAlpha; } 53 bool hasOverrideAlpha() const { return m_type == CurrentColorWithOverrideAlpha; } 54 float overrideAlpha() const { ASSERT(m_type == CurrentColorWithOverrideAlpha); return m_overrideAlpha; } 55 56 String color() const { ASSERT(m_type == RGBA || m_type == CMYKA); return Color(m_rgba).serialized(); } 51 57 CanvasGradient* canvasGradient() const { return m_gradient.get(); } 52 58 CanvasPattern* canvasPattern() const { return m_pattern.get(); } … … 60 66 61 67 private: 68 enum Type { RGBA, CMYKA, Gradient, ImagePattern, CurrentColor, CurrentColorWithOverrideAlpha }; 69 70 CanvasStyle(Type, float overrideAlpha = 0); 62 71 CanvasStyle(RGBA32 rgba); 63 72 CanvasStyle(float grayLevel, float alpha); … … 67 76 CanvasStyle(PassRefPtr<CanvasPattern>); 68 77 69 enum Type { RGBA, CMYKA, Gradient, ImagePattern };70 71 78 Type m_type; 72 79 73 RGBA32 m_rgba; 80 union { 81 RGBA32 m_rgba; 82 float m_overrideAlpha; 83 }; 74 84 75 85 RefPtr<CanvasGradient> m_gradient; … … 87 97 }; 88 98 99 RGBA32 currentColor(HTMLCanvasElement*); 100 bool parseColorOrCurrentColor(RGBA32& parsedColor, const String& colorString, HTMLCanvasElement*); 101 89 102 } // namespace WebCore 90 103
Note: See TracChangeset
for help on using the changeset viewer.