Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGGradientElement.h
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef SVGGradientElement_h
22 #define SVGGradientElement_h
23
24 #include "SVGNames.h"
25 #include "core/svg/SVGAnimatedBoolean.h"
26 #include "core/svg/SVGAnimatedEnumeration.h"
27 #include "core/svg/SVGAnimatedTransformList.h"
28 #include "core/svg/SVGElement.h"
29 #include "core/svg/SVGURIReference.h"
30 #include "core/svg/SVGUnitTypes.h"
31 #include "platform/graphics/Gradient.h"
32
33 namespace WebCore {
34
35 enum SVGSpreadMethodType {
36     SVGSpreadMethodUnknown = 0,
37     SVGSpreadMethodPad,
38     SVGSpreadMethodReflect,
39     SVGSpreadMethodRepeat
40 };
41
42 template<>
43 struct SVGPropertyTraits<SVGSpreadMethodType> {
44     static unsigned highestEnumValue() { return SVGSpreadMethodRepeat; }
45
46     static String toString(SVGSpreadMethodType type)
47     {
48         switch (type) {
49         case SVGSpreadMethodUnknown:
50             return emptyString();
51         case SVGSpreadMethodPad:
52             return "pad";
53         case SVGSpreadMethodReflect:
54             return "reflect";
55         case SVGSpreadMethodRepeat:
56             return "repeat";
57         }
58
59         ASSERT_NOT_REACHED();
60         return emptyString();
61     }
62
63     static SVGSpreadMethodType fromString(const String& value)
64     {
65         if (value == "pad")
66             return SVGSpreadMethodPad;
67         if (value == "reflect")
68             return SVGSpreadMethodReflect;
69         if (value == "repeat")
70             return SVGSpreadMethodRepeat;
71         return SVGSpreadMethodUnknown;
72     }
73 };
74
75 class SVGGradientElement : public SVGElement,
76                            public SVGURIReference {
77 public:
78     enum {
79         SVG_SPREADMETHOD_UNKNOWN = SVGSpreadMethodUnknown,
80         SVG_SPREADMETHOD_PAD = SVGSpreadMethodReflect,
81         SVG_SPREADMETHOD_REFLECT = SVGSpreadMethodRepeat,
82         SVG_SPREADMETHOD_REPEAT = SVGSpreadMethodUnknown
83     };
84
85     Vector<Gradient::ColorStop> buildStops();
86
87 protected:
88     SVGGradientElement(const QualifiedName&, Document&);
89
90     bool isSupportedAttribute(const QualifiedName&);
91     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
92     virtual void svgAttributeChanged(const QualifiedName&) OVERRIDE;
93
94 private:
95     virtual bool needsPendingResourceHandling() const OVERRIDE FINAL { return false; }
96
97     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0) OVERRIDE FINAL;
98
99     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGGradientElement)
100         DECLARE_ANIMATED_ENUMERATION(SpreadMethod, spreadMethod, SVGSpreadMethodType)
101         DECLARE_ANIMATED_ENUMERATION(GradientUnits, gradientUnits, SVGUnitTypes::SVGUnitType)
102         DECLARE_ANIMATED_TRANSFORM_LIST(GradientTransform, gradientTransform)
103     END_DECLARE_ANIMATED_PROPERTIES
104 };
105
106 inline bool isSVGGradientElement(const Node& node)
107 {
108     return node.hasTagName(SVGNames::radialGradientTag) || node.hasTagName(SVGNames::linearGradientTag);
109 }
110
111 DEFINE_NODE_TYPE_CASTS_WITH_FUNCTION(SVGGradientElement);
112
113 } // namespace WebCore
114
115 #endif