Home | History | Annotate | Download | only in svg
      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.get(), 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.get(); }
     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         ASSERT(m_role != PathSegUndefinedRole);
     68         m_element->pathSegListChanged(m_role);
     69     }
     70 
     71 private:
     72     SVGPathSegRole m_role;
     73     RefPtr<SVGPathElement> m_element;
     74 };
     75 
     76 class SVGPathSegSingleCoordinate : public SVGPathSegWithContext {
     77 public:
     78     float x() const { return m_x; }
     79     void setX(float x)
     80     {
     81         m_x = x;
     82         commitChange();
     83     }
     84 
     85     float y() const { return m_y; }
     86     void setY(float y)
     87     {
     88         m_y = y;
     89         commitChange();
     90     }
     91 
     92 protected:
     93     SVGPathSegSingleCoordinate(SVGPathElement* element, SVGPathSegRole role, float x, float y)
     94         : SVGPathSegWithContext(element, role)
     95         , m_x(x)
     96         , m_y(y)
     97     {
     98     }
     99 
    100 private:
    101     float m_x;
    102     float m_y;
    103 };
    104 
    105 } // namespace WebCore
    106 
    107 #endif
    108