24#include "wtf/Platform.h"
40SVGLinearGradientElement::SVGLinearGradientElement(
const QualifiedName& tagName, Document* doc)
41 : SVGGradientElement(tagName, doc)
42 , m_x1(this, LengthModeWidth)
43 , m_y1(this, LengthModeHeight)
44 , m_x2(this, LengthModeWidth)
45 , m_y2(this, LengthModeHeight)
48 setX2BaseValue(SVGLength(
this, LengthModeWidth,
"100%"));
51SVGLinearGradientElement::~SVGLinearGradientElement()
55ANIMATED_PROPERTY_DEFINITIONS(SVGLinearGradientElement, SVGLength, Length, length, X1, x1, SVGNames::x1Attr, m_x1)
56ANIMATED_PROPERTY_DEFINITIONS(SVGLinearGradientElement, SVGLength, Length, length, Y1, y1, SVGNames::y1Attr, m_y1)
57ANIMATED_PROPERTY_DEFINITIONS(SVGLinearGradientElement, SVGLength, Length, length, X2, x2, SVGNames::x2Attr, m_x2)
58ANIMATED_PROPERTY_DEFINITIONS(SVGLinearGradientElement, SVGLength, Length, length, Y2, y2, SVGNames::y2Attr, m_y2)
60void SVGLinearGradientElement::parseMappedAttribute(MappedAttribute* attr)
62 if (attr->name() == SVGNames::x1Attr)
63 setX1BaseValue(SVGLength(
this, LengthModeWidth, attr->value()));
64 else if (attr->name() == SVGNames::y1Attr)
65 setY1BaseValue(SVGLength(
this, LengthModeHeight, attr->value()));
66 else if (attr->name() == SVGNames::x2Attr)
67 setX2BaseValue(SVGLength(
this, LengthModeWidth, attr->value()));
68 else if (attr->name() == SVGNames::y2Attr)
69 setY2BaseValue(SVGLength(
this, LengthModeHeight, attr->value()));
71 SVGGradientElement::parseMappedAttribute(attr);
74void SVGLinearGradientElement::svgAttributeChanged(
const QualifiedName& attrName)
76 SVGGradientElement::svgAttributeChanged(attrName);
81 if (attrName == SVGNames::x1Attr || attrName == SVGNames::y1Attr ||
82 attrName == SVGNames::x2Attr || attrName == SVGNames::y2Attr)
83 m_resource->invalidate();
86void SVGLinearGradientElement::buildGradient()
const
88 LinearGradientAttributes attributes = collectGradientProperties();
91 if (attributes.stops().isEmpty())
94 RefPtr<SVGPaintServerLinearGradient> linearGradient = WTF::static_pointer_cast<SVGPaintServerLinearGradient>(m_resource);
96 linearGradient->setGradientStops(attributes.stops());
97 linearGradient->setBoundingBoxMode(attributes.boundingBoxMode());
98 linearGradient->setGradientSpreadMethod(attributes.spreadMethod());
99 linearGradient->setGradientTransform(attributes.gradientTransform());
100 linearGradient->setGradientStart(FloatPoint::narrowPrecision(attributes.x1(), attributes.y1()));
101 linearGradient->setGradientEnd(FloatPoint::narrowPrecision(attributes.x2(), attributes.y2()));
104LinearGradientAttributes SVGLinearGradientElement::collectGradientProperties()
const
106 LinearGradientAttributes attributes;
107 HashSet<const SVGGradientElement*> processedGradients;
109 bool isLinear =
true;
110 const SVGGradientElement* current =
this;
113 if (!attributes.hasSpreadMethod() && current->hasAttribute(SVGNames::spreadMethodAttr))
114 attributes.setSpreadMethod((SVGGradientSpreadMethod) current->spreadMethod());
116 if (!attributes.hasBoundingBoxMode() && current->hasAttribute(SVGNames::gradientUnitsAttr))
117 attributes.setBoundingBoxMode(current->getAttribute(SVGNames::gradientUnitsAttr) ==
"objectBoundingBox");
119 if (!attributes.hasGradientTransform() && current->hasAttribute(SVGNames::gradientTransformAttr))
120 attributes.setGradientTransform(current->gradientTransform()->consolidate().matrix());
122 if (!attributes.hasStops()) {
123 const Vector<SVGGradientStop>& stops(current->buildStops());
124 kDebug() <<
"stops.isEmpty()" << stops.isEmpty() << endl;
125 if (!stops.isEmpty())
126 attributes.setStops(stops);
130 const SVGLinearGradientElement* linear =
static_cast<const SVGLinearGradientElement*
>(current);
132 if (!attributes.hasX1() && current->hasAttribute(SVGNames::x1Attr))
133 attributes.setX1(linear->x1().valueAsPercentage());
135 if (!attributes.hasY1() && current->hasAttribute(SVGNames::y1Attr))
136 attributes.setY1(linear->y1().valueAsPercentage());
138 if (!attributes.hasX2() && current->hasAttribute(SVGNames::x2Attr))
139 attributes.setX2(linear->x2().valueAsPercentage());
141 if (!attributes.hasY2() && current->hasAttribute(SVGNames::y2Attr))
142 attributes.setY2(linear->y2().valueAsPercentage());
145 processedGradients.add(current);
148 Node* refNode = ownerDocument()->getElementById(SVGURIReference::getTarget(current->href()));
149 if (refNode && (refNode->hasTagName(SVGNames::linearGradientTag) || refNode->hasTagName(SVGNames::radialGradientTag))) {
150 current =
static_cast<const SVGGradientElement*
>(
const_cast<const Node*
>(refNode));
152 kDebug() <<
"take attributes from" << current->getAttributeNS(
"",
"id", ec) << endl;
155 if (processedGradients.contains(current))
156 return LinearGradientAttributes();
158 isLinear = current->gradientType() == LinearGradientPaintServer;
167quint32 SVGLinearGradientElement::id()
const
169 return SVGNames::linearGradientTag.id();