Changeset 112391 in webkit


Ignore:
Timestamp:
Mar 28, 2012 6:14:20 AM (12 years ago)
Author:
Nikolas Zimmermann
Message:

Enable animVal support for SVGAnimatedPreserveAspectRatio
https://bugs.webkit.org/show_bug.cgi?id=82326

Reviewed by Zoltan Herczeg.

Source/WebCore:

Enable animVal support for SVGAnimatedPreserveAspectRatio. Very simple now that everything is prepared.
All we have to do is add startAnimValAnimation/etc. methods to SVGAnimatedPreserveAspectRatioAnimator.

Modernize SVGPreserveAspectRatio, align parsing this object from String, with the other SVG DOM primitives,
who supply a "void parse(const String&)" method, for this task.

Extended existing tests to cover this.

  • svg/SVGAnimatedPreserveAspectRatio.cpp:

(WebCore::SVGAnimatedPreserveAspectRatioAnimator::constructFromString):
(WebCore::SVGAnimatedPreserveAspectRatioAnimator::startAnimValAnimation):
(WebCore::SVGAnimatedPreserveAspectRatioAnimator::stopAnimValAnimation):
(WebCore::SVGAnimatedPreserveAspectRatioAnimator::resetAnimValToBaseVal):
(WebCore::SVGAnimatedPreserveAspectRatioAnimator::animValWillChange):
(WebCore::SVGAnimatedPreserveAspectRatioAnimator::animValDidChange):

  • svg/SVGAnimatedPreserveAspectRatio.h:

(SVGAnimatedPreserveAspectRatioAnimator):

  • svg/SVGAnimatedType.cpp:

(WebCore::SVGAnimatedType::valueAsString):
(WebCore::SVGAnimatedType::setValueAsString):
(WebCore::SVGAnimatedType::supportsAnimVal):

  • svg/SVGFEImageElement.cpp:

(WebCore::SVGFEImageElement::parseAttribute):

  • svg/SVGFitToViewBox.cpp:

(WebCore::SVGFitToViewBox::parseAttribute):

  • svg/SVGImageElement.cpp:

(WebCore::SVGImageElement::parseAttribute):

  • svg/SVGPreserveAspectRatio.cpp:

(WebCore::SVGPreserveAspectRatio::parse):
(WebCore):

  • svg/SVGPreserveAspectRatio.h:

(SVGPreserveAspectRatio):

  • svg/SVGViewSpec.cpp:

(WebCore::SVGViewSpec::setPreserveAspectRatioString):
(WebCore::SVGViewSpec::parseViewSpec):

LayoutTests:

Extend SVGAnimatedPreserveAspectRatio tests to cover animVal support.

  • svg/animations/script-tests/svgPreserveAspectRatio-animation-1.js:

(sample1):
(sample2):
(sample3):

  • svg/animations/svgPreserveAspectRatio-animation-1-expected.txt:
  • svg/dom/preserve-aspect-ratio-parser-expected.txt:
  • svg/dom/preserve-aspect-ratio-parser.html: Parsing errors now yield to 'unknown' pAR values, as desired.
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r112387 r112391  
     12012-03-27  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Enable animVal support for SVGAnimatedPreserveAspectRatio
     4        https://bugs.webkit.org/show_bug.cgi?id=82326
     5
     6        Reviewed by Zoltan Herczeg.
     7
     8        Extend SVGAnimatedPreserveAspectRatio tests to cover animVal support.
     9
     10        * svg/animations/script-tests/svgPreserveAspectRatio-animation-1.js:
     11        (sample1):
     12        (sample2):
     13        (sample3):
     14        * svg/animations/svgPreserveAspectRatio-animation-1-expected.txt:
     15        * svg/dom/preserve-aspect-ratio-parser-expected.txt:
     16        * svg/dom/preserve-aspect-ratio-parser.html: Parsing errors now yield to 'unknown' pAR values, as desired.
     17
    1182012-03-28  Alexis Menard  <alexis.menard@openbossa.org>
    219
  • trunk/LayoutTests/svg/animations/script-tests/svgPreserveAspectRatio-animation-1.js

    r110574 r112391  
    2727    shouldBe("rootSVGElement.preserveAspectRatio.animVal.align", "SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN");
    2828    shouldBe("rootSVGElement.preserveAspectRatio.animVal.meetOrSlice", "SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET");
     29
     30    shouldBe("rootSVGElement.preserveAspectRatio.baseVal.align", "SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN");
     31    shouldBe("rootSVGElement.preserveAspectRatio.baseVal.meetOrSlice", "SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET");
    2932}
    3033
     
    3235    shouldBe("rootSVGElement.preserveAspectRatio.animVal.align", "SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN");
    3336    shouldBe("rootSVGElement.preserveAspectRatio.animVal.meetOrSlice", "SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET");
     37
     38    shouldBe("rootSVGElement.preserveAspectRatio.baseVal.align", "SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN");
     39    shouldBe("rootSVGElement.preserveAspectRatio.baseVal.meetOrSlice", "SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET");
    3440}
    3541
     
    3743    shouldBe("rootSVGElement.preserveAspectRatio.animVal.align", "SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMID");
    3844    shouldBe("rootSVGElement.preserveAspectRatio.animVal.meetOrSlice", "SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE");
     45
     46    shouldBe("rootSVGElement.preserveAspectRatio.baseVal.align", "SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN");
     47    shouldBe("rootSVGElement.preserveAspectRatio.baseVal.meetOrSlice", "SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET");
    3948}
    4049
  • trunk/LayoutTests/svg/animations/svgPreserveAspectRatio-animation-1-expected.txt

    r89833 r112391  
    88PASS rootSVGElement.preserveAspectRatio.animVal.align is SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN
    99PASS rootSVGElement.preserveAspectRatio.animVal.meetOrSlice is SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET
     10PASS rootSVGElement.preserveAspectRatio.baseVal.align is SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN
     11PASS rootSVGElement.preserveAspectRatio.baseVal.meetOrSlice is SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET
    1012PASS rootSVGElement.preserveAspectRatio.animVal.align is SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMINYMIN
    1113PASS rootSVGElement.preserveAspectRatio.animVal.meetOrSlice is SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET
     14PASS rootSVGElement.preserveAspectRatio.baseVal.align is SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN
     15PASS rootSVGElement.preserveAspectRatio.baseVal.meetOrSlice is SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET
    1216PASS rootSVGElement.preserveAspectRatio.animVal.align is SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMID
    1317PASS rootSVGElement.preserveAspectRatio.animVal.meetOrSlice is SVGPreserveAspectRatio.SVG_MEETORSLICE_SLICE
     18PASS rootSVGElement.preserveAspectRatio.baseVal.align is SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN
     19PASS rootSVGElement.preserveAspectRatio.baseVal.meetOrSlice is SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET
    1420PASS rootSVGElement.preserveAspectRatio.animVal.align is SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN
    1521PASS rootSVGElement.preserveAspectRatio.animVal.meetOrSlice is SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET
     22PASS rootSVGElement.preserveAspectRatio.baseVal.align is SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMIN
     23PASS rootSVGElement.preserveAspectRatio.baseVal.meetOrSlice is SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET
    1624PASS successfullyParsed is true
    1725
  • trunk/LayoutTests/svg/dom/preserve-aspect-ratio-parser-expected.txt

    r19121 r112391  
    311311
    312312Test string: 'slice'
    313 PASS imageElement.preserveAspectRatio.baseVal.align is 1
    314 PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 1
    315 
    316 Strings that fail to parse, and hence parse as "none".
     313PASS imageElement.preserveAspectRatio.baseVal.align is 0
     314PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 0
     315
     316Strings that fail to parse, and hence parse as unknown
    317317
    318318Test string: ''
    319 PASS imageElement.preserveAspectRatio.baseVal.align is 1
    320 PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 1
     319PASS imageElement.preserveAspectRatio.baseVal.align is 0
     320PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 0
    321321
    322322Test string: 'defer'
    323 PASS imageElement.preserveAspectRatio.baseVal.align is 1
    324 PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 1
     323PASS imageElement.preserveAspectRatio.baseVal.align is 0
     324PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 0
    325325
    326326Test string: 'meet'
    327 PASS imageElement.preserveAspectRatio.baseVal.align is 1
    328 PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 1
     327PASS imageElement.preserveAspectRatio.baseVal.align is 0
     328PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 0
    329329
    330330Test string: 'slice'
    331 PASS imageElement.preserveAspectRatio.baseVal.align is 1
    332 PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 1
     331PASS imageElement.preserveAspectRatio.baseVal.align is 0
     332PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 0
    333333
    334334Test string: 'xminymin'
    335 PASS imageElement.preserveAspectRatio.baseVal.align is 1
    336 PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 1
     335PASS imageElement.preserveAspectRatio.baseVal.align is 0
     336PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 0
    337337
    338338Test string: 'refer xMinYMin slice'
    339 PASS imageElement.preserveAspectRatio.baseVal.align is 1
    340 PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 1
     339PASS imageElement.preserveAspectRatio.baseVal.align is 0
     340PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 0
    341341
    342342Test string: 'xMinYMin defer'
    343 PASS imageElement.preserveAspectRatio.baseVal.align is 1
    344 PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 1
     343PASS imageElement.preserveAspectRatio.baseVal.align is 0
     344PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 0
    345345
    346346Test string: 'slice xMinYMin'
    347 PASS imageElement.preserveAspectRatio.baseVal.align is 1
    348 PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 1
     347PASS imageElement.preserveAspectRatio.baseVal.align is 0
     348PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 0
    349349
    350350Test string: 'xMinYMin '
    351 PASS imageElement.preserveAspectRatio.baseVal.align is 1
    352 PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 1
     351PASS imageElement.preserveAspectRatio.baseVal.align is 0
     352PASS imageElement.preserveAspectRatio.baseVal.meetOrSlice is 0
    353353
    354354PASS successfullyParsed is true
  • trunk/LayoutTests/svg/dom/preserve-aspect-ratio-parser.html

    r99258 r112391  
    113113
    114114parsePreserveAspectRatio("xMinYMin", 2, 1);
    115 parsePreserveAspectRatio("slice", 1, 1);
     115parsePreserveAspectRatio("slice", 0, 0);
    116116
    117 debug('Strings that fail to parse, and hence parse as "none".');
     117debug('Strings that fail to parse, and hence parse as unknown');
    118118debug('');
    119119
    120 parsePreserveAspectRatio("", 1, 1);
    121 parsePreserveAspectRatio("defer", 1, 1);
    122 parsePreserveAspectRatio("meet", 1, 1);
    123 parsePreserveAspectRatio("slice", 1, 1);
    124 parsePreserveAspectRatio("xminymin", 1, 1);
    125 parsePreserveAspectRatio("refer xMinYMin slice", 1, 1);
    126 parsePreserveAspectRatio("xMinYMin defer", 1, 1);
    127 parsePreserveAspectRatio("slice xMinYMin", 1, 1);
    128 parsePreserveAspectRatio("xMinYMin" + String.fromCharCode(0xa0), 1, 1);
     120parsePreserveAspectRatio("", 0, 0);
     121parsePreserveAspectRatio("defer", 0, 0);
     122parsePreserveAspectRatio("meet", 0, 0);
     123parsePreserveAspectRatio("slice", 0, 0);
     124parsePreserveAspectRatio("xminymin", 0, 0);
     125parsePreserveAspectRatio("refer xMinYMin slice", 0, 0);
     126parsePreserveAspectRatio("xMinYMin defer", 0, 0);
     127parsePreserveAspectRatio("slice xMinYMin", 0, 0);
     128parsePreserveAspectRatio("xMinYMin" + String.fromCharCode(0xa0), 0, 0);
    129129
    130130
  • trunk/Source/WebCore/ChangeLog

    r112390 r112391  
     12012-03-27  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Enable animVal support for SVGAnimatedPreserveAspectRatio
     4        https://bugs.webkit.org/show_bug.cgi?id=82326
     5
     6        Reviewed by Zoltan Herczeg.
     7
     8        Enable animVal support for SVGAnimatedPreserveAspectRatio. Very simple now that everything is prepared.
     9        All we have to do is add startAnimValAnimation/etc. methods to SVGAnimatedPreserveAspectRatioAnimator.
     10
     11        Modernize SVGPreserveAspectRatio, align parsing this object from String, with the other SVG DOM primitives,
     12        who supply a "void parse(const String&)" method, for this task.
     13
     14        Extended existing tests to cover this.
     15
     16        * svg/SVGAnimatedPreserveAspectRatio.cpp:
     17        (WebCore::SVGAnimatedPreserveAspectRatioAnimator::constructFromString):
     18        (WebCore::SVGAnimatedPreserveAspectRatioAnimator::startAnimValAnimation):
     19        (WebCore::SVGAnimatedPreserveAspectRatioAnimator::stopAnimValAnimation):
     20        (WebCore::SVGAnimatedPreserveAspectRatioAnimator::resetAnimValToBaseVal):
     21        (WebCore::SVGAnimatedPreserveAspectRatioAnimator::animValWillChange):
     22        (WebCore::SVGAnimatedPreserveAspectRatioAnimator::animValDidChange):
     23        * svg/SVGAnimatedPreserveAspectRatio.h:
     24        (SVGAnimatedPreserveAspectRatioAnimator):
     25        * svg/SVGAnimatedType.cpp:
     26        (WebCore::SVGAnimatedType::valueAsString):
     27        (WebCore::SVGAnimatedType::setValueAsString):
     28        (WebCore::SVGAnimatedType::supportsAnimVal):
     29        * svg/SVGFEImageElement.cpp:
     30        (WebCore::SVGFEImageElement::parseAttribute):
     31        * svg/SVGFitToViewBox.cpp:
     32        (WebCore::SVGFitToViewBox::parseAttribute):
     33        * svg/SVGImageElement.cpp:
     34        (WebCore::SVGImageElement::parseAttribute):
     35        * svg/SVGPreserveAspectRatio.cpp:
     36        (WebCore::SVGPreserveAspectRatio::parse):
     37        (WebCore):
     38        * svg/SVGPreserveAspectRatio.h:
     39        (SVGPreserveAspectRatio):
     40        * svg/SVGViewSpec.cpp:
     41        (WebCore::SVGViewSpec::setPreserveAspectRatioString):
     42        (WebCore::SVGViewSpec::parseViewSpec):
     43
    1442012-03-28  Pavel Feldman  <pfeldman@chromium.org>
    245
  • trunk/Source/WebCore/svg/SVGAnimatedPreserveAspectRatio.cpp

    r95901 r112391  
    3535{
    3636    OwnPtr<SVGAnimatedType> animatedType = SVGAnimatedType::createPreserveAspectRatio(new SVGPreserveAspectRatio);
    37     SVGPreserveAspectRatio::parsePreserveAspectRatio(animatedType.get(), string);
     37    animatedType->preserveAspectRatio().parse(string);
    3838    return animatedType.release();
     39}
     40
     41PassOwnPtr<SVGAnimatedType> SVGAnimatedPreserveAspectRatioAnimator::startAnimValAnimation(const Vector<SVGAnimatedProperty*>& properties)
     42{
     43    return SVGAnimatedType::createPreserveAspectRatio(constructFromOneBaseValue<SVGPreserveAspectRatio, SVGAnimatedPreserveAspectRatio>(properties));
     44}
     45
     46void SVGAnimatedPreserveAspectRatioAnimator::stopAnimValAnimation(const Vector<SVGAnimatedProperty*>& properties)
     47{
     48    SVGAnimatedTypeAnimator::stopAnimValAnimationForType<SVGAnimatedPreserveAspectRatio>(properties);
     49}
     50
     51void SVGAnimatedPreserveAspectRatioAnimator::resetAnimValToBaseVal(const Vector<SVGAnimatedProperty*>& properties, SVGAnimatedType* type)
     52{
     53    resetFromOneBaseValue<SVGPreserveAspectRatio, SVGAnimatedPreserveAspectRatio>(properties, type, &SVGAnimatedType::preserveAspectRatio);
     54}
     55
     56void SVGAnimatedPreserveAspectRatioAnimator::animValWillChange(const Vector<SVGAnimatedProperty*>& properties)
     57{
     58    animValWillChangeForType<SVGAnimatedPreserveAspectRatio>(properties);
     59}
     60
     61void SVGAnimatedPreserveAspectRatioAnimator::animValDidChange(const Vector<SVGAnimatedProperty*>& properties)
     62{
     63    animValDidChangeForType<SVGAnimatedPreserveAspectRatio>(properties);
    3964}
    4065
  • trunk/Source/WebCore/svg/SVGAnimatedPreserveAspectRatio.h

    r95901 r112391  
    4646   
    4747    virtual PassOwnPtr<SVGAnimatedType> constructFromString(const String&);
    48    
     48    virtual PassOwnPtr<SVGAnimatedType> startAnimValAnimation(const Vector<SVGAnimatedProperty*>&);
     49    virtual void stopAnimValAnimation(const Vector<SVGAnimatedProperty*>&);
     50    virtual void resetAnimValToBaseVal(const Vector<SVGAnimatedProperty*>&, SVGAnimatedType*);
     51    virtual void animValWillChange(const Vector<SVGAnimatedProperty*>&);
     52    virtual void animValDidChange(const Vector<SVGAnimatedProperty*>&);
     53
    4954    virtual void calculateFromAndToValues(OwnPtr<SVGAnimatedType>& fromValue, OwnPtr<SVGAnimatedType>& toValue, const String& fromString, const String& toString);
    5055    virtual void calculateFromAndByValues(OwnPtr<SVGAnimatedType>& fromValue, OwnPtr<SVGAnimatedType>& toValue, const String& fromString, const String& byString);
  • trunk/Source/WebCore/svg/SVGAnimatedType.cpp

    r112247 r112391  
    341341        ASSERT(m_data.color);
    342342        return m_data.color->serialized();
     343    case AnimatedEnumeration:
     344        // FIXME: AnimatedEnumeration is left todo.
     345        ASSERT_NOT_REACHED();
     346        break;
    343347    case AnimatedInteger:
    344348        ASSERT(m_data.integer);
     
    384388        ASSERT(m_data.transformList);
    385389        return m_data.transformList->valueAsString();
    386     case AnimatedEnumeration:
    387         // FIXME: AnimatedEnumeration is left todo.
    388         ASSERT_NOT_REACHED();
    389         break;
    390390    case AnimatedUnknown:
    391391        break;
     
    432432        pointsListFromSVGData(*m_data.pointList, value);
    433433        break;
    434     case AnimatedPreserveAspectRatio:
    435         ASSERT(m_data.preserveAspectRatio);
    436         SVGPreserveAspectRatio::parsePreserveAspectRatio(this, value);
    437         break;
    438434    case AnimatedRect:
    439435        ASSERT(m_data.rect);
     
    448444    case AnimatedAngle:
    449445    case AnimatedBoolean:
     446    case AnimatedInteger:
     447    case AnimatedIntegerOptionalInteger:
    450448    case AnimatedNumberList:
    451449    case AnimatedNumberOptionalNumber:
    452     case AnimatedInteger:
    453     case AnimatedIntegerOptionalInteger:
     450    case AnimatedPreserveAspectRatio:
    454451    case AnimatedTransformList:
    455452    case AnimatedUnknown:
     
    469466bool SVGAnimatedType::supportsAnimVal(AnimatedPropertyType type)
    470467{
    471     // FIXME: This lists the current state of our animVal support.
    472468    switch (type) {
    473469    case AnimatedAngle:
     
    480476    case AnimatedNumberList:
    481477    case AnimatedNumberOptionalNumber:
     478    case AnimatedPreserveAspectRatio:
    482479    case AnimatedRect:
    483480    case AnimatedString:
    484481    case AnimatedTransformList:
    485482        return true;
     483
     484    // Types only used for CSS property animations.
    486485    case AnimatedColor:
     486        return false;
     487
     488    // FIXME: Handle the remaining types in animVal concept.
    487489    case AnimatedEnumeration:
    488490    case AnimatedPath:
    489491    case AnimatedPoints:
    490     case AnimatedPreserveAspectRatio:
    491492    case AnimatedUnknown:
    492493        return false;
  • trunk/Source/WebCore/svg/SVGFEImageElement.cpp

    r107067 r112391  
    134134    }
    135135
    136     const AtomicString& value = attr->value();
    137136    if (attr->name() == SVGNames::preserveAspectRatioAttr) {
    138         SVGPreserveAspectRatio::parsePreserveAspectRatio(this, value);
     137        SVGPreserveAspectRatio preserveAspectRatio;
     138        preserveAspectRatio.parse(attr->value());
     139        setPreserveAspectRatioBaseValue(preserveAspectRatio);
    139140        return;
    140141    }
  • trunk/Source/WebCore/svg/SVGFitToViewBox.cpp

    r106769 r112391  
    9898        return true;
    9999    } else if (attr->name() == SVGNames::preserveAspectRatioAttr) {
    100         SVGPreserveAspectRatio::parsePreserveAspectRatio(this, attr->value());
     100        SVGPreserveAspectRatio preserveAspectRatio;
     101        preserveAspectRatio.parse(attr->value());
     102        setPreserveAspectRatioBaseValue(preserveAspectRatio);
    101103        return true;
    102104    }
  • trunk/Source/WebCore/svg/SVGImageElement.cpp

    r112215 r112391  
    119119    else if (attr->name() == SVGNames::yAttr)
    120120        setYBaseValue(SVGLength::construct(LengthModeHeight, attr->value(), parseError));
    121     else if (attr->name() == SVGNames::preserveAspectRatioAttr)
    122         SVGPreserveAspectRatio::parsePreserveAspectRatio(this, attr->value());
    123     else if (attr->name() == SVGNames::widthAttr)
     121    else if (attr->name() == SVGNames::preserveAspectRatioAttr) {
     122        SVGPreserveAspectRatio preserveAspectRatio;
     123        preserveAspectRatio.parse(attr->value());
     124        setPreserveAspectRatioBaseValue(preserveAspectRatio);
     125    } else if (attr->name() == SVGNames::widthAttr)
    124126        setWidthBaseValue(SVGLength::construct(LengthModeWidth, attr->value(), parseError, ForbidNegativeLengths));
    125127    else if (attr->name() == SVGNames::heightAttr)
  • trunk/Source/WebCore/svg/SVGPreserveAspectRatio.cpp

    r105575 r112391  
    5959}
    6060
    61 SVGPreserveAspectRatio SVGPreserveAspectRatio::parsePreserveAspectRatio(const UChar*& currParam, const UChar* end, bool validate, bool& result)
    62 {
    63     SVGPreserveAspectRatio aspectRatio;
    64     aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_NONE;
    65     aspectRatio.m_meetOrSlice = SVG_MEETORSLICE_MEET;
    66     result = false;
     61void SVGPreserveAspectRatio::parse(const String& value)
     62{
     63    const UChar* begin = value.characters();
     64    parse(begin, begin + value.length(), true);
     65}
     66
     67bool SVGPreserveAspectRatio::parse(const UChar*& currParam, const UChar* end, bool validate)
     68{
     69    m_align = SVG_PRESERVEASPECTRATIO_NONE;
     70    m_meetOrSlice = SVG_MEETORSLICE_MEET;
    6771
    6872    // FIXME: Rewrite this parser, without gotos!
     
    9195                if (currParam[6] == 'i') {
    9296                    if (currParam[7] == 'n')
    93                         aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMINYMIN;
     97                        m_align = SVG_PRESERVEASPECTRATIO_XMINYMIN;
    9498                    else if (currParam[7] == 'd')
    95                         aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMINYMID;
     99                        m_align = SVG_PRESERVEASPECTRATIO_XMINYMID;
    96100                    else
    97101                        goto bailOut;
    98102                } else if (currParam[6] == 'a' && currParam[7] == 'x')
    99                      aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMINYMAX;
     103                     m_align = SVG_PRESERVEASPECTRATIO_XMINYMAX;
    100104                else
    101105                     goto bailOut;
     
    103107                if (currParam[6] == 'i') {
    104108                    if (currParam[7] == 'n')
    105                         aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMIDYMIN;
     109                        m_align = SVG_PRESERVEASPECTRATIO_XMIDYMIN;
    106110                    else if (currParam[7] == 'd')
    107                         aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMIDYMID;
     111                        m_align = SVG_PRESERVEASPECTRATIO_XMIDYMID;
    108112                    else
    109113                        goto bailOut;
    110114                } else if (currParam[6] == 'a' && currParam[7] == 'x')
    111                     aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMIDYMAX;
     115                    m_align = SVG_PRESERVEASPECTRATIO_XMIDYMAX;
    112116                else
    113117                    goto bailOut;
     
    117121            if (currParam[6] == 'i') {
    118122                if (currParam[7] == 'n')
    119                     aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMAXYMIN;
     123                    m_align = SVG_PRESERVEASPECTRATIO_XMAXYMIN;
    120124                else if (currParam[7] == 'd')
    121                     aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMAXYMID;
     125                    m_align = SVG_PRESERVEASPECTRATIO_XMAXYMID;
    122126                else
    123127                    goto bailOut;
    124128            } else if (currParam[6] == 'a' && currParam[7] == 'x')
    125                 aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_XMAXYMAX;
     129                m_align = SVG_PRESERVEASPECTRATIO_XMAXYMAX;
    126130            else
    127131                goto bailOut;
     
    142146                goto bailOut;
    143147            skipOptionalSVGSpaces(currParam, end);
    144             if (aspectRatio.m_align != SVG_PRESERVEASPECTRATIO_NONE)
    145                 aspectRatio.m_meetOrSlice = SVG_MEETORSLICE_SLICE;   
     148            if (m_align != SVG_PRESERVEASPECTRATIO_NONE)
     149                m_meetOrSlice = SVG_MEETORSLICE_SLICE;
    146150        }
    147151    }
     
    149153    if (end != currParam && validate) {
    150154bailOut:
    151         // FIXME: Should the two values be set to UNKNOWN instead?
    152         aspectRatio.m_align = SVG_PRESERVEASPECTRATIO_NONE;
    153         aspectRatio.m_meetOrSlice = SVG_MEETORSLICE_MEET;
    154     } else
    155         result = true;
    156 
    157     return aspectRatio;
     155        m_align = SVG_PRESERVEASPECTRATIO_UNKNOWN;
     156        m_meetOrSlice = SVG_MEETORSLICE_UNKNOWN;
     157        return false;
     158    }
     159    return true;
    158160}
    159161
  • trunk/Source/WebCore/svg/SVGPreserveAspectRatio.h

    r99645 r112391  
    6868                           float physWidth, float physHeight) const;
    6969
    70     template<class Consumer>
    71     static bool parsePreserveAspectRatio(Consumer* consumer, const String& value, bool validate = true)
    72     {
    73         bool result = false;
    74         const UChar* begin = value.characters();
    75         const UChar* end = begin + value.length();
    76         consumer->setPreserveAspectRatioBaseValue(parsePreserveAspectRatio(begin, end, validate, result));
    77         return result;
    78     }
    79 
    80     // It's recommended to use the method above, only SVGViewSpec needs this parsing method
    81     static SVGPreserveAspectRatio parsePreserveAspectRatio(const UChar*& currParam, const UChar* end, bool validate, bool& result);
     70    void parse(const String&);
     71    bool parse(const UChar*& currParam, const UChar* end, bool validate);
    8272
    8373    String valueAsString() const;
  • trunk/Source/WebCore/svg/SVGViewSpec.cpp

    r110838 r112391  
    6464void SVGViewSpec::setPreserveAspectRatioString(const String& preserve)
    6565{
    66     SVGPreserveAspectRatio::parsePreserveAspectRatio(this, preserve);
     66    SVGPreserveAspectRatio preserveAspectRatio;
     67    preserveAspectRatio.parse(preserve);
     68    setPreserveAspectRatioBaseValue(preserveAspectRatio);
    6769}
    6870
     
    141143                return false;
    142144            currViewSpec++;
    143             bool result = false;
    144             setPreserveAspectRatioBaseValue(SVGPreserveAspectRatio::parsePreserveAspectRatio(currViewSpec, end, false, result));
    145             if (!result)
     145            SVGPreserveAspectRatio preserveAspectRatio;
     146            if (!preserveAspectRatio.parse(currViewSpec, end, false))
    146147                return false;
     148            setPreserveAspectRatioBaseValue(preserveAspectRatio);
    147149            if (currViewSpec >= end || *currViewSpec != ')')
    148150                return false;
Note: See TracChangeset for help on using the changeset viewer.