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

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

Issue 2462153002: [layoutng] Support computing min-content and max-content (Closed)
Patch Set: Created 4 years, 1 month 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_box.h" 5 #include "core/layout/ng/ng_box.h"
6 6
7 #include "core/layout/LayoutBlockFlow.h" 7 #include "core/layout/LayoutBlockFlow.h"
8 #include "core/layout/ng/layout_ng_block_flow.h" 8 #include "core/layout/ng/layout_ng_block_flow.h"
9 #include "core/layout/ng/ng_block_layout_algorithm.h" 9 #include "core/layout/ng/ng_block_layout_algorithm.h"
10 #include "core/layout/ng/ng_constraint_space_builder.h"
10 #include "core/layout/ng/ng_constraint_space.h" 11 #include "core/layout/ng/ng_constraint_space.h"
11 #include "core/layout/ng/ng_direction.h" 12 #include "core/layout/ng/ng_direction.h"
12 #include "core/layout/ng/ng_fragment.h" 13 #include "core/layout/ng/ng_fragment.h"
13 #include "core/layout/ng/ng_fragment_builder.h" 14 #include "core/layout/ng/ng_fragment_builder.h"
14 #include "core/layout/ng/ng_length_utils.h" 15 #include "core/layout/ng/ng_length_utils.h"
15 #include "core/layout/ng/ng_writing_mode.h" 16 #include "core/layout/ng/ng_writing_mode.h"
16 17
17 namespace blink { 18 namespace blink {
18 19
19 NGBox::NGBox(LayoutObject* layout_object) 20 NGBox::NGBox(LayoutObject* layout_object)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 fragment_ = RunOldLayout(*constraint_space); 57 fragment_ = RunOldLayout(*constraint_space);
57 } 58 }
58 *out = new NGFragment(constraint_space->WritingMode(), 59 *out = new NGFragment(constraint_space->WritingMode(),
59 FromPlatformDirection(Style()->direction()), 60 FromPlatformDirection(Style()->direction()),
60 fragment_.get()); 61 fragment_.get());
61 // Reset algorithm for future use 62 // Reset algorithm for future use
62 algorithm_ = nullptr; 63 algorithm_ = nullptr;
63 return true; 64 return true;
64 } 65 }
65 66
67 void NGBox::ComputeMinAndMaxContentSizes(NGFragment** min_content,
68 NGFragment** max_content) {
69 NGConstraintSpaceBuilder builder(
70 FromPlatformWritingMode(Style()->getWritingMode()));
71 builder.SetContainerSize(NGLogicalSize(LayoutUnit(), LayoutUnit()));
Gleb Lanbin 2016/10/31 19:52:47 nit. you can chain SetContainerSize call to line a
cbiesinger 2016/11/01 19:10:03 I'd rather not chain something to the constructor
72 NGConstraintSpace* constraint_space = new NGConstraintSpace(
73 FromPlatformWritingMode(Style()->getWritingMode()),
74 FromPlatformDirection(Style()->direction()), builder.ToConstraintSpace());
eae 2016/10/31 19:30:25 Presumably once Ian's work is done this will be bu
cbiesinger 2016/11/01 19:10:03 Ah, is that the plan? Added a TODO.
75
76 NGLayoutAlgorithm* algorithm =
77 new NGBlockLayoutAlgorithm(Style(), FirstChild(), constraint_space);
78 if (algorithm->ComputeMinAndMaxContentSizes(min_content, max_content) ==
Gleb Lanbin 2016/10/31 19:52:47 IMO it's a bit confusing that we have 2 almost ide
cbiesinger 2016/11/01 19:10:03 Renamed this one to ComputeOrSynthesizeMinAndMaxCo
79 NGLayoutAlgorithm::Success)
80 return;
81
82 // Have to synthesize this value.
83 NGPhysicalFragment* fragment;
84 while (!algorithm->Layout(&fragment))
85 continue;
86
87 HeapVector<Member<const NGPhysicalFragmentBase>> empty;
Gleb Lanbin 2016/10/31 19:52:47 may be add an additional constructor to NGPhysical
cbiesinger 2016/11/01 19:10:03 Removed this entirely due to other changes.
88 fragment =
89 new NGPhysicalFragment(fragment->OverflowSize(), fragment->OverflowSize(),
90 empty, NGMarginStrut());
91
92 *min_content =
93 new NGFragment(FromPlatformWritingMode(Style()->getWritingMode()),
94 FromPlatformDirection(Style()->direction()), fragment);
95
96 // Now, redo with infinite space for max_content
97 builder.SetContainerSize(NGLogicalSize(LayoutUnit::max(), LayoutUnit()));
98 constraint_space = new NGConstraintSpace(
99 FromPlatformWritingMode(Style()->getWritingMode()),
100 FromPlatformDirection(Style()->direction()), builder.ToConstraintSpace());
101
102 algorithm =
103 new NGBlockLayoutAlgorithm(Style(), FirstChild(), constraint_space);
104 while (!algorithm->Layout(&fragment))
105 continue;
106
107 fragment =
108 new NGPhysicalFragment(fragment->OverflowSize(), fragment->OverflowSize(),
109 empty, NGMarginStrut());
110 *max_content =
111 new NGFragment(FromPlatformWritingMode(Style()->getWritingMode()),
112 FromPlatformDirection(Style()->direction()), fragment);
113 }
114
66 const ComputedStyle* NGBox::Style() const { 115 const ComputedStyle* NGBox::Style() const {
67 if (style_) 116 if (style_)
68 return style_.get(); 117 return style_.get();
69 DCHECK(layout_box_); 118 DCHECK(layout_box_);
70 return layout_box_->style(); 119 return layout_box_->style();
71 } 120 }
72 121
73 NGBox* NGBox::NextSibling() { 122 NGBox* NGBox::NextSibling() {
74 if (!next_sibling_) { 123 if (!next_sibling_) {
75 LayoutObject* next_sibling = 124 LayoutObject* next_sibling =
(...skipping 14 matching lines...) Expand all
90 } 139 }
91 140
92 void NGBox::SetNextSibling(NGBox* sibling) { 141 void NGBox::SetNextSibling(NGBox* sibling) {
93 next_sibling_ = sibling; 142 next_sibling_ = sibling;
94 } 143 }
95 144
96 void NGBox::SetFirstChild(NGBox* child) { 145 void NGBox::SetFirstChild(NGBox* child) {
97 first_child_ = child; 146 first_child_ = child;
98 } 147 }
99 148
149 DEFINE_TRACE(NGBox) {
150 visitor->trace(algorithm_);
151 visitor->trace(fragment_);
152 visitor->trace(next_sibling_);
153 visitor->trace(first_child_);
154 }
155
100 void NGBox::PositionUpdated() { 156 void NGBox::PositionUpdated() {
101 if (!layout_box_) 157 if (!layout_box_)
102 return; 158 return;
103 DCHECK(layout_box_->parent()) << "Should be called on children only."; 159 DCHECK(layout_box_->parent()) << "Should be called on children only.";
104 160
105 layout_box_->setX(fragment_->LeftOffset()); 161 layout_box_->setX(fragment_->LeftOffset());
106 layout_box_->setY(fragment_->TopOffset()); 162 layout_box_->setY(fragment_->TopOffset());
107 163
108 if (layout_box_->isFloating() && layout_box_->parent()->isLayoutBlockFlow()) { 164 if (layout_box_->isFloating() && layout_box_->parent()->isLayoutBlockFlow()) {
109 FloatingObject* floating_object = toLayoutBlockFlow(layout_box_->parent()) 165 FloatingObject* floating_object = toLayoutBlockFlow(layout_box_->parent())
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 .SetBlockSize(layout_box_->logicalHeight()) 235 .SetBlockSize(layout_box_->logicalHeight())
180 .SetDirection(FromPlatformDirection(layout_box_->styleRef().direction())) 236 .SetDirection(FromPlatformDirection(layout_box_->styleRef().direction()))
181 .SetWritingMode( 237 .SetWritingMode(
182 FromPlatformWritingMode(layout_box_->styleRef().getWritingMode())) 238 FromPlatformWritingMode(layout_box_->styleRef().getWritingMode()))
183 .SetInlineOverflow(overflow.width()) 239 .SetInlineOverflow(overflow.width())
184 .SetBlockOverflow(overflow.height()); 240 .SetBlockOverflow(overflow.height());
185 return builder.ToFragment(); 241 return builder.ToFragment();
186 } 242 }
187 243
188 } // namespace blink 244 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698