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 #include "core/svg/properties/SVGAnimatedPathSegListPropertyTearOff.h" 24 25 namespace WebCore { 26 27 class SVGPathSegWithContext : public SVGPathSeg { 28 public: 29 SVGPathSegWithContext(SVGPathElement* element, SVGPathSegRole role) 30 : m_role(role) 31 , m_element(element) 32 { 33 } 34 35 SVGAnimatedProperty* animatedProperty() const 36 { 37 switch (m_role) { 38 case PathSegUndefinedRole: 39 return 0; 40 case PathSegUnalteredRole: 41 return SVGAnimatedProperty::lookupWrapper<SVGPathElement, SVGAnimatedPathSegListPropertyTearOff>(m_element, SVGPathElement::dPropertyInfo()); 42 case PathSegNormalizedRole: 43 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=15412 - Implement normalized path segment lists! 44 return 0; 45 }; 46 47 return 0; 48 } 49 50 SVGPathElement* contextElement() const { return m_element; } 51 SVGPathSegRole role() const { return m_role; } 52 53 void setContextAndRole(SVGPathElement* element, SVGPathSegRole role) 54 { 55 m_role = role; 56 m_element = element; 57 } 58 59 protected: 60 void commitChange() 61 { 62 if (!m_element) { 63 ASSERT(m_role == PathSegUndefinedRole); 64 return; 65 } 66 67 m_element->pathSegListChanged(m_role); 68 } 69 70 private: 71 SVGPathSegRole m_role; 72 SVGPathElement* m_element; 73 }; 74 75 class SVGPathSegSingleCoordinate : public SVGPathSegWithContext { 76 public: 77 float x() const { return m_x; } 78 void setX(float x) 79 { 80 m_x = x; 81 commitChange(); 82 } 83 84 float y() const { return m_y; } 85 void setY(float y) 86 { 87 m_y = y; 88 commitChange(); 89 } 90 91 protected: 92 SVGPathSegSingleCoordinate(SVGPathElement* element, SVGPathSegRole role, float x, float y) 93 : SVGPathSegWithContext(element, role) 94 , m_x(x) 95 , m_y(y) 96 { 97 } 98 99 private: 100 float m_x; 101 float m_y; 102 }; 103 104 } // namespace WebCore 105 106 #endif 107