Chromium Code Reviews| 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" |
| 11 #include "core/layout/ng/ng_units.h" | 11 #include "core/layout/ng/ng_units.h" |
| 12 #include "core/style/ComputedStyle.h" | 12 #include "core/style/ComputedStyle.h" |
| 13 #include "platform/LengthFunctions.h" | 13 #include "platform/LengthFunctions.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 LayoutUnit ComputeCollapsedMarginBlockStart( | 18 LayoutUnit ComputeCollapsedMarginBlockStart( |
| 19 const NGMarginStrut& prev_margin_strut, | 19 const NGMarginStrut& prev_margin_strut, |
| 20 const NGMarginStrut& curr_margin_strut) { | 20 const NGMarginStrut& curr_margin_strut) { |
| 21 return std::max(prev_margin_strut.margin_block_end, | 21 return std::max(prev_margin_strut.margin_block_end, |
| 22 curr_margin_strut.margin_block_start) - | 22 curr_margin_strut.margin_block_start) - |
| 23 std::max(prev_margin_strut.negative_margin_block_end.abs(), | 23 std::max(prev_margin_strut.negative_margin_block_end.abs(), |
| 24 curr_margin_strut.negative_margin_block_start.abs()); | 24 curr_margin_strut.negative_margin_block_start.abs()); |
| 25 } | 25 } |
| 26 | 26 |
| 27 // Returns true if a in-flow block-level child creates a new formatting context. | |
|
Gleb Lanbin
2016/10/18 22:54:10
.nit if a function returns boolean then google3 co
ikilpatrick
2016/10/18 22:59:28
Done, thanks!
| |
| 28 // | |
| 29 // This will *NOT* check the following cases: | |
| 30 // - The child is out-of-flow, e.g. floating or abs-pos. | |
| 31 // - The child is a inline-level, e.g. "display: inline-block". | |
| 32 // - The child establishes a new formatting context, but should be a child of | |
| 33 // another layout algorithm, e.g. "display: table-caption" or flex-item. | |
| 34 bool IsNewFormattingContextForInFlowBlockLevelChild( | |
| 35 const NGConstraintSpace& space, | |
| 36 const ComputedStyle& style) { | |
| 37 // TODO(layout-dev): This doesn't capture a few cases which can't be computed | |
| 38 // directly from style yet: | |
| 39 // - The child is a <fieldset>. | |
| 40 // - "column-span: all" is set on the child (requires knowledge that we are | |
| 41 // in a multi-col formatting context). | |
| 42 // (https://drafts.csswg.org/css-multicol-1/#valdef-column-span-all) | |
| 43 | |
| 44 if (style.specifiesColumns() || style.containsPaint() || | |
| 45 style.containsLayout()) | |
| 46 return true; | |
| 47 | |
| 48 if (!style.isOverflowVisible()) | |
| 49 return true; | |
| 50 | |
| 51 EDisplay display = style.display(); | |
| 52 if (display == EDisplay::Grid || display == EDisplay::Flex || | |
| 53 display == EDisplay::Box) | |
| 54 return true; | |
| 55 | |
| 56 if (space.WritingMode() != FromPlatformWritingMode(style.getWritingMode())) | |
| 57 return true; | |
| 58 | |
| 59 return false; | |
| 60 } | |
| 61 | |
| 27 } // namespace | 62 } // namespace |
| 28 | 63 |
| 29 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( | 64 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( |
| 30 PassRefPtr<const ComputedStyle> style, | 65 PassRefPtr<const ComputedStyle> style, |
| 31 NGBox* first_child) | 66 NGBox* first_child) |
| 32 : style_(style), | 67 : style_(style), |
| 33 first_child_(first_child), | 68 first_child_(first_child), |
| 34 state_(kStateInit), | 69 state_(kStateInit), |
| 35 is_fragment_margin_strut_block_start_updated_(false) { | 70 is_fragment_margin_strut_block_start_updated_(false) { |
| 36 DCHECK(style_); | 71 DCHECK(style_); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 66 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); | 101 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox); |
| 67 builder_->SetDirection(constraint_space->Direction()); | 102 builder_->SetDirection(constraint_space->Direction()); |
| 68 builder_->SetWritingMode(constraint_space->WritingMode()); | 103 builder_->SetWritingMode(constraint_space->WritingMode()); |
| 69 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); | 104 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); |
| 70 current_child_ = first_child_; | 105 current_child_ = first_child_; |
| 71 state_ = kStateChildLayout; | 106 state_ = kStateChildLayout; |
| 72 return false; | 107 return false; |
| 73 } | 108 } |
| 74 case kStateChildLayout: { | 109 case kStateChildLayout: { |
| 75 if (current_child_) { | 110 if (current_child_) { |
| 111 constraint_space_for_children_->SetIsNewFormattingContext( | |
| 112 IsNewFormattingContextForInFlowBlockLevelChild( | |
| 113 *constraint_space, *current_child_->Style())); | |
| 114 | |
| 76 NGFragment* fragment; | 115 NGFragment* fragment; |
| 77 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) | 116 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) |
| 78 return false; | 117 return false; |
| 79 NGBoxStrut child_margins = computeMargins( | 118 NGBoxStrut child_margins = computeMargins( |
| 80 *constraint_space_for_children_, *current_child_->Style(), | 119 *constraint_space_for_children_, *current_child_->Style(), |
| 81 constraint_space_for_children_->WritingMode(), | 120 constraint_space_for_children_->WritingMode(), |
| 82 constraint_space_for_children_->Direction()); | 121 constraint_space_for_children_->Direction()); |
| 83 ApplyAutoMargins(*constraint_space_for_children_, | 122 ApplyAutoMargins(*constraint_space_for_children_, |
| 84 *current_child_->Style(), *fragment, child_margins); | 123 *current_child_->Style(), *fragment, child_margins); |
| 85 | 124 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 | 232 |
| 194 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { | 233 void NGBlockLayoutAlgorithm::UpdateMarginStrut(const NGMarginStrut& from) { |
| 195 if (!is_fragment_margin_strut_block_start_updated_) { | 234 if (!is_fragment_margin_strut_block_start_updated_) { |
| 196 builder_->SetMarginStrutBlockStart(from); | 235 builder_->SetMarginStrutBlockStart(from); |
| 197 is_fragment_margin_strut_block_start_updated_ = true; | 236 is_fragment_margin_strut_block_start_updated_ = true; |
| 198 } | 237 } |
| 199 builder_->SetMarginStrutBlockEnd(from); | 238 builder_->SetMarginStrutBlockEnd(from); |
| 200 } | 239 } |
| 201 | 240 |
| 202 } // namespace blink | 241 } // namespace blink |
| OLD | NEW |