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) Research In Motion Limited 2010. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
20 */ | 20 */ |
21 | 21 |
22 #include "core/svg/SVGGradientElement.h" | 22 #include "core/svg/SVGGradientElement.h" |
23 | 23 |
24 #include "core/dom/Attribute.h" | 24 #include "core/dom/Attribute.h" |
25 #include "core/dom/ElementTraversal.h" | 25 #include "core/dom/ElementTraversal.h" |
26 #include "core/dom/StyleChangeReason.h" | 26 #include "core/dom/StyleChangeReason.h" |
27 #include "core/layout/svg/LayoutSVGResourceContainer.h" | 27 #include "core/layout/svg/LayoutSVGResourceContainer.h" |
| 28 #include "core/svg/GradientAttributes.h" |
28 #include "core/svg/SVGStopElement.h" | 29 #include "core/svg/SVGStopElement.h" |
29 #include "core/svg/SVGTransformList.h" | 30 #include "core/svg/SVGTransformList.h" |
30 | 31 |
31 namespace blink { | 32 namespace blink { |
32 | 33 |
33 template <> | 34 template <> |
34 const SVGEnumerationStringEntries& | 35 const SVGEnumerationStringEntries& |
35 getStaticStringEntries<SVGSpreadMethodType>() { | 36 getStaticStringEntries<SVGSpreadMethodType>() { |
36 DEFINE_STATIC_LOCAL(SVGEnumerationStringEntries, entries, ()); | 37 DEFINE_STATIC_LOCAL(SVGEnumerationStringEntries, entries, ()); |
37 if (entries.isEmpty()) { | 38 if (entries.isEmpty()) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 SVGElement::childrenChanged(change); | 113 SVGElement::childrenChanged(change); |
113 | 114 |
114 if (change.byParser) | 115 if (change.byParser) |
115 return; | 116 return; |
116 | 117 |
117 if (LayoutObject* object = layoutObject()) | 118 if (LayoutObject* object = layoutObject()) |
118 object->setNeedsLayoutAndFullPaintInvalidation( | 119 object->setNeedsLayoutAndFullPaintInvalidation( |
119 LayoutInvalidationReason::ChildChanged); | 120 LayoutInvalidationReason::ChildChanged); |
120 } | 121 } |
121 | 122 |
122 Vector<Gradient::ColorStop> SVGGradientElement::buildStops() { | 123 void SVGGradientElement::collectCommonAttributes( |
| 124 GradientAttributes& attributes) const { |
| 125 if (!attributes.hasSpreadMethod() && spreadMethod()->isSpecified()) |
| 126 attributes.setSpreadMethod(spreadMethod()->currentValue()->enumValue()); |
| 127 |
| 128 if (!attributes.hasGradientUnits() && gradientUnits()->isSpecified()) |
| 129 attributes.setGradientUnits(gradientUnits()->currentValue()->enumValue()); |
| 130 |
| 131 if (!attributes.hasGradientTransform() && |
| 132 hasTransform(SVGElement::ExcludeMotionTransform)) { |
| 133 attributes.setGradientTransform( |
| 134 calculateTransform(SVGElement::ExcludeMotionTransform)); |
| 135 } |
| 136 |
| 137 if (!attributes.hasStops()) { |
| 138 const Vector<Gradient::ColorStop>& stops(buildStops()); |
| 139 if (!stops.isEmpty()) |
| 140 attributes.setStops(stops); |
| 141 } |
| 142 } |
| 143 |
| 144 const SVGGradientElement* SVGGradientElement::referencedElement() const { |
| 145 // Respect xlink:href, take attributes from referenced element. |
| 146 Element* referencedElement = |
| 147 targetElementFromIRIString(hrefString(), treeScope()); |
| 148 if (!referencedElement || !isSVGGradientElement(*referencedElement)) |
| 149 return nullptr; |
| 150 return toSVGGradientElement(referencedElement); |
| 151 } |
| 152 |
| 153 Vector<Gradient::ColorStop> SVGGradientElement::buildStops() const { |
123 Vector<Gradient::ColorStop> stops; | 154 Vector<Gradient::ColorStop> stops; |
124 | 155 |
125 float previousOffset = 0.0f; | 156 float previousOffset = 0.0f; |
126 for (const SVGStopElement& stop : | 157 for (const SVGStopElement& stop : |
127 Traversal<SVGStopElement>::childrenOf(*this)) { | 158 Traversal<SVGStopElement>::childrenOf(*this)) { |
128 // Figure out right monotonic offset. | 159 // Figure out right monotonic offset. |
129 float offset = stop.offset()->currentValue()->value(); | 160 float offset = stop.offset()->currentValue()->value(); |
130 offset = std::min(std::max(previousOffset, offset), 1.0f); | 161 offset = std::min(std::max(previousOffset, offset), 1.0f); |
131 previousOffset = offset; | 162 previousOffset = offset; |
132 | 163 |
133 stops.push_back( | 164 stops.push_back( |
134 Gradient::ColorStop(offset, stop.stopColorIncludingOpacity())); | 165 Gradient::ColorStop(offset, stop.stopColorIncludingOpacity())); |
135 } | 166 } |
136 return stops; | 167 return stops; |
137 } | 168 } |
138 | 169 |
139 } // namespace blink | 170 } // namespace blink |
OLD | NEW |