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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 layout_box_(nullptr), | 70 layout_box_(nullptr), |
71 style_(style) { | 71 style_(style) { |
72 DCHECK(style_); | 72 DCHECK(style_); |
73 } | 73 } |
74 | 74 |
75 // Need an explicit destructor in the .cc file, or the MSWIN compiler will | 75 // Need an explicit destructor in the .cc file, or the MSWIN compiler will |
76 // produce an error when attempting to generate a default one, if the .h file is | 76 // produce an error when attempting to generate a default one, if the .h file is |
77 // included from a compilation unit that lacks the ComputedStyle definition. | 77 // included from a compilation unit that lacks the ComputedStyle definition. |
78 NGBlockNode::~NGBlockNode() {} | 78 NGBlockNode::~NGBlockNode() {} |
79 | 79 |
80 RefPtr<NGLayoutResult> NGBlockNode::Layout( | 80 RefPtr<NGLayoutResult> NGBlockNode::Layout(NGConstraintSpace* constraint_space, |
81 NGConstraintSpace* constraint_space) { | 81 NGBreakToken* break_token) { |
82 // Use the old layout code and synthesize a fragment. | 82 // Use the old layout code and synthesize a fragment. |
83 if (!CanUseNewLayout()) { | 83 if (!CanUseNewLayout()) { |
84 DCHECK(layout_box_); | 84 DCHECK(layout_box_); |
85 layout_result_ = RunOldLayout(*constraint_space); | 85 layout_result_ = RunOldLayout(*constraint_space); |
86 return layout_result_; | 86 return layout_result_; |
87 } | 87 } |
88 | 88 |
89 layout_result_ = | 89 layout_result_ = NGBlockLayoutAlgorithm(this, constraint_space, |
90 NGBlockLayoutAlgorithm(this, constraint_space, CurrentBreakToken()) | 90 toNGBlockBreakToken(break_token)) |
91 .Layout(); | 91 .Layout(); |
92 | 92 |
93 CopyFragmentDataToLayoutBox(*constraint_space); | 93 CopyFragmentDataToLayoutBox(*constraint_space); |
94 return layout_result_; | 94 return layout_result_; |
95 } | 95 } |
96 | 96 |
97 MinAndMaxContentSizes NGBlockNode::ComputeMinAndMaxContentSizes() { | 97 MinAndMaxContentSizes NGBlockNode::ComputeMinAndMaxContentSizes() { |
98 MinAndMaxContentSizes sizes; | 98 MinAndMaxContentSizes sizes; |
99 if (!CanUseNewLayout()) { | 99 if (!CanUseNewLayout()) { |
100 DCHECK(layout_box_); | 100 DCHECK(layout_box_); |
101 // TODO(layout-ng): This could be somewhat optimized by directly calling | 101 // TODO(layout-ng): This could be somewhat optimized by directly calling |
(...skipping 18 matching lines...) Expand all Loading... |
120 .ToConstraintSpace(FromPlatformWritingMode(Style().getWritingMode())); | 120 .ToConstraintSpace(FromPlatformWritingMode(Style().getWritingMode())); |
121 | 121 |
122 // TODO(cbiesinger): For orthogonal children, we need to always synthesize. | 122 // TODO(cbiesinger): For orthogonal children, we need to always synthesize. |
123 NGBlockLayoutAlgorithm minmax_algorithm(this, constraint_space); | 123 NGBlockLayoutAlgorithm minmax_algorithm(this, constraint_space); |
124 Optional<MinAndMaxContentSizes> maybe_sizes = | 124 Optional<MinAndMaxContentSizes> maybe_sizes = |
125 minmax_algorithm.ComputeMinAndMaxContentSizes(); | 125 minmax_algorithm.ComputeMinAndMaxContentSizes(); |
126 if (maybe_sizes.has_value()) | 126 if (maybe_sizes.has_value()) |
127 return *maybe_sizes; | 127 return *maybe_sizes; |
128 | 128 |
129 // Have to synthesize this value. | 129 // Have to synthesize this value. |
130 RefPtr<NGLayoutResult> layout_result = Layout(constraint_space); | 130 RefPtr<NGLayoutResult> layout_result = |
| 131 Layout(constraint_space, /* break_token */ nullptr); |
131 NGPhysicalFragment* physical_fragment = | 132 NGPhysicalFragment* physical_fragment = |
132 layout_result->PhysicalFragment().get(); | 133 layout_result->PhysicalFragment().get(); |
133 NGBoxFragment min_fragment(FromPlatformWritingMode(Style().getWritingMode()), | 134 NGBoxFragment min_fragment(FromPlatformWritingMode(Style().getWritingMode()), |
134 toNGPhysicalBoxFragment(physical_fragment)); | 135 toNGPhysicalBoxFragment(physical_fragment)); |
135 sizes.min_content = min_fragment.InlineOverflow(); | 136 sizes.min_content = min_fragment.InlineOverflow(); |
136 | 137 |
137 // Now, redo with infinite space for max_content | 138 // Now, redo with infinite space for max_content |
138 constraint_space = | 139 constraint_space = |
139 NGConstraintSpaceBuilder( | 140 NGConstraintSpaceBuilder( |
140 FromPlatformWritingMode(Style().getWritingMode())) | 141 FromPlatformWritingMode(Style().getWritingMode())) |
141 .SetTextDirection(Style().direction()) | 142 .SetTextDirection(Style().direction()) |
142 .SetAvailableSize({LayoutUnit::max(), LayoutUnit()}) | 143 .SetAvailableSize({LayoutUnit::max(), LayoutUnit()}) |
143 .SetPercentageResolutionSize({LayoutUnit(), LayoutUnit()}) | 144 .SetPercentageResolutionSize({LayoutUnit(), LayoutUnit()}) |
144 .ToConstraintSpace(FromPlatformWritingMode(Style().getWritingMode())); | 145 .ToConstraintSpace(FromPlatformWritingMode(Style().getWritingMode())); |
145 | 146 |
146 layout_result = Layout(constraint_space); | 147 layout_result = Layout(constraint_space, /* break_token */ nullptr); |
147 physical_fragment = layout_result->PhysicalFragment().get(); | 148 physical_fragment = layout_result->PhysicalFragment().get(); |
148 NGBoxFragment max_fragment(FromPlatformWritingMode(Style().getWritingMode()), | 149 NGBoxFragment max_fragment(FromPlatformWritingMode(Style().getWritingMode()), |
149 toNGPhysicalBoxFragment(physical_fragment)); | 150 toNGPhysicalBoxFragment(physical_fragment)); |
150 sizes.max_content = max_fragment.InlineOverflow(); | 151 sizes.max_content = max_fragment.InlineOverflow(); |
151 return sizes; | 152 return sizes; |
152 } | 153 } |
153 | 154 |
154 const ComputedStyle& NGBlockNode::Style() const { | 155 const ComputedStyle& NGBlockNode::Style() const { |
155 if (style_) | 156 if (style_) |
156 return *style_.get(); | 157 return *style_.get(); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 // Save static position for legacy AbsPos layout. | 361 // Save static position for legacy AbsPos layout. |
361 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) { | 362 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) { |
362 DCHECK(layout_box_); | 363 DCHECK(layout_box_); |
363 DCHECK(layout_box_->isOutOfFlowPositioned()); | 364 DCHECK(layout_box_->isOutOfFlowPositioned()); |
364 DCHECK(layout_box_->layer()); | 365 DCHECK(layout_box_->layer()); |
365 layout_box_->layer()->setStaticBlockPosition(offset.block_offset); | 366 layout_box_->layer()->setStaticBlockPosition(offset.block_offset); |
366 layout_box_->layer()->setStaticInlinePosition(offset.inline_offset); | 367 layout_box_->layer()->setStaticInlinePosition(offset.inline_offset); |
367 } | 368 } |
368 | 369 |
369 } // namespace blink | 370 } // namespace blink |
OLD | NEW |