| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 SVGGradientElement::svgAttributeChanged(attrName); | 89 SVGGradientElement::svgAttributeChanged(attrName); |
| 90 } | 90 } |
| 91 | 91 |
| 92 LayoutObject* SVGLinearGradientElement::createLayoutObject( | 92 LayoutObject* SVGLinearGradientElement::createLayoutObject( |
| 93 const ComputedStyle&) { | 93 const ComputedStyle&) { |
| 94 return new LayoutSVGResourceLinearGradient(this); | 94 return new LayoutSVGResourceLinearGradient(this); |
| 95 } | 95 } |
| 96 | 96 |
| 97 static void setGradientAttributes(SVGGradientElement* element, | 97 static void setGradientAttributes(const SVGGradientElement& element, |
| 98 LinearGradientAttributes& attributes, | 98 LinearGradientAttributes& attributes, |
| 99 bool isLinear = true) { | 99 bool isLinear) { |
| 100 if (!attributes.hasSpreadMethod() && element->spreadMethod()->isSpecified()) | 100 element.collectCommonAttributes(attributes); |
| 101 attributes.setSpreadMethod( | |
| 102 element->spreadMethod()->currentValue()->enumValue()); | |
| 103 | 101 |
| 104 if (!attributes.hasGradientUnits() && element->gradientUnits()->isSpecified()) | 102 if (!isLinear) |
| 105 attributes.setGradientUnits( | 103 return; |
| 106 element->gradientUnits()->currentValue()->enumValue()); | 104 const SVGLinearGradientElement& linear = toSVGLinearGradientElement(element); |
| 107 | 105 |
| 108 if (!attributes.hasGradientTransform() && | 106 if (!attributes.hasX1() && linear.x1()->isSpecified()) |
| 109 element->hasTransform(SVGElement::ExcludeMotionTransform)) { | 107 attributes.setX1(linear.x1()->currentValue()); |
| 110 attributes.setGradientTransform( | |
| 111 element->calculateTransform(SVGElement::ExcludeMotionTransform)); | |
| 112 } | |
| 113 | 108 |
| 114 if (!attributes.hasStops()) { | 109 if (!attributes.hasY1() && linear.y1()->isSpecified()) |
| 115 const Vector<Gradient::ColorStop>& stops(element->buildStops()); | 110 attributes.setY1(linear.y1()->currentValue()); |
| 116 if (!stops.isEmpty()) | |
| 117 attributes.setStops(stops); | |
| 118 } | |
| 119 | 111 |
| 120 if (isLinear) { | 112 if (!attributes.hasX2() && linear.x2()->isSpecified()) |
| 121 SVGLinearGradientElement* linear = toSVGLinearGradientElement(element); | 113 attributes.setX2(linear.x2()->currentValue()); |
| 122 | 114 |
| 123 if (!attributes.hasX1() && linear->x1()->isSpecified()) | 115 if (!attributes.hasY2() && linear.y2()->isSpecified()) |
| 124 attributes.setX1(linear->x1()->currentValue()); | 116 attributes.setY2(linear.y2()->currentValue()); |
| 125 | |
| 126 if (!attributes.hasY1() && linear->y1()->isSpecified()) | |
| 127 attributes.setY1(linear->y1()->currentValue()); | |
| 128 | |
| 129 if (!attributes.hasX2() && linear->x2()->isSpecified()) | |
| 130 attributes.setX2(linear->x2()->currentValue()); | |
| 131 | |
| 132 if (!attributes.hasY2() && linear->y2()->isSpecified()) | |
| 133 attributes.setY2(linear->y2()->currentValue()); | |
| 134 } | |
| 135 } | 117 } |
| 136 | 118 |
| 137 bool SVGLinearGradientElement::collectGradientAttributes( | 119 bool SVGLinearGradientElement::collectGradientAttributes( |
| 138 LinearGradientAttributes& attributes) { | 120 LinearGradientAttributes& attributes) { |
| 139 if (!layoutObject()) | 121 DCHECK(layoutObject()); |
| 140 return false; | |
| 141 | 122 |
| 142 HeapHashSet<Member<SVGGradientElement>> processedGradients; | 123 VisitedSet visited; |
| 143 SVGGradientElement* current = this; | 124 const SVGGradientElement* current = this; |
| 144 | |
| 145 setGradientAttributes(current, attributes); | |
| 146 processedGradients.insert(current); | |
| 147 | 125 |
| 148 while (true) { | 126 while (true) { |
| 149 // Respect xlink:href, take attributes from referenced element | 127 setGradientAttributes(*current, attributes, |
| 150 Node* refNode = SVGURIReference::targetElementFromIRIString( | 128 isSVGLinearGradientElement(*current)); |
| 151 current->href()->currentValue()->value(), treeScope()); | 129 visited.insert(current); |
| 152 if (refNode && isSVGGradientElement(*refNode)) { | |
| 153 current = toSVGGradientElement(refNode); | |
| 154 | 130 |
| 155 // Cycle detection | 131 current = current->referencedElement(); |
| 156 if (processedGradients.contains(current)) | 132 if (!current || visited.contains(current)) |
| 157 return true; | 133 break; |
| 158 | 134 if (!current->layoutObject()) |
| 159 if (!current->layoutObject()) | 135 return false; |
| 160 return false; | |
| 161 | |
| 162 setGradientAttributes(current, attributes, | |
| 163 isSVGLinearGradientElement(*current)); | |
| 164 processedGradients.insert(current); | |
| 165 } else { | |
| 166 return true; | |
| 167 } | |
| 168 } | 136 } |
| 169 | 137 return true; |
| 170 ASSERT_NOT_REACHED(); | |
| 171 return false; | |
| 172 } | 138 } |
| 173 | 139 |
| 174 bool SVGLinearGradientElement::selfHasRelativeLengths() const { | 140 bool SVGLinearGradientElement::selfHasRelativeLengths() const { |
| 175 return m_x1->currentValue()->isRelative() || | 141 return m_x1->currentValue()->isRelative() || |
| 176 m_y1->currentValue()->isRelative() || | 142 m_y1->currentValue()->isRelative() || |
| 177 m_x2->currentValue()->isRelative() || | 143 m_x2->currentValue()->isRelative() || |
| 178 m_y2->currentValue()->isRelative(); | 144 m_y2->currentValue()->isRelative(); |
| 179 } | 145 } |
| 180 | 146 |
| 181 } // namespace blink | 147 } // namespace blink |
| OLD | NEW |