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

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: review comments 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 bool NGBox::ComputeOrSynthesizeMinAndMaxContentSizes(
atotic 2016/11/01 21:56:02 This routine name is 41 chars long, 1/2 of our lin
cbiesinger 2016/11/02 20:18:08 Ok, I renamed it back to ComputeMinAndMaxContentSi
68 MinAndMaxContentSizes* sizes) {
69 if (!algorithm_) {
70 NGConstraintSpaceBuilder builder(
71 FromPlatformWritingMode(Style()->getWritingMode()));
72
73 builder.SetContainerSize(NGLogicalSize(LayoutUnit(), LayoutUnit()));
74 // TODO(layoutng): Use builder.ToConstraintSpace.ToLogicalConstraintSpace
75 // once
76 // that's available.
77 NGConstraintSpace* constraint_space = new NGConstraintSpace(
78 FromPlatformWritingMode(Style()->getWritingMode()),
79 FromPlatformDirection(Style()->direction()),
80 builder.ToConstraintSpace());
81
82 algorithm_ =
atotic 2016/11/01 21:56:02 algorithm_ is used in 2 functions (Layout & MinMax
cbiesinger 2016/11/02 20:18:08 OK -- I will do that for now. Once we have the sta
83 new NGBlockLayoutAlgorithm(Style(), FirstChild(), constraint_space);
84 }
85 // TODO(cbiesinger): For orthogonal children, we need to always synthesize.
86 NGLayoutAlgorithm::MinAndMaxState state =
87 algorithm_->ComputeMinAndMaxContentSizes(sizes);
88 if (state == NGLayoutAlgorithm::Success)
89 return true;
90 if (state == NGLayoutAlgorithm::Pending)
91 return false;
92 DCHECK_EQ(state, NGLayoutAlgorithm::NotImplemented);
93
94 // TODO(cbiesinger): Replace the loops below with a state machine like in
95 // Layout.
96
97 // Have to synthesize this value.
98 NGPhysicalFragment* physical_fragment;
99 while (!algorithm_->Layout(&physical_fragment))
100 continue;
101 NGFragment* fragment = new NGFragment(
102 FromPlatformWritingMode(Style()->getWritingMode()),
103 FromPlatformDirection(Style()->direction()), physical_fragment);
104
105 sizes->min_content = fragment->InlineOverflow();
106
107 // Now, redo with infinite space for max_content
108 NGConstraintSpaceBuilder builder(
109 FromPlatformWritingMode(Style()->getWritingMode()));
110 builder.SetContainerSize(NGLogicalSize(LayoutUnit::max(), LayoutUnit()));
111 NGConstraintSpace* constraint_space = new NGConstraintSpace(
112 FromPlatformWritingMode(Style()->getWritingMode()),
113 FromPlatformDirection(Style()->direction()), builder.ToConstraintSpace());
114
115 algorithm_ =
116 new NGBlockLayoutAlgorithm(Style(), FirstChild(), constraint_space);
117 while (!algorithm_->Layout(&physical_fragment))
118 continue;
119
120 fragment = new NGFragment(FromPlatformWritingMode(Style()->getWritingMode()),
121 FromPlatformDirection(Style()->direction()),
122 physical_fragment);
123 sizes->max_content = fragment->InlineOverflow();
124 return true;
125 }
126
66 const ComputedStyle* NGBox::Style() const { 127 const ComputedStyle* NGBox::Style() const {
67 if (style_) 128 if (style_)
68 return style_.get(); 129 return style_.get();
69 DCHECK(layout_box_); 130 DCHECK(layout_box_);
70 return layout_box_->style(); 131 return layout_box_->style();
71 } 132 }
72 133
73 NGBox* NGBox::NextSibling() { 134 NGBox* NGBox::NextSibling() {
74 if (!next_sibling_) { 135 if (!next_sibling_) {
75 LayoutObject* next_sibling = 136 LayoutObject* next_sibling =
(...skipping 14 matching lines...) Expand all
90 } 151 }
91 152
92 void NGBox::SetNextSibling(NGBox* sibling) { 153 void NGBox::SetNextSibling(NGBox* sibling) {
93 next_sibling_ = sibling; 154 next_sibling_ = sibling;
94 } 155 }
95 156
96 void NGBox::SetFirstChild(NGBox* child) { 157 void NGBox::SetFirstChild(NGBox* child) {
97 first_child_ = child; 158 first_child_ = child;
98 } 159 }
99 160
161 DEFINE_TRACE(NGBox) {
162 visitor->trace(algorithm_);
163 visitor->trace(fragment_);
164 visitor->trace(next_sibling_);
165 visitor->trace(first_child_);
166 }
167
100 void NGBox::PositionUpdated() { 168 void NGBox::PositionUpdated() {
101 if (!layout_box_) 169 if (!layout_box_)
102 return; 170 return;
103 DCHECK(layout_box_->parent()) << "Should be called on children only."; 171 DCHECK(layout_box_->parent()) << "Should be called on children only.";
104 172
105 layout_box_->setX(fragment_->LeftOffset()); 173 layout_box_->setX(fragment_->LeftOffset());
106 layout_box_->setY(fragment_->TopOffset()); 174 layout_box_->setY(fragment_->TopOffset());
107 175
108 if (layout_box_->isFloating() && layout_box_->parent()->isLayoutBlockFlow()) { 176 if (layout_box_->isFloating() && layout_box_->parent()->isLayoutBlockFlow()) {
109 FloatingObject* floating_object = toLayoutBlockFlow(layout_box_->parent()) 177 FloatingObject* floating_object = toLayoutBlockFlow(layout_box_->parent())
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 .SetBlockSize(layout_box_->logicalHeight()) 247 .SetBlockSize(layout_box_->logicalHeight())
180 .SetDirection(FromPlatformDirection(layout_box_->styleRef().direction())) 248 .SetDirection(FromPlatformDirection(layout_box_->styleRef().direction()))
181 .SetWritingMode( 249 .SetWritingMode(
182 FromPlatformWritingMode(layout_box_->styleRef().getWritingMode())) 250 FromPlatformWritingMode(layout_box_->styleRef().getWritingMode()))
183 .SetInlineOverflow(overflow.width()) 251 .SetInlineOverflow(overflow.width())
184 .SetBlockOverflow(overflow.height()); 252 .SetBlockOverflow(overflow.height());
185 return builder.ToFragment(); 253 return builder.ToFragment();
186 } 254 }
187 255
188 } // namespace blink 256 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_box.h ('k') | third_party/WebKit/Source/core/layout/ng/ng_box_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698