Replace PassRef with Ref/Ref&& across the board.
[WebKit-https.git] / Source / WebCore / rendering / svg / RenderSVGInline.cpp
1 /*
2  * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>
3  * Copyright (C) 2006 Apple Inc. All rights reserved.
4  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #include "config.h"
23 #include "RenderSVGInline.h"
24
25 #include "RenderSVGInlineText.h"
26 #include "RenderSVGResource.h"
27 #include "RenderSVGText.h"
28 #include "SVGInlineFlowBox.h"
29 #include "SVGResourcesCache.h"
30
31 namespace WebCore {
32     
33 RenderSVGInline::RenderSVGInline(SVGGraphicsElement& element, Ref<RenderStyle>&& style)
34     : RenderInline(element, WTF::move(style))
35 {
36     setAlwaysCreateLineBoxes();
37 }
38
39 std::unique_ptr<InlineFlowBox> RenderSVGInline::createInlineFlowBox()
40 {
41     auto box = std::make_unique<SVGInlineFlowBox>(*this);
42     box->setHasVirtualLogicalHeight();
43     return WTF::move(box);
44 }
45
46 FloatRect RenderSVGInline::objectBoundingBox() const
47 {
48     if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
49         return textAncestor->objectBoundingBox();
50
51     return FloatRect();
52 }
53
54 FloatRect RenderSVGInline::strokeBoundingBox() const
55 {
56     if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
57         return textAncestor->strokeBoundingBox();
58
59     return FloatRect();
60 }
61
62 FloatRect RenderSVGInline::repaintRectInLocalCoordinates() const
63 {
64     if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
65         return textAncestor->repaintRectInLocalCoordinates();
66
67     return FloatRect();
68 }
69
70 LayoutRect RenderSVGInline::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
71 {
72     return SVGRenderSupport::clippedOverflowRectForRepaint(*this, repaintContainer);
73 }
74
75 void RenderSVGInline::computeFloatRectForRepaint(const RenderLayerModelObject* repaintContainer, FloatRect& repaintRect, bool fixed) const
76 {
77     SVGRenderSupport::computeFloatRectForRepaint(*this, repaintContainer, repaintRect, fixed);
78 }
79
80 void RenderSVGInline::mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState& transformState, MapCoordinatesFlags, bool* wasFixed) const
81 {
82     SVGRenderSupport::mapLocalToContainer(*this, repaintContainer, transformState, wasFixed);
83 }
84
85 const RenderObject* RenderSVGInline::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
86 {
87     return SVGRenderSupport::pushMappingToContainer(*this, ancestorToStopAt, geometryMap);
88 }
89
90 void RenderSVGInline::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
91 {
92     auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this);
93     if (!textAncestor)
94         return;
95
96     FloatRect textBoundingBox = textAncestor->strokeBoundingBox();
97     for (InlineFlowBox* box = firstLineBox(); box; box = box->nextLineBox())
98         quads.append(localToAbsoluteQuad(FloatRect(textBoundingBox.x() + box->x(), textBoundingBox.y() + box->y(), box->logicalWidth(), box->logicalHeight()), false, wasFixed));
99 }
100
101 void RenderSVGInline::willBeDestroyed()
102 {
103     SVGResourcesCache::clientDestroyed(*this);
104     RenderInline::willBeDestroyed();
105 }
106
107 void RenderSVGInline::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
108 {
109     if (diff == StyleDifferenceLayout)
110         setNeedsBoundariesUpdate();
111     RenderInline::styleDidChange(diff, oldStyle);
112     SVGResourcesCache::clientStyleChanged(*this, diff, style());
113 }
114
115 void RenderSVGInline::updateFromStyle()
116 {
117     RenderInline::updateFromStyle();
118
119     // SVG text layout code expects us to be an inline-level element.
120     setInline(true);
121 }
122
123 void RenderSVGInline::addChild(RenderObject* child, RenderObject* beforeChild)
124 {
125     RenderInline::addChild(child, beforeChild);
126     SVGResourcesCache::clientWasAddedToTree(*child);
127
128     if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this))
129         textAncestor->subtreeChildWasAdded(child);
130 }
131
132 void RenderSVGInline::removeChild(RenderObject& child)
133 {
134     SVGResourcesCache::clientWillBeRemovedFromTree(child);
135
136     auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this);
137     if (!textAncestor) {
138         RenderInline::removeChild(child);
139         return;
140     }
141
142     Vector<SVGTextLayoutAttributes*, 2> affectedAttributes;
143     textAncestor->subtreeChildWillBeRemoved(&child, affectedAttributes);
144     RenderInline::removeChild(child);
145     textAncestor->subtreeChildWasRemoved(affectedAttributes);
146 }
147
148 }