Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2006, 2007, 2010 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 SVGSVGElement_h
     22 #define SVGSVGElement_h
     23 
     24 #if ENABLE(SVG)
     25 #include "SVGAnimatedBoolean.h"
     26 #include "SVGAnimatedLength.h"
     27 #include "SVGAnimatedPreserveAspectRatio.h"
     28 #include "SVGAnimatedRect.h"
     29 #include "SVGExternalResourcesRequired.h"
     30 #include "SVGFitToViewBox.h"
     31 #include "SVGLangSpace.h"
     32 #include "SVGStyledLocatableElement.h"
     33 #include "SVGTests.h"
     34 #include "SVGZoomAndPan.h"
     35 
     36 namespace WebCore {
     37 
     38 class SVGAngle;
     39 class SVGMatrix;
     40 class SVGTransform;
     41 class SVGViewSpec;
     42 class SVGViewElement;
     43 class SMILTimeContainer;
     44 
     45 class SVGSVGElement : public SVGStyledLocatableElement,
     46                       public SVGTests,
     47                       public SVGLangSpace,
     48                       public SVGExternalResourcesRequired,
     49                       public SVGFitToViewBox,
     50                       public SVGZoomAndPan {
     51 public:
     52     static PassRefPtr<SVGSVGElement> create(const QualifiedName&, Document*);
     53 
     54     virtual bool isValid() const { return SVGTests::isValid(); }
     55 
     56     // 'SVGSVGElement' functions
     57     const AtomicString& contentScriptType() const;
     58     void setContentScriptType(const AtomicString& type);
     59 
     60     const AtomicString& contentStyleType() const;
     61     void setContentStyleType(const AtomicString& type);
     62 
     63     FloatRect viewport() const;
     64 
     65     void setContainerSize(const IntSize& containerSize) { m_containerSize = containerSize; m_hasSetContainerSize = true; }
     66     IntSize containerSize() const { return m_containerSize; }
     67     bool hasSetContainerSize() const { return m_hasSetContainerSize; }
     68     int relativeWidthValue() const;
     69     int relativeHeightValue() const;
     70 
     71     float pixelUnitToMillimeterX() const;
     72     float pixelUnitToMillimeterY() const;
     73     float screenPixelToMillimeterX() const;
     74     float screenPixelToMillimeterY() const;
     75 
     76     bool useCurrentView() const;
     77     void setUseCurrentView(bool currentView);
     78 
     79     SVGViewSpec* currentView() const;
     80 
     81     float currentScale() const;
     82     void setCurrentScale(float scale);
     83 
     84     FloatPoint& currentTranslate() { return m_translation; }
     85     void setCurrentTranslate(const FloatPoint&);
     86 
     87     // Only used from the bindings.
     88     void updateCurrentTranslate();
     89 
     90     SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); }
     91 
     92     void pauseAnimations();
     93     void unpauseAnimations();
     94     bool animationsPaused() const;
     95 
     96     float getCurrentTime() const;
     97     void setCurrentTime(float seconds);
     98 
     99     unsigned suspendRedraw(unsigned maxWaitMilliseconds);
    100     void unsuspendRedraw(unsigned suspendHandleId);
    101     void unsuspendRedrawAll();
    102     void forceRedraw();
    103 
    104     NodeList* getIntersectionList(const FloatRect&, SVGElement* referenceElement);
    105     NodeList* getEnclosureList(const FloatRect&, SVGElement* referenceElement);
    106     bool checkIntersection(SVGElement*, const FloatRect&);
    107     bool checkEnclosure(SVGElement*, const FloatRect&);
    108     void deselectAll();
    109 
    110     static float createSVGNumber();
    111     static SVGLength createSVGLength();
    112     static SVGAngle createSVGAngle();
    113     static FloatPoint createSVGPoint();
    114     static SVGMatrix createSVGMatrix();
    115     static FloatRect createSVGRect();
    116     static SVGTransform createSVGTransform();
    117     static SVGTransform createSVGTransformFromMatrix(const SVGMatrix&);
    118 
    119     AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
    120 
    121     void inheritViewAttributes(SVGViewElement*);
    122 
    123     bool isOutermostSVG() const;
    124 
    125     Element* getElementById(const AtomicString&) const;
    126 
    127 protected:
    128     virtual void willMoveToNewOwnerDocument();
    129     virtual void didMoveToNewOwnerDocument();
    130 
    131 private:
    132     SVGSVGElement(const QualifiedName&, Document*);
    133     virtual ~SVGSVGElement();
    134 
    135     virtual bool isSVG() const { return true; }
    136 
    137     virtual void parseMappedAttribute(Attribute*);
    138 
    139     virtual bool rendererIsNeeded(RenderStyle* style) { return StyledElement::rendererIsNeeded(style); }
    140     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
    141 
    142     virtual void insertedIntoDocument();
    143     virtual void removedFromDocument();
    144 
    145     virtual void svgAttributeChanged(const QualifiedName&);
    146     virtual void synchronizeProperty(const QualifiedName&);
    147     virtual void fillAttributeToPropertyTypeMap();
    148     virtual AttributeToPropertyTypeMap& attributeToPropertyTypeMap();
    149 
    150     virtual bool selfHasRelativeLengths() const;
    151 
    152     // Animated property declarations
    153     DECLARE_ANIMATED_LENGTH(X, x)
    154     DECLARE_ANIMATED_LENGTH(Y, y)
    155     DECLARE_ANIMATED_LENGTH(Width, width)
    156     DECLARE_ANIMATED_LENGTH(Height, height)
    157 
    158     // SVGExternalResourcesRequired
    159     DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired)
    160 
    161     // SVGFitToViewBox
    162     DECLARE_ANIMATED_RECT(ViewBox, viewBox)
    163     DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio)
    164 
    165     virtual void documentWillBecomeInactive();
    166     virtual void documentDidBecomeActive();
    167 
    168     virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope) const;
    169 
    170     bool m_useCurrentView;
    171     RefPtr<SMILTimeContainer> m_timeContainer;
    172     FloatPoint m_translation;
    173     float m_scale;
    174     mutable OwnPtr<SVGViewSpec> m_viewSpec;
    175     IntSize m_containerSize;
    176     bool m_hasSetContainerSize;
    177 };
    178 
    179 } // namespace WebCore
    180 
    181 #endif // ENABLE(SVG)
    182 #endif
    183