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#pragma once
24
25#include "FloatRect.h"
26#include "RenderReplaced.h"
27#include "SVGRenderSupport.h"
28
29namespace WebCore {
30
31class AffineTransform;
32class RenderSVGResourceContainer;
33class SVGSVGElement;
34
35class RenderSVGRoot final : public RenderReplaced {
36 WTF_MAKE_ISO_ALLOCATED(RenderSVGRoot);
37public:
38 RenderSVGRoot(SVGSVGElement&, RenderStyle&&);
39 virtual ~RenderSVGRoot();
40
41 SVGSVGElement& svgSVGElement() const;
42
43 bool isEmbeddedThroughSVGImage() const;
44 bool isEmbeddedThroughFrameContainingSVGDocument() const;
45
46 void computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const override;
47
48 bool isLayoutSizeChanged() const { return m_isLayoutSizeChanged; }
49 void setNeedsBoundariesUpdate() override { m_needsBoundariesOrTransformUpdate = true; }
50 bool needsBoundariesUpdate() override { return m_needsBoundariesOrTransformUpdate; }
51 void setNeedsTransformUpdate() override { m_needsBoundariesOrTransformUpdate = true; }
52
53 IntSize containerSize() const { return m_containerSize; }
54 void setContainerSize(const IntSize& containerSize) { m_containerSize = containerSize; }
55
56 bool hasRelativeDimensions() const override;
57
58 // localToBorderBoxTransform maps local SVG viewport coordinates to local CSS box coordinates.
59 const AffineTransform& localToBorderBoxTransform() const { return m_localToBorderBoxTransform; }
60
61 // The flag is cleared at the beginning of each layout() pass. Elements then call this
62 // method during layout when they are invalidated by a filter.
63 static void addResourceForClientInvalidation(RenderSVGResourceContainer*);
64
65private:
66 void element() const = delete;
67
68 bool isSVGRoot() const override { return true; }
69 const char* renderName() const override { return "RenderSVGRoot"; }
70
71 LayoutUnit computeReplacedLogicalWidth(ShouldComputePreferred = ComputeActual) const override;
72 LayoutUnit computeReplacedLogicalHeight(Optional<LayoutUnit> estimatedUsedWidth = WTF::nullopt) const override;
73 void layout() override;
74 void paintReplaced(PaintInfo&, const LayoutPoint&) override;
75
76 void willBeDestroyed() override;
77
78 void insertedIntoTree() override;
79 void willBeRemovedFromTree() override;
80
81 void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
82
83 const AffineTransform& localToParentTransform() const override;
84
85 bool fillContains(const FloatPoint&) const;
86 bool strokeContains(const FloatPoint&) const;
87
88 FloatRect objectBoundingBox() const override { return m_objectBoundingBox; }
89 FloatRect strokeBoundingBox() const override { return m_strokeBoundingBox; }
90 FloatRect repaintRectInLocalCoordinates() const override { return m_repaintBoundingBox; }
91
92 bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override;
93
94 LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const override;
95 Optional<FloatRect> computeFloatVisibleRectInContainer(const FloatRect&, const RenderLayerModelObject* container, VisibleRectContext) const override;
96
97 void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags, bool* wasFixed) const override;
98 const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const override;
99
100 bool canBeSelectionLeaf() const override { return false; }
101 bool canHaveChildren() const override { return true; }
102
103 bool shouldApplyViewportClip() const;
104 void updateCachedBoundaries();
105 void buildLocalToBorderBoxTransform();
106
107 IntSize m_containerSize;
108 FloatRect m_objectBoundingBox;
109 bool m_objectBoundingBoxValid;
110 FloatRect m_strokeBoundingBox;
111 FloatRect m_repaintBoundingBox;
112 FloatRect m_repaintBoundingBoxExcludingShadow;
113 mutable AffineTransform m_localToParentTransform;
114 AffineTransform m_localToBorderBoxTransform;
115 HashSet<RenderSVGResourceContainer*> m_resourcesNeedingToInvalidateClients;
116 bool m_isLayoutSizeChanged : 1;
117 bool m_needsBoundariesOrTransformUpdate : 1;
118 bool m_hasBoxDecorations : 1;
119};
120
121} // namespace WebCore
122
123SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderSVGRoot, isSVGRoot())
124