Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / svg / RenderSVGRoot.h
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
28 namespace blink {
29
30 class SVGElement;
31
32 class RenderSVGRoot final : public RenderReplaced {
33 public:
34     explicit RenderSVGRoot(SVGElement*);
35     virtual ~RenderSVGRoot();
36     virtual void trace(Visitor*) override;
37
38     bool isEmbeddedThroughSVGImage() const;
39     bool isEmbeddedThroughFrameContainingSVGDocument() const;
40
41     virtual void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const override;
42
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;
46
47     RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); }
48     RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); }
49
50     bool isLayoutSizeChanged() const { return m_isLayoutSizeChanged; }
51     virtual void setNeedsBoundariesUpdate() override { m_needsBoundariesOrTransformUpdate = true; }
52     virtual void setNeedsTransformUpdate() override { m_needsBoundariesOrTransformUpdate = true; }
53
54     IntSize containerSize() const { return m_containerSize; }
55     void setContainerSize(const IntSize& containerSize)
56     {
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;
63     }
64
65     // localToBorderBoxTransform maps local SVG viewport coordinates to local CSS box coordinates.
66     const AffineTransform& localToBorderBoxTransform() const { return m_localToBorderBoxTransform; }
67     bool shouldApplyViewportClip() const;
68
69
70
71 private:
72     const RenderObjectChildList* children() const { return &m_children; }
73     RenderObjectChildList* children() { return &m_children; }
74
75     virtual RenderObjectChildList* virtualChildren() override { return children(); }
76     virtual const RenderObjectChildList* virtualChildren() const override { return children(); }
77
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); }
80
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;
85
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; }
92
93     virtual void insertedIntoTree() override;
94     virtual void willBeRemovedFromTree() override;
95
96     virtual const AffineTransform& localToParentTransform() const override;
97
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; }
101
102     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override;
103
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;
106
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;
109
110     virtual bool canBeSelectionLeaf() const override { return false; }
111     virtual bool canHaveChildren() const override { return true; }
112
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