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 #include "core/svg/SVGAnimatedBoolean.h"
     25 #include "core/svg/SVGAnimatedLength.h"
     26 #include "core/svg/SVGAnimatedPreserveAspectRatio.h"
     27 #include "core/svg/SVGAnimatedRect.h"
     28 #include "core/svg/SVGExternalResourcesRequired.h"
     29 #include "core/svg/SVGFitToViewBox.h"
     30 #include "core/svg/SVGGraphicsElement.h"
     31 #include "core/svg/SVGZoomAndPan.h"
     32 #include "wtf/WeakPtr.h"
     33 
     34 namespace WebCore {
     35 
     36 class SVGAngle;
     37 class SVGMatrix;
     38 class SVGTransform;
     39 class SVGViewSpec;
     40 class SVGViewElement;
     41 class SMILTimeContainer;
     42 
     43 class SVGSVGElement FINAL : public SVGGraphicsElement,
     44                             public SVGExternalResourcesRequired,
     45                             public SVGFitToViewBox,
     46                             public SVGZoomAndPan {
     47 public:
     48     static PassRefPtr<SVGSVGElement> create(Document&);
     49 
     50     using SVGGraphicsElement::ref;
     51     using SVGGraphicsElement::deref;
     52 
     53     virtual bool isValid() const { return SVGTests::isValid(); }
     54     virtual bool supportsFocus() const OVERRIDE { return hasFocusEventListeners(); }
     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     SVGRect viewport() const;
     64 
     65     float pixelUnitToMillimeterX() const;
     66     float pixelUnitToMillimeterY() const;
     67     float screenPixelToMillimeterX() const;
     68     float screenPixelToMillimeterY() const;
     69 
     70     bool useCurrentView() const { return m_useCurrentView; }
     71     SVGViewSpec* currentView();
     72 
     73     enum ConsiderCSSMode {
     74         RespectCSSProperties,
     75         IgnoreCSSProperties
     76     };
     77 
     78     // RenderSVGRoot wants to query the intrinsic size, by only examining the width/height attributes.
     79     Length intrinsicWidth(ConsiderCSSMode = RespectCSSProperties) const;
     80     Length intrinsicHeight(ConsiderCSSMode = RespectCSSProperties) const;
     81     FloatSize currentViewportSize() const;
     82     SVGRect currentViewBoxRect() const;
     83 
     84     float currentScale() const;
     85     void setCurrentScale(float scale);
     86 
     87     SVGPoint& currentTranslate() { return m_translation; }
     88     void setCurrentTranslate(const FloatPoint&);
     89 
     90     // Only used from the bindings.
     91     void updateCurrentTranslate();
     92 
     93     SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); }
     94 
     95     void pauseAnimations();
     96     void unpauseAnimations();
     97     bool animationsPaused() const;
     98 
     99     float getCurrentTime() const;
    100     void setCurrentTime(float seconds);
    101 
    102     unsigned suspendRedraw(unsigned maxWaitMilliseconds);
    103     void unsuspendRedraw(unsigned suspendHandleId);
    104     void unsuspendRedrawAll();
    105     void forceRedraw();
    106 
    107     PassRefPtr<NodeList> getIntersectionList(const SVGRect&, SVGElement* referenceElement) const;
    108     PassRefPtr<NodeList> getEnclosureList(const SVGRect&, SVGElement* referenceElement) const;
    109     bool checkIntersection(SVGElement*, const SVGRect&) const;
    110     bool checkEnclosure(SVGElement*, const SVGRect&) const;
    111     void deselectAll();
    112 
    113     static float createSVGNumber();
    114     static SVGLength createSVGLength();
    115     static SVGAngle createSVGAngle();
    116     static SVGPoint createSVGPoint();
    117     static SVGMatrix createSVGMatrix();
    118     static SVGRect createSVGRect();
    119     static SVGTransform createSVGTransform();
    120     static SVGTransform createSVGTransformFromMatrix(const SVGMatrix&);
    121 
    122     AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
    123 
    124     void setupInitialView(const String& fragmentIdentifier, Element* anchorNode);
    125 
    126     Element* getElementById(const AtomicString&) const;
    127 
    128     bool widthAttributeEstablishesViewport() const;
    129     bool heightAttributeEstablishesViewport() const;
    130 
    131     SVGZoomAndPanType zoomAndPan() const { return m_zoomAndPan; }
    132     void setZoomAndPan(unsigned short zoomAndPan) { m_zoomAndPan = SVGZoomAndPan::parseFromNumber(zoomAndPan); }
    133 
    134     bool hasEmptyViewBox() const { return viewBoxCurrentValue().isValid() && viewBoxCurrentValue().isEmpty(); }
    135 
    136 private:
    137     explicit SVGSVGElement(Document&);
    138     virtual ~SVGSVGElement();
    139 
    140     virtual bool isSVGSVGElement() const OVERRIDE { return true; }
    141 
    142     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
    143 
    144     virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
    145     virtual RenderObject* createRenderer(RenderStyle*);
    146 
    147     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
    148     virtual void removedFrom(ContainerNode*) OVERRIDE;
    149 
    150     virtual void svgAttributeChanged(const QualifiedName&);
    151 
    152     virtual bool selfHasRelativeLengths() const;
    153 
    154     void inheritViewAttributes(SVGViewElement*);
    155 
    156     enum CollectIntersectionOrEnclosure {
    157         CollectIntersectionList,
    158         CollectEnclosureList
    159     };
    160 
    161     PassRefPtr<NodeList> collectIntersectionOrEnclosureList(const SVGRect&, SVGElement*, CollectIntersectionOrEnclosure) const;
    162 
    163     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGSVGElement)
    164         DECLARE_ANIMATED_LENGTH(X, x)
    165         DECLARE_ANIMATED_LENGTH(Y, y)
    166         DECLARE_ANIMATED_LENGTH(Width, width)
    167         DECLARE_ANIMATED_LENGTH(Height, height)
    168         DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired)
    169         DECLARE_ANIMATED_RECT(ViewBox, viewBox)
    170         DECLARE_ANIMATED_PRESERVEASPECTRATIO(PreserveAspectRatio, preserveAspectRatio)
    171     END_DECLARE_ANIMATED_PROPERTIES
    172 
    173     virtual AffineTransform localCoordinateSpaceTransform(SVGElement::CTMScope) const;
    174 
    175     bool m_useCurrentView;
    176     SVGZoomAndPanType m_zoomAndPan;
    177     RefPtr<SMILTimeContainer> m_timeContainer;
    178     SVGPoint m_translation;
    179     RefPtr<SVGViewSpec> m_viewSpec;
    180     WeakPtrFactory<SVGSVGElement> m_weakFactory;
    181 };
    182 
    183 inline bool isSVGSVGElement(const Node& node)
    184 {
    185     return node.isSVGElement() && toSVGElement(node).isSVGSVGElement();
    186 }
    187 
    188 DEFINE_NODE_TYPE_CASTS_WITH_FUNCTION(SVGSVGElement);
    189 
    190 } // namespace WebCore
    191 
    192 #endif
    193