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

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

Issue 2583063004: [layoutng] Add a function to compute the min- and max-content contribution (Closed)
Patch Set: include margins Created 3 years, 12 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_length_utils.h" 5 #include "core/layout/ng/ng_length_utils.h"
6 6
7 #include "core/layout/ng/ng_constraint_space.h" 7 #include "core/layout/ng/ng_constraint_space.h"
8 #include "core/layout/ng/ng_constraint_space_builder.h" 8 #include "core/layout/ng/ng_constraint_space_builder.h"
9 #include "core/layout/ng/ng_fragment.h" 9 #include "core/layout/ng/ng_fragment.h"
10 #include "core/layout/ng/ng_fragment_builder.h" 10 #include "core/layout/ng/ng_fragment_builder.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 EXPECT_EQ(LayoutUnit(0), ResolveBlockLength(Length(Auto))); 115 EXPECT_EQ(LayoutUnit(0), ResolveBlockLength(Length(Auto)));
116 EXPECT_EQ(LayoutUnit(300), ResolveBlockLength(Length(FillAvailable))); 116 EXPECT_EQ(LayoutUnit(300), ResolveBlockLength(Length(FillAvailable)));
117 117
118 EXPECT_EQ(LayoutUnit(0), 118 EXPECT_EQ(LayoutUnit(0),
119 ResolveBlockLength(Length(Auto), LengthResolveType::kContentSize)); 119 ResolveBlockLength(Length(Auto), LengthResolveType::kContentSize));
120 EXPECT_EQ(LayoutUnit(300), 120 EXPECT_EQ(LayoutUnit(300),
121 ResolveBlockLength(Length(FillAvailable), 121 ResolveBlockLength(Length(FillAvailable),
122 LengthResolveType::kContentSize)); 122 LengthResolveType::kContentSize));
123 } 123 }
124 124
125 TEST_F(NGLengthUtilsTest, testComputeContentContribution) {
126 MinAndMaxContentSizes sizes;
127 sizes.min_content = LayoutUnit(30);
128 sizes.max_content = LayoutUnit(40);
129
130 MinAndMaxContentSizes expected{LayoutUnit(), LayoutUnit()};
131 style_->setLogicalWidth(Length(30, Percent));
132 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
133
134 style_->setLogicalWidth(Length(FillAvailable));
135 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
136
137 expected = MinAndMaxContentSizes{LayoutUnit(150), LayoutUnit(150)};
138 style_->setLogicalWidth(Length(150, Fixed));
139 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
140
141 expected = sizes;
142 style_->setLogicalWidth(Length(Auto));
143 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
144
145 expected = MinAndMaxContentSizes{LayoutUnit(430), LayoutUnit(440)};
146 style_->setPaddingLeft(Length(400, Fixed));
147 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
148
149 expected = MinAndMaxContentSizes{LayoutUnit(100), LayoutUnit(100)};
150 style_->setPaddingLeft(Length(0, Fixed));
151 style_->setLogicalWidth(Length(CalculationValue::create(
152 PixelsAndPercent(100, -10), ValueRangeNonNegative)));
153 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
154
155 expected = MinAndMaxContentSizes{LayoutUnit(30), LayoutUnit(35)};
156 style_->setLogicalWidth(Length(Auto));
157 style_->setMaxWidth(Length(35, Fixed));
158 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
159
160 expected = MinAndMaxContentSizes{LayoutUnit(80), LayoutUnit(80)};
161 style_->setLogicalWidth(Length(50, Fixed));
162 style_->setMinWidth(Length(80, Fixed));
163 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
164
165 expected = MinAndMaxContentSizes{LayoutUnit(150), LayoutUnit(150)};
166 style_ = ComputedStyle::create();
167 style_->setLogicalWidth(Length(100, Fixed));
168 style_->setPaddingLeft(Length(50, Fixed));
169 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
170
171 expected = MinAndMaxContentSizes{LayoutUnit(100), LayoutUnit(100)};
172 style_->setBoxSizing(BoxSizingBorderBox);
173 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
174
175 // Content size should never be below zero, even with box-sizing: border-box
176 // and a large padding...
177 expected = MinAndMaxContentSizes{LayoutUnit(400), LayoutUnit(400)};
178 style_->setPaddingLeft(Length(400, Fixed));
179 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
180
181 expected.min_content = expected.max_content =
182 sizes.min_content + LayoutUnit(400);
183 style_->setLogicalWidth(Length(MinContent));
184 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
185 style_->setLogicalWidth(Length(100, Fixed));
186 style_->setMaxWidth(Length(MaxContent));
187 // Due to padding and box-sizing, width computes to 400px and max-width to
188 // 440px, so the result is 400.
189 expected = MinAndMaxContentSizes{LayoutUnit(400), LayoutUnit(400)};
190 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
191 expected = MinAndMaxContentSizes{LayoutUnit(40), LayoutUnit(40)};
192 style_->setPaddingLeft(Length(0, Fixed));
193 EXPECT_EQ(expected, ComputeMinAndMaxContentContribution(*style_, sizes));
194 }
195
125 TEST_F(NGLengthUtilsTest, testComputeInlineSizeForFragment) { 196 TEST_F(NGLengthUtilsTest, testComputeInlineSizeForFragment) {
126 MinAndMaxContentSizes sizes; 197 MinAndMaxContentSizes sizes;
127 sizes.min_content = LayoutUnit(30); 198 sizes.min_content = LayoutUnit(30);
128 sizes.max_content = LayoutUnit(40); 199 sizes.max_content = LayoutUnit(40);
129 200
130 style_->setLogicalWidth(Length(30, Percent)); 201 style_->setLogicalWidth(Length(30, Percent));
131 EXPECT_EQ(LayoutUnit(60), ComputeInlineSizeForFragment()); 202 EXPECT_EQ(LayoutUnit(60), ComputeInlineSizeForFragment());
132 203
133 style_->setLogicalWidth(Length(150, Fixed)); 204 style_->setLogicalWidth(Length(150, Fixed));
134 EXPECT_EQ(LayoutUnit(150), ComputeInlineSizeForFragment()); 205 EXPECT_EQ(LayoutUnit(150), ComputeInlineSizeForFragment());
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 EXPECT_EQ(125, GetUsedColumnWidth(4, 100, 10, 530)); 493 EXPECT_EQ(125, GetUsedColumnWidth(4, 100, 10, 530));
423 EXPECT_EQ(4, GetUsedColumnCount(4, 100, 10, 530)); 494 EXPECT_EQ(4, GetUsedColumnCount(4, 100, 10, 530));
424 EXPECT_EQ(100, GetUsedColumnWidth(6, 100, 10, 540)); 495 EXPECT_EQ(100, GetUsedColumnWidth(6, 100, 10, 540));
425 EXPECT_EQ(5, GetUsedColumnCount(6, 100, 10, 540)); 496 EXPECT_EQ(5, GetUsedColumnCount(6, 100, 10, 540));
426 EXPECT_EQ(100, GetUsedColumnWidth(0, 100, 10, 540)); 497 EXPECT_EQ(100, GetUsedColumnWidth(0, 100, 10, 540));
427 EXPECT_EQ(5, GetUsedColumnCount(0, 100, 10, 540)); 498 EXPECT_EQ(5, GetUsedColumnCount(0, 100, 10, 540));
428 } 499 }
429 500
430 } // namespace 501 } // namespace
431 } // namespace blink 502 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_length_utils.cc ('k') | third_party/WebKit/Source/core/layout/ng/ng_units.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698