Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2006 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 SVGMarkerElement_h
     22 #define SVGMarkerElement_h
     23 
     24 #include "bindings/v8/ExceptionState.h"
     25 #include "core/svg/SVGAnimatedAngle.h"
     26 #include "core/svg/SVGAnimatedBoolean.h"
     27 #include "core/svg/SVGAnimatedEnumeration.h"
     28 #include "core/svg/SVGAnimatedLength.h"
     29 #include "core/svg/SVGAnimatedPreserveAspectRatio.h"
     30 #include "core/svg/SVGAnimatedRect.h"
     31 #include "core/svg/SVGElement.h"
     32 #include "core/svg/SVGExternalResourcesRequired.h"
     33 #include "core/svg/SVGFitToViewBox.h"
     34 
     35 namespace WebCore {
     36 
     37 enum SVGMarkerUnitsType {
     38     SVGMarkerUnitsUnknown = 0,
     39     SVGMarkerUnitsUserSpaceOnUse,
     40     SVGMarkerUnitsStrokeWidth
     41 };
     42 
     43 enum SVGMarkerOrientType {
     44     SVGMarkerOrientUnknown = 0,
     45     SVGMarkerOrientAuto,
     46     SVGMarkerOrientAngle
     47 };
     48 
     49 template<>
     50 struct SVGPropertyTraits<SVGMarkerUnitsType> {
     51     static unsigned highestEnumValue() { return SVGMarkerUnitsStrokeWidth; }
     52 
     53     static String toString(SVGMarkerUnitsType type)
     54     {
     55         switch (type) {
     56         case SVGMarkerUnitsUnknown:
     57             return emptyString();
     58         case SVGMarkerUnitsUserSpaceOnUse:
     59             return "userSpaceOnUse";
     60         case SVGMarkerUnitsStrokeWidth:
     61             return "strokeWidth";
     62         }
     63 
     64         ASSERT_NOT_REACHED();
     65         return emptyString();
     66     }
     67 
     68     static SVGMarkerUnitsType fromString(const String& value)
     69     {
     70         if (value == "userSpaceOnUse")
     71             return SVGMarkerUnitsUserSpaceOnUse;
     72         if (value == "strokeWidth")
     73             return SVGMarkerUnitsStrokeWidth;
     74         return SVGMarkerUnitsUnknown;
     75     }
     76 };
     77 
     78 template<>
     79 struct SVGPropertyTraits<SVGMarkerOrientType> {
     80     static unsigned highestEnumValue() { return SVGMarkerOrientAngle; }
     81 
     82     // toString is not needed, synchronizeOrientType() handles this on its own.
     83 
     84     static SVGMarkerOrientType fromString(const String& value, SVGAngle& angle)
     85     {
     86         if (value == "auto")
     87             return SVGMarkerOrientAuto;
     88 
     89         TrackExceptionState es;
     90         angle.setValueAsString(value, es);
     91         if (!es.hadException())
     92             return SVGMarkerOrientAngle;
     93         return SVGMarkerOrientUnknown;
     94     }
     95 };
     96 
     97 class SVGMarkerElement FINAL : public SVGElement,
     98                                public SVGExternalResourcesRequired,
     99                                public SVGFitToViewBox {
    100 public:
    101     // Forward declare enumerations in the W3C naming scheme, for IDL generation.
    102     enum {
    103         SVG_MARKERUNITS_UNKNOWN = SVGMarkerUnitsUnknown,
    104         SVG_MARKERUNITS_USERSPACEONUSE = SVGMarkerUnitsUserSpaceOnUse,
    105         SVG_MARKERUNITS_STROKEWIDTH = SVGMarkerUnitsStrokeWidth
    106     };
    107 
    108     enum {
    109         SVG_MARKER_ORIENT_UNKNOWN = SVGMarkerOrientUnknown,
    110         SVG_MARKER_ORIENT_AUTO = SVGMarkerOrientAuto,
    111         SVG_MARKER_ORIENT_ANGLE = SVGMarkerOrientAngle
    112     };
    113 
    114     static PassRefPtr<SVGMarkerElement> create(const QualifiedName&, Document*);
    115 
    116     AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
    117 
    118     void setOrientToAuto();
    119     void setOrientToAngle(const SVGAngle&);
    120 
    121     static const SVGPropertyInfo* orientTypePropertyInfo();
    122 
    123 private:
    124     SVGMarkerElement(const QualifiedName&, Document*);
    125 
    126     virtual bool needsPendingResourceHandling() const { return false; }
    127 
    128     bool isSupportedAttribute(const QualifiedName&);
    129     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
    130     virtual void svgAttributeChanged(const QualifiedName&);
    131     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
    132 
    133     virtual RenderObject* createRenderer(RenderStyle*);
    134     virtual bool rendererIsNeeded(const NodeRenderingContext&) { return true; }
    135 
    136     virtual bool selfHasRelativeLengths() const;
    137 
    138     void synchronizeOrientType();
    139 
    140     static const AtomicString& orientTypeIdentifier();
    141     static const AtomicString& orientAngleIdentifier();
    142 
    143     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGMarkerElement)
    144         DECLARE_ANIMATED_LENGTH(RefX, refX)
    145         DECLARE_ANIMATED_LENGTH(RefY, refY)
    146         DECLARE_ANIMATED_LENGTH(MarkerWidth, markerWidth)
    147         DECLARE_ANIMATED_LENGTH(MarkerHeight, markerHeight)
    148         DECLARE_ANIMATED_ENUMERATION(MarkerUnits, markerUnits, SVGMarkerUnitsType)
    149         DECLARE_ANIMATED_ANGLE(OrientAngle, orientAngle)
    150         DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired)
    151         DECLARE_ANIMATED_RECT(ViewBox, viewBox)
    152         DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio)
    153     END_DECLARE_ANIMATED_PROPERTIES
    154 
    155 public:
    156     // Custom 'orientType' property.
    157     static void synchronizeOrientType(SVGElement* contextElement);
    158     static PassRefPtr<SVGAnimatedProperty> lookupOrCreateOrientTypeWrapper(SVGElement* contextElement);
    159     SVGMarkerOrientType& orientTypeCurrentValue() const { return m_orientType.value; }
    160     SVGMarkerOrientType& orientTypeBaseValue() const { return m_orientType.value; }
    161     void setOrientTypeBaseValue(const SVGMarkerOrientType& type) { m_orientType.value = type; }
    162     PassRefPtr<SVGAnimatedEnumerationPropertyTearOff<SVGMarkerOrientType> > orientType();
    163 
    164 private:
    165     mutable SVGSynchronizableAnimatedProperty<SVGMarkerOrientType> m_orientType;
    166 };
    167 
    168 inline SVGMarkerElement* toSVGMarkerElement(Node* node)
    169 {
    170     ASSERT_WITH_SECURITY_IMPLICATION(!node || node->hasTagName(SVGNames::markerTag));
    171     return static_cast<SVGMarkerElement*>(node);
    172 }
    173 
    174 }
    175 
    176 #endif
    177