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/LayoutBox.h" | 7 #include "core/layout/LayoutBox.h" |
8 #include "core/layout/ng/ng_constraint_space.h" | 8 #include "core/layout/ng/ng_constraint_space.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 20 matching lines...) Expand all Loading... | |
31 PassRefPtr<const ComputedStyle> style, | 31 PassRefPtr<const ComputedStyle> style, |
32 NGBox* first_child) | 32 NGBox* first_child) |
33 : style_(style), first_child_(first_child), state_(kStateInit) { | 33 : style_(style), first_child_(first_child), state_(kStateInit) { |
34 DCHECK(style_); | 34 DCHECK(style_); |
35 } | 35 } |
36 | 36 |
37 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space, | 37 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space, |
38 NGPhysicalFragment** out) { | 38 NGPhysicalFragment** out) { |
39 switch (state_) { | 39 switch (state_) { |
40 case kStateInit: { | 40 case kStateInit: { |
41 border_and_padding_ = | |
42 computeBorders(*style_) + computePadding(*constraint_space, *style_); | |
43 | |
41 LayoutUnit inline_size = | 44 LayoutUnit inline_size = |
42 computeInlineSizeForFragment(*constraint_space, *style_); | 45 computeInlineSizeForFragment(*constraint_space, *style_); |
43 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of | 46 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of |
44 // -1? | 47 // -1? |
45 LayoutUnit block_size = computeBlockSizeForFragment( | 48 LayoutUnit block_size = computeBlockSizeForFragment( |
46 *constraint_space, *style_, LayoutUnit(-1)); | 49 *constraint_space, *style_, LayoutUnit(-1)); |
47 constraint_space_for_children_ = | 50 constraint_space_for_children_ = new NGConstraintSpace( |
48 new NGConstraintSpace(*constraint_space, NGLogicalOffset(), | 51 *constraint_space, NGLogicalOffset(), |
49 NGLogicalSize(inline_size, block_size)); | 52 NGLogicalSize(inline_size - border_and_padding_.inline_start, |
mstensho (USE GERRIT)
2016/09/12 20:05:50
I may lack some understanding of how this thing wo
cbiesinger
2016/09/13 18:04:54
Great point! That should be changed, thanks.
| |
50 content_size_ = LayoutUnit(); | 53 block_size - border_and_padding_.block_start)); |
54 content_size_ = border_and_padding_.block_start; | |
51 | 55 |
52 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); | 56 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); |
53 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); | 57 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); |
54 current_child_ = first_child_; | 58 current_child_ = first_child_; |
55 state_ = kStateChildLayout; | 59 state_ = kStateChildLayout; |
56 return false; | 60 return false; |
57 } | 61 } |
58 case kStateChildLayout: { | 62 case kStateChildLayout: { |
59 if (current_child_) { | 63 if (current_child_) { |
60 NGFragment* fragment; | 64 NGFragment* fragment; |
61 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) | 65 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) |
62 return false; | 66 return false; |
63 NGBoxStrut child_margins = computeMargins( | 67 NGBoxStrut child_margins = computeMargins( |
64 *constraint_space_for_children_, *current_child_->Style()); | 68 *constraint_space_for_children_, *current_child_->Style()); |
65 | 69 |
66 LayoutUnit margin_block_start = | 70 LayoutUnit margin_block_start = |
67 CollapseMargins(child_margins, fragment->MarginStrut()); | 71 CollapseMargins(child_margins, fragment->MarginStrut()); |
68 | 72 |
69 // TODO(layout-ng): Support auto margins | 73 // TODO(layout-ng): Support auto margins |
70 builder_->AddChild(fragment, | 74 builder_->AddChild(fragment, |
71 NGLogicalOffset(child_margins.inline_start, | 75 NGLogicalOffset(border_and_padding_.inline_start + |
76 child_margins.inline_start, | |
72 content_size_ + margin_block_start)); | 77 content_size_ + margin_block_start)); |
73 | 78 |
74 content_size_ += fragment->BlockSize() + margin_block_start; | 79 content_size_ += fragment->BlockSize() + margin_block_start; |
75 max_inline_size_ = | 80 max_inline_size_ = |
76 std::max(max_inline_size_, | 81 std::max(max_inline_size_, fragment->InlineSize() + |
77 fragment->InlineSize() + child_margins.InlineSum()); | 82 child_margins.InlineSum() + |
83 border_and_padding_.InlineSum()); | |
78 current_child_ = current_child_->NextSibling(); | 84 current_child_ = current_child_->NextSibling(); |
79 if (current_child_) | 85 if (current_child_) |
80 return false; | 86 return false; |
81 } | 87 } |
82 state_ = kStateFinalize; | 88 state_ = kStateFinalize; |
83 return false; | 89 return false; |
84 } | 90 } |
85 case kStateFinalize: { | 91 case kStateFinalize: { |
92 content_size_ += border_and_padding_.block_end; | |
86 // Recompute the block-axis size now that we know our content size. | 93 // Recompute the block-axis size now that we know our content size. |
87 LayoutUnit block_size = computeBlockSizeForFragment( | 94 LayoutUnit block_size = computeBlockSizeForFragment( |
88 *constraint_space, *style_, content_size_); | 95 *constraint_space, *style_, content_size_); |
89 | 96 |
90 builder_->SetBlockSize(block_size) | 97 builder_->SetBlockSize(block_size) |
91 .SetInlineOverflow(max_inline_size_) | 98 .SetInlineOverflow(max_inline_size_) |
92 .SetBlockOverflow(content_size_); | 99 .SetBlockOverflow(content_size_); |
93 *out = builder_->ToFragment(); | 100 *out = builder_->ToFragment(); |
94 state_ = kStateInit; | 101 state_ = kStateInit; |
95 return true; | 102 return true; |
(...skipping 25 matching lines...) Expand all Loading... | |
121 margin_block_start = ComputeCollapsedMarginBlockStart( | 128 margin_block_start = ComputeCollapsedMarginBlockStart( |
122 prev_child_margin_strut_, curr_margin_strut); | 129 prev_child_margin_strut_, curr_margin_strut); |
123 | 130 |
124 prev_child_margin_strut_ = curr_margin_strut; | 131 prev_child_margin_strut_ = curr_margin_strut; |
125 // TODO(layout-ng): support other Margin Collapsing use cases, | 132 // TODO(layout-ng): support other Margin Collapsing use cases, |
126 // i.e. support 0 height elements etc. | 133 // i.e. support 0 height elements etc. |
127 return margin_block_start; | 134 return margin_block_start; |
128 } | 135 } |
129 | 136 |
130 } // namespace blink | 137 } // namespace blink |
OLD | NEW |