| 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_node.h" | 5 #include "core/layout/ng/ng_block_node.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutBlockFlow.h" | 7 #include "core/layout/LayoutBlockFlow.h" |
| 8 #include "core/layout/api/LineLayoutAPIShim.h" | 8 #include "core/layout/api/LineLayoutAPIShim.h" |
| 9 #include "core/layout/line/InlineIterator.h" | 9 #include "core/layout/line/InlineIterator.h" |
| 10 #include "core/layout/ng/layout_ng_block_flow.h" | 10 #include "core/layout/ng/layout_ng_block_flow.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 fragment_ = toNGPhysicalBoxFragment(algorithm->Layout()); | 88 fragment_ = toNGPhysicalBoxFragment(algorithm->Layout()); |
| 89 CopyFragmentDataToLayoutBox(*constraint_space); | 89 CopyFragmentDataToLayoutBox(*constraint_space); |
| 90 } else { | 90 } else { |
| 91 DCHECK(layout_box_); | 91 DCHECK(layout_box_); |
| 92 fragment_ = RunOldLayout(*constraint_space); | 92 fragment_ = RunOldLayout(*constraint_space); |
| 93 } | 93 } |
| 94 | 94 |
| 95 return fragment_; | 95 return fragment_; |
| 96 } | 96 } |
| 97 | 97 |
| 98 MinAndMaxContentSizes NGBlockNode::ComputeMinAndMaxContentSizesSync() { | 98 MinAndMaxContentSizes NGBlockNode::ComputeMinAndMaxContentSizes() { |
| 99 MinAndMaxContentSizes sizes; | 99 MinAndMaxContentSizes sizes; |
| 100 while (!ComputeMinAndMaxContentSizes(&sizes)) | |
| 101 continue; | |
| 102 return sizes; | |
| 103 } | |
| 104 | |
| 105 bool NGBlockNode::ComputeMinAndMaxContentSizes(MinAndMaxContentSizes* sizes) { | |
| 106 if (!CanUseNewLayout()) { | 100 if (!CanUseNewLayout()) { |
| 107 DCHECK(layout_box_); | 101 DCHECK(layout_box_); |
| 108 // TODO(layout-ng): This could be somewhat optimized by directly calling | 102 // TODO(layout-ng): This could be somewhat optimized by directly calling |
| 109 // computeIntrinsicLogicalWidths, but that function is currently private. | 103 // computeIntrinsicLogicalWidths, but that function is currently private. |
| 110 // Consider doing that if this becomes a performance issue. | 104 // Consider doing that if this becomes a performance issue. |
| 111 LayoutUnit borderAndPadding = layout_box_->borderAndPaddingLogicalWidth(); | 105 LayoutUnit borderAndPadding = layout_box_->borderAndPaddingLogicalWidth(); |
| 112 sizes->min_content = layout_box_->computeLogicalWidthUsing( | 106 sizes.min_content = layout_box_->computeLogicalWidthUsing( |
| 113 MainOrPreferredSize, Length(MinContent), | 107 MainOrPreferredSize, Length(MinContent), |
| 114 LayoutUnit(), layout_box_->containingBlock()) - | 108 LayoutUnit(), layout_box_->containingBlock()) - |
| 115 borderAndPadding; | 109 borderAndPadding; |
| 116 sizes->max_content = layout_box_->computeLogicalWidthUsing( | 110 sizes.max_content = layout_box_->computeLogicalWidthUsing( |
| 117 MainOrPreferredSize, Length(MaxContent), | 111 MainOrPreferredSize, Length(MaxContent), |
| 118 LayoutUnit(), layout_box_->containingBlock()) - | 112 LayoutUnit(), layout_box_->containingBlock()) - |
| 119 borderAndPadding; | 113 borderAndPadding; |
| 120 return true; | 114 return sizes; |
| 121 } | 115 } |
| 122 | 116 |
| 123 NGConstraintSpace* constraint_space = | 117 NGConstraintSpace* constraint_space = |
| 124 NGConstraintSpaceBuilder( | 118 NGConstraintSpaceBuilder( |
| 125 FromPlatformWritingMode(Style()->getWritingMode())) | 119 FromPlatformWritingMode(Style()->getWritingMode())) |
| 126 .SetTextDirection(Style()->direction()) | 120 .SetTextDirection(Style()->direction()) |
| 127 .ToConstraintSpace(); | 121 .ToConstraintSpace(); |
| 128 | 122 |
| 129 // TODO(cbiesinger): For orthogonal children, we need to always synthesize. | 123 // TODO(cbiesinger): For orthogonal children, we need to always synthesize. |
| 130 NGBlockLayoutAlgorithm minmax_algorithm( | 124 NGBlockLayoutAlgorithm minmax_algorithm( |
| 131 layout_box_, Style(), toNGBlockNode(FirstChild()), constraint_space); | 125 layout_box_, Style(), toNGBlockNode(FirstChild()), constraint_space); |
| 132 if (minmax_algorithm.ComputeMinAndMaxContentSizes(sizes)) | 126 if (minmax_algorithm.ComputeMinAndMaxContentSizes(&sizes)) |
| 133 return true; | 127 return sizes; |
| 134 | 128 |
| 135 // Have to synthesize this value. | 129 // Have to synthesize this value. |
| 136 NGPhysicalFragment* physical_fragment = Layout(constraint_space); | 130 NGPhysicalFragment* physical_fragment = Layout(constraint_space); |
| 137 NGBoxFragment* fragment = new NGBoxFragment( | 131 NGBoxFragment* fragment = new NGBoxFragment( |
| 138 FromPlatformWritingMode(Style()->getWritingMode()), Style()->direction(), | 132 FromPlatformWritingMode(Style()->getWritingMode()), Style()->direction(), |
| 139 toNGPhysicalBoxFragment(physical_fragment)); | 133 toNGPhysicalBoxFragment(physical_fragment)); |
| 140 | 134 |
| 141 sizes->min_content = fragment->InlineOverflow(); | 135 sizes.min_content = fragment->InlineOverflow(); |
| 142 | 136 |
| 143 // Now, redo with infinite space for max_content | 137 // Now, redo with infinite space for max_content |
| 144 constraint_space = | 138 constraint_space = |
| 145 NGConstraintSpaceBuilder( | 139 NGConstraintSpaceBuilder( |
| 146 FromPlatformWritingMode(Style()->getWritingMode())) | 140 FromPlatformWritingMode(Style()->getWritingMode())) |
| 147 .SetTextDirection(Style()->direction()) | 141 .SetTextDirection(Style()->direction()) |
| 148 .SetAvailableSize({LayoutUnit::max(), LayoutUnit()}) | 142 .SetAvailableSize({LayoutUnit::max(), LayoutUnit()}) |
| 149 .SetPercentageResolutionSize({LayoutUnit(), LayoutUnit()}) | 143 .SetPercentageResolutionSize({LayoutUnit(), LayoutUnit()}) |
| 150 .ToConstraintSpace(); | 144 .ToConstraintSpace(); |
| 151 | 145 |
| 152 physical_fragment = Layout(constraint_space); | 146 physical_fragment = Layout(constraint_space); |
| 153 fragment = new NGBoxFragment( | 147 fragment = new NGBoxFragment( |
| 154 FromPlatformWritingMode(Style()->getWritingMode()), Style()->direction(), | 148 FromPlatformWritingMode(Style()->getWritingMode()), Style()->direction(), |
| 155 toNGPhysicalBoxFragment(physical_fragment)); | 149 toNGPhysicalBoxFragment(physical_fragment)); |
| 156 sizes->max_content = fragment->InlineOverflow(); | 150 sizes.max_content = fragment->InlineOverflow(); |
| 157 return true; | 151 return sizes; |
| 158 } | 152 } |
| 159 | 153 |
| 160 ComputedStyle* NGBlockNode::MutableStyle() { | 154 ComputedStyle* NGBlockNode::MutableStyle() { |
| 161 if (style_) | 155 if (style_) |
| 162 return style_.get(); | 156 return style_.get(); |
| 163 DCHECK(layout_box_); | 157 DCHECK(layout_box_); |
| 164 return layout_box_->mutableStyle(); | 158 return layout_box_->mutableStyle(); |
| 165 } | 159 } |
| 166 | 160 |
| 167 const ComputedStyle* NGBlockNode::Style() const { | 161 const ComputedStyle* NGBlockNode::Style() const { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // Save static position for legacy AbsPos layout. | 334 // Save static position for legacy AbsPos layout. |
| 341 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) { | 335 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) { |
| 342 DCHECK(layout_box_); | 336 DCHECK(layout_box_); |
| 343 DCHECK(layout_box_->isOutOfFlowPositioned()); | 337 DCHECK(layout_box_->isOutOfFlowPositioned()); |
| 344 DCHECK(layout_box_->layer()); | 338 DCHECK(layout_box_->layer()); |
| 345 layout_box_->layer()->setStaticBlockPosition(offset.block_offset); | 339 layout_box_->layer()->setStaticBlockPosition(offset.block_offset); |
| 346 layout_box_->layer()->setStaticInlinePosition(offset.inline_offset); | 340 layout_box_->layer()->setStaticInlinePosition(offset.inline_offset); |
| 347 } | 341 } |
| 348 | 342 |
| 349 } // namespace blink | 343 } // namespace blink |
| OLD | NEW |