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/platform/graphics/FloatRect.h" 27 #include "core/rendering/RenderReplaced.h" 28 #include "core/rendering/svg/SVGRenderSupport.h" 29 30 namespace WebCore { 31 32 class AffineTransform; 33 class SVGElement; 34 35 class RenderSVGRoot FINAL : public RenderReplaced { 36 public: 37 explicit RenderSVGRoot(SVGElement*); 38 virtual ~RenderSVGRoot(); 39 40 bool isEmbeddedThroughSVGImage() const; 41 bool isEmbeddedThroughFrameContainingSVGDocument() const; 42 43 virtual void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio, bool& isPercentageIntrinsicSize) const; 44 45 RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); } 46 RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); } 47 48 const RenderObjectChildList* children() const { return &m_children; } 49 RenderObjectChildList* children() { return &m_children; } 50 51 bool isLayoutSizeChanged() const { return m_isLayoutSizeChanged; } 52 virtual void setNeedsBoundariesUpdate() { m_needsBoundariesOrTransformUpdate = true; } 53 virtual bool needsBoundariesUpdate() OVERRIDE { return m_needsBoundariesOrTransformUpdate; } 54 virtual void setNeedsTransformUpdate() { m_needsBoundariesOrTransformUpdate = true; } 55 56 IntSize containerSize() const { return m_containerSize; } 57 void setContainerSize(const IntSize& containerSize) { m_containerSize = containerSize; } 58 59 virtual bool hasRelativeDimensions() const OVERRIDE; 60 virtual bool hasRelativeIntrinsicLogicalWidth() const OVERRIDE; 61 virtual bool hasRelativeLogicalHeight() const OVERRIDE; 62 63 // localToBorderBoxTransform maps local SVG viewport coordinates to local CSS box coordinates. 64 const AffineTransform& localToBorderBoxTransform() const { return m_localToBorderBoxTransform; } 65 66 // The flag is cleared at the beginning of each layout() pass. Elements then call this 67 // method during layout when they are invalidated by a filter. 68 static void addResourceForClientInvalidation(RenderSVGResourceContainer*); 69 70 private: 71 virtual RenderObjectChildList* virtualChildren() { return children(); } 72 virtual const RenderObjectChildList* virtualChildren() const { return children(); } 73 74 virtual bool isSVGRoot() const { return true; } 75 virtual const char* renderName() const { return "RenderSVGRoot"; } 76 77 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const OVERRIDE; 78 virtual LayoutUnit computeReplacedLogicalHeight() const; 79 virtual void layout(); 80 virtual void paintReplaced(PaintInfo&, const LayoutPoint&); 81 82 virtual void willBeDestroyed(); 83 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle); 84 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); 85 virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0) OVERRIDE; 86 virtual void removeChild(RenderObject*) OVERRIDE; 87 88 virtual const AffineTransform& localToParentTransform() const; 89 90 bool fillContains(const FloatPoint&) const; 91 bool strokeContains(const FloatPoint&) const; 92 93 virtual FloatRect objectBoundingBox() const { return m_objectBoundingBox; } 94 virtual FloatRect strokeBoundingBox() const { return m_strokeBoundingBox; } 95 virtual FloatRect repaintRectInLocalCoordinates() const { return m_repaintBoundingBox; } 96 97 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE; 98 99 virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE; 100 virtual void computeFloatRectForRepaint(const RenderLayerModelObject* repaintContainer, FloatRect& repaintRect, bool fixed) const OVERRIDE; 101 102 virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE; 103 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE; 104 105 virtual bool canBeSelectionLeaf() const { return false; } 106 virtual bool canHaveChildren() const { return true; } 107 108 void updateCachedBoundaries(); 109 void buildLocalToBorderBoxTransform(); 110 111 RenderObjectChildList m_children; 112 IntSize m_containerSize; 113 FloatRect m_objectBoundingBox; 114 bool m_objectBoundingBoxValid; 115 FloatRect m_strokeBoundingBox; 116 FloatRect m_repaintBoundingBox; 117 mutable AffineTransform m_localToParentTransform; 118 AffineTransform m_localToBorderBoxTransform; 119 HashSet<RenderSVGResourceContainer*> m_resourcesNeedingToInvalidateClients; 120 bool m_isLayoutSizeChanged : 1; 121 bool m_needsBoundariesOrTransformUpdate : 1; 122 }; 123 124 inline RenderSVGRoot* toRenderSVGRoot(RenderObject* object) 125 { 126 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isSVGRoot()); 127 return static_cast<RenderSVGRoot*>(object); 128 } 129 130 inline const RenderSVGRoot* toRenderSVGRoot(const RenderObject* object) 131 { 132 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isSVGRoot()); 133 return static_cast<const RenderSVGRoot*>(object); 134 } 135 136 // This will catch anyone doing an unnecessary cast. 137 void toRenderSVGRoot(const RenderSVGRoot*); 138 139 } // namespace WebCore 140 141 #endif // RenderSVGRoot_h 142