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