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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 borderAndPadding; | 109 borderAndPadding; |
110 sizes.max_content = layout_box_->computeLogicalWidthUsing( | 110 sizes.max_content = layout_box_->computeLogicalWidthUsing( |
111 MainOrPreferredSize, Length(MaxContent), | 111 MainOrPreferredSize, Length(MaxContent), |
112 LayoutUnit(), layout_box_->containingBlock()) - | 112 LayoutUnit(), layout_box_->containingBlock()) - |
113 borderAndPadding; | 113 borderAndPadding; |
114 return sizes; | 114 return sizes; |
115 } | 115 } |
116 | 116 |
117 NGConstraintSpace* constraint_space = | 117 NGConstraintSpace* constraint_space = |
118 NGConstraintSpaceBuilder( | 118 NGConstraintSpaceBuilder( |
119 FromPlatformWritingMode(Style()->getWritingMode())) | 119 FromPlatformWritingMode(Style().getWritingMode())) |
120 .SetTextDirection(Style()->direction()) | 120 .SetTextDirection(Style().direction()) |
121 .ToConstraintSpace(); | 121 .ToConstraintSpace(); |
122 | 122 |
123 // TODO(cbiesinger): For orthogonal children, we need to always synthesize. | 123 // TODO(cbiesinger): For orthogonal children, we need to always synthesize. |
124 // TODO(kojii): Add other algorithms when they support | 124 // TODO(kojii): Add other algorithms when they support |
125 // ComputeMinAndMaxContentSizes. | 125 // ComputeMinAndMaxContentSizes. |
126 NGLayoutInputNode* first_child = FirstChild(); | 126 NGLayoutInputNode* first_child = FirstChild(); |
127 if (!first_child || first_child->Type() == kLegacyBlock) { | 127 if (!first_child || first_child->Type() == kLegacyBlock) { |
128 NGBlockLayoutAlgorithm minmax_algorithm( | 128 NGBlockLayoutAlgorithm minmax_algorithm( |
129 layout_box_, Style(), toNGBlockNode(FirstChild()), constraint_space); | 129 layout_box_, &Style(), toNGBlockNode(FirstChild()), constraint_space); |
130 if (minmax_algorithm.ComputeMinAndMaxContentSizes(&sizes)) | 130 if (minmax_algorithm.ComputeMinAndMaxContentSizes(&sizes)) |
131 return sizes; | 131 return sizes; |
132 } | 132 } |
133 | 133 |
134 // Have to synthesize this value. | 134 // Have to synthesize this value. |
135 NGPhysicalFragment* physical_fragment = Layout(constraint_space); | 135 NGPhysicalFragment* physical_fragment = Layout(constraint_space); |
136 NGBoxFragment* fragment = new NGBoxFragment( | 136 NGBoxFragment* fragment = new NGBoxFragment( |
137 FromPlatformWritingMode(Style()->getWritingMode()), Style()->direction(), | 137 FromPlatformWritingMode(Style().getWritingMode()), Style().direction(), |
138 toNGPhysicalBoxFragment(physical_fragment)); | 138 toNGPhysicalBoxFragment(physical_fragment)); |
139 | 139 |
140 sizes.min_content = fragment->InlineOverflow(); | 140 sizes.min_content = fragment->InlineOverflow(); |
141 | 141 |
142 // Now, redo with infinite space for max_content | 142 // Now, redo with infinite space for max_content |
143 constraint_space = | 143 constraint_space = |
144 NGConstraintSpaceBuilder( | 144 NGConstraintSpaceBuilder( |
145 FromPlatformWritingMode(Style()->getWritingMode())) | 145 FromPlatformWritingMode(Style().getWritingMode())) |
146 .SetTextDirection(Style()->direction()) | 146 .SetTextDirection(Style().direction()) |
147 .SetAvailableSize({LayoutUnit::max(), LayoutUnit()}) | 147 .SetAvailableSize({LayoutUnit::max(), LayoutUnit()}) |
148 .SetPercentageResolutionSize({LayoutUnit(), LayoutUnit()}) | 148 .SetPercentageResolutionSize({LayoutUnit(), LayoutUnit()}) |
149 .ToConstraintSpace(); | 149 .ToConstraintSpace(); |
150 | 150 |
151 physical_fragment = Layout(constraint_space); | 151 physical_fragment = Layout(constraint_space); |
152 fragment = new NGBoxFragment( | 152 fragment = new NGBoxFragment( |
153 FromPlatformWritingMode(Style()->getWritingMode()), Style()->direction(), | 153 FromPlatformWritingMode(Style().getWritingMode()), Style().direction(), |
154 toNGPhysicalBoxFragment(physical_fragment)); | 154 toNGPhysicalBoxFragment(physical_fragment)); |
155 sizes.max_content = fragment->InlineOverflow(); | 155 sizes.max_content = fragment->InlineOverflow(); |
156 return sizes; | 156 return sizes; |
157 } | 157 } |
158 | 158 |
159 ComputedStyle* NGBlockNode::MutableStyle() { | 159 const ComputedStyle& NGBlockNode::Style() const { |
160 if (style_) | 160 if (style_) |
161 return style_.get(); | 161 return *style_.get(); |
162 DCHECK(layout_box_); | 162 DCHECK(layout_box_); |
163 return layout_box_->mutableStyle(); | 163 return layout_box_->styleRef(); |
164 } | |
165 | |
166 const ComputedStyle* NGBlockNode::Style() const { | |
167 if (style_) | |
168 return style_.get(); | |
169 DCHECK(layout_box_); | |
170 return layout_box_->style(); | |
171 } | 164 } |
172 | 165 |
173 NGBlockNode* NGBlockNode::NextSibling() { | 166 NGBlockNode* NGBlockNode::NextSibling() { |
174 if (!next_sibling_) { | 167 if (!next_sibling_) { |
175 LayoutObject* next_sibling = | 168 LayoutObject* next_sibling = |
176 layout_box_ ? layout_box_->nextSibling() : nullptr; | 169 layout_box_ ? layout_box_->nextSibling() : nullptr; |
177 NGBlockNode* box = next_sibling ? new NGBlockNode(next_sibling) : nullptr; | 170 NGBlockNode* box = next_sibling ? new NGBlockNode(next_sibling) : nullptr; |
178 SetNextSibling(box); | 171 SetNextSibling(box); |
179 } | 172 } |
180 return next_sibling_; | 173 return next_sibling_; |
181 } | 174 } |
182 | 175 |
183 LayoutObject* NGBlockNode::GetLayoutObject() { | 176 LayoutObject* NGBlockNode::GetLayoutObject() { |
184 return layout_box_; | 177 return layout_box_; |
185 } | 178 } |
186 | 179 |
187 NGLayoutInputNode* NGBlockNode::FirstChild() { | 180 NGLayoutInputNode* NGBlockNode::FirstChild() { |
188 if (!first_child_) { | 181 if (!first_child_) { |
189 LayoutObject* child = layout_box_ ? layout_box_->slowFirstChild() : nullptr; | 182 LayoutObject* child = layout_box_ ? layout_box_->slowFirstChild() : nullptr; |
190 if (child) { | 183 if (child) { |
191 if (child->isInline()) { | 184 if (child->isInline()) { |
192 SetFirstChild(new NGInlineNode(child, MutableStyle())); | 185 SetFirstChild(new NGInlineNode(child, &Style())); |
193 } else { | 186 } else { |
194 SetFirstChild(new NGBlockNode(child)); | 187 SetFirstChild(new NGBlockNode(child)); |
195 } | 188 } |
196 } | 189 } |
197 } | 190 } |
198 return first_child_; | 191 return first_child_; |
199 } | 192 } |
200 | 193 |
201 void NGBlockNode::SetNextSibling(NGBlockNode* sibling) { | 194 void NGBlockNode::SetNextSibling(NGBlockNode* sibling) { |
202 next_sibling_ = sibling; | 195 next_sibling_ = sibling; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 238 |
246 void NGBlockNode::CopyFragmentDataToLayoutBox( | 239 void NGBlockNode::CopyFragmentDataToLayoutBox( |
247 const NGConstraintSpace& constraint_space) { | 240 const NGConstraintSpace& constraint_space) { |
248 // We may not have a layout_box_ during unit tests. | 241 // We may not have a layout_box_ during unit tests. |
249 if (!layout_box_) | 242 if (!layout_box_) |
250 return; | 243 return; |
251 | 244 |
252 layout_box_->setWidth(fragment_->Width()); | 245 layout_box_->setWidth(fragment_->Width()); |
253 layout_box_->setHeight(fragment_->Height()); | 246 layout_box_->setHeight(fragment_->Height()); |
254 NGBoxStrut border_and_padding = | 247 NGBoxStrut border_and_padding = |
255 ComputeBorders(*Style()) + ComputePadding(constraint_space, *Style()); | 248 ComputeBorders(Style()) + ComputePadding(constraint_space, Style()); |
256 LayoutUnit intrinsic_logical_height = | 249 LayoutUnit intrinsic_logical_height = |
257 layout_box_->style()->isHorizontalWritingMode() | 250 layout_box_->style()->isHorizontalWritingMode() |
258 ? fragment_->HeightOverflow() | 251 ? fragment_->HeightOverflow() |
259 : fragment_->WidthOverflow(); | 252 : fragment_->WidthOverflow(); |
260 intrinsic_logical_height -= border_and_padding.BlockSum(); | 253 intrinsic_logical_height -= border_and_padding.BlockSum(); |
261 layout_box_->setIntrinsicContentLogicalHeight(intrinsic_logical_height); | 254 layout_box_->setIntrinsicContentLogicalHeight(intrinsic_logical_height); |
262 | 255 |
263 // TODO(layout-dev): Currently we are not actually performing layout on | 256 // TODO(layout-dev): Currently we are not actually performing layout on |
264 // inline children. For now just clear the needsLayout bit so that we can | 257 // inline children. For now just clear the needsLayout bit so that we can |
265 // run unittests. | 258 // run unittests. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 // Save static position for legacy AbsPos layout. | 332 // Save static position for legacy AbsPos layout. |
340 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) { | 333 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) { |
341 DCHECK(layout_box_); | 334 DCHECK(layout_box_); |
342 DCHECK(layout_box_->isOutOfFlowPositioned()); | 335 DCHECK(layout_box_->isOutOfFlowPositioned()); |
343 DCHECK(layout_box_->layer()); | 336 DCHECK(layout_box_->layer()); |
344 layout_box_->layer()->setStaticBlockPosition(offset.block_offset); | 337 layout_box_->layer()->setStaticBlockPosition(offset.block_offset); |
345 layout_box_->layer()->setStaticInlinePosition(offset.inline_offset); | 338 layout_box_->layer()->setStaticInlinePosition(offset.inline_offset); |
346 } | 339 } |
347 | 340 |
348 } // namespace blink | 341 } // namespace blink |
OLD | NEW |