initial import
[vuplus_webkit] / Source / WebCore / svg / SVGPathSegWithContext.h
1 /*
2  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef SVGPathSegWithContext_h
21 #define SVGPathSegWithContext_h
22
23 #if ENABLE(SVG)
24 #include "SVGPathElement.h"
25
26 namespace WebCore {
27
28 class SVGPathSegWithContext : public SVGPathSeg {
29 public:
30     SVGPathSegWithContext(SVGPathElement* element, SVGPathSegRole role)
31         : m_role(role)
32         , m_element(element)
33     {
34     }
35
36     SVGAnimatedProperty* animatedProperty() const
37     {
38         switch (m_role) {
39         case PathSegUndefinedRole:
40             return 0;
41         case PathSegUnalteredRole:
42             return SVGAnimatedProperty::lookupWrapper<SVGPathElement, SVGAnimatedPathSegListPropertyTearOff, true>(m_element.get(), SVGPathElement::dPropertyInfo());
43         case PathSegNormalizedRole:
44             // FIXME: https://bugs.webkit.org/show_bug.cgi?id=15412 - Implement normalized path segment lists!
45             return 0;
46         };
47
48         return 0;
49     }
50
51     SVGPathElement* contextElement() const { return m_element.get(); }
52     SVGPathSegRole role() const { return m_role; }
53
54     void setContextAndRole(SVGPathElement* element, SVGPathSegRole role)
55     {
56         m_role = role;
57         m_element = element;
58     }
59
60 protected:
61     void commitChange()
62     {
63         if (!m_element) {
64             ASSERT(m_role == PathSegUndefinedRole);
65             return;
66         }
67
68         ASSERT(m_role != PathSegUndefinedRole);
69         m_element->pathSegListChanged(m_role);
70     }
71
72 private:
73     SVGPathSegRole m_role;
74     RefPtr<SVGPathElement> m_element;
75 };
76
77 class SVGPathSegSingleCoordinate : public SVGPathSegWithContext { 
78 public:
79     float x() const { return m_x; }
80     void setX(float x)
81     {
82         m_x = x;
83         commitChange();
84     }
85
86     float y() const { return m_y; }
87     void setY(float y)
88     {
89         m_y = y;
90         commitChange();
91     }
92
93 protected:
94     SVGPathSegSingleCoordinate(SVGPathElement* element, SVGPathSegRole role, float x, float y)
95         : SVGPathSegWithContext(element, role)
96         , m_x(x)
97         , m_y(y)
98     {
99     }
100
101 private:
102     float m_x;
103     float m_y;
104 };
105
106 } // namespace WebCore
107
108 #endif // ENABLE(SVG)
109 #endif