Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2007 Rob Buis <buis (at) kde.org>
      4  * Copyright (C) 2009 Google, Inc.  All rights reserved.
      5  * Copyright (C) 2009 Apple Inc. All rights reserved.
      6  *
      7  * This library is free software; you can redistribute it and/or
      8  * modify it under the terms of the GNU Library General Public
      9  * License as published by the Free Software Foundation; either
     10  * version 2 of the License, or (at your option) any later version.
     11  *
     12  * This library is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  * Library General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU Library General Public License
     18  * along with this library; see the file COPYING.LIB.  If not, write to
     19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     20  * Boston, MA 02110-1301, USA.
     21  */
     22 
     23 #ifndef RenderSVGRoot_h
     24 #define RenderSVGRoot_h
     25 
     26 #include "core/rendering/RenderReplaced.h"
     27 #include "platform/geometry/FloatRect.h"
     28 
     29 namespace blink {
     30 
     31 class SVGElement;
     32 
     33 class RenderSVGRoot FINAL : public RenderReplaced {
     34 public:
     35     explicit RenderSVGRoot(SVGElement*);
     36     virtual ~RenderSVGRoot();
     37     virtual void trace(Visitor*) OVERRIDE;
     38 
     39     bool isEmbeddedThroughSVGImage() const;
     40     bool isEmbeddedThroughFrameContainingSVGDocument() const;
     41 
     42     virtual void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const OVERRIDE;
     43 
     44     RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); }
     45     RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); }
     46 
     47     // If you have a RenderSVGRoot, use firstChild or lastChild instead.
     48     void slowFirstChild() const WTF_DELETED_FUNCTION;
     49     void slowLastChild() const WTF_DELETED_FUNCTION;
     50 
     51     const RenderObjectChildList* children() const { return &m_children; }
     52     RenderObjectChildList* children() { return &m_children; }
     53 
     54     bool isLayoutSizeChanged() const { return m_isLayoutSizeChanged; }
     55     virtual void setNeedsBoundariesUpdate() OVERRIDE { m_needsBoundariesOrTransformUpdate = true; }
     56     virtual void setNeedsTransformUpdate() OVERRIDE { m_needsBoundariesOrTransformUpdate = true; }
     57 
     58     IntSize containerSize() const { return m_containerSize; }
     59     void setContainerSize(const IntSize& containerSize)
     60     {
     61         // SVGImage::draw() does a view layout prior to painting,
     62         // and we need that layout to know of the new size otherwise
     63         // the rendering may be incorrectly using the old size.
     64         if (m_containerSize != containerSize)
     65             setNeedsLayoutAndFullPaintInvalidation();
     66         m_containerSize = containerSize;
     67     }
     68 
     69     // localToBorderBoxTransform maps local SVG viewport coordinates to local CSS box coordinates.
     70     const AffineTransform& localToBorderBoxTransform() const { return m_localToBorderBoxTransform; }
     71 
     72 private:
     73     virtual RenderObjectChildList* virtualChildren() OVERRIDE { return children(); }
     74     virtual const RenderObjectChildList* virtualChildren() const OVERRIDE { return children(); }
     75 
     76     virtual const char* renderName() const OVERRIDE { return "RenderSVGRoot"; }
     77     virtual bool isSVGRoot() const OVERRIDE { return true; }
     78     virtual bool isSVG() const OVERRIDE { return true; }
     79 
     80     virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred  = ComputeActual) const OVERRIDE;
     81     virtual LayoutUnit computeReplacedLogicalHeight() const OVERRIDE;
     82     virtual void layout() OVERRIDE;
     83     virtual void paintReplaced(PaintInfo&, const LayoutPoint&) OVERRIDE;
     84 
     85     virtual void willBeDestroyed() OVERRIDE;
     86     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
     87     virtual bool isChildAllowed(RenderObject*, RenderStyle*) const OVERRIDE;
     88     virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0) OVERRIDE;
     89     virtual void removeChild(RenderObject*) OVERRIDE;
     90     virtual bool canHaveWhitespaceChildren() const OVERRIDE { return false; }
     91 
     92     virtual void insertedIntoTree() OVERRIDE;
     93     virtual void willBeRemovedFromTree() OVERRIDE;
     94 
     95     virtual const AffineTransform& localToParentTransform() const OVERRIDE;
     96 
     97     virtual FloatRect objectBoundingBox() const OVERRIDE { return m_objectBoundingBox; }
     98     virtual FloatRect strokeBoundingBox() const OVERRIDE { return m_strokeBoundingBox; }
     99     virtual FloatRect paintInvalidationRectInLocalCoordinates() const OVERRIDE { return m_paintInvalidationBoundingBox; }
    100 
    101     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
    102 
    103     virtual LayoutRect clippedOverflowRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* = 0) const OVERRIDE;
    104     virtual void computeFloatRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, FloatRect& paintInvalidationRect, const PaintInvalidationState* = 0) const OVERRIDE;
    105 
    106     virtual void mapLocalToContainer(const RenderLayerModelObject* paintInvalidationContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0, const PaintInvalidationState* = 0) const OVERRIDE;
    107     virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE;
    108 
    109     virtual bool canBeSelectionLeaf() const OVERRIDE { return false; }
    110     virtual bool canHaveChildren() const OVERRIDE { return true; }
    111 
    112     bool shouldApplyViewportClip() const;
    113     void updateCachedBoundaries();
    114     void buildLocalToBorderBoxTransform();
    115 
    116     RenderObjectChildList m_children;
    117     IntSize m_containerSize;
    118     FloatRect m_objectBoundingBox;
    119     bool m_objectBoundingBoxValid;
    120     FloatRect m_strokeBoundingBox;
    121     FloatRect m_paintInvalidationBoundingBox;
    122     mutable AffineTransform m_localToParentTransform;
    123     AffineTransform m_localToBorderBoxTransform;
    124     bool m_isLayoutSizeChanged : 1;
    125     bool m_needsBoundariesOrTransformUpdate : 1;
    126     bool m_hasBoxDecorationBackground : 1;
    127 };
    128 
    129 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderSVGRoot, isSVGRoot());
    130 
    131 } // namespace blink
    132 
    133 #endif // RenderSVGRoot_h
    134