| 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 19 matching lines...) Expand all Loading... |
| 30 PassRefPtr<const ComputedStyle> style, | 30 PassRefPtr<const ComputedStyle> style, |
| 31 NGBox* first_child) | 31 NGBox* first_child) |
| 32 : style_(style), first_child_(first_child), state_(kStateInit) { | 32 : style_(style), first_child_(first_child), state_(kStateInit) { |
| 33 DCHECK(style_); | 33 DCHECK(style_); |
| 34 } | 34 } |
| 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_ = |
| 41 computeBorders(*style_) + computePadding(*constraint_space, *style_); |
| 42 |
| 40 LayoutUnit inline_size = | 43 LayoutUnit inline_size = |
| 41 computeInlineSizeForFragment(*constraint_space, *style_); | 44 computeInlineSizeForFragment(*constraint_space, *style_); |
| 42 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of | 45 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of |
| 43 // -1? | 46 // -1? |
| 44 LayoutUnit block_size = computeBlockSizeForFragment( | 47 LayoutUnit block_size = computeBlockSizeForFragment( |
| 45 *constraint_space, *style_, LayoutUnit(-1)); | 48 *constraint_space, *style_, LayoutUnit(-1)); |
| 46 constraint_space_for_children_ = | 49 constraint_space_for_children_ = new NGConstraintSpace( |
| 47 new NGConstraintSpace(*constraint_space, NGLogicalOffset(), | 50 *constraint_space, NGLogicalOffset(), |
| 48 NGLogicalSize(inline_size, block_size)); | 51 NGLogicalSize(inline_size - border_and_padding_.InlineSum(), |
| 49 content_size_ = | 52 block_size - border_and_padding_.BlockSum())); |
| 50 computeBorderAndPaddingBlockStart(*constraint_space, *style_); | 53 content_size_ = border_and_padding_.block_start; |
| 51 | 54 |
| 52 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); | 55 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); |
| 53 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); | 56 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); |
| 54 current_child_ = first_child_; | 57 current_child_ = first_child_; |
| 55 state_ = kStateChildLayout; | 58 state_ = kStateChildLayout; |
| 56 return false; | 59 return false; |
| 57 } | 60 } |
| 58 case kStateChildLayout: { | 61 case kStateChildLayout: { |
| 59 if (current_child_) { | 62 if (current_child_) { |
| 60 NGFragment* fragment; | 63 NGFragment* fragment; |
| 61 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) | 64 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) |
| 62 return false; | 65 return false; |
| 63 NGBoxStrut child_margins = computeMargins( | 66 NGBoxStrut child_margins = computeMargins( |
| 64 *constraint_space_for_children_, *current_child_->Style()); | 67 *constraint_space_for_children_, *current_child_->Style()); |
| 65 | 68 |
| 66 LayoutUnit margin_block_start = | 69 LayoutUnit margin_block_start = |
| 67 CollapseMargins(child_margins, fragment->MarginStrut()); | 70 CollapseMargins(child_margins, fragment->MarginStrut()); |
| 68 | 71 |
| 69 // TODO(layout-ng): This is probably something we shouldn't calculate | |
| 70 // over and over again for each child. | |
| 71 LayoutUnit content_inline_start_edge = | |
| 72 computeBorderAndPaddingInlineStart(*constraint_space, *style_); | |
| 73 | |
| 74 // TODO(layout-ng): Support auto margins | 72 // TODO(layout-ng): Support auto margins |
| 75 builder_->AddChild(fragment, | 73 builder_->AddChild(fragment, |
| 76 NGLogicalOffset(content_inline_start_edge + | 74 NGLogicalOffset(border_and_padding_.inline_start + |
| 77 child_margins.inline_start, | 75 child_margins.inline_start, |
| 78 content_size_ + margin_block_start)); | 76 content_size_ + margin_block_start)); |
| 79 | 77 |
| 80 content_size_ += fragment->BlockSize() + margin_block_start; | 78 content_size_ += fragment->BlockSize() + margin_block_start; |
| 81 max_inline_size_ = | 79 max_inline_size_ = |
| 82 std::max(max_inline_size_, | 80 std::max(max_inline_size_, fragment->InlineSize() + |
| 83 fragment->InlineSize() + child_margins.InlineSum()); | 81 child_margins.InlineSum() + |
| 82 border_and_padding_.InlineSum()); |
| 84 current_child_ = current_child_->NextSibling(); | 83 current_child_ = current_child_->NextSibling(); |
| 85 if (current_child_) | 84 if (current_child_) |
| 86 return false; | 85 return false; |
| 87 } | 86 } |
| 88 state_ = kStateFinalize; | 87 state_ = kStateFinalize; |
| 89 return false; | 88 return false; |
| 90 } | 89 } |
| 91 case kStateFinalize: { | 90 case kStateFinalize: { |
| 91 content_size_ += border_and_padding_.block_end; |
| 92 // Recompute the block-axis size now that we know our content size. | 92 // Recompute the block-axis size now that we know our content size. |
| 93 LayoutUnit block_size = computeBlockSizeForFragment( | 93 LayoutUnit block_size = computeBlockSizeForFragment( |
| 94 *constraint_space, *style_, content_size_); | 94 *constraint_space, *style_, content_size_); |
| 95 | 95 |
| 96 builder_->SetBlockSize(block_size) | 96 builder_->SetBlockSize(block_size) |
| 97 .SetInlineOverflow(max_inline_size_) | 97 .SetInlineOverflow(max_inline_size_) |
| 98 .SetBlockOverflow(content_size_); | 98 .SetBlockOverflow(content_size_); |
| 99 *out = builder_->ToFragment(); | 99 *out = builder_->ToFragment(); |
| 100 state_ = kStateInit; | 100 state_ = kStateInit; |
| 101 return true; | 101 return true; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 127 margin_block_start = ComputeCollapsedMarginBlockStart( | 127 margin_block_start = ComputeCollapsedMarginBlockStart( |
| 128 prev_child_margin_strut_, curr_margin_strut); | 128 prev_child_margin_strut_, curr_margin_strut); |
| 129 | 129 |
| 130 prev_child_margin_strut_ = curr_margin_strut; | 130 prev_child_margin_strut_ = curr_margin_strut; |
| 131 // TODO(layout-ng): support other Margin Collapsing use cases, | 131 // TODO(layout-ng): support other Margin Collapsing use cases, |
| 132 // i.e. support 0 height elements etc. | 132 // i.e. support 0 height elements etc. |
| 133 return margin_block_start; | 133 return margin_block_start; |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace blink | 136 } // namespace blink |
| OLD | NEW |