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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // Need an explicit destructor in the .cc file, or the MSWIN compiler will | 78 // Need an explicit destructor in the .cc file, or the MSWIN compiler will |
79 // produce an error when attempting to generate a default one, if the .h file is | 79 // produce an error when attempting to generate a default one, if the .h file is |
80 // included from a compilation unit that lacks the ComputedStyle definition. | 80 // included from a compilation unit that lacks the ComputedStyle definition. |
81 NGBlockNode::~NGBlockNode() {} | 81 NGBlockNode::~NGBlockNode() {} |
82 | 82 |
83 RefPtr<NGLayoutResult> NGBlockNode::Layout(NGConstraintSpace* constraint_space, | 83 RefPtr<NGLayoutResult> NGBlockNode::Layout(NGConstraintSpace* constraint_space, |
84 NGBreakToken* break_token) { | 84 NGBreakToken* break_token) { |
85 // Use the old layout code and synthesize a fragment. | 85 // Use the old layout code and synthesize a fragment. |
86 if (!CanUseNewLayout()) { | 86 if (!CanUseNewLayout()) { |
87 DCHECK(layout_box_); | 87 DCHECK(layout_box_); |
88 layout_result_ = RunOldLayout(*constraint_space); | 88 return RunOldLayout(*constraint_space); |
89 return layout_result_; | |
90 } | 89 } |
91 | 90 |
92 layout_result_ = NGBlockLayoutAlgorithm(this, constraint_space, | 91 RefPtr<NGLayoutResult> layout_result = |
93 toNGBlockBreakToken(break_token)) | 92 NGBlockLayoutAlgorithm(this, constraint_space, |
94 .Layout(); | 93 toNGBlockBreakToken(break_token)) |
| 94 .Layout(); |
95 | 95 |
96 CopyFragmentDataToLayoutBox(*constraint_space); | 96 CopyFragmentDataToLayoutBox(*constraint_space, layout_result.get()); |
97 return layout_result_; | 97 return layout_result; |
98 } | 98 } |
99 | 99 |
100 MinAndMaxContentSizes NGBlockNode::ComputeMinAndMaxContentSizes() { | 100 MinAndMaxContentSizes NGBlockNode::ComputeMinAndMaxContentSizes() { |
101 MinAndMaxContentSizes sizes; | 101 MinAndMaxContentSizes sizes; |
102 if (!CanUseNewLayout()) { | 102 if (!CanUseNewLayout()) { |
103 DCHECK(layout_box_); | 103 DCHECK(layout_box_); |
104 // TODO(layout-ng): This could be somewhat optimized by directly calling | 104 // TODO(layout-ng): This could be somewhat optimized by directly calling |
105 // computeIntrinsicLogicalWidths, but that function is currently private. | 105 // computeIntrinsicLogicalWidths, but that function is currently private. |
106 // Consider doing that if this becomes a performance issue. | 106 // Consider doing that if this becomes a performance issue. |
107 LayoutUnit borderAndPadding = layout_box_->borderAndPaddingLogicalWidth(); | 107 LayoutUnit borderAndPadding = layout_box_->borderAndPaddingLogicalWidth(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 148 |
149 layout_result = Layout(constraint_space.get()); | 149 layout_result = Layout(constraint_space.get()); |
150 physical_fragment = layout_result->PhysicalFragment().get(); | 150 physical_fragment = layout_result->PhysicalFragment().get(); |
151 NGBoxFragment max_fragment(FromPlatformWritingMode(Style().getWritingMode()), | 151 NGBoxFragment max_fragment(FromPlatformWritingMode(Style().getWritingMode()), |
152 toNGPhysicalBoxFragment(physical_fragment)); | 152 toNGPhysicalBoxFragment(physical_fragment)); |
153 sizes.max_content = max_fragment.InlineOverflow(); | 153 sizes.max_content = max_fragment.InlineOverflow(); |
154 return sizes; | 154 return sizes; |
155 } | 155 } |
156 | 156 |
157 const ComputedStyle& NGBlockNode::Style() const { | 157 const ComputedStyle& NGBlockNode::Style() const { |
158 if (style_) | |
159 return *style_.get(); | |
160 DCHECK(layout_box_); | 158 DCHECK(layout_box_); |
161 return layout_box_->styleRef(); | 159 return layout_box_->styleRef(); |
162 } | 160 } |
163 | 161 |
164 NGLayoutInputNode* NGBlockNode::NextSibling() { | 162 NGLayoutInputNode* NGBlockNode::NextSibling() { |
165 if (!next_sibling_) { | 163 if (!next_sibling_) { |
166 LayoutObject* next_sibling = | 164 LayoutObject* next_sibling = |
167 layout_box_ ? layout_box_->nextSibling() : nullptr; | 165 layout_box_ ? layout_box_->nextSibling() : nullptr; |
168 if (next_sibling) { | 166 if (next_sibling) { |
169 if (next_sibling->isInline()) | 167 if (next_sibling->isInline()) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 while (child) { | 217 while (child) { |
220 if (child->isInline()) | 218 if (child->isInline()) |
221 return true; | 219 return true; |
222 child = child->nextSibling(); | 220 child = child->nextSibling(); |
223 } | 221 } |
224 | 222 |
225 return false; | 223 return false; |
226 } | 224 } |
227 | 225 |
228 void NGBlockNode::CopyFragmentDataToLayoutBox( | 226 void NGBlockNode::CopyFragmentDataToLayoutBox( |
229 const NGConstraintSpace& constraint_space) { | 227 const NGConstraintSpace& constraint_space, |
| 228 NGLayoutResult* layout_result) { |
230 // We may not have a layout_box_ during unit tests. | 229 // We may not have a layout_box_ during unit tests. |
231 if (!layout_box_) | 230 if (!layout_box_) |
232 return; | 231 return; |
233 | 232 |
234 NGPhysicalBoxFragment* fragment = | 233 NGPhysicalBoxFragment* fragment = |
235 toNGPhysicalBoxFragment(layout_result_->PhysicalFragment().get()); | 234 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get()); |
236 | 235 |
237 layout_box_->setWidth(fragment->Width()); | 236 layout_box_->setWidth(fragment->Width()); |
238 layout_box_->setHeight(fragment->Height()); | 237 layout_box_->setHeight(fragment->Height()); |
239 NGBoxStrut border_and_padding = ComputeBorders(constraint_space, Style()) + | 238 NGBoxStrut border_and_padding = ComputeBorders(constraint_space, Style()) + |
240 ComputePadding(constraint_space, Style()); | 239 ComputePadding(constraint_space, Style()); |
241 LayoutUnit intrinsic_logical_height = | 240 LayoutUnit intrinsic_logical_height = |
242 layout_box_->style()->isHorizontalWritingMode() | 241 layout_box_->style()->isHorizontalWritingMode() |
243 ? fragment->HeightOverflow() | 242 ? fragment->HeightOverflow() |
244 : fragment->WidthOverflow(); | 243 : fragment->WidthOverflow(); |
245 intrinsic_logical_height -= border_and_padding.BlockSum(); | 244 intrinsic_logical_height -= border_and_padding.BlockSum(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // Save static position for legacy AbsPos layout. | 349 // Save static position for legacy AbsPos layout. |
351 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) { | 350 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) { |
352 DCHECK(layout_box_); | 351 DCHECK(layout_box_); |
353 DCHECK(layout_box_->isOutOfFlowPositioned()); | 352 DCHECK(layout_box_->isOutOfFlowPositioned()); |
354 DCHECK(layout_box_->layer()); | 353 DCHECK(layout_box_->layer()); |
355 layout_box_->layer()->setStaticBlockPosition(offset.block_offset); | 354 layout_box_->layer()->setStaticBlockPosition(offset.block_offset); |
356 layout_box_->layer()->setStaticInlinePosition(offset.inline_offset); | 355 layout_box_->layer()->setStaticInlinePosition(offset.inline_offset); |
357 } | 356 } |
358 | 357 |
359 } // namespace blink | 358 } // namespace blink |
OLD | NEW |