1 | /* |
2 | * Copyright (C) 2018 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "RenderTreeBuilderSVG.h" |
28 | |
29 | #include "RenderSVGContainer.h" |
30 | #include "RenderSVGInline.h" |
31 | #include "RenderSVGRoot.h" |
32 | #include "RenderSVGText.h" |
33 | #include "RenderTreeBuilderBlock.h" |
34 | #include "RenderTreeBuilderBlockFlow.h" |
35 | #include "RenderTreeBuilderInline.h" |
36 | #include "SVGResourcesCache.h" |
37 | |
38 | namespace WebCore { |
39 | |
40 | RenderTreeBuilder::SVG::SVG(RenderTreeBuilder& builder) |
41 | : m_builder(builder) |
42 | { |
43 | } |
44 | |
45 | void RenderTreeBuilder::SVG::attach(RenderSVGContainer& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild) |
46 | { |
47 | auto& childToAdd = *child; |
48 | m_builder.attachToRenderElement(parent, WTFMove(child), beforeChild); |
49 | SVGResourcesCache::clientWasAddedToTree(childToAdd); |
50 | } |
51 | |
52 | void RenderTreeBuilder::SVG::attach(RenderSVGInline& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild) |
53 | { |
54 | auto& childToAdd = *child; |
55 | m_builder.inlineBuilder().attach(parent, WTFMove(child), beforeChild); |
56 | SVGResourcesCache::clientWasAddedToTree(childToAdd); |
57 | |
58 | if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(parent)) |
59 | textAncestor->subtreeChildWasAdded(&childToAdd); |
60 | } |
61 | |
62 | void RenderTreeBuilder::SVG::attach(RenderSVGRoot& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild) |
63 | { |
64 | auto& childToAdd = *child; |
65 | m_builder.attachToRenderElement(parent, WTFMove(child), beforeChild); |
66 | SVGResourcesCache::clientWasAddedToTree(childToAdd); |
67 | } |
68 | |
69 | void RenderTreeBuilder::SVG::attach(RenderSVGText& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild) |
70 | { |
71 | auto& childToAdd = *child; |
72 | m_builder.blockFlowBuilder().attach(parent, WTFMove(child), beforeChild); |
73 | |
74 | SVGResourcesCache::clientWasAddedToTree(childToAdd); |
75 | parent.subtreeChildWasAdded(&childToAdd); |
76 | } |
77 | |
78 | RenderPtr<RenderObject> RenderTreeBuilder::SVG::detach(RenderSVGText& parent, RenderObject& child) |
79 | { |
80 | SVGResourcesCache::clientWillBeRemovedFromTree(child); |
81 | |
82 | Vector<SVGTextLayoutAttributes*, 2> affectedAttributes; |
83 | parent.subtreeChildWillBeRemoved(&child, affectedAttributes); |
84 | auto takenChild = m_builder.blockBuilder().detach(parent, child); |
85 | parent.subtreeChildWasRemoved(affectedAttributes); |
86 | return takenChild; |
87 | } |
88 | |
89 | RenderPtr<RenderObject> RenderTreeBuilder::SVG::detach(RenderSVGInline& parent, RenderObject& child) |
90 | { |
91 | SVGResourcesCache::clientWillBeRemovedFromTree(child); |
92 | |
93 | auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(parent); |
94 | if (!textAncestor) |
95 | return m_builder.detachFromRenderElement(parent, child); |
96 | |
97 | Vector<SVGTextLayoutAttributes*, 2> affectedAttributes; |
98 | textAncestor->subtreeChildWillBeRemoved(&child, affectedAttributes); |
99 | auto takenChild = m_builder.detachFromRenderElement(parent, child); |
100 | textAncestor->subtreeChildWasRemoved(affectedAttributes); |
101 | return takenChild; |
102 | } |
103 | |
104 | RenderPtr<RenderObject> RenderTreeBuilder::SVG::detach(RenderSVGContainer& parent, RenderObject& child) |
105 | { |
106 | SVGResourcesCache::clientWillBeRemovedFromTree(child); |
107 | return m_builder.detachFromRenderElement(parent, child); |
108 | } |
109 | |
110 | RenderPtr<RenderObject> RenderTreeBuilder::SVG::detach(RenderSVGRoot& parent, RenderObject& child) |
111 | { |
112 | SVGResourcesCache::clientWillBeRemovedFromTree(child); |
113 | return m_builder.detachFromRenderElement(parent, child); |
114 | } |
115 | |
116 | } |
117 | |