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 18 matching lines...) Expand all Loading... | |
29 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( | 29 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( |
30 PassRefPtr<const ComputedStyle> style, | 30 PassRefPtr<const ComputedStyle> style, |
31 NGBox* first_child) | 31 NGBox* first_child) |
32 : style_(style), | 32 : style_(style), |
33 first_child_(first_child), | 33 first_child_(first_child), |
34 state_(kStateInit), | 34 state_(kStateInit), |
35 is_fragment_margin_strut_block_start_updated_(false) { | 35 is_fragment_margin_strut_block_start_updated_(false) { |
36 DCHECK(style_); | 36 DCHECK(style_); |
37 } | 37 } |
38 | 38 |
39 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space, | 39 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace& constraint_space, |
40 NGPhysicalFragment** out) { | 40 NGPhysicalFragment** out) { |
41 switch (state_) { | 41 switch (state_) { |
42 case kStateInit: { | 42 case kStateInit: { |
43 border_and_padding_ = | 43 border_and_padding_ = |
44 computeBorders(*style_) + computePadding(*constraint_space, *style_); | 44 computeBorders(*style_) + computePadding(constraint_space, *style_); |
45 | 45 |
46 LayoutUnit inline_size = | 46 LayoutUnit inline_size = |
47 computeInlineSizeForFragment(*constraint_space, *style_); | 47 computeInlineSizeForFragment(constraint_space, *style_); |
48 LayoutUnit adjusted_inline_size = | 48 LayoutUnit adjusted_inline_size = |
49 inline_size - border_and_padding_.InlineSum(); | 49 inline_size - border_and_padding_.InlineSum(); |
50 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of | 50 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of |
51 // -1? | 51 // -1? |
52 LayoutUnit block_size = computeBlockSizeForFragment( | 52 LayoutUnit block_size = computeBlockSizeForFragment( |
53 *constraint_space, *style_, NGSizeIndefinite); | 53 constraint_space, *style_, NGSizeIndefinite); |
54 LayoutUnit adjusted_block_size(block_size); | 54 LayoutUnit adjusted_block_size(block_size); |
55 // Our calculated block-axis size may be indefinite at this point. | 55 // Our calculated block-axis size may be indefinite at this point. |
56 // If so, just leave the size as NGSizeIndefinite instead of subtracting | 56 // If so, just leave the size as NGSizeIndefinite instead of subtracting |
57 // borders and padding. | 57 // borders and padding. |
58 if (adjusted_block_size != NGSizeIndefinite) | 58 if (adjusted_block_size != NGSizeIndefinite) |
59 adjusted_block_size -= border_and_padding_.BlockSum(); | 59 adjusted_block_size -= border_and_padding_.BlockSum(); |
60 constraint_space_for_children_ = new NGConstraintSpace( | 60 constraint_space_for_children_ = new NGConstraintSpace( |
61 FromPlatformWritingMode(style_->getWritingMode()), | 61 FromPlatformWritingMode(style_->getWritingMode()), |
62 FromPlatformDirection(style_->direction()), *constraint_space, | 62 FromPlatformDirection(style_->direction()), constraint_space, |
63 NGLogicalSize(adjusted_inline_size, adjusted_block_size)); | 63 NGLogicalSize(adjusted_inline_size, adjusted_block_size)); |
64 content_size_ = border_and_padding_.block_start; | 64 content_size_ = border_and_padding_.block_start; |
65 | 65 |
66 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); | 66 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); |
67 builder_->SetDirection(constraint_space->Direction()); | 67 builder_->SetDirection(constraint_space.Direction()); |
68 builder_->SetWritingMode(constraint_space->WritingMode()); | 68 builder_->SetWritingMode(constraint_space.WritingMode()); |
69 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); | 69 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); |
70 current_child_ = first_child_; | 70 current_child_ = first_child_; |
71 state_ = kStateChildLayout; | 71 state_ = kStateChildLayout; |
72 return false; | 72 return false; |
73 } | 73 } |
74 case kStateChildLayout: { | 74 case kStateChildLayout: { |
75 if (current_child_) { | 75 if (current_child_) { |
76 NGFragment* fragment; | 76 if (!current_child_->Layout(constraint_space_for_children_.get())) |
cbiesinger
2016/09/26 17:17:55
Why did you remove the out param?
| |
77 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) | |
78 return false; | 77 return false; |
78 NGFragment* fragment = current_child_->Fragment(); | |
79 NGBoxStrut child_margins = computeMargins( | 79 NGBoxStrut child_margins = computeMargins( |
80 *constraint_space_for_children_, *current_child_->Style(), | 80 *constraint_space_for_children_, *current_child_->Style(), |
81 constraint_space_for_children_->WritingMode(), | 81 constraint_space_for_children_->WritingMode(), |
82 constraint_space_for_children_->Direction()); | 82 constraint_space_for_children_->Direction()); |
83 | 83 |
84 LayoutUnit margin_block_start = | 84 LayoutUnit margin_block_start = |
85 CollapseMargins(*constraint_space, child_margins, *fragment); | 85 CollapseMargins(constraint_space, child_margins, *fragment); |
86 | 86 |
87 // TODO(layout-ng): Support auto margins | 87 // TODO(layout-ng): Support auto margins |
88 builder_->AddChild(fragment, | 88 builder_->AddChild(fragment, |
89 NGLogicalOffset(border_and_padding_.inline_start + | 89 NGLogicalOffset(border_and_padding_.inline_start + |
90 child_margins.inline_start, | 90 child_margins.inline_start, |
91 content_size_ + margin_block_start)); | 91 content_size_ + margin_block_start)); |
92 | 92 |
93 content_size_ += fragment->BlockSize() + margin_block_start; | 93 content_size_ += fragment->BlockSize() + margin_block_start; |
94 max_inline_size_ = | 94 max_inline_size_ = |
95 std::max(max_inline_size_, fragment->InlineSize() + | 95 std::max(max_inline_size_, fragment->InlineSize() + |
96 child_margins.InlineSum() + | 96 child_margins.InlineSum() + |
97 border_and_padding_.InlineSum()); | 97 border_and_padding_.InlineSum()); |
98 current_child_ = current_child_->NextSibling(); | 98 current_child_ = current_child_->NextSibling(); |
99 if (current_child_) | 99 if (current_child_) |
100 return false; | 100 return false; |
101 } | 101 } |
102 state_ = kStateFinalize; | 102 state_ = kStateFinalize; |
103 return false; | 103 return false; |
104 } | 104 } |
105 case kStateFinalize: { | 105 case kStateFinalize: { |
106 content_size_ += border_and_padding_.block_end; | 106 content_size_ += border_and_padding_.block_end; |
107 // Recompute the block-axis size now that we know our content size. | 107 // Recompute the block-axis size now that we know our content size. |
108 LayoutUnit block_size = computeBlockSizeForFragment( | 108 LayoutUnit block_size = |
109 *constraint_space, *style_, content_size_); | 109 computeBlockSizeForFragment(constraint_space, *style_, content_size_); |
110 | 110 |
111 builder_->SetBlockSize(block_size) | 111 builder_->SetBlockSize(block_size) |
112 .SetInlineOverflow(max_inline_size_) | 112 .SetInlineOverflow(max_inline_size_) |
113 .SetBlockOverflow(content_size_); | 113 .SetBlockOverflow(content_size_); |
114 *out = builder_->ToFragment(); | 114 *out = builder_->ToFragment(); |
115 state_ = kStateInit; | 115 state_ = kStateInit; |
116 return true; | 116 return true; |
117 } | 117 } |
118 }; | 118 }; |
119 NOTREACHED(); | 119 NOTREACHED(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 | 175 |
176 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { | 176 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { |
177 if (!is_fragment_margin_strut_block_start_updated_) { | 177 if (!is_fragment_margin_strut_block_start_updated_) { |
178 builder_->SetMarginStrutBlockStart(from); | 178 builder_->SetMarginStrutBlockStart(from); |
179 is_fragment_margin_strut_block_start_updated_ = true; | 179 is_fragment_margin_strut_block_start_updated_ = true; |
180 } | 180 } |
181 builder_->SetMarginStrutBlockEnd(from); | 181 builder_->SetMarginStrutBlockEnd(from); |
182 } | 182 } |
183 | 183 |
184 } // namespace blink | 184 } // namespace blink |
OLD | NEW |