Changeset 79675 in webkit


Ignore:
Timestamp:
Feb 25, 2011 5:08:26 AM (13 years ago)
Author:
Nikolas Zimmermann
Message:

2011-02-25 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Dirk Schulze.

Implement SVGColor/SVGPaint API
https://bugs.webkit.org/show_bug.cgi?id=55119

SVGColor::cssText() shouldn't return #RRGGBBAA colors
https://bugs.webkit.org/show_bug.cgi?id=48120

Rewrite SVGColor/SVGPaint to actually implement their desired setPaint/setColor/setURI APIs.
SVGPaint is a CSSValue, and its setPaint() function allows to switch to an arbitary paint type.
That means, unlike all other CSSValues, SVGColor/SVGPaint are mutable. That means changes to
their CSSValues should be reflected in the elements style as well as in the computed style.
This patch doesn't yet implement that, the stubbed-out method valueChanged() is what
needs to be implemented. For now you can grab a SVGColor/SVGPaint object through getCSSPropertyValue
and manipulate it, in every possible way (SVPaint.uri/paintType/colorType/color attributes are all sync'ed).
Switch to strict JS bindings (RequiresAllArguments=Raise, StrictTypeChecking) for both objects.

Enable proper serialization of colors through Color::serialized(), affects some testcases (#FF.. -> #ff..)
Add extensive tests of all SVGColor/SVGPaint API, currently shows some FAIL messages, as element style
<-> computed style is not live, after mutating SVGColor/SVGPaint. That will be implemented in a follow-up patch.

Tests: svg/dom/SVGColor.html

svg/dom/SVGPaint.html

  • bindings/scripts/CodeGenerator.pm: Remove obsolete handling of "SVGPaintType", take ushort for paintType, as specified in the SVG 1.1 IDLs.
  • bindings/scripts/CodeGeneratorJS.pm: Ditto.
  • bindings/scripts/CodeGeneratorObjC.pm: Ditto.
  • bindings/scripts/CodeGeneratorV8.pm: Ditto.
  • css/SVGCSSParser.cpp: Adapt to SVGPaint/SVGColor create() naming convention changes. (WebCore::CSSParser::parseSVGValue): (WebCore::CSSParser::parseSVGPaint): (WebCore::CSSParser::parseSVGColor):
  • svg/SVGColor.cpp: Rewrite to fully implement the SVGColor API, merge all constructors into one, use more descriptable create() naming convention. (WebCore::valueChanged): Stub implementation, will land in a follow-up patch. (WebCore::SVGColor::SVGColor): (WebCore::SVGColor::setRGBColor): (WebCore::SVGColor::colorFromRGBColorString): (WebCore::SVGColor::setRGBColorICCColor): (WebCore::SVGColor::setColor): (WebCore::SVGColor::cssText):
  • svg/SVGColor.h: (WebCore::SVGColor::createFromString): (WebCore::SVGColor::createFromColor): (WebCore::SVGColor::color): (WebCore::SVGColor::colorType): (WebCore::SVGColor::~SVGColor): (WebCore::SVGColor::setColor): (WebCore::SVGColor::setColorType):
  • svg/SVGColor.idl: Enable strict type checking.
  • svg/SVGPaint.cpp: Rewrite to fully implement the SVGPaint API, merge all constructors into one, use more descriptable create() naming convention. (WebCore::valueChanged): Stub implementation, will land in a follow-up patch. (WebCore::colorTypeForPaintType): (WebCore::SVGPaint::SVGPaint): (WebCore::SVGPaint::setUri): (WebCore::SVGPaint::defaultFill): (WebCore::SVGPaint::defaultStroke): (WebCore::SVGPaint::setPaint): (WebCore::SVGPaint::cssText): (WebCore::SVGPaint::matchesTargetURI):
  • svg/SVGPaint.h: (WebCore::SVGPaint::createUnknown): (WebCore::SVGPaint::createNone): (WebCore::SVGPaint::createCurrentColor): (WebCore::SVGPaint::createColor): (WebCore::SVGPaint::createURI): (WebCore::SVGPaint::createURIAndColor): (WebCore::SVGPaint::paintType): (WebCore::SVGPaint::uri): (WebCore::SVGPaint::create): (WebCore::SVGPaint::isSVGPaint):
  • svg/SVGPaint.idl: Enable strict type checking.

2011-02-25 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Dirk Schulze.

Implement SVGColor/SVGPaint API
https://bugs.webkit.org/show_bug.cgi?id=55119

SVGColor::cssText() shouldn't return #RRGGBBAA colors
https://bugs.webkit.org/show_bug.cgi?id=48120

Add two new tests covering the SVGColor/SVGPaint APIs.
Adapt to SVGColor::cssText() changes, color is properly serialized now.

  • svg/animations/animate-color-transparent-expected.txt:
  • svg/animations/animate-currentColor-expected.txt:
  • svg/animations/animate-dynamic-update-attributeName-expected.txt:
  • svg/animations/animate-inherit-css-property-expected.txt:
  • svg/animations/script-tests/animate-color-transparent.js: (expectTransparent): (expectOtherColor):
  • svg/animations/script-tests/animate-currentColor.js: (sample1):
  • svg/animations/script-tests/animate-inherit-css-property.js: (sample1):
  • svg/css/getComputedStyle-basic-expected.txt:
  • svg/custom/getPresentationAttribute-modify.svg:
  • svg/custom/rgbcolor-syntax.svg:
  • svg/dom/SVGColor-expected.txt: Added.
  • svg/dom/SVGColor.html: Added.
  • svg/dom/SVGPaint-expected.txt: Added.
  • svg/dom/SVGPaint.html: Added.
  • svg/dom/script-tests/SVGColor.js: Added. (checkStopColor):
  • svg/dom/script-tests/SVGPaint.js: Added. (resetStyle): (checkFillColor):
Location:
trunk
Files:
6 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r79674 r79675  
     12011-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
    1382011-02-25  Renata Hodovan  <reni@webkit.org>
    239
  • trunk/LayoutTests/svg/animations/animate-color-transparent-expected.txt

    r70236 r79675  
    66
    77
    8 PASS rect.style.fill is '#00FF00'
    9 PASS rect.style.fill is '#7F0000'
     8PASS rect.style.fill is '#00ff00'
     9PASS rect.style.fill is '#7f0000'
    1010PASS successfullyParsed is true
    1111
  • trunk/LayoutTests/svg/animations/animate-currentColor-expected.txt

    r78543 r79675  
    66
    77
    8 PASS rect.style.fill is '#FF0000'
     8PASS rect.style.fill is '#ff0000'
    99PASS rect.style.fill is '#804000'
    1010PASS rect.style.fill is '#008000'
  • trunk/LayoutTests/svg/animations/animate-dynamic-update-attributeName-expected.txt

    r79155 r79675  
    77
    88PASS rect.style.color is 'rgb(0, 128, 0)'
    9 FAIL rect.style.fill should be #008000. Was #FF0000.
     9FAIL rect.style.fill should be #008000. Was #ff0000.
    1010PASS successfullyParsed is true
    1111
  • trunk/LayoutTests/svg/animations/animate-inherit-css-property-expected.txt

    r78543 r79675  
    66
    77
    8 PASS rect.style.fill is '#FF0000'
     8PASS rect.style.fill is '#ff0000'
    99PASS rect.style.fill is '#804000'
    1010PASS rect.style.fill is '#008000'
  • trunk/LayoutTests/svg/animations/script-tests/animate-color-transparent.js

    r70236 r79675  
    2222function expectTransparent() {
    2323    // Check initial/end conditions
    24     shouldBe("rect.style.fill", "'#00FF00'");
     24    shouldBe("rect.style.fill", "'#00ff00'");
    2525}
    2626
    2727function expectOtherColor() {
    2828    // Check half-time conditions
    29     shouldBe("rect.style.fill", "'#7F0000'");
     29    shouldBe("rect.style.fill", "'#7f0000'");
    3030}
    3131
  • trunk/LayoutTests/svg/animations/script-tests/animate-currentColor.js

    r78543 r79675  
    2424function sample1() {
    2525    // Check initial/end conditions
    26     shouldBe("rect.style.fill", "'#FF0000'");
     26    shouldBe("rect.style.fill", "'#ff0000'");
    2727}
    2828
  • trunk/LayoutTests/svg/animations/script-tests/animate-inherit-css-property.js

    r78543 r79675  
    2727function sample1() {
    2828    // Check initial/end conditions
    29     shouldBe("rect.style.fill", "'#FF0000'");
     29    shouldBe("rect.style.fill", "'#ff0000'");
    3030}
    3131
  • trunk/LayoutTests/svg/css/getComputedStyle-basic-expected.txt

    r74538 r79675  
    373373rect: style.getPropertyValue(color-rendering) : auto
    374374rect: style.getPropertyCSSValue(color-rendering) : [object CSSPrimitiveValue]
    375 rect: style.getPropertyValue(fill) : #0000FF
     375rect: style.getPropertyValue(fill) : #0000ff
    376376rect: style.getPropertyCSSValue(fill) : [object SVGPaint]
    377377rect: style.getPropertyValue(fill-opacity) : 1
     
    389389rect: style.getPropertyValue(shape-rendering) : auto
    390390rect: style.getPropertyCSSValue(shape-rendering) : [object CSSPrimitiveValue]
    391 rect: style.getPropertyValue(stroke) : #FFA500
     391rect: style.getPropertyValue(stroke) : #ffa500
    392392rect: style.getPropertyCSSValue(stroke) : [object SVGPaint]
    393393rect: style.getPropertyValue(stroke-dasharray) : none
     
    815815g: style.getPropertyValue(shape-rendering) : auto
    816816g: style.getPropertyCSSValue(shape-rendering) : [object CSSPrimitiveValue]
    817 g: style.getPropertyValue(stroke) : #FFA500
     817g: style.getPropertyValue(stroke) : #ffa500
    818818g: style.getPropertyCSSValue(stroke) : [object SVGPaint]
    819819g: style.getPropertyValue(stroke-dasharray) : none
  • trunk/LayoutTests/svg/custom/getPresentationAttribute-modify.svg

    r34448 r79675  
    2323        rect = document.getElementById("firstrect");
    2424        fill = rect.getPresentationAttribute("fill");
    25         if (fill.cssText != '#FF0000') {
     25        if (fill.cssText != '#ff0000') {
    2626            log("Changing fill PA should not change firstrect fill PA");
    2727            return;
  • trunk/LayoutTests/svg/custom/rgbcolor-syntax.svg

    r75408 r79675  
    4646        if (!expectsException(col, "#fffffff")) return;
    4747        if (!expectsException(col, "green,")) 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;
     48        if (!expectsValid(col, "rgb(0, 10, 20)", "#000a14")) return;
     49        if (!expectsValid(col, "#FFF", "#ffffff")) return;
     50        if (!expectsValid(col, "#FFFFFF", "#ffffff")) return;
    5151        if (!expectsValid(col, " green", "#008000")) return;
    5252        if (!expectsValid(col, "green ", "#008000")) return;
  • trunk/Source/WebCore/ChangeLog

    r79674 r79675  
     12011-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
    1752011-02-25  Renata Hodovan  <reni@webkit.org>
    276
  • trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm

    r73011 r79675  
    5353my %stringTypeHash = ("DOMString" => 1, "AtomicString" => 1);
    5454
    55 my %nonPointerTypeHash = ("DOMTimeStamp" => 1, "CompareHow" => 1, "SVGPaintType" => 1);
     55my %nonPointerTypeHash = ("DOMTimeStamp" => 1, "CompareHow" => 1);
    5656
    5757my %svgAnimatedTypeHash = ("SVGAnimatedAngle" => 1, "SVGAnimatedBoolean" => 1,
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r79616 r79675  
    23702370    "SerializedScriptValue" => "RefPtr<SerializedScriptValue>",
    23712371    "IDBKey" => "RefPtr<IDBKey>",
    2372     "SVGPaintType" => "SVGPaint::SVGPaintType",
    23732372    "boolean" => "bool",
    23742373    "double" => "double",
     
    24572456    return "valueToDate(exec, $value)" if $type eq "Date";
    24582457    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";
    24602458
    24612459    if ($type eq "DOMString") {
     
    25162514    }
    25172515
    2518     if ($codeGenerator->IsPrimitiveType($type) or $type eq "SVGPaintType" or $type eq "DOMTimeStamp") {
     2516    if ($codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp") {
    25192517        $implIncludes{"<runtime/JSNumberCell.h>"} = 1;
    25202518        return "jsNumber($value)";
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorObjC.pm

    r73011 r79675  
    475475    return "id <$name>" if IsProtocolType($type);
    476476    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";
    478478    return "$name *";
    479479}
     
    493493    } elsif ($codeGenerator->IsSVGAnimatedType($type)) {
    494494        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") {
    496496        push(@attributes, "retain");
    497497    }
     
    516516    return $argName . "Node" if $type eq "EventTarget";
    517517    return "static_cast<WebCore::Range::CompareHow>($argName)" if $type eq "CompareHow";
    518     return "static_cast<WebCore::SVGPaint::SVGPaintType>($argName)" if $type eq "SVGPaintType";
    519518    return "WTF::getPtr(nativeEventListener)" if $type eq "EventListener";
    520519    return "WTF::getPtr(nativeNodeFilter)" if $type eq "NodeFilter";
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r79223 r79675  
    28052805    return "String" if $type eq "DOMString";
    28062806    return "Range::CompareHow" if $type eq "CompareHow";
    2807     return "SVGPaint::SVGPaintType" if $type eq "SVGPaintType";
    28082807    return "DOMTimeStamp" if $type eq "DOMTimeStamp";
    28092808    return "unsigned" if $type eq "unsigned int";
     
    28822881    return "toInt64($value)" if $type eq "unsigned long long" or $type eq "long long";
    28832882    return "static_cast<Range::CompareHow>($value->Int32Value())" if $type eq "CompareHow";
    2884     return "static_cast<SVGPaint::SVGPaintType>($value->ToInt32()->Int32Value())" if $type eq "SVGPaintType";
    28852883    return "toWebCoreDate($value)" if $type eq "Date";
    28862884    return "v8ValueToWebCoreDOMStringList($value)" if $type eq "DOMStringList";
     
    30363034    'CompareHow' => 1,
    30373035    'SerializedScriptValue' => 1,
    3038     'SVGPaintType' => 1,
    30393036    'DOMTimeStamp' => 1,
    30403037    'JSObject' => 1,
     
    31133110    # long long and unsigned long long are not representable in ECMAScript.
    31143111    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);
    31163113    return "$value.v8Value()" if $nativeType eq "ScriptValue";
    31173114
  • trunk/Source/WebCore/css/SVGCSSParser.cpp

    r67695 r79675  
    180180        {
    181181            if (id == CSSValueNone)
    182                 parsedValue = SVGPaint::create(SVGPaint::SVG_PAINTTYPE_NONE);
     182                parsedValue = SVGPaint::createNone();
    183183            else if (id == CSSValueCurrentcolor)
    184                 parsedValue = SVGPaint::create(SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR);
     184                parsedValue = SVGPaint::createCurrentColor();
    185185            else if ((id >= CSSValueActiveborder && id <= CSSValueWindowtext) || id == CSSValueMenu)
    186                 parsedValue = SVGPaint::create(RenderTheme::defaultTheme()->systemColor(id));
     186                parsedValue = SVGPaint::createColor(RenderTheme::defaultTheme()->systemColor(id));
    187187            else if (value->unit == CSSPrimitiveValue::CSS_URI) {
    188188                RGBA32 c = Color::transparent;
    189189                if (m_valueList->next() && parseColorFromValue(m_valueList->current(), c)) {
    190                     parsedValue = SVGPaint::create(value->string, c);
     190                    parsedValue = SVGPaint::createURIAndColor(value->string, c);
    191191                } else
    192                     parsedValue = SVGPaint::create(SVGPaint::SVG_PAINTTYPE_URI, value->string);
     192                    parsedValue = SVGPaint::createURI(value->string);
    193193            } else
    194194                parsedValue = parseSVGPaint();
     
    202202        if ((id >= CSSValueAqua && id <= CSSValueWindowtext) ||
    203203           (id >= CSSValueAliceblue && id <= CSSValueYellowgreen))
    204             parsedValue = SVGColor::create(value->string);
     204            parsedValue = SVGColor::createFromString(value->string);
    205205        else
    206206            parsedValue = parseSVGColor();
     
    215215        if ((id >= CSSValueAqua && id <= CSSValueWindowtext) ||
    216216           (id >= CSSValueAliceblue && id <= CSSValueYellowgreen))
    217             parsedValue = SVGColor::create(value->string);
     217            parsedValue = SVGColor::createFromString(value->string);
    218218        else if (id == CSSValueCurrentcolor)
    219219            parsedValue = SVGColor::createCurrentColor();
     
    340340    RGBA32 c = Color::transparent;
    341341    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));
    344344}
    345345
     
    349349    if (!parseColorFromValue(m_valueList->current(), c))
    350350        return 0;
    351     return SVGColor::create(Color(c));
     351    return SVGColor::createFromColor(Color(c));
    352352}
    353353
     
    355355
    356356#endif // ENABLE(SVG)
    357 
    358 // vim:ts=4:noet
  • trunk/Source/WebCore/svg/SVGColor.cpp

    r78590 r79675  
    22 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
    33 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
     4 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
    45 *
    56 * This library is free software; you can redistribute it and/or
     
    2021
    2122#include "config.h"
     23
    2224#if ENABLE(SVG)
    2325#include "SVGColor.h"
     
    2931namespace WebCore {
    3032
    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)
     33SVGColor::SVGColor(const SVGColorType& colorType)
    4334    : m_colorType(colorType)
    44 {
    45 }
    46 
    47 SVGColor::SVGColor(const Color& c)
    48     : m_color(c)
    49     , m_colorType(SVG_COLORTYPE_RGBCOLOR)
    5035{
    5136}
     
    5944{
    6045    Color color = SVGColor::colorFromRGBColorString(rgbColor);
    61     if (color.isValid())
    62         m_color = color;
    63     else
     46    if (!color.isValid()) {
    6447        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.
    6554}
    6655
    6756Color SVGColor::colorFromRGBColorString(const String& colorString)
    6857{
    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.
    7159    RGBA32 color;
    72     if (CSSParser::parseColor(color, s))
     60    if (CSSParser::parseColor(color, colorString.stripWhiteSpace()))
    7361        return color;
    7462    return Color();
    7563}
    7664
    77 void SVGColor::setRGBColorICCColor(const String& /* rgbColor */, const String& /* iccColor */, ExceptionCode&)
     65void SVGColor::setRGBColorICCColor(const String& rgbColor, const String& iccColor, ExceptionCode& ec)
    7866{
    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.
    8079}
    8180
    82 void SVGColor::setColor(unsigned short colorType, const String& /* rgbColor */ , const String& /* iccColor */, ExceptionCode&)
     81void SVGColor::setColor(unsigned short colorType, const String& rgbColor, const String& iccColor, ExceptionCode& ec)
    8382{
    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);
    86130}
    87131
    88132String SVGColor::cssText() const
    89133{
    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";
    93145    }
    94146
     147    ASSERT_NOT_REACHED();
    95148    return String();
    96149}
     
    98151}
    99152
    100 // vim:ts=4:noet
    101153#endif // ENABLE(SVG)
    102 
  • trunk/Source/WebCore/svg/SVGColor.h

    r74472 r79675  
    22 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
    33 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
     4 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
    45 *
    56 * This library is free software; you can redistribute it and/or
     
    2122#ifndef SVGColor_h
    2223#define SVGColor_h
     24
    2325#if ENABLE(SVG)
    24 
    2526#include "CSSValue.h"
    2627#include "Color.h"
     
    3334class SVGColor : public CSSValue {
    3435public:
    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 
    4836    enum SVGColorType {
    4937        SVG_COLORTYPE_UNKNOWN = 0,
     
    5341    };
    5442
    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    }
    5749
     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; }
    5864    PassRefPtr<RGBColor> rgbColor() const;
    5965
    6066    static Color colorFromRGBColorString(const String&);
    6167
    62     void setRGBColor(const String& rgbColor) { ExceptionCode ignored = 0; setRGBColor(rgbColor, ignored); }
    6368    void setRGBColor(const String& rgbColor, ExceptionCode&);
    6469    void setRGBColorICCColor(const String& rgbColor, const String& iccColor, ExceptionCode&);
    6570    void setColor(unsigned short colorType, const String& rgbColor, const String& iccColor, ExceptionCode&);
    6671
    67     const Color& color() const { return m_color; }
     72protected:
     73    friend class CSSComputedStyleDeclaration;
    6874
    69 protected:
    70     SVGColor();
    71     SVGColor(const String& color);
    72     SVGColor(const Color&);
    73 
     75    SVGColor(const SVGColorType&);
     76    virtual ~SVGColor() { }
    7477    virtual String cssText() const;
    7578
     79    void setColor(const Color& color) { m_color = color; }
     80    void setColorType(const SVGColorType& type) { m_colorType = type; }
     81
    7682private:
    77     SVGColor(SVGColorType);
    78 
    79     static void create(int); // compile-time guard
    80 
    8183    virtual bool isSVGColor() const { return true; }
    8284
    8385    Color m_color;
    84     unsigned short m_colorType;
     86    SVGColorType m_colorType;
    8587};
    8688
     
    8991#endif // ENABLE(SVG)
    9092#endif // SVGColor_h
    91 
    92 // vim:ts=4:noet
  • trunk/Source/WebCore/svg/SVGColor.idl

    r64579 r79675  
    2323
    2424    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;
    2827        const unsigned short SVG_COLORTYPE_RGBCOLOR_ICCCOLOR = 2;
    29         const unsigned short SVG_COLORTYPE_CURRENTCOLOR      = 3;
     28        const unsigned short SVG_COLORTYPE_CURRENTCOLOR = 3;
    3029
    3130        readonly attribute unsigned short colorType;
    32         readonly attribute RGBColor  rgbColor;
    33         /*readonly attribute SVGICCColor    iccColor;*/
     31        readonly attribute RGBColor rgbColor;
     32        // FIXME: readonly attribute SVGICCColor iccColor;
    3433
    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);
    4442    };
    4543
  • trunk/Source/WebCore/svg/SVGPaint.cpp

    r74493 r79675  
    22 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
    33 * 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.
    55 *
    66 * This library is free software; you can redistribute it and/or
     
    2525#include "SVGPaint.h"
    2626
     27#include "SVGException.h"
    2728#include "SVGURIReference.h"
     29#include <wtf/text/StringConcatenate.h>
    2830
    2931namespace WebCore {
    3032
    31 SVGPaint::SVGPaint()
    32     : m_paintType(SVG_PAINTTYPE_UNKNOWN)
     33static 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
     56SVGPaint::SVGPaint(const SVGPaintType& paintType, String uri)
     57    : SVGColor(colorTypeForPaintType(paintType))
     58    , m_paintType(paintType)
     59    , m_uri(uri)
    3360{
    3461}
    3562
    36 SVGPaint::SVGPaint(const String& uri)
    37     : m_paintType(SVG_PAINTTYPE_URI_RGBCOLOR)
     63void SVGPaint::setUri(const String& uri)
    3864{
    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.
    6571}
    6672
    6773SVGPaint* SVGPaint::defaultFill()
    6874{
    69     static SVGPaint* staticDefaultFill = create(Color::black).releaseRef();
     75    static SVGPaint* staticDefaultFill = createColor(Color::black).releaseRef();
    7076    return staticDefaultFill;
    7177}
     
    7379SVGPaint* SVGPaint::defaultStroke()
    7480{
    75     static SVGPaint* staticDefaultStroke = create(SVG_PAINTTYPE_NONE).releaseRef();
     81    static SVGPaint* staticDefaultStroke = createNone().releaseRef();
    7682    return staticDefaultStroke;
    7783}
    7884
    79 String SVGPaint::uri() const
     85void SVGPaint::setPaint(unsigned short paintType, const String& uri, const String& rgbColor, const String& iccColor, ExceptionCode& ec)
    8086{
    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    }
    8391
    84 void SVGPaint::setUri(const String& uri)
    85 {
    86     m_uri = uri;
    87 }
     92    bool requiresURI = false;
    8893
    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    };
    92113
    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.
    97136}
    98137
    99138String SVGPaint::cssText() const
    100139{
    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:
    102147        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    };
    107161
    108     return SVGColor::cssText();
     162    ASSERT_NOT_REACHED();
     163    return String();
    109164}
    110165
    111166bool SVGPaint::matchesTargetURI(const String& referenceId)
    112167{
    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:
    114174        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    }
    115182
    116     return referenceId == SVGURIReference::getTarget(m_uri);
     183    ASSERT_NOT_REACHED();
     184    return false;
    117185}
    118186
  • trunk/Source/WebCore/svg/SVGPaint.h

    r74493 r79675  
    33 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
    44 * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmial.com>
     5 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
    56 *
    67 * This library is free software; you can redistribute it and/or
     
    2223#ifndef SVGPaint_h
    2324#define SVGPaint_h
     25
    2426#if ENABLE(SVG)
    25 #include "PlatformString.h"
    2627#include "SVGColor.h"
     28#include <wtf/text/WTFString.h>
    2729
    2830namespace WebCore {
     
    4345    };
    4446
    45     static PassRefPtr<SVGPaint> create()
     47    static PassRefPtr<SVGPaint> createUnknown()
    4648    {
    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));
    6450    }
    6551
    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; }
    6984
    7085    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
    7390    static SVGPaint* defaultFill();
    7491    static SVGPaint* defaultStroke();
    7592
    76     bool matchesTargetURI(const String& referenceId);
     93private:
     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    }
    77102
    78103private:
    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());
    85105
    86106    virtual bool isSVGPaint() const { return true; }
    87 
    88107    virtual String cssText() const;
    89108
  • trunk/Source/WebCore/svg/SVGPaint.idl

    r64579 r79675  
    2727
    2828    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;
    3837        const unsigned short SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR = 106;
    39         const unsigned short SVG_PAINTTYPE_URI                   = 107;
     38        const unsigned short SVG_PAINTTYPE_URI = 107;
    4039
    41         readonly attribute SVGPaintType paintType;
     40        readonly attribute unsigned short paintType;
    4241        readonly attribute DOMString uri;
    4342
    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);
    5046    };
    5147
Note: See TracChangeset for help on using the changeset viewer.