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_constraint_space.h" | 7 #include "core/layout/ng/ng_constraint_space.h" |
8 #include "core/layout/ng/ng_constraint_space_builder.h" | 8 #include "core/layout/ng/ng_constraint_space_builder.h" |
9 #include "core/layout/ng/ng_fragment_builder.h" | 9 #include "core/layout/ng/ng_fragment_builder.h" |
10 #include "core/layout/ng/ng_fragment.h" | 10 #include "core/layout/ng/ng_fragment.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 const NGMarginStrut& prev_margin_strut, | 21 const NGMarginStrut& prev_margin_strut, |
22 const NGMarginStrut& curr_margin_strut) { | 22 const NGMarginStrut& curr_margin_strut) { |
23 return std::max(prev_margin_strut.margin_block_end, | 23 return std::max(prev_margin_strut.margin_block_end, |
24 curr_margin_strut.margin_block_start) - | 24 curr_margin_strut.margin_block_start) - |
25 std::max(prev_margin_strut.negative_margin_block_end.abs(), | 25 std::max(prev_margin_strut.negative_margin_block_end.abs(), |
26 curr_margin_strut.negative_margin_block_start.abs()); | 26 curr_margin_strut.negative_margin_block_start.abs()); |
27 } | 27 } |
28 | 28 |
29 // Creates an exclusion from the fragment that will be placed in the provided | 29 // Creates an exclusion from the fragment that will be placed in the provided |
30 // layout opportunity. | 30 // layout opportunity. |
31 NGExclusion* CreateExclusion(const NGFragment& fragment, | 31 NGLogicalRect CreateExclusion(const NGFragment& fragment, |
32 const NGLayoutOpportunity& opportunity, | 32 const NGLayoutOpportunity& opportunity, |
33 LayoutUnit float_offset, | 33 LayoutUnit float_offset, |
34 NGBoxStrut margins) { | 34 NGBoxStrut margins) { |
35 LayoutUnit exclusion_top = opportunity.offset.block_offset; | 35 NGLogicalRect exclusion; |
| 36 exclusion.offset = opportunity.offset; |
| 37 exclusion.offset.inline_offset += float_offset; |
36 | 38 |
37 LayoutUnit exclusion_left = opportunity.offset.inline_offset; | 39 exclusion.size.inline_size = fragment.InlineSize(); |
38 exclusion_left += float_offset; | 40 exclusion.size.block_size = fragment.BlockSize(); |
39 | |
40 LayoutUnit exclusion_bottom = exclusion_top + fragment.BlockSize(); | |
41 LayoutUnit exclusion_right = exclusion_left + fragment.InlineSize(); | |
42 | 41 |
43 // Adjust to child's margin. | 42 // Adjust to child's margin. |
44 exclusion_bottom += margins.BlockSum(); | 43 exclusion.size.block_size += margins.BlockSum(); |
45 exclusion_right += margins.InlineSum(); | 44 exclusion.size.inline_size += margins.InlineSum(); |
46 | 45 |
47 return new NGExclusion(exclusion_top, exclusion_right, exclusion_bottom, | 46 return exclusion; |
48 exclusion_left); | |
49 } | 47 } |
50 | 48 |
51 // Finds a layout opportunity for the fragment. | 49 // Finds a layout opportunity for the fragment. |
52 // It iterates over all layout opportunities in the constraint space and returns | 50 // It iterates over all layout opportunities in the constraint space and returns |
53 // the first layout opportunity that is wider than the fragment or returns the | 51 // the first layout opportunity that is wider than the fragment or returns the |
54 // last one which is always the widest. | 52 // last one which is always the widest. |
55 // | 53 // |
56 // @param space Constraint space that is used to find layout opportunity for | 54 // @param space Constraint space that is used to find layout opportunity for |
57 // the fragment. | 55 // the fragment. |
58 // @param fragment Fragment that needs to be placed. | 56 // @param fragment Fragment that needs to be placed. |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 FindLayoutOpportunityForFragment(constraint_space_, fragment, margins); | 352 FindLayoutOpportunityForFragment(constraint_space_, fragment, margins); |
355 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; | 353 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; |
356 | 354 |
357 // Calculate the float offset if needed. | 355 // Calculate the float offset if needed. |
358 LayoutUnit float_offset; | 356 LayoutUnit float_offset; |
359 if (current_child_->Style()->floating() == EFloat::Right) { | 357 if (current_child_->Style()->floating() == EFloat::Right) { |
360 float_offset = opportunity.size.inline_size - fragment.InlineSize(); | 358 float_offset = opportunity.size.inline_size - fragment.InlineSize(); |
361 } | 359 } |
362 | 360 |
363 // Add the float as an exclusion. | 361 // Add the float as an exclusion. |
364 const NGExclusion* exclusion = | 362 const NGLogicalRect exclusion = |
365 CreateExclusion(fragment, opportunity, float_offset, margins); | 363 CreateExclusion(fragment, opportunity, float_offset, margins); |
366 constraint_space_->AddExclusion(exclusion); | 364 constraint_space_->AddExclusion(exclusion); |
367 | 365 |
368 return CalculateLogicalOffsetForOpportunity(opportunity, border_and_padding_, | 366 return CalculateLogicalOffsetForOpportunity(opportunity, border_and_padding_, |
369 float_offset, margins); | 367 float_offset, margins); |
370 } | 368 } |
371 | 369 |
372 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { | 370 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { |
373 if (!is_fragment_margin_strut_block_start_updated_) { | 371 if (!is_fragment_margin_strut_block_start_updated_) { |
374 builder_->SetMarginStrutBlockStart(from); | 372 builder_->SetMarginStrutBlockStart(from); |
375 is_fragment_margin_strut_block_start_updated_ = true; | 373 is_fragment_margin_strut_block_start_updated_ = true; |
376 } | 374 } |
377 builder_->SetMarginStrutBlockEnd(from); | 375 builder_->SetMarginStrutBlockEnd(from); |
378 } | 376 } |
379 | 377 |
380 DEFINE_TRACE(NGBlockLayoutAlgorithm) { | 378 DEFINE_TRACE(NGBlockLayoutAlgorithm) { |
381 NGLayoutAlgorithm::trace(visitor); | 379 NGLayoutAlgorithm::trace(visitor); |
382 visitor->trace(first_child_); | 380 visitor->trace(first_child_); |
383 visitor->trace(constraint_space_); | 381 visitor->trace(constraint_space_); |
384 visitor->trace(builder_); | 382 visitor->trace(builder_); |
385 visitor->trace(space_builder_); | 383 visitor->trace(space_builder_); |
386 visitor->trace(space_for_current_child_); | 384 visitor->trace(space_for_current_child_); |
387 visitor->trace(current_child_); | 385 visitor->trace(current_child_); |
388 } | 386 } |
389 | 387 |
390 } // namespace blink | 388 } // namespace blink |
OLD | NEW |