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_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_box_fragment.h" | 9 #include "core/layout/ng/ng_box_fragment.h" |
10 #include "core/layout/ng/ng_column_mapper.h" | 10 #include "core/layout/ng/ng_column_mapper.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 break; | 307 break; |
308 } | 308 } |
309 | 309 |
310 content_size_ += border_and_padding_.block_end; | 310 content_size_ += border_and_padding_.block_end; |
311 | 311 |
312 // Recompute the block-axis size now that we know our content size. | 312 // Recompute the block-axis size now that we know our content size. |
313 block_size = | 313 block_size = |
314 ComputeBlockSizeForFragment(ConstraintSpace(), Style(), content_size_); | 314 ComputeBlockSizeForFragment(ConstraintSpace(), Style(), content_size_); |
315 builder_->SetBlockSize(block_size); | 315 builder_->SetBlockSize(block_size); |
316 | 316 |
317 // Out of flow setup. | 317 HeapLinkedHashSet<WeakMember<NGBlockNode>> positioned_out_of_flow_children = |
318 out_of_flow_layout_ = new NGOutOfFlowLayoutPart(&Style(), builder_->Size()); | 318 LayoutOutOfFlowChildren(); |
319 builder_->GetAndClearOutOfFlowDescendantCandidates( | |
320 &out_of_flow_candidates_, &out_of_flow_candidate_positions_); | |
321 out_of_flow_candidate_positions_index_ = 0; | |
322 current_child_ = nullptr; | |
323 | |
324 while (!LayoutOutOfFlowChild()) | |
325 continue; | |
326 | 319 |
327 builder_->SetInlineOverflow(max_inline_size_).SetBlockOverflow(content_size_); | 320 builder_->SetInlineOverflow(max_inline_size_).SetBlockOverflow(content_size_); |
328 | 321 |
329 if (ConstraintSpace().HasBlockFragmentation()) | 322 if (ConstraintSpace().HasBlockFragmentation()) |
330 FinalizeForFragmentation(); | 323 FinalizeForFragmentation(); |
331 | 324 |
332 *fragment_out = builder_->ToBoxFragment(); | 325 *fragment_out = builder_->ToBoxFragment(); |
| 326 |
| 327 for (auto& node : positioned_out_of_flow_children) |
| 328 node->PositionUpdated(); |
| 329 |
333 return kNewFragment; | 330 return kNewFragment; |
334 } | 331 } |
335 | 332 |
336 void NGBlockLayoutAlgorithm::FinishCurrentChildLayout(NGFragment* fragment) { | 333 void NGBlockLayoutAlgorithm::FinishCurrentChildLayout(NGFragment* fragment) { |
337 NGBoxStrut child_margins = ComputeMargins( | 334 NGBoxStrut child_margins = ComputeMargins( |
338 *space_for_current_child_, CurrentChildStyle(), | 335 *space_for_current_child_, CurrentChildStyle(), |
339 constraint_space_->WritingMode(), constraint_space_->Direction()); | 336 constraint_space_->WritingMode(), constraint_space_->Direction()); |
340 | 337 |
341 NGLogicalOffset fragment_offset; | 338 NGLogicalOffset fragment_offset; |
342 if (CurrentChildStyle().isFloating()) { | 339 if (CurrentChildStyle().isFloating()) { |
343 fragment_offset = PositionFloatFragment(*fragment, child_margins); | 340 fragment_offset = PositionFloatFragment(*fragment, child_margins); |
344 } else { | 341 } else { |
345 ApplyAutoMargins(*space_for_current_child_, CurrentChildStyle(), *fragment, | 342 ApplyAutoMargins(*space_for_current_child_, CurrentChildStyle(), *fragment, |
346 &child_margins); | 343 &child_margins); |
347 fragment_offset = PositionFragment(*fragment, child_margins); | 344 fragment_offset = PositionFragment(*fragment, child_margins); |
348 } | 345 } |
349 if (fragmentainer_mapper_) | 346 if (fragmentainer_mapper_) |
350 fragmentainer_mapper_->ToVisualOffset(fragment_offset); | 347 fragmentainer_mapper_->ToVisualOffset(fragment_offset); |
351 else | 348 else |
352 fragment_offset.block_offset -= PreviousBreakOffset(); | 349 fragment_offset.block_offset -= PreviousBreakOffset(); |
353 builder_->AddChild(fragment, fragment_offset); | 350 builder_->AddChild(fragment, fragment_offset); |
354 } | 351 } |
355 | 352 |
356 bool NGBlockLayoutAlgorithm::LayoutOutOfFlowChild() { | 353 HeapLinkedHashSet<WeakMember<NGBlockNode>> |
357 if (out_of_flow_candidates_.isEmpty()) { | 354 NGBlockLayoutAlgorithm::LayoutOutOfFlowChildren() { |
358 out_of_flow_layout_ = nullptr; | 355 HeapLinkedHashSet<WeakMember<NGBlockNode>> out_of_flow_candidates; |
359 out_of_flow_candidate_positions_.clear(); | 356 Vector<NGStaticPosition> out_of_flow_candidate_positions; |
360 return true; | 357 builder_->GetAndClearOutOfFlowDescendantCandidates( |
| 358 &out_of_flow_candidates, &out_of_flow_candidate_positions); |
| 359 |
| 360 Member<NGOutOfFlowLayoutPart> out_of_flow_layout = |
| 361 new NGOutOfFlowLayoutPart(&Style(), builder_->Size()); |
| 362 HeapLinkedHashSet<WeakMember<NGBlockNode>> positioned_children; |
| 363 size_t candidate_positions_index = 0; |
| 364 |
| 365 for (auto& child : out_of_flow_candidates) { |
| 366 NGStaticPosition static_position = |
| 367 out_of_flow_candidate_positions[candidate_positions_index++]; |
| 368 |
| 369 if (IsContainingBlockForAbsoluteChild(Style(), *child->Style())) { |
| 370 NGFragment* fragment; |
| 371 NGLogicalOffset offset; |
| 372 out_of_flow_layout->Layout(*child, static_position, &fragment, &offset); |
| 373 // TODO(atotic) Need to adjust size of overflow rect per spec. |
| 374 positioned_children.add(child); |
| 375 builder_->AddChild(fragment, offset); |
| 376 } else { |
| 377 builder_->AddOutOfFlowDescendant(child, static_position); |
| 378 } |
361 } | 379 } |
362 current_child_ = out_of_flow_candidates_.first(); | 380 return positioned_children; |
363 out_of_flow_candidates_.removeFirst(); | |
364 NGStaticPosition static_position = out_of_flow_candidate_positions_ | |
365 [out_of_flow_candidate_positions_index_++]; | |
366 | |
367 if (IsContainingBlockForAbsoluteChild(Style(), *current_child_->Style())) { | |
368 NGFragment* fragment; | |
369 NGLogicalOffset offset; | |
370 out_of_flow_layout_->Layout(*current_child_, static_position, &fragment, | |
371 &offset); | |
372 // TODO(atotic) Need to adjust size of overflow rect per spec. | |
373 builder_->AddChild(fragment, offset); | |
374 } else { | |
375 builder_->AddOutOfFlowDescendant(current_child_, static_position); | |
376 } | |
377 | |
378 return false; | |
379 } | 381 } |
380 | 382 |
381 bool NGBlockLayoutAlgorithm::ProceedToNextUnfinishedSibling( | 383 bool NGBlockLayoutAlgorithm::ProceedToNextUnfinishedSibling( |
382 NGPhysicalFragment* child_fragment) { | 384 NGPhysicalFragment* child_fragment) { |
383 DCHECK(current_child_); | 385 DCHECK(current_child_); |
384 NGBlockNode* finished_child = current_child_; | 386 NGBlockNode* finished_child = current_child_; |
385 current_child_ = current_child_->NextSibling(); | 387 current_child_ = current_child_->NextSibling(); |
386 if (!ConstraintSpace().HasBlockFragmentation() && !fragmentainer_mapper_) | 388 if (!ConstraintSpace().HasBlockFragmentation() && !fragmentainer_mapper_) |
387 return true; | 389 return true; |
388 // If we're resuming layout after a fragmentainer break, we need to skip | 390 // If we're resuming layout after a fragmentainer break, we need to skip |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 | 674 |
673 DEFINE_TRACE(NGBlockLayoutAlgorithm) { | 675 DEFINE_TRACE(NGBlockLayoutAlgorithm) { |
674 NGLayoutAlgorithm::trace(visitor); | 676 NGLayoutAlgorithm::trace(visitor); |
675 visitor->trace(first_child_); | 677 visitor->trace(first_child_); |
676 visitor->trace(constraint_space_); | 678 visitor->trace(constraint_space_); |
677 visitor->trace(break_token_); | 679 visitor->trace(break_token_); |
678 visitor->trace(builder_); | 680 visitor->trace(builder_); |
679 visitor->trace(space_builder_); | 681 visitor->trace(space_builder_); |
680 visitor->trace(space_for_current_child_); | 682 visitor->trace(space_for_current_child_); |
681 visitor->trace(current_child_); | 683 visitor->trace(current_child_); |
682 visitor->trace(out_of_flow_layout_); | |
683 visitor->trace(out_of_flow_candidates_); | |
684 visitor->trace(fragmentainer_mapper_); | 684 visitor->trace(fragmentainer_mapper_); |
685 } | 685 } |
686 | 686 |
687 } // namespace blink | 687 } // namespace blink |
OLD | NEW |