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 #include "core/rendering/RenderReplaced.h" 27 #include "platform/geometry/FloatRect.h" 28 29 namespace WebCore { 30 31 class SVGElement; 32 33 class RenderSVGRoot FINAL : public RenderReplaced { 34 public: 35 explicit RenderSVGRoot(SVGElement*); 36 virtual ~RenderSVGRoot(); 37 38 bool isEmbeddedThroughSVGImage() const; 39 bool isEmbeddedThroughFrameContainingSVGDocument() const; 40 41 virtual void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const OVERRIDE; 42 firstChild()43 RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); } lastChild()44 RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); } 45 46 // If you have a RenderSVGRoot, use firstChild or lastChild instead. 47 void slowFirstChild() const WTF_DELETED_FUNCTION; 48 void slowLastChild() const WTF_DELETED_FUNCTION; 49 children()50 const RenderObjectChildList* children() const { return &m_children; } children()51 RenderObjectChildList* children() { return &m_children; } 52 isLayoutSizeChanged()53 bool isLayoutSizeChanged() const { return m_isLayoutSizeChanged; } setNeedsBoundariesUpdate()54 virtual void setNeedsBoundariesUpdate() OVERRIDE { m_needsBoundariesOrTransformUpdate = true; } setNeedsTransformUpdate()55 virtual void setNeedsTransformUpdate() OVERRIDE { m_needsBoundariesOrTransformUpdate = true; } 56 containerSize()57 IntSize containerSize() const { return m_containerSize; } setContainerSize(const IntSize & containerSize)58 void setContainerSize(const IntSize& containerSize) 59 { 60 // SVGImage::draw() does a view layout prior to painting, 61 // and we need that layout to know of the new size otherwise 62 // the rendering may be incorrectly using the old size. 63 if (m_containerSize != containerSize) 64 setNeedsLayoutAndFullPaintInvalidation(); 65 m_containerSize = containerSize; 66 } 67 68 // localToBorderBoxTransform maps local SVG viewport coordinates to local CSS box coordinates. localToBorderBoxTransform()69 const AffineTransform& localToBorderBoxTransform() const { return m_localToBorderBoxTransform; } 70 71 private: virtualChildren()72 virtual RenderObjectChildList* virtualChildren() OVERRIDE { return children(); } virtualChildren()73 virtual const RenderObjectChildList* virtualChildren() const OVERRIDE { return children(); } 74 renderName()75 virtual const char* renderName() const OVERRIDE { return "RenderSVGRoot"; } isSVGRoot()76 virtual bool isSVGRoot() const OVERRIDE { return true; } isSVG()77 virtual bool isSVG() const OVERRIDE { return true; } 78 79 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const OVERRIDE; 80 virtual LayoutUnit computeReplacedLogicalHeight() const OVERRIDE; 81 virtual void layout() OVERRIDE; 82 virtual void paintReplaced(PaintInfo&, const LayoutPoint&) OVERRIDE; 83 84 virtual void willBeDestroyed() OVERRIDE; 85 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE; 86 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const OVERRIDE; 87 virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0) OVERRIDE; 88 virtual void removeChild(RenderObject*) OVERRIDE; canHaveWhitespaceChildren()89 virtual bool canHaveWhitespaceChildren() const OVERRIDE { return false; } 90 91 virtual void insertedIntoTree() OVERRIDE; 92 virtual void willBeRemovedFromTree() OVERRIDE; 93 94 virtual const AffineTransform& localToParentTransform() const OVERRIDE; 95 objectBoundingBox()96 virtual FloatRect objectBoundingBox() const OVERRIDE { return m_objectBoundingBox; } strokeBoundingBox()97 virtual FloatRect strokeBoundingBox() const OVERRIDE { return m_strokeBoundingBox; } paintInvalidationRectInLocalCoordinates()98 virtual FloatRect paintInvalidationRectInLocalCoordinates() const OVERRIDE { return m_repaintBoundingBox; } 99 100 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE; 101 102 virtual LayoutRect clippedOverflowRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer) const OVERRIDE; 103 virtual void computeFloatRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, FloatRect& paintInvalidationRect, bool fixed) const OVERRIDE; 104 105 virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE; 106 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE; 107 canBeSelectionLeaf()108 virtual bool canBeSelectionLeaf() const OVERRIDE { return false; } canHaveChildren()109 virtual bool canHaveChildren() const OVERRIDE { return true; } 110 111 bool shouldApplyViewportClip() const; 112 void updateCachedBoundaries(); 113 void buildLocalToBorderBoxTransform(); 114 115 RenderObjectChildList m_children; 116 IntSize m_containerSize; 117 FloatRect m_objectBoundingBox; 118 bool m_objectBoundingBoxValid; 119 FloatRect m_strokeBoundingBox; 120 FloatRect m_repaintBoundingBox; 121 mutable AffineTransform m_localToParentTransform; 122 AffineTransform m_localToBorderBoxTransform; 123 bool m_isLayoutSizeChanged : 1; 124 bool m_needsBoundariesOrTransformUpdate : 1; 125 bool m_hasBoxDecorations : 1; 126 }; 127 128 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderSVGRoot, isSVGRoot()); 129 130 } // namespace WebCore 131 132 #endif // RenderSVGRoot_h 133