OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/GridTrackSizingAlgorithm.h" | 5 #include "core/layout/GridTrackSizingAlgorithm.h" |
6 | 6 |
7 #include "core/layout/Grid.h" | 7 #include "core/layout/Grid.h" |
8 #include "core/layout/LayoutGrid.h" | 8 #include "core/layout/LayoutGrid.h" |
9 #include "platform/LengthFunctions.h" | 9 #include "platform/LengthFunctions.h" |
10 | 10 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 LayoutUnit(-1)); | 280 LayoutUnit(-1)); |
281 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis); | 281 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis); |
282 } | 282 } |
283 | 283 |
284 // We need to clear the stretched height to properly compute logical height | 284 // We need to clear the stretched height to properly compute logical height |
285 // during layout. | 285 // during layout. |
286 if (child.NeedsLayout()) | 286 if (child.NeedsLayout()) |
287 child.ClearOverrideLogicalContentHeight(); | 287 child.ClearOverrideLogicalContentHeight(); |
288 | 288 |
289 child.LayoutIfNeeded(); | 289 child.LayoutIfNeeded(); |
290 GridAxis baseline_axis = GetLayoutGrid()->IsOrthogonalChild(child) | 290 |
291 ? kGridRowAxis | 291 if (auto baseline_extent = ExtentForBaselineAlignment(child)) |
292 : kGridColumnAxis; | 292 return baseline_extent.value(); |
293 if (GetLayoutGrid()->IsBaselineAlignmentForChild(child, baseline_axis) && | 293 |
294 GetLayoutGrid()->IsBaselineContextComputed(baseline_axis)) { | |
295 auto& group = | |
296 GetLayoutGrid()->GetBaselineGroupForChild(child, baseline_axis); | |
297 return group.MaxAscent() + group.MaxDescent(); | |
298 } | |
299 return child.LogicalHeight() + child.MarginLogicalHeight(); | 294 return child.LogicalHeight() + child.MarginLogicalHeight(); |
300 } | 295 } |
301 | 296 |
302 DISABLE_CFI_PERF | 297 DISABLE_CFI_PERF |
303 LayoutUnit GridTrackSizingAlgorithmStrategy::MinContentForChild( | 298 LayoutUnit GridTrackSizingAlgorithmStrategy::MinContentForChild( |
304 LayoutBox& child) const { | 299 LayoutBox& child) const { |
305 GridTrackSizingDirection child_inline_direction = | 300 GridTrackSizingDirection child_inline_direction = |
306 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns); | 301 FlowAwareDirectionForChild(GetLayoutGrid(), child, kForColumns); |
307 if (Direction() == child_inline_direction) { | 302 if (Direction() == child_inline_direction) { |
308 // If |child| has a relative logical width, we shouldn't let it override its | 303 // If |child| has a relative logical width, we shouldn't let it override its |
(...skipping 10 matching lines...) Expand all Loading... |
319 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html | 314 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html |
320 LayoutUnit margin_logical_width = | 315 LayoutUnit margin_logical_width = |
321 child.NeedsLayout() ? ComputeMarginLogicalSizeForChild( | 316 child.NeedsLayout() ? ComputeMarginLogicalSizeForChild( |
322 kInlineDirection, GetLayoutGrid(), child) | 317 kInlineDirection, GetLayoutGrid(), child) |
323 : child.MarginLogicalWidth(); | 318 : child.MarginLogicalWidth(); |
324 return child.MinPreferredLogicalWidth() + margin_logical_width; | 319 return child.MinPreferredLogicalWidth() + margin_logical_width; |
325 } | 320 } |
326 | 321 |
327 if (Direction() == kForColumns && !AvailableSpace()) { | 322 if (Direction() == kForColumns && !AvailableSpace()) { |
328 DCHECK(GetLayoutGrid()->IsOrthogonalChild(child)); | 323 DCHECK(GetLayoutGrid()->IsOrthogonalChild(child)); |
329 if (GetLayoutGrid()->IsBaselineAlignmentForChild(child, kGridRowAxis) && | 324 if (auto baseline_extent = ExtentForBaselineAlignment(child)) |
330 GetLayoutGrid()->IsBaselineContextComputed(kGridRowAxis)) { | 325 return baseline_extent.value(); |
331 auto& group = | |
332 GetLayoutGrid()->GetBaselineGroupForChild(child, kGridRowAxis); | |
333 return group.MaxAscent() + group.MaxDescent(); | |
334 } | |
335 } | 326 } |
336 | 327 |
337 if (UpdateOverrideContainingBlockContentSizeForChild(child, | 328 if (UpdateOverrideContainingBlockContentSizeForChild(child, |
338 child_inline_direction)) | 329 child_inline_direction)) |
339 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis); | 330 child.SetNeedsLayout(LayoutInvalidationReason::kGridChanged, kMarkOnlyThis); |
340 return LogicalHeightForChild(child); | 331 return LogicalHeightForChild(child); |
341 } | 332 } |
342 | 333 |
343 DISABLE_CFI_PERF | 334 DISABLE_CFI_PERF |
344 LayoutUnit GridTrackSizingAlgorithmStrategy::MaxContentForChild( | 335 LayoutUnit GridTrackSizingAlgorithmStrategy::MaxContentForChild( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 return algorithm_.FindFrUnitSize(tracks_span, left_over_space); | 414 return algorithm_.FindFrUnitSize(tracks_span, left_over_space); |
424 } | 415 } |
425 | 416 |
426 void GridTrackSizingAlgorithmStrategy::DistributeSpaceToTracks( | 417 void GridTrackSizingAlgorithmStrategy::DistributeSpaceToTracks( |
427 Vector<GridTrack*>& tracks, | 418 Vector<GridTrack*>& tracks, |
428 LayoutUnit& available_logical_space) const { | 419 LayoutUnit& available_logical_space) const { |
429 algorithm_.DistributeSpaceToTracks<kMaximizeTracks>(tracks, nullptr, | 420 algorithm_.DistributeSpaceToTracks<kMaximizeTracks>(tracks, nullptr, |
430 available_logical_space); | 421 available_logical_space); |
431 } | 422 } |
432 | 423 |
| 424 Optional<LayoutUnit> |
| 425 GridTrackSizingAlgorithmStrategy::ExtentForBaselineAlignment( |
| 426 LayoutBox& child) const { |
| 427 auto grid = algorithm_.layout_grid_; |
| 428 GridAxis baseline_axis = |
| 429 grid->IsOrthogonalChild(child) ? kGridRowAxis : kGridColumnAxis; |
| 430 if (!grid->IsBaselineAlignmentForChild(child, baseline_axis) || |
| 431 !grid->IsBaselineContextComputed(baseline_axis)) |
| 432 return WTF::kNullopt; |
| 433 |
| 434 auto& group = grid->GetBaselineGroupForChild(child, baseline_axis); |
| 435 return group.MaxAscent() + group.MaxDescent(); |
| 436 } |
| 437 |
433 LayoutUnit DefiniteSizeStrategy::MinLogicalWidthForChild( | 438 LayoutUnit DefiniteSizeStrategy::MinLogicalWidthForChild( |
434 LayoutBox& child, | 439 LayoutBox& child, |
435 Length child_min_size, | 440 Length child_min_size, |
436 GridTrackSizingDirection child_inline_direction) const { | 441 GridTrackSizingDirection child_inline_direction) const { |
437 LayoutUnit margin_logical_width = ComputeMarginLogicalSizeForChild( | 442 LayoutUnit margin_logical_width = ComputeMarginLogicalSizeForChild( |
438 kInlineDirection, GetLayoutGrid(), child); | 443 kInlineDirection, GetLayoutGrid(), child); |
439 return child.ComputeLogicalWidthUsing( | 444 return child.ComputeLogicalWidthUsing( |
440 kMinSize, child_min_size, | 445 kMinSize, child_min_size, |
441 OverrideContainingBlockContentSizeForChild(child, | 446 OverrideContainingBlockContentSizeForChild(child, |
442 child_inline_direction), | 447 child_inline_direction), |
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 DCHECK(algorithm_.IsValidTransition()); | 1498 DCHECK(algorithm_.IsValidTransition()); |
1494 DCHECK(!algorithm_.needs_setup_); | 1499 DCHECK(!algorithm_.needs_setup_); |
1495 } | 1500 } |
1496 | 1501 |
1497 GridTrackSizingAlgorithm::StateMachine::~StateMachine() { | 1502 GridTrackSizingAlgorithm::StateMachine::~StateMachine() { |
1498 algorithm_.AdvanceNextState(); | 1503 algorithm_.AdvanceNextState(); |
1499 algorithm_.needs_setup_ = true; | 1504 algorithm_.needs_setup_ = true; |
1500 } | 1505 } |
1501 | 1506 |
1502 } // namespace blink | 1507 } // namespace blink |
OLD | NEW |