Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc

Issue 2752123002: [LayoutNG] Move NGFloatingObject off Oilpan (Closed)
Patch Set: fix comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_block_layout_algorithm.h" 5 #include "core/layout/ng/ng_block_layout_algorithm.h"
6 6
7 #include "core/layout/ng/ng_absolute_utils.h" 7 #include "core/layout/ng/ng_absolute_utils.h"
8 #include "core/layout/ng/ng_block_break_token.h" 8 #include "core/layout/ng/ng_block_break_token.h"
9 #include "core/layout/ng/ng_block_child_iterator.h" 9 #include "core/layout/ng/ng_block_child_iterator.h"
10 #include "core/layout/ng/ng_box_fragment.h" 10 #include "core/layout/ng/ng_box_fragment.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 156 }
157 return opportunity; 157 return opportunity;
158 } 158 }
159 159
160 // Calculates the logical offset for opportunity. 160 // Calculates the logical offset for opportunity.
161 NGLogicalOffset CalculateLogicalOffsetForOpportunity( 161 NGLogicalOffset CalculateLogicalOffsetForOpportunity(
162 const NGLayoutOpportunity& opportunity, 162 const NGLayoutOpportunity& opportunity,
163 const LayoutUnit float_offset, 163 const LayoutUnit float_offset,
164 const NGLogicalOffset& from_offset, 164 const NGLogicalOffset& from_offset,
165 NGFloatingObject* floating_object) { 165 NGFloatingObject* floating_object) {
166 DCHECK(floating_object);
166 auto margins = floating_object->margins; 167 auto margins = floating_object->margins;
167 // Adjust to child's margin. 168 // Adjust to child's margin.
168 LayoutUnit inline_offset = margins.inline_start; 169 LayoutUnit inline_offset = margins.inline_start;
169 LayoutUnit block_offset = margins.block_start; 170 LayoutUnit block_offset = margins.block_start;
170 171
171 // Offset from the opportunity's block/inline start. 172 // Offset from the opportunity's block/inline start.
172 inline_offset += opportunity.offset.inline_offset; 173 inline_offset += opportunity.offset.inline_offset;
173 block_offset += opportunity.offset.block_offset; 174 block_offset += opportunity.offset.block_offset;
174 175
175 // Adjust to float: right offset if needed. 176 // Adjust to float: right offset if needed.
176 inline_offset += float_offset; 177 inline_offset += float_offset;
177 178
178 block_offset -= from_offset.block_offset; 179 block_offset -= from_offset.block_offset;
179 inline_offset -= from_offset.inline_offset; 180 inline_offset -= from_offset.inline_offset;
180 181
181 return NGLogicalOffset(inline_offset, block_offset); 182 return NGLogicalOffset(inline_offset, block_offset);
182 } 183 }
183 184
184 // Calculates the relative position from {@code from_offset} of the 185 // Calculates the relative position from {@code from_offset} of the
185 // floating object that is requested to be positioned from {@code origin_point}. 186 // floating object that is requested to be positioned from {@code origin_point}.
186 NGLogicalOffset PositionFloat(const NGLogicalOffset& origin_point, 187 NGLogicalOffset PositionFloat(const NGLogicalOffset& origin_point,
187 const NGLogicalOffset& from_offset, 188 const NGLogicalOffset& from_offset,
188 NGFloatingObject* floating_object, 189 NGFloatingObject* floating_object,
189 NGConstraintSpace* new_parent_space) { 190 NGConstraintSpace* new_parent_space) {
191 DCHECK(floating_object);
190 const auto* float_space = floating_object->space.get(); 192 const auto* float_space = floating_object->space.get();
191 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; 193 DCHECK(floating_object->fragment) << "Fragment cannot be null here";
192 194
193 // TODO(ikilpatrick): The writing mode switching here looks wrong. 195 // TODO(ikilpatrick): The writing mode switching here looks wrong.
194 NGBoxFragment float_fragment( 196 NGBoxFragment float_fragment(
195 float_space->WritingMode(), 197 float_space->WritingMode(),
196 toNGPhysicalBoxFragment(floating_object->fragment.get())); 198 toNGPhysicalBoxFragment(floating_object->fragment.get()));
197 199
198 // Find a layout opportunity that will fit our float. 200 // Find a layout opportunity that will fit our float.
199 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( 201 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment(
(...skipping 13 matching lines...) Expand all
213 float_fragment, opportunity, float_offset, floating_object->margins, 215 float_fragment, opportunity, float_offset, floating_object->margins,
214 floating_object->exclusion_type); 216 floating_object->exclusion_type);
215 new_parent_space->AddExclusion(exclusion); 217 new_parent_space->AddExclusion(exclusion);
216 218
217 return CalculateLogicalOffsetForOpportunity(opportunity, float_offset, 219 return CalculateLogicalOffsetForOpportunity(opportunity, float_offset,
218 from_offset, floating_object); 220 from_offset, floating_object);
219 } 221 }
220 222
221 // Updates the Floating Object's left offset from the provided parent_space 223 // Updates the Floating Object's left offset from the provided parent_space
222 // and {@code floating_object}'s space and margins. 224 // and {@code floating_object}'s space and margins.
223 void UpdateFloatingObjectLeftOffset( 225 void UpdateFloatingObjectLeftOffset(const NGConstraintSpace& new_parent_space,
224 const NGConstraintSpace& new_parent_space, 226 const NGLogicalOffset& float_logical_offset,
225 const Persistent<NGFloatingObject>& floating_object, 227 NGFloatingObject* floating_object) {
226 const NGLogicalOffset& float_logical_offset) { 228 DCHECK(floating_object);
227 // TODO(glebl): We should use physical offset here. 229 // TODO(glebl): We should use physical offset here.
228 floating_object->left_offset = 230 floating_object->left_offset =
229 floating_object->original_parent_space->BfcOffset().inline_offset - 231 floating_object->original_parent_space->BfcOffset().inline_offset -
230 new_parent_space.BfcOffset().inline_offset + 232 new_parent_space.BfcOffset().inline_offset +
231 float_logical_offset.inline_offset; 233 float_logical_offset.inline_offset;
232 } 234 }
233 235
234 // Positions pending floats stored on the fragment builder starting from 236 // Positions pending floats stored on the fragment builder starting from
235 // {@code origin_point_block_offset}. 237 // {@code origin_point_block_offset}.
236 void PositionPendingFloats(const LayoutUnit origin_point_block_offset, 238 void PositionPendingFloats(const LayoutUnit origin_point_block_offset,
237 NGConstraintSpace* new_parent_space, 239 NGConstraintSpace* new_parent_space,
238 NGFragmentBuilder* builder) { 240 NGFragmentBuilder* builder) {
239 DCHECK(builder->BfcOffset()) << "Parent BFC offset should be known here"; 241 DCHECK(builder->BfcOffset()) << "Parent BFC offset should be known here";
240 LayoutUnit bfc_block_offset = builder->BfcOffset().value().block_offset; 242 LayoutUnit bfc_block_offset = builder->BfcOffset().value().block_offset;
241 243
242 for (auto& floating_object : builder->UnpositionedFloats()) { 244 for (auto& floating_object : builder->UnpositionedFloats()) {
243 const auto* float_space = floating_object->space.get(); 245 const auto* float_space = floating_object->space.get();
244 const NGConstraintSpace* original_parent_space = 246 const NGConstraintSpace* original_parent_space =
245 floating_object->original_parent_space.get(); 247 floating_object->original_parent_space.get();
246 248
247 NGLogicalOffset origin_point = {float_space->BfcOffset().inline_offset, 249 NGLogicalOffset origin_point = {float_space->BfcOffset().inline_offset,
248 origin_point_block_offset}; 250 origin_point_block_offset};
249 NGLogicalOffset from_offset = { 251 NGLogicalOffset from_offset = {
250 original_parent_space->BfcOffset().inline_offset, bfc_block_offset}; 252 original_parent_space->BfcOffset().inline_offset, bfc_block_offset};
251 253
252 NGLogicalOffset float_fragment_offset = PositionFloat( 254 NGLogicalOffset float_fragment_offset = PositionFloat(
253 origin_point, from_offset, floating_object, new_parent_space); 255 origin_point, from_offset, floating_object.get(), new_parent_space);
254 builder->AddFloatingObject(floating_object, float_fragment_offset); 256 builder->AddFloatingObject(floating_object, float_fragment_offset);
255 UpdateFloatingObjectLeftOffset(*new_parent_space, floating_object, 257 UpdateFloatingObjectLeftOffset(*new_parent_space, float_fragment_offset,
256 float_fragment_offset); 258 floating_object.get());
257 } 259 }
258 builder->MutableUnpositionedFloats().clear(); 260 builder->MutableUnpositionedFloats().clear();
259 } 261 }
260 262
261 // Whether an in-flow block-level child creates a new formatting context. 263 // Whether an in-flow block-level child creates a new formatting context.
262 // 264 //
263 // This will *NOT* check the following cases: 265 // This will *NOT* check the following cases:
264 // - The child is out-of-flow, e.g. floating or abs-pos. 266 // - The child is out-of-flow, e.g. floating or abs-pos.
265 // - The child is a inline-level, e.g. "display: inline-block". 267 // - The child is a inline-level, e.g. "display: inline-block".
266 // - The child establishes a new formatting context, but should be a child of 268 // - The child establishes a new formatting context, but should be a child of
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get())); 529 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get()));
528 530
529 // Pull out unpositioned floats to the current fragment. This may needed if 531 // Pull out unpositioned floats to the current fragment. This may needed if
530 // for example the child fragment could not position its floats because it's 532 // for example the child fragment could not position its floats because it's
531 // empty and therefore couldn't determine its position in space. 533 // empty and therefore couldn't determine its position in space.
532 builder_.MutableUnpositionedFloats().appendVector( 534 builder_.MutableUnpositionedFloats().appendVector(
533 layout_result->UnpositionedFloats()); 535 layout_result->UnpositionedFloats());
534 536
535 if (child->Type() == NGLayoutInputNode::kLegacyBlock && 537 if (child->Type() == NGLayoutInputNode::kLegacyBlock &&
536 toNGBlockNode(child)->Style().isFloating()) { 538 toNGBlockNode(child)->Style().isFloating()) {
537 NGFloatingObject* floating_object = new NGFloatingObject( 539 NGFloatingObject* floating_object = new NGFloatingObject(
ikilpatrick 2017/03/15 23:39:18 this should have an adoptRef instead of AddUnposit
Gleb Lanbin 2017/03/16 01:14:34 Done.
538 child_space, constraint_space_, toNGBlockNode(child)->Style(), 540 child_space, constraint_space_, toNGBlockNode(child)->Style(),
539 curr_child_margins_, layout_result->PhysicalFragment().get()); 541 curr_child_margins_, layout_result->PhysicalFragment().get());
540 builder_.AddUnpositionedFloat(floating_object); 542 builder_.AddUnpositionedFloat(floating_object);
541 // No need to postpone the positioning if we know the correct offset. 543 // No need to postpone the positioning if we know the correct offset.
542 if (builder_.BfcOffset()) { 544 if (builder_.BfcOffset()) {
543 NGLogicalOffset origin_point = curr_bfc_offset_; 545 NGLogicalOffset origin_point = curr_bfc_offset_;
544 // Adjust origin point to the margins of the last child. 546 // Adjust origin point to the margins of the last child.
545 // Example: <div style="margin-bottom: 20px"><float></div> 547 // Example: <div style="margin-bottom: 20px"><float></div>
546 // <div style="margin-bottom: 30px"></div> 548 // <div style="margin-bottom: 30px"></div>
547 origin_point.block_offset += curr_margin_strut_.Sum(); 549 origin_point.block_offset += curr_margin_strut_.Sum();
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 DCHECK(builder_.BfcOffset()); 746 DCHECK(builder_.BfcOffset());
745 space_available -= curr_bfc_offset_.block_offset; 747 space_available -= curr_bfc_offset_.block_offset;
746 } 748 }
747 } 749 }
748 space_builder_.SetFragmentainerSpaceAvailable(space_available); 750 space_builder_.SetFragmentainerSpaceAvailable(space_available);
749 751
750 return space_builder_.ToConstraintSpace( 752 return space_builder_.ToConstraintSpace(
751 FromPlatformWritingMode(child_style.getWritingMode())); 753 FromPlatformWritingMode(child_style.getWritingMode()));
752 } 754 }
753 } // namespace blink 755 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698