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.
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.
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.
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.
23 #ifndef RenderSVGRoot_h
24 #define RenderSVGRoot_h
26 #include "core/rendering/RenderReplaced.h"
32 class RenderSVGRoot final : public RenderReplaced {
34 explicit RenderSVGRoot(SVGElement*);
35 virtual ~RenderSVGRoot();
36 virtual void trace(Visitor*) override;
38 bool isEmbeddedThroughSVGImage() const;
39 bool isEmbeddedThroughFrameContainingSVGDocument() const;
41 virtual void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const override;
43 // If you have a RenderSVGRoot, use firstChild or lastChild instead.
44 void slowFirstChild() const WTF_DELETED_FUNCTION;
45 void slowLastChild() const WTF_DELETED_FUNCTION;
47 RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); }
48 RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); }
50 bool isLayoutSizeChanged() const { return m_isLayoutSizeChanged; }
51 virtual void setNeedsBoundariesUpdate() override { m_needsBoundariesOrTransformUpdate = true; }
52 virtual void setNeedsTransformUpdate() override { m_needsBoundariesOrTransformUpdate = true; }
54 IntSize containerSize() const { return m_containerSize; }
55 void setContainerSize(const IntSize& containerSize)
57 // SVGImage::draw() does a view layout prior to painting,
58 // and we need that layout to know of the new size otherwise
59 // the rendering may be incorrectly using the old size.
60 if (m_containerSize != containerSize)
61 setNeedsLayoutAndFullPaintInvalidation();
62 m_containerSize = containerSize;
65 // localToBorderBoxTransform maps local SVG viewport coordinates to local CSS box coordinates.
66 const AffineTransform& localToBorderBoxTransform() const { return m_localToBorderBoxTransform; }
67 bool shouldApplyViewportClip() const;
72 const RenderObjectChildList* children() const { return &m_children; }
73 RenderObjectChildList* children() { return &m_children; }
75 virtual RenderObjectChildList* virtualChildren() override { return children(); }
76 virtual const RenderObjectChildList* virtualChildren() const override { return children(); }
78 virtual const char* renderName() const override { return "RenderSVGRoot"; }
79 virtual bool isOfType(RenderObjectType type) const override { return type == RenderObjectSVG || type == RenderObjectSVGRoot || RenderReplaced::isOfType(type); }
81 virtual LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const override;
82 virtual LayoutUnit computeReplacedLogicalHeight() const override;
83 virtual void layout() override;
84 virtual void paintReplaced(PaintInfo&, const LayoutPoint&) override;
86 virtual void willBeDestroyed() override;
87 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
88 virtual bool isChildAllowed(RenderObject*, RenderStyle*) const override;
89 virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0) override;
90 virtual void removeChild(RenderObject*) override;
91 virtual bool canHaveWhitespaceChildren() const override { return false; }
93 virtual void insertedIntoTree() override;
94 virtual void willBeRemovedFromTree() override;
96 virtual const AffineTransform& localToParentTransform() const override;
98 virtual FloatRect objectBoundingBox() const override { return m_objectBoundingBox; }
99 virtual FloatRect strokeBoundingBox() const override { return m_strokeBoundingBox; }
100 virtual FloatRect paintInvalidationRectInLocalCoordinates() const override { return m_paintInvalidationBoundingBox; }
102 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override;
104 virtual LayoutRect clippedOverflowRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* = 0) const override;
105 virtual void computeFloatRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, FloatRect& paintInvalidationRect, const PaintInvalidationState* = 0) const override;
107 virtual void mapLocalToContainer(const RenderLayerModelObject* paintInvalidationContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0, const PaintInvalidationState* = 0) const override;
108 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const override;
110 virtual bool canBeSelectionLeaf() const override { return false; }
111 virtual bool canHaveChildren() const override { return true; }
113 void updateCachedBoundaries();
114 void buildLocalToBorderBoxTransform();
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;
129 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderSVGRoot, isSVGRoot());
133 #endif // RenderSVGRoot_h