OLD | NEW |
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/style/ComputedStyle.h" | 10 #include "core/style/ComputedStyle.h" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 if (space.IsFixedSizeInline()) | 235 if (space.IsFixedSizeInline()) |
236 return space.AvailableSize().inline_size; | 236 return space.AvailableSize().inline_size; |
237 | 237 |
238 Length logicalWidth = style.logicalWidth(); | 238 Length logicalWidth = style.logicalWidth(); |
239 if (logicalWidth.isAuto() && space.IsShrinkToFit()) | 239 if (logicalWidth.isAuto() && space.IsShrinkToFit()) |
240 logicalWidth = Length(FitContent); | 240 logicalWidth = Length(FitContent); |
241 | 241 |
242 LayoutUnit extent = ResolveInlineLength( | 242 LayoutUnit extent = ResolveInlineLength( |
243 space, style, min_and_max, logicalWidth, LengthResolveType::kContentSize); | 243 space, style, min_and_max, logicalWidth, LengthResolveType::kContentSize); |
244 | 244 |
245 Length max_length = style.logicalMaxWidth(); | 245 Optional<LayoutUnit> max_length; |
246 if (!max_length.isMaxSizeNone()) { | 246 if (!style.logicalMaxWidth().isMaxSizeNone()) { |
247 LayoutUnit max = ResolveInlineLength(space, style, min_and_max, max_length, | 247 max_length = |
248 LengthResolveType::kMaxSize); | 248 ResolveInlineLength(space, style, min_and_max, style.logicalMaxWidth(), |
249 extent = std::min(extent, max); | 249 LengthResolveType::kMaxSize); |
250 } | 250 } |
251 | 251 Optional<LayoutUnit> min_length = |
252 LayoutUnit min = | |
253 ResolveInlineLength(space, style, min_and_max, style.logicalMinWidth(), | 252 ResolveInlineLength(space, style, min_and_max, style.logicalMinWidth(), |
254 LengthResolveType::kMinSize); | 253 LengthResolveType::kMinSize); |
255 extent = std::max(extent, min); | 254 return ConstrainByMinMax(extent, min_length, max_length); |
256 return extent; | |
257 } | 255 } |
258 | 256 |
259 LayoutUnit ComputeBlockSizeForFragment( | 257 LayoutUnit ComputeBlockSizeForFragment( |
260 const NGConstraintSpace& constraint_space, | 258 const NGConstraintSpace& constraint_space, |
261 const ComputedStyle& style, | 259 const ComputedStyle& style, |
262 LayoutUnit content_size) { | 260 LayoutUnit content_size) { |
263 if (constraint_space.IsFixedSizeBlock()) | 261 if (constraint_space.IsFixedSizeBlock()) |
264 return constraint_space.AvailableSize().block_size; | 262 return constraint_space.AvailableSize().block_size; |
265 | 263 |
266 LayoutUnit extent = | 264 LayoutUnit extent = |
267 ResolveBlockLength(constraint_space, style, style.logicalHeight(), | 265 ResolveBlockLength(constraint_space, style, style.logicalHeight(), |
268 content_size, LengthResolveType::kContentSize); | 266 content_size, LengthResolveType::kContentSize); |
269 if (extent == NGSizeIndefinite) { | 267 if (extent == NGSizeIndefinite) { |
270 DCHECK_EQ(content_size, NGSizeIndefinite); | 268 DCHECK_EQ(content_size, NGSizeIndefinite); |
271 return extent; | 269 return extent; |
272 } | 270 } |
273 | 271 Optional<LayoutUnit> max_length; |
274 Length max_length = style.logicalMaxHeight(); | 272 if (!style.logicalMaxHeight().isMaxSizeNone()) { |
275 if (!max_length.isMaxSizeNone()) { | 273 max_length = |
276 LayoutUnit max = | 274 ResolveBlockLength(constraint_space, style, style.logicalMaxHeight(), |
277 ResolveBlockLength(constraint_space, style, max_length, content_size, | 275 content_size, LengthResolveType::kMaxSize); |
278 LengthResolveType::kMaxSize); | |
279 extent = std::min(extent, max); | |
280 } | 276 } |
281 | 277 Optional<LayoutUnit> min_length = |
282 LayoutUnit min = | |
283 ResolveBlockLength(constraint_space, style, style.logicalMinHeight(), | 278 ResolveBlockLength(constraint_space, style, style.logicalMinHeight(), |
284 content_size, LengthResolveType::kMinSize); | 279 content_size, LengthResolveType::kMinSize); |
285 extent = std::max(extent, min); | 280 return ConstrainByMinMax(extent, min_length, max_length); |
286 return extent; | |
287 } | 281 } |
288 | 282 |
289 int ResolveUsedColumnCount(int computed_count, | 283 int ResolveUsedColumnCount(int computed_count, |
290 LayoutUnit computed_size, | 284 LayoutUnit computed_size, |
291 LayoutUnit used_gap, | 285 LayoutUnit used_gap, |
292 LayoutUnit available_size) { | 286 LayoutUnit available_size) { |
293 if (computed_size == NGSizeIndefinite) { | 287 if (computed_size == NGSizeIndefinite) { |
294 DCHECK(computed_count); | 288 DCHECK(computed_count); |
295 return computed_count; | 289 return computed_count; |
296 } | 290 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 if (style.marginStart().isAuto() && style.marginEnd().isAuto()) { | 395 if (style.marginStart().isAuto() && style.marginEnd().isAuto()) { |
402 margins->inline_start = available_space / 2; | 396 margins->inline_start = available_space / 2; |
403 margins->inline_end = available_space - margins->inline_start; | 397 margins->inline_end = available_space - margins->inline_start; |
404 } else if (style.marginStart().isAuto()) { | 398 } else if (style.marginStart().isAuto()) { |
405 margins->inline_start = available_space; | 399 margins->inline_start = available_space; |
406 } else if (style.marginEnd().isAuto()) { | 400 } else if (style.marginEnd().isAuto()) { |
407 margins->inline_end = available_space; | 401 margins->inline_end = available_space; |
408 } | 402 } |
409 } | 403 } |
410 | 404 |
| 405 LayoutUnit ConstrainByMinMax(LayoutUnit length, |
| 406 Optional<LayoutUnit> min, |
| 407 Optional<LayoutUnit> max) { |
| 408 if (max && length > max.value()) |
| 409 length = max.value(); |
| 410 if (min && length < min.value()) |
| 411 length = min.value(); |
| 412 return length; |
| 413 } |
| 414 |
411 } // namespace blink | 415 } // namespace blink |
OLD | NEW |