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  * Copyright (C) 2014 Google, Inc.
      5  *
      6  * This library is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Library General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2 of the License, or (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Library General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Library General Public License
     17  * along with this library; see the file COPYING.LIB.  If not, write to
     18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19  * Boston, MA 02110-1301, USA.
     20  */
     21 
     22 #ifndef SVGSVGElement_h
     23 #define SVGSVGElement_h
     24 
     25 #include "core/svg/SVGAnimatedBoolean.h"
     26 #include "core/svg/SVGAnimatedLength.h"
     27 #include "core/svg/SVGFitToViewBox.h"
     28 #include "core/svg/SVGGraphicsElement.h"
     29 #include "core/svg/SVGLengthTearOff.h"
     30 #include "core/svg/SVGPointTearOff.h"
     31 #include "core/svg/SVGZoomAndPan.h"
     32 
     33 namespace blink {
     34 
     35 class SVGMatrixTearOff;
     36 class SVGAngleTearOff;
     37 class SVGNumberTearOff;
     38 class SVGTransformTearOff;
     39 class SVGViewSpec;
     40 class SVGViewElement;
     41 class SMILTimeContainer;
     42 
     43 class SVGSVGElement FINAL : public SVGGraphicsElement,
     44                             public SVGFitToViewBox,
     45                             public SVGZoomAndPan {
     46     DEFINE_WRAPPERTYPEINFO();
     47 public:
     48     DECLARE_NODE_FACTORY(SVGSVGElement);
     49 
     50 #if !ENABLE(OILPAN)
     51     using SVGGraphicsElement::ref;
     52     using SVGGraphicsElement::deref;
     53 #endif
     54 
     55     // 'SVGSVGElement' functions
     56     PassRefPtr<SVGRectTearOff> viewport() const;
     57 
     58     float pixelUnitToMillimeterX() const;
     59     float pixelUnitToMillimeterY() const;
     60     float screenPixelToMillimeterX() const;
     61     float screenPixelToMillimeterY() const;
     62 
     63     bool useCurrentView() const { return m_useCurrentView; }
     64     SVGViewSpec* currentView();
     65 
     66     Length intrinsicWidth() const;
     67     Length intrinsicHeight() const;
     68     FloatSize currentViewportSize() const;
     69     FloatRect currentViewBoxRect() const;
     70 
     71     float currentScale() const;
     72     void setCurrentScale(float scale);
     73 
     74     FloatPoint currentTranslate() { return m_translation->value(); }
     75     void setCurrentTranslate(const FloatPoint&);
     76     PassRefPtr<SVGPointTearOff> currentTranslateFromJavascript();
     77 
     78     SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); }
     79 
     80     void pauseAnimations();
     81     void unpauseAnimations();
     82     bool animationsPaused() const;
     83 
     84     float getCurrentTime() const;
     85     void setCurrentTime(float seconds);
     86 
     87     // Stubs for the deprecated 'redraw' interface.
     88     unsigned suspendRedraw(unsigned) { return 1; }
     89     void unsuspendRedraw(unsigned) { }
     90     void unsuspendRedrawAll() { }
     91     void forceRedraw() { }
     92 
     93     PassRefPtrWillBeRawPtr<StaticNodeList> getIntersectionList(PassRefPtr<SVGRectTearOff>, SVGElement* referenceElement) const;
     94     PassRefPtrWillBeRawPtr<StaticNodeList> getEnclosureList(PassRefPtr<SVGRectTearOff>, SVGElement* referenceElement) const;
     95     bool checkIntersection(SVGElement*, PassRefPtr<SVGRectTearOff>) const;
     96     bool checkEnclosure(SVGElement*, PassRefPtr<SVGRectTearOff>) const;
     97     void deselectAll();
     98 
     99     static PassRefPtr<SVGNumberTearOff> createSVGNumber();
    100     static PassRefPtr<SVGLengthTearOff> createSVGLength();
    101     static PassRefPtr<SVGAngleTearOff> createSVGAngle();
    102     static PassRefPtr<SVGPointTearOff> createSVGPoint();
    103     static PassRefPtr<SVGMatrixTearOff> createSVGMatrix();
    104     static PassRefPtr<SVGRectTearOff> createSVGRect();
    105     static PassRefPtr<SVGTransformTearOff> createSVGTransform();
    106     static PassRefPtr<SVGTransformTearOff> createSVGTransformFromMatrix(PassRefPtr<SVGMatrixTearOff>);
    107 
    108     AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
    109 
    110     void setupInitialView(const String& fragmentIdentifier, Element* anchorNode);
    111 
    112     bool hasIntrinsicWidth() const;
    113     bool hasIntrinsicHeight() const;
    114 
    115     SVGAnimatedLength* x() const { return m_x.get(); }
    116     SVGAnimatedLength* y() const { return m_y.get(); }
    117     SVGAnimatedLength* width() const { return m_width.get(); }
    118     SVGAnimatedLength* height() const { return m_height.get(); }
    119 
    120     virtual void trace(Visitor*) OVERRIDE;
    121 
    122 private:
    123     explicit SVGSVGElement(Document&);
    124     virtual ~SVGSVGElement();
    125 
    126     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
    127     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
    128     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
    129 
    130     virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
    131     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
    132 
    133     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
    134     virtual void removedFrom(ContainerNode*) OVERRIDE;
    135 
    136     virtual void svgAttributeChanged(const QualifiedName&) OVERRIDE;
    137 
    138     virtual bool selfHasRelativeLengths() const OVERRIDE;
    139 
    140     void inheritViewAttributes(SVGViewElement*);
    141 
    142     void updateCurrentTranslate();
    143 
    144     virtual void finishParsingChildren() OVERRIDE;
    145 
    146     enum CheckIntersectionOrEnclosure {
    147         CheckIntersection,
    148         CheckEnclosure
    149     };
    150 
    151     bool checkIntersectionOrEnclosure(const SVGElement&, const FloatRect&, CheckIntersectionOrEnclosure) const;
    152     PassRefPtrWillBeRawPtr<StaticNodeList> collectIntersectionOrEnclosureList(const FloatRect&, SVGElement*, CheckIntersectionOrEnclosure) const;
    153 
    154     RefPtr<SVGAnimatedLength> m_x;
    155     RefPtr<SVGAnimatedLength> m_y;
    156     RefPtr<SVGAnimatedLength> m_width;
    157     RefPtr<SVGAnimatedLength> m_height;
    158 
    159     virtual AffineTransform localCoordinateSpaceTransform(SVGElement::CTMScope) const OVERRIDE;
    160 
    161     bool m_useCurrentView;
    162     RefPtrWillBeMember<SMILTimeContainer> m_timeContainer;
    163     RefPtr<SVGPoint> m_translation;
    164     RefPtrWillBeMember<SVGViewSpec> m_viewSpec;
    165 
    166     friend class SVGCurrentTranslateTearOff;
    167 };
    168 
    169 } // namespace blink
    170 
    171 #endif // SVGSVGElement_h
    172