OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NGFragmentBuilder_h | 5 #ifndef NGFragmentBuilder_h |
6 #define NGFragmentBuilder_h | 6 #define NGFragmentBuilder_h |
7 | 7 |
| 8 #include "core/layout/ng/ng_constraint_space.h" |
| 9 #include "core/layout/ng/ng_floating_object.h" |
8 #include "core/layout/ng/ng_physical_fragment.h" | 10 #include "core/layout/ng/ng_physical_fragment.h" |
9 #include "core/layout/ng/ng_units.h" | 11 #include "core/layout/ng/ng_units.h" |
10 | 12 |
11 namespace blink { | 13 namespace blink { |
12 | 14 |
13 class NGFragment; | 15 class NGFragment; |
14 class NGInlineNode; | 16 class NGInlineNode; |
15 class NGPhysicalBoxFragment; | 17 class NGPhysicalBoxFragment; |
16 class NGPhysicalTextFragment; | 18 class NGPhysicalTextFragment; |
17 | 19 |
18 class CORE_EXPORT NGFragmentBuilder final | 20 class CORE_EXPORT NGFragmentBuilder final |
19 : public GarbageCollectedFinalized<NGFragmentBuilder> { | 21 : public GarbageCollectedFinalized<NGFragmentBuilder> { |
20 public: | 22 public: |
21 NGFragmentBuilder(NGPhysicalFragment::NGFragmentType); | 23 NGFragmentBuilder(NGPhysicalFragment::NGFragmentType); |
22 | 24 |
23 using WeakBoxList = HeapLinkedHashSet<WeakMember<NGBlockNode>>; | 25 using WeakBoxList = HeapLinkedHashSet<WeakMember<NGBlockNode>>; |
24 | 26 |
25 NGFragmentBuilder& SetWritingMode(NGWritingMode); | 27 NGFragmentBuilder& SetWritingMode(NGWritingMode); |
26 NGFragmentBuilder& SetDirection(TextDirection); | 28 NGFragmentBuilder& SetDirection(TextDirection); |
27 | 29 |
28 NGFragmentBuilder& SetInlineSize(LayoutUnit); | 30 NGFragmentBuilder& SetInlineSize(LayoutUnit); |
29 NGFragmentBuilder& SetBlockSize(LayoutUnit); | 31 NGFragmentBuilder& SetBlockSize(LayoutUnit); |
30 NGLogicalSize Size() const { return size_; } | 32 NGLogicalSize Size() const { return size_; } |
31 | 33 |
32 NGFragmentBuilder& SetInlineOverflow(LayoutUnit); | 34 NGFragmentBuilder& SetInlineOverflow(LayoutUnit); |
33 NGFragmentBuilder& SetBlockOverflow(LayoutUnit); | 35 NGFragmentBuilder& SetBlockOverflow(LayoutUnit); |
34 | 36 |
35 NGFragmentBuilder& AddChild(NGFragment*, const NGLogicalOffset&); | 37 NGFragmentBuilder& AddChild(NGFragment*, const NGLogicalOffset&); |
| 38 NGFragmentBuilder& AddFloatingObject(NGFloatingObject*, |
| 39 const NGLogicalOffset&); |
36 | 40 |
37 // Builder has non-trivial out-of-flow descendant methods. | 41 // Builder has non-trivial out-of-flow descendant methods. |
38 // These methods are building blocks for implementation of | 42 // These methods are building blocks for implementation of |
39 // out-of-flow descendants by layout algorithms. | 43 // out-of-flow descendants by layout algorithms. |
40 // | 44 // |
41 // They are intended to be used by layout algorithm like this: | 45 // They are intended to be used by layout algorithm like this: |
42 // | 46 // |
43 // Part 1: layout algorithm positions in-flow children. | 47 // Part 1: layout algorithm positions in-flow children. |
44 // out-of-flow children, and out-of-flow descendants of fragments | 48 // out-of-flow children, and out-of-flow descendants of fragments |
45 // are stored inside builder. | 49 // are stored inside builder. |
(...skipping 27 matching lines...) Expand all Loading... |
73 // } | 77 // } |
74 // } | 78 // } |
75 NGFragmentBuilder& AddOutOfFlowChildCandidate(NGBlockNode*, NGLogicalOffset); | 79 NGFragmentBuilder& AddOutOfFlowChildCandidate(NGBlockNode*, NGLogicalOffset); |
76 | 80 |
77 void GetAndClearOutOfFlowDescendantCandidates(WeakBoxList*, | 81 void GetAndClearOutOfFlowDescendantCandidates(WeakBoxList*, |
78 Vector<NGStaticPosition>*); | 82 Vector<NGStaticPosition>*); |
79 | 83 |
80 NGFragmentBuilder& AddOutOfFlowDescendant(NGBlockNode*, | 84 NGFragmentBuilder& AddOutOfFlowDescendant(NGBlockNode*, |
81 const NGStaticPosition&); | 85 const NGStaticPosition&); |
82 | 86 |
| 87 NGFragmentBuilder& AddUnpositionedFloat(NGFloatingObject* floating_object); |
| 88 |
83 void SetBreakToken(NGBreakToken* token) { | 89 void SetBreakToken(NGBreakToken* token) { |
84 DCHECK(!break_token_); | 90 DCHECK(!break_token_); |
85 break_token_ = token; | 91 break_token_ = token; |
86 } | 92 } |
87 bool HasBreakToken() const { return break_token_; } | 93 bool HasBreakToken() const { return break_token_; } |
88 | 94 |
89 // Sets MarginStrut for the resultant fragment. | 95 // Sets MarginStrut for the resultant fragment. |
90 NGFragmentBuilder& SetMarginStrutBlockStart(const NGMarginStrut& from); | 96 NGFragmentBuilder& SetMarginStrutBlockStart(const NGMarginStrut& from); |
91 NGFragmentBuilder& SetMarginStrutBlockEnd(const NGMarginStrut& from); | 97 NGFragmentBuilder& SetMarginStrutBlockEnd(const NGMarginStrut& from); |
92 | 98 |
93 // Offsets are not supposed to be set during fragment construction, so we | 99 // Offsets are not supposed to be set during fragment construction, so we |
94 // do not provide a setter here. | 100 // do not provide a setter here. |
95 | 101 |
96 // Creates the fragment. Can only be called once. | 102 // Creates the fragment. Can only be called once. |
97 NGPhysicalBoxFragment* ToBoxFragment(); | 103 NGPhysicalBoxFragment* ToBoxFragment(); |
98 NGPhysicalTextFragment* ToTextFragment(NGInlineNode*, | 104 NGPhysicalTextFragment* ToTextFragment(NGInlineNode*, |
99 unsigned start_index, | 105 unsigned start_index, |
100 unsigned end_index); | 106 unsigned end_index); |
101 | 107 |
| 108 // List of floats that need to be positioned. |
| 109 HeapVector<Member<NGFloatingObject>>& UnpositionedFloats() { |
| 110 return unpositioned_floats_; |
| 111 } |
| 112 |
102 DECLARE_VIRTUAL_TRACE(); | 113 DECLARE_VIRTUAL_TRACE(); |
103 | 114 |
104 private: | 115 private: |
105 // Out-of-flow descendant placement information. | 116 // Out-of-flow descendant placement information. |
106 // The generated fragment must compute NGStaticPosition for all | 117 // The generated fragment must compute NGStaticPosition for all |
107 // out-of-flow descendants. | 118 // out-of-flow descendants. |
108 // The resulting NGStaticPosition gets derived from: | 119 // The resulting NGStaticPosition gets derived from: |
109 // 1. The offset of fragment's child. | 120 // 1. The offset of fragment's child. |
110 // 2. The static position of descendant wrt child. | 121 // 2. The static position of descendant wrt child. |
111 // | 122 // |
(...skipping 19 matching lines...) Expand all Loading... |
131 | 142 |
132 HeapVector<Member<NGPhysicalFragment>> children_; | 143 HeapVector<Member<NGPhysicalFragment>> children_; |
133 Vector<NGLogicalOffset> offsets_; | 144 Vector<NGLogicalOffset> offsets_; |
134 | 145 |
135 WeakBoxList out_of_flow_descendant_candidates_; | 146 WeakBoxList out_of_flow_descendant_candidates_; |
136 Vector<OutOfFlowPlacement> out_of_flow_candidate_placements_; | 147 Vector<OutOfFlowPlacement> out_of_flow_candidate_placements_; |
137 | 148 |
138 WeakBoxList out_of_flow_descendants_; | 149 WeakBoxList out_of_flow_descendants_; |
139 Vector<NGStaticPosition> out_of_flow_positions_; | 150 Vector<NGStaticPosition> out_of_flow_positions_; |
140 | 151 |
| 152 // Floats that need to be positioned by the next in-flow fragment that can |
| 153 // determine its block position in space. |
| 154 HeapVector<Member<NGFloatingObject>> unpositioned_floats_; |
| 155 |
| 156 Vector<NGLogicalOffset> floating_object_offsets_; |
| 157 HeapVector<Member<NGFloatingObject>> positioned_floats_; |
| 158 |
141 Member<NGBreakToken> break_token_; | 159 Member<NGBreakToken> break_token_; |
142 }; | 160 }; |
143 | 161 |
144 } // namespace blink | 162 } // namespace blink |
145 | 163 |
146 #endif // NGFragmentBuilder | 164 #endif // NGFragmentBuilder |
OLD | NEW |