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_fragment_builder.h" | 8 #include "core/layout/ng/ng_fragment_builder.h" |
9 #include "core/layout/ng/ng_fragment.h" | 9 #include "core/layout/ng/ng_fragment.h" |
10 #include "core/layout/ng/ng_length_utils.h" | 10 #include "core/layout/ng/ng_length_utils.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space, | 36 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space, |
37 NGPhysicalFragment** out) { | 37 NGPhysicalFragment** out) { |
38 switch (state_) { | 38 switch (state_) { |
39 case kStateInit: { | 39 case kStateInit: { |
40 border_and_padding_ = | 40 border_and_padding_ = |
41 computeBorders(*style_) + computePadding(*constraint_space, *style_); | 41 computeBorders(*style_) + computePadding(*constraint_space, *style_); |
42 | 42 |
43 LayoutUnit inline_size = | 43 LayoutUnit inline_size = |
44 computeInlineSizeForFragment(*constraint_space, *style_); | 44 computeInlineSizeForFragment(*constraint_space, *style_); |
| 45 LayoutUnit adjusted_inline_size = |
| 46 inline_size - border_and_padding_.InlineSum(); |
45 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of | 47 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of |
46 // -1? | 48 // -1? |
47 LayoutUnit block_size = computeBlockSizeForFragment( | 49 LayoutUnit block_size = computeBlockSizeForFragment( |
48 *constraint_space, *style_, LayoutUnit(-1)); | 50 *constraint_space, *style_, NGSizeIndefinite); |
| 51 LayoutUnit adjusted_block_size(block_size); |
| 52 // Our calculated block-axis size may be indefinite at this point. |
| 53 // If so, just leave the size as NGSizeIndefinite instead of subtracting |
| 54 // borders and padding. |
| 55 if (adjusted_block_size != NGSizeIndefinite) |
| 56 adjusted_block_size -= border_and_padding_.BlockSum(); |
49 constraint_space_for_children_ = new NGConstraintSpace( | 57 constraint_space_for_children_ = new NGConstraintSpace( |
50 *constraint_space, NGLogicalOffset(), | 58 FromPlatformWritingMode(style_->getWritingMode()), |
51 NGLogicalSize(inline_size - border_and_padding_.InlineSum(), | 59 FromPlatformDirection(style_->direction()), *constraint_space, |
52 block_size - border_and_padding_.BlockSum())); | 60 NGLogicalSize(adjusted_inline_size, adjusted_block_size)); |
53 content_size_ = border_and_padding_.block_start; | 61 content_size_ = border_and_padding_.block_start; |
54 | 62 |
55 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); | 63 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); |
56 builder_->SetDirection(constraint_space->Direction()); | 64 builder_->SetDirection(constraint_space->Direction()); |
57 builder_->SetWritingMode(constraint_space->WritingMode()); | 65 builder_->SetWritingMode(constraint_space->WritingMode()); |
58 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); | 66 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); |
59 current_child_ = first_child_; | 67 current_child_ = first_child_; |
60 state_ = kStateChildLayout; | 68 state_ = kStateChildLayout; |
61 return false; | 69 return false; |
62 } | 70 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 margin_block_start = ComputeCollapsedMarginBlockStart( | 164 margin_block_start = ComputeCollapsedMarginBlockStart( |
157 prev_child_margin_strut_, curr_margin_strut); | 165 prev_child_margin_strut_, curr_margin_strut); |
158 | 166 |
159 prev_child_margin_strut_ = curr_margin_strut; | 167 prev_child_margin_strut_ = curr_margin_strut; |
160 // TODO(layout-ng): support other Margin Collapsing use cases, | 168 // TODO(layout-ng): support other Margin Collapsing use cases, |
161 // i.e. support 0 height elements etc. | 169 // i.e. support 0 height elements etc. |
162 return margin_block_start; | 170 return margin_block_start; |
163 } | 171 } |
164 | 172 |
165 } // namespace blink | 173 } // namespace blink |
OLD | NEW |