Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis (at) 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 SVGPathElement_h
     22 #define SVGPathElement_h
     23 
     24 #include "SVGNames.h"
     25 #include "core/svg/SVGAnimatedBoolean.h"
     26 #include "core/svg/SVGAnimatedNumber.h"
     27 #include "core/svg/SVGExternalResourcesRequired.h"
     28 #include "core/svg/SVGGeometryElement.h"
     29 #include "core/svg/SVGPathByteStream.h"
     30 #include "core/svg/SVGPathSegList.h"
     31 
     32 namespace WebCore {
     33 
     34 class SVGPathSegArcAbs;
     35 class SVGPathSegArcRel;
     36 class SVGPathSegClosePath;
     37 class SVGPathSegLinetoAbs;
     38 class SVGPathSegLinetoRel;
     39 class SVGPathSegMovetoAbs;
     40 class SVGPathSegMovetoRel;
     41 class SVGPathSegCurvetoCubicAbs;
     42 class SVGPathSegCurvetoCubicRel;
     43 class SVGPathSegLinetoVerticalAbs;
     44 class SVGPathSegLinetoVerticalRel;
     45 class SVGPathSegLinetoHorizontalAbs;
     46 class SVGPathSegLinetoHorizontalRel;
     47 class SVGPathSegCurvetoQuadraticAbs;
     48 class SVGPathSegCurvetoQuadraticRel;
     49 class SVGPathSegCurvetoCubicSmoothAbs;
     50 class SVGPathSegCurvetoCubicSmoothRel;
     51 class SVGPathSegCurvetoQuadraticSmoothAbs;
     52 class SVGPathSegCurvetoQuadraticSmoothRel;
     53 class SVGPathSegListPropertyTearOff;
     54 
     55 class SVGPathElement FINAL : public SVGGeometryElement,
     56                              public SVGExternalResourcesRequired {
     57 public:
     58     static PassRefPtr<SVGPathElement> create(Document&);
     59 
     60     float getTotalLength();
     61     SVGPoint getPointAtLength(float distance);
     62     unsigned getPathSegAtLength(float distance);
     63 
     64     PassRefPtr<SVGPathSegClosePath> createSVGPathSegClosePath(SVGPathSegRole role = PathSegUndefinedRole);
     65     PassRefPtr<SVGPathSegMovetoAbs> createSVGPathSegMovetoAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
     66     PassRefPtr<SVGPathSegMovetoRel> createSVGPathSegMovetoRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
     67     PassRefPtr<SVGPathSegLinetoAbs> createSVGPathSegLinetoAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
     68     PassRefPtr<SVGPathSegLinetoRel> createSVGPathSegLinetoRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
     69     PassRefPtr<SVGPathSegCurvetoCubicAbs> createSVGPathSegCurvetoCubicAbs(float x, float y, float x1, float y1, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole);
     70     PassRefPtr<SVGPathSegCurvetoCubicRel> createSVGPathSegCurvetoCubicRel(float x, float y, float x1, float y1, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole);
     71     PassRefPtr<SVGPathSegCurvetoQuadraticAbs> createSVGPathSegCurvetoQuadraticAbs(float x, float y, float x1, float y1, SVGPathSegRole role = PathSegUndefinedRole);
     72     PassRefPtr<SVGPathSegCurvetoQuadraticRel> createSVGPathSegCurvetoQuadraticRel(float x, float y, float x1, float y1, SVGPathSegRole role = PathSegUndefinedRole);
     73     PassRefPtr<SVGPathSegArcAbs> createSVGPathSegArcAbs(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, SVGPathSegRole role = PathSegUndefinedRole);
     74     PassRefPtr<SVGPathSegArcRel> createSVGPathSegArcRel(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, SVGPathSegRole role = PathSegUndefinedRole);
     75     PassRefPtr<SVGPathSegLinetoHorizontalAbs> createSVGPathSegLinetoHorizontalAbs(float x, SVGPathSegRole role = PathSegUndefinedRole);
     76     PassRefPtr<SVGPathSegLinetoHorizontalRel> createSVGPathSegLinetoHorizontalRel(float x, SVGPathSegRole role = PathSegUndefinedRole);
     77     PassRefPtr<SVGPathSegLinetoVerticalAbs> createSVGPathSegLinetoVerticalAbs(float y, SVGPathSegRole role = PathSegUndefinedRole);
     78     PassRefPtr<SVGPathSegLinetoVerticalRel> createSVGPathSegLinetoVerticalRel(float y, SVGPathSegRole role = PathSegUndefinedRole);
     79     PassRefPtr<SVGPathSegCurvetoCubicSmoothAbs> createSVGPathSegCurvetoCubicSmoothAbs(float x, float y, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole);
     80     PassRefPtr<SVGPathSegCurvetoCubicSmoothRel> createSVGPathSegCurvetoCubicSmoothRel(float x, float y, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole);
     81     PassRefPtr<SVGPathSegCurvetoQuadraticSmoothAbs> createSVGPathSegCurvetoQuadraticSmoothAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
     82     PassRefPtr<SVGPathSegCurvetoQuadraticSmoothRel> createSVGPathSegCurvetoQuadraticSmoothRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
     83 
     84     // Used in the bindings only.
     85     SVGPathSegListPropertyTearOff* pathSegList();
     86     SVGPathSegListPropertyTearOff* animatedPathSegList();
     87     SVGPathSegListPropertyTearOff* normalizedPathSegList();
     88     SVGPathSegListPropertyTearOff* animatedNormalizedPathSegList();
     89 
     90     SVGPathByteStream* pathByteStream() const;
     91 
     92     void pathSegListChanged(SVGPathSegRole, ListModification = ListModificationUnknown);
     93 
     94     virtual SVGRect getBBox() OVERRIDE FINAL;
     95 
     96     static const SVGPropertyInfo* dPropertyInfo();
     97 
     98     bool isAnimValObserved() const { return m_isAnimValObserved; }
     99 
    100 private:
    101     explicit SVGPathElement(Document&);
    102 
    103     virtual bool isValid() const { return SVGTests::isValid(); }
    104     virtual bool supportsFocus() const OVERRIDE { return hasFocusEventListeners(); }
    105 
    106     bool isSupportedAttribute(const QualifiedName&);
    107     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
    108     virtual void svgAttributeChanged(const QualifiedName&);
    109     virtual bool supportsMarkers() const { return true; }
    110 
    111     // Custom 'd' property
    112     static void synchronizeD(SVGElement* contextElement);
    113     static PassRefPtr<SVGAnimatedProperty> lookupOrCreateDWrapper(SVGElement* contextElement);
    114 
    115     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
    116 
    117     virtual Node::InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
    118     virtual void removedFrom(ContainerNode*) OVERRIDE;
    119 
    120     void invalidateMPathDependencies();
    121 
    122     OwnPtr<SVGPathByteStream> m_pathByteStream;
    123     mutable SVGSynchronizableAnimatedProperty<SVGPathSegList> m_pathSegList;
    124     bool m_isAnimValObserved;
    125 
    126     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGPathElement)
    127         DECLARE_ANIMATED_NUMBER(PathLength, pathLength)
    128         DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired)
    129     END_DECLARE_ANIMATED_PROPERTIES
    130 };
    131 
    132 DEFINE_NODE_TYPE_CASTS(SVGPathElement, hasTagName(SVGNames::pathTag));
    133 
    134 } // namespace WebCore
    135 
    136 #endif
    137