Changeset 79675 in webkit
- Timestamp:
- Feb 25, 2011 5:08:26 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r79674 r79675 1 2011-02-25 Nikolas Zimmermann <nzimmermann@rim.com> 2 3 Reviewed by Dirk Schulze. 4 5 Implement SVGColor/SVGPaint API 6 https://bugs.webkit.org/show_bug.cgi?id=55119 7 8 SVGColor::cssText() shouldn't return #RRGGBBAA colors 9 https://bugs.webkit.org/show_bug.cgi?id=48120 10 11 Add two new tests covering the SVGColor/SVGPaint APIs. 12 Adapt to SVGColor::cssText() changes, color is properly serialized now. 13 14 * svg/animations/animate-color-transparent-expected.txt: 15 * svg/animations/animate-currentColor-expected.txt: 16 * svg/animations/animate-dynamic-update-attributeName-expected.txt: 17 * svg/animations/animate-inherit-css-property-expected.txt: 18 * svg/animations/script-tests/animate-color-transparent.js: 19 (expectTransparent): 20 (expectOtherColor): 21 * svg/animations/script-tests/animate-currentColor.js: 22 (sample1): 23 * svg/animations/script-tests/animate-inherit-css-property.js: 24 (sample1): 25 * svg/css/getComputedStyle-basic-expected.txt: 26 * svg/custom/getPresentationAttribute-modify.svg: 27 * svg/custom/rgbcolor-syntax.svg: 28 * svg/dom/SVGColor-expected.txt: Added. 29 * svg/dom/SVGColor.html: Added. 30 * svg/dom/SVGPaint-expected.txt: Added. 31 * svg/dom/SVGPaint.html: Added. 32 * svg/dom/script-tests/SVGColor.js: Added. 33 (checkStopColor): 34 * svg/dom/script-tests/SVGPaint.js: Added. 35 (resetStyle): 36 (checkFillColor): 37 1 38 2011-02-25 Renata Hodovan <reni@webkit.org> 2 39 -
trunk/LayoutTests/svg/animations/animate-color-transparent-expected.txt
r70236 r79675 6 6 7 7 8 PASS rect.style.fill is '#00 FF00'9 PASS rect.style.fill is '#7 F0000'8 PASS rect.style.fill is '#00ff00' 9 PASS rect.style.fill is '#7f0000' 10 10 PASS successfullyParsed is true 11 11 -
trunk/LayoutTests/svg/animations/animate-currentColor-expected.txt
r78543 r79675 6 6 7 7 8 PASS rect.style.fill is '# FF0000'8 PASS rect.style.fill is '#ff0000' 9 9 PASS rect.style.fill is '#804000' 10 10 PASS rect.style.fill is '#008000' -
trunk/LayoutTests/svg/animations/animate-dynamic-update-attributeName-expected.txt
r79155 r79675 7 7 8 8 PASS rect.style.color is 'rgb(0, 128, 0)' 9 FAIL rect.style.fill should be #008000. Was # FF0000.9 FAIL rect.style.fill should be #008000. Was #ff0000. 10 10 PASS successfullyParsed is true 11 11 -
trunk/LayoutTests/svg/animations/animate-inherit-css-property-expected.txt
r78543 r79675 6 6 7 7 8 PASS rect.style.fill is '# FF0000'8 PASS rect.style.fill is '#ff0000' 9 9 PASS rect.style.fill is '#804000' 10 10 PASS rect.style.fill is '#008000' -
trunk/LayoutTests/svg/animations/script-tests/animate-color-transparent.js
r70236 r79675 22 22 function expectTransparent() { 23 23 // Check initial/end conditions 24 shouldBe("rect.style.fill", "'#00 FF00'");24 shouldBe("rect.style.fill", "'#00ff00'"); 25 25 } 26 26 27 27 function expectOtherColor() { 28 28 // Check half-time conditions 29 shouldBe("rect.style.fill", "'#7 F0000'");29 shouldBe("rect.style.fill", "'#7f0000'"); 30 30 } 31 31 -
trunk/LayoutTests/svg/animations/script-tests/animate-currentColor.js
r78543 r79675 24 24 function sample1() { 25 25 // Check initial/end conditions 26 shouldBe("rect.style.fill", "'# FF0000'");26 shouldBe("rect.style.fill", "'#ff0000'"); 27 27 } 28 28 -
trunk/LayoutTests/svg/animations/script-tests/animate-inherit-css-property.js
r78543 r79675 27 27 function sample1() { 28 28 // Check initial/end conditions 29 shouldBe("rect.style.fill", "'# FF0000'");29 shouldBe("rect.style.fill", "'#ff0000'"); 30 30 } 31 31 -
trunk/LayoutTests/svg/css/getComputedStyle-basic-expected.txt
r74538 r79675 373 373 rect: style.getPropertyValue(color-rendering) : auto 374 374 rect: style.getPropertyCSSValue(color-rendering) : [object CSSPrimitiveValue] 375 rect: style.getPropertyValue(fill) : #0000 FF375 rect: style.getPropertyValue(fill) : #0000ff 376 376 rect: style.getPropertyCSSValue(fill) : [object SVGPaint] 377 377 rect: style.getPropertyValue(fill-opacity) : 1 … … 389 389 rect: style.getPropertyValue(shape-rendering) : auto 390 390 rect: style.getPropertyCSSValue(shape-rendering) : [object CSSPrimitiveValue] 391 rect: style.getPropertyValue(stroke) : # FFA500391 rect: style.getPropertyValue(stroke) : #ffa500 392 392 rect: style.getPropertyCSSValue(stroke) : [object SVGPaint] 393 393 rect: style.getPropertyValue(stroke-dasharray) : none … … 815 815 g: style.getPropertyValue(shape-rendering) : auto 816 816 g: style.getPropertyCSSValue(shape-rendering) : [object CSSPrimitiveValue] 817 g: style.getPropertyValue(stroke) : # FFA500817 g: style.getPropertyValue(stroke) : #ffa500 818 818 g: style.getPropertyCSSValue(stroke) : [object SVGPaint] 819 819 g: style.getPropertyValue(stroke-dasharray) : none -
trunk/LayoutTests/svg/custom/getPresentationAttribute-modify.svg
r34448 r79675 23 23 rect = document.getElementById("firstrect"); 24 24 fill = rect.getPresentationAttribute("fill"); 25 if (fill.cssText != '# FF0000') {25 if (fill.cssText != '#ff0000') { 26 26 log("Changing fill PA should not change firstrect fill PA"); 27 27 return; -
trunk/LayoutTests/svg/custom/rgbcolor-syntax.svg
r75408 r79675 46 46 if (!expectsException(col, "#fffffff")) return; 47 47 if (!expectsException(col, "green,")) return; 48 if (!expectsValid(col, "rgb(0, 10, 20)", "#000 A14")) return;49 if (!expectsValid(col, "#FFF", "# FFFFFF")) return;50 if (!expectsValid(col, "#FFFFFF", "# FFFFFF")) return;48 if (!expectsValid(col, "rgb(0, 10, 20)", "#000a14")) return; 49 if (!expectsValid(col, "#FFF", "#ffffff")) return; 50 if (!expectsValid(col, "#FFFFFF", "#ffffff")) return; 51 51 if (!expectsValid(col, " green", "#008000")) return; 52 52 if (!expectsValid(col, "green ", "#008000")) return; -
trunk/Source/WebCore/ChangeLog
r79674 r79675 1 2011-02-25 Nikolas Zimmermann <nzimmermann@rim.com> 2 3 Reviewed by Dirk Schulze. 4 5 Implement SVGColor/SVGPaint API 6 https://bugs.webkit.org/show_bug.cgi?id=55119 7 8 SVGColor::cssText() shouldn't return #RRGGBBAA colors 9 https://bugs.webkit.org/show_bug.cgi?id=48120 10 11 Rewrite SVGColor/SVGPaint to actually implement their desired setPaint/setColor/setURI APIs. 12 SVGPaint is a CSSValue, and its setPaint() function allows to switch to an arbitary paint type. 13 That means, unlike all other CSSValues, SVGColor/SVGPaint are mutable. That means changes to 14 their CSSValues should be reflected in the elements style as well as in the computed style. 15 This patch doesn't yet implement that, the stubbed-out method valueChanged() is what 16 needs to be implemented. For now you can grab a SVGColor/SVGPaint object through getCSSPropertyValue 17 and manipulate it, in every possible way (SVPaint.uri/paintType/colorType/color attributes are all sync'ed). 18 Switch to strict JS bindings (RequiresAllArguments=Raise, StrictTypeChecking) for both objects. 19 20 Enable proper serialization of colors through Color::serialized(), affects some testcases (#FF.. -> #ff..) 21 Add extensive tests of all SVGColor/SVGPaint API, currently shows some FAIL messages, as element style 22 <-> computed style is not live, after mutating SVGColor/SVGPaint. That will be implemented in a follow-up patch. 23 24 Tests: svg/dom/SVGColor.html 25 svg/dom/SVGPaint.html 26 27 * bindings/scripts/CodeGenerator.pm: Remove obsolete handling of "SVGPaintType", take ushort for paintType, as specified in the SVG 1.1 IDLs. 28 * bindings/scripts/CodeGeneratorJS.pm: Ditto. 29 * bindings/scripts/CodeGeneratorObjC.pm: Ditto. 30 * bindings/scripts/CodeGeneratorV8.pm: Ditto. 31 * css/SVGCSSParser.cpp: Adapt to SVGPaint/SVGColor create() naming convention changes. 32 (WebCore::CSSParser::parseSVGValue): 33 (WebCore::CSSParser::parseSVGPaint): 34 (WebCore::CSSParser::parseSVGColor): 35 * svg/SVGColor.cpp: Rewrite to fully implement the SVGColor API, merge all constructors into one, use more descriptable create() naming convention. 36 (WebCore::valueChanged): Stub implementation, will land in a follow-up patch. 37 (WebCore::SVGColor::SVGColor): 38 (WebCore::SVGColor::setRGBColor): 39 (WebCore::SVGColor::colorFromRGBColorString): 40 (WebCore::SVGColor::setRGBColorICCColor): 41 (WebCore::SVGColor::setColor): 42 (WebCore::SVGColor::cssText): 43 * svg/SVGColor.h: 44 (WebCore::SVGColor::createFromString): 45 (WebCore::SVGColor::createFromColor): 46 (WebCore::SVGColor::color): 47 (WebCore::SVGColor::colorType): 48 (WebCore::SVGColor::~SVGColor): 49 (WebCore::SVGColor::setColor): 50 (WebCore::SVGColor::setColorType): 51 * svg/SVGColor.idl: Enable strict type checking. 52 * svg/SVGPaint.cpp: Rewrite to fully implement the SVGPaint API, merge all constructors into one, use more descriptable create() naming convention. 53 (WebCore::valueChanged): Stub implementation, will land in a follow-up patch. 54 (WebCore::colorTypeForPaintType): 55 (WebCore::SVGPaint::SVGPaint): 56 (WebCore::SVGPaint::setUri): 57 (WebCore::SVGPaint::defaultFill): 58 (WebCore::SVGPaint::defaultStroke): 59 (WebCore::SVGPaint::setPaint): 60 (WebCore::SVGPaint::cssText): 61 (WebCore::SVGPaint::matchesTargetURI): 62 * svg/SVGPaint.h: 63 (WebCore::SVGPaint::createUnknown): 64 (WebCore::SVGPaint::createNone): 65 (WebCore::SVGPaint::createCurrentColor): 66 (WebCore::SVGPaint::createColor): 67 (WebCore::SVGPaint::createURI): 68 (WebCore::SVGPaint::createURIAndColor): 69 (WebCore::SVGPaint::paintType): 70 (WebCore::SVGPaint::uri): 71 (WebCore::SVGPaint::create): 72 (WebCore::SVGPaint::isSVGPaint): 73 * svg/SVGPaint.idl: Enable strict type checking. 74 1 75 2011-02-25 Renata Hodovan <reni@webkit.org> 2 76 -
trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm
r73011 r79675 53 53 my %stringTypeHash = ("DOMString" => 1, "AtomicString" => 1); 54 54 55 my %nonPointerTypeHash = ("DOMTimeStamp" => 1, "CompareHow" => 1 , "SVGPaintType" => 1);55 my %nonPointerTypeHash = ("DOMTimeStamp" => 1, "CompareHow" => 1); 56 56 57 57 my %svgAnimatedTypeHash = ("SVGAnimatedAngle" => 1, "SVGAnimatedBoolean" => 1, -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r79616 r79675 2370 2370 "SerializedScriptValue" => "RefPtr<SerializedScriptValue>", 2371 2371 "IDBKey" => "RefPtr<IDBKey>", 2372 "SVGPaintType" => "SVGPaint::SVGPaintType",2373 2372 "boolean" => "bool", 2374 2373 "double" => "double", … … 2457 2456 return "valueToDate(exec, $value)" if $type eq "Date"; 2458 2457 return "static_cast<Range::CompareHow>($value.toInt32(exec))" if $type eq "CompareHow"; 2459 return "static_cast<SVGPaint::SVGPaintType>($value.toInt32(exec))" if $type eq "SVGPaintType";2460 2458 2461 2459 if ($type eq "DOMString") { … … 2516 2514 } 2517 2515 2518 if ($codeGenerator->IsPrimitiveType($type) or $type eq " SVGPaintType" or $type eq "DOMTimeStamp") {2516 if ($codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp") { 2519 2517 $implIncludes{"<runtime/JSNumberCell.h>"} = 1; 2520 2518 return "jsNumber($value)"; -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm
r73011 r79675 475 475 return "id <$name>" if IsProtocolType($type); 476 476 return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp"; 477 return "unsigned short" if $type eq "CompareHow" or $type eq "SVGPaintType";477 return "unsigned short" if $type eq "CompareHow"; 478 478 return "$name *"; 479 479 } … … 493 493 } elsif ($codeGenerator->IsSVGAnimatedType($type)) { 494 494 push(@attributes, "retain"); 495 } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow" && $type ne "SVGPaintType") {495 } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow") { 496 496 push(@attributes, "retain"); 497 497 } … … 516 516 return $argName . "Node" if $type eq "EventTarget"; 517 517 return "static_cast<WebCore::Range::CompareHow>($argName)" if $type eq "CompareHow"; 518 return "static_cast<WebCore::SVGPaint::SVGPaintType>($argName)" if $type eq "SVGPaintType";519 518 return "WTF::getPtr(nativeEventListener)" if $type eq "EventListener"; 520 519 return "WTF::getPtr(nativeNodeFilter)" if $type eq "NodeFilter"; -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
r79223 r79675 2805 2805 return "String" if $type eq "DOMString"; 2806 2806 return "Range::CompareHow" if $type eq "CompareHow"; 2807 return "SVGPaint::SVGPaintType" if $type eq "SVGPaintType";2808 2807 return "DOMTimeStamp" if $type eq "DOMTimeStamp"; 2809 2808 return "unsigned" if $type eq "unsigned int"; … … 2882 2881 return "toInt64($value)" if $type eq "unsigned long long" or $type eq "long long"; 2883 2882 return "static_cast<Range::CompareHow>($value->Int32Value())" if $type eq "CompareHow"; 2884 return "static_cast<SVGPaint::SVGPaintType>($value->ToInt32()->Int32Value())" if $type eq "SVGPaintType";2885 2883 return "toWebCoreDate($value)" if $type eq "Date"; 2886 2884 return "v8ValueToWebCoreDOMStringList($value)" if $type eq "DOMStringList"; … … 3036 3034 'CompareHow' => 1, 3037 3035 'SerializedScriptValue' => 1, 3038 'SVGPaintType' => 1,3039 3036 'DOMTimeStamp' => 1, 3040 3037 'JSObject' => 1, … … 3113 3110 # long long and unsigned long long are not representable in ECMAScript. 3114 3111 return "v8::Number::New(static_cast<double>($value))" if $type eq "long long" or $type eq "unsigned long long" or $type eq "DOMTimeStamp"; 3115 return "v8::Number::New($value)" if $codeGenerator->IsPrimitiveType($type) or $type eq "SVGPaintType";3112 return "v8::Number::New($value)" if $codeGenerator->IsPrimitiveType($type); 3116 3113 return "$value.v8Value()" if $nativeType eq "ScriptValue"; 3117 3114 -
trunk/Source/WebCore/css/SVGCSSParser.cpp
r67695 r79675 180 180 { 181 181 if (id == CSSValueNone) 182 parsedValue = SVGPaint::create (SVGPaint::SVG_PAINTTYPE_NONE);182 parsedValue = SVGPaint::createNone(); 183 183 else if (id == CSSValueCurrentcolor) 184 parsedValue = SVGPaint::create (SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR);184 parsedValue = SVGPaint::createCurrentColor(); 185 185 else if ((id >= CSSValueActiveborder && id <= CSSValueWindowtext) || id == CSSValueMenu) 186 parsedValue = SVGPaint::create (RenderTheme::defaultTheme()->systemColor(id));186 parsedValue = SVGPaint::createColor(RenderTheme::defaultTheme()->systemColor(id)); 187 187 else if (value->unit == CSSPrimitiveValue::CSS_URI) { 188 188 RGBA32 c = Color::transparent; 189 189 if (m_valueList->next() && parseColorFromValue(m_valueList->current(), c)) { 190 parsedValue = SVGPaint::create (value->string, c);190 parsedValue = SVGPaint::createURIAndColor(value->string, c); 191 191 } else 192 parsedValue = SVGPaint::create (SVGPaint::SVG_PAINTTYPE_URI,value->string);192 parsedValue = SVGPaint::createURI(value->string); 193 193 } else 194 194 parsedValue = parseSVGPaint(); … … 202 202 if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || 203 203 (id >= CSSValueAliceblue && id <= CSSValueYellowgreen)) 204 parsedValue = SVGColor::create (value->string);204 parsedValue = SVGColor::createFromString(value->string); 205 205 else 206 206 parsedValue = parseSVGColor(); … … 215 215 if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || 216 216 (id >= CSSValueAliceblue && id <= CSSValueYellowgreen)) 217 parsedValue = SVGColor::create (value->string);217 parsedValue = SVGColor::createFromString(value->string); 218 218 else if (id == CSSValueCurrentcolor) 219 219 parsedValue = SVGColor::createCurrentColor(); … … 340 340 RGBA32 c = Color::transparent; 341 341 if (!parseColorFromValue(m_valueList->current(), c)) 342 return SVGPaint::create ();343 return SVGPaint::create (Color(c));342 return SVGPaint::createUnknown(); 343 return SVGPaint::createColor(Color(c)); 344 344 } 345 345 … … 349 349 if (!parseColorFromValue(m_valueList->current(), c)) 350 350 return 0; 351 return SVGColor::create (Color(c));351 return SVGColor::createFromColor(Color(c)); 352 352 } 353 353 … … 355 355 356 356 #endif // ENABLE(SVG) 357 358 // vim:ts=4:noet -
trunk/Source/WebCore/svg/SVGColor.cpp
r78590 r79675 2 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> 3 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 4 5 * 5 6 * This library is free software; you can redistribute it and/or … … 20 21 21 22 #include "config.h" 23 22 24 #if ENABLE(SVG) 23 25 #include "SVGColor.h" … … 29 31 namespace WebCore { 30 32 31 SVGColor::SVGColor() 32 : m_colorType(SVG_COLORTYPE_UNKNOWN) 33 { 34 } 35 36 SVGColor::SVGColor(const String& rgbColor) 37 : m_colorType(SVG_COLORTYPE_RGBCOLOR) 38 { 39 setRGBColor(rgbColor); 40 } 41 42 SVGColor::SVGColor(SVGColorType colorType) 33 SVGColor::SVGColor(const SVGColorType& colorType) 43 34 : m_colorType(colorType) 44 {45 }46 47 SVGColor::SVGColor(const Color& c)48 : m_color(c)49 , m_colorType(SVG_COLORTYPE_RGBCOLOR)50 35 { 51 36 } … … 59 44 { 60 45 Color color = SVGColor::colorFromRGBColorString(rgbColor); 61 if (color.isValid()) 62 m_color = color; 63 else 46 if (!color.isValid()) { 64 47 ec = SVGException::SVG_INVALID_VALUE_ERR; 48 return; 49 } 50 51 m_color = color; 52 m_colorType = SVG_COLORTYPE_RGBCOLOR; 53 // FIXME: A follow up patch will call valueChanged() here. 65 54 } 66 55 67 56 Color SVGColor::colorFromRGBColorString(const String& colorString) 68 57 { 69 String s = colorString.stripWhiteSpace(); 70 // FIXME: rework css parser so it is more svg aware 58 // FIXME: Rework css parser so it is more SVG aware. 71 59 RGBA32 color; 72 if (CSSParser::parseColor(color, s))60 if (CSSParser::parseColor(color, colorString.stripWhiteSpace())) 73 61 return color; 74 62 return Color(); 75 63 } 76 64 77 void SVGColor::setRGBColorICCColor(const String& /* rgbColor */, const String& /* iccColor */, ExceptionCode&)65 void SVGColor::setRGBColorICCColor(const String& rgbColor, const String& iccColor, ExceptionCode& ec) 78 66 { 79 // TODO: implement me! 67 if (rgbColor.isEmpty() || iccColor.isEmpty()) { 68 ec = SVGException::SVG_INVALID_VALUE_ERR; 69 return; 70 } 71 72 // FIXME: No support for ICC colors. We're just ignoring it. 73 setRGBColor(rgbColor, ec); 74 if (ec) 75 return; 76 77 m_colorType = SVG_COLORTYPE_RGBCOLOR_ICCCOLOR; 78 // FIXME: A follow up patch will call valueChanged() here. 80 79 } 81 80 82 void SVGColor::setColor(unsigned short colorType, const String& /* rgbColor */ , const String& /* iccColor */, ExceptionCode&)81 void SVGColor::setColor(unsigned short colorType, const String& rgbColor, const String& iccColor, ExceptionCode& ec) 83 82 { 84 // TODO: implement me! 85 m_colorType = colorType; 83 if (colorType > SVG_COLORTYPE_CURRENTCOLOR) { 84 ec = SVGException::SVG_WRONG_TYPE_ERR; 85 return; 86 } 87 88 bool requiresRGBColor = false; 89 bool requiresICCColor = false; 90 91 SVGColorType type = static_cast<SVGColorType>(colorType); 92 switch (type) { 93 case SVG_COLORTYPE_UNKNOWN: 94 // Spec: It is invalid to attempt to define a new value of this type or to attempt to switch an existing value to this type. 95 ec = SVGException::SVG_INVALID_VALUE_ERR; 96 return; 97 case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: 98 requiresICCColor = true; 99 case SVG_COLORTYPE_RGBCOLOR: 100 requiresRGBColor = true; 101 break; 102 case SVG_COLORTYPE_CURRENTCOLOR: 103 break; 104 } 105 106 // Spec: If colorType requires an RGBColor, then rgbColor must be a string that matches <color>; otherwise, rgbColor must be null. 107 if (requiresRGBColor && rgbColor.isEmpty()) { 108 ec = SVGException::SVG_INVALID_VALUE_ERR; 109 return; 110 } 111 112 // Spec: If colorType requires an SVGICCColor, then iccColor must be a string that matches <icccolor>; otherwise, iccColor must be null. 113 if (requiresICCColor && iccColor.isEmpty()) { 114 ec = SVGException::SVG_INVALID_VALUE_ERR; 115 return; 116 } 117 118 // FIXME: A follow up patch will call valueChanged() here. 119 m_colorType = type; 120 if (!requiresRGBColor) { 121 ASSERT(!requiresICCColor); 122 m_color = Color(); 123 return; 124 } 125 126 if (requiresICCColor) 127 setRGBColorICCColor(rgbColor, iccColor, ec); 128 else 129 setRGBColor(rgbColor, ec); 86 130 } 87 131 88 132 String SVGColor::cssText() const 89 133 { 90 if (m_colorType == SVG_COLORTYPE_RGBCOLOR) { 91 // FIXME: Use Color::serialized() instead. 92 return m_color.nameForRenderTreeAsText(); 134 switch (m_colorType) { 135 case SVG_COLORTYPE_UNKNOWN: 136 return String(); 137 case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: 138 case SVG_COLORTYPE_RGBCOLOR: 139 // FIXME: No ICC color support. 140 return m_color.serialized(); 141 case SVG_COLORTYPE_CURRENTCOLOR: 142 if (m_color.isValid()) 143 return m_color.serialized(); 144 return "currentColor"; 93 145 } 94 146 147 ASSERT_NOT_REACHED(); 95 148 return String(); 96 149 } … … 98 151 } 99 152 100 // vim:ts=4:noet101 153 #endif // ENABLE(SVG) 102 -
trunk/Source/WebCore/svg/SVGColor.h
r74472 r79675 2 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> 3 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 4 5 * 5 6 * This library is free software; you can redistribute it and/or … … 21 22 #ifndef SVGColor_h 22 23 #define SVGColor_h 24 23 25 #if ENABLE(SVG) 24 25 26 #include "CSSValue.h" 26 27 #include "Color.h" … … 33 34 class SVGColor : public CSSValue { 34 35 public: 35 static PassRefPtr<SVGColor> create(const String& color)36 {37 return adoptRef(new SVGColor(color));38 }39 static PassRefPtr<SVGColor> create(const Color& color)40 {41 return adoptRef(new SVGColor(color));42 }43 static PassRefPtr<SVGColor> createCurrentColor()44 {45 return adoptRef(new SVGColor(SVG_COLORTYPE_CURRENTCOLOR));46 }47 48 36 enum SVGColorType { 49 37 SVG_COLORTYPE_UNKNOWN = 0, … … 53 41 }; 54 42 55 // 'SVGColor' functions 56 unsigned short colorType() const { return m_colorType; } 43 static PassRefPtr<SVGColor> createFromString(const String& rgbColor) 44 { 45 RefPtr<SVGColor> color = adoptRef(new SVGColor(SVG_COLORTYPE_RGBCOLOR)); 46 color->setColor(colorFromRGBColorString(rgbColor)); 47 return color.release(); 48 } 57 49 50 static PassRefPtr<SVGColor> createFromColor(const Color& rgbColor) 51 { 52 RefPtr<SVGColor> color = adoptRef(new SVGColor(SVG_COLORTYPE_RGBCOLOR)); 53 color->setColor(rgbColor); 54 return color.release(); 55 } 56 57 static PassRefPtr<SVGColor> createCurrentColor() 58 { 59 return adoptRef(new SVGColor(SVG_COLORTYPE_CURRENTCOLOR)); 60 } 61 62 const Color& color() const { return m_color; } 63 const SVGColorType& colorType() const { return m_colorType; } 58 64 PassRefPtr<RGBColor> rgbColor() const; 59 65 60 66 static Color colorFromRGBColorString(const String&); 61 67 62 void setRGBColor(const String& rgbColor) { ExceptionCode ignored = 0; setRGBColor(rgbColor, ignored); }63 68 void setRGBColor(const String& rgbColor, ExceptionCode&); 64 69 void setRGBColorICCColor(const String& rgbColor, const String& iccColor, ExceptionCode&); 65 70 void setColor(unsigned short colorType, const String& rgbColor, const String& iccColor, ExceptionCode&); 66 71 67 const Color& color() const { return m_color; } 72 protected: 73 friend class CSSComputedStyleDeclaration; 68 74 69 protected: 70 SVGColor(); 71 SVGColor(const String& color); 72 SVGColor(const Color&); 73 75 SVGColor(const SVGColorType&); 76 virtual ~SVGColor() { } 74 77 virtual String cssText() const; 75 78 79 void setColor(const Color& color) { m_color = color; } 80 void setColorType(const SVGColorType& type) { m_colorType = type; } 81 76 82 private: 77 SVGColor(SVGColorType);78 79 static void create(int); // compile-time guard80 81 83 virtual bool isSVGColor() const { return true; } 82 84 83 85 Color m_color; 84 unsigned shortm_colorType;86 SVGColorType m_colorType; 85 87 }; 86 88 … … 89 91 #endif // ENABLE(SVG) 90 92 #endif // SVGColor_h 91 92 // vim:ts=4:noet -
trunk/Source/WebCore/svg/SVGColor.idl
r64579 r79675 23 23 24 24 interface [Conditional=SVG] SVGColor : CSSValue { 25 // Color Types 26 const unsigned short SVG_COLORTYPE_UNKNOWN = 0; 27 const unsigned short SVG_COLORTYPE_RGBCOLOR = 1; 25 const unsigned short SVG_COLORTYPE_UNKNOWN = 0; 26 const unsigned short SVG_COLORTYPE_RGBCOLOR = 1; 28 27 const unsigned short SVG_COLORTYPE_RGBCOLOR_ICCCOLOR = 2; 29 const unsigned short SVG_COLORTYPE_CURRENTCOLOR 28 const unsigned short SVG_COLORTYPE_CURRENTCOLOR = 3; 30 29 31 30 readonly attribute unsigned short colorType; 32 readonly attribute RGBColor 33 / *readonly attribute SVGICCColor iccColor;*/31 readonly attribute RGBColor rgbColor; 32 // FIXME: readonly attribute SVGICCColor iccColor; 34 33 35 void setRGBColor(in DOMString rgbColor) 36 raises(SVGException); 37 void setRGBColorICCColor(in DOMString rgbColor, 38 in DOMString iccColor) 39 raises(SVGException); 40 void setColor(in unsigned short colorType, 41 in DOMString rgbColor, 42 in DOMString iccColor) 43 raises(SVGException); 34 [StrictTypeChecking, RequiresAllArguments=Raise] void setRGBColor(in DOMString rgbColor) 35 raises(DOMException, SVGException); 36 37 [StrictTypeChecking, RequiresAllArguments=Raise] void setRGBColorICCColor(in DOMString rgbColor, in DOMString iccColor) 38 raises(DOMException, SVGException); 39 40 [StrictTypeChecking, RequiresAllArguments=Raise] void setColor(in unsigned short colorType, in DOMString rgbColor, in DOMString iccColor) 41 raises(DOMException, SVGException); 44 42 }; 45 43 -
trunk/Source/WebCore/svg/SVGPaint.cpp
r74493 r79675 2 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> 3 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 4 * Copyright (C) Research In Motion Limited 2010 . All rights reserved.4 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 25 25 #include "SVGPaint.h" 26 26 27 #include "SVGException.h" 27 28 #include "SVGURIReference.h" 29 #include <wtf/text/StringConcatenate.h> 28 30 29 31 namespace WebCore { 30 32 31 SVGPaint::SVGPaint() 32 : m_paintType(SVG_PAINTTYPE_UNKNOWN) 33 static inline SVGColor::SVGColorType colorTypeForPaintType(const SVGPaint::SVGPaintType& paintType) 34 { 35 switch (paintType) { 36 case SVGPaint::SVG_PAINTTYPE_NONE: 37 case SVGPaint::SVG_PAINTTYPE_UNKNOWN: 38 case SVGPaint::SVG_PAINTTYPE_URI: 39 case SVGPaint::SVG_PAINTTYPE_URI_NONE: 40 return SVGColor::SVG_COLORTYPE_UNKNOWN; 41 case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR: 42 case SVGPaint::SVG_PAINTTYPE_RGBCOLOR: 43 return SVGColor::SVG_COLORTYPE_RGBCOLOR; 44 case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: 45 case SVGPaint::SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: 46 return SVGColor::SVG_COLORTYPE_RGBCOLOR_ICCCOLOR; 47 case SVGPaint::SVG_PAINTTYPE_URI_CURRENTCOLOR: 48 case SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR: 49 return SVGColor::SVG_COLORTYPE_CURRENTCOLOR; 50 } 51 52 ASSERT_NOT_REACHED(); 53 return SVGColor::SVG_COLORTYPE_UNKNOWN; 54 } 55 56 SVGPaint::SVGPaint(const SVGPaintType& paintType, String uri) 57 : SVGColor(colorTypeForPaintType(paintType)) 58 , m_paintType(paintType) 59 , m_uri(uri) 33 60 { 34 61 } 35 62 36 SVGPaint::SVGPaint(const String& uri) 37 : m_paintType(SVG_PAINTTYPE_URI_RGBCOLOR) 63 void SVGPaint::setUri(const String& uri) 38 64 { 39 setUri(uri); 40 } 41 42 SVGPaint::SVGPaint(SVGPaintType paintType) 43 : m_paintType(paintType) 44 { 45 } 46 47 SVGPaint::SVGPaint(SVGPaintType paintType, const String& uri, const String& rgbPaint, const String&) 48 : SVGColor(rgbPaint) 49 , m_paintType(paintType) 50 { 51 setUri(uri); 52 } 53 54 SVGPaint::SVGPaint(const Color& c) 55 : SVGColor(c) 56 , m_paintType(SVG_PAINTTYPE_RGBCOLOR) 57 { 58 } 59 60 SVGPaint::SVGPaint(const String& uri, const Color& c) 61 : SVGColor(c) 62 , m_paintType(SVG_PAINTTYPE_URI_RGBCOLOR) 63 { 64 setUri(uri); 65 // Spec: Sets the paintType to SVG_PAINTTYPE_URI_NONE and sets uri to the specified value. 66 m_uri = uri; 67 m_paintType = SVG_PAINTTYPE_URI_NONE; 68 setColor(Color()); 69 setColorType(colorTypeForPaintType(m_paintType)); 70 // FIXME: A follow up patch will call valueChanged() here. 65 71 } 66 72 67 73 SVGPaint* SVGPaint::defaultFill() 68 74 { 69 static SVGPaint* staticDefaultFill = create (Color::black).releaseRef();75 static SVGPaint* staticDefaultFill = createColor(Color::black).releaseRef(); 70 76 return staticDefaultFill; 71 77 } … … 73 79 SVGPaint* SVGPaint::defaultStroke() 74 80 { 75 static SVGPaint* staticDefaultStroke = create (SVG_PAINTTYPE_NONE).releaseRef();81 static SVGPaint* staticDefaultStroke = createNone().releaseRef(); 76 82 return staticDefaultStroke; 77 83 } 78 84 79 String SVGPaint::uri() const 85 void SVGPaint::setPaint(unsigned short paintType, const String& uri, const String& rgbColor, const String& iccColor, ExceptionCode& ec) 80 86 { 81 return m_uri; 82 } 87 if ((paintType > SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR && paintType < SVG_PAINTTYPE_NONE) || paintType > SVG_PAINTTYPE_URI) { 88 ec = SVGException::SVG_WRONG_TYPE_ERR; 89 return; 90 } 83 91 84 void SVGPaint::setUri(const String& uri) 85 { 86 m_uri = uri; 87 } 92 bool requiresURI = false; 88 93 89 void SVGPaint::setPaint(SVGPaintType paintType, const String& uri, const String& rgbPaint, const String&, ExceptionCode&) 90 { 91 m_paintType = paintType; 94 SVGPaintType type = static_cast<SVGPaintType>(paintType); 95 switch (type) { 96 case SVG_PAINTTYPE_UNKNOWN: 97 // Spec: It is invalid to attempt to define a new value of this type or to attempt to switch an existing value to this type. 98 ec = SVGException::SVG_INVALID_VALUE_ERR; 99 return; 100 case SVG_PAINTTYPE_RGBCOLOR: 101 case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: 102 case SVG_PAINTTYPE_NONE: 103 case SVG_PAINTTYPE_CURRENTCOLOR: 104 break; 105 case SVG_PAINTTYPE_URI_NONE: 106 case SVG_PAINTTYPE_URI_CURRENTCOLOR: 107 case SVG_PAINTTYPE_URI_RGBCOLOR: 108 case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: 109 case SVG_PAINTTYPE_URI: 110 requiresURI = true; 111 break; 112 }; 92 113 93 if (m_paintType == SVG_PAINTTYPE_URI) 94 setUri(uri); 95 else if (m_paintType == SVG_PAINTTYPE_RGBCOLOR) 96 setRGBColor(rgbPaint); 114 // Spec: If paintType requires a URI, then uri must be non-null; otherwise, uri must be null. 115 if (requiresURI && uri.isEmpty()) { 116 ec = SVGException::SVG_INVALID_VALUE_ERR; 117 return; 118 } 119 120 SVGColor::SVGColorType colorType = colorTypeForPaintType(type); 121 if (colorType == SVGColor::SVG_COLORTYPE_UNKNOWN) { 122 // The standard setColor() code path used in the else branch 123 // raises an exception when attempting to switch to an unknown color type. 124 // Here we explicitely want to reset to Color() and an unknown type, so force it. 125 setColorType(colorType); 126 setColor(Color()); 127 } else { 128 setColor(colorType, rgbColor, iccColor, ec); 129 if (ec) 130 return; 131 } 132 133 m_paintType = type; 134 m_uri = requiresURI ? uri : String(); 135 // FIXME: A follow up patch will call valueChanged() here. 97 136 } 98 137 99 138 String SVGPaint::cssText() const 100 139 { 101 if (m_paintType == SVG_PAINTTYPE_NONE) 140 switch (m_paintType) { 141 case SVG_PAINTTYPE_UNKNOWN: 142 case SVG_PAINTTYPE_RGBCOLOR: 143 case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: 144 case SVG_PAINTTYPE_CURRENTCOLOR: 145 return SVGColor::cssText(); 146 case SVG_PAINTTYPE_NONE: 102 147 return "none"; 103 if (m_paintType == SVG_PAINTTYPE_CURRENTCOLOR) 104 return "currentColor"; 105 if (m_paintType == SVG_PAINTTYPE_URI) 106 return "url(" + m_uri + ")"; 148 case SVG_PAINTTYPE_URI_NONE: 149 return makeString(m_uri, " none"); 150 case SVG_PAINTTYPE_URI_CURRENTCOLOR: 151 case SVG_PAINTTYPE_URI_RGBCOLOR: 152 case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: { 153 String color = SVGColor::cssText(); 154 if (color.isEmpty()) 155 return m_uri; 156 return makeString(m_uri, ' ', color); 157 } 158 case SVG_PAINTTYPE_URI: 159 return m_uri; 160 }; 107 161 108 return SVGColor::cssText(); 162 ASSERT_NOT_REACHED(); 163 return String(); 109 164 } 110 165 111 166 bool SVGPaint::matchesTargetURI(const String& referenceId) 112 167 { 113 if (m_paintType != SVG_PAINTTYPE_URI && m_paintType != SVG_PAINTTYPE_URI_RGBCOLOR) 168 switch (m_paintType) { 169 case SVG_PAINTTYPE_UNKNOWN: 170 case SVG_PAINTTYPE_RGBCOLOR: 171 case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: 172 case SVG_PAINTTYPE_CURRENTCOLOR: 173 case SVG_PAINTTYPE_NONE: 114 174 return false; 175 case SVG_PAINTTYPE_URI_NONE: 176 case SVG_PAINTTYPE_URI_CURRENTCOLOR: 177 case SVG_PAINTTYPE_URI_RGBCOLOR: 178 case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: 179 case SVG_PAINTTYPE_URI: 180 return referenceId == SVGURIReference::getTarget(m_uri); 181 } 115 182 116 return referenceId == SVGURIReference::getTarget(m_uri); 183 ASSERT_NOT_REACHED(); 184 return false; 117 185 } 118 186 -
trunk/Source/WebCore/svg/SVGPaint.h
r74493 r79675 3 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 4 4 * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmial.com> 5 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 5 6 * 6 7 * This library is free software; you can redistribute it and/or … … 22 23 #ifndef SVGPaint_h 23 24 #define SVGPaint_h 25 24 26 #if ENABLE(SVG) 25 #include "PlatformString.h"26 27 #include "SVGColor.h" 28 #include <wtf/text/WTFString.h> 27 29 28 30 namespace WebCore { … … 43 45 }; 44 46 45 static PassRefPtr<SVGPaint> create ()47 static PassRefPtr<SVGPaint> createUnknown() 46 48 { 47 return adoptRef(new SVGPaint); 48 } 49 static PassRefPtr<SVGPaint> create(SVGPaintType type) 50 { 51 return adoptRef(new SVGPaint(type)); 52 } 53 static PassRefPtr<SVGPaint> create(const Color& color) 54 { 55 return adoptRef(new SVGPaint(color)); 56 } 57 static PassRefPtr<SVGPaint> create(SVGPaintType type, const String& uri) 58 { 59 return adoptRef(new SVGPaint(type, uri, String(), String())); 60 } 61 static PassRefPtr<SVGPaint> create(const String& uri, const Color& color) 62 { 63 return adoptRef(new SVGPaint(uri, color)); 49 return adoptRef(new SVGPaint(SVG_PAINTTYPE_UNKNOWN)); 64 50 } 65 51 66 // 'SVGPaint' functions 67 SVGPaintType paintType() const { return m_paintType; } 68 String uri() const; 52 static PassRefPtr<SVGPaint> createNone() 53 { 54 return adoptRef(new SVGPaint(SVG_PAINTTYPE_NONE)); 55 } 56 57 static PassRefPtr<SVGPaint> createCurrentColor() 58 { 59 return adoptRef(new SVGPaint(SVG_PAINTTYPE_CURRENTCOLOR)); 60 } 61 62 static PassRefPtr<SVGPaint> createColor(const Color& color) 63 { 64 RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_RGBCOLOR)); 65 paint->setColor(color); 66 return paint.release(); 67 } 68 69 static PassRefPtr<SVGPaint> createURI(const String& uri) 70 { 71 RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_URI, uri)); 72 return paint.release(); 73 } 74 75 static PassRefPtr<SVGPaint> createURIAndColor(const String& uri, const Color& color) 76 { 77 RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(SVG_PAINTTYPE_URI_RGBCOLOR, uri)); 78 paint->setColor(color); 79 return paint.release(); 80 } 81 82 const SVGPaintType& paintType() const { return m_paintType; } 83 String uri() const { return m_uri; } 69 84 70 85 void setUri(const String&); 71 void setPaint(SVGPaintType, const String& uri, const String& rgbPaint, const String& iccPaint, ExceptionCode&); 72 86 void setPaint(unsigned short paintType, const String& uri, const String& rgbColor, const String& iccColor, ExceptionCode&); 87 88 bool matchesTargetURI(const String& referenceId); 89 73 90 static SVGPaint* defaultFill(); 74 91 static SVGPaint* defaultStroke(); 75 92 76 bool matchesTargetURI(const String& referenceId); 93 private: 94 friend class CSSComputedStyleDeclaration; 95 96 static PassRefPtr<SVGPaint> create(const SVGPaintType& type, const String& uri, const Color& color) 97 { 98 RefPtr<SVGPaint> paint = adoptRef(new SVGPaint(type, uri)); 99 paint->setColor(color); 100 return paint.release(); 101 } 77 102 78 103 private: 79 SVGPaint(); 80 SVGPaint(const String& uri); 81 SVGPaint(SVGPaintType); 82 SVGPaint(SVGPaintType, const String& uri, const String& rgbPaint, const String& iccPaint); 83 SVGPaint(const Color& c); 84 SVGPaint(const String& uri, const Color& c); 104 SVGPaint(const SVGPaintType&, String uri = String()); 85 105 86 106 virtual bool isSVGPaint() const { return true; } 87 88 107 virtual String cssText() const; 89 108 -
trunk/Source/WebCore/svg/SVGPaint.idl
r64579 r79675 27 27 28 28 interface [Conditional=SVG] SVGPaint : SVGColor { 29 // SVGPaintType 30 const unsigned short SVG_PAINTTYPE_UNKNOWN = 0; 31 const unsigned short SVG_PAINTTYPE_RGBCOLOR = 1; 32 const unsigned short SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR = 2; 33 const unsigned short SVG_PAINTTYPE_NONE = 101; 34 const unsigned short SVG_PAINTTYPE_CURRENTCOLOR = 102; 35 const unsigned short SVG_PAINTTYPE_URI_NONE = 103; 36 const unsigned short SVG_PAINTTYPE_URI_CURRENTCOLOR = 104; 37 const unsigned short SVG_PAINTTYPE_URI_RGBCOLOR = 105; 29 const unsigned short SVG_PAINTTYPE_UNKNOWN = 0; 30 const unsigned short SVG_PAINTTYPE_RGBCOLOR = 1; 31 const unsigned short SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR = 2; 32 const unsigned short SVG_PAINTTYPE_NONE = 101; 33 const unsigned short SVG_PAINTTYPE_CURRENTCOLOR = 102; 34 const unsigned short SVG_PAINTTYPE_URI_NONE = 103; 35 const unsigned short SVG_PAINTTYPE_URI_CURRENTCOLOR = 104; 36 const unsigned short SVG_PAINTTYPE_URI_RGBCOLOR = 105; 38 37 const unsigned short SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR = 106; 39 const unsigned short SVG_PAINTTYPE_URI 38 const unsigned short SVG_PAINTTYPE_URI = 107; 40 39 41 readonly attribute SVGPaintTypepaintType;40 readonly attribute unsigned short paintType; 42 41 readonly attribute DOMString uri; 43 42 44 void setUri(in DOMString uri); 45 void setPaint(in SVGPaintType paintType, 46 in DOMString uri, 47 in DOMString rgbColor, 48 in DOMString iccColor) 49 raises(SVGException); 43 [StrictTypeChecking, RequiresAllArguments=Raise] void setUri(in DOMString uri); 44 [StrictTypeChecking, RequiresAllArguments=Raise] void setPaint(in unsigned short paintType, in DOMString uri, in DOMString rgbColor, in DOMString iccColor) 45 raises(DOMException, SVGException); 50 46 }; 51 47
Note: See TracChangeset
for help on using the changeset viewer.