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

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

Issue 2282213002: [LayoutNG] Introduce NGPhysicalFragment and make NGFragment a 'view' (Closed)
Patch Set: address comments. Created 4 years, 3 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_layout_algorithm.h" 5 #include "core/layout/ng/ng_block_layout_algorithm.h"
6 6
7 #include "core/layout/LayoutBox.h" 7 #include "core/layout/LayoutBox.h"
8 #include "core/layout/ng/ng_constraint_space.h" 8 #include "core/layout/ng/ng_constraint_space.h"
9 #include "core/layout/ng/ng_fragment_builder.h" 9 #include "core/layout/ng/ng_fragment_builder.h"
10 #include "core/layout/ng/ng_fragment.h" 10 #include "core/layout/ng/ng_fragment.h"
11 #include "core/layout/ng/ng_length_utils.h" 11 #include "core/layout/ng/ng_length_utils.h"
12 #include "core/layout/ng/ng_units.h"
12 #include "core/style/ComputedStyle.h" 13 #include "core/style/ComputedStyle.h"
13 #include "platform/LengthFunctions.h" 14 #include "platform/LengthFunctions.h"
14 15
15 namespace blink { 16 namespace blink {
16 17
17 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( 18 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(
18 PassRefPtr<const ComputedStyle> style, 19 PassRefPtr<const ComputedStyle> style,
19 NGBox* first_child) 20 NGBox* first_child)
20 : style_(style), first_child_(first_child), state_(kStateInit) {} 21 : style_(style), first_child_(first_child), state_(kStateInit) {}
21 22
22 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space, 23 bool NGBlockLayoutAlgorithm::Layout(const NGConstraintSpace* constraint_space,
23 NGFragment** out) { 24 NGPhysicalFragment** out) {
24 switch (state_) { 25 switch (state_) {
25 case kStateInit: { 26 case kStateInit: {
26 LayoutUnit inline_size = 27 LayoutUnit inline_size =
27 computeInlineSizeForFragment(*constraint_space, *style_); 28 computeInlineSizeForFragment(*constraint_space, *style_);
28 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of 29 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of
29 // -1? 30 // -1?
30 LayoutUnit block_size = computeBlockSizeForFragment( 31 LayoutUnit block_size = computeBlockSizeForFragment(
31 *constraint_space, *style_, LayoutUnit(-1)); 32 *constraint_space, *style_, LayoutUnit(-1));
32 constraint_space_for_children_ = new NGConstraintSpace( 33 constraint_space_for_children_ = new NGConstraintSpace(
33 *constraint_space, NGLogicalSize(inline_size, block_size)); 34 *constraint_space, NGLogicalSize(inline_size, block_size));
34 content_size_ = LayoutUnit(); 35 content_size_ = LayoutUnit();
35 36
36 builder_ = new NGFragmentBuilder(NGFragmentBase::FragmentBox); 37 builder_ = new NGFragmentBuilder(NGPhysicalFragmentBase::FragmentBox);
37 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); 38 builder_->SetInlineSize(inline_size).SetBlockSize(block_size);
38 current_child_ = first_child_; 39 current_child_ = first_child_;
39 state_ = kStateChildLayout; 40 state_ = kStateChildLayout;
40 return false; 41 return false;
41 } 42 }
42 case kStateChildLayout: { 43 case kStateChildLayout: {
43 if (current_child_) { 44 if (current_child_) {
44 NGFragment* fragment; 45 NGFragment* fragment;
45 if (!current_child_->Layout(constraint_space_for_children_, &fragment)) 46 if (!current_child_->Layout(constraint_space_for_children_, &fragment))
46 return false; 47 return false;
47 NGBoxStrut child_margins = computeMargins( 48 NGBoxStrut child_margins = computeMargins(
48 *constraint_space_for_children_, *current_child_->Style()); 49 *constraint_space_for_children_, *current_child_->Style());
49 // TODO(layout-ng): Support auto margins 50 // TODO(layout-ng): Support auto margins
50 fragment->SetOffset(child_margins.inline_start, 51 builder_->AddChild(
51 content_size_ + child_margins.block_start); 52 fragment,
52 current_child_->PositionUpdated(*fragment); 53 NGLogicalOffset(child_margins.inline_start,
54 content_size_ + child_margins.block_start));
55
53 content_size_ += fragment->BlockSize() + child_margins.BlockSum(); 56 content_size_ += fragment->BlockSize() + child_margins.BlockSum();
54 max_inline_size_ = 57 max_inline_size_ =
55 std::max(max_inline_size_, 58 std::max(max_inline_size_,
56 fragment->InlineSize() + child_margins.InlineSum()); 59 fragment->InlineSize() + child_margins.InlineSum());
57 builder_->AddChild(fragment);
58 current_child_ = current_child_->NextSibling(); 60 current_child_ = current_child_->NextSibling();
59 if (current_child_) 61 if (current_child_)
60 return false; 62 return false;
61 } 63 }
62 64
63 state_ = kStateFinalize; 65 state_ = kStateFinalize;
64 return false; 66 return false;
65 } 67 }
66 case kStateFinalize: { 68 case kStateFinalize: {
67 // Recompute the block-axis size now that we know our content size. 69 // Recompute the block-axis size now that we know our content size.
68 LayoutUnit block_size = computeBlockSizeForFragment( 70 LayoutUnit block_size = computeBlockSizeForFragment(
69 *constraint_space, *style_, content_size_); 71 *constraint_space, *style_, content_size_);
70 72
71 builder_->SetBlockSize(block_size) 73 builder_->SetBlockSize(block_size)
72 .SetInlineOverflow(max_inline_size_) 74 .SetInlineOverflow(max_inline_size_)
73 .SetBlockOverflow(content_size_); 75 .SetBlockOverflow(content_size_);
74 *out = builder_->ToFragment(); 76 *out = builder_->ToFragment();
75 state_ = kStateInit; 77 state_ = kStateInit;
76 return true; 78 return true;
77 } 79 }
78 }; 80 };
79 NOTREACHED(); 81 NOTREACHED();
80 *out = nullptr; 82 *out = nullptr;
81 return true; 83 return true;
82 } 84 }
83 85
84 } // namespace blink 86 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698