• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • svg
SVGGradientElement.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4
5 This file is part of the KDE project
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21*/
22
23#include "config.h"
24#include "wtf/Platform.h"
25
26#if ENABLE(SVG)
27#include "SVGGradientElement.h"
28
29#include "css/cssstyleselector.h"
30#include "RenderPath.h"
31#include "RenderSVGHiddenContainer.h"
32#include "SVGNames.h"
33#include "SVGPaintServerLinearGradient.h"
34#include "SVGPaintServerRadialGradient.h"
35#include "SVGStopElement.h"
36#include "SVGTransformList.h"
37#include "SVGTransformable.h"
38#include "SVGUnitTypes.h"
39
40namespace WebCore {
41
42SVGGradientElement::SVGGradientElement(const QualifiedName& tagName, Document* doc)
43 : SVGStyledElement(tagName, doc)
44 , SVGURIReference()
45 , SVGExternalResourcesRequired()
46 , m_spreadMethod(0)
47 , m_gradientUnits(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX)
48 , m_gradientTransform(SVGTransformList::create(SVGNames::gradientTransformAttr))
49{
50}
51
52SVGGradientElement::~SVGGradientElement()
53{
54}
55
56ANIMATED_PROPERTY_DEFINITIONS(SVGGradientElement, int, Enumeration, enumeration, GradientUnits, gradientUnits, SVGNames::gradientUnitsAttr, m_gradientUnits)
57ANIMATED_PROPERTY_DEFINITIONS(SVGGradientElement, SVGTransformList*, TransformList, transformList, GradientTransform, gradientTransform, SVGNames::gradientTransformAttr, m_gradientTransform.get())
58ANIMATED_PROPERTY_DEFINITIONS(SVGGradientElement, int, Enumeration, enumeration, SpreadMethod, spreadMethod, SVGNames::spreadMethodAttr, m_spreadMethod)
59
60void SVGGradientElement::parseMappedAttribute(MappedAttribute* attr)
61{
62 if (attr->name() == SVGNames::gradientUnitsAttr) {
63 if (attr->value() == "userSpaceOnUse")
64 setGradientUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
65 else if (attr->value() == "objectBoundingBox")
66 setGradientUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
67 } else if (attr->name() == SVGNames::gradientTransformAttr) {
68 SVGTransformList* gradientTransforms = gradientTransformBaseValue();
69 if (!SVGTransformable::parseTransformAttribute(gradientTransforms, attr->value())) {
70 ExceptionCode ec = 0;
71 gradientTransforms->clear(ec);
72 }
73 } else if (attr->name() == SVGNames::spreadMethodAttr) {
74 if (attr->value() == "reflect")
75 setSpreadMethodBaseValue(SVG_SPREADMETHOD_REFLECT);
76 else if (attr->value() == "repeat")
77 setSpreadMethodBaseValue(SVG_SPREADMETHOD_REPEAT);
78 else if (attr->value() == "pad")
79 setSpreadMethodBaseValue(SVG_SPREADMETHOD_PAD);
80 } else {
81 if (SVGURIReference::parseMappedAttribute(attr))
82 return;
83 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
84 return;
85
86 SVGStyledElement::parseMappedAttribute(attr);
87 }
88}
89
90void SVGGradientElement::svgAttributeChanged(const QualifiedName& attrName)
91{
92 SVGStyledElement::svgAttributeChanged(attrName);
93
94 if (!m_resource)
95 return;
96
97 if (attrName == SVGNames::gradientUnitsAttr ||
98 attrName == SVGNames::gradientTransformAttr ||
99 attrName == SVGNames::spreadMethodAttr ||
100 SVGURIReference::isKnownAttribute(attrName) ||
101 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
102 SVGStyledElement::isKnownAttribute(attrName))
103 m_resource->invalidate();
104}
105
106void SVGGradientElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
107{
108 SVGStyledElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
109
110 if (m_resource)
111 m_resource->invalidate();
112}
113
114RenderObject* SVGGradientElement::createRenderer(RenderArena* arena, RenderStyle*)
115{
116 return new (arena) RenderSVGHiddenContainer(this);
117}
118
119SVGResource* SVGGradientElement::canvasResource()
120{
121 kDebug() << "request gradient paint server" << endl;
122 if (!m_resource) {
123 if (gradientType() == LinearGradientPaintServer)
124 m_resource = SVGPaintServerLinearGradient::create(this);
125 else
126 m_resource = SVGPaintServerRadialGradient::create(this);
127 }
128
129 return m_resource.get();
130}
131
132Vector<SVGGradientStop> SVGGradientElement::buildStops() const
133{
134 Vector<SVGGradientStop> stops;
135
136 for (Node* n = firstChild(); n; n = n->nextSibling()) {
137 SVGElement* element = n->isSVGElement() ? static_cast<SVGElement*>(n) : 0;
138
139 if (element && element->isGradientStop()) {
140 SVGStopElement* stop = static_cast<SVGStopElement*>(element);
141 float stopOffset = stop->offset();
142
143 RenderStyle* stopStyle = stop->computedStyle();
144 QColor color = stopStyle->svgStyle()->stopColor();
145 float opacity = stopStyle->svgStyle()->stopOpacity();
146
147 stops.append(makeGradientStop(stopOffset, QColor(color.red(), color.green(), color.blue(), int(opacity * 255.))));
148 }
149 }
150
151 return stops;
152}
153
154}
155
156#endif // ENABLE(SVG)
SVGGradientElement.h
SVGNames.h
SVGPaintServerLinearGradient.h
SVGPaintServerRadialGradient.h
SVGStopElement.h
SVGTransformList.h
SVGTransformable.h
SVGUnitTypes.h
kDebug
#define kDebug
create
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
stop
KGuiItem stop()
WebCore::SVGNames::gradientTransformAttr
DOM::QualifiedName gradientTransformAttr
Definition: SVGNames.cpp:183
WebCore
Definition: CSSHelper.h:7
khtml::ExceptionCode
unsigned short ExceptionCode
Definition: ExceptionCode.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal