24 #include "wtf/Platform.h" 40 SVGLinearGradientElement::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%"));
51 SVGLinearGradientElement::~SVGLinearGradientElement()
55 ANIMATED_PROPERTY_DEFINITIONS(SVGLinearGradientElement, SVGLength, Length, length, X1, x1,
SVGNames::x1Attr, m_x1)
56 ANIMATED_PROPERTY_DEFINITIONS(SVGLinearGradientElement, SVGLength, Length, length, Y1, y1,
SVGNames::y1Attr, m_y1)
57 ANIMATED_PROPERTY_DEFINITIONS(SVGLinearGradientElement, SVGLength, Length, length, X2, x2,
SVGNames::x2Attr, m_x2)
58 ANIMATED_PROPERTY_DEFINITIONS(SVGLinearGradientElement, SVGLength, Length, length, Y2, y2,
SVGNames::y2Attr, m_y2)
60 void SVGLinearGradientElement::parseMappedAttribute(MappedAttribute* attr)
63 setX1BaseValue(SVGLength(
this, LengthModeWidth, attr->value()));
65 setY1BaseValue(SVGLength(
this, LengthModeHeight, attr->value()));
67 setX2BaseValue(SVGLength(
this, LengthModeWidth, attr->value()));
69 setY2BaseValue(SVGLength(
this, LengthModeHeight, attr->value()));
71 SVGGradientElement::parseMappedAttribute(attr);
74 void SVGLinearGradientElement::svgAttributeChanged(
const QualifiedName& attrName)
76 SVGGradientElement::svgAttributeChanged(attrName);
83 m_resource->invalidate();
86 void 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()));
104 LinearGradientAttributes SVGLinearGradientElement::collectGradientProperties()
const 106 LinearGradientAttributes attributes;
107 HashSet<const SVGGradientElement*> processedGradients;
109 bool isLinear =
true;
110 const SVGGradientElement* current =
this;
114 attributes.setSpreadMethod((SVGGradientSpreadMethod) current->spreadMethod());
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);
133 attributes.setX1(linear->x1().valueAsPercentage());
136 attributes.setY1(linear->y1().valueAsPercentage());
139 attributes.setX2(linear->x2().valueAsPercentage());
142 attributes.setY2(linear->y2().valueAsPercentage());
145 processedGradients.add(current);
148 Node* refNode = ownerDocument()->getElementById(SVGURIReference::getTarget(current->href()));
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;
167 quint32 SVGLinearGradientElement::id()
const 174 #endif // ENABLE(SVG)
DOM::QualifiedName radialGradientTag
DOM::QualifiedName spreadMethodAttr
DOM::QualifiedName x1Attr
DOM::QualifiedName y1Attr
DOM::QualifiedName linearGradientTag
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
DOM::QualifiedName x2Attr
DOM::QualifiedName gradientTransformAttr
DOM::QualifiedName gradientUnitsAttr
DOM::QualifiedName y2Attr