1 | /* |
2 | * Copyright (C) 2017 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 | #pragma once |
27 | |
28 | #include "RenderTreePosition.h" |
29 | |
30 | namespace WebCore { |
31 | |
32 | class RenderFullScreen; |
33 | class RenderGrid; |
34 | class RenderTreeUpdater; |
35 | |
36 | class RenderTreeBuilder { |
37 | public: |
38 | RenderTreeBuilder(RenderView&); |
39 | ~RenderTreeBuilder(); |
40 | |
41 | // This avoids having to convert all sites that need RenderTreeBuilder in one go. |
42 | // FIXME: Remove. |
43 | static RenderTreeBuilder* current() { return s_current; } |
44 | |
45 | void attach(RenderTreePosition&, RenderPtr<RenderObject>); |
46 | void attach(RenderElement& parent, RenderPtr<RenderObject>, RenderObject* beforeChild = nullptr); |
47 | |
48 | enum class CanCollapseAnonymousBlock { No, Yes }; |
49 | RenderPtr<RenderObject> detach(RenderElement&, RenderObject&, CanCollapseAnonymousBlock = CanCollapseAnonymousBlock::Yes) WARN_UNUSED_RETURN; |
50 | |
51 | void destroy(RenderObject& renderer); |
52 | |
53 | // NormalizeAfterInsertion::Yes ensures that the destination subtree is consistent after the insertion (anonymous wrappers etc). |
54 | enum class NormalizeAfterInsertion { No, Yes }; |
55 | void move(RenderBoxModelObject& from, RenderBoxModelObject& to, RenderObject& child, NormalizeAfterInsertion); |
56 | |
57 | void updateAfterDescendants(RenderElement&); |
58 | void destroyAndCleanUpAnonymousWrappers(RenderObject& child); |
59 | void normalizeTreeAfterStyleChange(RenderElement&, RenderStyle& oldStyle); |
60 | |
61 | #if ENABLE(FULLSCREEN_API) |
62 | void createPlaceholderForFullScreen(RenderFullScreen&, std::unique_ptr<RenderStyle>, const LayoutRect&); |
63 | #endif |
64 | |
65 | private: |
66 | void childFlowStateChangesAndAffectsParentBlock(RenderElement& child); |
67 | void childFlowStateChangesAndNoLongerAffectsParentBlock(RenderElement& child); |
68 | void attachIgnoringContinuation(RenderElement& parent, RenderPtr<RenderObject>, RenderObject* beforeChild = nullptr); |
69 | void attachToRenderGrid(RenderGrid& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr); |
70 | void attachToRenderElement(RenderElement& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr); |
71 | void attachToRenderElementInternal(RenderElement& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr); |
72 | |
73 | RenderPtr<RenderObject> detachFromRenderElement(RenderElement& parent, RenderObject& child) WARN_UNUSED_RETURN; |
74 | RenderPtr<RenderObject> detachFromRenderGrid(RenderGrid& parent, RenderObject& child) WARN_UNUSED_RETURN; |
75 | |
76 | void move(RenderBoxModelObject& from, RenderBoxModelObject& to, RenderObject& child, RenderObject* beforeChild, NormalizeAfterInsertion); |
77 | // Move all of the kids from |startChild| up to but excluding |endChild|. 0 can be passed as the |endChild| to denote |
78 | // that all the kids from |startChild| onwards should be moved. |
79 | void moveChildren(RenderBoxModelObject& from, RenderBoxModelObject& to, RenderObject* startChild, RenderObject* endChild, NormalizeAfterInsertion); |
80 | void moveChildren(RenderBoxModelObject& from, RenderBoxModelObject& to, RenderObject* startChild, RenderObject* endChild, RenderObject* beforeChild, NormalizeAfterInsertion); |
81 | void moveAllChildrenIncludingFloats(RenderBlock& from, RenderBlock& toBlock, RenderTreeBuilder::NormalizeAfterInsertion); |
82 | void moveAllChildren(RenderBoxModelObject& from, RenderBoxModelObject& to, NormalizeAfterInsertion); |
83 | void moveAllChildren(RenderBoxModelObject& from, RenderBoxModelObject& to, RenderObject* beforeChild, NormalizeAfterInsertion); |
84 | |
85 | RenderObject* splitAnonymousBoxesAroundChild(RenderBox& parent, RenderObject& originalBeforeChild); |
86 | void makeChildrenNonInline(RenderBlock& parent, RenderObject* insertionPoint = nullptr); |
87 | void removeAnonymousWrappersForInlineChildrenIfNeeded(RenderElement& parent); |
88 | |
89 | class FirstLetter; |
90 | class List; |
91 | class MultiColumn; |
92 | class Table; |
93 | class Ruby; |
94 | class FormControls; |
95 | class Block; |
96 | class BlockFlow; |
97 | class Inline; |
98 | class SVG; |
99 | #if ENABLE(MATHML) |
100 | class MathML; |
101 | #endif |
102 | class Continuation; |
103 | #if ENABLE(FULLSCREEN_API) |
104 | class FullScreen; |
105 | #endif |
106 | |
107 | FirstLetter& firstLetterBuilder() { return *m_firstLetterBuilder; } |
108 | List& listBuilder() { return *m_listBuilder; } |
109 | MultiColumn& multiColumnBuilder() { return *m_multiColumnBuilder; } |
110 | Table& tableBuilder() { return *m_tableBuilder; } |
111 | Ruby& rubyBuilder() { return *m_rubyBuilder; } |
112 | FormControls& formControlsBuilder() { return *m_formControlsBuilder; } |
113 | Block& blockBuilder() { return *m_blockBuilder; } |
114 | BlockFlow& blockFlowBuilder() { return *m_blockFlowBuilder; } |
115 | Inline& inlineBuilder() { return *m_inlineBuilder; } |
116 | SVG& svgBuilder() { return *m_svgBuilder; } |
117 | #if ENABLE(MATHML) |
118 | MathML& mathMLBuilder() { return *m_mathMLBuilder; } |
119 | #endif |
120 | Continuation& continuationBuilder() { return *m_continuationBuilder; } |
121 | #if ENABLE(FULLSCREEN_API) |
122 | FullScreen& fullScreenBuilder() { return *m_fullScreenBuilder; } |
123 | #endif |
124 | |
125 | RenderView& m_view; |
126 | RenderTreeBuilder* m_previous { nullptr }; |
127 | static RenderTreeBuilder* s_current; |
128 | |
129 | std::unique_ptr<FirstLetter> m_firstLetterBuilder; |
130 | std::unique_ptr<List> m_listBuilder; |
131 | std::unique_ptr<MultiColumn> m_multiColumnBuilder; |
132 | std::unique_ptr<Table> m_tableBuilder; |
133 | std::unique_ptr<Ruby> m_rubyBuilder; |
134 | std::unique_ptr<FormControls> m_formControlsBuilder; |
135 | std::unique_ptr<Block> m_blockBuilder; |
136 | std::unique_ptr<BlockFlow> m_blockFlowBuilder; |
137 | std::unique_ptr<Inline> m_inlineBuilder; |
138 | std::unique_ptr<SVG> m_svgBuilder; |
139 | #if ENABLE(MATHML) |
140 | std::unique_ptr<MathML> m_mathMLBuilder; |
141 | #endif |
142 | std::unique_ptr<Continuation> m_continuationBuilder; |
143 | #if ENABLE(FULLSCREEN_API) |
144 | std::unique_ptr<FullScreen> m_fullScreenBuilder; |
145 | #endif |
146 | }; |
147 | |
148 | } |
149 | |