Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGAngle.h
1 /*
2  * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifndef SVGAngle_h
23 #define SVGAngle_h
24
25 #include "core/svg/SVGEnumeration.h"
26 #include "core/svg/properties/SVGPropertyHelper.h"
27
28 namespace blink {
29
30 class SVGAngle;
31 class SVGAngleTearOff;
32
33 enum SVGMarkerOrientType {
34     SVGMarkerOrientUnknown = 0,
35     SVGMarkerOrientAuto,
36     SVGMarkerOrientAngle,
37     SVGMarkerOrientAutoStartReverse
38 };
39 template<> const SVGEnumerationStringEntries& getStaticStringEntries<SVGMarkerOrientType>();
40 template<> unsigned short getMaxExposedEnumValue<SVGMarkerOrientType>();
41
42 class SVGMarkerOrientEnumeration : public SVGEnumeration<SVGMarkerOrientType> {
43 public:
44     static PassRefPtr<SVGMarkerOrientEnumeration> create(SVGAngle* angle)
45     {
46         return adoptRef(new SVGMarkerOrientEnumeration(angle));
47     }
48
49     virtual ~SVGMarkerOrientEnumeration();
50
51     virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) override;
52     virtual void calculateAnimatedValue(SVGAnimationElement*, float, unsigned, PassRefPtr<SVGPropertyBase>, PassRefPtr<SVGPropertyBase>, PassRefPtr<SVGPropertyBase>, SVGElement*) override;
53     virtual float calculateDistance(PassRefPtr<SVGPropertyBase>, SVGElement*) override;
54
55 private:
56     SVGMarkerOrientEnumeration(SVGAngle*);
57
58     virtual void notifyChange() override;
59
60     // FIXME: oilpan: This is kept as raw-ptr to avoid reference cycles. Should be Member in oilpan.
61     SVGAngle* m_angle;
62 };
63
64 class SVGAngle : public SVGPropertyHelper<SVGAngle> {
65 public:
66     typedef SVGAngleTearOff TearOffType;
67
68     enum SVGAngleType {
69         SVG_ANGLETYPE_UNKNOWN = 0,
70         SVG_ANGLETYPE_UNSPECIFIED = 1,
71         SVG_ANGLETYPE_DEG = 2,
72         SVG_ANGLETYPE_RAD = 3,
73         SVG_ANGLETYPE_GRAD = 4,
74         SVG_ANGLETYPE_TURN = 5
75     };
76
77     static PassRefPtr<SVGAngle> create()
78     {
79         return adoptRef(new SVGAngle());
80     }
81
82     virtual ~SVGAngle();
83
84     SVGAngleType unitType() const { return m_unitType; }
85
86     void setValue(float);
87     float value() const;
88
89     void setValueInSpecifiedUnits(float valueInSpecifiedUnits) { m_valueInSpecifiedUnits = valueInSpecifiedUnits; }
90     float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; }
91
92     void newValueSpecifiedUnits(SVGAngleType unitType, float valueInSpecifiedUnits);
93     void convertToSpecifiedUnits(SVGAngleType unitType, ExceptionState&);
94
95     SVGEnumeration<SVGMarkerOrientType>* orientType() { return m_orientType.get(); }
96     const SVGEnumeration<SVGMarkerOrientType>* orientType() const { return m_orientType.get(); }
97     void orientTypeChanged();
98
99     // SVGPropertyBase:
100
101     PassRefPtr<SVGAngle> clone() const;
102
103     virtual String valueAsString() const override;
104     void setValueAsString(const String&, ExceptionState&);
105
106     virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) override;
107     virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBase> to, PassRefPtr<SVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement) override;
108     virtual float calculateDistance(PassRefPtr<SVGPropertyBase> to, SVGElement* contextElement) override;
109
110     static AnimatedPropertyType classType() { return AnimatedAngle; }
111
112 private:
113     SVGAngle();
114     SVGAngle(SVGAngleType, float, SVGMarkerOrientType);
115
116     void assign(const SVGAngle&);
117
118     SVGAngleType m_unitType;
119     float m_valueInSpecifiedUnits;
120     RefPtr<SVGMarkerOrientEnumeration> m_orientType;
121 };
122
123 inline PassRefPtr<SVGAngle> toSVGAngle(PassRefPtr<SVGPropertyBase> passBase)
124 {
125     RefPtr<SVGPropertyBase> base = passBase;
126     ASSERT(base->type() == SVGAngle::classType());
127     return static_pointer_cast<SVGAngle>(base.release());
128 }
129
130 } // namespace blink
131
132 #endif // SVGAngle_h