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 #include "core/layout/ng/ng_fragment_builder.h" | 5 #include "core/layout/ng/ng_fragment_builder.h" |
6 | 6 |
7 #include "core/layout/ng/ng_block_node.h" | 7 #include "core/layout/ng/ng_block_node.h" |
8 #include "core/layout/ng/ng_break_token.h" | 8 #include "core/layout/ng/ng_break_token.h" |
9 #include "core/layout/ng/ng_fragment.h" | 9 #include "core/layout/ng/ng_fragment.h" |
10 #include "core/layout/ng/ng_physical_box_fragment.h" | 10 #include "core/layout/ng/ng_physical_box_fragment.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 size_t oof_index = 0; | 62 size_t oof_index = 0; |
63 for (auto& oof_node : physical_fragment->OutOfFlowDescendants()) { | 63 for (auto& oof_node : physical_fragment->OutOfFlowDescendants()) { |
64 NGStaticPosition oof_position = oof_positions[oof_index++]; | 64 NGStaticPosition oof_position = oof_positions[oof_index++]; |
65 out_of_flow_descendant_candidates_.add(oof_node); | 65 out_of_flow_descendant_candidates_.add(oof_node); |
66 out_of_flow_candidate_placements_.push_back( | 66 out_of_flow_candidate_placements_.push_back( |
67 OutOfFlowPlacement{child_offset, oof_position}); | 67 OutOfFlowPlacement{child_offset, oof_position}); |
68 } | 68 } |
69 return *this; | 69 return *this; |
70 } | 70 } |
71 | 71 |
72 NGFragmentBuilder& NGFragmentBuilder::AddFloatingObject( | |
73 NGFloatingObject* floating_object, | |
74 const NGLogicalOffset& floating_object_offset) { | |
75 positioned_floats_.append(floating_object); | |
76 floating_object_offsets_.append(floating_object_offset); | |
77 return *this; | |
78 } | |
79 | |
72 NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowChildCandidate( | 80 NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowChildCandidate( |
73 NGBlockNode* child, | 81 NGBlockNode* child, |
74 NGLogicalOffset child_offset) { | 82 NGLogicalOffset child_offset) { |
75 out_of_flow_descendant_candidates_.add(child); | 83 out_of_flow_descendant_candidates_.add(child); |
76 NGStaticPosition child_position = | 84 NGStaticPosition child_position = |
77 NGStaticPosition::Create(writing_mode_, direction_, NGPhysicalOffset()); | 85 NGStaticPosition::Create(writing_mode_, direction_, NGPhysicalOffset()); |
78 out_of_flow_candidate_placements_.push_back( | 86 out_of_flow_candidate_placements_.push_back( |
79 OutOfFlowPlacement{child_offset, child_position}); | 87 OutOfFlowPlacement{child_offset, child_position}); |
80 child->SaveStaticOffsetForLegacy(child_offset); | 88 child->SaveStaticOffsetForLegacy(child_offset); |
81 return *this; | 89 return *this; |
82 } | 90 } |
83 | 91 |
92 NGFragmentBuilder& NGFragmentBuilder::AddUnpositionedFloat( | |
93 NGFloatingObject* floating_object) { | |
94 unpositioned_floats_.append(floating_object); | |
95 return *this; | |
96 } | |
97 | |
84 void NGFragmentBuilder::GetAndClearOutOfFlowDescendantCandidates( | 98 void NGFragmentBuilder::GetAndClearOutOfFlowDescendantCandidates( |
85 WeakBoxList* descendants, | 99 WeakBoxList* descendants, |
86 Vector<NGStaticPosition>* descendant_positions) { | 100 Vector<NGStaticPosition>* descendant_positions) { |
87 DCHECK(descendants->isEmpty()); | 101 DCHECK(descendants->isEmpty()); |
88 DCHECK(descendant_positions->isEmpty()); | 102 DCHECK(descendant_positions->isEmpty()); |
89 | 103 |
90 DCHECK_GE(size_.inline_size, LayoutUnit()); | 104 DCHECK_GE(size_.inline_size, LayoutUnit()); |
91 DCHECK_GE(size_.block_size, LayoutUnit()); | 105 DCHECK_GE(size_.block_size, LayoutUnit()); |
92 NGPhysicalSize builder_physical_size{size_.ConvertToPhysical(writing_mode_)}; | 106 NGPhysicalSize builder_physical_size{size_.ConvertToPhysical(writing_mode_)}; |
93 | 107 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 NGPhysicalSize physical_size = size_.ConvertToPhysical(writing_mode_); | 158 NGPhysicalSize physical_size = size_.ConvertToPhysical(writing_mode_); |
145 HeapVector<Member<const NGPhysicalFragment>> children; | 159 HeapVector<Member<const NGPhysicalFragment>> children; |
146 children.reserveCapacity(children_.size()); | 160 children.reserveCapacity(children_.size()); |
147 | 161 |
148 for (size_t i = 0; i < children_.size(); ++i) { | 162 for (size_t i = 0; i < children_.size(); ++i) { |
149 NGPhysicalFragment* child = children_[i].get(); | 163 NGPhysicalFragment* child = children_[i].get(); |
150 child->SetOffset(offsets_[i].ConvertToPhysical( | 164 child->SetOffset(offsets_[i].ConvertToPhysical( |
151 writing_mode_, direction_, physical_size, child->Size())); | 165 writing_mode_, direction_, physical_size, child->Size())); |
152 children.push_back(child); | 166 children.push_back(child); |
153 } | 167 } |
168 | |
169 HeapVector<Member<NGFloatingObject>> positioned_floats; | |
170 positioned_floats.reserveCapacity(positioned_floats_.size()); | |
171 | |
172 for (size_t i = 0; i < positioned_floats_.size(); ++i) { | |
173 Member<NGFloatingObject>& floating_object = positioned_floats_[i]; | |
174 NGPhysicalFragment* floating_fragment = floating_object->fragment; | |
175 floating_fragment->SetOffset(floating_object_offsets_[i].ConvertToPhysical( | |
176 writing_mode_, direction_, physical_size, floating_fragment->Size())); | |
177 positioned_floats.append(floating_object); | |
178 } | |
179 | |
154 return new NGPhysicalBoxFragment( | 180 return new NGPhysicalBoxFragment( |
155 physical_size, overflow_.ConvertToPhysical(writing_mode_), children, | 181 physical_size, overflow_.ConvertToPhysical(writing_mode_), children, |
156 out_of_flow_descendants_, out_of_flow_positions_, margin_strut_, | 182 out_of_flow_descendants_, out_of_flow_positions_, margin_strut_, |
157 break_token); | 183 unpositioned_floats_, positioned_floats_, break_token); |
158 } | 184 } |
159 | 185 |
160 NGPhysicalTextFragment* NGFragmentBuilder::ToTextFragment(NGInlineNode* node, | 186 NGPhysicalTextFragment* NGFragmentBuilder::ToTextFragment(NGInlineNode* node, |
161 unsigned start_index, | 187 unsigned start_index, |
162 unsigned end_index) { | 188 unsigned end_index) { |
163 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentText); | 189 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentText); |
164 DCHECK(children_.isEmpty()); | 190 DCHECK(children_.isEmpty()); |
165 DCHECK(offsets_.isEmpty()); | 191 DCHECK(offsets_.isEmpty()); |
192 | |
193 HeapVector<Member<NGFloatingObject>> empty_unpositioned_floats; | |
194 HeapVector<Member<NGFloatingObject>> empty_positioned_floats; | |
195 | |
166 return new NGPhysicalTextFragment( | 196 return new NGPhysicalTextFragment( |
167 node, start_index, end_index, size_.ConvertToPhysical(writing_mode_), | 197 node, start_index, end_index, size_.ConvertToPhysical(writing_mode_), |
168 overflow_.ConvertToPhysical(writing_mode_), out_of_flow_descendants_, | 198 overflow_.ConvertToPhysical(writing_mode_), out_of_flow_descendants_, |
169 out_of_flow_positions_); | 199 out_of_flow_positions_, empty_unpositioned_floats, |
200 empty_positioned_floats); | |
170 } | 201 } |
171 | 202 |
172 DEFINE_TRACE(NGFragmentBuilder) { | 203 DEFINE_TRACE(NGFragmentBuilder) { |
173 visitor->trace(children_); | 204 visitor->trace(children_); |
174 visitor->trace(out_of_flow_descendant_candidates_); | 205 visitor->trace(out_of_flow_descendant_candidates_); |
175 visitor->trace(out_of_flow_descendants_); | 206 visitor->trace(out_of_flow_descendants_); |
176 visitor->trace(break_token_); | 207 visitor->trace(break_token_); |
ikilpatrick
2017/01/20 18:11:14
.nit ordering if changed in header.
Gleb Lanbin
2017/01/20 21:21:59
Done.
| |
208 visitor->trace(positioned_floats_); | |
209 visitor->trace(unpositioned_floats_); | |
177 } | 210 } |
178 | 211 |
179 } // namespace blink | 212 } // namespace blink |
OLD | NEW |