source: trunk/Source/WebCore/svg/SVGViewSpec.cpp @ 112391

Revision 112391, 6.6 KB checked in by zimmermann@webkit.org, 3 years ago (diff)

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.
  • Property svn:eol-style set to native
Line 
1/*
2 * Copyright (C) 2007, 2010 Rob Buis <buis@kde.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB.  If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "config.h"
21
22#if ENABLE(SVG)
23#include "SVGViewSpec.h"
24
25#include "Document.h"
26#include "SVGNames.h"
27#include "SVGParserUtilities.h"
28#include "SVGSVGElement.h"
29#include "SVGTransformable.h"
30
31namespace WebCore {
32
33// Animated property definitions
34DEFINE_ANIMATED_RECT(SVGViewSpec, SVGNames::viewBoxAttr, ViewBox, viewBox)
35DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGViewSpec, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio)
36
37BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGViewSpec)
38    REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox)
39    REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio)
40END_REGISTER_ANIMATED_PROPERTIES
41
42SVGViewSpec::SVGViewSpec(SVGElement* contextElement)
43    : m_contextElement(contextElement)
44{
45    ASSERT(m_contextElement);
46    registerAnimatedPropertiesForSVGViewSpec();
47}
48
49void SVGViewSpec::setTransform(const String& transform)
50{
51    m_transform.parse(transform);
52}
53
54void SVGViewSpec::setViewBoxString(const String& viewBoxStr)
55{
56    FloatRect viewBox;
57    const UChar* c = viewBoxStr.characters();
58    const UChar* end = c + viewBoxStr.length();
59    if (!parseViewBox(m_contextElement->document(), c, end, viewBox, false))
60         return;
61    setViewBoxBaseValue(viewBox);
62}
63
64void SVGViewSpec::setPreserveAspectRatioString(const String& preserve)
65{
66    SVGPreserveAspectRatio preserveAspectRatio;
67    preserveAspectRatio.parse(preserve);
68    setPreserveAspectRatioBaseValue(preserveAspectRatio);
69}
70
71void SVGViewSpec::setViewTargetString(const String& viewTargetString)
72{
73    m_viewTargetString = viewTargetString;
74}
75
76SVGElement* SVGViewSpec::viewTarget() const
77{
78    return static_cast<SVGElement*>(m_contextElement->treeScope()->getElementById(m_viewTargetString));
79}
80
81static const UChar svgViewSpec[] = {'s', 'v', 'g', 'V', 'i', 'e', 'w'};
82static const UChar viewBoxSpec[] = {'v', 'i', 'e', 'w', 'B', 'o', 'x'};
83static const UChar preserveAspectRatioSpec[] = {'p', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'A', 's', 'p', 'e', 'c', 't', 'R', 'a', 't', 'i', 'o'};
84static const UChar transformSpec[] = {'t', 'r', 'a', 'n', 's', 'f', 'o', 'r', 'm'};
85static const UChar zoomAndPanSpec[] = {'z', 'o', 'o', 'm', 'A', 'n', 'd', 'P', 'a', 'n'};
86static const UChar viewTargetSpec[] =  {'v', 'i', 'e', 'w', 'T', 'a', 'r', 'g', 'e', 't'};
87
88bool SVGViewSpec::parseViewSpec(const String& viewSpec)
89{
90    const UChar* currViewSpec = viewSpec.characters();
91    const UChar* end = currViewSpec + viewSpec.length();
92
93    if (currViewSpec >= end)
94        return false;
95
96    if (!skipString(currViewSpec, end, svgViewSpec, WTF_ARRAY_LENGTH(svgViewSpec)))
97        return false;
98
99    if (currViewSpec >= end || *currViewSpec != '(')
100        return false;
101    currViewSpec++;
102
103    while (currViewSpec < end && *currViewSpec != ')') {
104        if (*currViewSpec == 'v') {
105            if (skipString(currViewSpec, end, viewBoxSpec, WTF_ARRAY_LENGTH(viewBoxSpec))) {
106                if (currViewSpec >= end || *currViewSpec != '(')
107                    return false;
108                currViewSpec++;
109                FloatRect viewBox;
110                if (!parseViewBox(m_contextElement->document(), currViewSpec, end, viewBox, false))
111                    return false;
112                setViewBoxBaseValue(viewBox);
113                if (currViewSpec >= end || *currViewSpec != ')')
114                    return false;
115                currViewSpec++;
116            } else if (skipString(currViewSpec, end, viewTargetSpec, WTF_ARRAY_LENGTH(viewTargetSpec))) {
117                if (currViewSpec >= end || *currViewSpec != '(')
118                    return false;
119                const UChar* viewTargetStart = ++currViewSpec;
120                while (currViewSpec < end && *currViewSpec != ')')
121                    currViewSpec++;
122                if (currViewSpec >= end)
123                    return false;
124                setViewTargetString(String(viewTargetStart, currViewSpec - viewTargetStart));
125                currViewSpec++;
126            } else
127                return false;
128        } else if (*currViewSpec == 'z') {
129            if (!skipString(currViewSpec, end, zoomAndPanSpec, WTF_ARRAY_LENGTH(zoomAndPanSpec)))
130                return false;
131            if (currViewSpec >= end || *currViewSpec != '(')
132                return false;
133            currViewSpec++;
134            if (!parseZoomAndPan(currViewSpec, end))
135                return false;
136            if (currViewSpec >= end || *currViewSpec != ')')
137                return false;
138            currViewSpec++;
139        } else if (*currViewSpec == 'p') {
140            if (!skipString(currViewSpec, end, preserveAspectRatioSpec, WTF_ARRAY_LENGTH(preserveAspectRatioSpec)))
141                return false;
142            if (currViewSpec >= end || *currViewSpec != '(')
143                return false;
144            currViewSpec++;
145            SVGPreserveAspectRatio preserveAspectRatio;
146            if (!preserveAspectRatio.parse(currViewSpec, end, false))
147                return false;
148            setPreserveAspectRatioBaseValue(preserveAspectRatio);
149            if (currViewSpec >= end || *currViewSpec != ')')
150                return false;
151            currViewSpec++;
152        } else if (*currViewSpec == 't') {
153            if (!skipString(currViewSpec, end, transformSpec, WTF_ARRAY_LENGTH(transformSpec)))
154                return false;
155            if (currViewSpec >= end || *currViewSpec != '(')
156                return false;
157            currViewSpec++;
158            SVGTransformable::parseTransformAttribute(m_transform, currViewSpec, end, SVGTransformable::DoNotClearList);
159            if (currViewSpec >= end || *currViewSpec != ')')
160                return false;
161            currViewSpec++;
162        } else
163            return false;
164
165        if (currViewSpec < end && *currViewSpec == ';')
166            currViewSpec++;
167    }
168   
169    if (currViewSpec >= end || *currViewSpec != ')')
170        return false;
171
172    return true;
173}
174
175}
176
177#endif // ENABLE(SVG)
Note: See TracBrowser for help on using the repository browser.