| 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_constraint_space_builder.h" | 9 #include "core/layout/ng/ng_constraint_space_builder.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_physical_fragment.h" |
| 11 #include "core/style/ComputedStyle.h" | 12 #include "core/style/ComputedStyle.h" |
| 12 #include "core/layout/ng/ng_fragment.h" | 13 #include "core/layout/ng/ng_fragment.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 NGOutOfFlowLayoutPart::NGOutOfFlowLayoutPart( | 17 NGOutOfFlowLayoutPart::NGOutOfFlowLayoutPart( |
| 17 PassRefPtr<const ComputedStyle> container_style, | 18 PassRefPtr<const ComputedStyle> container_style, |
| 18 NGLogicalSize container_size) { | 19 NGLogicalSize container_size) { |
| 19 contains_fixed_ = container_style->canContainFixedPositionObjects(); | 20 contains_fixed_ = container_style->canContainFixedPositionObjects(); |
| 20 contains_absolute_ = | 21 contains_absolute_ = |
| 21 container_style->canContainAbsolutePositionObjects() || contains_fixed_; | 22 container_style->canContainAbsolutePositionObjects() || contains_fixed_; |
| 22 // Initialize ConstraintSpace | 23 // Initialize ConstraintSpace |
| 23 NGLogicalSize space_size = container_size; | 24 NGLogicalSize space_size = container_size; |
| 24 NGBoxStrut borders = ComputeBorders(*container_style); | 25 NGBoxStrut borders = ComputeBorders(*container_style); |
| 25 space_size.block_size -= borders.BlockSum(); | 26 space_size.block_size -= borders.BlockSum(); |
| 26 space_size.inline_size -= borders.InlineSum(); | 27 space_size.inline_size -= borders.InlineSum(); |
| 27 parent_offset_ = NGLogicalOffset{borders.inline_start, borders.block_start}; | 28 parent_offset_ = NGLogicalOffset{borders.inline_start, borders.block_start}; |
| 28 parent_physical_offset_ = parent_offset_.ConvertToPhysical( | 29 parent_physical_offset_ = parent_offset_.ConvertToPhysical( |
| 29 FromPlatformWritingMode(container_style->getWritingMode()), | 30 FromPlatformWritingMode(container_style->getWritingMode()), |
| 30 container_style->direction(), | 31 container_style->direction(), |
| 31 container_size.ConvertToPhysical( | 32 container_size.ConvertToPhysical( |
| 32 FromPlatformWritingMode(container_style->getWritingMode())), | 33 FromPlatformWritingMode(container_style->getWritingMode())), |
| 33 NGPhysicalSize()); | 34 NGPhysicalSize()); |
| 34 NGConstraintSpaceBuilder space_builder( | 35 NGConstraintSpaceBuilder space_builder( |
| 35 FromPlatformWritingMode(container_style->getWritingMode())); | 36 FromPlatformWritingMode(container_style->getWritingMode())); |
| 36 space_builder.SetAvailableSize(space_size); | 37 space_builder.SetAvailableSize(space_size); |
| 38 space_builder.SetPercentageResolutionSize(space_size); |
| 37 space_builder.SetIsNewFormattingContext(true); | 39 space_builder.SetIsNewFormattingContext(true); |
| 38 space_builder.SetTextDirection(container_style->direction()); | 40 space_builder.SetTextDirection(container_style->direction()); |
| 39 parent_space_ = space_builder.ToConstraintSpace(); | 41 parent_space_ = space_builder.ToConstraintSpace(); |
| 40 } | 42 } |
| 41 | 43 |
| 42 bool NGOutOfFlowLayoutPart::StartLayout( | 44 bool NGOutOfFlowLayoutPart::StartLayout( |
| 43 NGBlockNode* node, | 45 NGBlockNode* node, |
| 44 const NGStaticPosition& static_position) { | 46 const NGStaticPosition& static_position) { |
| 45 EPosition position = node->Style()->position(); | 47 EPosition position = node->Style()->position(); |
| 46 if ((contains_absolute_ && position == AbsolutePosition) || | 48 if ((contains_absolute_ && position == AbsolutePosition) || |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 offset->block_offset = inset.block_start + parent_offset_.block_offset; | 102 offset->block_offset = inset.block_start + parent_offset_.block_offset; |
| 101 return kNewFragment; | 103 return kNewFragment; |
| 102 } | 104 } |
| 103 return kNotFinished; | 105 return kNotFinished; |
| 104 } | 106 } |
| 105 | 107 |
| 106 bool NGOutOfFlowLayoutPart::ComputeInlineSizeEstimate() { | 108 bool NGOutOfFlowLayoutPart::ComputeInlineSizeEstimate() { |
| 107 if (AbsoluteNeedsChildInlineSize(*node_->Style())) { | 109 if (AbsoluteNeedsChildInlineSize(*node_->Style())) { |
| 108 MinAndMaxContentSizes size; | 110 MinAndMaxContentSizes size; |
| 109 if (node_->ComputeMinAndMaxContentSizes(&size)) { | 111 if (node_->ComputeMinAndMaxContentSizes(&size)) { |
| 110 inline_estimate_ = | 112 inline_estimate_ = size; |
| 111 size.ShrinkToFit(parent_space_->AvailableSize().inline_size); | |
| 112 return true; | 113 return true; |
| 113 } | 114 } |
| 114 return false; | 115 return false; |
| 115 } | 116 } |
| 116 return true; | 117 return true; |
| 117 } | 118 } |
| 118 | 119 |
| 119 bool NGOutOfFlowLayoutPart::ComputeBlockSizeEstimate() { | 120 bool NGOutOfFlowLayoutPart::ComputeBlockSizeEstimate() { |
| 120 if (AbsoluteNeedsChildBlockSize(*node_->Style())) { | 121 if (AbsoluteNeedsChildBlockSize(*node_->Style())) { |
| 121 if (ComputeNodeFragment()) { | 122 if (ComputeNodeFragment()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 138 // Node fragment is computed in one of these two scenarios: | 139 // Node fragment is computed in one of these two scenarios: |
| 139 // 1. To estimate block size | 140 // 1. To estimate block size |
| 140 // In this case, available block_size is parent's size. | 141 // In this case, available block_size is parent's size. |
| 141 // 2. To compute final block fragment, when block size is known. | 142 // 2. To compute final block fragment, when block size is known. |
| 142 | 143 |
| 143 NGLogicalSize available_size = | 144 NGLogicalSize available_size = |
| 144 NGLogicalSize(inline_width, parent_space_->AvailableSize().block_size); | 145 NGLogicalSize(inline_width, parent_space_->AvailableSize().block_size); |
| 145 if (block_estimate_) | 146 if (block_estimate_) |
| 146 available_size.block_size = *block_estimate_; | 147 available_size.block_size = *block_estimate_; |
| 147 builder.SetAvailableSize(available_size); | 148 builder.SetAvailableSize(available_size); |
| 148 builder.SetPercentageResolutionSize(available_size); | 149 builder.SetPercentageResolutionSize(parent_space_->AvailableSize()); |
| 149 if (block_estimate_) | 150 if (block_estimate_) |
| 150 builder.SetIsFixedSizeBlock(true); | 151 builder.SetIsFixedSizeBlock(true); |
| 151 builder.SetIsFixedSizeInline(true); | 152 builder.SetIsFixedSizeInline(true); |
| 152 builder.SetIsNewFormattingContext(true); | 153 builder.SetIsNewFormattingContext(true); |
| 153 node_space_ = builder.ToConstraintSpace(); | 154 node_space_ = builder.ToConstraintSpace(); |
| 154 } | 155 } |
| 155 NGFragment* fragment; | 156 NGFragment* fragment; |
| 156 if (node_->Layout(node_space_, &fragment)) { | 157 if (node_->Layout(node_space_, &fragment)) { |
| 157 node_fragment_ = fragment; | 158 node_fragment_ = fragment; |
| 158 return true; | 159 return true; |
| 159 } | 160 } |
| 160 return false; | 161 return false; |
| 161 } | 162 } |
| 162 | 163 |
| 163 DEFINE_TRACE(NGOutOfFlowLayoutPart) { | 164 DEFINE_TRACE(NGOutOfFlowLayoutPart) { |
| 164 visitor->trace(node_); | 165 visitor->trace(node_); |
| 165 visitor->trace(parent_space_); | 166 visitor->trace(parent_space_); |
| 166 visitor->trace(node_fragment_); | 167 visitor->trace(node_fragment_); |
| 167 visitor->trace(node_space_); | 168 visitor->trace(node_space_); |
| 168 } | 169 } |
| 169 } | 170 } |
| OLD | NEW |