Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(714)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_block_node.cc

Issue 2714803002: [LayoutNG] Allow block-flow layout to be fragmented using new approach. (Closed)
Patch Set: rebase. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "core/layout/ng/ng_block_break_token.h"
11 #include "core/layout/ng/ng_block_layout_algorithm.h" 12 #include "core/layout/ng/ng_block_layout_algorithm.h"
12 #include "core/layout/ng/ng_box_fragment.h" 13 #include "core/layout/ng/ng_box_fragment.h"
13 #include "core/layout/ng/ng_constraint_space.h" 14 #include "core/layout/ng/ng_constraint_space.h"
14 #include "core/layout/ng/ng_constraint_space_builder.h" 15 #include "core/layout/ng/ng_constraint_space_builder.h"
15 #include "core/layout/ng/ng_fragment_builder.h" 16 #include "core/layout/ng/ng_fragment_builder.h"
16 #include "core/layout/ng/ng_inline_node.h" 17 #include "core/layout/ng/ng_inline_node.h"
17 #include "core/layout/ng/ng_layout_result.h" 18 #include "core/layout/ng/ng_layout_result.h"
18 #include "core/layout/ng/ng_length_utils.h" 19 #include "core/layout/ng/ng_length_utils.h"
19 #include "core/layout/ng/ng_writing_mode.h" 20 #include "core/layout/ng/ng_writing_mode.h"
20 #include "core/paint/PaintLayer.h" 21 #include "core/paint/PaintLayer.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 layout_box_(nullptr), 80 layout_box_(nullptr),
80 style_(style) { 81 style_(style) {
81 DCHECK(style_); 82 DCHECK(style_);
82 } 83 }
83 84
84 // Need an explicit destructor in the .cc file, or the MSWIN compiler will 85 // Need an explicit destructor in the .cc file, or the MSWIN compiler will
85 // produce an error when attempting to generate a default one, if the .h file is 86 // produce an error when attempting to generate a default one, if the .h file is
86 // included from a compilation unit that lacks the ComputedStyle definition. 87 // included from a compilation unit that lacks the ComputedStyle definition.
87 NGBlockNode::~NGBlockNode() {} 88 NGBlockNode::~NGBlockNode() {}
88 89
89 RefPtr<NGLayoutResult> NGBlockNode::Layout( 90 RefPtr<NGLayoutResult> NGBlockNode::Layout(NGConstraintSpace* constraint_space,
90 NGConstraintSpace* constraint_space) { 91 NGBreakToken* break_token) {
91 // Use the old layout code and synthesize a fragment. 92 // Use the old layout code and synthesize a fragment.
92 if (!CanUseNewLayout()) { 93 if (!CanUseNewLayout()) {
93 DCHECK(layout_box_); 94 DCHECK(layout_box_);
94 layout_result_ = RunOldLayout(*constraint_space); 95 layout_result_ = RunOldLayout(*constraint_space);
95 return layout_result_; 96 return layout_result_;
96 } 97 }
97 98
98 layout_result_ = 99 layout_result_ = NGBlockLayoutAlgorithm(this, constraint_space,
99 NGBlockLayoutAlgorithm(this, constraint_space, CurrentBreakToken()) 100 toNGBlockBreakToken(break_token))
100 .Layout(); 101 .Layout();
101 102
102 CopyFragmentDataToLayoutBox(*constraint_space); 103 CopyFragmentDataToLayoutBox(*constraint_space);
103 return layout_result_; 104 return layout_result_;
104 } 105 }
105 106
106 MinAndMaxContentSizes NGBlockNode::ComputeMinAndMaxContentSizes() { 107 MinAndMaxContentSizes NGBlockNode::ComputeMinAndMaxContentSizes() {
107 MinAndMaxContentSizes sizes; 108 MinAndMaxContentSizes sizes;
108 if (!CanUseNewLayout()) { 109 if (!CanUseNewLayout()) {
109 DCHECK(layout_box_); 110 DCHECK(layout_box_);
110 // TODO(layout-ng): This could be somewhat optimized by directly calling 111 // TODO(layout-ng): This could be somewhat optimized by directly calling
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 201 }
201 202
202 void NGBlockNode::SetNextSibling(NGLayoutInputNode* sibling) { 203 void NGBlockNode::SetNextSibling(NGLayoutInputNode* sibling) {
203 next_sibling_ = sibling; 204 next_sibling_ = sibling;
204 } 205 }
205 206
206 void NGBlockNode::SetFirstChild(NGLayoutInputNode* child) { 207 void NGBlockNode::SetFirstChild(NGLayoutInputNode* child) {
207 first_child_ = child; 208 first_child_ = child;
208 } 209 }
209 210
210 NGBreakToken* NGBlockNode::CurrentBreakToken() const {
211 return layout_result_ ? layout_result_->PhysicalFragment()->BreakToken()
212 : nullptr;
213 }
214
215 DEFINE_TRACE(NGBlockNode) { 211 DEFINE_TRACE(NGBlockNode) {
216 visitor->trace(next_sibling_); 212 visitor->trace(next_sibling_);
217 visitor->trace(first_child_); 213 visitor->trace(first_child_);
218 NGLayoutInputNode::trace(visitor); 214 NGLayoutInputNode::trace(visitor);
219 } 215 }
220 216
221 bool NGBlockNode::CanUseNewLayout() { 217 bool NGBlockNode::CanUseNewLayout() {
222 if (!layout_box_) 218 if (!layout_box_)
223 return true; 219 return true;
224 if (!layout_box_->isLayoutBlockFlow()) 220 if (!layout_box_->isLayoutBlockFlow())
(...skipping 23 matching lines...) Expand all
248 const NGConstraintSpace& constraint_space) { 244 const NGConstraintSpace& constraint_space) {
249 // We may not have a layout_box_ during unit tests. 245 // We may not have a layout_box_ during unit tests.
250 if (!layout_box_) 246 if (!layout_box_)
251 return; 247 return;
252 248
253 NGPhysicalBoxFragment* fragment = 249 NGPhysicalBoxFragment* fragment =
254 toNGPhysicalBoxFragment(layout_result_->PhysicalFragment().get()); 250 toNGPhysicalBoxFragment(layout_result_->PhysicalFragment().get());
255 251
256 layout_box_->setWidth(fragment->Width()); 252 layout_box_->setWidth(fragment->Width());
257 layout_box_->setHeight(fragment->Height()); 253 layout_box_->setHeight(fragment->Height());
258 NGBoxStrut border_and_padding = 254 NGBoxStrut border_and_padding = ComputeBorders(constraint_space, Style()) +
259 ComputeBorders(Style()) + ComputePadding(constraint_space, Style()); 255 ComputePadding(constraint_space, Style());
260 LayoutUnit intrinsic_logical_height = 256 LayoutUnit intrinsic_logical_height =
261 layout_box_->style()->isHorizontalWritingMode() 257 layout_box_->style()->isHorizontalWritingMode()
262 ? fragment->HeightOverflow() 258 ? fragment->HeightOverflow()
263 : fragment->WidthOverflow(); 259 : fragment->WidthOverflow();
264 intrinsic_logical_height -= border_and_padding.BlockSum(); 260 intrinsic_logical_height -= border_and_padding.BlockSum();
265 layout_box_->setIntrinsicContentLogicalHeight(intrinsic_logical_height); 261 layout_box_->setIntrinsicContentLogicalHeight(intrinsic_logical_height);
266 262
267 // We may still have unpositioned floats when we reach the root box. 263 // We may still have unpositioned floats when we reach the root box.
268 if (!layout_box_->parent()) { 264 if (!layout_box_->parent()) {
269 for (const auto& floating_object : fragment->PositionedFloats()) { 265 for (const auto& floating_object : fragment->PositionedFloats()) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 // Save static position for legacy AbsPos layout. 365 // Save static position for legacy AbsPos layout.
370 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) { 366 void NGBlockNode::SaveStaticOffsetForLegacy(const NGLogicalOffset& offset) {
371 DCHECK(layout_box_); 367 DCHECK(layout_box_);
372 DCHECK(layout_box_->isOutOfFlowPositioned()); 368 DCHECK(layout_box_->isOutOfFlowPositioned());
373 DCHECK(layout_box_->layer()); 369 DCHECK(layout_box_->layer());
374 layout_box_->layer()->setStaticBlockPosition(offset.block_offset); 370 layout_box_->layer()->setStaticBlockPosition(offset.block_offset);
375 layout_box_->layer()->setStaticInlinePosition(offset.inline_offset); 371 layout_box_->layer()->setStaticInlinePosition(offset.inline_offset);
376 } 372 }
377 373
378 } // namespace blink 374 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_block_node.h ('k') | third_party/WebKit/Source/core/layout/ng/ng_column_mapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698