OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
5 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 5 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #include "core/rendering/svg/RenderSVGResourceLinearGradient.h" | 28 #include "core/rendering/svg/RenderSVGResourceLinearGradient.h" |
29 #include "core/svg/LinearGradientAttributes.h" | 29 #include "core/svg/LinearGradientAttributes.h" |
30 #include "core/svg/SVGElementInstance.h" | 30 #include "core/svg/SVGElementInstance.h" |
31 #include "core/svg/SVGLength.h" | 31 #include "core/svg/SVGLength.h" |
32 #include "core/svg/SVGTransformList.h" | 32 #include "core/svg/SVGTransformList.h" |
33 | 33 |
34 namespace WebCore { | 34 namespace WebCore { |
35 | 35 |
36 // Animated property definitions | 36 // Animated property definitions |
37 DEFINE_ANIMATED_LENGTH(SVGLinearGradientElement, SVGNames::x1Attr, X1, x1) | |
38 DEFINE_ANIMATED_LENGTH(SVGLinearGradientElement, SVGNames::y1Attr, Y1, y1) | |
39 DEFINE_ANIMATED_LENGTH(SVGLinearGradientElement, SVGNames::x2Attr, X2, x2) | |
40 DEFINE_ANIMATED_LENGTH(SVGLinearGradientElement, SVGNames::y2Attr, Y2, y2) | |
41 | |
42 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGLinearGradientElement) | 37 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGLinearGradientElement) |
43 REGISTER_LOCAL_ANIMATED_PROPERTY(x1) | |
44 REGISTER_LOCAL_ANIMATED_PROPERTY(y1) | |
45 REGISTER_LOCAL_ANIMATED_PROPERTY(x2) | |
46 REGISTER_LOCAL_ANIMATED_PROPERTY(y2) | |
47 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGradientElement) | 38 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGradientElement) |
48 END_REGISTER_ANIMATED_PROPERTIES | 39 END_REGISTER_ANIMATED_PROPERTIES |
49 | 40 |
50 inline SVGLinearGradientElement::SVGLinearGradientElement(Document& document) | 41 inline SVGLinearGradientElement::SVGLinearGradientElement(Document& document) |
51 : SVGGradientElement(SVGNames::linearGradientTag, document) | 42 : SVGGradientElement(SVGNames::linearGradientTag, document) |
52 , m_x1(LengthModeWidth) | 43 , m_x1(SVGAnimatedLength::create(this, SVGNames::x1Attr, SVGLength::create(L
engthModeWidth))) |
53 , m_y1(LengthModeHeight) | 44 , m_y1(SVGAnimatedLength::create(this, SVGNames::y1Attr, SVGLength::create(L
engthModeHeight))) |
54 , m_x2(LengthModeWidth, "100%") | 45 , m_x2(SVGAnimatedLength::create(this, SVGNames::x2Attr, SVGLength::create(L
engthModeWidth))) |
55 , m_y2(LengthModeHeight) | 46 , m_y2(SVGAnimatedLength::create(this, SVGNames::y2Attr, SVGLength::create(L
engthModeHeight))) |
56 { | 47 { |
| 48 ScriptWrappable::init(this); |
| 49 |
57 // Spec: If the x2 attribute is not specified, the effect is as if a value o
f "100%" were specified. | 50 // Spec: If the x2 attribute is not specified, the effect is as if a value o
f "100%" were specified. |
58 ScriptWrappable::init(this); | 51 m_x2->setDefaultValueAsString("100%"); |
| 52 |
| 53 addToPropertyMap(m_x1); |
| 54 addToPropertyMap(m_y1); |
| 55 addToPropertyMap(m_x2); |
| 56 addToPropertyMap(m_y2); |
59 registerAnimatedPropertiesForSVGLinearGradientElement(); | 57 registerAnimatedPropertiesForSVGLinearGradientElement(); |
60 } | 58 } |
61 | 59 |
62 PassRefPtr<SVGLinearGradientElement> SVGLinearGradientElement::create(Document&
document) | 60 PassRefPtr<SVGLinearGradientElement> SVGLinearGradientElement::create(Document&
document) |
63 { | 61 { |
64 return adoptRef(new SVGLinearGradientElement(document)); | 62 return adoptRef(new SVGLinearGradientElement(document)); |
65 } | 63 } |
66 | 64 |
67 bool SVGLinearGradientElement::isSupportedAttribute(const QualifiedName& attrNam
e) | 65 bool SVGLinearGradientElement::isSupportedAttribute(const QualifiedName& attrNam
e) |
68 { | 66 { |
69 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); | 67 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); |
70 if (supportedAttributes.isEmpty()) { | 68 if (supportedAttributes.isEmpty()) { |
71 supportedAttributes.add(SVGNames::x1Attr); | 69 supportedAttributes.add(SVGNames::x1Attr); |
72 supportedAttributes.add(SVGNames::x2Attr); | 70 supportedAttributes.add(SVGNames::x2Attr); |
73 supportedAttributes.add(SVGNames::y1Attr); | 71 supportedAttributes.add(SVGNames::y1Attr); |
74 supportedAttributes.add(SVGNames::y2Attr); | 72 supportedAttributes.add(SVGNames::y2Attr); |
75 } | 73 } |
76 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); | 74 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); |
77 } | 75 } |
78 | 76 |
79 void SVGLinearGradientElement::parseAttribute(const QualifiedName& name, const A
tomicString& value) | 77 void SVGLinearGradientElement::parseAttribute(const QualifiedName& name, const A
tomicString& value) |
80 { | 78 { |
81 SVGParsingError parseError = NoError; | 79 SVGParsingError parseError = NoError; |
82 | 80 |
83 if (!isSupportedAttribute(name)) | 81 if (!isSupportedAttribute(name)) |
84 SVGGradientElement::parseAttribute(name, value); | 82 SVGGradientElement::parseAttribute(name, value); |
85 else if (name == SVGNames::x1Attr) | 83 else if (name == SVGNames::x1Attr) |
86 setX1BaseValue(SVGLength::construct(LengthModeWidth, value, parseError))
; | 84 m_x1->setBaseValueAsString(value, AllowNegativeLengths, parseError); |
87 else if (name == SVGNames::y1Attr) | 85 else if (name == SVGNames::y1Attr) |
88 setY1BaseValue(SVGLength::construct(LengthModeHeight, value, parseError)
); | 86 m_y1->setBaseValueAsString(value, AllowNegativeLengths, parseError); |
89 else if (name == SVGNames::x2Attr) | 87 else if (name == SVGNames::x2Attr) |
90 setX2BaseValue(SVGLength::construct(LengthModeWidth, value, parseError))
; | 88 m_x2->setBaseValueAsString(value, AllowNegativeLengths, parseError); |
91 else if (name == SVGNames::y2Attr) | 89 else if (name == SVGNames::y2Attr) |
92 setY2BaseValue(SVGLength::construct(LengthModeHeight, value, parseError)
); | 90 m_y2->setBaseValueAsString(value, AllowNegativeLengths, parseError); |
93 else | 91 else |
94 ASSERT_NOT_REACHED(); | 92 ASSERT_NOT_REACHED(); |
95 | 93 |
96 reportAttributeParsingError(parseError, name, value); | 94 reportAttributeParsingError(parseError, name, value); |
97 } | 95 } |
98 | 96 |
99 void SVGLinearGradientElement::svgAttributeChanged(const QualifiedName& attrName
) | 97 void SVGLinearGradientElement::svgAttributeChanged(const QualifiedName& attrName
) |
100 { | 98 { |
101 if (!isSupportedAttribute(attrName)) { | 99 if (!isSupportedAttribute(attrName)) { |
102 SVGGradientElement::svgAttributeChanged(attrName); | 100 SVGGradientElement::svgAttributeChanged(attrName); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 if (!attributes.hasStops()) { | 141 if (!attributes.hasStops()) { |
144 const Vector<Gradient::ColorStop>& stops(current->buildStops()); | 142 const Vector<Gradient::ColorStop>& stops(current->buildStops()); |
145 if (!stops.isEmpty()) | 143 if (!stops.isEmpty()) |
146 attributes.setStops(stops); | 144 attributes.setStops(stops); |
147 } | 145 } |
148 | 146 |
149 if (isLinear) { | 147 if (isLinear) { |
150 SVGLinearGradientElement* linear = toSVGLinearGradientElement(curren
t); | 148 SVGLinearGradientElement* linear = toSVGLinearGradientElement(curren
t); |
151 | 149 |
152 if (!attributes.hasX1() && current->hasAttribute(SVGNames::x1Attr)) | 150 if (!attributes.hasX1() && current->hasAttribute(SVGNames::x1Attr)) |
153 attributes.setX1(linear->x1CurrentValue()); | 151 attributes.setX1(linear->x1()->currentValue()); |
154 | 152 |
155 if (!attributes.hasY1() && current->hasAttribute(SVGNames::y1Attr)) | 153 if (!attributes.hasY1() && current->hasAttribute(SVGNames::y1Attr)) |
156 attributes.setY1(linear->y1CurrentValue()); | 154 attributes.setY1(linear->y1()->currentValue()); |
157 | 155 |
158 if (!attributes.hasX2() && current->hasAttribute(SVGNames::x2Attr)) | 156 if (!attributes.hasX2() && current->hasAttribute(SVGNames::x2Attr)) |
159 attributes.setX2(linear->x2CurrentValue()); | 157 attributes.setX2(linear->x2()->currentValue()); |
160 | 158 |
161 if (!attributes.hasY2() && current->hasAttribute(SVGNames::y2Attr)) | 159 if (!attributes.hasY2() && current->hasAttribute(SVGNames::y2Attr)) |
162 attributes.setY2(linear->y2CurrentValue()); | 160 attributes.setY2(linear->y2()->currentValue()); |
163 } | 161 } |
164 | 162 |
165 processedGradients.add(current); | 163 processedGradients.add(current); |
166 | 164 |
167 // Respect xlink:href, take attributes from referenced element | 165 // Respect xlink:href, take attributes from referenced element |
168 Node* refNode = SVGURIReference::targetElementFromIRIString(current->hre
fCurrentValue(), document()); | 166 Node* refNode = SVGURIReference::targetElementFromIRIString(current->hre
fCurrentValue(), document()); |
169 if (refNode && (refNode->hasTagName(SVGNames::linearGradientTag) || refN
ode->hasTagName(SVGNames::radialGradientTag))) { | 167 if (refNode && (refNode->hasTagName(SVGNames::linearGradientTag) || refN
ode->hasTagName(SVGNames::radialGradientTag))) { |
170 current = toSVGGradientElement(refNode); | 168 current = toSVGGradientElement(refNode); |
171 | 169 |
172 // Cycle detection | 170 // Cycle detection |
173 if (processedGradients.contains(current)) { | 171 if (processedGradients.contains(current)) { |
174 current = 0; | 172 current = 0; |
175 break; | 173 break; |
176 } | 174 } |
177 | 175 |
178 isLinear = current->hasTagName(SVGNames::linearGradientTag); | 176 isLinear = current->hasTagName(SVGNames::linearGradientTag); |
179 } else | 177 } else |
180 current = 0; | 178 current = 0; |
181 } | 179 } |
182 | 180 |
183 return true; | 181 return true; |
184 } | 182 } |
185 | 183 |
186 bool SVGLinearGradientElement::selfHasRelativeLengths() const | 184 bool SVGLinearGradientElement::selfHasRelativeLengths() const |
187 { | 185 { |
188 return x1CurrentValue().isRelative() | 186 return m_x1->currentValue()->isRelative() |
189 || y1CurrentValue().isRelative() | 187 || m_y1->currentValue()->isRelative() |
190 || x2CurrentValue().isRelative() | 188 || m_x2->currentValue()->isRelative() |
191 || y2CurrentValue().isRelative(); | 189 || m_y2->currentValue()->isRelative(); |
192 } | 190 } |
193 | 191 |
194 } | 192 } |
OLD | NEW |