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_out_of_flow_layout_part.h" | 5 #include "core/layout/ng/ng_out_of_flow_layout_part.h" |
| 6 | 6 |
| 7 #include "core/layout/ng/ng_absolute_utils.h" | 7 #include "core/layout/ng/ng_absolute_utils.h" |
| 8 #include "core/layout/ng/ng_block_node.h" | 8 #include "core/layout/ng/ng_block_node.h" |
| 9 #include "core/layout/ng/ng_box_fragment.h" | 9 #include "core/layout/ng/ng_box_fragment.h" |
| 10 #include "core/layout/ng/ng_constraint_space_builder.h" | 10 #include "core/layout/ng/ng_constraint_space_builder.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 | 98 |
| 99 RefPtr<NGLayoutResult> NGOutOfFlowLayoutPart::LayoutDescendant( | 99 RefPtr<NGLayoutResult> NGOutOfFlowLayoutPart::LayoutDescendant( |
| 100 NGBlockNode& descendant, | 100 NGBlockNode& descendant, |
| 101 NGStaticPosition static_position, | 101 NGStaticPosition static_position, |
| 102 NGLogicalOffset* offset) { | 102 NGLogicalOffset* offset) { |
| 103 // Adjust the static_position origin. The static_position coordinate origin is | 103 // Adjust the static_position origin. The static_position coordinate origin is |
| 104 // relative to the container's border box, ng_absolute_utils expects it to be | 104 // relative to the container's border box, ng_absolute_utils expects it to be |
| 105 // relative to the container's padding box. | 105 // relative to the container's padding box. |
| 106 static_position.offset -= container_border_physical_offset_; | 106 static_position.offset -= container_border_physical_offset_; |
| 107 | 107 |
| 108 RefPtr<NGLayoutResult> layout_result = nullptr; | 108 // The inline and block estimates are in the descendant's writing mode. |
| 109 Optional<MinAndMaxContentSizes> inline_estimate; | 109 Optional<MinAndMaxContentSizes> inline_estimate; |
| 110 Optional<LayoutUnit> block_estimate; | 110 Optional<LayoutUnit> block_estimate; |
| 111 | 111 |
| 112 RefPtr<NGLayoutResult> layout_result = nullptr; | |
| 113 NGWritingMode descendant_writing_mode( | |
| 114 FromPlatformWritingMode(descendant.Style().getWritingMode())); | |
| 115 | |
| 112 if (AbsoluteNeedsChildInlineSize(descendant.Style())) { | 116 if (AbsoluteNeedsChildInlineSize(descendant.Style())) { |
| 113 inline_estimate = descendant.ComputeMinAndMaxContentSizes(); | 117 inline_estimate = descendant.ComputeMinAndMaxContentSizes(); |
| 114 } | 118 } |
| 115 | 119 |
| 116 NGAbsolutePhysicalPosition node_position = | 120 NGAbsolutePhysicalPosition node_position = |
| 117 ComputePartialAbsoluteWithChildInlineSize( | 121 ComputePartialAbsoluteWithChildInlineSize( |
| 118 *container_space_, descendant.Style(), static_position, | 122 *container_space_, descendant.Style(), static_position, |
| 119 inline_estimate); | 123 inline_estimate); |
| 120 | 124 |
| 121 if (AbsoluteNeedsChildBlockSize(descendant.Style())) { | 125 if (AbsoluteNeedsChildBlockSize(descendant.Style())) { |
| 122 layout_result = GenerateFragment(descendant, block_estimate, node_position); | 126 layout_result = GenerateFragment(descendant, block_estimate, node_position); |
| 123 | 127 |
| 124 // TODO(ikilpatrick): the writing mode switching here looks wrong. | |
| 125 NGBoxFragment fragment( | 128 NGBoxFragment fragment( |
| 126 container_space_->WritingMode(), | 129 descendant_writing_mode, |
| 127 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get())); | 130 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get())); |
| 128 | 131 |
| 129 block_estimate = fragment.BlockSize(); | 132 block_estimate = fragment.BlockSize(); |
| 130 } | 133 } |
| 131 | 134 |
| 132 ComputeFullAbsoluteWithChildBlockSize(*container_space_, descendant.Style(), | 135 ComputeFullAbsoluteWithChildBlockSize(*container_space_, descendant.Style(), |
| 133 static_position, block_estimate, | 136 static_position, block_estimate, |
| 134 &node_position); | 137 &node_position); |
| 135 | 138 |
| 136 // Skip this step if we produced a fragment when estimating the block size. | 139 // Skip this step if we produced a fragment when estimating the block size. |
| 137 if (!layout_result) { | 140 if (!layout_result) { |
| 138 block_estimate = | 141 block_estimate = |
| 139 node_position.size.ConvertToLogical(container_space_->WritingMode()) | 142 node_position.size.ConvertToLogical(descendant_writing_mode).block_size; |
| 140 .block_size; | |
| 141 layout_result = GenerateFragment(descendant, block_estimate, node_position); | 143 layout_result = GenerateFragment(descendant, block_estimate, node_position); |
| 142 } | 144 } |
| 143 | 145 |
| 144 // Compute logical offset, NGAbsolutePhysicalPosition is calculated relative | 146 // Compute logical offset, NGAbsolutePhysicalPosition is calculated relative |
| 145 // to the padding box so add back the container's borders. | 147 // to the padding box so add back the container's borders. |
| 146 NGBoxStrut inset = node_position.inset.ConvertToLogical( | 148 NGBoxStrut inset = node_position.inset.ConvertToLogical( |
| 147 container_space_->WritingMode(), container_space_->Direction()); | 149 container_space_->WritingMode(), container_space_->Direction()); |
| 148 offset->inline_offset = | 150 offset->inline_offset = |
| 149 inset.inline_start + container_border_offset_.inline_offset; | 151 inset.inline_start + container_border_offset_.inline_offset; |
| 150 offset->block_offset = | 152 offset->block_offset = |
| 151 inset.block_start + container_border_offset_.block_offset; | 153 inset.block_start + container_border_offset_.block_offset; |
| 152 | 154 |
| 153 return layout_result; | 155 return layout_result; |
| 154 } | 156 } |
| 155 | 157 |
| 158 // The fragment is generated in one of these two scenarios: | |
| 159 // 1. To estimate descendant's block size, in this case block_size is | |
| 160 // container's available size. | |
| 161 // 2. To compute final fragment, when block size is known from the absolute | |
| 162 // position calculation. | |
| 156 RefPtr<NGLayoutResult> NGOutOfFlowLayoutPart::GenerateFragment( | 163 RefPtr<NGLayoutResult> NGOutOfFlowLayoutPart::GenerateFragment( |
| 157 NGBlockNode& descendant, | 164 NGBlockNode& descendant, |
| 158 const Optional<LayoutUnit>& block_estimate, | 165 const Optional<LayoutUnit>& block_estimate, |
| 159 const NGAbsolutePhysicalPosition node_position) { | 166 const NGAbsolutePhysicalPosition node_position) { |
| 160 // The fragment is generated in one of these two scenarios: | 167 // As the block_estimate is always in the descendant's writing mode, we build |
| 161 // 1. To estimate descendant's block size, in this case block_size is | 168 // the constraint space in the descendant's writing mode. |
| 162 // container's available size. | 169 NGWritingMode writing_mode( |
| 163 // 2. To compute final fragment, when block size is known from the absolute | 170 FromPlatformWritingMode(descendant.Style().getWritingMode())); |
| 164 // position calculation. | 171 NGLogicalSize logical_available_size( |
| 172 container_space_->AvailableSize() | |
| 173 .ConvertToPhysical(container_space_->WritingMode()) | |
| 174 .ConvertToLogical(writing_mode)); | |
| 175 | |
| 165 LayoutUnit inline_size = | 176 LayoutUnit inline_size = |
| 166 node_position.size.ConvertToLogical(container_space_->WritingMode()) | 177 node_position.size.ConvertToLogical(writing_mode).inline_size; |
| 167 .inline_size; | 178 LayoutUnit block_size = |
| 168 LayoutUnit block_size = block_estimate | 179 block_estimate ? *block_estimate : logical_available_size.block_size; |
| 169 ? *block_estimate | |
| 170 : container_space_->AvailableSize().block_size; | |
| 171 | 180 |
| 172 NGLogicalSize available_size{inline_size, block_size}; | 181 NGLogicalSize available_size{inline_size, block_size}; |
|
cbiesinger
2017/03/03 12:58:49
You have a variable logical_available_size and an
ikilpatrick
2017/03/03 17:27:06
Sent, thanks for picking up on this. :)
| |
| 173 | 182 |
| 174 NGConstraintSpaceBuilder builder(container_space_->WritingMode()); | 183 NGConstraintSpaceBuilder builder(writing_mode); |
| 175 builder.SetAvailableSize(available_size); | 184 builder.SetAvailableSize(available_size); |
| 176 builder.SetPercentageResolutionSize(container_space_->AvailableSize()); | 185 builder.SetPercentageResolutionSize(logical_available_size); |
| 177 if (block_estimate) | 186 if (block_estimate) |
| 178 builder.SetIsFixedSizeBlock(true); | 187 builder.SetIsFixedSizeBlock(true); |
| 179 builder.SetIsFixedSizeInline(true); | 188 builder.SetIsFixedSizeInline(true); |
| 180 builder.SetIsNewFormattingContext(true); | 189 builder.SetIsNewFormattingContext(true); |
| 181 RefPtr<NGConstraintSpace> space = | 190 RefPtr<NGConstraintSpace> space = builder.ToConstraintSpace(writing_mode); |
| 182 builder.ToConstraintSpace(container_space_->WritingMode()); | |
| 183 | 191 |
| 184 return descendant.Layout(space.get()); | 192 return descendant.Layout(space.get()); |
| 185 } | 193 } |
| 186 | 194 |
| 187 } // namespace blink | 195 } // namespace blink |
| OLD | NEW |